本文整理汇总了PHP中quiz_attempt::has_capability方法的典型用法代码示例。如果您正苦于以下问题:PHP quiz_attempt::has_capability方法的具体用法?PHP quiz_attempt::has_capability怎么用?PHP quiz_attempt::has_capability使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类quiz_attempt
的用法示例。
在下文中一共展示了quiz_attempt::has_capability方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: quiz_send_overdue_message
/**
* Send the notification message when a quiz attempt becomes overdue.
*
* @param quiz_attempt $attemptobj all the data about the quiz attempt.
*/
function quiz_send_overdue_message($attemptobj)
{
global $CFG, $DB;
$submitter = $DB->get_record('user', array('id' => $attemptobj->get_userid()), '*', MUST_EXIST);
if (!$attemptobj->has_capability('mod/quiz:emailwarnoverdue', $submitter->id, false)) {
return;
// Message not required.
}
if (!$attemptobj->has_response_to_at_least_one_graded_question()) {
return;
// Message not required.
}
// Prepare lots of useful information that admins might want to include in
// the email message.
$quizname = format_string($attemptobj->get_quiz_name());
$deadlines = array();
if ($attemptobj->get_quiz()->timelimit) {
$deadlines[] = $attemptobj->get_attempt()->timestart + $attemptobj->get_quiz()->timelimit;
}
if ($attemptobj->get_quiz()->timeclose) {
$deadlines[] = $attemptobj->get_quiz()->timeclose;
}
$duedate = min($deadlines);
$graceend = $duedate + $attemptobj->get_quiz()->graceperiod;
$a = new stdClass();
// Course info.
$a->coursename = format_string($attemptobj->get_course()->fullname);
$a->courseshortname = format_string($attemptobj->get_course()->shortname);
// Quiz info.
$a->quizname = $quizname;
$a->quizurl = $attemptobj->view_url();
$a->quizlink = '<a href="' . $a->quizurl . '">' . $quizname . '</a>';
// Attempt info.
$a->attemptduedate = userdate($duedate);
$a->attemptgraceend = userdate($graceend);
$a->attemptsummaryurl = $attemptobj->summary_url()->out(false);
$a->attemptsummarylink = '<a href="' . $a->attemptsummaryurl . '">' . $quizname . ' review</a>';
// Student's info.
$a->studentidnumber = $submitter->idnumber;
$a->studentname = fullname($submitter);
$a->studentusername = $submitter->username;
// Prepare the message.
$eventdata = new stdClass();
$eventdata->component = 'mod_quiz';
$eventdata->name = 'attempt_overdue';
$eventdata->notification = 1;
$eventdata->userfrom = core_user::get_noreply_user();
$eventdata->userto = $submitter;
$eventdata->subject = get_string('emailoverduesubject', 'quiz', $a);
$eventdata->fullmessage = get_string('emailoverduebody', 'quiz', $a);
$eventdata->fullmessageformat = FORMAT_PLAIN;
$eventdata->fullmessagehtml = '';
$eventdata->smallmessage = get_string('emailoverduesmall', 'quiz', $a);
$eventdata->contexturl = $a->quizurl;
$eventdata->contexturlname = $a->quizname;
// Send the message.
return message_send($eventdata);
}
示例2: dirname
* @package quiz
*/
require_once dirname(__FILE__) . '/../../config.php';
require_once 'locallib.php';
$attemptid = required_param('attempt', PARAM_INT);
// attempt id
$questionid = required_param('question', PARAM_INT);
// question id
$stateid = optional_param('state', 0, PARAM_INT);
// state id
$attemptobj = new quiz_attempt($attemptid);
/// Check login.
require_login($attemptobj->get_courseid(), false, $attemptobj->get_cm());
$attemptobj->check_review_capability();
/// Permissions checks for normal users who do not have quiz:viewreports capability.
if (!$attemptobj->has_capability('mod/quiz:viewreports')) {
/// Can't review during the attempt - send them back to the attempt page.
if (!$attemptobj->is_finished()) {
notify(get_string('cannotreviewopen', 'quiz'));
close_window_button();
}
/// Can't review other users' attempts.
if (!$attemptobj->is_own_attempt()) {
notify(get_string('notyourattempt', 'quiz'));
close_window_button();
}
/// Can't review unless Students may review -> Responses option is turned on.
if (!$options->responses) {
$accessmanager = $attemptobj->get_access_manager(time());
notify($accessmanager->cannot_review_message($attemptobj->get_review_options()));
close_window_button();