MDL-11082 Improved groups upgrade performance 1.8x -> 1.9; thanks Eloy for telling...
[moodle-pu.git] / mod / lesson / tabs.php
blob3c88a5b0393f7705b7d85643c4a5e0c626b66741
1 <?php // $Id$
2 /**
3 * Sets up the tabs used by the lesson pages for teachers.
5 * This file was adapted from the mod/quiz/tabs.php
7 * @version $Id$
8 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
9 * @package lesson
12 /// This file to be included so we can assume config.php has already been included.
14 if (empty($lesson)) {
15 error('You cannot call this script in that way');
17 if (!isset($currenttab)) {
18 $currenttab = '';
20 if (!isset($cm)) {
21 $cm = get_coursemodule_from_instance('lesson', $lesson->id);
22 $context = get_context_instance(CONTEXT_MODULE, $cm->id);
24 if (!isset($course)) {
25 $course = get_record('course', 'id', $lesson->course);
28 $tabs = $row = $inactive = $activated = array();
30 /// user attempt count for reports link hover (completed attempts - much faster)
31 $counts = new stdClass;
32 $counts->attempts = count_records('lesson_grades', 'lessonid', $lesson->id);
33 $counts->student = $course->student;
35 $row[] = new tabobject('view', "$CFG->wwwroot/mod/lesson/view.php?id=$cm->id", get_string('preview', 'lesson'), get_string('previewlesson', 'lesson', format_string($lesson->name)));
36 $row[] = new tabobject('edit', "$CFG->wwwroot/mod/lesson/edit.php?id=$cm->id", get_string('edit', 'lesson'), get_string('edit', 'moodle', format_string($lesson->name)));
37 $row[] = new tabobject('reports', "$CFG->wwwroot/mod/lesson/report.php?id=$cm->id", get_string('reports', 'lesson'), get_string('viewreports', 'lesson', $counts));
38 if (has_capability('mod/lesson:edit', $context)) {
39 $row[] = new tabobject('essay', "$CFG->wwwroot/mod/lesson/essay.php?id=$cm->id", get_string('manualgrading', 'lesson'));
41 if ($lesson->highscores) {
42 $row[] = new tabobject('highscores', "$CFG->wwwroot/mod/lesson/highscores.php?id=$cm->id", get_string('highscores', 'lesson'));
45 $tabs[] = $row;
48 switch ($currenttab) {
49 case 'reportoverview':
50 case 'reportdetail':
51 /// sub tabs for reports (overview and detail)
52 $inactive[] = 'reports';
53 $activated[] = 'reports';
55 $row = array();
56 $row[] = new tabobject('reportoverview', "$CFG->wwwroot/mod/lesson/report.php?id=$cm->id&amp;action=reportoverview", get_string('overview', 'lesson'));
57 $row[] = new tabobject('reportdetail', "$CFG->wwwroot/mod/lesson/report.php?id=$cm->id&amp;action=reportdetail", get_string('detailedstats', 'lesson'));
58 $tabs[] = $row;
59 break;
60 case 'collapsed':
61 case 'full':
62 case 'single':
63 /// sub tabs for edit view (collapsed and expanded aka full)
64 $inactive[] = 'edit';
65 $activated[] = 'edit';
67 $row = array();
68 $row[] = new tabobject('collapsed', "$CFG->wwwroot/mod/lesson/edit.php?id=$cm->id&amp;mode=collapsed", get_string('collapsed', 'lesson'));
69 $row[] = new tabobject('full', "$CFG->wwwroot/mod/lesson/edit.php?id=$cm->id&amp;mode=full", get_string('full', 'lesson'));
70 $tabs[] = $row;
71 break;
74 print_tabs($tabs, $currenttab, $inactive, $activated);