本文整理汇总了PHP中question_has_capability_on函数的典型用法代码示例。如果您正苦于以下问题:PHP question_has_capability_on函数的具体用法?PHP question_has_capability_on怎么用?PHP question_has_capability_on使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了question_has_capability_on函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: display_content
protected function display_content($question, $rowclasses)
{
if (!question_has_capability_on($question, 'use')) {
return;
}
$this->print_icon('t/add', $this->stradd, $this->qbank->add_to_rtq_url($question->id));
}
示例2: display_content
protected function display_content($question, $rowclasses)
{
global $PAGE;
if (question_has_capability_on($question, 'use')) {
echo $PAGE->get_renderer('core_question')->question_preview_link($question->id, $this->qbank->get_most_specific_context(), false);
}
}
示例3: print_question
function print_question(&$question, &$state, $number, $cmoptions, $options)
{
global $CFG;
$isfinished = question_state_is_graded($state->last_graded) || $state->event == QUESTION_EVENTCLOSE;
if (!empty($cmoptions->id)) {
$cm = get_coursemodule_from_instance('quiz', $cmoptions->id);
$cmorcourseid = '&cmid=' . $cm->id;
} else {
if (!empty($cmoptions->course)) {
$cmorcourseid = '&courseid=' . $cmoptions->course;
} else {
error('Need to provide courseid or cmid to print_question.');
}
}
// For editing teachers print a link to an editing popup window
$editlink = '';
if (question_has_capability_on($question, 'edit')) {
$stredit = get_string('edit');
$linktext = '<img src="' . $CFG->pixpath . '/t/edit.gif" alt="' . $stredit . '" />';
$editlink = link_to_popup_window('/question/question.php?id=' . $question->id . $cmorcourseid, $stredit, $linktext, 450, 550, $stredit, '', true);
}
$questiontext = $this->format_text($question->questiontext, $question->questiontextformat, $cmoptions);
$image = get_question_image($question);
$generalfeedback = '';
if ($isfinished && $options->generalfeedback) {
$generalfeedback = $this->format_text($question->generalfeedback, $question->questiontextformat, $cmoptions);
}
include "{$CFG->dirroot}/question/type/description/question.html";
}
示例4: question_preview_question_pluginfile
/**
* Called via pluginfile.php -> question_pluginfile to serve files belonging to
* a question in a question_attempt when that attempt is a preview.
*
* @param object $course course settings object
* @param object $context context object
* @param string $component the name of the component we are serving files for.
* @param string $filearea the name of the file area.
* @param array $args the remaining bits of the file path.
* @param bool $forcedownload whether the user must be forced to download the file.
* @return bool false if file not found, does not return if found - justsend the file
*/
function question_preview_question_pluginfile($course, $context, $component, $filearea, $attemptid, $questionid, $args, $forcedownload)
{
global $USER, $SESSION, $DB, $CFG;
require_once $CFG->dirroot . '/mod/quiz/locallib.php';
if (!($question = $DB->get_record('question', array('id' => $questionid)))) {
return send_file_not_found();
}
if (!question_has_capability_on($question, 'use', $question->category)) {
send_file_not_found();
}
if (!isset($SESSION->quizpreview->states) || $SESSION->quizpreview->questionid != $questionid) {
send_file_not_found();
}
$states = end($SESSION->quizpreview->states);
if (!array_key_exists($question->id, $states)) {
send_file_not_found();
}
$state = $states[$question->id];
// Build fake cmoptions
$quiz = new cmoptions();
$quiz->id = 0;
$quiz->review = get_config('quiz', 'review');
if (empty($course->id)) {
$quiz->course = SITEID;
} else {
$quiz->course = $course->id;
}
$quiz->decimalpoints = get_config('quiz', 'decimalpoints');
$questions[$question->id] = $question;
get_question_options($questions);
// Build fake attempt
$timenow = time();
$attempt = new stdClass();
$attempt->quiz = $quiz->id;
$attempt->userid = $USER->id;
$attempt->attempt = 0;
$attempt->sumgrades = 0;
$attempt->timestart = $timenow;
$attempt->timefinish = 0;
$attempt->timemodified = $timenow;
$attempt->uniqueid = 0;
$attempt->id = 0;
$attempt->layout = $question->id;
$options = quiz_get_renderoptions($quiz, $attempt, $context, $state);
$options->noeditlink = true;
// XXX: mulitichoice type needs quiz id to get maxgrade
$options->quizid = 0;
if (!question_check_file_access($question, $state, $options, $context->id, $component, $filearea, $args, $forcedownload)) {
send_file_not_found();
}
$fs = get_file_storage();
$relativepath = implode('/', $args);
$fullpath = "/{$context->id}/{$component}/{$filearea}/{$relativepath}";
if (!($file = $fs->get_file_by_hash(sha1($fullpath))) or $file->is_directory()) {
send_file_not_found();
}
send_stored_file($file, 0, 0, $forcedownload);
}
示例5: display_content
protected function display_content($question, $rowclasses)
{
// To copy a question, you need permission to add a question in the same
// category as the existing question, and ability to access the details of
// the question being copied.
if (question_has_capability_on($question, 'add') && (question_has_capability_on($question, 'edit') || question_has_capability_on($question, 'view'))) {
$this->print_icon('t/copy', $this->strcopy, $this->qbank->copy_question_url($question->id));
}
}
示例6: display_content
protected function display_content($question, $rowclasses)
{
if (question_has_capability_on($question, 'edit')) {
$this->print_icon('t/edit', $this->stredit, $this->qbank->edit_question_url($question->id));
} else {
if (question_has_capability_on($question, 'view')) {
$this->print_icon('i/info', $this->strview, $this->qbank->edit_question_url($question->id));
}
}
}
示例7: drop_questions
function drop_questions($a)
{
global $DB;
// First sanity check the existance of the context. there may be deleted contexts and some question wreck inside.
$contextid = $DB->get_field('question_categories', 'contextid', array('id' => $a->category));
if (!$DB->record_exists('context', array('id' => $contextid))) {
return false;
}
return question_has_capability_on($a->id, 'use');
}
示例8: display_content
protected function display_content($question, $rowclasses)
{
if (!question_has_capability_on($question, 'use')) {
return;
}
$disabled = false;
if ($this->qbank->offlinequiz_contains($question->id)) {
$disabled = true;
}
$this->print_icon('t/add', $this->stradd, $this->qbank->add_to_offlinequiz_url($question->id), $disabled);
}
示例9: display_content
protected function display_content($question, $rowclasses)
{
if (question_has_capability_on($question, 'edit')) {
if ($question->hidden) {
$url = new \moodle_url($this->qbank->base_url(), array('unhide' => $question->id, 'sesskey' => sesskey()));
$this->print_icon('t/restore', $this->strrestore, $url);
} else {
$url = new \moodle_url($this->qbank->base_url(), array('deleteselected' => $question->id, 'q' . $question->id => 1, 'sesskey' => sesskey()));
$this->print_icon('t/delete', $this->strdelete, $url);
}
}
}
示例10: get_context_instance_by_id
$categorycontext = get_context_instance_by_id($category->contextid);
$addpermission = has_capability('moodle/question:add', $categorycontext);
if ($id) {
$canview = question_has_capability_on($question, 'view');
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, 'view');
} else {
$question->formoptions->canedit = question_has_capability_on($question, 'edit');
$question->formoptions->canmove = question_has_capability_on($question, 'move') && $addpermission;
$question->formoptions->cansaveasnew = ($canview || question_has_capability_on($question, 'edit')) && $addpermission;
$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');
}
}
} else {
// creating a new question
require_capability('moodle/question:add', $categorycontext);
$formeditable = true;
$question->formoptions->repeatelements = true;
$question->formoptions->movecontext = false;
}
// Validate the question type.
示例11: get_question_edit_link
/**
* Get a link to an edit icon for this question, if the current user is allowed
* to edit it.
*
* @param object $question the question object.
* @param object $cmoptions the options from the module. If $cmoptions->thispageurl is set
* then the link will be to edit the question in this browser window, then return to
* $cmoptions->thispageurl. Otherwise the link will be to edit in a popup. $cmoptions->cmid should also be set.
* @return string the HTML of the link, or nothing it the currenty user is not allowed to edit.
*/
function get_question_edit_link($question, $cmoptions, $options)
{
global $CFG;
/// Is this user allowed to edit this question?
if (!empty($options->noeditlink) || !question_has_capability_on($question, 'edit')) {
return '';
}
/// Work out the right URL.
$linkurl = '/question/question.php?id=' . $question->id;
if (!empty($cmoptions->cmid)) {
$linkurl .= '&cmid=' . $cmoptions->cmid;
} else {
if (!empty($cmoptions->course)) {
$linkurl .= '&courseid=' . $cmoptions->course;
} else {
error('Need to provide courseid or cmid to get_question_edit_link.');
}
}
/// Work out the contents of the link.
$stredit = get_string('edit');
$linktext = '<img src="' . $CFG->pixpath . '/t/edit.gif" alt="' . $stredit . '" />';
if (!empty($cmoptions->thispageurl)) {
/// The module allow editing in the same window, print an ordinary link.
return '<a href="' . $CFG->wwwroot . $linkurl . '&returnurl=' . urlencode($cmoptions->thispageurl) . '" title="' . $stredit . '">' . $linktext . '</a>';
} else {
/// We have to edit in a pop-up.
return link_to_popup_window($linkurl . '&inpopup=1', 'editquestion', $linktext, false, false, $stredit, '', true);
}
}
示例12: question_require_capability_on
/**
* Require capability on question.
*/
function question_require_capability_on($question, $cap)
{
if (!question_has_capability_on($question, $cap)) {
print_error('nopermissions', '', '', $cap);
}
return true;
}
示例13: question_list
//.........这里部分代码省略.........
return;
}
}
print_paging_bar($totalnumber, $page, $perpage, $pageurl, 'qpage');
echo question_sort_options($pageurl, $sortorder);
echo '<form method="post" action="edit.php">';
echo '<fieldset class="invisiblefieldset" style="display: block;">';
echo '<input type="hidden" name="sesskey" value="' . $USER->sesskey . '" />';
echo $pageurl->hidden_params_out();
echo '<table id="categoryquestions" style="width: 100%"><tr>';
echo "<th style=\"white-space:nowrap;\" class=\"header\" scope=\"col\">{$straction}</th>";
echo "<th style=\"white-space:nowrap; text-align: left;\" class=\"header\" scope=\"col\">{$strquestionname}</th>\n <th style=\"white-space:nowrap; text-align: right;\" class=\"header\" scope=\"col\">{$strtype}</th>";
echo "</tr>\n";
foreach ($questions as $question) {
$nameclass = '';
$textclass = '';
if ($question->hidden) {
$nameclass = 'dimmed_text';
$textclass = 'dimmed_text';
}
if ($showquestiontext) {
$nameclass .= ' header';
}
if ($question->id == $lastchangedid) {
$nameclass = 'highlight';
}
if ($nameclass) {
$nameclass = 'class="' . $nameclass . '"';
}
if ($textclass) {
$textclass = 'class="' . $textclass . '"';
}
echo "<tr>\n<td style=\"white-space:nowrap;\" {$nameclass}>\n";
$canuseq = question_has_capability_on($question, 'use', $question->category);
if (function_exists('module_specific_actions')) {
echo module_specific_actions($pageurl, $question->id, $cm->id, $canuseq);
}
// preview
if ($canuseq) {
$quizorcourseid = $quizid ? '&quizid=' . $quizid : '&courseid=' . $COURSE->id;
link_to_popup_window('/question/preview.php?id=' . $question->id . $quizorcourseid, 'questionpreview', "<img src=\"{$CFG->pixpath}/t/preview.gif\" class=\"iconsmall\" alt=\"{$strpreview}\" />", 0, 0, $strpreview, QUESTION_PREVIEW_POPUP_OPTIONS);
}
// edit, hide, delete question, using question capabilities, not quiz capabilieies
if (question_has_capability_on($question, 'edit', $question->category) || question_has_capability_on($question, 'move', $question->category)) {
echo "<a title=\"{$stredit}\" href=\"" . $questionurl->out(false, array('id' => $question->id)) . "\"><img\n src=\"{$CFG->pixpath}/t/edit.gif\" alt=\"{$stredit}\" /></a> ";
} elseif (question_has_capability_on($question, 'view', $question->category)) {
echo "<a title=\"{$strview}\" href=\"" . $questionurl->out(false, array('id' => $question->id)) . "\"><img\n src=\"{$CFG->pixpath}/i/info.gif\" alt=\"{$strview}\" /></a> ";
}
if (question_has_capability_on($question, 'move', $question->category) && question_has_capability_on($question, 'view', $question->category)) {
echo "<a title=\"{$strmove}\" href=\"" . $questionurl->out(false, array('id' => $question->id, 'movecontext' => 1)) . "\"><img\n src=\"{$CFG->pixpath}/t/move.gif\" alt=\"{$strmove}\" /></a> ";
}
if (question_has_capability_on($question, 'edit', $question->category)) {
// hide-feature
if ($question->hidden) {
echo "<a title=\"{$strrestore}\" href=\"edit.php?" . $pageurl->get_query_string() . "&unhide={$question->id}&sesskey={$USER->sesskey}\"><img\n src=\"{$CFG->pixpath}/t/restore.gif\" alt=\"{$strrestore}\" /></a>";
} else {
echo "<a title=\"{$strdelete}\" href=\"edit.php?" . $pageurl->get_query_string() . "&deleteselected={$question->id}&q{$question->id}=1\"><img\n src=\"{$CFG->pixpath}/t/delete.gif\" alt=\"{$strdelete}\" /></a>";
}
}
if ($caneditall || $canmoveall || $canuseall) {
echo " <input title=\"{$strselect}\" type=\"checkbox\" name=\"q{$question->id}\" value=\"1\" />";
}
echo "</td>\n";
echo "<td {$nameclass}>" . format_string($question->name) . "</td>\n";
echo "<td {$nameclass} style='text-align: right'>\n";
print_question_icon($question);
示例14: quiz_question_preview_button
/**
* @param object $quiz the quiz settings
* @param object $question the question
* @param bool $label if true, show the preview question label after the icon
* @return the HTML for a preview question icon.
*/
function quiz_question_preview_button($quiz, $question, $label = false) {
global $CFG, $OUTPUT;
if (!question_has_capability_on($question, 'use', $question->category)) {
return '';
}
$url = quiz_question_preview_url($quiz, $question);
// Do we want a label?
$strpreviewlabel = '';
if ($label) {
$strpreviewlabel = get_string('preview', 'quiz');
}
// Build the icon.
$strpreviewquestion = get_string('previewquestion', 'quiz');
$image = $OUTPUT->pix_icon('t/preview', $strpreviewquestion);
$action = new popup_action('click', $url, 'questionpreview',
question_preview_popup_params());
return $OUTPUT->action_link($url, $image, $action, array('title' => $strpreviewquestion));
}
示例15: quiz_print_question_list
//.........这里部分代码省略.........
}
if (!$quiz->shufflequestions) {
// Print and increment question number
$questioncountstring = '';
if ($questioncount > 999 || $reordertool && $questioncount > 99) {
$questioncountstring = "{$reordercheckboxlabel}<small>{$questioncount}</small>" . $reordercheckboxlabelclose . $reordercheckbox;
} else {
$questioncountstring = $reordercheckboxlabel . $questioncount . $reordercheckboxlabelclose . $reordercheckbox;
}
echo $questioncountstring;
$qno += $question->length;
} else {
echo "{$reordercheckboxlabel} ? {$reordercheckboxlabelclose}" . " {$reordercheckbox}";
}
?>
</div>
<div class="content">
<div class="questioncontrols">
<?php
if ($count != 0) {
if (!$hasattempts) {
$upbuttonclass = '';
if ($count >= $lastindex - 1) {
$upbuttonclass = 'upwithoutdown';
}
echo "<a title=\"{$strmoveup}\" href=\"" . $pageurl->out_action(array('up' => $question->id)) . "\"><img\n src=\"{$CFG->pixpath}/t/up.gif\" class=\"iconsmall\n {$upbuttonclass}\" alt=\"{$strmoveup}\" /></a>";
}
}
if ($count < $lastindex - 1) {
if (!$hasattempts) {
echo "<a title=\"{$strmovedown}\" href=\"" . $pageurl->out_action(array('down' => $question->id)) . "\"><img\n src=\"{$CFG->pixpath}/t/down.gif\" class=\"iconsmall\"" . " alt=\"{$strmovedown}\" /></a>";
}
}
if ($allowdelete && question_has_capability_on($question, 'use', $question->category)) {
// remove from quiz, not question delete.
if (!$hasattempts) {
echo "<a title=\"{$strremove}\" href=\"" . $pageurl->out_action(array('remove' => $question->id)) . "\">\n <img src=\"{$CFG->pixpath}/t/delete.gif\" " . "class=\"iconsmall\" alt=\"{$strremove}\" /></a>";
}
}
?>
</div><?php
if ($question->qtype != 'description' && !$reordertool) {
?>
<div class="points">
<form method="post" action="edit.php"><div>
<fieldset class="invisiblefieldset" style="display: block;">
<label for="<?php
echo "inputq{$question->id}";
?>
"><?php
echo $strgrade;
?>
</label>:<br />
<input type="hidden" name="sesskey" value="<?php
echo sesskey();
?>
" />
<?php
echo $pageurl->hidden_params_out();
?>
<input type="hidden" name="savechanges" value="save" />
<?php
echo '<input type="text" name="g' . $question->id . '" id="inputq' . $question->id . '" size="' . ($quiz->decimalpoints + 2) . '" value="' . (0 + $quiz->grades[$qnum]) . '" tabindex="' . ($lastindex + $qno) . '" />';
?>
<input type="submit" class="pointssubmitbutton" value="<?php
echo $strsave;