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


PHP completion_info::get_completions方法代码示例

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


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

示例1: get_content

 public function get_content()
 {
     global $USER, $CFG, $DB, $COURSE;
     // If content is cached
     if ($this->content !== NULL) {
         return $this->content;
     }
     // Create empty content
     $this->content = new stdClass();
     // Can edit settings?
     $can_edit = has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $this->page->course->id));
     // Get course completion data
     $info = new completion_info($this->page->course);
     // Don't display if completion isn't enabled!
     if (!completion_info::is_enabled_for_site()) {
         if ($can_edit) {
             $this->content->text = get_string('completionnotenabledforsite', 'completion');
         }
         return $this->content;
     } else {
         if (!$info->is_enabled()) {
             if ($can_edit) {
                 $this->content->text = get_string('completionnotenabledforcourse', 'completion');
             }
             return $this->content;
         }
     }
     // Load criteria to display
     $completions = $info->get_completions($USER->id);
     // Check if this course has any criteria
     if (empty($completions)) {
         if ($can_edit) {
             $this->content->text = get_string('nocriteriaset', 'completion');
         }
         return $this->content;
     }
     // Check this user is enroled
     if (!$info->is_tracked_user($USER->id)) {
         // If not enrolled, but are can view the report:
         if (has_capability('report/completion:view', get_context_instance(CONTEXT_COURSE, $COURSE->id))) {
             $this->content->text = '<a href="' . $CFG->wwwroot . '/report/completion/index.php?course=' . $COURSE->id . '">' . get_string('viewcoursereport', 'completion') . '</a>';
             return $this->content;
         }
         // Otherwise, show error
         $this->content->text = get_string('notenroled', 'completion');
         return $this->content;
     }
     // Generate markup for criteria statuses
     $shtml = '';
     // For aggregating activity completion
     $activities = array();
     $activities_complete = 0;
     // For aggregating course prerequisites
     $prerequisites = array();
     $prerequisites_complete = 0;
     // Flag to set if current completion data is inconsistent with
     // what is stored in the database
     $pending_update = false;
     // Loop through course criteria
     foreach ($completions as $completion) {
         $criteria = $completion->get_criteria();
         $complete = $completion->is_complete();
         if (!$pending_update && $criteria->is_pending($completion)) {
             $pending_update = true;
         }
         // Activities are a special case, so cache them and leave them till last
         if ($criteria->criteriatype == COMPLETION_CRITERIA_TYPE_ACTIVITY) {
             $activities[$criteria->moduleinstance] = $complete;
             if ($complete) {
                 $activities_complete++;
             }
             continue;
         }
         // Prerequisites are also a special case, so cache them and leave them till last
         if ($criteria->criteriatype == COMPLETION_CRITERIA_TYPE_COURSE) {
             $prerequisites[$criteria->courseinstance] = $complete;
             if ($complete) {
                 $prerequisites_complete++;
             }
             continue;
         }
         $shtml .= '<tr><td>';
         $shtml .= $criteria->get_title();
         $shtml .= '</td><td style="text-align: right">';
         $shtml .= $completion->get_status();
         $shtml .= '</td></tr>';
     }
     // Aggregate activities
     if (!empty($activities)) {
         $shtml .= '<tr><td>';
         $shtml .= get_string('activitiescompleted', 'completion');
         $shtml .= '</td><td style="text-align: right">';
         $a = new stdClass();
         $a->first = $activities_complete;
         $a->second = count($activities);
         $shtml .= get_string('firstofsecond', 'block_completionstatus', $a);
         $shtml .= '</td></tr>';
     }
     // Aggregate prerequisites
     if (!empty($prerequisites)) {
//.........这里部分代码省略.........
开发者ID:nutanrajmalanai,项目名称:moodle,代码行数:101,代码来源:block_completionstatus.php

示例2: array

// Load course completion.
$params = array('userid' => $user->id, 'course' => $course->id);
$ccompletion = new completion_completion($params);
if ($coursecomplete) {
    echo get_string('complete');
} else {
    if (!$criteriacomplete && !$ccompletion->timestarted) {
        echo html_writer::tag('i', get_string('notyetstarted', 'completion'));
    } else {
        echo html_writer::tag('i', get_string('inprogress', 'completion'));
    }
}
echo html_writer::end_tag('td');
echo html_writer::end_tag('tr');
// Load criteria to display.
$completions = $info->get_completions($user->id);
// Check if this course has any criteria.
if (empty($completions)) {
    echo html_writer::start_tag('tr');
    echo html_writer::start_tag('td', array('colspan' => '2'));
    echo html_writer::start_tag('br');
    echo $OUTPUT->box(get_string('err_nocriteria', 'completion'), 'noticebox');
    echo html_writer::end_tag('td');
    echo html_writer::end_tag('tr');
    echo html_writer::end_tag('tbody');
    echo html_writer::end_tag('table');
} else {
    echo html_writer::start_tag('tr');
    echo html_writer::start_tag('td', array('colspan' => '2'));
    echo html_writer::tag('b', get_string('required'));
    // Get overall aggregation method.
开发者ID:Jtgadbois,项目名称:Pedadida,代码行数:31,代码来源:details.php

示例3: get_course_completion_status

 /**
  * Get Course completion status
  *
  * @param int $courseid ID of the Course
  * @param int $userid ID of the User
  * @return array of course completion status and warnings
  * @since Moodle 2.9
  * @throws moodle_exception
  */
 public static function get_course_completion_status($courseid, $userid)
 {
     global $CFG, $USER;
     require_once $CFG->libdir . '/grouplib.php';
     $warnings = array();
     $arrayparams = array('courseid' => $courseid, 'userid' => $userid);
     $params = self::validate_parameters(self::get_course_completion_status_parameters(), $arrayparams);
     $course = get_course($params['courseid']);
     $user = core_user::get_user($params['userid'], 'id', MUST_EXIST);
     $context = context_course::instance($course->id);
     self::validate_context($context);
     // Can current user see user's course completion status?
     // This check verifies if completion is enabled because $course is mandatory.
     if (!completion_can_view_data($user->id, $course)) {
         throw new moodle_exception('cannotviewreport');
     }
     // The previous function doesn't check groups.
     if ($user->id != $USER->id) {
         if (!groups_user_groups_visible($course, $user->id)) {
             // We are not in the same group!
             throw new moodle_exception('accessdenied', 'admin');
         }
     }
     $info = new completion_info($course);
     // Check this user is enroled.
     if (!$info->is_tracked_user($user->id)) {
         if ($USER->id == $user->id) {
             throw new moodle_exception('notenroled', 'completion');
         } else {
             throw new moodle_exception('usernotenroled', 'completion');
         }
     }
     $completions = $info->get_completions($user->id);
     if (empty($completions)) {
         throw new moodle_exception('nocriteriaset', 'completion');
     }
     // Load course completion.
     $completionparams = array('userid' => $user->id, 'course' => $course->id);
     $ccompletion = new completion_completion($completionparams);
     $completionrows = array();
     // Loop through course criteria.
     foreach ($completions as $completion) {
         $criteria = $completion->get_criteria();
         $completionrow = array();
         $completionrow['type'] = $criteria->criteriatype;
         $completionrow['title'] = $criteria->get_title();
         $completionrow['status'] = $completion->get_status();
         $completionrow['complete'] = $completion->is_complete();
         $completionrow['timecompleted'] = $completion->timecompleted;
         $completionrow['details'] = $criteria->get_details($completion);
         $completionrows[] = $completionrow;
     }
     $result = array('completed' => $info->is_course_complete($user->id), 'aggregation' => $info->get_aggregation_method(), 'completions' => $completionrows);
     $results = array('completionstatus' => $result, 'warnings' => $warnings);
     return $results;
 }
开发者ID:educakanchay,项目名称:campus,代码行数:65,代码来源:external.php

示例4: get_content

 public function get_content()
 {
     global $USER;
     $rows = array();
     $srows = array();
     $prows = array();
     // If content is cached.
     if ($this->content !== null) {
         return $this->content;
     }
     $course = $this->page->course;
     $context = context_course::instance($course->id);
     // Create empty content.
     $this->content = new stdClass();
     $this->content->text = '';
     $this->content->footer = '';
     // Can edit settings?
     $can_edit = has_capability('moodle/course:update', $context);
     // Get course completion data.
     $info = new completion_info($course);
     // Don't display if completion isn't enabled!
     if (!completion_info::is_enabled_for_site()) {
         if ($can_edit) {
             $this->content->text .= get_string('completionnotenabledforsite', 'completion');
         }
         return $this->content;
     } else {
         if (!$info->is_enabled()) {
             if ($can_edit) {
                 $this->content->text .= get_string('completionnotenabledforcourse', 'completion');
             }
             return $this->content;
         }
     }
     // Load criteria to display.
     $completions = $info->get_completions($USER->id);
     // Check if this course has any criteria.
     if (empty($completions)) {
         if ($can_edit) {
             $this->content->text .= get_string('nocriteriaset', 'completion');
         }
         return $this->content;
     }
     // Check this user is enroled.
     if ($info->is_tracked_user($USER->id)) {
         // Generate markup for criteria statuses.
         $data = '';
         // For aggregating activity completion.
         $activities = array();
         $activities_complete = 0;
         // For aggregating course prerequisites.
         $prerequisites = array();
         $prerequisites_complete = 0;
         // Flag to set if current completion data is inconsistent with what is stored in the database.
         $pending_update = false;
         // Loop through course criteria.
         foreach ($completions as $completion) {
             $criteria = $completion->get_criteria();
             $complete = $completion->is_complete();
             if (!$pending_update && $criteria->is_pending($completion)) {
                 $pending_update = true;
             }
             // Activities are a special case, so cache them and leave them till last.
             if ($criteria->criteriatype == COMPLETION_CRITERIA_TYPE_ACTIVITY) {
                 $activities[$criteria->moduleinstance] = $complete;
                 if ($complete) {
                     $activities_complete++;
                 }
                 continue;
             }
             // Prerequisites are also a special case, so cache them and leave them till last.
             if ($criteria->criteriatype == COMPLETION_CRITERIA_TYPE_COURSE) {
                 $prerequisites[$criteria->courseinstance] = $complete;
                 if ($complete) {
                     $prerequisites_complete++;
                 }
                 continue;
             }
             $row = new html_table_row();
             $row->cells[0] = new html_table_cell($criteria->get_title());
             $row->cells[1] = new html_table_cell($completion->get_status());
             $row->cells[1]->style = 'text-align: right;';
             $srows[] = $row;
         }
         // Aggregate activities.
         if (!empty($activities)) {
             $a = new stdClass();
             $a->first = $activities_complete;
             $a->second = count($activities);
             $row = new html_table_row();
             $row->cells[0] = new html_table_cell(get_string('activitiescompleted', 'completion'));
             $row->cells[1] = new html_table_cell(get_string('firstofsecond', 'block_completionstatus', $a));
             $row->cells[1]->style = 'text-align: right;';
             $srows[] = $row;
         }
         // Aggregate prerequisites.
         if (!empty($prerequisites)) {
             $a = new stdClass();
             $a->first = $prerequisites_complete;
             $a->second = count($prerequisites);
//.........这里部分代码省略.........
开发者ID:alanaipe2015,项目名称:moodle,代码行数:101,代码来源:block_completionstatus.php

示例5: foreach

 $completion = new completion_info($course);
 $trackeduser = $user ? $user : $USER->id;
 if (!$completion->is_enabled()) {
     throw new moodle_exception('completionnotenabled', 'completion');
 } else {
     if (!$completion->is_tracked_user($trackeduser)) {
         throw new moodle_exception('nottracked', 'completion');
     }
 }
 if ($user && $rolec) {
     require_sesskey();
     completion_criteria::factory(array('id' => $rolec, 'criteriatype' => COMPLETION_CRITERIA_TYPE_ROLE));
     //TODO: this is dumb, because it does not fetch the data?!?!
     $criteria = completion_criteria_role::fetch(array('id' => $rolec));
     if ($criteria and user_has_role_assignment($USER->id, $criteria->role, $context->id)) {
         $criteria_completions = $completion->get_completions($user, COMPLETION_CRITERIA_TYPE_ROLE);
         foreach ($criteria_completions as $criteria_completion) {
             if ($criteria_completion->criteriaid == $rolec) {
                 $criteria->complete($criteria_completion);
                 break;
             }
         }
     }
     // Return to previous page
     $referer = clean_param($_SERVER['HTTP_REFERER'], PARAM_LOCALURL);
     if (!empty($referer)) {
         redirect($referer);
     } else {
         redirect('view.php?id=' . $course->id);
     }
 } else {
开发者ID:Keneth1212,项目名称:moodle,代码行数:31,代码来源:togglecompletion.php

示例6: get_content

    public function get_content()
    {
        global $USER, $CFG, $DB, $COURSE;
        if ($this->content !== null) {
            return $this->content;
        }
        $this->content = new stdClass();
        $courses1 = enrol_get_my_courses('', 'visible DESC,sortorder ASC');
        //defined in lib/enrollib.php file
        // Display completion status
        $this->content->text .= '<table cellpadding="0" cellspacing="0" width="178" border="0">';
        $this->content->text .= '<tr>';
        $this->content->text .= '<td width="85" align="right"><b>Total</b>';
        $this->content->text .= '</td><td align="left"><b>Over</b>';
        $this->content->text .= '</td><td align="left"><b>%</b>';
        $this->content->text .= '</td></tr></table>';
        $this->content->text .= '<table cellpadding="0" cellspacing="0" width="178" border="0">';
        foreach ($courses1 as $course1) {
            if ($course1->id == SITEID) {
                continue;
            }
            $userid = optional_param('user', 0, PARAM_INT);
            // Load course
            $course = $DB->get_record('course', array('id' => $course1->id));
            // Load user
            if ($userid) {
                $user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST);
            } else {
                $user = $USER;
            }
            $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
            $personalcontext = get_context_instance(CONTEXT_USER, $user->id);
            $can_view = false;
            // Can view own report
            if ($USER->id == $user->id) {
                $can_view = true;
            } else {
                if (has_capability('moodle/user:viewuseractivitiesreport', $personalcontext)) {
                    $can_view = true;
                } else {
                    if (has_capability('coursereport/completion:view', $coursecontext)) {
                        $can_view = true;
                    } else {
                        if (has_capability('coursereport/completion:view', $personalcontext)) {
                            $can_view = true;
                        }
                    }
                }
            }
            if (!$can_view) {
                $this->content->text .= print_error('cannotviewreport');
            }
            // Load completion data
            $info = new completion_info($course);
            // Load criteria to display
            $completions = $info->get_completions($user->id);
            // Check this user is enroled
            if (!$info->is_tracked_user($user->id)) {
                if ($USER->id == $user->id) {
                    $this->content->text .= print_error('notenroled', 'completion', $returnurl);
                } else {
                    $this->content->text .= print_error('usernotenroled', 'completion', $returnurl);
                }
            }
            // Is course complete?
            $coursecomplete = $info->is_course_complete($user->id);
            // Has this user completed any criteria?
            $criteriacomplete = $info->count_course_user_data($user->id);
            if ($coursecomplete) {
                $status = get_string('complete');
            } else {
                if (!$criteriacomplete) {
                    $status = '<i>' . get_string('notyetstarted', 'completion') . '</i>';
                } else {
                    $status = '<i>' . get_string('inprogress', 'completion') . '</i>';
                }
            }
            //GET TOTAL NUMBER OF TASKS ASSIGNED TO CURRENT USER
            $conditions = array("course" => $course->id);
            $tot_rec = $DB->count_records('course_completion_criteria', $conditions);
            //GET TOTAL NUMBER OF TASKS ASSIGNED TO CURRENT USER
            $result = $DB->get_records_sql('SELECT mc.coursemoduleid,mc.userid,mc.completionstate,
				m.id,m.course FROM `mdl_course_modules_completion` mc 
				LEFT JOIN 
				mdl_course_modules m
				ON
				mc.coursemoduleid=m.id WHERE mc.userid = ? AND m.course = ?', array($user->id, $course->id));
            $tot_comp = count($result);
            $count1 = $tot_comp / $tot_rec;
            $count2 = $count1 * 100;
            $count = number_format($count2, 0);
            $linkhref = new moodle_url('/course/view.php', array('id' => $course->id));
            $this->content->text .= '<tr><td colspan="4"><b title="Course" style="color:#000066;">';
            $this->content->text .= '<a href="' . $linkhref . '">' . $course1->fullname . '</a>';
            $this->content->text .= '</b></td></tr>';
            $this->content->text .= '<tr><td align="left" width="70" title="Activity completion status">';
            //$this->content->text .=$course1->fullname;
            $this->content->text .= $status;
            $this->content->text .= '</td><td align="left" width="27" title="Total activities">' . $tot_rec;
            $this->content->text .= '</td><td width="27" align="left" title="Total Activities completed">' . $tot_comp;
//.........这里部分代码省略.........
开发者ID:nadavkav,项目名称:Moodle2-Hebrew-plugins,代码行数:101,代码来源:block_activity_track.php

示例7: get_targets_by_username


//.........这里部分代码省略.........
         $courses[$core]['course_total_modified'] = $gi_item->timemodified;
         $gg = new grade_grade();
         $gg_grade = $gg::fetch(array('itemid' => $gi_item->id, 'userid' => $user->id));
         // If the scale is going to be a U (or Refer, or Fail etc) as the L3VA is 0, pass null.
         if ($gg_grade && $gg_grade->finalgrade > 0) {
             $courses[$core]['course_total'] = $gg_grade->finalgrade;
             $gs = new grade_scale();
             $gs_scale = $gs::fetch(array('id' => $gi_item->scaleid));
             if ($gi_item->display != 0) {
                 // Check first for a non-zero 'display' variable, and run with that if found.
                 $courses[$core]['course_total_display'] = grade_format_gradevalue($gg_grade->finalgrade, $gi_item, true, $gi_item->display);
             } else {
                 if ($gs_scale) {
                     // See if we have a scale and use that if found.
                     $courses[$core]['course_total_display'] = $gs_scale->get_nearest_item($gg_grade->finalgrade);
                 } else {
                     if (is_numeric($gg_grade->finalgrade)) {
                         $courses[$core]['course_total_display'] = round($courses[$core]['course_total'], 0, PHP_ROUND_HALF_UP);
                     } else {
                         $courses[$core]['course_total_display'] = $courses[$core]['course_total'];
                     }
                 }
             }
         } else {
             $courses[$core]['course_total'] = 0;
             $courses[$core]['course_total_display'] = null;
         }
         // For each target, same as above.
         foreach ($targets as $target) {
             $gi = new grade_item();
             $gi_item = $gi::fetch(array('courseid' => $courses[$core]['course_id'], 'itemtype' => 'manual', 'itemname' => $target));
             $gg = new grade_grade();
             $gg_grade = $gg::fetch(array('itemid' => $gi_item->id, 'userid' => $user->id));
             $courses[$core][strtolower($target)] = $gg_grade->finalgrade;
             // Get the named result (e.g. 'merit') only for targets which are not L3VA.
             if ($target != 'L3VA') {
                 $gs = new grade_scale();
                 $gs_scale = $gs::fetch(array('id' => $gi_item->scaleid));
                 // Updating the most recently modified date if it's newer.
                 if ($gi_item->timemodified > $courses[$core]['course_total_modified']) {
                     $courses[$core]['course_total_modified'] = $gi_item->timemodified;
                 }
                 // If the scale is going to be a U (or Refer, or Fail etc) as the L3VA is 0, pass null.
                 if ($gg_grade->finalgrade > 0) {
                     // If there's no scale, just pass the data across.
                     if ($gs_scale) {
                         $courses[$core][strtolower($target) . '_display'] = $gs_scale->get_nearest_item($gg_grade->finalgrade);
                     } else {
                         $courses[$core][strtolower($target) . '_display'] = $gg_grade->finalgrade;
                     }
                 } else {
                     $courses[$core][strtolower($target) . '_display'] = null;
                 }
             } else {
                 $courses[$core][strtolower($target) . '_display'] = $courses[$core][strtolower($target)];
             }
             // Rounding.
             if (is_numeric($courses[$core][strtolower($target) . '_display'])) {
                 $courses[$core][strtolower($target) . '_display'] = round($courses[$core][strtolower($target) . '_display'], 2, PHP_ROUND_HALF_UP);
             }
         }
         // Default both of these to null.
         $courses[$core]['course_completion_total'] = null;
         $courses[$core]['course_completion_completed'] = null;
         // We could do with a course object to use.
         $sql = "SELECT id from {course} WHERE id LIKE ?;";
         if (!($thiscourse = $DB->get_record_sql($sql, array($courses[$core]['course_id'])))) {
             exit(1);
         }
         if (completion_info::is_enabled_for_site()) {
             $info = new completion_info($thiscourse);
             $completions = $info->get_completions($user->id);
             // If there's no completions, none have been configured so do nothing.
             if (!empty($completions)) {
                 $courses[$core]['course_completion_total'] = count($completions);
                 $courses[$core]['course_completion_completed'] = $info->count_course_user_data($user->id);
                 // Loop through each timecompleted value, ignore if null, update if more recent.
                 foreach ($completions as $completion) {
                     if (!is_null($completion->timecompleted) && $completion->timecompleted > $courses[$core]['course_total_modified']) {
                         $courses[$core]['course_total_modified'] = $completion->timecompleted;
                     }
                 }
             }
         }
         // END completion info enabled for site check.
         // Stress reduction code.
         $courses[$core]['meaning_of_life'] = '42';
         $courses[$core]['smiley_face'] = ':)';
         // Incomplete course check.
         // TODO: make this better. We scan through all four 'leapcore_' tags (and all the new A2 ones) and get the results,
         // but sometimes there aren't any.  So for the tags with no associated courses, we remove them.
         if (!isset($courses[$core]['course_shortname'])) {
             unset($courses[$core]);
         }
     }
     // END foreach $courses.
     if (!empty($courses)) {
         return $courses;
     }
 }
开发者ID:briancrocker81,项目名称:moodle-local_leapwebservices,代码行数:101,代码来源:externallib.php


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