Merge branch 'MDL-74815-400' of https://github.com/junpataleta/moodle into MOODLE_400...
[moodle.git] / mod / lesson / tabs.php
blobe3b385746ff42104122e065fb7f9d54376f29026
1 <?php
3 // This file is part of Moodle - http://moodle.org/
4 //
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 /**
19 * Sets up the tabs used by the lesson pages for teachers.
21 * This file was adapted from the mod/quiz/tabs.php
23 * @package mod_lesson
24 * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
25 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or late
28 defined('MOODLE_INTERNAL') || die();
30 /// This file to be included so we can assume config.php has already been included.
31 global $DB;
32 if (empty($lesson)) {
33 print_error('cannotcallscript');
35 if (!isset($currenttab)) {
36 $currenttab = '';
38 if (!isset($cm)) {
39 $cm = get_coursemodule_from_instance('lesson', $lesson->id);
40 $context = context_module::instance($cm->id);
42 if (!isset($course)) {
43 $course = $DB->get_record('course', array('id' => $lesson->course));
46 $tabs = $row = $inactive = $activated = array();
48 /// user attempt count for reports link hover (completed attempts - much faster)
49 $attemptscount = $DB->count_records('lesson_grades', array('lessonid'=>$lesson->id));
51 $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)));
52 $row[] = new tabobject('edit', "$CFG->wwwroot/mod/lesson/edit.php?id=$cm->id", get_string('edit', 'lesson'), get_string('edita', 'moodle', format_string($lesson->name)));
53 if (has_capability('mod/lesson:viewreports', $context)) {
54 $row[] = new tabobject('reports', "$CFG->wwwroot/mod/lesson/report.php?id=$cm->id", get_string('reports', 'lesson'),
55 get_string('viewreports2', 'lesson', $attemptscount));
57 if (has_capability('mod/lesson:grade', $context)) {
58 $row[] = new tabobject('essay', "$CFG->wwwroot/mod/lesson/essay.php?id=$cm->id", get_string('manualgrading', 'lesson'));
61 $tabs[] = $row;
64 switch ($currenttab) {
65 case 'reportoverview':
66 case 'reportdetail':
67 /// sub tabs for reports (overview and detail)
68 $inactive[] = 'reports';
69 $activated[] = 'reports';
71 $row = array();
72 $row[] = new tabobject('reportoverview', "$CFG->wwwroot/mod/lesson/report.php?id=$cm->id&amp;action=reportoverview", get_string('overview', 'lesson'));
73 $row[] = new tabobject('reportdetail', "$CFG->wwwroot/mod/lesson/report.php?id=$cm->id&amp;action=reportdetail", get_string('detailedstats', 'lesson'));
74 $tabs[] = $row;
75 break;
76 case 'collapsed':
77 case 'full':
78 case 'single':
79 /// sub tabs for edit view (collapsed and expanded aka full)
80 $inactive[] = 'edit';
81 $activated[] = 'edit';
83 $row = array();
84 $row[] = new tabobject('collapsed', "$CFG->wwwroot/mod/lesson/edit.php?id=$cm->id&amp;mode=collapsed", get_string('collapsed', 'lesson'));
85 $row[] = new tabobject('full', "$CFG->wwwroot/mod/lesson/edit.php?id=$cm->id&amp;mode=full", get_string('full', 'lesson'));
86 $tabs[] = $row;
87 break;
90 print_tabs($tabs, $currenttab, $inactive, $activated);