/** * Returns an array of options to display when choosing the jumpto for a page/answer * @static * @param int $pageid * @param lesson $lesson * @return array */ public static function get_jumptooptions($pageid, lesson $lesson) { global $DB; $jump = array(); $jump[0] = get_string("thispage", "lesson"); $jump[LESSON_NEXTPAGE] = get_string("nextpage", "lesson"); $jump[LESSON_PREVIOUSPAGE] = get_string("previouspage", "lesson"); $jump[LESSON_EOL] = get_string("endoflesson", "lesson"); if ($pageid == 0) { return $jump; } $pages = $lesson->load_all_pages(); if ($pages[$pageid]->qtype == LESSON_PAGE_BRANCHTABLE || $lesson->is_sub_page_of_type($pageid, array(LESSON_PAGE_BRANCHTABLE), array(LESSON_PAGE_ENDOFBRANCH, LESSON_PAGE_CLUSTER))) { $jump[LESSON_UNSEENBRANCHPAGE] = get_string("unseenpageinbranch", "lesson"); $jump[LESSON_RANDOMPAGE] = get_string("randompageinbranch", "lesson"); } if ($pages[$pageid]->qtype == LESSON_PAGE_CLUSTER || $lesson->is_sub_page_of_type($pageid, array(LESSON_PAGE_CLUSTER), array(LESSON_PAGE_ENDOFCLUSTER))) { $jump[LESSON_CLUSTERJUMP] = get_string("clusterjump", "lesson"); } if (!optional_param('firstpage', 0, PARAM_INT)) { $apageid = $DB->get_field("lesson_pages", "id", array("lessonid" => $lesson->id, "prevpageid" => 0)); while (true) { if ($apageid) { $title = $DB->get_field("lesson_pages", "title", array("id" => $apageid)); $jump[$apageid] = strip_tags(format_string($title, true)); $apageid = $DB->get_field("lesson_pages", "nextpageid", array("id" => $apageid)); } else { // last page reached break; } } } return $jump; }
/** * Returns HTML to display a progress bar of progression through a lesson * * @param lesson $lesson * @return string */ public function progress_bar(lesson $lesson) { global $CFG, $USER, $DB; $context = context_module::instance($this->page->cm->id); // lesson setting to turn progress bar on or off if (!$lesson->progressbar) { return ''; } // catch teachers if (has_capability('mod/lesson:manage', $context)) { return $this->output->notification(get_string('progressbarteacherwarning2', 'lesson')); } if (!isset($USER->modattempts[$lesson->id])) { // all of the lesson pages $pages = $lesson->load_all_pages(); foreach ($pages as $page) { if ($page->prevpageid == 0) { $pageid = $page->id; // find the first page id break; } } // current attempt number if (!($ntries = $DB->count_records("lesson_grades", array("lessonid" => $lesson->id, "userid" => $USER->id)))) { $ntries = 0; // may not be necessary } $viewedpageids = array(); if ($attempts = $lesson->get_attempts($ntries, false)) { foreach ($attempts as $attempt) { $viewedpageids[$attempt->pageid] = $attempt; } } $viewedbranches = array(); // collect all of the branch tables viewed if ($branches = $DB->get_records("lesson_branch", array("lessonid" => $lesson->id, "userid" => $USER->id, "retry" => $ntries), 'timeseen ASC', 'id, pageid')) { foreach ($branches as $branch) { $viewedbranches[$branch->pageid] = $branch; } $viewedpageids = array_merge($viewedpageids, $viewedbranches); } // Filter out the following pages: // End of Cluster // End of Branch // Pages found inside of Clusters // Do not filter out Cluster Page(s) because we count a cluster as one. // By keeping the cluster page, we get our 1 $validpages = array(); while ($pageid != 0) { $pageid = $pages[$pageid]->valid_page_and_view($validpages, $viewedpageids); } // progress calculation as a percent $progress = round(count($viewedpageids) / count($validpages), 2) * 100; } else { $progress = 100; } // print out the Progress Bar. Attempted to put as much as possible in the style sheets. $content = '<br />' . html_writer::tag('div', $progress . '%', array('class' => 'progress_bar_completed', 'style' => 'width: ' . $progress . '%;')); $printprogress = html_writer::tag('div', get_string('progresscompleted', 'lesson', $progress) . $content, array('class' => 'progress_bar')); return $this->output->box($printprogress, 'progress_bar'); }
/** * Returns HTML to display a progress bar of progression through a lesson * * @param lesson $lesson * @return string */ public function progress_bar(lesson $lesson) { global $CFG, $USER, $DB; $context = get_context_instance(CONTEXT_MODULE, $this->page->cm->id); // lesson setting to turn progress bar on or off if (!$lesson->progressbar) { return ''; } // catch teachers if (has_capability('mod/lesson:manage', $context)) { return $this->output->notification(get_string('progressbarteacherwarning2', 'lesson')); } if (!isset($USER->modattempts[$lesson->id])) { // all of the lesson pages $pages = $lesson->load_all_pages(); foreach ($pages as $page) { if ($page->prevpageid == 0) { $pageid = $page->id; // find the first page id break; } } // current attempt number if (!($ntries = $DB->count_records("lesson_grades", array("lessonid" => $lesson->id, "userid" => $USER->id)))) { $ntries = 0; // may not be necessary } $viewedpageids = array(); if ($attempts = $lesson->get_attempts($ntries, true)) { $viewedpageids = array_merge($viewedpageids, array_keys($attempts)); } // collect all of the branch tables viewed if ($viewedbranches = $DB->get_records("lesson_branch", array("lessonid" => $lesson->id, "userid" => $USER->id, "retry" => $ntries), 'timeseen DESC', 'id, pageid')) { $viewedpageids = array_merge($viewedpageids, array_keys($viewedbranches)); } // Filter out the following pages: // End of Cluster // End of Branch // Pages found inside of Clusters // Do not filter out Cluster Page(s) because we count a cluster as one. // By keeping the cluster page, we get our 1 $validpages = array(); while ($pageid != 0) { $pageid = $pages[$pageid]->valid_page_and_view($validpages, $viewedpageids); } // progress calculation as a percent $progress = round(count($viewedpageids) / count($validpages), 2) * 100; } else { $progress = 100; } // print out the Progress Bar. Attempted to put as much as possible in the style sheets. $cells = array(); if ($progress != 0) { // some browsers do not repsect the 0 width. $cells[0] = new html_table_cell(); $cells[0]->style = 'width:' . $progress . '%'; $cells[0]->attributes['class'] = 'progress_bar_completed'; $cells[0]->text = ' '; } $cells[] = '<div class="progress_bar_token"></div>'; $table = new html_table(); $table->attributes['class'] = 'progress_bar_table'; $table->data = array(new html_table_row($cells)); return $this->output->box(html_writer::table($table), 'progress_bar'); }
/** * Returns progress percentage of courses which will be displayed in course_overview block * Autor : GalaxyWebLinks * * @param bool $course and $USER of current user. * @return int progress percentage of courses */ function get_course_progress_percentage($course, $USER) { global $DB, $CFG; require_once $CFG->dirroot . '/mod/lesson/locallib.php'; $progress = 0; $lessions = $DB->get_record("lesson", array("course" => $course->id)); $lessonid = $lessions->id; $courseshown = $course->id; if ($lessonid) { if (!isset($USER->modattempts[$lessonid])) { $lesson = new lesson($DB->get_record('lesson', array('id' => $lessonid), '*', MUST_EXIST)); $pages = $lesson->load_all_pages($lesson); foreach ($pages as $page) { if ($page->prevpageid == 0) { $pageid = $page->id; // find the first page id break; } } // current attempt number if (!($ntries = $DB->count_records("lesson_grades", array("lessonid" => $lessonid, "userid" => $USER->id)))) { $ntries = 0; // may not be necessary } $viewedpageids = array(); if ($attempts = $lesson->get_attempts($ntries, false)) { foreach ($attempts as $attempt) { $viewedpageids[$attempt->pageid] = $attempt; } } $branches = $DB->get_records("lesson_branch", array("lessonid" => $lessonid, "userid" => $USER->id, "retry" => $ntries), 'timeseen ASC', 'id, pageid'); $viewedbranches = array(); foreach ($branches as $branch) { $viewedbranches[$branch->pageid] = $branch; } $viewedpageids = array_merge($viewedpageids, $viewedbranches); $validpages = array(); while ($pageid != 0) { $pageid = $pages[$pageid]->valid_page_and_view($validpages, $viewedpageids); } $progress = round(count($viewedpageids) / count($validpages), 2) * 100; } else { $progress = 100; } } return $progress; }