当前位置: 首页>>代码示例>>PHP>>正文


PHP lesson::get_attempts方法代码示例

本文整理汇总了PHP中lesson::get_attempts方法的典型用法代码示例。如果您正苦于以下问题:PHP lesson::get_attempts方法的具体用法?PHP lesson::get_attempts怎么用?PHP lesson::get_attempts使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在lesson的用法示例。


在下文中一共展示了lesson::get_attempts方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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');
 }
开发者ID:vuchannguyen,项目名称:web,代码行数:71,代码来源:renderer.php

示例2: 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 = 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');
 }
开发者ID:mongo0se,项目名称:moodle,代码行数:67,代码来源:renderer.php


注:本文中的lesson::get_attempts方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。