本文整理汇总了PHP中completion_info::update_state方法的典型用法代码示例。如果您正苦于以下问题:PHP completion_info::update_state方法的具体用法?PHP completion_info::update_state怎么用?PHP completion_info::update_state使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类completion_info
的用法示例。
在下文中一共展示了completion_info::update_state方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: update_activity_completion_status_manually
/**
* Update completion status for the current user in an activity, only for activities with manual tracking.
* @param int $cmid Course module id
* @param bool $completed Activity completed or not
* @return array Result and possible warnings
* @since Moodle 2.9
* @throws moodle_exception
*/
public static function update_activity_completion_status_manually($cmid, $completed)
{
// Validate and normalize parameters.
$params = self::validate_parameters(self::update_activity_completion_status_manually_parameters(), array('cmid' => $cmid, 'completed' => $completed));
$cmid = $params['cmid'];
$completed = $params['completed'];
$warnings = array();
$context = context_module::instance($cmid);
self::validate_context($context);
list($course, $cm) = get_course_and_cm_from_cmid($cmid);
// Set up completion object and check it is enabled.
$completion = new completion_info($course);
if (!$completion->is_enabled()) {
throw new moodle_exception('completionnotenabled', 'completion');
}
// Check completion state is manual.
if ($cm->completion != COMPLETION_TRACKING_MANUAL) {
throw new moodle_exception('cannotmanualctrack', 'error');
}
$targetstate = $completed ? COMPLETION_COMPLETE : COMPLETION_INCOMPLETE;
$completion->update_state($cm, $targetstate);
$result = array();
$result['status'] = true;
$result['warnings'] = $warnings;
return $result;
}
示例2: execute
public function execute()
{
global $DB, $CFG;
$result = $DB->get_records_sql('SELECT ba.id, ba.bookingid, ba.optionid, ba.userid, b.course
FROM {booking_answers} AS ba
LEFT JOIN {booking_options} AS bo
ON bo.id = ba.optionid
LEFT JOIN {booking} AS b
ON b.id = bo.bookingid
WHERE bo.removeafterminutes > 0
AND ba.completed = 1
AND IF(ba.timemodified < (UNIX_TIMESTAMP() - (bo.removeafterminutes*60)), 1, 0) = 1;');
require_once $CFG->libdir . '/completionlib.php';
foreach ($result as $value) {
$course = $DB->get_record('course', array('id' => $value->course));
$completion = new \completion_info($course);
$cm = get_coursemodule_from_instance('booking', $value->bookingid);
$userData = $DB->get_record('booking_answers', array('id' => $value->id));
$booking = $DB->get_record('booking', array('id' => $value->bookingid));
$userData->completed = '0';
$userData->timemodified = time();
$DB->update_record('booking_answers', $userData);
if ($completion->is_enabled($cm) && $booking->enablecompletion) {
$completion->update_state($cm, COMPLETION_INCOMPLETE, $userData->userid);
}
}
}
示例3: mod_stopwatch_update_timer
/**
*
* @param cm_info $cm
* @param stdClass $stopwatch
* @param int $duration
*/
function mod_stopwatch_update_timer(cm_info $cm, $stopwatch, $duration)
{
global $USER, $DB, $CFG;
require_once $CFG->libdir . '/completionlib.php';
$record = $DB->get_record('stopwatch_user', array('stopwatchid' => $cm->instance, 'courseid' => $cm->course, 'userid' => $USER->id));
if ($record) {
$data = array('id' => $record->id, 'timemodified' => time(), 'duration' => $duration);
$DB->update_record('stopwatch_user', $data);
} else {
$data = array('courseid' => $cm->course, 'stopwatchid' => $cm->instance, 'userid' => $USER->id, 'timecreated' => time(), 'timemodified' => time(), 'duration' => $duration);
$DB->insert_record('stopwatch_user', $data);
}
// Update completion state
$completion = new completion_info($cm->get_course());
if ($completion->is_enabled($cm) && $stopwatch->completiontimed) {
$completion->update_state($cm, COMPLETION_COMPLETE);
}
}
示例4: update_require_specific_grade
/**
* Updates activity completion status.
*
* @return void
*/
public static function update_require_specific_grade(\core\event\base $event)
{
global $DB;
$entryuserid = $event->relateduserid;
$giid = $event->other['itemid'];
if (!($gitem = \grade_item::fetch(array('id' => $giid, 'itemmodule' => 'dataform')))) {
return;
}
$dataformid = $gitem->iteminstance;
$df = \mod_dataform_dataform::instance($dataformid);
// Currently only completion by require entries.
if ($df->completionspecificgrade) {
$completion = new \completion_info($df->course);
if ($completion->is_enabled($df->cm) != COMPLETION_TRACKING_AUTOMATIC) {
return;
}
$completion->update_state($df->cm, COMPLETION_UNKNOWN, $entryuserid);
}
}
示例5: checklist_update_grades
//.........这里部分代码省略.........
foreach ($items as $item) {
if ($item->grouping) {
if (!in_array($item->grouping, $groupings)) {
continue;
}
}
$itemlist .= $item->id . ',';
$total++;
}
if (!$total) {
// No items - set score to 0
$ugrade = new stdClass();
$ugrade->userid = $userid;
$ugrade->rawgrade = 0;
$ugrade->date = time();
} else {
$itemlist = substr($itemlist, 0, -1);
// Remove trailing ','
$sql = 'SELECT ? AS userid, (SUM(CASE WHEN ' . $where . ' THEN 1 ELSE 0 END) * ? / ? ) AS rawgrade' . $date;
$sql .= " FROM {checklist_check} c ";
$sql .= " WHERE c.item IN ({$itemlist})";
$sql .= ' AND c.userid = ? ';
$ugrade = $DB->get_record_sql($sql, array($userid, $checklist->maxgrade, $total, $userid));
if (!$ugrade) {
$ugrade = new stdClass();
$ugrade->userid = $userid;
$ugrade->rawgrade = 0;
$ugrade->date = time();
}
}
$ugrade->firstname = $user->firstname;
$ugrade->lastname = $user->lastname;
$grades[$userid] = $ugrade;
}
} else {
// No need to check groupings, so update all student grades at once
if ($userid) {
$users = $userid;
} else {
if ($CFG->version < 2011120100) {
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
} else {
$context = context_module::instance($cm->id);
}
if (!($users = get_users_by_capability($context, 'mod/checklist:updateown', 'u.id', '', '', '', '', '', false))) {
return;
}
$users = array_keys($users);
}
$total = count($items);
list($usql, $uparams) = $DB->get_in_or_equal($users);
list($isql, $iparams) = $DB->get_in_or_equal(array_keys($items));
$sql = 'SELECT u.id AS userid, (SUM(CASE WHEN ' . $where . ' THEN 1 ELSE 0 END) * ? / ? ) AS rawgrade' . $date;
$sql .= ' , u.firstname, u.lastname ';
$sql .= ' FROM {user} u LEFT JOIN {checklist_check} c ON u.id = c.userid';
$sql .= " WHERE u.id {$usql}";
$sql .= " AND c.item {$isql}";
$sql .= ' GROUP BY u.id, u.firstname, u.lastname';
$params = array_merge($uparams, $iparams);
$params = array_merge(array($checklist->maxgrade, $total), $params);
$grades = $DB->get_records_sql($sql, $params);
}
foreach ($grades as $grade) {
// Log completion of checklist
if ($grade->rawgrade == $checklist->maxgrade) {
if ($checklist->emailoncomplete) {
$timelimit = time() - 1 * 60 * 60;
// Do not send another email if this checklist was already 'completed' in the last hour
$filter = "l.time > ? AND l.cmid = ? AND l.userid = ? AND l.action = 'complete'";
get_logs($filter, array($timelimit, $cm->id, $grade->userid), '', 1, 1, $logcount);
if ($logcount == 0) {
if (!isset($context)) {
if ($CFG->version < 2011120100) {
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
} else {
$context = context_module::instance($cm->id);
}
}
if ($recipients = get_users_by_capability($context, 'mod/checklist:emailoncomplete', 'u.*', '', '', '', '', '', false)) {
foreach ($recipients as $recipient) {
$details = new stdClass();
$details->user = fullname($grade);
$details->checklist = s($checklist->name);
$subj = get_string('emailoncompletesubject', 'checklist', $details);
$content = get_string('emailoncompletebody', 'checklist', $details);
$content .= $CFG->wwwroot . '/mod/checklist/view.php?id=' . $cm->id;
email_to_user($recipient, $grade, $subj, $content, '', '', '', false);
}
}
}
}
add_to_log($checklist->course, 'checklist', 'complete', "view.php?id={$cm->id}", $checklist->name, $cm->id, $grade->userid);
}
$ci = new completion_info($course);
if ($cm->completion == COMPLETION_TRACKING_AUTOMATIC) {
$ci->update_state($cm, COMPLETION_UNKNOWN, $grade->userid);
}
}
checklist_grade_item_update($checklist, $grades);
}
示例6: array
require_course_login($course, false, $cm);
if (!($choice = choice_get_choice($cm->instance))) {
print_error('invalidcoursemodule');
}
$strchoice = get_string('modulename', 'choice');
$strchoices = get_string('modulenameplural', 'choice');
$context = context_module::instance($cm->id);
list($choiceavailable, $warnings) = choice_get_availability_status($choice);
if ($action == 'delchoice' and confirm_sesskey() and is_enrolled($context, NULL, 'mod/choice:choose') and $choice->allowupdate and $choiceavailable) {
$answercount = $DB->count_records('choice_answers', array('choiceid' => $choice->id, 'userid' => $USER->id));
if ($answercount > 0) {
$DB->delete_records('choice_answers', array('choiceid' => $choice->id, 'userid' => $USER->id));
// Update completion state
$completion = new completion_info($course);
if ($completion->is_enabled($cm) && $choice->completionsubmit) {
$completion->update_state($cm, COMPLETION_INCOMPLETE);
}
redirect("view.php?id={$cm->id}");
}
}
$PAGE->set_title($choice->name);
$PAGE->set_heading($course->fullname);
/// Submit any new data if there is any
if (data_submitted() && is_enrolled($context, NULL, 'mod/choice:choose') && confirm_sesskey()) {
$timenow = time();
if (has_capability('mod/choice:deleteresponses', $context) && $action == 'delete') {
//some responses need to be deleted
choice_delete_responses($attemptids, $choice, $cm, $course);
//delete responses.
redirect("view.php?id={$cm->id}");
}
示例7: stdClass
$context = context_module::instance($cm->id);
require_capability('mod/glossary:approve', $context);
if ($newstate != $entry->approved && confirm_sesskey()) {
$newentry = new stdClass();
$newentry->id = $entry->id;
$newentry->approved = $newstate;
$newentry->timemodified = time();
// wee need this date here to speed up recent activity, TODO: use timestamp in approved field instead in 2.0
$DB->update_record("glossary_entries", $newentry);
// Trigger event about entry approval/disapproval.
$params = array('context' => $context, 'objectid' => $entry->id);
if ($newstate) {
$event = \mod_glossary\event\entry_approved::create($params);
} else {
$event = \mod_glossary\event\entry_disapproved::create($params);
}
$entry->approved = $newstate ? 1 : 0;
$entry->timemodified = $newentry->timemodified;
$event->add_record_snapshot('glossary_entries', $entry);
$event->trigger();
// Update completion state
$completion = new completion_info($course);
if ($completion->is_enabled($cm) == COMPLETION_TRACKING_AUTOMATIC && $glossary->completionentries) {
$completion->update_state($cm, COMPLETION_COMPLETE, $entry->userid);
}
// Reset caches.
if ($entry->usedynalink) {
\mod_glossary\local\concept_cache::reset_glossary($glossary);
}
}
redirect("view.php?id={$cm->id}&mode={$mode}&hook={$hook}");
示例8: facetoface_archive_completion
/**
* Removes grades and resets completion
*
* @global object $CFG
* @global object $DB
* @param int $userid
* @param int $courseid
* @return boolean
*/
function facetoface_archive_completion($userid, $courseid) {
global $DB, $CFG;
require_once($CFG->libdir . '/completionlib.php');
$course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
$completion = new completion_info($course);
// All face to face with this course and user
$sql = "SELECT f.*
FROM {facetoface} f
WHERE f.course = :courseid
AND EXISTS (SELECT su.id
FROM {facetoface_sessions} s
JOIN {facetoface_signups} su ON su.sessionid = s.id AND su.userid = :userid
WHERE s.facetoface = f.id)";
$facetofaces = $DB->get_records_sql($sql, array('courseid' => $courseid, 'userid' => $userid));
foreach ($facetofaces as $facetoface) {
// Add an archive flag
$params = array('facetofaceid' => $facetoface->id, 'userid' => $userid, 'archived' => 1, 'archived2' => 1);
$sql = "UPDATE {facetoface_signups}
SET archived = :archived
WHERE userid = :userid
AND archived <> :archived2
AND EXISTS (SELECT {facetoface_sessions}.id
FROM {facetoface_sessions}
WHERE {facetoface_sessions}.id = {facetoface_signups}.sessionid
AND {facetoface_sessions}.facetoface = :facetofaceid)";
$DB->execute($sql, $params);
// Reset the grades
facetoface_update_grades($facetoface, $userid, true);
// Set completion to incomplete
// Reset viewed
$course_module = get_coursemodule_from_instance('facetoface', $facetoface->id, $courseid);
$completion->set_module_viewed_reset($course_module, $userid);
// And reset completion, in case viewed is not a required condition
$completion->update_state($course_module, COMPLETION_INCOMPLETE, $userid);
$completion->invalidatecache($courseid, $userid, true);
}
}
示例9: forum_delete_post
/**
* Deletes a single forum post.
*
* @global object
* @param object $post Forum post object
* @param mixed $children Whether to delete children. If false, returns false
* if there are any children (without deleting the post). If true,
* recursively deletes all children. If set to special value 'ignore', deletes
* post regardless of children (this is for use only when deleting all posts
* in a disussion).
* @param object $course Course
* @param object $cm Course-module
* @param object $forum Forum
* @param bool $skipcompletion True to skip updating completion state if it
* would otherwise be updated, i.e. when deleting entire forum anyway.
* @return bool
*/
function forum_delete_post($post, $children, $course, $cm, $forum, $skipcompletion = false)
{
global $DB, $CFG, $USER;
require_once $CFG->libdir . '/completionlib.php';
$context = context_module::instance($cm->id);
if ($children !== 'ignore' && ($childposts = $DB->get_records('forum_posts', array('parent' => $post->id)))) {
if ($children) {
foreach ($childposts as $childpost) {
forum_delete_post($childpost, true, $course, $cm, $forum, $skipcompletion);
}
} else {
return false;
}
}
// Delete ratings.
require_once $CFG->dirroot . '/rating/lib.php';
$delopt = new stdClass();
$delopt->contextid = $context->id;
$delopt->component = 'mod_forum';
$delopt->ratingarea = 'post';
$delopt->itemid = $post->id;
$rm = new rating_manager();
$rm->delete_ratings($delopt);
// Delete attachments.
$fs = get_file_storage();
$fs->delete_area_files($context->id, 'mod_forum', 'attachment', $post->id);
$fs->delete_area_files($context->id, 'mod_forum', 'post', $post->id);
// Delete cached RSS feeds.
if (!empty($CFG->enablerssfeeds)) {
require_once $CFG->dirroot . '/mod/forum/rsslib.php';
forum_rss_delete_file($forum);
}
if ($DB->delete_records("forum_posts", array("id" => $post->id))) {
forum_tp_delete_read_records(-1, $post->id);
// Just in case we are deleting the last post
forum_discussion_update_last_post($post->discussion);
// Update completion state if we are tracking completion based on number of posts
// But don't bother when deleting whole thing
if (!$skipcompletion) {
$completion = new completion_info($course);
if ($completion->is_enabled($cm) == COMPLETION_TRACKING_AUTOMATIC && ($forum->completiondiscussions || $forum->completionreplies || $forum->completionposts)) {
$completion->update_state($cm, COMPLETION_INCOMPLETE, $post->userid);
}
}
$params = array('context' => $context, 'objectid' => $post->id, 'other' => array('discussionid' => $post->discussion, 'forumid' => $forum->id, 'forumtype' => $forum->type));
if ($post->userid !== $USER->id) {
$params['relateduserid'] = $post->userid;
}
$event = \mod_forum\event\post_deleted::create($params);
$event->add_record_snapshot('forum_posts', $post);
$event->trigger();
return true;
}
return false;
}
示例10: add_discussion
//.........这里部分代码省略.........
'groupid' => $groupid,
'options' => $options
));
// Validate options.
$options = array(
'discussionsubscribe' => true
);
foreach ($params['options'] as $option) {
$name = trim($option['name']);
switch ($name) {
case 'discussionsubscribe':
$value = clean_param($option['value'], PARAM_BOOL);
break;
default:
throw new moodle_exception('errorinvalidparam', 'webservice', '', $name);
}
$options[$name] = $value;
}
$warnings = array();
// Request and permission validation.
$forum = $DB->get_record('forum', array('id' => $params['forumid']), '*', MUST_EXIST);
list($course, $cm) = get_course_and_cm_from_instance($forum, 'forum');
$context = context_module::instance($cm->id);
self::validate_context($context);
// Normalize group.
if (!groups_get_activity_groupmode($cm)) {
// Groups not supported, force to -1.
$groupid = -1;
} else {
// Check if we receive the default or and empty value for groupid,
// in this case, get the group for the user in the activity.
if ($groupid === -1 or empty($params['groupid'])) {
$groupid = groups_get_activity_group($cm);
} else {
// Here we rely in the group passed, forum_user_can_post_discussion will validate the group.
$groupid = $params['groupid'];
}
}
if (!forum_user_can_post_discussion($forum, $groupid, -1, $cm, $context)) {
throw new moodle_exception('cannotcreatediscussion', 'forum');
}
$thresholdwarning = forum_check_throttling($forum, $cm);
forum_check_blocking_threshold($thresholdwarning);
// Create the discussion.
$discussion = new stdClass();
$discussion->course = $course->id;
$discussion->forum = $forum->id;
$discussion->message = $params['message'];
$discussion->messageformat = FORMAT_HTML; // Force formatting for now.
$discussion->messagetrust = trusttext_trusted($context);
$discussion->itemid = 0;
$discussion->groupid = $groupid;
$discussion->mailnow = 0;
$discussion->subject = $params['subject'];
$discussion->name = $discussion->subject;
$discussion->timestart = 0;
$discussion->timeend = 0;
if ($discussionid = forum_add_discussion($discussion)) {
$discussion->id = $discussionid;
// Trigger events and completion.
$params = array(
'context' => $context,
'objectid' => $discussion->id,
'other' => array(
'forumid' => $forum->id,
)
);
$event = \mod_forum\event\discussion_created::create($params);
$event->add_record_snapshot('forum_discussions', $discussion);
$event->trigger();
$completion = new completion_info($course);
if ($completion->is_enabled($cm) &&
($forum->completiondiscussions || $forum->completionposts)) {
$completion->update_state($cm, COMPLETION_COMPLETE);
}
$settings = new stdClass();
$settings->discussionsubscribe = $options['discussionsubscribe'];
forum_post_subscription($settings, $forum, $discussion);
} else {
throw new moodle_exception('couldnotadd', 'forum');
}
$result = array();
$result['discussionid'] = $discussionid;
$result['warnings'] = $warnings;
return $result;
}
示例11: glossary_edit_entry
//.........这里部分代码省略.........
$isnewentry = false;
}
$entry->concept = trim($entry->concept);
$entry->definition = ''; // Updated later.
$entry->definitionformat = FORMAT_HTML; // Updated later.
$entry->definitiontrust = 0; // Updated later.
$entry->timemodified = $timenow;
$entry->approved = 0;
$entry->usedynalink = isset($entry->usedynalink) ? $entry->usedynalink : 0;
$entry->casesensitive = isset($entry->casesensitive) ? $entry->casesensitive : 0;
$entry->fullmatch = isset($entry->fullmatch) ? $entry->fullmatch : 0;
if ($glossary->defaultapproval or has_capability('mod/glossary:approve', $context)) {
$entry->approved = 1;
}
if ($isnewentry) {
// Add new entry.
$entry->id = $DB->insert_record('glossary_entries', $entry);
} else {
// Update existing entry.
$DB->update_record('glossary_entries', $entry);
}
// Save and relink embedded images and save attachments.
if (!empty($entry->definition_editor)) {
$entry = file_postupdate_standard_editor($entry, 'definition', $definitionoptions, $context, 'mod_glossary', 'entry',
$entry->id);
}
if (!empty($entry->attachment_filemanager)) {
$entry = file_postupdate_standard_filemanager($entry, 'attachment', $attachmentoptions, $context, 'mod_glossary',
'attachment', $entry->id);
}
// Store the updated value values.
$DB->update_record('glossary_entries', $entry);
// Refetch complete entry.
$entry = $DB->get_record('glossary_entries', array('id' => $entry->id));
// Update entry categories.
$DB->delete_records('glossary_entries_categories', array('entryid' => $entry->id));
// TODO: this deletes cats from both both main and secondary glossary :-(.
if (!empty($categories) and array_search(0, $categories) === false) {
foreach ($categories as $catid) {
$newcategory = new stdClass();
$newcategory->entryid = $entry->id;
$newcategory->categoryid = $catid;
$DB->insert_record('glossary_entries_categories', $newcategory, false);
}
}
// Update aliases.
$DB->delete_records('glossary_alias', array('entryid' => $entry->id));
if ($aliases !== '') {
$aliases = explode("\n", $aliases);
foreach ($aliases as $alias) {
$alias = trim($alias);
if ($alias !== '') {
$newalias = new stdClass();
$newalias->entryid = $entry->id;
$newalias->alias = $alias;
$DB->insert_record('glossary_alias', $newalias, false);
}
}
}
// Trigger event and update completion (if entry was created).
$eventparams = array(
'context' => $context,
'objectid' => $entry->id,
'other' => array('concept' => $entry->concept)
);
if ($isnewentry) {
$event = \mod_glossary\event\entry_created::create($eventparams);
} else {
$event = \mod_glossary\event\entry_updated::create($eventparams);
}
$event->add_record_snapshot('glossary_entries', $entry);
$event->trigger();
if ($isnewentry) {
// Update completion state.
$completion = new completion_info($course);
if ($completion->is_enabled($cm) == COMPLETION_TRACKING_AUTOMATIC && $glossary->completionentries && $entry->approved) {
$completion->update_state($cm, COMPLETION_COMPLETE);
}
}
// Reset caches.
if ($isnewentry) {
if ($entry->usedynalink and $entry->approved) {
\mod_glossary\local\concept_cache::reset_glossary($glossary);
}
} else {
// So many things may affect the linking, let's just purge the cache always on edit.
\mod_glossary\local\concept_cache::reset_glossary($glossary);
}
return $entry;
}
示例12: booking_activitycompletion
function booking_activitycompletion($selectedusers, $booking, $cmid, $optionid)
{
global $DB;
$course = $DB->get_record('course', array('id' => $booking->course));
$completion = new completion_info($course);
$cm = get_coursemodule_from_id('booking', $cmid, 0, false, MUST_EXIST);
foreach ($selectedusers as $ui) {
$userData = $DB->get_record('booking_answers', array('optionid' => $optionid, 'userid' => $ui));
if ($userData->completed == '1') {
$userData->completed = '0';
$userData->timemodified = time();
$DB->update_record('booking_answers', $userData);
if ($completion->is_enabled($cm) && $booking->enablecompletion) {
$completion->update_state($cm, COMPLETION_INCOMPLETE, $ui);
}
} else {
$userData->completed = '1';
$userData->timemodified = time();
$DB->update_record('booking_answers', $userData);
if ($completion->is_enabled($cm) && $booking->enablecompletion) {
$completion->update_state($cm, COMPLETION_COMPLETE, $ui);
}
}
}
}
示例13: can_issue
/**
* Verify if user meet issue conditions
*
* @param int $userid User id
* @return string null if user meet issued conditions, or an text with erro
*/
protected function can_issue($user = null, $chkcompletation = true)
{
global $DB, $USER, $CFG;
if (empty($user)) {
$user = $USER;
}
if (has_capability('mod/simplecertificate:manage', $this->context, $user)) {
return get_string('cantissue', 'simplecertificate');
}
if ($chkcompletation) {
$completion = new completion_info($this->course);
if ($completion->is_enabled($this->coursemodule) && $this->get_instance()->requiredtime) {
if ($this->get_course_time($user) < $this->get_instance()->requiredtime) {
$a = new stdClass();
$a->requiredtime = $this->get_instance()->requiredtime;
return get_string('requiredtimenotmet', 'simplecertificate', $a);
}
// Mark as complete
$completion->update_state($this->coursemodule, COMPLETION_COMPLETE, $user->id);
}
if ($CFG->enableavailability) {
$modinfo = get_fast_modinfo($this->get_course());
$cm = $modinfo->get_cm($this->get_course_module()->id);
if (!$cm->uservisible) {
if ($cm->availableinfo) {
return $cm->availableinfo;
} else {
return get_string('cantissue', 'simplecertificate');
}
}
return null;
}
}
}
示例14: update_timer
/**
* Updates the timer to the current time and returns the new timer object
* @param bool $restart If set to true the timer is restarted
* @param bool $continue If set to true AND $restart=true then the timer
* will continue from a previous attempt
* @return stdClass The new timer
*/
public function update_timer($restart = false, $continue = false, $endreached = false)
{
global $USER, $DB;
$cm = get_coursemodule_from_instance('lesson', $this->properties->id, $this->properties->course);
// clock code
// get time information for this user
$params = array("lessonid" => $this->properties->id, "userid" => $USER->id);
if (!($timer = $DB->get_records('lesson_timer', $params, 'starttime DESC', '*', 0, 1))) {
$this->start_timer();
$timer = $DB->get_records('lesson_timer', $params, 'starttime DESC', '*', 0, 1);
}
$timer = current($timer);
// This will get the latest start time record.
if ($restart) {
if ($continue) {
// continue a previous test, need to update the clock (think this option is disabled atm)
$timer->starttime = time() - ($timer->lessontime - $timer->starttime);
// Trigger lesson resumed event.
$event = \mod_lesson\event\lesson_resumed::create(array('objectid' => $this->properties->id, 'context' => context_module::instance($cm->id), 'courseid' => $this->properties->course));
$event->trigger();
} else {
// starting over, so reset the clock
$timer->starttime = time();
// Trigger lesson restarted event.
$event = \mod_lesson\event\lesson_restarted::create(array('objectid' => $this->properties->id, 'context' => context_module::instance($cm->id), 'courseid' => $this->properties->course));
$event->trigger();
}
}
$timer->lessontime = time();
$timer->completed = $endreached;
$DB->update_record('lesson_timer', $timer);
// Update completion state.
$cm = get_coursemodule_from_instance('lesson', $this->properties()->id, $this->properties()->course, false, MUST_EXIST);
$course = get_course($cm->course);
$completion = new completion_info($course);
if ($completion->is_enabled($cm) && $this->properties()->completiontimespent > 0) {
$completion->update_state($cm, COMPLETION_COMPLETE);
}
return $timer;
}
示例15: attendanceregister__update_user_aggregates
/**
* Updates Aggregates for a given user
* and notify completion, if needed [feature #7]
*
* @param object $regiser
* @param int $userId
*/
function attendanceregister__update_user_aggregates($register, $userId)
{
global $DB;
// Delete old aggregates
$DB->delete_records('attendanceregister_aggregate', array('userid' => $userId, 'register' => $register->id));
$aggregates = array();
$queryParams = array('registerid' => $register->id, 'userid' => $userId);
// Calculate aggregates of offline Sessions
if ($register->offlinesessions) {
// (note that refcourse has passed as first column to avoid warning of duplicate values in first column by get_records())
$sql = 'SELECT sess.refcourse, sess.register, sess.userid, 0 AS onlinesess, SUM(sess.duration) AS duration, 0 AS total, 0 as grandtotal' . ' FROM {attendanceregister_session} sess' . ' WHERE sess.onlinesess = 0 AND sess.register = :registerid AND sess.userid = :userid' . ' GROUP BY sess.register, sess.userid, sess.refcourse';
$offlinePerCourseAggregates = $DB->get_records_sql($sql, $queryParams);
// Append records
if ($offlinePerCourseAggregates) {
$aggregates = array_merge($aggregates, $offlinePerCourseAggregates);
}
// Calculates total offline, regardless of RefCourse
$sql = 'SELECT sess.register, sess.userid, 0 AS onlinesess, null AS refcourse, SUM(sess.duration) AS duration, 1 AS total, 0 as grandtotal' . ' FROM {attendanceregister_session} sess' . ' WHERE sess.onlinesess = 0 AND sess.register = :registerid AND sess.userid = :userid' . ' GROUP BY sess.register, sess.userid';
$totalOfflineAggregate = $DB->get_record_sql($sql, $queryParams);
// Append record
if ($totalOfflineAggregate) {
$aggregates[] = $totalOfflineAggregate;
}
}
// Calculates aggregates of online Sessions (this is a total as no RefCourse may exist)
$sql = 'SELECT sess.register, sess.userid, 1 AS onlinesess, null AS refcourse, SUM(sess.duration) AS duration, 1 AS total, 0 as grandtotal' . ' FROM {attendanceregister_session} sess' . ' WHERE sess.onlinesess = 1 AND sess.register = :registerid AND sess.userid = :userid' . ' GROUP BY sess.register, sess.userid';
$onlineAggregate = $DB->get_record_sql($sql, $queryParams);
// If User has no Session, generate an online Total record
if (!$onlineAggregate) {
$onlineAggregate = new stdClass();
$onlineAggregate->register = $register->id;
$onlineAggregate->userid = $userId;
$onlineAggregate->onlinesess = 1;
$onlineAggregate->refcourse = null;
$onlineAggregate->duration = 0;
$onlineAggregate->total = 1;
$onlineAggregate->grandtotal = 0;
}
// Append record
$aggregates[] = $onlineAggregate;
// Calculates grand total
$sql = 'SELECT sess.register, sess.userid, null AS onlinesess, null AS refcourse, SUM(sess.duration) AS duration, 0 AS total, 1 as grandtotal' . ' FROM {attendanceregister_session} sess' . ' WHERE sess.register = :registerid AND sess.userid = :userid' . ' GROUP BY sess.register, sess.userid';
$grandTotalAggregate = $DB->get_record_sql($sql, $queryParams);
// If User has no Session, generate a grandTotal record
if (!$grandTotalAggregate) {
$grandTotalAggregate = new stdClass();
$grandTotalAggregate->register = $register->id;
$grandTotalAggregate->userid = $userId;
$grandTotalAggregate->onlinesess = null;
$grandTotalAggregate->refcourse = null;
$grandTotalAggregate->duration = 0;
$grandTotalAggregate->total = 0;
$grandTotalAggregate->grandtotal = 1;
}
// Add lastSessionLogout to GrandTotal
$grandTotalAggregate->lastsessionlogout = attendanceregister__calculate_last_user_online_session_logout($register, $userId);
// Append record
$aggregates[] = $grandTotalAggregate;
// Save all as Aggregates
foreach ($aggregates as $aggregate) {
$DB->insert_record('attendanceregister_aggregate', $aggregate);
}
// Notify completion if needed
// (only if any completion condition is enabled)
if (attendanceregister__isAnyCompletionConditionSpecified($register)) {
// Retrieve Course-Module an Course instances
$cm = get_coursemodule_from_instance('attendanceregister', $register->id, $register->course, null, MUST_EXIST);
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
$completion = new completion_info($course);
if ($completion->is_enabled($cm)) {
// Check completion values
$completionTrackedValues = array('totaldurationsecs' => $grandTotalAggregate->duration);
$isComplete = attendanceregister__areCompletionConditionsMet($register, $completionTrackedValues);
// Notify complete or incomplete
if ($isComplete) {
$completion->update_state($cm, COMPLETION_COMPLETE, $userId);
} else {
$completion->update_state($cm, COMPLETION_INCOMPLETE, $userId);
}
}
}
}