-<?php // $Id$
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
/**
* Standard library of functions and constants for lesson
*
- * @version $Id$
- * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
- * @package lesson
+ * @package mod-lesson
+ * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
**/
+/** Include {@link eventslib.php} */
require_once($CFG->libdir.'/eventslib.php');
-define("LESSON_MAX_EVENT_LENGTH", "432000"); // 5 days maximum
+/** LESSON_MAX_EVENT_LENGTH = 432000 ; 5 days maximum */
+define("LESSON_MAX_EVENT_LENGTH", "432000");
/**
* Given an object containing all the necessary data,
* will create a new instance and return the id number
* of the new instance.
*
+ * @global object
+ * @global object
* @param object $lesson Lesson post data from the form
* @return int
**/
* (defined by the form in mod_form.php) this function
* will update an existing instance with new data.
*
+ * @global object
* @param object $lesson Lesson post data from the form
* @return boolean
**/
}
-/*******************************************************************/
+/**
+ * Given an ID of an instance of this module,
+ * this function will permanently delete the instance
+ * and any data that depends on it.
+ *
+ * @global object
+ * @param int $id
+ * @return bool
+ */
function lesson_delete_instance($id) {
global $DB;
-/// Given an ID of an instance of this module,
-/// this function will permanently delete the instance
-/// and any data that depends on it.
if (! $lesson = $DB->get_record("lesson", array("id"=>$id))) {
return false;
*
* As of now, this function just cleans the lesson_default table
*
+ * @global object
* @param object $course an object representing the course that is being deleted
* @param boolean $feedback to specify if the process must output a summary of its work
* @return boolean
return true;
}
-/*******************************************************************/
+/**
+ * Return a small object with summary information about what a
+ * user has done with a given particular instance of this module
+ * Used for user activity reports.
+ * $return->time = the time they did it
+ * $return->info = a short text description
+ *
+ * @global object
+ * @param object $course
+ * @param object $user
+ * @param object $mod
+ * @param object $lesson
+ * @return object
+ */
function lesson_user_outline($course, $user, $mod, $lesson) {
-/// Return a small object with summary information about what a
-/// user has done with a given particular instance of this module
-/// Used for user activity reports.
-/// $return->time = the time they did it
-/// $return->info = a short text description
global $DB;
$params = array ("lessonid" => $lesson->id, "userid" => $user->id);
return $return;
}
-/*******************************************************************/
+/**
+ * Print a detailed representation of what a user has done with
+ * a given particular instance of this module, for user activity reports.
+ *
+ * @global object
+ * @param object $course
+ * @param object $user
+ * @param object $mod
+ * @param object $lesson
+ * @return bool
+ */
function lesson_user_complete($course, $user, $mod, $lesson) {
-/// Print a detailed representation of what a user has done with
-/// a given particular instance of this module, for user activity reports.
global $DB;
$params = array ("lessonid" => $lesson->id, "userid" => $user->id);
* lessons that have a deadline that has not already passed
* and it is available for taking.
*
+ * @global object
+ * @global stdClass
+ * @global object
+ * @uses CONTEXT_MODULE
* @param array $courses An array of course objects to get lesson instances from
* @param array $htmlarray Store overview output array( course ID => 'lesson' => HTML output )
+ * @return void
*/
function lesson_print_overview($courses, &$htmlarray) {
global $USER, $CFG, $DB;
}
}
-/*******************************************************************/
+/**
+ * Function to be run periodically according to the moodle cron
+ * This function searches for things that need to be done, such
+ * as sending out mail, toggling flags etc ...
+ * @global stdClass
+ * @return bool true
+ */
function lesson_cron () {
-/// Function to be run periodically according to the moodle cron
-/// This function searches for things that need to be done, such
-/// as sending out mail, toggling flags etc ...
-
global $CFG;
return true;
/**
* Return grade for given user or all users.
*
+ * @global stdClass
+ * @global object
* @param int $lessonid id of lesson
* @param int $userid optional user id, 0 means all users
* @return array array of grades, false if none
/**
* Update grades in central gradebook
*
+ * @global stdclass
+ * @global object
* @param object $lesson
* @param int $userid specific user only, 0 means all
+ * @param bool $nullifnone
*/
function lesson_update_grades($lesson, $userid=0, $nullifnone=true) {
global $CFG, $DB;
/**
* Update all grades in gradebook.
+ *
+ * @global object
*/
function lesson_upgrade_grades() {
global $DB;
/**
* Create grade item for given lesson
*
+ * @global stdClass
+ * @uses GRADE_TYPE_VALUE
+ * @uses GRADE_TYPE_NONE
* @param object $lesson object with extra cmidnumber
- * @param mixed optional array/object of grade(s); 'reset' means reset grades in gradebook
+ * @param array|object $grades optional array/object of grade(s); 'reset' means reset grades in gradebook
* @return int 0 if ok, error code otherwise
*/
function lesson_grade_item_update($lesson, $grades=NULL) {
/**
* Delete grade item for given lesson
*
+ * @global stdClass
* @param object $lesson object
* @return object lesson
*/
}
-/*******************************************************************/
+/**
+ * Must return an array of user records (all data) who are participants
+ * for a given instance of lesson. Must include every user involved
+ * in the instance, independient of his role (student, teacher, admin...)
+ *
+ * @global stdClass
+ * @global object
+ * @param int $lessonid
+ * @return array
+ */
function lesson_get_participants($lessonid) {
-//Must return an array of user records (all data) who are participants
-//for a given instance of lesson. Must include every user involved
-//in the instance, independient of his role (student, teacher, admin...)
-
global $CFG, $DB;
//Get students
return ($students);
}
+/**
+ * @return array
+ */
function lesson_get_view_actions() {
return array('view','view all');
}
+/**
+ * @return array
+ */
function lesson_get_post_actions() {
return array('end','start', 'update grade attempt');
}
* Runs any processes that must run before
* a lesson insert/update
*
+ * @global object
* @param object $lesson Lesson form data
* @return void
**/
* Runs any processes that must be run
* after a lesson insert/update
*
+ * @global object
* @param object $lesson Lesson form data
* @return void
**/
/**
* Implementation of the function for printing the form elements that control
* whether the course reset functionality affects the lesson.
+ *
* @param $mform form passed by reference
*/
function lesson_reset_course_form_definition(&$mform) {
/**
* Course reset form defaults.
+ * @param object $course
+ * @return array
*/
function lesson_reset_course_form_defaults($course) {
return array('reset_lesson'=>1);
/**
* Removes all grades from gradebook
+ *
+ * @global stdClass
+ * @global object
* @param int $courseid
* @param string optional type
*/
/**
* Actual implementation of the rest coures functionality, delete all the
* lesson attempts for course $data->courseid.
- * @param $data the data submitted from the reset course.
+ *
+ * @global stdClass
+ * @global object
+ * @param object $data the data submitted from the reset course.
* @return array status array
*/
function lesson_reset_userdata($data) {
/**
* Returns all other caps used in module
+ * @return array
*/
function lesson_get_extra_capabilities() {
return array('moodle/site:accessallgroups');
}
/**
+ * @uses FEATURE_GROUPS
+ * @uses FEATURE_GROUPINGS
+ * @uses FEATURE_GROUPMEMBERSONLY
+ * @uses FEATURE_MOD_INTRO
+ * @uses FEATURE_COMPLETION_TRACKS_VIEWS
+ * @uses FEATURE_GRADE_HAS_GRADE
+ * @uses FEATURE_GRADE_OUTCOMES
* @param string $feature FEATURE_xx constant for requested feature
- * @return mixed True if module supports feature, null if doesn't know
+ * @return mixed True if module supports feature, false if not, null if doesn't know
*/
function lesson_supports($feature) {
switch($feature) {
-<?php // $Id$
-
-///////////////////////////////////////////////////////////////////////////
-// //
-// NOTICE OF COPYRIGHT //
-// //
-// Moodle - Modular Object-Oriented Dynamic Learning Environment //
-// http://moodle.org //
-// //
-// Copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com //
-// //
-// This program is free software; you can redistribute it and/or modify //
-// it under the terms of the GNU General Public License as published by //
-// the Free Software Foundation; either version 2 of the License, or //
-// (at your option) any later version. //
-// //
-// This program is distributed in the hope that it will be useful, //
-// but WITHOUT ANY WARRANTY; without even the implied warranty of //
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
-// GNU General Public License for more details: //
-// //
-// http://www.gnu.org/copyleft/gpl.html //
-// //
-///////////////////////////////////////////////////////////////////////////
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Library of functions for the quiz module.
* This contains functions that are called also from outside the quiz module
* Functions that are only called by the quiz module itself are in {@link locallib.php}
*
- * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
- * @package quiz
+ * @package mod-quiz
+ * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
+/** Require {@link eventslib.php} */
require_once($CFG->libdir . '/eventslib.php');
/// CONSTANTS ///////////////////////////////////////////////////////////////////
* will create a new instance and return the id number
* of the new instance.
*
+ * @global object
* @param object $quiz the data that came from the form.
* @return mixed the id of the new instance on success,
* false or a string error message on failure.
* (defined by the form in mod_form.php) this function
* will update an existing instance with new data.
*
+ * @global stdClass
+ * @global object
* @param object $quiz the data that came from the form.
* @return mixed true on success, false or a string error message on failure.
*/
return true;
}
+/**
+ * Given an ID of an instance of this module,
+ * this function will permanently delete the instance
+ * and any data that depends on it.
+ *
+ * @global object
+ * @param int $id
+ * @return bool
+ */
function quiz_delete_instance($id) {
global $DB;
-/// Given an ID of an instance of this module,
-/// this function will permanently delete the instance
-/// and any data that depends on it.
if (!$quiz = $DB->get_record('quiz', array('id' => $id))) {
return false;
/**
* Delete all the attempts belonging to a quiz.
- * @param $quiz The quiz object.
+ *
+ * @global stdClass
+ * @global object
+ * @param object $quiz The quiz object.
*/
function quiz_delete_all_attempts($quiz) {
global $CFG, $DB;
$DB->delete_records('quiz_grades', array('quiz' => $quiz->id));
}
+/**
+ * Return a small object with summary information about what a
+ * user has done with a given particular instance of this module
+ * Used for user activity reports.
+ * $return->time = the time they did it
+ * $return->info = a short text description
+ *
+ * @global object
+ * @param object $course
+ * @param object $user
+ * @param object $mod
+ * @param object $quiz
+ * @return object|null
+ */
function quiz_user_outline($course, $user, $mod, $quiz) {
global $DB;
-/// Return a small object with summary information about what a
-/// user has done with a given particular instance of this module
-/// Used for user activity reports.
-/// $return->time = the time they did it
-/// $return->info = a short text description
$grade = quiz_get_best_grade($quiz, $user->id);
if (is_null($grade)) {
return NULL;
/**
* Get the best current grade for a particular user in a quiz.
*
+ * @global object
* @param object $quiz the quiz object.
* @param integer $userid the id of the user.
* @return float the user's current grade for this quiz, or NULL if this user does
}
}
+/**
+ * Print a detailed representation of what a user has done with
+ * a given particular instance of this module, for user activity reports.
+ *
+ * @global object
+ * @param object $course
+ * @param object $user
+ * @param object $mod
+ * @param object $quiz
+ * @return bool
+ */
function quiz_user_complete($course, $user, $mod, $quiz) {
global $DB;
-/// Print a detailed representation of what a user has done with
-/// a given particular instance of this module, for user activity reports.
if ($attempts = $DB->get_records('quiz_attempts', array('userid' => $user->id, 'quiz' => $quiz->id), 'attempt')) {
if (quiz_has_grades($quiz) && $grade = quiz_get_best_grade($quiz, $user->id)) {
return true;
}
+/**
+ * Function to be run periodically according to the moodle cron
+ * This function searches for things that need to be done, such
+ * as sending out mail, toggling flags etc ...
+ *
+ * @global stdClass
+ * @return bool true
+ */
function quiz_cron() {
-/// Function to be run periodically according to the moodle cron
-/// This function searches for things that need to be done, such
-/// as sending out mail, toggling flags etc ...
-
global $CFG;
return true;
}
/**
+ * @global object
* @param integer $quizid the quiz id.
* @param integer $userid the userid.
* @param string $status 'all', 'finished' or 'unfinished' to control
+ * @param bool $includepreviews
* @return an array of all the user's attempts at this quiz. Returns an empty array if there are none.
*/
function quiz_get_user_attempts($quizid, $userid=0, $status = 'finished', $includepreviews = false) {
/**
* Return grade for given user or all users.
*
+ * @global stdClass
+ * @global object
* @param int $quizid id of quiz
* @param int $userid optional user id, 0 means all users
* @return array array of grades, false if none. These are raw grades. They should
*
* @param object $quiz The quiz table row, only $quiz->decimalpoints is used.
* @param float $grade The grade to round.
+ * @return float
*/
function quiz_format_grade($quiz, $grade) {
return format_float($grade, $quiz->decimalpoints);
*
* @param object $quiz The quiz table row, only $quiz->decimalpoints is used.
* @param float $grade The grade to round.
+ * @return float
*/
function quiz_format_question_grade($quiz, $grade) {
if ($quiz->questiondecimalpoints == -1) {
/**
* Update grades in central gradebook
*
+ * @global stdClass
+ * @global object
* @param object $quiz
* @param int $userid specific user only, 0 means all
*/
/**
* Update all grades in gradebook.
+ *
+ * @global object
*/
function quiz_upgrade_grades() {
global $DB;
/**
* Create grade item for given quiz
*
+ * @global stdClass
+ * @uses GRADE_TYPE_VALUE
+ * @uses GRADE_TYPE_NONE
+ * @uses QUIZ_REVIEW_SCORES
+ * @uses QUIZ_REVIEW_CLOSED
+ * @uses QUIZ_REVIEW_OPEN
+ * @uses PARAM_INT
+ * @uses GRADE_UPDATE_ITEM_LOCKED
* @param object $quiz object with extra cmidnumber
- * @param mixed optional array/object of grade(s); 'reset' means reset grades in gradebook
+ * @param mixed $grades optional array/object of grade(s); 'reset' means reset grades in gradebook
* @return int 0 if ok, error code otherwise
*/
function quiz_grade_item_update($quiz, $grades=NULL) {
/**
* Delete grade item for given quiz
*
+ * @global stdClass
* @param object $quiz object
* @return object quiz
*/
QUIZ_ATTEMPTLAST => get_string('attemptlast', 'quiz'));
}
+/**
+ * Returns an array of users who have data in a given quiz
+ *
+ * @global stdClass
+ * @global object
+ * @param int $quizid
+ * @return array
+ */
function quiz_get_participants($quizid) {
-/// Returns an array of users who have data in a given quiz
global $CFG, $DB;
//Get users from attempts
}
+/**
+ * This standard function will check all instances of this module
+ * and make sure there are up-to-date events created for each of them.
+ * If courseid = 0, then every quiz event in the site is checked, else
+ * only quiz events belonging to the course specified are checked.
+ * This function is used, in its new format, by restore_refresh_events()
+ *
+ * @global object
+ * @uses QUIZ_MAX_EVENT_LENGTH
+ * @param int $courseid
+ * @return bool
+ */
function quiz_refresh_events($courseid = 0) {
global $DB;
-// This standard function will check all instances of this module
-// and make sure there are up-to-date events created for each of them.
-// If courseid = 0, then every quiz event in the site is checked, else
-// only quiz events belonging to the course specified are checked.
-// This function is used, in its new format, by restore_refresh_events()
if ($courseid == 0) {
if (! $quizzes = $DB->get_records('quiz')) {
/**
* Returns all quiz graded users since a given time for specified quiz
+ *
+ * @global stdClass
+ * @global object
+ * @global object
+ * @global object
+ * @uses CONTEXT_MODULE
+ * @param array $activities By reference
+ * @param int $index By reference
+ * @param int $timestart
+ * @param int $courseid
+ * @param int $cmid
+ * @param int $userid
+ * @param int $groupid
+ * @return void
*/
function quiz_get_recent_mod_activity(&$activities, &$index, $timestart, $courseid, $cmid, $userid=0, $groupid=0) {
global $CFG, $COURSE, $USER, $DB;
return;
}
+/**
+ * @global stdClass
+ * @param object $activity
+ * @param int $courseid
+ * @param bool $detail
+ * @param array $modnames
+ * @return void output is echo'd
+ */
function quiz_print_recent_mod_activity($activity, $courseid, $detail, $modnames) {
global $CFG;
* Pre-process the quiz options form data, making any necessary adjustments.
* Called by add/update instance in this file.
*
+ * @uses QUIZ_REVIEW_OVERALLFEEDBACK
+ * @uses QUIZ_REVIEW_CLOSED
+ * @uses QUIZ_REVIEW_OPEN
+ * @uses QUIZ_REVIEW_IMMEDIATELY
+ * @uses QUIZ_REVIEW_GENERALFEEDBACK
+ * @uses QUIZ_REVIEW_SOLUTIONS
+ * @uses QUIZ_REVIEW_ANSWERS
+ * @uses QUIZ_REVIEW_FEEDBACK
+ * @uses QUIZ_REVIEW_SCORES
+ * @uses QUIZ_REVIEW_RESPONSES
+ * @uses QUESTION_ADAPTIVE
* @param object $quiz The variables set on the form.
+ * @return string
*/
function quiz_process_options(&$quiz) {
$quiz->timemodified = time();
* This function is called at the end of quiz_add_instance
* and quiz_update_instance, to do the common processing.
*
+ * @global object
+ * @uses QUIZ_MAX_EVENT_LENGTH
* @param object $quiz the quiz object.
+ * @return void|string Void or error message
*/
function quiz_after_add_or_update($quiz) {
global $DB;
quiz_grade_item_update($quiz);
}
+/**
+ * @return array
+ */
function quiz_get_view_actions() {
return array('view', 'view all', 'report', 'review');
}
+/**
+ * @return array
+ */
function quiz_get_post_actions() {
return array('attempt', 'close attempt', 'preview', 'editquestions', 'delete attempt', 'manualgrade');
}
/**
* Returns an array of names of quizzes that use this question
*
+ * @global stdClass
+ * @global object
* @param object $questionid
* @return array of strings
*/
/**
* Implementation of the function for printing the form elements that control
* whether the course reset functionality affects the quiz.
+ *
* @param $mform form passed by reference
*/
function quiz_reset_course_form_definition(&$mform) {
/**
* Course reset form defaults.
+ * @return array
*/
function quiz_reset_course_form_defaults($course) {
return array('reset_quiz_attempts'=>1);
/**
* Removes all grades from gradebook
+ *
+ * @global stdClass
+ * @global object
* @param int $courseid
* @param string optional type
*/
* set and true.
*
* Also, move the quiz open and close dates, if the course start date is changing.
- * @param $data the data submitted from the reset course.
+ *
+ * @global stdClass
+ * @global object
+ * @param object $data the data submitted from the reset course.
* @return array status array
*/
function quiz_reset_userdata($data) {
* Checks whether the current user is allowed to view a file uploaded in a quiz.
* Teachers can view any from their courses, students can only view their own.
*
+ * @global object
+ * @global object
+ * @uses CONTEXT_COURSE
* @param int $attemptuniqueid int attempt id
* @param int $questionid int question id
* @return boolean to indicate access granted or denied
/**
* Prints quiz summaries on MyMoodle Page
+ *
+ * @global object
+ * @global object
+ * @param arry $courses
+ * @param array $htmlarray
*/
function quiz_print_overview($courses, &$htmlarray) {
global $USER, $CFG;
/**
* Return a textual summary of the number of attemtps that have been made at a particular quiz,
* returns '' if no attemtps have been made yet, unless $returnzero is passed as true.
+ *
+ * @global stdClass
+ * @global object
+ * @global object
* @param object $quiz the quiz object. Only $quiz->id is used at the moment.
* @param object $cm the cm object. Only $cm->course, $cm->groupmode and $cm->groupingid fields are used at the moment.
* @param boolean $returnzero if false (default), when no attempts have been made '' is returned instead of 'Attempts: 0'.
}
/**
+ * @uses FEATURE_GROUPS
+ * @uses FEATURE_GROUPINGS
+ * @uses FEATURE_GROUPMEMBERSONLY
+ * @uses FEATURE_MOD_INTRO
+ * @uses FEATURE_COMPLETION_TRACKS_VIEWS
+ * @uses FEATURE_GRADE_HAS_GRADE
+ * @uses FEATURE_GRADE_OUTCOMES
* @param string $feature FEATURE_xx constant for requested feature
* @return bool True if quiz supports feature
*/
}
/**
+ * @global object
+ * @global stdClass
* @return array all other caps used in module
*/
function quiz_get_extra_capabilities() {