';
-if (!$quiz_reordertool) {
+if (!$quiz_reordertool && $canaddrandom) {
$randomform = new quiz_add_random_form(new moodle_url('/mod/quiz/addrandom.php'), $contexts);
$randomform->set_data(array(
'category' => $pagevars['cat'],
diff --git a/mod/quiz/editlib.php b/mod/quiz/editlib.php
index ac2528cf037..be12593b7f1 100644
--- a/mod/quiz/editlib.php
+++ b/mod/quiz/editlib.php
@@ -35,6 +35,28 @@ require_once($CFG->dirroot . '/mod/quiz/locallib.php');
define('NUM_QS_TO_SHOW_IN_RANDOM', 3);
+/**
+ * Verify that the question exists, and the user has permission to use it.
+ * Does not return. Throws an exception if the question cannot be used.
+ * @param int $questionid The id of the question.
+ */
+function quiz_require_question_use($questionid) {
+ global $DB;
+ $question = $DB->get_record('question', array('id' => $questionid), '*', MUST_EXIST);
+ question_require_capability_on($question, 'use');
+}
+
+/**
+ * Verify that the question exists, and the user has permission to use it.
+ * @param int $questionid The id of the question.
+ * @return bool whether the user can use this question.
+ */
+function quiz_has_question_use($questionid) {
+ global $DB;
+ $question = $DB->get_record('question', array('id' => $questionid), '*', MUST_EXIST);
+ return question_has_capability_on($question, 'use');
+}
+
/**
* Remove a question from a quiz
* @param object $quiz the quiz object.
@@ -333,19 +355,21 @@ function quiz_move_question_down($layout, $questionid) {
* Prints a list of quiz questions for the edit.php main view for edit
* ($reordertool = false) and order and paging ($reordertool = true) tabs
*
- * @return int sum of maximum grades
* @param object $quiz This is not the standard quiz object used elsewhere but
* it contains the quiz layout in $quiz->questions and the grades in
* $quiz->grades
- * @param object $pageurl The url of the current page with the parameters required
+ * @param moodle_url $pageurl The url of the current page with the parameters required
* for links returning to the current page, as a moodle_url object
* @param bool $allowdelete Indicates whether the delete icons should be displayed
* @param bool $reordertool Indicates whether the reorder tool should be displayed
* @param bool $quiz_qbanktool Indicates whether the question bank should be displayed
* @param bool $hasattempts Indicates whether the quiz has attempts
+ * @param object $defaultcategoryobj
+ * @param bool $canaddquestion is the user able to add and use questions anywere?
+ * @param bool $canaddrandom is the user able to add random questions anywere?
*/
function quiz_print_question_list($quiz, $pageurl, $allowdelete, $reordertool,
- $quiz_qbanktool, $hasattempts, $defaultcategoryobj) {
+ $quiz_qbanktool, $hasattempts, $defaultcategoryobj, $canaddquestion, $canaddrandom) {
global $CFG, $DB, $OUTPUT;
$strorder = get_string('order');
$strquestionname = get_string('questionname', 'quiz');
@@ -667,7 +691,7 @@ function quiz_print_question_list($quiz, $pageurl, $allowdelete, $reordertool,
if (!$reordertool && !($quiz->shufflequestions &&
$count < $questiontotalcount - 1)) {
quiz_print_pagecontrols($quiz, $pageurl, $pagecount,
- $hasattempts, $defaultcategoryobj);
+ $hasattempts, $defaultcategoryobj, $canaddquestion, $canaddrandom);
} else if ($count < $questiontotalcount - 1) {
//do not include the last page break for reordering
//to avoid creating a new extra page in the end
@@ -703,12 +727,19 @@ function quiz_print_question_list($quiz, $pageurl, $allowdelete, $reordertool,
* Print all the controls for adding questions directly into the
* specific page in the edit tab of edit.php
*
- * @param unknown_type $quiz
- * @param unknown_type $pageurl
- * @param unknown_type $page
- * @param unknown_type $hasattempts
+ * @param object $quiz This is not the standard quiz object used elsewhere but
+ * it contains the quiz layout in $quiz->questions and the grades in
+ * $quiz->grades
+ * @param moodle_url $pageurl The url of the current page with the parameters required
+ * for links returning to the current page, as a moodle_url object
+ * @param int $page the current page number.
+ * @param bool $hasattempts Indicates whether the quiz has attempts
+ * @param object $defaultcategoryobj
+ * @param bool $canaddquestion is the user able to add and use questions anywere?
+ * @param bool $canaddrandom is the user able to add random questions anywere?
*/
-function quiz_print_pagecontrols($quiz, $pageurl, $page, $hasattempts, $defaultcategoryobj) {
+function quiz_print_pagecontrols($quiz, $pageurl, $page, $hasattempts,
+ $defaultcategoryobj, $canaddquestion, $canaddrandom) {
global $CFG, $OUTPUT;
static $randombuttoncount = 0;
$randombuttoncount++;
@@ -724,22 +755,25 @@ function quiz_print_pagecontrols($quiz, $pageurl, $page, $hasattempts, $defaultc
$defaultcategoryid = $defaultcategoryobj->id;
}
- // Create the url the question page will return to
- $returnurladdtoquiz = new moodle_url($pageurl, array('addonpage' => $page));
+ if ($canaddquestion) {
+ // Create the url the question page will return to
+ $returnurladdtoquiz = new moodle_url($pageurl, array('addonpage' => $page));
- // Print a button linking to the choose question type page.
- $returnurladdtoquiz = $returnurladdtoquiz->out_as_local_url(false);
- $newquestionparams = array('returnurl' => $returnurladdtoquiz,
- 'cmid' => $quiz->cmid, 'appendqnumstring' => 'addquestion');
- create_new_question_button($defaultcategoryid, $newquestionparams,
- get_string('addaquestion', 'quiz'),
- get_string('createquestionandadd', 'quiz'), $hasattempts);
+ // Print a button linking to the choose question type page.
+ $returnurladdtoquiz = $returnurladdtoquiz->out_as_local_url(false);
+ $newquestionparams = array('returnurl' => $returnurladdtoquiz,
+ 'cmid' => $quiz->cmid, 'appendqnumstring' => 'addquestion');
+ create_new_question_button($defaultcategoryid, $newquestionparams,
+ get_string('addaquestion', 'quiz'),
+ get_string('createquestionandadd', 'quiz'), $hasattempts);
+ }
if ($hasattempts) {
$disabled = 'disabled="disabled"';
} else {
$disabled = '';
}
+ if ($canaddrandom) {
?>