本文整理汇总了PHP中question_edit_contexts::have_cap方法的典型用法代码示例。如果您正苦于以下问题:PHP question_edit_contexts::have_cap方法的具体用法?PHP question_edit_contexts::have_cap怎么用?PHP question_edit_contexts::have_cap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类question_edit_contexts
的用法示例。
在下文中一共展示了question_edit_contexts::have_cap方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: stdClass
}
}
}
$qtypeobj = question_bank::get_qtype($question->qtype);
// Validate the question category.
if (!($category = $DB->get_record('question_categories', array('id' => $question->category)))) {
print_error('categorydoesnotexist', 'question', $returnurl);
}
// Check permissions
$question->formoptions = new stdClass();
$categorycontext = context::instance_by_id($category->contextid);
$addpermission = has_capability('moodle/question:add', $categorycontext);
if ($id) {
if ($movecontext) {
$question->formoptions->canedit = false;
$question->formoptions->canmove = question_has_capability_on($question, 'move') && $contexts->have_cap('moodle/question:add');
$question->formoptions->cansaveasnew = false;
$question->formoptions->repeatelements = false;
$question->formoptions->movecontext = true;
$formeditable = true;
question_require_capability_on($question, 'move');
} else {
$question->formoptions->canedit = question_has_capability_on($question, 'edit');
$question->formoptions->canmove = $addpermission && question_has_capability_on($question, 'move');
$question->formoptions->cansaveasnew = $addpermission && (question_has_capability_on($question, 'view') || $question->formoptions->canedit);
$question->formoptions->repeatelements = $question->formoptions->canedit || $question->formoptions->cansaveasnew;
$formeditable = $question->formoptions->canedit || $question->formoptions->cansaveasnew || $question->formoptions->canmove;
$question->formoptions->movecontext = false;
if (!$formeditable) {
question_require_capability_on($question, 'view');
}
示例2: random_question_form
/**
* Return random question form.
* @param \moodle_url $thispageurl the canonical URL of this page.
* @param \question_edit_contexts $contexts the relevant question bank contexts.
* @param array $pagevars the variables from {@link \question_edit_setup()}.
* @return string HTML to output.
*/
protected function random_question_form(\moodle_url $thispageurl, \question_edit_contexts $contexts, array $pagevars)
{
if (!$contexts->have_cap('moodle/question:useall')) {
return '';
}
$randomform = new \quiz_add_random_form(new \moodle_url('/mod/quiz/addrandom.php'), array('contexts' => $contexts, 'cat' => $pagevars['cat']));
$randomform->set_data(array('category' => $pagevars['cat'], 'returnurl' => $thispageurl->out_as_local_url(true), 'randomnumber' => 1, 'cmid' => $thispageurl->param('cmid')));
return html_writer::div($randomform->render(), 'randomquestionformforpopup');
}