From b71d1e936f7115895587a5bfc0df6336f823fea0 Mon Sep 17 00:00:00 2001 From: Michael Sands Date: Sun, 15 Sep 2013 15:19:35 +1200 Subject: [PATCH 1/2] Grading and preview tabs now omitted when no content exists --- mod/lesson/locallib.php | 2 +- mod/lesson/tabs.php | 20 +++++++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/mod/lesson/locallib.php b/mod/lesson/locallib.php index 5213a8e..6c4c9c9 100644 --- a/mod/lesson/locallib.php +++ b/mod/lesson/locallib.php @@ -2726,7 +2726,7 @@ class lesson_page_type_manager { public function load_all_pages(lesson $lesson) { global $DB; if (!($pages =$DB->get_records('lesson_pages', array('lessonid'=>$lesson->id)))) { - print_error('cannotfindpages', 'lesson'); + #print_error('cannotfindpages', 'lesson'); } foreach ($pages as $key=>$page) { $pagetype = get_class($this->types[$page->qtype]); diff --git a/mod/lesson/tabs.php b/mod/lesson/tabs.php index 548ad18..ea1ca41 100644 --- a/mod/lesson/tabs.php +++ b/mod/lesson/tabs.php @@ -46,13 +46,27 @@ if (!isset($course)) { $tabs = $row = $inactive = $activated = array(); +$pages = $lesson->load_all_pages(); +$pagestoview = False; +$essaysfound = False; +foreach ($pages as $key=>$page) { + if ($page->qtype == LESSON_PAGE_ESSAY) { + $essaysfound = True; + } + + if ($page->prevpageid == 0) { + $pagestoview = True; + } +} + /// user attempt count for reports link hover (completed attempts - much faster) $attemptscount = $DB->count_records('lesson_grades', array('lessonid'=>$lesson->id)); - -$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))); +if ($pagestoview) { + $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))); +} $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))); $row[] = new tabobject('reports', "$CFG->wwwroot/mod/lesson/report.php?id=$cm->id", get_string('reports', 'lesson'), get_string('viewreports2', 'lesson', $attemptscount)); -if (has_capability('mod/lesson:edit', $context)) { +if ($essaysfound and has_capability('mod/lesson:edit', $context)) { $row[] = new tabobject('essay', "$CFG->wwwroot/mod/lesson/essay.php?id=$cm->id", get_string('manualgrading', 'lesson')); } if ($lesson->highscores) { -- 1.8.2.3 From eacfb27fc7806e78fcb98ca345561dd958e5ec5e Mon Sep 17 00:00:00 2001 From: Michael Sands Date: Sun, 15 Sep 2013 15:43:29 +1200 Subject: [PATCH 2/2] Remove error checking as it was not checking anything useful, but was preventing a nicer 'no items found' message. --- mod/lesson/locallib.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/mod/lesson/locallib.php b/mod/lesson/locallib.php index 6c4c9c9..b1c787e 100644 --- a/mod/lesson/locallib.php +++ b/mod/lesson/locallib.php @@ -2725,9 +2725,7 @@ class lesson_page_type_manager { */ public function load_all_pages(lesson $lesson) { global $DB; - if (!($pages =$DB->get_records('lesson_pages', array('lessonid'=>$lesson->id)))) { - #print_error('cannotfindpages', 'lesson'); - } + $pages = $DB->get_records('lesson_pages', array('lessonid'=>$lesson->id)); foreach ($pages as $key=>$page) { $pagetype = get_class($this->types[$page->qtype]); $pages[$key] = new $pagetype($page, $lesson); -- 1.8.2.3