diff --git a/backup/moodle1/lib.php b/backup/moodle1/lib.php index 64d2881a..b51b2bba 100644 --- a/backup/moodle1/lib.php +++ b/backup/moodle1/lib.php @@ -17,8 +17,7 @@ /** * Provides support for the conversion of moodle1 backup to the moodle2 format * - * @package mod - * @subpackage questionnaire + * @package mod_questionnaire * @copyright 2011 Robin de Vries * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ @@ -33,7 +32,7 @@ class moodle1_mod_questionnaire_handler extends moodle1_mod_handler { /** * Declare the paths in moodle.xml we are able to convert * - * The method returns list of {@link convert_path} instances. For each path returned, + * The method returns list of convert_path instances. For each path returned, * at least one of on_xxx_start(), process_xxx() and on_xxx_end() methods must be * defined. The method process_xxx() is not executed if the associated path element is * empty (i.e. it contains none elements or sub-paths only). @@ -42,7 +41,7 @@ class moodle1_mod_questionnaire_handler extends moodle1_mod_handler { * actually exist in the file. The last element with the module name was * appended by the moodle1_converter class. * - * @return array of {@link convert_path} instances + * @return array of convert_path instances */ public function get_paths() { return array( @@ -62,9 +61,11 @@ public function get_paths() { new convert_path('question_choice', '/MOODLE_BACKUP/COURSE/MODULES/MOD/QUESTIONNAIRE/SURVEY/QUESTION/QUESTION_CHOICE'), ); } + /** * This is executed every time we have one /MOODLE_BACKUP/COURSE/MODULES/MOD/QUESTIONNAIRE - * data available + * data available. + * @param array $data */ public function process_questionnaire($data) { // Get the course module id and context id. @@ -88,7 +89,6 @@ public function process_questionnaire($data) { /** * This is executed when we reach the closing tag of our 'questionnaire' path */ - public function on_questionnaire_end() { // Close questionnaire.xml. $this->xmlwriter->end_tag('surveys'); @@ -96,9 +96,11 @@ public function on_questionnaire_end() { $this->xmlwriter->end_tag('activity'); $this->close_xml_writer(); } + /** * This is executed every time we have one /MOODLE_BACKUP/COURSE/MODULES/MOD/QUESTIONNAIRE/SURVEY * data available + * @param array $data */ public function process_survey($data) { $this->xmlwriter->begin_tag('survey', array('id' => $data['id'])); @@ -120,6 +122,7 @@ public function on_survey_end() { /** * This is executed every time we have one /MOODLE_BACKUP/COURSE/MODULES/MOD/QUESTIONNAIRE/SURVEY/QUESTION * data available + * @param array $data */ public function process_question($data) { @@ -144,9 +147,9 @@ public function on_question_end() { /** * This is executed every time we have one /MOODLE_BACKUP/COURSE/MODULES/MOD/QUESTIONNAIRE/SURVEY/QUESTION/QUESTION_CHOICE * data available + * @param array $data */ public function process_question_choice($data) { $this->write_xml('quest_choice', $data, array('/question_choice/id')); } - } diff --git a/backup/moodle2/backup_questionnaire_activity_task.class.php b/backup/moodle2/backup_questionnaire_activity_task.class.php index 33e4e2aa..808672e8 100644 --- a/backup/moodle2/backup_questionnaire_activity_task.class.php +++ b/backup/moodle2/backup_questionnaire_activity_task.class.php @@ -14,13 +14,6 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * @package mod_questionnaire - * @copyright 2016 Mike Churchward (mike.churchward@poetgroup.org) - * @author Mike Churchward - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - defined('MOODLE_INTERNAL') || die(); // Because it exists (must). @@ -29,8 +22,11 @@ require_once($CFG->dirroot . '/mod/questionnaire/backup/moodle2/backup_questionnaire_settingslib.php'); /** - * questionnaire backup task that provides all the settings and steps to perform one - * complete backup of the activity + * Questionnaire backup task that provides all the settings and steps to perform one complete backup of the activity. + * @package mod_questionnaire + * @copyright 2016 Mike Churchward (mike.churchward@poetgroup.org) + * @author Mike Churchward + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class backup_questionnaire_activity_task extends backup_activity_task { @@ -52,6 +48,8 @@ protected function define_my_steps() { /** * Code the transformations to perform in the activity in * order to get transportable (encoded) links + * @param string $content + * @return array|string|string[]|null */ public static function encode_content_links($content) { global $CFG; diff --git a/backup/moodle2/backup_questionnaire_settingslib.php b/backup/moodle2/backup_questionnaire_settingslib.php index 8c7fd054..63f4c35d 100644 --- a/backup/moodle2/backup_questionnaire_settingslib.php +++ b/backup/moodle2/backup_questionnaire_settingslib.php @@ -15,6 +15,7 @@ // along with Moodle. If not, see . /** + * The required settingslib file. * @package mod_questionnaire * @copyright 2016 Mike Churchward (mike.churchward@poetgroup.org) * @author Mike Churchward diff --git a/backup/moodle2/backup_questionnaire_stepslib.php b/backup/moodle2/backup_questionnaire_stepslib.php index 0b0dafe9..7af614ca 100644 --- a/backup/moodle2/backup_questionnaire_stepslib.php +++ b/backup/moodle2/backup_questionnaire_stepslib.php @@ -14,24 +14,24 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +defined('MOODLE_INTERNAL') || die(); + /** + * Define all the backup steps that will be used by the backup_questionnaire_activity_task. + * + * Define the complete choice structure for backup, with file and id annotations. + * * @package mod_questionnaire * @copyright 2016 Mike Churchward (mike.churchward@poetgroup.org) * @author Mike Churchward * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - -defined('MOODLE_INTERNAL') || die(); - -/** - * Define all the backup steps that will be used by the backup_questionnaire_activity_task - */ - -/** - * Define the complete choice structure for backup, with file and id annotations - */ class backup_questionnaire_activity_structure_step extends backup_activity_structure_step { + /** + * Defines the backup structure. + * @return backup_nested_element + */ protected function define_structure() { global $DB; // To know if we are including userinfo. diff --git a/backup/moodle2/restore_questionnaire_activity_task.class.php b/backup/moodle2/restore_questionnaire_activity_task.class.php index 60f28beb..7f41e4c6 100644 --- a/backup/moodle2/restore_questionnaire_activity_task.class.php +++ b/backup/moodle2/restore_questionnaire_activity_task.class.php @@ -14,21 +14,17 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * @package mod_questionnaire - * @copyright 2016 Mike Churchward (mike.churchward@poetgroup.org) - * @author Mike Churchward - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - defined('MOODLE_INTERNAL') || die(); // Because it exists (must). require_once($CFG->dirroot . '/mod/questionnaire/backup/moodle2/restore_questionnaire_stepslib.php'); /** - * questionnaire restore task that provides all the settings and steps to perform one - * complete restore of the activity + * Questionnaire restore task that provides all the settings and steps to perform one complete restore of the activity. + * @package mod_questionnaire + * @copyright 2016 Mike Churchward (mike.churchward@poetgroup.org) + * @author Mike Churchward + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class restore_questionnaire_activity_task extends restore_activity_task { @@ -78,9 +74,9 @@ public static function define_decode_rules() { /** * Define the restore log rules that will be applied - * by the {@link restore_logs_processor} when restoring + * by the restore_logs_processor when restoring * questionnaire logs. It must return one array - * of {@link restore_log_rule} objects + * of restore_log_rule objects */ public static function define_restore_log_rules() { $rules = array(); @@ -97,9 +93,9 @@ public static function define_restore_log_rules() { /** * Define the restore log rules that will be applied - * by the {@link restore_logs_processor} when restoring + * by the restore_logs_processor when restoring * course logs. It must return one array - * of {@link restore_log_rule} objects + * of restore_log_rule objects * * Note this rules are applied when restoring course logs * by the restore final task, but are defined here at diff --git a/backup/moodle2/restore_questionnaire_stepslib.php b/backup/moodle2/restore_questionnaire_stepslib.php index 0a4b7799..7b537479 100644 --- a/backup/moodle2/restore_questionnaire_stepslib.php +++ b/backup/moodle2/restore_questionnaire_stepslib.php @@ -14,22 +14,18 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +defined('MOODLE_INTERNAL') || die(); + /** + * Define all the restore steps that will be used by the restore_questionnaire_activity_task. + * + * Structure step to restore one questionnaire activity. + * * @package mod_questionnaire * @copyright 2016 Mike Churchward (mike.churchward@poetgroup.org) * @author Mike Churchward * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - -defined('MOODLE_INTERNAL') || die(); - -/** - * Define all the restore steps that will be used by the restore_questionnaire_activity_task - */ - -/** - * Structure step to restore one questionnaire activity - */ class restore_questionnaire_activity_structure_step extends restore_activity_structure_step { /** @@ -47,6 +43,10 @@ class restore_questionnaire_activity_structure_step extends restore_activity_str */ protected $olddependencies = []; + /** + * Implementation of define_structure. + * @return mixed + */ protected function define_structure() { $paths = array(); @@ -110,6 +110,10 @@ protected function define_structure() { return $this->prepare_activity_structure($paths); } + /** + * Implementation of process_questionnaire. + * @param array $data + */ protected function process_questionnaire($data) { global $DB; @@ -126,6 +130,10 @@ protected function process_questionnaire($data) { $this->apply_activity_instance($newitemid); } + /** + * Process the survey table. + * @param array $data + */ protected function process_questionnaire_survey($data) { global $DB; @@ -146,6 +154,10 @@ protected function process_questionnaire_survey($data) { $DB->set_field('questionnaire', 'sid', $newitemid, array('id' => $this->get_new_parentid('questionnaire'))); } + /** + * Process the questions. + * @param array $data + */ protected function process_questionnaire_question($data) { global $DB; @@ -166,9 +178,9 @@ protected function process_questionnaire_question($data) { } /** + * Process the feedback sections. * $qid is unused, but is needed in order to get the $key elements of the array. Suppress PHPMD warning. - * - * @SuppressWarnings(PHPMD.UnusedLocalVariable) + * @param array $data */ protected function process_questionnaire_fb_sections($data) { global $DB; @@ -193,6 +205,10 @@ protected function process_questionnaire_fb_sections($data) { $this->set_mapping('questionnaire_fb_sections', $oldid, $newitemid, true); } + /** + * Process feedback. + * @param array $data + */ protected function process_questionnaire_feedback($data) { global $DB; @@ -205,6 +221,10 @@ protected function process_questionnaire_feedback($data) { $this->set_mapping('questionnaire_feedback', $oldid, $newitemid, true); } + /** + * Process question choices. + * @param array $data + */ protected function process_questionnaire_quest_choice($data) { global $CFG, $DB; @@ -234,6 +254,10 @@ protected function process_questionnaire_quest_choice($data) { $this->set_mapping('questionnaire_quest_choice', $oldid, $newitemid); } + /** + * Process dependencies. + * @param array $data + */ protected function process_questionnaire_dependency($data) { $data = (object)$data; @@ -245,11 +269,20 @@ protected function process_questionnaire_dependency($data) { } } + /** + * Process attempts (these are no longer used). + * @param array $data + * @return bool + */ protected function process_questionnaire_attempt($data) { // New structure will be completed in process_questionnaire_response. Nothing to do here any more. return true; } + /** + * Process responses. + * @param array $data + */ protected function process_questionnaire_response($data) { global $DB; @@ -269,6 +302,11 @@ protected function process_questionnaire_response($data) { $this->set_mapping('questionnaire_response', $oldid, $newitemid); } + /** + * Process boolean responses. + * @param array $data + * @throws dml_exception + */ protected function process_questionnaire_response_bool($data) { global $DB; @@ -280,6 +318,11 @@ protected function process_questionnaire_response_bool($data) { $DB->insert_record('questionnaire_response_bool', $data); } + /** + * Process date responses. + * @param array $data + * @throws dml_exception + */ protected function process_questionnaire_response_date($data) { global $DB; @@ -291,6 +334,11 @@ protected function process_questionnaire_response_date($data) { $DB->insert_record('questionnaire_response_date', $data); } + /** + * Process multiple responses. + * @param array $data + * @throws dml_exception + */ protected function process_questionnaire_response_multiple($data) { global $DB; @@ -303,6 +351,11 @@ protected function process_questionnaire_response_multiple($data) { $DB->insert_record('questionnaire_resp_multiple', $data); } + /** + * Process other responses. + * @param array $data + * @throws dml_exception + */ protected function process_questionnaire_response_other($data) { global $DB; @@ -315,6 +368,11 @@ protected function process_questionnaire_response_other($data) { $DB->insert_record('questionnaire_response_other', $data); } + /** + * Process rank responses. + * @param array $data + * @throws dml_exception + */ protected function process_questionnaire_response_rank($data) { global $DB; @@ -333,6 +391,11 @@ protected function process_questionnaire_response_rank($data) { $DB->insert_record('questionnaire_response_rank', $data); } + /** + * Process single responses. + * @param array $data + * @throws dml_exception + */ protected function process_questionnaire_response_single($data) { global $DB; @@ -345,6 +408,10 @@ protected function process_questionnaire_response_single($data) { $DB->insert_record('questionnaire_resp_single', $data); } + /** + * Process text answers. + * @param array $data + */ protected function process_questionnaire_response_text($data) { global $DB; @@ -356,6 +423,9 @@ protected function process_questionnaire_response_text($data) { $DB->insert_record('questionnaire_response_text', $data); } + /** + * Stuff to do after execution. + */ protected function after_execute() { global $DB; diff --git a/classes/db/bulk_sql_config.php b/classes/db/bulk_sql_config.php index 82272b97..cc3a1e0d 100644 --- a/classes/db/bulk_sql_config.php +++ b/classes/db/bulk_sql_config.php @@ -53,6 +53,7 @@ class bulk_sql_config { protected $userank = false; /** + * The class constructor. * @param string $table * @param string $tablealias * @param bool $usechoiceid diff --git a/classes/edit_question_form.php b/classes/edit_question_form.php index 79c9ff55..6e10d60a 100644 --- a/classes/edit_question_form.php +++ b/classes/edit_question_form.php @@ -15,11 +15,11 @@ // along with Moodle. If not, see . /** + * The form class for editing questions. * @package mod_questionnaire * @copyright 2016 Mike Churchward (mike.churchward@poetgroup.org) * @author Mike Churchward & Joseph Rézeau * @license http://www.gnu.org/copyleft/gpl.html GNU Public License - * @package questionnaire */ namespace mod_questionnaire; @@ -36,6 +36,9 @@ */ class edit_question_form extends \moodleform { + /** + * Form definition. + */ public function definition() { // TODO - Find a way to not use globals. Maybe the base class allows more parameters to be passed? global $questionnaire, $question, $SESSION; @@ -55,6 +58,14 @@ public function definition() { } } + /** + * Form validation. + * + * @param array $data array of ("fieldname"=>value) of submitted data + * @param array $files array of uploaded files "element_name"=>tmp_file_path + * @return array of "element_name"=>"error_description" if there are errors, + * or an empty array if everything is OK (true allowed for backwards compatibility too). + */ public function validation($data, $files) { $errors = parent::validation($data, $files); @@ -86,7 +97,6 @@ public function validation($data, $files) { * Magic method for getting the protected $_form MoodleQuickForm and $_customdata array properties. * @param string $name * @return mixed - * @throws \coding_exception */ public function __get($name) { if ($name == '_form') { diff --git a/classes/event/question_created.php b/classes/event/question_created.php index da3f68c3..b480b678 100644 --- a/classes/event/question_created.php +++ b/classes/event/question_created.php @@ -14,38 +14,25 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * The mod_questionnaire question_created event. - * - * @package mod_questionnaire - * @copyright 2014 Joseph Rézeau - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - namespace mod_questionnaire\event; -defined('MOODLE_INTERNAL') || die(); - /** * The mod_questionnaire question_created event class. * * @package mod_questionnaire - * @since Moodle 2.7 * @copyright 2014 Joseph Rézeau * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - class question_created extends \core\event\base { - /* + /** * Set basic properties for the event. */ - protected function init() { $this->data['crud'] = 'c'; $this->data['edulevel'] = self::LEVEL_TEACHING; } - /* + /** * Return localised event name. * * @return string @@ -54,7 +41,7 @@ public static function get_name() { return get_string('event_question_created', 'mod_questionnaire'); } - /* + /** * Returns description of what happened. * * @return string diff --git a/classes/event/question_deleted.php b/classes/event/question_deleted.php index 34730ee2..900172b3 100644 --- a/classes/event/question_deleted.php +++ b/classes/event/question_deleted.php @@ -14,39 +14,25 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * The mod_questionnaire question_deleted event. - * - * @package mod_questionnaire - * @copyright 2014 Joseph Rézeau - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - namespace mod_questionnaire\event; -defined('MOODLE_INTERNAL') || die(); - /** * The mod_questionnaire question_deleted event class. * * @package mod_questionnaire - * @since Moodle 2.7 * @copyright 2014 Joseph Rézeau * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - - class question_deleted extends \core\event\base { - /* + /** * Set basic properties for the event. */ - protected function init() { $this->data['crud'] = 'd'; $this->data['edulevel'] = self::LEVEL_TEACHING; } - /* + /** * Return localised event name. * * @return string @@ -55,7 +41,7 @@ public static function get_name() { return get_string('event_question_deleted', 'mod_questionnaire'); } - /* + /** * Returns description of what happened. * * @return string diff --git a/classes/feedback/section.php b/classes/feedback/section.php index 7fbf0d3a..abcad77a 100644 --- a/classes/feedback/section.php +++ b/classes/feedback/section.php @@ -14,17 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Manage feedback sections. - * - * @package mod_questionnaire - * @copyright 2018 onward Mike Churchward (mike.churchward@poetopensource.org) - * @author Mike Churchward - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - namespace mod_questionnaire\feedback; -defined('MOODLE_INTERNAL') || die(); use invalid_parameter_exception; use coding_exception; @@ -32,23 +22,35 @@ /** * Class for describing a feedback section. * - * @author Mike Churchward - * @package feedback + * @package mod_questionnaire + * @copyright 2018 onward Mike Churchward (mike.churchward@poetopensource.org) + * @author Mike Churchward + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - class section { + /** @var int */ public $id = 0; + /** @var int */ public $surveyid = 0; + /** @var int */ public $section = 1; + /** @var array */ public $scorecalculation = []; + /** @var string */ public $sectionlabel = ''; + /** @var string */ public $sectionheading = ''; + /** @var string */ public $sectionheadingformat = FORMAT_HTML; + /** @var array */ public $sectionfeedback = []; + /** @var array */ public $questions = []; + /** The table name. */ const TABLE = 'questionnaire_fb_sections'; + /** Represents the "no score" setting. */ const NOSCORE = -1; /** @@ -80,7 +82,9 @@ public function __construct($questions, $params = []) { /** * Factory method to create a new, empty section and return an instance. - * + * @param int $surveyid + * @param string $sectionlabel + * @return section */ public static function new_section($surveyid, $sectionlabel = '') { global $DB; @@ -154,11 +158,8 @@ public function load_section($params) { /** * Loads the section feedback record into the proper array location. * - * @param $feedbackrec + * @param \stdClass $feedbackrec * @return int The id of the section feedback record. - * @throws \dml_exception - * @throws coding_exception - * @throws invalid_parameter_exception */ public function load_sectionfeedback($feedbackrec) { if (!isset($feedbackrec->id) || empty($feedbackrec->id)) { @@ -174,8 +175,7 @@ public function load_sectionfeedback($feedbackrec) { /** * Updates the object and data record with a new scorecalculation. If no new score provided, uses what's in the object. * - * @param $scorecalculation - * @throws \dml_exception + * @param array $scorecalculation * @throws coding_exception */ public function set_new_scorecalculation($scorecalculation = null) { @@ -261,6 +261,7 @@ public function update() { } /** + * Return the decoded calculation array/ * @param string $codedstring * @return mixed * @throws coding_exception @@ -292,6 +293,7 @@ protected function decode_scorecalculation($codedstring) { } /** + * Return the encoded score array as a serialized string. * @param string $scorearray * @return mixed * @throws coding_exception diff --git a/classes/feedback/sectionfeedback.php b/classes/feedback/sectionfeedback.php index bd4a4cc5..69e56291 100644 --- a/classes/feedback/sectionfeedback.php +++ b/classes/feedback/sectionfeedback.php @@ -14,17 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Manage feedback sections. - * - * @package mod_questionnaire - * @copyright 2018 onward Mike Churchward (mike.churchward@poetopensource.org) - * @author Mike Churchward - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - namespace mod_questionnaire\feedback; -defined('MOODLE_INTERNAL') || die(); use invalid_parameter_exception; use coding_exception; @@ -32,28 +22,34 @@ /** * Class for describing a feedback section's feedback definition. * - * @author Mike Churchward - * @package feedback + * @package mod_questionnaire + * @copyright 2018 onward Mike Churchward (mike.churchward@poetopensource.org) + * @author Mike Churchward + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - class sectionfeedback { - + /** @var int */ public $id = 0; + /** @var int */ public $sectionid = 0; + /** @var string */ public $feedbacklabel = ''; // I don't think this is actually used? + /** @var string */ public $feedbacktext = ''; + /** @var string */ public $feedbacktextformat = FORMAT_HTML; + /** @var float */ public $minscore = 0.0; + /** @var float */ public $maxscore = 0.0; + /** The table name. */ const TABLE = 'questionnaire_feedback'; /** + * Class constructor. * @param int $id * @param null|object $record - * @throws \dml_exception - * @throws coding_exception - * @throws invalid_parameter_exception */ public function __construct($id = 0, $record = null) { // Return a new section based on the data id. @@ -70,7 +66,8 @@ public function __construct($id = 0, $record = null) { /** * Factory method to create a new sectionfeedback from the provided data and return an instance. - * + * @param \stdClass $data + * @return sectionfeedback */ public static function new_sectionfeedback($data) { global $DB; @@ -99,9 +96,9 @@ public function update() { } /** - * @param $id + * Return the record specified by the id. + * @param int $id * @return mixed - * @throws \dml_exception */ protected function get_sectionfeedback($id) { global $DB; diff --git a/classes/feedback_form.php b/classes/feedback_form.php index bb40a609..a856e62a 100644 --- a/classes/feedback_form.php +++ b/classes/feedback_form.php @@ -14,6 +14,13 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace mod_questionnaire; + +defined('MOODLE_INTERNAL') || die(); + +require_once($CFG->libdir . '/formslib.php'); +require_once($CFG->dirroot.'/mod/questionnaire/lib.php'); + /** * Print the form to manage feedback settings. * @@ -22,16 +29,11 @@ * @author Joseph Rezeau * @license http://www.gnu.org/copyleft/gpl.html GNU Public License */ - -namespace mod_questionnaire; - -defined('MOODLE_INTERNAL') || die(); - -require_once($CFG->libdir . '/formslib.php'); -require_once($CFG->dirroot.'/mod/questionnaire/lib.php'); - class feedback_form extends \moodleform { + /** + * Defition of the form. + */ public function definition() { global $questionnaire; @@ -130,6 +132,12 @@ public function definition() { } } + /** + * Validate the data submitted. + * @param array $data + * @param array $files + * @return array + */ public function validation($data, $files) { $errors = parent::validation($data, $files); return $errors; diff --git a/classes/feedback_section_form.php b/classes/feedback_section_form.php index 7f47480f..740d5604 100644 --- a/classes/feedback_section_form.php +++ b/classes/feedback_section_form.php @@ -14,6 +14,13 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace mod_questionnaire; + +defined('MOODLE_INTERNAL') || die(); + +require_once($CFG->libdir . '/formslib.php'); +require_once($CFG->dirroot.'/mod/questionnaire/lib.php'); + /** * Print the form to add or edit a questionnaire-instance * @@ -22,18 +29,14 @@ * @author Joseph Rezeau (based on Quiz by Tim Hunt) * @license http://www.gnu.org/copyleft/gpl.html GNU Public License */ - -namespace mod_questionnaire; - -defined('MOODLE_INTERNAL') || die(); - -require_once($CFG->libdir . '/formslib.php'); -require_once($CFG->dirroot.'/mod/questionnaire/lib.php'); - class feedback_section_form extends \moodleform { + /** @var mixed $_feedbacks */ protected $_feedbacks; + /** + * Form definition. + */ public function definition() { global $questionnaire; @@ -175,6 +178,10 @@ public function definition() { $mform->closeHeaderBefore('buttonar'); } + /** + * Form preprocessing. + * @param array $toform + */ public function data_preprocessing(&$toform) { if (count($this->_feedbacks)) { $key = 0; @@ -200,6 +207,13 @@ public function data_preprocessing(&$toform) { } } } + + /** + * Form validation. + * @param array $data + * @param array $files + * @return array + */ public function validation($data, $files) { $errors = parent::validation($data, $files); @@ -250,7 +264,7 @@ public function validation($data, $files) { * form definition (new entry form); this function is used to load in data where values * already exist and data is being edited (edit entry form). * - * @param mixed $default_values object or array of default values + * @param array $defaultvalues */ public function set_data($defaultvalues) { if (is_object($defaultvalues)) { diff --git a/classes/file_storage.php b/classes/file_storage.php index 58ef4907..329e9dff 100644 --- a/classes/file_storage.php +++ b/classes/file_storage.php @@ -14,17 +14,15 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace mod_questionnaire; + /** + * Defines the file stoeage class for questionnaire. * @package mod_questionnaire * @copyright 2020 onwards Mike Churchward (mike.churchward@poetopensource.org) * @author Mike Churchward * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - -namespace mod_questionnaire; - -defined('MOODLE_INTERNAL') || die(); - class file_storage extends \file_storage { /** diff --git a/classes/generator/question_response.php b/classes/generator/question_response.php index 34d7ec8b..fc4c7221 100644 --- a/classes/generator/question_response.php +++ b/classes/generator/question_response.php @@ -14,20 +14,28 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace mod_questionnaire\generator; + +use mod_questionnaire\responsetype\response\response; + /** * Question response class * @author gthomas2 + * @copyright 2016 onward Mike Churchward (mike.churchward@poetopensource.org) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @package mod_questionnaire */ - -namespace mod_questionnaire\generator; - -defined('MOODLE_INTERNAL') || die(); - class question_response { + /** @var int $questionid */ public $questionid; + /** @var response $response */ public $response; + /** + * Class constructor. + * @param int $questionid + * @param response $response + */ public function __construct($questionid, $response) { $this->questionid = $questionid; $this->response = $response; diff --git a/classes/generator/question_response_rank.php b/classes/generator/question_response_rank.php index 7ff9690b..4ff25a7e 100644 --- a/classes/generator/question_response_rank.php +++ b/classes/generator/question_response_rank.php @@ -14,20 +14,28 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace mod_questionnaire\generator; + +use mod_questionnaire\question\choice; + /** * Question response rank class * @author gthomas2 + * @copyright 2016 onward Mike Churchward (mike.churchward@poetopensource.org) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @package mod_questionnaire */ - -namespace mod_questionnaire\generator; - -defined('MOODLE_INTERNAL') || die(); - class question_response_rank { + /** @var choice $choice */ public $choice; + /** @var int $rankvalue */ public $rankvalue; + /** + * Class constructor. + * @param choice $choice + * @param int $rank + */ public function __construct($choice, $rank) { $this->choice = $choice; $this->rankvalue = $rank; diff --git a/classes/output/completepage.php b/classes/output/completepage.php index b9438433..03192113 100644 --- a/classes/output/completepage.php +++ b/classes/output/completepage.php @@ -14,6 +14,8 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace mod_questionnaire\output; + /** * Contains class mod_questionnaire\output\viewpage * @@ -22,11 +24,6 @@ * @author Mike Churchward * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - -namespace mod_questionnaire\output; - -defined('MOODLE_INTERNAL') || die(); - class completepage implements \renderable, \templatable { /** @@ -49,8 +46,8 @@ public function __construct($data = null) { /** * Add data for export. - * @param string The index for the data. - * @param string The content for the index. + * @param string $element The index for the data. + * @param string $content The content for the index. */ public function add_to_page($element, $content) { if ($element !== 'questions') { diff --git a/classes/output/fbsectionspage.php b/classes/output/fbsectionspage.php index 034f4b2f..2c3b0cb1 100644 --- a/classes/output/fbsectionspage.php +++ b/classes/output/fbsectionspage.php @@ -14,6 +14,8 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace mod_questionnaire\output; + /** * Contains class mod_questionnaire\output\fbsectionspage * @@ -22,11 +24,6 @@ * @author Mike Churchward * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - -namespace mod_questionnaire\output; - -defined('MOODLE_INTERNAL') || die(); - class fbsectionspage implements \renderable, \templatable { /** @@ -49,8 +46,8 @@ public function __construct($data = null) { /** * Add data for export. - * @param string The index for the data. - * @param string The content for the index. + * @param string $element The index for the data. + * @param string $content The content for the index. */ public function add_to_page($element, $content) { $this->data->{$element} = empty($this->data->{$element}) ? $content : ($this->data->{$element} . $content); diff --git a/classes/output/feedbackpage.php b/classes/output/feedbackpage.php index 5856613a..21eed2c3 100644 --- a/classes/output/feedbackpage.php +++ b/classes/output/feedbackpage.php @@ -14,6 +14,8 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace mod_questionnaire\output; + /** * Contains class mod_questionnaire\output\feedback * @@ -22,11 +24,6 @@ * @author Mike Churchward * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - -namespace mod_questionnaire\output; - -defined('MOODLE_INTERNAL') || die(); - class feedbackpage implements \renderable, \templatable { /** @@ -49,8 +46,8 @@ public function __construct($data = null) { /** * Add data for export. - * @param string The index for the data. - * @param string The content for the index. + * @param string $element The index for the data. + * @param string $content The content for the index. */ public function add_to_page($element, $content) { $this->data->{$element} = empty($this->data->{$element}) ? $content : ($this->data->{$element} . $content); diff --git a/classes/output/mobile.php b/classes/output/mobile.php index 761f8156..0dd58aa4 100644 --- a/classes/output/mobile.php +++ b/classes/output/mobile.php @@ -14,16 +14,18 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace mod_questionnaire\output; + +use mod_questionnaire\responsetype\response\response; + /** * Mobile output class for mod_questionnaire. * - * @copyright 2018 Igor Sazonov - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @package mod_questionnaire + * @copyright 2016 Mike Churchward (mike.churchward@poetgroup.org) + * @author Mike Churchward + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -namespace mod_questionnaire\output; - -defined('MOODLE_INTERNAL') || die(); - class mobile { /** @@ -202,8 +204,10 @@ protected static function require_capability(\stdClass $cm, \context $context, s } /** - * @param $questionnaire - * @param $data + * Add the submissions. + * @param \questionnaire $questionnaire + * @param array $data + * @param int $userid */ protected static function add_index_data($questionnaire, &$data, $userid) { // List any existing submissions, if user is allowed to review them. @@ -226,9 +230,10 @@ protected static function add_index_data($questionnaire, &$data, $userid) { } /** - * @param $questionnaire - * @param $pagenum - * @param null $response + * Ass the questions for the page. + * @param \questionnaire $questionnaire + * @param int $pagenum + * @param response $response * @return array */ protected static function add_pagequestion_data($questionnaire, $pagenum, $response=null) { diff --git a/classes/output/nonrespondentspage.php b/classes/output/nonrespondentspage.php index fa7a1f95..4771ebf0 100644 --- a/classes/output/nonrespondentspage.php +++ b/classes/output/nonrespondentspage.php @@ -14,6 +14,8 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace mod_questionnaire\output; + /** * Contains class mod_questionnaire\output\viewpage * @@ -22,11 +24,6 @@ * @author Mike Churchward * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - -namespace mod_questionnaire\output; - -defined('MOODLE_INTERNAL') || die(); - class nonrespondentspage implements \renderable, \templatable { /** @@ -49,8 +46,8 @@ public function __construct($data = null) { /** * Add data for export. - * @param string The index for the data. - * @param string The content for the index. + * @param string $element The index for the data. + * @param string $content The content for the index. */ public function add_to_page($element, $content) { $this->data->{$element} = empty($this->data->{$element}) ? $content : ($this->data->{$element} . $content); diff --git a/classes/output/previewpage.php b/classes/output/previewpage.php index a19b62ab..82267de3 100644 --- a/classes/output/previewpage.php +++ b/classes/output/previewpage.php @@ -14,6 +14,8 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace mod_questionnaire\output; + /** * Contains class mod_questionnaire\output\viewpage * @@ -22,11 +24,6 @@ * @author Mike Churchward * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - -namespace mod_questionnaire\output; - -defined('MOODLE_INTERNAL') || die(); - class previewpage implements \renderable, \templatable { /** @@ -49,8 +46,8 @@ public function __construct($data = null) { /** * Add data for export. - * @param string The index for the data. - * @param string The content for the index. + * @param string $element The index for the data. + * @param string $content The content for the index. */ public function add_to_page($element, $content) { if ($element === 'questions') { diff --git a/classes/output/qsettingspage.php b/classes/output/qsettingspage.php index bea8ba7b..311a18d1 100644 --- a/classes/output/qsettingspage.php +++ b/classes/output/qsettingspage.php @@ -14,6 +14,8 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace mod_questionnaire\output; + /** * Contains class mod_questionnaire\output\viewpage * @@ -22,11 +24,6 @@ * @author Mike Churchward * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - -namespace mod_questionnaire\output; - -defined('MOODLE_INTERNAL') || die(); - class qsettingspage implements \renderable, \templatable { /** @@ -49,8 +46,8 @@ public function __construct($data = null) { /** * Add data for export. - * @param string The index for the data. - * @param string The content for the index. + * @param string $element The index for the data. + * @param string $content The content for the index. */ public function add_to_page($element, $content) { $this->data->{$element} = empty($this->data->{$element}) ? $content : ($this->data->{$element} . $content); diff --git a/classes/output/questionspage.php b/classes/output/questionspage.php index 3a655588..09ea8dd7 100644 --- a/classes/output/questionspage.php +++ b/classes/output/questionspage.php @@ -14,6 +14,8 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace mod_questionnaire\output; + /** * Contains class mod_questionnaire\output\viewpage * @@ -22,11 +24,6 @@ * @author Mike Churchward * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - -namespace mod_questionnaire\output; - -defined('MOODLE_INTERNAL') || die(); - class questionspage implements \renderable, \templatable { /** @@ -49,8 +46,8 @@ public function __construct($data = null) { /** * Add data for export. - * @param string The index for the data. - * @param string The content for the index. + * @param string $element The index for the data. + * @param string $content The content for the index. */ public function add_to_page($element, $content) { $this->data->{$element} = empty($this->data->{$element}) ? $content : ($this->data->{$element} . $content); diff --git a/classes/output/renderer.php b/classes/output/renderer.php index feb78320..5bc029b3 100755 --- a/classes/output/renderer.php +++ b/classes/output/renderer.php @@ -14,6 +14,10 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace mod_questionnaire\output; + +use mod_questionnaire\question\question; + /** * Contains class mod_questionnaire\output\renderer * @@ -22,11 +26,6 @@ * @author Mike Churchward * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - -namespace mod_questionnaire\output; - -defined('MOODLE_INTERNAL') || die(); - class renderer extends \plugin_renderer_base { /** * Main view page. @@ -167,7 +166,7 @@ public function complete_formend($inputs=[]) { /** * Render the completion form control buttons. - * @param array | string $inputs Name/(Type/attribute) array of input types and values used by the form. + * @param array|string $inputs Name/(Type/attribute) array of input types and values used by the form. * @return string The output for the page. */ public function complete_controlbuttons($inputs=null) { @@ -182,6 +181,12 @@ public function complete_controlbuttons($inputs=null) { return $output; } + /** + * Calculate the progress and return it. + * @param int $section + * @param array $questionsbysec + * @return float + */ private function calculate_progress($section, $questionsbysec) { $done = 0; $todo = 0; @@ -196,6 +201,12 @@ private function calculate_progress($section, $questionsbysec) { return round($done / ($done + $todo) * 100); } + /** + * Render the progress bar and return it. + * @param int $section + * @param array $questionsbysec + * @return bool|string + */ public function render_progress_bar($section, $questionsbysec) { $templatecontext['percent'] = $this->calculate_progress($section, $questionsbysec); $helpicon = new \help_icon('progresshelp', 'mod_questionnaire'); @@ -268,10 +279,9 @@ public function response_output($question, $response, $qnum=null, $pdf=false) { /** * Render all responses for a question. - * @param array \mod_questionnaire\responstype\response\response | string $responses - * @param array \mod_questionnaire\question\question $questions + * @param array|string $responses + * @param array $questions * @return string The output for the page. - * @throws \moodle_exception */ public function all_response_output($responses, $questions = null) { $output = ''; @@ -302,13 +312,12 @@ public function all_response_output($responses, $questions = null) { /** * Render a question results summary. - * @param mod_questionnaire\question\question $question The question object. + * @param question $question The question object. * @param array $rids The response ids. * @param string $sort The sort order being used. * @param string $anonymous The value of the anonymous setting. * @param bool $pdf * @return string The output for the page. - * @throws \moodle_exception */ public function results_output($question, $rids, $sort, $anonymous, $pdf = false) { $pagetags = $question->display_results($rids, $sort, $anonymous); @@ -392,9 +401,10 @@ public function homelink($url, $text) { /** - * @param $children - * @param $langstring - * @param $strnum + * Generate and return any dependency warnings. + * @param array $children + * @param string $langstring + * @param int $strnum * @return string */ public function dependency_warnings($children, $langstring, $strnum) { @@ -454,8 +464,8 @@ public function dependency_warnings($children, $langstring, $strnum) { /** * Get displayable list of parents for the question in questions_form. - * @param $qid The question id. - * @param $dependencies Array of dependency records for a question. + * @param int $qid The question id. + * @param array $dependencies Array of dependency records for a question. * @return string */ public function get_dependency_html($qid, $dependencies) { diff --git a/classes/output/reportpage.php b/classes/output/reportpage.php index ba00dad4..48a218a8 100644 --- a/classes/output/reportpage.php +++ b/classes/output/reportpage.php @@ -14,6 +14,8 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace mod_questionnaire\output; + /** * Contains class mod_questionnaire\output\viewpage * @@ -22,11 +24,6 @@ * @author Mike Churchward * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - -namespace mod_questionnaire\output; - -defined('MOODLE_INTERNAL') || die(); - class reportpage implements \renderable, \templatable { /** @@ -49,8 +46,8 @@ public function __construct($data = null) { /** * Add data for export. - * @param string The index for the data. - * @param string The content for the index. + * @param string $element The index for the data. + * @param string $content The content for the index. */ public function add_to_page($element, $content) { if ($element === 'responses') { diff --git a/classes/output/reportpagepdf.php b/classes/output/reportpagepdf.php index 5d2acae6..9e74f6cf 100644 --- a/classes/output/reportpagepdf.php +++ b/classes/output/reportpagepdf.php @@ -14,6 +14,8 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace mod_questionnaire\output; + /** * Contains class mod_questionnaire\output\reportpagepdf * @@ -22,11 +24,6 @@ * @author Mike Churchward * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - -namespace mod_questionnaire\output; - -defined('MOODLE_INTERNAL') || die(); - class reportpagepdf implements \renderable, \templatable { /** @@ -49,8 +46,8 @@ public function __construct($data = null) { /** * Add data for export. - * @param string The index for the data. - * @param string The content for the index. + * @param string $element The index for the data. + * @param string $content The content for the index. */ public function add_to_page($element, $content) { if ($element === 'responses') { diff --git a/classes/output/responsepagepdf.php b/classes/output/responsepagepdf.php index 4599d75d..ce7cbfab 100644 --- a/classes/output/responsepagepdf.php +++ b/classes/output/responsepagepdf.php @@ -14,6 +14,8 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace mod_questionnaire\output; + /** * Contains class mod_questionnaire\output\responsepagepdf * @@ -22,11 +24,6 @@ * @author Mike Churchward * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - -namespace mod_questionnaire\output; - -defined('MOODLE_INTERNAL') || die(); - class responsepagepdf implements \renderable, \templatable { /** @@ -49,8 +46,8 @@ public function __construct($data = null) { /** * Add data for export. - * @param string The index for the data. - * @param string The content for the index. + * @param string $element The index for the data. + * @param string $content The content for the index. */ public function add_to_page($element, $content) { if ($element === 'responses') { diff --git a/classes/output/viewpage.php b/classes/output/viewpage.php index 1a41446d..ab7462f5 100644 --- a/classes/output/viewpage.php +++ b/classes/output/viewpage.php @@ -14,6 +14,8 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace mod_questionnaire\output; + /** * Contains class mod_questionnaire\output\viewpage * @@ -22,11 +24,6 @@ * @author Mike Churchward * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - -namespace mod_questionnaire\output; - -defined('MOODLE_INTERNAL') || die(); - class viewpage implements \renderable, \templatable { /** @@ -49,8 +46,8 @@ public function __construct($data = null) { /** * Add data for export. - * @param string The index for the data. - * @param string The content for the index. + * @param string $element The index for the data. + * @param string $content The content for the index. */ public function add_to_page($element, $content) { $this->data->{$element} = empty($this->data->{$element}) ? $content : ($this->data->{$element} . $content); diff --git a/classes/privacy/provider.php b/classes/privacy/provider.php index 5c0829cd..3388857d 100644 --- a/classes/privacy/provider.php +++ b/classes/privacy/provider.php @@ -14,25 +14,22 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Contains class mod_questionnaire\privacy\provider - * - * @package mod_questionnaire - * @copyright 2018 onward Mike Churchward (mike.churchward@poetopensource.org) - * @author Mike Churchward - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - namespace mod_questionnaire\privacy; -defined('MOODLE_INTERNAL') || die(); - use \core_privacy\local\metadata\collection; use \core_privacy\local\request\contextlist; use \core_privacy\local\request\userlist; use \core_privacy\local\request\approved_contextlist; use \core_privacy\local\request\approved_userlist; +/** + * Contains class mod_questionnaire\privacy\provider + * + * @package mod_questionnaire + * @copyright 2018 onward Mike Churchward (mike.churchward@poetopensource.org) + * @author Mike Churchward + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ class provider implements // This plugin has data. \core_privacy\local\metadata\provider, @@ -46,7 +43,7 @@ class provider implements /** * Returns meta data about this system. * - * @param collection $items The collection to add metadata to. + * @param collection $collection The collection to add metadata to. * @return collection The array of metadata */ public static function get_metadata(collection $collection): collection { @@ -323,7 +320,7 @@ public static function delete_data_for_users(approved_userlist $userlist) { /** * Helper function to delete all the response records for a recordset array of responses. * - * @param recordset $responses The list of response records to delete for. + * @param \moodle_recordset $responses The list of response records to delete for. */ private static function delete_responses(\moodle_recordset $responses) { global $DB; diff --git a/classes/question/check.php b/classes/question/check.php index 654e1b66..f736ef8e 100644 --- a/classes/question/check.php +++ b/classes/question/check.php @@ -14,24 +14,30 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace mod_questionnaire\question; + /** * This file contains the parent class for check question types. * * @author Mike Churchward + * @copyright 2016 onward Mike Churchward (mike.churchward@poetopensource.org) * @license http://www.gnu.org/copyleft/gpl.html GNU Public License - * @package questiontypes + * @package mod_questionnaire */ - -namespace mod_questionnaire\question; -defined('MOODLE_INTERNAL') || die(); -use \html_writer; - class check extends question { + /** + * Return the responseclass used. + * @return string + */ protected function responseclass() { return '\\mod_questionnaire\\responsetype\\multiple'; } + /** + * Return the help name. + * @return string + */ public function helpname() { return 'checkboxes'; } @@ -45,7 +51,7 @@ public function has_choices() { /** * Override and return a form template if provided. Output of question_survey_display is iterpreted based on this. - * @return boolean | string + * @return string */ public function question_template() { return 'mod_questionnaire/question_check'; @@ -53,7 +59,7 @@ public function question_template() { /** * Override and return a form template if provided. Output of response_survey_display is iterpreted based on this. - * @return boolean | string + * @return string */ public function response_template() { return 'mod_questionnaire/response_check'; @@ -72,7 +78,7 @@ public function allows_dependents() { * @param \mod_questionnaire\responsetype\response\response $response * @param array $dependants Array of all questions/choices depending on this question. * @param boolean $blankquestionnaire - * @return object The check question context tags. + * @return \stdClass The check question context tags. * */ protected function question_survey_display($response, $dependants, $blankquestionnaire=false) { @@ -153,7 +159,7 @@ protected function question_survey_display($response, $dependants, $blankquestio /** * Return the context tags for the check response template. * @param \mod_questionnaire\responsetype\response\response $response - * @return object The check question response context tags. + * @return \stdClass The check question response context tags. */ protected function response_survey_display($response) { static $uniquetag = 0; // To make sure all radios have unique names. @@ -194,7 +200,7 @@ protected function response_survey_display($response) { /** * Check question's form data for valid response. Override this is type has specific format requirements. * - * @param object $responsedata The data entered into the response. + * @param \stdClass $responsedata The data entered into the response. * @return boolean */ public function response_valid($responsedata) { @@ -247,10 +253,20 @@ public function response_valid($responsedata) { return $valid; } + /** + * Return the length form element. + * @param \MoodleQuickForm $mform + * @param string $helptext + */ protected function form_length(\MoodleQuickForm $mform, $helptext = '') { return parent::form_length($mform, 'minforcedresponses'); } + /** + * Return the precision form element. + * @param \MoodleQuickForm $mform + * @param string $helptext + */ protected function form_precise(\MoodleQuickForm $mform, $helptext = '') { return parent::form_precise($mform, 'maxforcedresponses'); } @@ -266,6 +282,8 @@ public function supports_mobile() { /** * Preprocess choice data. + * @param \stdClass $formdata + * @return bool */ protected function form_preprocess_choicedata($formdata) { if (empty($formdata->allchoices)) { @@ -290,11 +308,10 @@ protected function form_preprocess_choicedata($formdata) { } /** - * @param $qnum - * @param $fieldkey + * Return the mobile question display. + * @param int $qnum * @param bool $autonum * @return \stdClass - * @throws \coding_exception */ public function mobile_question_display($qnum, $autonum = false) { $mobiledata = parent::mobile_question_display($qnum, $autonum); @@ -303,8 +320,8 @@ public function mobile_question_display($qnum, $autonum = false) { } /** - * @param $mobiledata - * @return mixed + * Return the mobile question choices display. + * @return array */ public function mobile_question_choices_display() { $choices = parent::mobile_question_choices_display(); @@ -320,7 +337,8 @@ public function mobile_question_choices_display() { } /** - * @param $response + * Return the mobile response data. + * @param \stdClass $response * @return array */ public function get_mobile_response_data($response) { diff --git a/classes/question/choice.php b/classes/question/choice.php index eb2d1a88..567d271c 100644 --- a/classes/question/choice.php +++ b/classes/question/choice.php @@ -14,18 +14,16 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace mod_questionnaire\question; + /** * This defines a structured class to hold question choices. * * @author Mike Churchward * @license http://www.gnu.org/copyleft/gpl.html GNU Public License - * @package response + * @package mod_questionnaire * @copyright 2019, onwards Poet */ - -namespace mod_questionnaire\question; -defined('MOODLE_INTERNAL') || die(); - class choice { // Class properties. @@ -47,10 +45,10 @@ class choice { /** * Choice constructor. - * @param null $id - * @param null $questionid - * @param null $content - * @param null $value + * @param int $id + * @param int $questionid + * @param string $content + * @param mixed $value */ public function __construct($id = null, $questionid = null, $content = null, $value = null) { $this->id = $id; @@ -80,7 +78,7 @@ public static function create_from_id($id) { /** * Create and return a choice object from data. * - * @param object | array $choicedata The data to load. + * @param \stdclass|array $choicedata The data to load. * @return choice */ public static function create_from_data($choicedata) { @@ -111,7 +109,9 @@ public static function tablename() { } /** - * + * Delete the choice record. + * @param int $id + * @return bool */ public static function delete_from_db_by_id($id) { global $DB; @@ -119,8 +119,8 @@ public static function delete_from_db_by_id($id) { } /** + * Delete this record from the DB. * @return bool - * @throws \dml_exception */ public function delete_from_db() { return self::delete_from_db_by_id($this->id); @@ -148,9 +148,8 @@ public function is_other_choice() { /** * Return the string to display for an "other" option content string. If the option is not an "other", return false. * - * @param $content - * @return string | bool - * @throws \coding_exception + * @param string $content + * @return string|bool */ public static function content_other_choice_display($content) { if (!self::content_is_other_choice($content)) { @@ -164,7 +163,7 @@ public static function content_other_choice_display($content) { /** * Return the string to display for an "other" option for this object. If the option is not an "other", return false. * - * @return string | bool + * @return string|bool */ public function other_choice_display() { return self::content_other_choice_display($this->content); @@ -172,7 +171,7 @@ public function other_choice_display() { /** * Is the content a named degree rate choice. - * @param $content + * @param string $content * @return array|bool */ public static function content_is_named_degree_choice($content) { @@ -203,8 +202,6 @@ public static function id_other_choice_name($choiceid) { /** * Return the string to use as an input name for an other choice. - * - * @param int $choiceid * @return string */ public function other_choice_name() { diff --git a/classes/question/date.php b/classes/question/date.php index 2d684cb0..c564c34b 100644 --- a/classes/question/date.php +++ b/classes/question/date.php @@ -14,24 +14,30 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace mod_questionnaire\question; + /** * This file contains the parent class for date question types. * * @author Mike Churchward + * @copyright 2016 onward Mike Churchward (mike.churchward@poetopensource.org) * @license http://www.gnu.org/copyleft/gpl.html GNU Public License - * @package questiontypes + * @package mod_questionnaire */ - -namespace mod_questionnaire\question; -defined('MOODLE_INTERNAL') || die(); -use \html_writer; - class date extends question { + /** + * Return the responseclass used. + * @return string + */ protected function responseclass() { return '\\mod_questionnaire\\responsetype\\date'; } + /** + * Return the help name. + * @return string + */ public function helpname() { return 'date'; } @@ -55,10 +61,9 @@ public function response_template() { /** * Return the context tags for the check question template. * @param \mod_questionnaire\responsetype\response\response $response - * @param $descendantsdata + * @param array $descendantsdata * @param boolean $blankquestionnaire * @return object The check question context tags. - * @throws \coding_exception */ protected function question_survey_display($response, $descendantsdata, $blankquestionnaire=false) { // Date. @@ -100,7 +105,7 @@ protected function response_survey_display($response) { /** * Check question's form data for valid response. Override this is type has specific format requirements. * - * @param object $responsedata The data entered into the response. + * @param \stdClass $responsedata The data entered into the response. * @return boolean */ public function response_valid($responsedata) { @@ -125,17 +130,29 @@ public function response_valid($responsedata) { } } + /** + * Return the form length. + * @param \MoodleQuickForm $mform + * @param string $helpname + * @return \MoodleQuickForm|void + */ protected function form_length(\MoodleQuickForm $mform, $helpname = '') { return question::form_length_hidden($mform); } + /** + * Return the form precision. + * @param \MoodleQuickForm $mform + * @param string $helpname + * @return \MoodleQuickForm|void + */ protected function form_precise(\MoodleQuickForm $mform, $helpname = '') { return question::form_precise_hidden($mform); } /** * Verify that the date provided is in the proper YYYY-MM-DD format. - * @param $date + * @param string $date * @return bool */ public function check_date_format($date) { @@ -187,11 +204,10 @@ public function supports_mobile() { } /** - * @param $qnum - * @param $fieldkey + * Does the question support mobile display. + * @param int $qnum * @param bool $autonum * @return \stdClass - * @throws \coding_exception */ public function mobile_question_display($qnum, $autonum = false) { $mobiledata = parent::mobile_question_display($qnum, $autonum); @@ -200,7 +216,7 @@ public function mobile_question_display($qnum, $autonum = false) { } /** - * @param $mobiledata + * Does the question have mobile choices. * @return mixed */ public function mobile_question_choices_display() { diff --git a/classes/question/drop.php b/classes/question/drop.php index 5044837c..17c49667 100644 --- a/classes/question/drop.php +++ b/classes/question/drop.php @@ -14,25 +14,33 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace mod_questionnaire\question; +use \html_writer; +use mod_questionnaire\question\choice; +use mod_questionnaire\responsetype\response\response; + /** * This file contains the parent class for drop question types. * * @author Mike Churchward + * @copyright 2016 onward Mike Churchward (mike.churchward@poetopensource.org) * @license http://www.gnu.org/copyleft/gpl.html GNU Public License - * @package questiontypes + * @package mod_questionnaire */ - -namespace mod_questionnaire\question; -defined('MOODLE_INTERNAL') || die(); -use \html_writer; -use mod_questionnaire\question\choice; - class drop extends question { + /** + * Each question type must define its response class. + * @return string The response object based off of questionnaire_response_base. + */ protected function responseclass() { return '\\mod_questionnaire\\responsetype\\single'; } + /** + * Short name for this question type - no spaces, etc.. + * @return string + */ public function helpname() { return 'dropdown'; } @@ -46,7 +54,7 @@ public function has_choices() { /** * Override and return a form template if provided. Output of question_survey_display is iterpreted based on this. - * @return boolean | string + * @return string */ public function question_template() { return 'mod_questionnaire/question_drop'; @@ -54,7 +62,7 @@ public function question_template() { /** * Override and return a form template if provided. Output of response_survey_display is iterpreted based on this. - * @return boolean | string + * @return string */ public function response_template() { return 'mod_questionnaire/response_drop'; @@ -62,7 +70,7 @@ public function response_template() { /** * Override this and return true if the question type allows dependent questions. - * @return boolean + * @return bool */ public function allows_dependents() { return true; @@ -70,6 +78,7 @@ public function allows_dependents() { /** * True if question type supports feedback options. False by default. + * @return bool */ public function supports_feedback() { return true; @@ -115,8 +124,7 @@ protected function question_survey_display($response, $dependants, $blankquestio /** * Return the context tags for the drop response template. * @param \mod_questionnaire\responsetype\response\response $response - * @return object The check question response context tags. - * @throws \coding_exception + * @return \stdClass The check question response context tags. */ protected function response_survey_display($response) { static $uniquetag = 0; // To make sure all radios have unique names. @@ -147,17 +155,26 @@ protected function response_survey_display($response) { return $resptags; } + /** + * Return the length form element. + * @param \MoodleQuickForm $mform + * @param string $helpname + */ protected function form_length(\MoodleQuickForm $mform, $helpname = '') { return question::form_length_hidden($mform); } + /** + * Return the precision form element. + * @param \MoodleQuickForm $mform + * @param string $helpname + */ protected function form_precise(\MoodleQuickForm $mform, $helpname = '') { return question::form_precise_hidden($mform); } /** * True if question provides mobile support. - * * @return bool */ public function supports_mobile() { @@ -165,11 +182,10 @@ public function supports_mobile() { } /** - * @param $qnum - * @param $fieldkey + * Return the mobile question display. + * @param int $qnum * @param bool $autonum * @return \stdClass - * @throws \coding_exception */ public function mobile_question_display($qnum, $autonum = false) { $mobiledata = parent::mobile_question_display($qnum, $autonum); @@ -178,7 +194,8 @@ public function mobile_question_display($qnum, $autonum = false) { } /** - * @param $response + * Return the mobile response data. + * @param response $response * @return array */ public function get_mobile_response_data($response) { diff --git a/classes/question/essay.php b/classes/question/essay.php index e37a9c35..a0256350 100644 --- a/classes/question/essay.php +++ b/classes/question/essay.php @@ -14,28 +14,30 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace mod_questionnaire\question; +use \html_writer; +use mod_questionnaire\responsetype\response\response; + /** * This file contains the parent class for essay question types. * * @author Mike Churchward + * @copyright 2016 onward Mike Churchward (mike.churchward@poetopensource.org) * @license http://www.gnu.org/copyleft/gpl.html GNU Public License - * @package questiontypes + * @package mod_questionnaire */ - -namespace mod_questionnaire\question; -defined('MOODLE_INTERNAL') || die(); -use \html_writer; - class essay extends text { /** - * @return object|string + * Each question type must define its response class. + * @return object The response object based off of questionnaire_response_base. */ protected function responseclass() { return '\\mod_questionnaire\\responsetype\\text'; } /** + * Short name for this question type - no spaces, etc.. * @return string */ public function helpname() { @@ -59,10 +61,11 @@ public function response_template() { } /** - * @param \mod_questionnaire\responsetype\response\response $response - * @param $descendantsdata + * Question specific display method. + * @param response $response + * @param array $descendantsdata * @param bool $blankquestionnaire - * @return object|string + * */ protected function question_survey_display($response, $descendantsdata, $blankquestionnaire=false) { $output = ''; @@ -102,8 +105,9 @@ protected function question_survey_display($response, $descendantsdata, $blankqu } /** - * @param \mod_questionnaire\responsetype\response\response $response - * @return object|string + * Question specific response display method. + * @param \stdClass $response + * */ protected function response_survey_display($response) { if (isset($response->answers[$this->id])) { @@ -120,11 +124,11 @@ protected function response_survey_display($response) { } // Note - intentianally returning 'precise' for length and 'length' for precise. + /** + * Return the length form element. * @param \MoodleQuickForm $mform * @param string $helptext - * @return \MoodleQuickForm|void - * @throws \coding_exception */ protected function form_length(\MoodleQuickForm $mform, $helptext = '') { $responseformats = array( @@ -137,7 +141,6 @@ protected function form_length(\MoodleQuickForm $mform, $helptext = '') { /** * True if question provides mobile support. - * * @return bool */ public function supports_mobile() { @@ -145,10 +148,9 @@ public function supports_mobile() { } /** + * Return the precision form element. * @param \MoodleQuickForm $mform * @param string $helptext - * @return \MoodleQuickForm|void - * @throws \coding_exception */ protected function form_precise(\MoodleQuickForm $mform, $helptext = '') { $choices = array(); diff --git a/classes/question/numerical.php b/classes/question/numerical.php index c078a77b..904f080a 100644 --- a/classes/question/numerical.php +++ b/classes/question/numerical.php @@ -14,39 +14,51 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace mod_questionnaire\question; + /** * This file contains the parent class for numeric question types. * * @author Mike Churchward + * @copyright 2016 onward Mike Churchward (mike.churchward@poetopensource.org) * @license http://www.gnu.org/copyleft/gpl.html GNU Public License - * @package questiontypes + * @package mod_questionnaire */ - -namespace mod_questionnaire\question; -defined('MOODLE_INTERNAL') || die(); - class numerical extends question { /** * Constructor. Use to set any default properties. - * + * @param int $id + * @param \stdClass $question + * @param string $context + * @param array $params */ public function __construct($id = 0, $question = null, $context = null, $params = []) { $this->length = 10; return parent::__construct($id, $question, $context, $params); } + /** + * Each question type must define its response class. + * + * @return string The response object based off of questionnaire_response_base. + * + */ protected function responseclass() { return '\\mod_questionnaire\\responsetype\\numericaltext'; } + /** + * Short name for this question type - no spaces, etc.. + * @return string + */ public function helpname() { return 'numeric'; } /** * Override and return a form template if provided. Output of question_survey_display is iterpreted based on this. - * @return boolean | string + * @return string */ public function question_template() { return 'mod_questionnaire/question_numeric'; @@ -54,7 +66,7 @@ public function question_template() { /** * Override and return a response template if provided. Output of response_survey_display is iterpreted based on this. - * @return boolean | string + * @return string */ public function response_template() { return 'mod_questionnaire/response_numeric'; @@ -63,10 +75,9 @@ public function response_template() { /** * Return the context tags for the check question template. * @param \mod_questionnaire\responsetype\response\response $response - * @param $descendantsdata + * @param array $descendantsdata * @param boolean $blankquestionnaire - * @return object The check question context tags. - * @throws \coding_exception + * @return \stdClass The check question context tags. */ protected function question_survey_display($response, $descendantsdata, $blankquestionnaire=false) { // Numeric. @@ -119,7 +130,7 @@ protected function question_survey_display($response, $descendantsdata, $blankqu /** * Check question's form data for valid response. Override this is type has specific format requirements. * - * @param object $responsedata The data entered into the response. + * @param \stdClass $responsedata The data entered into the response. * @return boolean */ public function response_valid($responsedata) { @@ -144,9 +155,8 @@ public function response_valid($responsedata) { /** * Return the context tags for the numeric response template. - * @param object $data - * @return object The numeric question response context tags. - * + * @param \mod_questionnaire\responsetype\response\response $response + * @return \stdClass The numeric question response context tags. */ protected function response_survey_display($response) { $resptags = new \stdClass(); @@ -157,18 +167,27 @@ protected function response_survey_display($response) { return $resptags; } + /** + * Return the length form element. + * @param \MoodleQuickForm $mform + * @param string $helptext + */ protected function form_length(\MoodleQuickForm $mform, $helptext = '') { $this->length = isset($this->length) ? $this->length : 10; return parent::form_length($mform, 'maxdigitsallowed'); } + /** + * Return the precision form element. + * @param \MoodleQuickForm $mform + * @param string $helptext + */ protected function form_precise(\MoodleQuickForm $mform, $helptext = '') { return parent::form_precise($mform, 'numberofdecimaldigits'); } /** * True if question provides mobile support. - * * @return bool */ public function supports_mobile() { @@ -176,11 +195,10 @@ public function supports_mobile() { } /** - * @param $qnum - * @param $fieldkey + * Return the mobile question display. + * @param int $qnum * @param bool $autonum * @return \stdClass - * @throws \coding_exception */ public function mobile_question_display($qnum, $autonum = false) { $mobiledata = parent::mobile_question_display($qnum, $autonum); @@ -189,7 +207,8 @@ public function mobile_question_display($qnum, $autonum = false) { } /** - * @return mixed + * Return the mobile question choices display. + * @return array */ public function mobile_question_choices_display() { $choices = []; diff --git a/classes/question/pagebreak.php b/classes/question/pagebreak.php index 48ef954b..c831641d 100644 --- a/classes/question/pagebreak.php +++ b/classes/question/pagebreak.php @@ -14,29 +14,30 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace mod_questionnaire\question; +use mod_questionnaire\edit_question_form; +use \questionnaire; + /** * This file contains the parent class for pagebreak question types. * * @author Mike Churchward + * @copyright 2016 onward Mike Churchward (mike.churchward@poetopensource.org) * @license http://www.gnu.org/copyleft/gpl.html GNU Public License - * @package questiontypes + * @package mod_questionnaire */ - -namespace mod_questionnaire\question; -use mod_questionnaire\edit_question_form; -use \questionnaire; -defined('MOODLE_INTERNAL') || die(); - class pagebreak extends question { /** - * @return object|string + * Each question type must define its response class. + * @return object The response object based off of questionnaire_response_base. */ protected function responseclass() { return ''; } /** + * Short name for this question type - no spaces, etc.. * @return string */ public function helpname() { @@ -44,35 +45,40 @@ public function helpname() { } /** + * Get the output for the start of the questions in a survey. * @param int $qnum - * @param null $response - * @return \stdClass|string + * @param \mod_questionnaire\responsetype\response\response $response + * @return \stdClass */ public function questionstart_survey_display($qnum, $response=null) { return ''; } /** - * @param object $data - * @param $descendantsdata + * Question specific display method. + * @param \stdClass $data + * @param array $descendantsdata * @param bool $blankquestionnaire - * @return string + * */ protected function question_survey_display($data, $descendantsdata, $blankquestionnaire=false) { return ''; } /** - * @param object $data - * @return string + * Question specific response display method. + * @param \stdClass $data + * */ protected function response_survey_display($data) { return ''; } /** - * @param edit_question_form $form - * @param questionnaire $questionnaire + * Override this, or any of the internal methods, to provide specific form data for editing the question type. + * The structure of the elements here is the default layout for the question form. + * @param edit_question_form $form The main moodleform object. + * @param questionnaire $questionnaire The questionnaire being edited. * @return bool */ public function edit_form(edit_question_form $form, questionnaire $questionnaire) { @@ -81,7 +87,6 @@ public function edit_form(edit_question_form $form, questionnaire $questionnaire /** * True if question provides mobile support. - * * @return bool */ public function supports_mobile() { @@ -90,12 +95,9 @@ public function supports_mobile() { /** * Override and return false if not supporting mobile app. - * - * @param $qnum - * @param $fieldkey + * @param int $qnum * @param bool $autonum * @return \stdClass - * @throws \coding_exception */ public function mobile_question_display($qnum, $autonum = false) { return false; diff --git a/classes/question/question.php b/classes/question/question.php index e1897422..b05eab7c 100644 --- a/classes/question/question.php +++ b/classes/question/question.php @@ -16,6 +16,7 @@ namespace mod_questionnaire\question; use mod_questionnaire\edit_question_form; +use mod_questionnaire\responsetype\response\response; use \questionnaire; defined('MOODLE_INTERNAL') || die(); @@ -25,17 +26,10 @@ * This file contains the parent class for questionnaire question types. * * @author Mike Churchward + * @copyright 2016 onward Mike Churchward (mike.churchward@poetopensource.org) * @license http://www.gnu.org/copyleft/gpl.html GNU Public License - * @package questiontypes + * @package mod_questionnaire */ - -/** - * Class for describing a question - * - * @author Mike Churchward - * @package questiontypes - */ - // Constants. define('QUESCHOOSE', 0); define('QUESYESNO', 1); @@ -55,6 +49,14 @@ require_once($CFG->dirroot.'/mod/questionnaire/locallib.php'); + +/** + * Class for describing a question + * + * @author Mike Churchward + * @copyright 2016 onward Mike Churchward (mike.churchward@poetopensource.org) + * @package mod_questionnaire + */ abstract class question { // Class Properties. @@ -125,7 +127,10 @@ abstract class question { /** * The class constructor - * + * @param int $id + * @param \stdClass $question + * @param \context $context + * @param array $params */ public function __construct($id = 0, $question = null, $context = null, $params = []) { global $DB; @@ -183,10 +188,10 @@ abstract public function helpname(); /** * Build a question from data. - * @var int $qtype The question type code. - * @var int|array|object $qdata Either the id of the record, or a structure containing the question data, or null. - * @var object $context The context for the question. - * @return A question object. + * @param int $qtype + * @param int|array $qdata + * @param \stdClass $context + * @return mixed */ public static function question_builder($qtype, $qdata = null, $context = null) { $qclassname = '\\mod_questionnaire\\question\\'.self::qtypename($qtype); @@ -201,7 +206,7 @@ public static function question_builder($qtype, $qdata = null, $context = null) /** * Return the different question type names. - * @param $qtype + * @param int $qtype * @return string */ public static function qtypename($qtype) { @@ -222,12 +227,14 @@ public static function qtypenames() { /** * Override and return true if the question has choices. + * @return bool */ public function has_choices() { return false; } /** + * Load any choices into the object. * @throws \dml_exception */ private function get_choices() { @@ -244,7 +251,7 @@ private function get_choices() { /** * Return true if this question has been marked as required. - * @return boolean + * @return bool */ public function required() { return ($this->required == 'y'); @@ -252,7 +259,7 @@ public function required() { /** * Return true if the question has defined dependencies. - * @return boolean + * @return bool */ public function has_dependencies() { return !empty($this->dependencies); @@ -260,14 +267,14 @@ public function has_dependencies() { /** * Override this and return true if the question type allows dependent questions. - * @return boolean + * @return bool */ public function allows_dependents() { return false; } /** - * @throws \dml_exception + * Load any dependencies. */ private function get_dependencies() { global $DB; @@ -370,7 +377,8 @@ public function dependency_fulfilled($rid, $questions) { } /** - * @return mixed + * Return the responsetype table for this question. + * @return string */ public function response_table() { return $this->responsetype->response_table(); @@ -378,8 +386,8 @@ public function response_table() { /** * Return true if the specified response for this question contains the specified choice. - * @param $rid - * @param $choiceid + * @param int $rid + * @param int $choiceid * @return bool */ public function response_has_choice($rid, $choiceid) { @@ -391,7 +399,7 @@ public function response_has_choice($rid, $choiceid) { /** * Insert response data method. - * @param object $responsedata All of the responsedata. + * @param \stdClass $responsedata All of the responsedata. * @return bool */ public function insert_response($responsedata) { @@ -405,6 +413,8 @@ public function insert_response($responsedata) { /** * Get results data method. + * @param array|bool $rids + * @return array|false */ public function get_results($rids = false) { if (isset ($this->responsetype) && is_object($this->responsetype) && @@ -417,6 +427,10 @@ public function get_results($rids = false) { /** * Display results method. + * @param bool $rids + * @param string $sort + * @param bool $anonymous + * @return false|string */ public function display_results($rids=false, $sort='', $anonymous=false) { if (isset ($this->responsetype) && is_object($this->responsetype) && @@ -449,14 +463,13 @@ public function get_notifications() { /** * Each question type must define its response class. - * * @return object The response object based off of questionnaire_response_base. - * */ abstract protected function responseclass(); /** * True if question type allows responses. + * @return bool */ public function supports_responses() { return !empty($this->responseclass()); @@ -464,6 +477,7 @@ public function supports_responses() { /** * True if question type supports feedback options. False by default. + * @return bool */ public function supports_feedback() { return false; @@ -471,6 +485,7 @@ public function supports_feedback() { /** * True if question type supports feedback scores and weights. Same as supports_feedback() by default. + * @return bool */ public function supports_feedback_scores() { return $this->supports_feedback(); @@ -478,6 +493,7 @@ public function supports_feedback_scores() { /** * True if the question supports feedback and has valid settings for feedback. Override if the default logic is not enough. + * @return bool */ public function valid_feedback() { if ($this->supports_feedback() && $this->has_choices() && $this->required() && !empty($this->name)) { @@ -486,15 +502,14 @@ public function valid_feedback() { return true; } } - } else { - return false; } + return false; } /** * Provide the feedback scores for all requested response id's. This should be provided only by questions that provide feedback. * @param array $rids - * @return array | boolean + * @return array|bool */ public function get_feedback_scores(array $rids) { if ($this->valid_feedback() && isset($this->responsetype) && is_object($this->responsetype) && @@ -507,7 +522,7 @@ public function get_feedback_scores(array $rids) { /** * Get the maximum score possible for feedback if appropriate. Override if default behaviour is not correct. - * @return int | boolean + * @return int|bool */ public function get_feedback_maxscore() { if ($this->valid_feedback()) { @@ -527,9 +542,8 @@ public function get_feedback_maxscore() { /** * Check question's form data for complete response. - * - * @param object $responsedata The data entered into the response. - * @return boolean + * @param \stdClass $responsedata The data entered into the response. + * @return bool */ public function response_complete($responsedata) { if (is_a($responsedata, 'mod_questionnaire\responsetype\response\response')) { @@ -554,9 +568,8 @@ public function response_complete($responsedata) { /** * Check question's form data for valid response. Override this if type has specific format requirements. - * - * @param object $responsedata The data entered into the response. - * @return boolean + * @param \stdClass $responsedata The data entered into the response. + * @return bool */ public function response_valid($responsedata) { return true; @@ -564,9 +577,8 @@ public function response_valid($responsedata) { /** * Update data record from object or optional question data. - * - * @param object $questionrecord An object with all updated question record data. - * @param boolean $updatechoices True if choices should also be updated. + * @param \stdClass $questionrecord An object with all updated question record data. + * @param bool $updatechoices True if choices should also be updated. */ public function update($questionrecord = null, $updatechoices = true) { global $DB; @@ -604,7 +616,7 @@ public function update($questionrecord = null, $updatechoices = true) { /** * Add the question to the database from supplied arguments. - * @param object $questionrecord The required data for adding the question. + * @param \stdClass $questionrecord The required data for adding the question. * @param array $choicerecords An array of choice records with 'content' and 'value' properties. * @param boolean $calcposition Whether or not to calculate the next available position in the survey. */ @@ -641,6 +653,7 @@ public function add($questionrecord, array $choicerecords = null, $calcposition } /** + * Update all choices. * @return bool */ public function update_choices() { @@ -665,9 +678,9 @@ public function update_choices() { } /** - * @param $choicerecord + * Update the choice with the choicerecord. + * @param \stdClass $choicerecord * @return bool - * @throws \dml_exception */ public function update_choice($choicerecord) { global $DB; @@ -675,9 +688,9 @@ public function update_choice($choicerecord) { } /** - * @param $choicerecord + * Add a new choice to the database. + * @param \stdClass $choicerecord * @return bool - * @throws \dml_exception */ public function add_choice($choicerecord) { global $DB; @@ -694,8 +707,7 @@ public function add_choice($choicerecord) { /** * Delete the choice from the question object and the database. - * - * @param integer|object $choice Either the integer id of the choice, or the choice record. + * @param int|\stdClass $choice Either the integer id of the choice, or the choice record. */ public function delete_choice($choice) { $retvalue = true; @@ -714,9 +726,8 @@ public function delete_choice($choice) { /** * Insert extradata field into db. This will be stored as a string. If a question needs a different format, override this. - * @param $extradata + * @param string $extradata * @return bool - * @throws \dml_exception */ public function insert_extradata($extradata) { global $DB; @@ -724,9 +735,9 @@ public function insert_extradata($extradata) { } /** - * @param $dependencyrecord + * Update the dependency record. + * @param \stdClass $dependencyrecord * @return bool - * @throws \dml_exception */ public function update_dependency($dependencyrecord) { global $DB; @@ -734,9 +745,9 @@ public function update_dependency($dependencyrecord) { } /** - * @param $dependencyrecord + * Add a dependency record. + * @param \stdClass $dependencyrecord * @return bool - * @throws \dml_exception */ public function add_dependency($dependencyrecord) { global $DB; @@ -756,8 +767,7 @@ public function add_dependency($dependencyrecord) { /** * Delete the dependency from the question object and the database. - * - * @param integer|object $dependency Either the integer id of the dependency, or the dependency record. + * @param int|\stdClass $dependency Either the integer id of the dependency, or the dependency record. */ public function delete_dependency($dependency) { global $DB; @@ -778,8 +788,7 @@ public function delete_dependency($dependency) { /** * Set the question required field in the object and database. - * - * @param boolean $required Whether question should be required or not. + * @param bool $required Whether question should be required or not. */ public function set_required($required) { global $DB; @@ -796,26 +805,23 @@ public function set_required($required) { /** * Question specific display method. - * - * @param object $formdata - * @param array $descendantdata - * @param boolean $blankquestionnaire + * @param \stdClass $formdata + * @param array $descendantsdata + * @param bool $blankquestionnaire * */ abstract protected function question_survey_display($formdata, $descendantsdata, $blankquestionnaire); /** * Question specific response display method. - * - * @param object $data - * @param integer $qnum + * @param \stdClass $data * */ abstract protected function response_survey_display($data); /** * Override and return a form template if provided. Output of question_survey_display is iterpreted based on this. - * @return boolean | string + * @return bool|string */ public function question_template() { return false; @@ -823,7 +829,7 @@ public function question_template() { /** * Override and return a form template if provided. Output of response_survey_display is iterpreted based on this. - * @return boolean | string + * @return bool|string */ public function response_template() { return false; @@ -832,7 +838,7 @@ public function response_template() { /** * Override and return a form template if provided. Output of results_output is iterpreted based on this. * @param bool $pdf - * @return boolean | string + * @return bool|string */ public function results_template($pdf = false) { if (isset ($this->responsetype) && is_object($this->responsetype) && @@ -848,7 +854,7 @@ public function results_template($pdf = false) { * @param \mod_questionnaire\responsetype\response\response $response * @param boolean $blankquestionnaire * @param array $dependants Array of all questions/choices depending on this question. - * @param integer $qnum + * @param int $qnum * @return \stdClass */ public function question_output($response, $blankquestionnaire, $dependants=[], $qnum='') { @@ -871,10 +877,9 @@ public function response_output($response, $qnum='') { /** * Get the output for the start of the questions in a survey. - * @param integer $qnum + * @param int $qnum * @param \mod_questionnaire\responsetype\response\response $response * @return \stdClass - * @throws \coding_exception */ public function questionstart_survey_display($qnum, $response=null) { global $OUTPUT, $SESSION, $questionnaire, $PAGE; @@ -1013,9 +1018,9 @@ public function edit_form(edit_question_form $form, questionnaire $questionnaire } /** + * Add the form header. * @param \MoodleQuickForm $mform * @param string $helpname - * @throws \coding_exception */ protected function form_header(\MoodleQuickForm $mform, $helpname = '') { // Display different messages for new question creation and existing question modification. @@ -1033,9 +1038,9 @@ protected function form_header(\MoodleQuickForm $mform, $helpname = '') { } /** + * Add the form name field. * @param \MoodleQuickForm $mform * @return \MoodleQuickForm - * @throws \coding_exception */ protected function form_name(\MoodleQuickForm $mform) { $mform->addElement('text', 'name', get_string('optionalname', 'questionnaire'), @@ -1046,9 +1051,9 @@ protected function form_name(\MoodleQuickForm $mform) { } /** + * Add the form required field. * @param \MoodleQuickForm $mform * @return \MoodleQuickForm - * @throws \coding_exception */ protected function form_required(\MoodleQuickForm $mform) { $reqgroup = []; @@ -1060,6 +1065,7 @@ protected function form_required(\MoodleQuickForm $mform) { } /** + * Return the length form element. * @param \MoodleQuickForm $mform * @param string $helpname */ @@ -1068,6 +1074,7 @@ protected function form_length(\MoodleQuickForm $mform, $helpname = '') { } /** + * Return the precision form element. * @param \MoodleQuickForm $mform * @param string $helpname */ @@ -1076,9 +1083,9 @@ protected function form_precise(\MoodleQuickForm $mform, $helpname = '') { } /** - * @param \MoodleQuickForm $mform The moodle form to add elements to. - * @param $questionnaire - * @param $editquestionformobject + * Determine form dependencies. + * @param \MoodleQuickForm $form The moodle form to add elements to. + * @param array $questions * @return bool */ protected function form_dependencies($form, $questions) { @@ -1165,10 +1172,10 @@ protected function form_dependencies($form, $questions) { } /** + * Return the question text element. * @param \MoodleQuickForm $mform - * @param $context + * @param string $context * @return \MoodleQuickForm - * @throws \coding_exception */ protected function form_question_text(\MoodleQuickForm $mform, $context) { $editoroptions = ['maxfiles' => EDITOR_UNLIMITED_FILES, 'trusttext' => true, 'context' => $context]; @@ -1179,9 +1186,9 @@ protected function form_question_text(\MoodleQuickForm $mform, $context) { } /** + * Add the choices to the form. * @param \MoodleQuickForm $mform * @return string - * @throws \coding_exception */ protected function form_choices(\MoodleQuickForm $mform) { if ($this->has_choices()) { @@ -1224,6 +1231,7 @@ protected function form_extradata(\MoodleQuickForm $mform, $helpname = '') { // Helper functions for commonly used editing functions. /** + * Add the length element as hidden. * @param \MoodleQuickForm $mform * @param int $value * @return \MoodleQuickForm @@ -1235,11 +1243,11 @@ public static function form_length_hidden(\MoodleQuickForm $mform, $value = 0) { } /** + * Add the length element as text. * @param \MoodleQuickForm $mform * @param string $helpname * @param int $value * @return \MoodleQuickForm - * @throws \coding_exception */ public static function form_length_text(\MoodleQuickForm $mform, $helpname = '', $value = 0) { $mform->addElement('text', 'length', get_string($helpname, 'questionnaire'), ['size' => '1'], $value); @@ -1251,6 +1259,7 @@ public static function form_length_text(\MoodleQuickForm $mform, $helpname = '', } /** + * Add the precise element as hidden. * @param \MoodleQuickForm $mform * @param int $value * @return \MoodleQuickForm @@ -1262,6 +1271,7 @@ public static function form_precise_hidden(\MoodleQuickForm $mform, $value = 0) } /** + * Add the precise element as text. * @param \MoodleQuickForm $mform * @param string $helpname * @param int $value @@ -1279,6 +1289,8 @@ public static function form_precise_text(\MoodleQuickForm $mform, $helpname = '' /** * Create and update question data from the forms. + * @param \stdClass $formdata + * @param questionnaire $questionnaire */ public function form_update($formdata, $questionnaire) { global $DB; @@ -1460,6 +1472,8 @@ public function form_update($formdata, $questionnaire) { /** * Any preprocessing of general data. + * @param \stdClass $formdata + * @return bool */ protected function form_preprocess_data($formdata) { if ($this->has_choices()) { @@ -1504,6 +1518,8 @@ protected function form_preprocess_data($formdata) { /** * Override this function for question specific choice preprocessing. + * @param \stdClass $formdata + * @return false */ protected function form_preprocess_choicedata($formdata) { if (empty($formdata->allchoices)) { @@ -1514,7 +1530,6 @@ protected function form_preprocess_choicedata($formdata) { /** * True if question provides mobile support. - * * @return bool */ public function supports_mobile() { @@ -1523,12 +1538,9 @@ public function supports_mobile() { /** * Override and return false if not supporting mobile app. - * - * @param $qnum - * @param $fieldkey + * @param int $qnum * @param bool $autonum * @return \stdClass - * @throws \coding_exception */ public function mobile_question_display($qnum, $autonum = false) { $options = ['noclean' => true, 'para' => false, 'filter' => true, @@ -1560,6 +1572,7 @@ public function mobile_question_display($qnum, $autonum = false) { } /** + * Override and return false if not supporting mobile app. * @return array */ public function mobile_question_choices_display() { @@ -1578,7 +1591,7 @@ public function mobile_question_choices_display() { /** * Return a field key to be used by the mobile app. - * @param $choiceid + * @param int $choiceid * @return string */ public function mobile_fieldkey($choiceid = 0) { @@ -1590,7 +1603,8 @@ public function mobile_fieldkey($choiceid = 0) { } /** - * @param $response + * Return the mobile response data. + * @param response $response * @return array */ public function get_mobile_response_data($response) { diff --git a/classes/question/radio.php b/classes/question/radio.php index 06f23cea..ef1b1f80 100644 --- a/classes/question/radio.php +++ b/classes/question/radio.php @@ -14,24 +14,30 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace mod_questionnaire\question; + /** * This file contains the parent class for radio question types. * * @author Mike Churchward + * @copyright 2016 onward Mike Churchward (mike.churchward@poetopensource.org) * @license http://www.gnu.org/copyleft/gpl.html GNU Public License - * @package questiontypes + * @package mod_questionnaire */ - -namespace mod_questionnaire\question; - -defined('MOODLE_INTERNAL') || die(); - class radio extends question { + /** + * Each question type must define its response class. + * @return object The response object based off of questionnaire_response_base. + */ protected function responseclass() { return '\\mod_questionnaire\\responsetype\\single'; } + /** + * Short name for this question type - no spaces, etc.. + * @return string + */ public function helpname() { return 'radiobuttons'; } @@ -228,6 +234,11 @@ public function response_complete($responsedata) { } } + /** + * Return the length form element. + * @param \MoodleQuickForm $mform + * @param string $helptext + */ protected function form_length(\MoodleQuickForm $mform, $helptext = '') { $lengroup = []; $lengroup[] =& $mform->createElement('radio', 'length', '', get_string('vertical', 'questionnaire'), '0'); @@ -239,6 +250,11 @@ protected function form_length(\MoodleQuickForm $mform, $helptext = '') { return $mform; } + /** + * Return the precision form element. + * @param \MoodleQuickForm $mform + * @param string $helptext + */ protected function form_precise(\MoodleQuickForm $mform, $helptext = '') { return question::form_precise_hidden($mform); } @@ -253,11 +269,10 @@ public function supports_mobile() { } /** - * @param $qnum - * @param $fieldkey + * Override and return false if not supporting mobile app. + * @param int $qnum * @param bool $autonum * @return \stdClass - * @throws \coding_exception */ public function mobile_question_display($qnum, $autonum = false) { $mobiledata = parent::mobile_question_display($qnum, $autonum); @@ -266,8 +281,8 @@ public function mobile_question_display($qnum, $autonum = false) { } /** - * @param $mobiledata - * @return mixed + * Override and return false if not supporting mobile app. + * @return array */ public function mobile_question_choices_display() { $choices = parent::mobile_question_choices_display(); @@ -281,7 +296,8 @@ public function mobile_question_choices_display() { } /** - * @param $response + * Return the mobile response data. + * @param response $response * @return array */ public function get_mobile_response_data($response) { diff --git a/classes/question/rate.php b/classes/question/rate.php index d3d4d2d1..4e6e4e6c 100644 --- a/classes/question/rate.php +++ b/classes/question/rate.php @@ -14,25 +14,27 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace mod_questionnaire\question; + /** * This file contains the parent class for rate question types. * * @author Mike Churchward + * @copyright 2016 onward Mike Churchward (mike.churchward@poetopensource.org) * @license http://www.gnu.org/copyleft/gpl.html GNU Public License - * @package questiontypes + * @package mod_questionnaire */ - -namespace mod_questionnaire\question; -defined('MOODLE_INTERNAL') || die(); -use \html_writer; - class rate extends question { + /** @var array $nameddegrees */ public $nameddegrees = []; /** - * Constructor. Use to set any default properties. - * + * The class constructor + * @param int $id + * @param \stdClass $question + * @param \context $context + * @param array $params */ public function __construct($id = 0, $question = null, $context = null, $params = array()) { $this->length = 5; @@ -40,10 +42,18 @@ public function __construct($id = 0, $question = null, $context = null, $params $this->add_nameddegrees_from_extradata(); } + /** + * Each question type must define its response class. + * @return object The response object based off of questionnaire_response_base. + */ protected function responseclass() { return '\\mod_questionnaire\\responsetype\\rank'; } + /** + * Short name for this question type - no spaces, etc.. + * @return string + */ public function helpname() { return 'ratescale'; } @@ -73,7 +83,7 @@ public function response_template() { /** * Return true if rate scale type is set to "Normal". - * @param $scaletype + * @param int $scaletype * @return bool */ public static function type_is_normal_rate_scale($scaletype) { @@ -82,7 +92,7 @@ public static function type_is_normal_rate_scale($scaletype) { /** * Return true if rate scale type is set to "N/A column". - * @param $scaletype + * @param int $scaletype * @return bool */ public static function type_is_na_column($scaletype) { @@ -91,7 +101,7 @@ public static function type_is_na_column($scaletype) { /** * Return true if rate scale type is set to "No duplicate choices". - * @param $scaletype + * @param int $scaletype * @return bool */ public static function type_is_no_duplicate_choices($scaletype) { @@ -100,7 +110,7 @@ public static function type_is_no_duplicate_choices($scaletype) { /** * Return true if rate scale type is set to "Osgood". - * @param $scaletype + * @param int $scaletype * @return bool */ public static function type_is_osgood_rate_scale($scaletype) { @@ -177,8 +187,8 @@ public function get_feedback_maxscore() { /** * Return the context tags for the check question template. - * @param \mod_questionnaire\responsetype\response\response $data - * @param string $descendantdata + * @param \mod_questionnaire\responsetype\response\response $response + * @param string $descendantsdata * @param boolean $blankquestionnaire * @return object The check question context tags. * @@ -399,7 +409,7 @@ protected function question_survey_display($response, $descendantsdata, $blankqu /** * Return the context tags for the rate response template. * @param \mod_questionnaire\responsetype\response\response $response - * @return object The rate question response context tags. + * @return \stdClass The rate question response context tags. * @throws \coding_exception */ protected function response_survey_display($response) { @@ -540,7 +550,7 @@ protected function response_survey_display($response) { /** * Check question's form data for complete response. * - * @param object $responsedata The data entered into the response. + * @param \stdClass $responsedata The data entered into the response. * @return boolean * */ @@ -592,7 +602,7 @@ public function response_complete($responsedata) { /** * Check question's form data for valid response. Override this is type has specific format requirements. * - * @param object $responsedata The data entered into the response. + * @param \stdClass $responsedata The data entered into the response. * @return boolean */ public function response_valid($responsedata) { @@ -653,10 +663,20 @@ public function response_valid($responsedata) { } } + /** + * Return the length form element. + * @param \MoodleQuickForm $mform + * @param string $helptext + */ protected function form_length(\MoodleQuickForm $mform, $helptext = '') { return parent::form_length($mform, 'numberscaleitems'); } + /** + * Return the precision form element. + * @param \MoodleQuickForm $mform + * @param string $helptext + */ protected function form_precise(\MoodleQuickForm $mform, $helptext = '') { $precoptions = array("0" => get_string('normal', 'questionnaire'), "1" => get_string('notapplicablecolumn', 'questionnaire'), @@ -691,7 +711,8 @@ protected function form_extradata(\MoodleQuickForm $mform, $helpname = '') { } /** - * @param $formdata + * Any preprocessing of general data. + * @param \stdClass $formdata * @return bool */ protected function form_preprocess_data($formdata) { @@ -714,7 +735,9 @@ protected function form_preprocess_data($formdata) { } /** - * Preprocess choice data. + * Override this function for question specific choice preprocessing. + * @param \stdClass $formdata + * @return false */ protected function form_preprocess_choicedata($formdata) { if (empty($formdata->allchoices)) { @@ -757,9 +780,9 @@ protected function form_preprocess_choicedata($formdata) { } /** - * @param $choicerecord + * Update the choice with the choicerecord. + * @param \stdClass $choicerecord * @return bool - * @throws \dml_exception */ public function update_choice($choicerecord) { if ($nameddegree = \mod_questionnaire\question\choice::content_is_named_degree_choice($choicerecord->content)) { @@ -771,9 +794,9 @@ public function update_choice($choicerecord) { } /** - * @param $choicerecord + * Add a new choice to the database. + * @param \stdClass $choicerecord * @return bool - * @throws \dml_exception */ public function add_choice($choicerecord) { if ($nameddegree = \mod_questionnaire\question\choice::content_is_named_degree_choice($choicerecord->content)) { @@ -794,11 +817,10 @@ public function supports_mobile() { } /** - * @param $qnum - * @param $fieldkey + * Override and return false if not supporting mobile app. + * @param int $qnum * @param bool $autonum * @return \stdClass - * @throws \coding_exception */ public function mobile_question_display($qnum, $autonum = false) { $mobiledata = parent::mobile_question_display($qnum, $autonum); @@ -812,8 +834,8 @@ public function mobile_question_display($qnum, $autonum = false) { } /** - * @return mixed - * @throws \coding_exception + * Override and return false if not supporting mobile app. + * @return array */ public function mobile_question_choices_display() { $choices = []; @@ -908,8 +930,8 @@ public function mobile_question_choices_display() { } /** - * @return mixed - * @throws \coding_exception + * Display the rates question for mobile. + * @return array */ public function mobile_question_rates_display() { $rates = []; @@ -926,7 +948,8 @@ public function mobile_question_rates_display() { } /** - * @param $response + * Return the mobile response data. + * @param response $response * @return array */ public function get_mobile_response_data($response) { @@ -971,8 +994,7 @@ public function insert_nameddegrees(array $nameddegrees) { * Helper function used to move existing named degree choices for the specified question from the "quest_choice" table to the * "question" table. * @param int $qid - * @param \stdClass | null $questionrec - * @throws \dml_exception + * @param null|\stdClass $questionrec */ public static function move_nameddegree_choices(int $qid = 0, \stdClass $questionrec = null) { global $DB; @@ -1023,6 +1045,7 @@ public static function move_nameddegree_choices(int $qid = 0, \stdClass $questio * Helper function to move named degree choices for all questions, optionally for a specific surveyid. * This should only be called for an upgrade from before '2018110103', or from a restore operation for a version of a * questionnaire before '2018110103'. + * @param int|null $surveyid */ public static function move_all_nameddegree_choices(int $surveyid = null) { global $DB; diff --git a/classes/question/sectiontext.php b/classes/question/sectiontext.php index 1dc0d55d..38135965 100644 --- a/classes/question/sectiontext.php +++ b/classes/question/sectiontext.php @@ -14,27 +14,28 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace mod_questionnaire\question; + /** * This file contains the parent class for sectiontext question types. * * @author Mike Churchward + * @copyright 2016 onward Mike Churchward (mike.churchward@poetopensource.org) * @license http://www.gnu.org/copyleft/gpl.html GNU Public License - * @package questiontypes + * @package mod_questionnaire */ - -namespace mod_questionnaire\question; -defined('MOODLE_INTERNAL') || die(); - class sectiontext extends question { /** - * @return object|string + * Each question type must define its response class. + * @return object The response object based off of questionnaire_response_base. */ protected function responseclass() { return ''; } /** + * Short name for this question type - no spaces, etc.. * @return string */ public function helpname() { @@ -81,7 +82,7 @@ public function question_template() { /** * Return the context tags for the check question template. * @param \mod_questionnaire\responsetype\response\response $response - * @param array $dependants Array of all questions/choices depending on this question. + * @param array $descendantsdata Array of all questions/choices depending on this question. * @param boolean $blankquestionnaire * @return object The check question context tags. * @@ -138,8 +139,9 @@ protected function question_survey_display($response, $descendantsdata, $blankqu } /** - * @param object $data - * @return string + * Question specific response display method. + * @param \stdClass $data + * */ protected function response_survey_display($data) { return ''; @@ -156,6 +158,7 @@ public function response_complete($responsedata) { } /** + * Add the form required field. * @param \MoodleQuickForm $mform * @return \MoodleQuickForm */ @@ -164,18 +167,18 @@ protected function form_required(\MoodleQuickForm $mform) { } /** + * Return the length form element. * @param \MoodleQuickForm $mform * @param string $helpname - * @return \MoodleQuickForm|void */ protected function form_length(\MoodleQuickForm $mform, $helpname = '') { return question::form_length_hidden($mform); } /** + * Return the precision form element. * @param \MoodleQuickForm $mform * @param string $helpname - * @return \MoodleQuickForm|void */ protected function form_precise(\MoodleQuickForm $mform, $helpname = '') { return question::form_precise_hidden($mform); diff --git a/classes/question/text.php b/classes/question/text.php index 92abea9a..3bd12661 100644 --- a/classes/question/text.php +++ b/classes/question/text.php @@ -14,22 +14,24 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace mod_questionnaire\question; + /** * This file contains the parent class for text question types. * * @author Mike Churchward + * @copyright 2016 onward Mike Churchward (mike.churchward@poetopensource.org) * @license http://www.gnu.org/copyleft/gpl.html GNU Public License - * @package questiontypes + * @package mod_questionnaire */ - -namespace mod_questionnaire\question; -defined('MOODLE_INTERNAL') || die(); - class text extends question { /** - * Constructor. Use to set any default properties. - * + * The class constructor + * @param int $id + * @param \stdClass $question + * @param \context $context + * @param array $params */ public function __construct($id = 0, $question = null, $context = null, $params = []) { $this->length = 20; @@ -38,13 +40,15 @@ public function __construct($id = 0, $question = null, $context = null, $params } /** - * @return object|string + * Each question type must define its response class. + * @return object The response object based off of questionnaire_response_base. */ protected function responseclass() { return '\\mod_questionnaire\\responsetype\\text'; } /** + * Short name for this question type - no spaces, etc.. * @return string */ public function helpname() { @@ -68,11 +72,11 @@ public function response_template() { } /** - * Return the context tags for the check question template. - * @param \mod_questionnaire\responsetype\response\response $response - * @param $descendantsdata - * @param boolean $blankquestionnaire - * @return object The check question context tags. + * Question specific display method. + * @param \stdClass $response + * @param array $descendantsdata + * @param bool $blankquestionnaire + * */ protected function question_survey_display($response, $descendantsdata, $blankquestionnaire=false) { // Text Box. @@ -93,9 +97,8 @@ protected function question_survey_display($response, $descendantsdata, $blankqu } /** - * Return the context tags for the text response template. - * @param object $data - * @return object The radio question response context tags. + * Question specific response display method. + * @param \stdClass $response */ protected function response_survey_display($response) { $resptags = new \stdClass(); @@ -107,6 +110,7 @@ protected function response_survey_display($response) { } /** + * Return the length form element. * @param \MoodleQuickForm $mform * @param string $helptext */ @@ -115,6 +119,7 @@ protected function form_length(\MoodleQuickForm $mform, $helptext = '') { } /** + * Return the precision form element. * @param \MoodleQuickForm $mform * @param string $helptext */ @@ -124,7 +129,6 @@ protected function form_precise(\MoodleQuickForm $mform, $helptext = '') { /** * True if question provides mobile support. - * * @return bool */ public function supports_mobile() { @@ -132,11 +136,10 @@ public function supports_mobile() { } /** - * @param $qnum - * @param $fieldkey + * Override and return false if not supporting mobile app. + * @param int $qnum * @param bool $autonum * @return \stdClass - * @throws \coding_exception */ public function mobile_question_display($qnum, $autonum = false) { $mobiledata = parent::mobile_question_display($qnum, $autonum); @@ -145,8 +148,8 @@ public function mobile_question_display($qnum, $autonum = false) { } /** - * @param $mobiledata - * @return mixed + * Override and return false if not supporting mobile app. + * @return array */ public function mobile_question_choices_display() { $choices = []; diff --git a/classes/question/yesno.php b/classes/question/yesno.php index 99d08ff8..935c7ffe 100644 --- a/classes/question/yesno.php +++ b/classes/question/yesno.php @@ -14,30 +14,37 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace mod_questionnaire\question; + /** * This file contains the parent class for yesno question types. * * @author Mike Churchward + * @copyright 2016 onward Mike Churchward (mike.churchward@poetopensource.org) * @license http://www.gnu.org/copyleft/gpl.html GNU Public License - * @package questiontypes + * @package mod_questionnaire */ - -namespace mod_questionnaire\question; -defined('MOODLE_INTERNAL') || die(); - class yesno extends question { + /** + * Each question type must define its response class. + * @return object The response object based off of questionnaire_response_base. + */ protected function responseclass() { return '\\mod_questionnaire\\responsetype\\boolean'; } + /** + * Short name for this question type - no spaces, etc.. + * @return string + */ public function helpname() { return 'yesno'; } /** * Override and return a form template if provided. Output of question_survey_display is iterpreted based on this. - * @return boolean | string + * @return string */ public function question_template() { return 'mod_questionnaire/question_yesno'; @@ -45,7 +52,7 @@ public function question_template() { /** * Override and return a response template if provided. Output of question_survey_display is iterpreted based on this. - * @return boolean | string + * @return string */ public function response_template() { return 'mod_questionnaire/response_yesno'; @@ -53,7 +60,7 @@ public function response_template() { /** * Override this and return true if the question type allows dependent questions. - * @return boolean + * @return bool */ public function allows_dependents() { return true; @@ -61,6 +68,7 @@ public function allows_dependents() { /** * True if question type supports feedback options. False by default. + * @return bool */ public function supports_feedback() { return true; @@ -68,6 +76,7 @@ public function supports_feedback() { /** * True if the question supports feedback and has valid settings for feedback. Override if the default logic is not enough. + * @return bool */ public function valid_feedback() { return $this->required(); @@ -196,10 +205,20 @@ protected function response_survey_display($response) { return $resptags; } + /** + * Return the length form element. + * @param \MoodleQuickForm $mform + * @param string $helpname + */ protected function form_length(\MoodleQuickForm $mform, $helpname = '') { return question::form_length_hidden($mform); } + /** + * Return the precision form element. + * @param \MoodleQuickForm $mform + * @param string $helpname + */ protected function form_precise(\MoodleQuickForm $mform, $helpname = '') { return question::form_precise_hidden($mform); } @@ -214,11 +233,10 @@ public function supports_mobile() { } /** - * @param $qnum - * @param $fieldkey + * Override and return false if not supporting mobile app. + * @param int $qnum * @param bool $autonum * @return \stdClass - * @throws \coding_exception */ public function mobile_question_display($qnum, $autonum = false) { $mobiledata = parent::mobile_question_display($qnum, $autonum); @@ -227,8 +245,8 @@ public function mobile_question_display($qnum, $autonum = false) { } /** - * @return mixed - * @throws \coding_exception + * Override and return false if not supporting mobile app. + * @return array */ public function mobile_question_choices_display() { $choices = []; @@ -255,7 +273,8 @@ public function mobile_question_choices_display() { } /** - * @param $response + * Return the mobile response data. + * @param response $response * @return array */ public function get_mobile_response_data($response) { diff --git a/classes/questions_form.php b/classes/questions_form.php index fcc9b5c4..40966eb2 100644 --- a/classes/questions_form.php +++ b/classes/questions_form.php @@ -14,26 +14,35 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * @package mod_questionnaire - * @copyright 2016 Mike Churchward (mike.churchward@poetgroup.org) - * @author Mike Churchward & Joseph Rézeau - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - namespace mod_questionnaire; defined('MOODLE_INTERNAL') || die(); require_once($CFG->libdir . '/formslib.php'); +/** + * The form definition class for questions. + * + * @package mod_questionnaire + * @copyright 2016 Mike Churchward (mike.churchward@poetgroup.org) + * @author Mike Churchward & Joseph Rézeau + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ class questions_form extends \moodleform { + /** + * The constructor. + * @param mixed $action + * @param bool $moveq + */ public function __construct($action, $moveq=false) { $this->moveq = $moveq; return parent::__construct($action); } + /** + * Form definition. + */ public function definition() { global $CFG, $questionnaire, $SESSION; global $DB; @@ -367,9 +376,14 @@ public function definition() { $mform->addElement('html', ''); } + /** + * Form validation. + * @param array $data + * @param array $files + * @return array + */ public function validation($data, $files) { $errors = parent::validation($data, $files); return $errors; } - } diff --git a/classes/responsetype/answer/answer.php b/classes/responsetype/answer/answer.php index 63de9f23..7f9bab53 100644 --- a/classes/responsetype/answer/answer.php +++ b/classes/responsetype/answer/answer.php @@ -14,18 +14,16 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace mod_questionnaire\responsetype\answer; + /** * This defines a structured class to hold question answers. * * @author Mike Churchward * @license http://www.gnu.org/copyleft/gpl.html GNU Public License - * @package response + * @package mod_questionnaire * @copyright 2019, onwards Poet */ - -namespace mod_questionnaire\responsetype\answer; -defined('MOODLE_INTERNAL') || die(); - class answer { // Class properties. @@ -64,7 +62,7 @@ public function __construct($id = null, $responseid = null, $questionid = null, /** * Create and return an answer object from data. * - * @param \stdClass | array $answerdata The data to load. + * @param \stdClass|array $answerdata The data to load. * @return answer */ public static function create_from_data($answerdata) { diff --git a/classes/responsetype/boolean.php b/classes/responsetype/boolean.php index 04742f43..6dbe39de 100644 --- a/classes/responsetype/boolean.php +++ b/classes/responsetype/boolean.php @@ -14,16 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * This file contains the parent class for questionnaire question types. - * - * @author Mike Churchward - * @license http://www.gnu.org/copyleft/gpl.html GNU Public License - * @package questiontypes - */ - namespace mod_questionnaire\responsetype; -defined('MOODLE_INTERNAL') || die(); use coding_exception; use dml_exception; @@ -34,13 +25,17 @@ * Class for boolean response types. * * @author Mike Churchward - * @package response + * @copyright 2016 onward Mike Churchward (mike.churchward@poetopensource.org) + * @license http://www.gnu.org/copyleft/gpl.html GNU Public License + * @package mod_questionnaire */ - class boolean extends responsetype { /** - * @return string + * Provide the necessary response data table name. Should probably always be used with late static binding 'static::' form + * rather than 'self::' form to allow for class extending. + * + * @return string response table name. */ public static function response_table() { return 'questionnaire_response_bool'; @@ -81,10 +76,10 @@ public static function answers_from_appdata($responsedata, $question) { } /** - * @param \mod_questionnaire\responsetype\response\response|\stdClass $responsedata - * @return bool|int - * @throws \coding_exception - * @throws \dml_exception + * Insert a provided response to the question. + * + * @param object $responsedata All of the responsedata as an object. + * @return int|bool - on error the subtype should call set_error and return false. */ public function insert_response($responsedata) { global $DB; @@ -107,11 +102,11 @@ public function insert_response($responsedata) { } /** - * @param bool $rids - * @param bool $anonymous - * @return array - * @throws coding_exception - * @throws dml_exception + * Provide the result information for the specified result records. + * + * @param int|array $rids - A single response id, or array. + * @param boolean $anonymous - Whether or not responses are anonymous. + * @return array - Array of data records. */ public function get_results($rids=false, $anonymous=false) { global $DB; @@ -134,8 +129,8 @@ public function get_results($rids=false, $anonymous=false) { /** * If the choice id needs to be transformed into a different value, override this in the child class. - * @param $choiceid - * @return mixed + * @param int $choiceid + * @return string */ public function transform_choiceid($choiceid) { if ($choiceid == 0) { diff --git a/classes/responsetype/date.php b/classes/responsetype/date.php index 8c8deeb7..befc5cba 100644 --- a/classes/responsetype/date.php +++ b/classes/responsetype/date.php @@ -14,16 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * This file contains the parent class for questionnaire question types. - * - * @author Mike Churchward - * @license http://www.gnu.org/copyleft/gpl.html GNU Public License - * @package questiontypes - */ - namespace mod_questionnaire\responsetype; -defined('MOODLE_INTERNAL') || die(); use mod_questionnaire\db\bulk_sql_config; @@ -31,12 +22,16 @@ * Class for date response types. * * @author Mike Churchward - * @package responsetypes + * @copyright 2016 onward Mike Churchward (mike.churchward@poetopensource.org) + * @license http://www.gnu.org/copyleft/gpl.html GNU Public License + * @package mod_questionnaire */ - class date extends responsetype { /** - * @return string + * Provide the necessary response data table name. Should probably always be used with late static binding 'static::' form + * rather than 'self::' form to allow for class extending. + * + * @return string response table name. */ public static function response_table() { return 'questionnaire_response_date'; @@ -77,10 +72,10 @@ public static function answers_from_appdata($responsedata, $question) { } /** - * @param \mod_questionnaire\responsetype\response\response\ $responsedata - * @return bool|int - * @throws \coding_exception - * @throws \dml_exception + * Insert a provided response to the question. + * + * @param object $responsedata All of the responsedata as an object. + * @return int|bool - on error the subtype should call set_error and return false. */ public function insert_response($responsedata) { global $DB; @@ -108,11 +103,11 @@ public function insert_response($responsedata) { } /** - * @param bool $rids - * @param bool $anonymous - * @return array - * @throws \coding_exception - * @throws \dml_exception + * Provide the result information for the specified result records. + * + * @param int|array $rids - A single response id, or array. + * @param boolean $anonymous - Whether or not responses are anonymous. + * @return array - Array of data records. */ public function get_results($rids=false, $anonymous=false) { global $DB; @@ -146,11 +141,12 @@ public function results_template($pdf = false) { } /** - * @param bool $rids - * @param string $sort - * @param bool $anonymous - * @return string - * @throws \coding_exception + * Provide the result information for the specified result records. + * + * @param int|array $rids - A single response id, or array. + * @param string $sort - Optional display sort. + * @param boolean $anonymous - Whether or not responses are anonymous. + * @return string - Display output. */ public function display_results($rids=false, $sort='', $anonymous=false) { $numresps = count($rids); @@ -174,15 +170,14 @@ public function display_results($rids=false, $sort='', $anonymous=false) { } /** - * Override the results tags function for templates for questions with dates. + * Gets the results tags for templates for questions with defined choices (single, multiple, boolean). * - * @param $weights - * @param $participants Number of questionnaire participants. - * @param $respondents Number of question respondents. - * @param $showtotals + * @param arrays $weights + * @param int $participants Number of questionnaire participants. + * @param int $respondents Number of question respondents. + * @param int $showtotals * @param string $sort * @return \stdClass - * @throws \coding_exception */ public function get_results_tags($weights, $participants, $respondents, $showtotals = 1, $sort = '') { $dateformat = get_string('strfdate', 'questionnaire'); diff --git a/classes/responsetype/multiple.php b/classes/responsetype/multiple.php index a4454906..d5d943d4 100644 --- a/classes/responsetype/multiple.php +++ b/classes/responsetype/multiple.php @@ -14,26 +14,16 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * This file contains the parent class for questionnaire question types. - * - * @author Mike Churchward - * @license http://www.gnu.org/copyleft/gpl.html GNU Public License - * @package questiontypes - */ - namespace mod_questionnaire\responsetype; -defined('MOODLE_INTERNAL') || die(); - -use mod_questionnaire\db\bulk_sql_config; /** * Class for multiple response types. * * @author Mike Churchward - * @package responsetypes + * @copyright 2016 onward Mike Churchward (mike.churchward@poetopensource.org) + * @license http://www.gnu.org/copyleft/gpl.html GNU Public License + * @package mod_questionnaire */ - class multiple extends single { /** * The only differences between multuple and single responses are the @@ -156,11 +146,13 @@ public static function response_select($rid) { /** * Return sql and params for getting responses in bulk. - * @author Guy Thomas * @param int|array $questionnaireids One id, or an array of ids. * @param bool|int $responseid * @param bool|int $userid + * @param bool $groupid + * @param int $showincompletes * @return array + * author Guy Thomas */ public function get_bulk_sql($questionnaireids, $responseid = false, $userid = false, $groupid = false, $showincompletes = 0) { global $DB; @@ -208,8 +200,8 @@ public function get_bulk_sql($questionnaireids, $responseid = false, $userid = f /** * Return sql for getting responses in bulk. - * @author Guy Thomas * @return string + * author Guy Thomas */ protected function bulk_sql() { global $DB; diff --git a/classes/responsetype/numericaltext.php b/classes/responsetype/numericaltext.php index 712502e2..be14d4e3 100644 --- a/classes/responsetype/numericaltext.php +++ b/classes/responsetype/numericaltext.php @@ -14,26 +14,16 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * This file contains the numerical text response type class. - * - * @author Mike Churchward - * @license http://www.gnu.org/copyleft/gpl.html GNU Public License - * @package responstype - */ - namespace mod_questionnaire\responsetype; -defined('MOODLE_INTERNAL') || die(); - -use mod_questionnaire\db\bulk_sql_config; /** * Class for numerical text response types. * * @author Mike Churchward - * @package responsetypes + * @copyright 2016 onward Mike Churchward (mike.churchward@poetopensource.org) + * @license http://www.gnu.org/copyleft/gpl.html GNU Public License + * @package mod_questionnaire */ - class numericaltext extends text { /** * Provide an array of answer objects from web form data for the question. @@ -59,11 +49,12 @@ public static function answers_from_webform($responsedata, $question) { } /** - * @param bool $rids - * @param string $sort - * @param bool $anonymous - * @return string - * @throws \coding_exception + * Provide the result information for the specified result records. + * + * @param int|array $rids - A single response id, or array. + * @param string $sort - Optional display sort. + * @param boolean $anonymous - Whether or not responses are anonymous. + * @return string - Display output. */ public function display_results($rids=false, $sort='', $anonymous=false) { if (is_array($rids)) { diff --git a/classes/responsetype/rank.php b/classes/responsetype/rank.php index 1e0c1f40..ad8dbaf7 100644 --- a/classes/responsetype/rank.php +++ b/classes/responsetype/rank.php @@ -14,16 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * This file contains the parent class for questionnaire question types. - * - * @author Mike Churchward - * @license http://www.gnu.org/copyleft/gpl.html GNU Public License - * @package questiontypes - */ - namespace mod_questionnaire\responsetype; -defined('MOODLE_INTERNAL') || die(); use Composer\Package\Package; use mod_questionnaire\db\bulk_sql_config; @@ -32,12 +23,16 @@ * Class for rank responses. * * @author Mike Churchward - * @package responsetypes + * @copyright 2016 onward Mike Churchward (mike.churchward@poetopensource.org) + * @license http://www.gnu.org/copyleft/gpl.html GNU Public License + * @package mod_questionnaire */ - class rank extends responsetype { /** - * @return string + * Provide the necessary response data table name. Should probably always be used with late static binding 'static::' form + * rather than 'self::' form to allow for class extending. + * + * @return string response table name. */ public static function response_table() { return 'questionnaire_response_rank'; @@ -107,10 +102,10 @@ public static function answers_from_appdata($responsedata, $question) { } /** - * @param \mod_questionnaire\responsetype\response\response|\stdClass $responsedata - * @return bool|int - * @throws \coding_exception - * @throws \dml_exception + * Insert a provided response to the question. + * + * @param object $responsedata All of the responsedata as an object. + * @return int|bool - on error the subtype should call set_error and return false. */ public function insert_response($responsedata) { global $DB; @@ -289,10 +284,12 @@ public function results_template($pdf = false) { } /** - * @param bool $rids - * @param string $sort - * @param bool $anonymous - * @return string + * Provide the result information for the specified result records. + * + * @param int|array $rids - A single response id, or array. + * @param string $sort - Optional display sort. + * @param boolean $anonymous - Whether or not responses are anonymous. + * @return string - Display output. */ public function display_results($rids=false, $sort='', $anonymous=false) { $output = ''; @@ -435,10 +432,10 @@ protected function bulk_sql_config() { } /** - * @param $sort + * Return a structure for averages. + * @param string $sort * @param string $stravgvalue * @return \stdClass - * @throws \coding_exception */ private function mkresavg($sort, $stravgvalue='') { global $CFG; @@ -739,12 +736,11 @@ private function mkresavg($sort, $stravgvalue='') { } /** - * @param $rids - * @param $rows - * @param $sort + * Return a structure for counts. + * @param array $rids + * @param array $rows + * @param string $sort * @return \stdClass - * @throws \coding_exception - * @throws \dml_exception */ private function mkrescount($rids, $rows, $sort) { // Display number of responses to Rate questions - see http://moodle.org/mod/forum/discuss.php?d=185106. @@ -947,9 +943,9 @@ private function mkrescount($rids, $rows, $sort) { } /** - * Sorting functions for ascending and descending. - * @param $a - * @param $b + * Sorting function for ascending. + * @param \stdClass $a + * @param \stdClass $b * @return int */ private static function sortavgasc($a, $b) { @@ -965,8 +961,9 @@ private static function sortavgasc($a, $b) { } /** - * @param $a - * @param $b + * Sorting function for descending. + * @param \stdClass $a + * @param \stdClass $b * @return int */ private static function sortavgdesc($a, $b) { diff --git a/classes/responsetype/response/response.php b/classes/responsetype/response/response.php index 5764259a..070160d2 100644 --- a/classes/responsetype/response/response.php +++ b/classes/responsetype/response/response.php @@ -14,20 +14,16 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace mod_questionnaire\responsetype\response; + /** * This defines a structured class to hold responses. * * @author Mike Churchward * @license http://www.gnu.org/copyleft/gpl.html GNU Public License - * @package response + * @package mod_questionnaire * @copyright 2019, onwards Poet */ - -namespace mod_questionnaire\responsetype\response; -use mod_questionnaire\responsetype\answer\answer; - -defined('MOODLE_INTERNAL') || die(); - class response { // Class properties. @@ -81,7 +77,7 @@ public function __construct($id = null, $questionnaireid = null, $userid = null, /** * Create and return a response object from data. * - * @param object | array $responsedata The data to load. + * @param \stdClass|array $responsedata The data to load. * @return response */ public static function create_from_data($responsedata) { @@ -104,9 +100,8 @@ public static function create_from_data($responsedata) { * Provide a response object from web form data to the question. * * @param \stdClass $responsedata All of the responsedata as an object. - * @param array \mod_questionnaire\question\question $questions + * @param array $questions * @return bool|response A response object. - * @throws \coding_exception */ public static function response_from_webform($responsedata, $questions) { global $USER; @@ -125,10 +120,10 @@ public static function response_from_webform($responsedata, $questions) { /** * Provide a response object from mobile app data to the question. * - * @param $questionnaireid - * @param $responseid + * @param id $questionnaireid + * @param id $responseid * @param \stdClass $responsedata All of the responsedata as an object. - * @param $questions Array of question objects. + * @param array $questions Array of question objects. * @return bool|response A response object. */ public static function response_from_appdata($questionnaireid, $responseid, $responsedata, $questions) { diff --git a/classes/responsetype/responsetype.php b/classes/responsetype/responsetype.php index a1ce8033..59e3715d 100644 --- a/classes/responsetype/responsetype.php +++ b/classes/responsetype/responsetype.php @@ -14,28 +14,21 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * This file contains the parent class for questionnaire response types. - * - * @author Mike Churchward - * @license http://www.gnu.org/copyleft/gpl.html GNU Public License - * @package response - */ - namespace mod_questionnaire\responsetype; -defined('MOODLE_INTERNAL') || die(); + use \html_writer; use \html_table; use mod_questionnaire\db\bulk_sql_config; /** - * Class for describing a response. + * This file contains the parent class for questionnaire response types. * * @author Mike Churchward - * @package response + * @copyright 2016 onward Mike Churchward (mike.churchward@poetopensource.org) + * @license http://www.gnu.org/copyleft/gpl.html GNU Public License + * @package mod_questionnaire */ - abstract class responsetype { // Class properties. @@ -118,7 +111,7 @@ abstract public function display_results($rids=false, $sort='', $anonymous=false /** * If the choice id needs to be transformed into a different value, override this in the child class. - * @param $choiceid + * @param mixed $choiceid * @return mixed */ public function transform_choiceid($choiceid) { @@ -137,13 +130,12 @@ public function results_template($pdf = false) { /** * Gets the results tags for templates for questions with defined choices (single, multiple, boolean). * - * @param $weights - * @param $participants Number of questionnaire participants. - * @param $respondents Number of question respondents. - * @param $showtotals + * @param array $weights + * @param int $participants Number of questionnaire participants. + * @param int $respondents Number of question respondents. + * @param int $showtotals * @param string $sort * @return \stdClass - * @throws \coding_exception */ public function get_results_tags($weights, $participants, $respondents, $showtotals = 1, $sort = '') { global $CFG; @@ -285,8 +277,8 @@ public static function answers_from_appdata($responsedata, $question) { /** * Return all the fields to be used for users in bulk questionnaire sql. * - * @author: Guy Thomas * @return string + * author: Guy Thomas */ protected function user_fields_sql() { if (class_exists('\core_user\fields')) { @@ -306,12 +298,13 @@ protected function user_fields_sql() { /** * Return sql and params for getting responses in bulk. - * @author Guy Thomas * @param int|array $questionnaireids One id, or an array of ids. * @param bool|int $responseid * @param bool|int $userid * @param bool|int $groupid + * @param int $showincompletes * @return array + * author Guy Thomas */ public function get_bulk_sql($questionnaireids, $responseid = false, $userid = false, $groupid = false, $showincompletes = 0) { global $DB; diff --git a/classes/responsetype/single.php b/classes/responsetype/single.php index 62a308ce..d8dc2f7c 100644 --- a/classes/responsetype/single.php +++ b/classes/responsetype/single.php @@ -14,28 +14,22 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * This file contains the parent class for questionnaire question types. - * - * @author Mike Churchward - * @license http://www.gnu.org/copyleft/gpl.html GNU Public License - * @package questiontypes - */ - namespace mod_questionnaire\responsetype; -defined('MOODLE_INTERNAL') || die(); - /** * Class for single response types. * * @author Mike Churchward - * @package responsetypes + * @copyright 2016 onward Mike Churchward (mike.churchward@poetopensource.org) + * @license http://www.gnu.org/copyleft/gpl.html GNU Public License + * @package mod_questionnaire */ - class single extends responsetype { /** - * @return string + * Provide the necessary response data table name. Should probably always be used with late static binding 'static::' form + * rather than 'self::' form to allow for class extending. + * + * @return string response table name. */ public static function response_table() { return 'questionnaire_resp_single'; @@ -96,10 +90,10 @@ public static function answers_from_appdata($responsedata, $question) { } /** - * @param \mod_questionnaire\responsetype\response\response|\stdClass $responsedata - * @return bool|int - * @throws \coding_exception - * @throws \dml_exception + * Insert a provided response to the question. + * + * @param object $responsedata All of the responsedata as an object. + * @return int|bool - on error the subtype should call set_error and return false. */ public function insert_response($responsedata) { global $DB; @@ -139,11 +133,11 @@ public function insert_response($responsedata) { } /** - * @param bool $rids - * @param bool $anonymous - * @return array - * @throws \coding_exception - * @throws \dml_exception + * Provide the result information for the specified result records. + * + * @param int|array $rids - A single response id, or array. + * @param boolean $anonymous - Whether or not responses are anonymous. + * @return array - Array of data records. */ public function get_results($rids=false, $anonymous=false) { global $DB; @@ -331,11 +325,13 @@ public static function response_answers_by_question($rid) { /** * Return sql and params for getting responses in bulk. - * @author Guy Thomas * @param int|array $questionnaireids One id, or an array of ids. * @param bool|int $responseid * @param bool|int $userid + * @param bool|int $groupid + * @param int $showincompletes * @return array + * author Guy Thomas */ public function get_bulk_sql($questionnaireids, $responseid = false, $userid = false, $groupid = false, $showincompletes = 0) { global $DB; diff --git a/classes/responsetype/text.php b/classes/responsetype/text.php index 5839fd05..b03b7d47 100644 --- a/classes/responsetype/text.php +++ b/classes/responsetype/text.php @@ -14,29 +14,23 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * This file contains the parent class for questionnaire question types. - * - * @author Mike Churchward - * @license http://www.gnu.org/copyleft/gpl.html GNU Public License - * @package questiontypes - */ - namespace mod_questionnaire\responsetype; -defined('MOODLE_INTERNAL') || die(); use mod_questionnaire\db\bulk_sql_config; /** * Class for text response types. - * * @author Mike Churchward - * @package responsetypes + * @copyright 2016 onward Mike Churchward (mike.churchward@poetopensource.org) + * @license http://www.gnu.org/copyleft/gpl.html GNU Public License + * @package mod_questionnaire */ - class text extends responsetype { /** - * @return string + * Provide the necessary response data table name. Should probably always be used with late static binding 'static::' form + * rather than 'self::' form to allow for class extending. + * + * @return string response table name. */ public static function response_table() { return 'questionnaire_response_text'; @@ -63,10 +57,10 @@ public static function answers_from_webform($responsedata, $question) { } /** - * @param \mod_questionnaire\responsetype\response\response|\stdClass $responsedata - * @return bool|int - * @throws \coding_exception - * @throws \dml_exception + * Insert a provided response to the question. + * + * @param object $responsedata All of the responsedata as an object. + * @return int|bool - on error the subtype should call set_error and return false. */ public function insert_response($responsedata) { global $DB; @@ -89,11 +83,11 @@ public function insert_response($responsedata) { } /** - * @param bool $rids - * @param bool $anonymous - * @return array - * @throws \coding_exception - * @throws \dml_exception + * Provide the result information for the specified result records. + * + * @param int|array $rids - A single response id, or array. + * @param boolean $anonymous - Whether or not responses are anonymous. + * @return array - Array of data records. */ public function get_results($rids=false, $anonymous=false) { global $DB; @@ -141,11 +135,12 @@ public function results_template($pdf = false) { } /** - * @param bool $rids - * @param string $sort - * @param bool $anonymous - * @return string - * @throws \coding_exception + * Provide the result information for the specified result records. + * + * @param int|array $rids - A single response id, or array. + * @param string $sort - Optional display sort. + * @param boolean $anonymous - Whether or not responses are anonymous. + * @return string - Display output. */ public function display_results($rids=false, $sort='', $anonymous=false) { if (is_array($rids)) { @@ -164,15 +159,14 @@ public function display_results($rids=false, $sort='', $anonymous=false) { } /** - * Override the results tags function for templates for questions with dates. + * Gets the results tags for templates for questions with defined choices (single, multiple, boolean). * - * @param $weights - * @param $participants Number of questionnaire participants. - * @param $respondents Number of question respondents. - * @param $showtotals + * @param array $weights + * @param int $participants Number of questionnaire participants. + * @param int $respondents Number of question respondents. + * @param int $showtotals * @param string $sort * @return \stdClass - * @throws \coding_exception */ public function get_results_tags($weights, $participants, $respondents, $showtotals = 1, $sort = '') { $pagetags = new \stdClass(); diff --git a/classes/search/question.php b/classes/search/question.php index 26b8a1fc..0d5d4b60 100644 --- a/classes/search/question.php +++ b/classes/search/question.php @@ -13,21 +13,17 @@ // // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Contains class mod_questionnaire\search\question - * - * @package mod_questionnaire - * @copyright 2016 Mike Churchward (mike.churchward@poetgroup.org) - * @author Mike Churchward - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ + namespace mod_questionnaire\search; -defined('MOODLE_INTERNAL') || die(); + /** + * Contains the question class definition for search. + * * Search area for mod_questionnaire questions. Separated from the activity search so that admins can choose whether or not they * want this part enabled. * * @package mod_questionnaire + * @author Mike Churchward * @copyright 2016 Mike Churchward (mike.churchward@poetgroup.org) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ diff --git a/classes/settings_form.php b/classes/settings_form.php index 72ab24d8..c810f0d6 100644 --- a/classes/settings_form.php +++ b/classes/settings_form.php @@ -14,21 +14,24 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * @package mod_questionnaire - * @copyright 2016 Mike Churchward (mike.churchward@poetgroup.org) - * @author Mike Churchward - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - namespace mod_questionnaire; defined('MOODLE_INTERNAL') || die(); require_once($CFG->libdir . '/formslib.php'); +/** + * The questionnaire settings form. + * @package mod_questionnaire + * @copyright 2016 Mike Churchward (mike.churchward@poetgroup.org) + * @author Mike Churchward + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ class settings_form extends \moodleform { + /** + * Defines the form. + */ public function definition() { global $questionnaire, $questionnairerealms; @@ -127,6 +130,13 @@ public function definition() { } + /** + * Validation rules for form. + * @param array $data array of ("fieldname"=>value) of submitted data + * @param array $files array of uploaded files "element_name"=>tmp_file_path + * @return array of "element_name"=>"error_description" if there are errors, + * or an empty array if everything is OK (true allowed for backwards compatibility too). + */ public function validation($data, $files) { $errors = parent::validation($data, $files); return $errors; diff --git a/classes/task/cleanup.php b/classes/task/cleanup.php index 1dc8396e..7cd40678 100644 --- a/classes/task/cleanup.php +++ b/classes/task/cleanup.php @@ -14,17 +14,16 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace mod_questionnaire\task; + /** * A scheduled task for Questionnaire. * * @package mod_questionnaire * @copyright 2015 The Open University + * @author Mike Churchward * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -namespace mod_questionnaire\task; - -defined('MOODLE_INTERNAL') || die(); - class cleanup extends \core\task\scheduled_task { /** @@ -36,6 +35,9 @@ public function get_name() { return get_string('crontask', 'mod_questionnaire'); } + /** + * Execute method. + */ public function execute() { global $CFG; require_once($CFG->dirroot . '/mod/questionnaire/locallib.php'); diff --git a/complete.php b/complete.php index a6210aa1..b6b24dec 100644 --- a/complete.php +++ b/complete.php @@ -14,8 +14,15 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -// This page prints a particular instance of questionnaire. - +/** + * This page prints a particular instance of questionnaire. + * + * @package mod_questionnaire + * @copyright 2016 Mike Churchward (mike.churchward@poetgroup.org) + * @author Mike Churchward + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * + */ require_once("../../config.php"); require_once($CFG->libdir . '/completionlib.php'); require_once($CFG->dirroot.'/mod/questionnaire/questionnaire.class.php'); diff --git a/db/install.php b/db/install.php index ec30ff4f..479cf2bd 100644 --- a/db/install.php +++ b/db/install.php @@ -14,18 +14,19 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/* - * - * @package mod - * @subpackage questionnaire +/** + * The file containing the install functions. + * @package mod_questionnaire * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * This file is executed right after the install.xml - * @copyright 2010 Remote Learner (http://www.remote-learner.net) + * @copyright 2016 Mike Churchward (mike.churchward@poetopensource.org) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - defined('MOODLE_INTERNAL') || die(); +/** + * The install function. + */ function xmldb_questionnaire_install() { global $DB; diff --git a/db/log.php b/db/log.php index f30b3517..968e5dc0 100644 --- a/db/log.php +++ b/db/log.php @@ -17,9 +17,8 @@ /** * Capability definitions for the quiz module. * - * @package mod - * @subpackage questionnaire - * @copyright 2010 Remote-Learner.net (http://www.remote-learner.net) + * @package mod_questionnaire + * @copyright 2016 Mike Churchward (mike.churchward@poetopensource.org) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ diff --git a/db/tasks.php b/db/tasks.php index c36110b1..40d241ab 100644 --- a/db/tasks.php +++ b/db/tasks.php @@ -16,6 +16,7 @@ /** * Definition of Questionnaire scheduled tasks. + * * Default is to run once every 12 hours. * * @package mod_questionnaire @@ -23,9 +24,9 @@ * @copyright 2015 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - defined('MOODLE_INTERNAL') || die(); +/** @var array $tasks */ $tasks = array( array( 'classname' => 'mod_questionnaire\task\cleanup', diff --git a/db/upgrade.php b/db/upgrade.php index ca290ae7..fe31f36c 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -15,14 +15,20 @@ // along with Moodle. If not, see . /** + * The file containing the upgrade functions. * @package mod_questionnaire - * @copyright 2016 Mike Churchward (mike.churchward@poetgroup.org) + * @copyright 2016 Mike Churchward (mike.churchward@poetopensource.org) * @author Mike Churchward * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die(); +/** + * The module upgrade function. + * @param int $oldversion + * @return bool + */ function xmldb_questionnaire_upgrade($oldversion=0) { global $CFG, $DB; @@ -982,7 +988,10 @@ function xmldb_questionnaire_upgrade($oldversion=0) { return $result; } -// Supporting functions used once. +/** + * Supporting functions used once. + * @return bool + */ function questionnaire_upgrade_2007120101() { global $DB; diff --git a/drawchart.php b/drawchart.php index 91977c0e..1b144892 100644 --- a/drawchart.php +++ b/drawchart.php @@ -15,6 +15,7 @@ // along with Moodle. If not, see . /** + * Library draw chart function. * @package mod_questionnaire * @copyright 2016 Mike Churchward (mike.churchward@poetgroup.org) * @author Mike Churchward @@ -23,6 +24,18 @@ defined('MOODLE_INTERNAL') || die(); +/** + * This is the function. + * @param string $feedbacktype + * @param array $labels + * @param string $groupname + * @param bool $allresponses + * @param null|string $charttype + * @param null|array $score + * @param null|array $allscore + * @param null|string $globallabel + * @return string + */ function draw_chart($feedbacktype, $labels, $groupname, $allresponses, $charttype=null, $score=null, $allscore=null, $globallabel=null) { global $PAGE; diff --git a/externallib.php b/externallib.php index 653c4ed3..d9773f8d 100644 --- a/externallib.php +++ b/externallib.php @@ -82,9 +82,9 @@ public static function submit_questionnaire_response_parameters() { * @param int $completed Completed survey 1/0 * @param int $rid Already in progress response id. * @param int $submit Submit survey? + * @param string $action * @param array $responses the response ids * @return array answers information and warnings - * @since Moodle 3.0 */ public static function submit_questionnaire_response($questionnaireid, $surveyid, $userid, $cmid, $sec, $completed, $rid, $submit, $action, $responses) { diff --git a/index.php b/index.php index b667e6a3..05bce900 100644 --- a/index.php +++ b/index.php @@ -17,13 +17,11 @@ /** * This script lists all the instances of questionnaire in a particular course * - * @package mod - * @subpackage questionnaire - * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} + * @package mod_questionnaire + * @copyright 2016 Mike Churchward (mike.churchward@poetopensource.org) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - require_once("../../config.php"); require_once($CFG->dirroot.'/mod/questionnaire/locallib.php'); diff --git a/lib.php b/lib.php index c91aaa61..46f15244 100644 --- a/lib.php +++ b/lib.php @@ -14,20 +14,25 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -// Library of functions and constants for module questionnaire. - /** + * Library of functions and constants for module questionnaire. * @package mod_questionnaire - * @copyright 2016 Mike Churchward (mike.churchward@poetgroup.org) + * @copyright 2016 Mike Churchward (mike.churchward@poetopensource.org) * @author Mike Churchward * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -defined('MOODLE_INTERNAL') || die(); - +/** This may no longer be needed. */ define('QUESTIONNAIRE_RESETFORM_RESET', 'questionnaire_reset_data_'); + +/** This may no longer be needed. */ define('QUESTIONNAIRE_RESETFORM_DROP', 'questionnaire_drop_questionnaire_'); +/** + * Library supports implementation. + * @param string $feature + * @return bool|null + */ function questionnaire_supports($feature) { switch($feature) { case FEATURE_BACKUP_MOODLE2: @@ -55,17 +60,28 @@ function questionnaire_supports($feature) { } /** + * Return any extra capabilities. * @return array all other caps used in module */ function questionnaire_get_extra_capabilities() { return array('moodle/site:accessallgroups'); } +/** + * Implementation of get_instance. + * @param int $questionnaireid + * @return false|mixed|stdClass + */ function questionnaire_get_instance($questionnaireid) { global $DB; return $DB->get_record('questionnaire', array('id' => $questionnaireid)); } +/** + * Implementation of add_instance. + * @param stdClass $questionnaire + * @return bool|int + */ function questionnaire_add_instance($questionnaire) { // Given an object containing all the necessary data, // (defined by the form in mod.html) this function @@ -150,9 +166,12 @@ function questionnaire_add_instance($questionnaire) { return $questionnaire->id; } -// Given an object containing all the necessary data, -// (defined by the form in mod.html) this function -// will update an existing instance with new data. +/** + * Given an object containing all the necessary data, (defined by the form in mod.html) this function will update an existing + * instance with new data. + * @param stdClass $questionnaire + * @return bool + */ function questionnaire_update_instance($questionnaire) { global $DB, $CFG; require_once($CFG->dirroot.'/mod/questionnaire/locallib.php'); @@ -183,9 +202,11 @@ function questionnaire_update_instance($questionnaire) { return $DB->update_record("questionnaire", $questionnaire); } -// Given an ID of an instance of this module, -// this function will permanently delete the instance -// and any data that depends on it. +/** + * Given an ID of an instance of this module, this function will permanently delete the instance and any data that depends on it. + * @param int $id + * @return bool + */ function questionnaire_delete_instance($id) { global $DB, $CFG; require_once($CFG->dirroot.'/mod/questionnaire/locallib.php'); @@ -217,15 +238,17 @@ function questionnaire_delete_instance($id) { return $result; } -// 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. /** + * 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. * $course and $mod are unused, but API requires them. Suppress PHPMD warning. - * - * @SuppressWarnings(PHPMD.UnusedFormalParameter) + * @param stdClass $course + * @param stdClass $user + * @param stdClass $mod + * @param stdClass $questionnaire + * @return stdClass */ function questionnaire_user_outline($course, $user, $mod, $questionnaire) { global $CFG; @@ -247,12 +270,15 @@ function questionnaire_user_outline($course, $user, $mod, $questionnaire) { return $result; } -// Print a detailed representation of what a user has done with -// a given particular instance of this module, for user activity reports. /** + * Print a detailed representation of what a user has done with a given particular instance of this module, for user + * activity reports. * $course and $mod are unused, but API requires them. Suppress PHPMD warning. - * - * @SuppressWarnings(PHPMD.UnusedFormalParameter) + * @param stdClass $course + * @param stdClass $user + * @param stdClass $mod + * @param stdClass $questionnaire + * @return bool */ function questionnaire_user_complete($course, $user, $mod, $questionnaire) { global $CFG; @@ -273,24 +299,25 @@ function questionnaire_user_complete($course, $user, $mod, $questionnaire) { return true; } -// Given a course and a time, this module should find recent activity -// that has occurred in questionnaire activities and print it out. -// Return true if there was output, or false is there was none. /** + * Given a course and a time, this module should find recent activity that has occurred in questionnaire activities and print it + * out. + * Return true if there was output, or false is there was none. * $course, $isteacher and $timestart are unused, but API requires them. Suppress PHPMD warning. - * - * @SuppressWarnings(PHPMD.UnusedFormalParameter) + * @param stdClass $course + * @param bool $isteacher + * @param int $timestart + * @return false */ function questionnaire_print_recent_activity($course, $isteacher, $timestart) { return false; // True if anything was printed, otherwise false. } -// Must return an array of grades for a given instance of this module, -// indexed by user. It also returns a maximum allowed grade. /** + * Must return an array of grades for a given instance of this module, indexed by user. It also returns a maximum allowed grade. * $questionnaireid is unused, but API requires it. Suppress PHPMD warning. - * - * @SuppressWarnings(PHPMD.UnusedFormalParameter) + * @param int $questionnaireid + * @return null */ function questionnaire_grades($questionnaireid) { return null; @@ -299,7 +326,7 @@ function questionnaire_grades($questionnaireid) { /** * Return grade for given user or all users. * - * @param int $questionnaireid id of assignment + * @param stdClass $questionnaire * @param int $userid optional user id, 0 means all users * @return array array of grades, false if none */ @@ -319,14 +346,11 @@ function questionnaire_get_user_grades($questionnaire, $userid=0) { } /** - * Update grades by firing grade_updated event - * - * @param object $assignment null means all assignments - * @param int $userid specific user only, 0 mean all - * + * Update grades by firing grade_updated event. * $nullifnone is unused, but API requires it. Suppress PHPMD warning. - * - * @SuppressWarnings(PHPMD.UnusedFormalParameter) + * @param stdClass $questionnaire + * @param int $userid + * @param bool $nullifnone */ function questionnaire_update_grades($questionnaire=null, $userid=0, $nullifnone=true) { global $CFG, $DB; @@ -376,8 +400,8 @@ function questionnaire_update_grades($questionnaire=null, $userid=0, $nullifnone /** * Create grade item for given questionnaire * - * @param object $questionnaire object with extra cmidnumber - * @param mixed optional array/object of grade(s); 'reset' means reset grades in gradebook + * @param stdClass $questionnaire object with extra cmidnumber + * @param mixed $grades optional array/object of grade(s); 'reset' means reset grades in gradebook * @return int 0 if ok, error code otherwise */ function questionnaire_grade_item_update($questionnaire, $grades = null) { @@ -427,13 +451,11 @@ function questionnaire_grade_item_update($questionnaire, $grades = null) { * it it has support for grading and scales. Commented code should be * modified if necessary. See forum, glossary or journal modules * as reference. - * @param $questionnaireid int - * @param $scaleid int + * @param int $questionnaireid + * @param int $scaleid * @return boolean True if the scale is used by any questionnaire * * Function parameters are unused, but API requires them. Suppress PHPMD warning. - * - * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ function questionnaire_scale_used ($questionnaireid, $scaleid) { return false; @@ -443,12 +465,10 @@ function questionnaire_scale_used ($questionnaireid, $scaleid) { * Checks if scale is being used by any instance of questionnaire * * This is used to find out if scale used anywhere - * @param $scaleid int + * @param int $scaleid * @return boolean True if the scale is used by any questionnaire * * Function parameters are unused, but API requires them. Suppress PHPMD warning. - * - * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ function questionnaire_scale_used_anywhere($scaleid) { return false; @@ -457,17 +477,15 @@ function questionnaire_scale_used_anywhere($scaleid) { /** * Serves the questionnaire attachments. Implements needed access control ;-) * - * @param object $course - * @param object $cm - * @param object $context + * @param stdClass $course + * @param stdClass $cm + * @param stdClass $context * @param string $filearea * @param array $args * @param bool $forcedownload * @return bool false if file not found, does not return if found - justsend the file * * $forcedownload is unused, but API requires it. Suppress PHPMD warning. - * - * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ function questionnaire_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload) { global $DB; @@ -524,8 +542,6 @@ function questionnaire_pluginfile($course, $cm, $context, $filearea, $args, $for * @param navigation_node $questionnairenode The node to add module settings to * * $settings is unused, but API requires it. Suppress PHPMD warning. - * - * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ function questionnaire_extend_settings_navigation(settings_navigation $settings, navigation_node $questionnairenode) { @@ -738,16 +754,35 @@ function questionnaire_extend_settings_navigation(settings_navigation $settings, // Any other questionnaire functions go here. Each of them must have a name that // starts with questionnaire_. +/** + * Return the view actions. + * @return string[] + */ function questionnaire_get_view_actions() { return array('view', 'view all'); } +/** + * Return the post actions. + * @return string[] + */ function questionnaire_get_post_actions() { return array('submit', 'update'); } +/** + * Return the recent activity. + * @param array $activities + * @param int $index + * @param int $timestart + * @param int $courseid + * @param int $cmid + * @param int $userid + * @param int $groupid + * @return mixed|void + */ function questionnaire_get_recent_mod_activity(&$activities, &$index, $timestart, - $courseid, $cmid, $userid = 0, $groupid = 0) { + $courseid, $cmid, $userid = 0, $groupid = 0) { global $CFG, $COURSE, $USER, $DB; require_once($CFG->dirroot . '/mod/questionnaire/locallib.php'); @@ -911,16 +946,13 @@ function questionnaire_get_recent_mod_activity(&$activities, &$index, $timestart /** * Prints all users who have completed a specified questionnaire since a given time * - * @global object - * @param object $activity + * @param stdClass $activity * @param int $courseid * @param string $detail not used but needed for compability * @param array $modnames * @return void Output is echo'd * * $details and $modenames are unused, but API requires them. Suppress PHPMD warning. - * - * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ function questionnaire_print_recent_mod_activity($activity, $courseid, $detail, $modnames) { global $OUTPUT; @@ -989,10 +1021,6 @@ function questionnaire_print_recent_mod_activity($activity, $courseid, $detail, * questionnaires 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 questionnaire instances from * @param array $htmlarray Store overview output array( course ID => 'questionnaire' => HTML output ) * @return void @@ -1077,7 +1105,7 @@ function questionnaire_print_overview($courses, &$htmlarray) { * Implementation of the function for printing the form elements that control * whether the course reset functionality affects the questionnaire. * - * @param $mform the course reset form that is being built. + * @param stdClass $mform the course reset form that is being built. */ function questionnaire_reset_course_form_definition($mform) { $mform->addElement('header', 'questionnaireheader', get_string('modulenameplural', 'questionnaire')); @@ -1087,11 +1115,10 @@ function questionnaire_reset_course_form_definition($mform) { /** * Course reset form defaults. + * @param stdClass $course * @return array the defaults. * * Function parameters are unused, but API requires them. Suppress PHPMD warning. - * - * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ function questionnaire_reset_course_form_defaults($course) { return array('reset_questionnaire' => 1); @@ -1101,7 +1128,7 @@ function questionnaire_reset_course_form_defaults($course) { * Actual implementation of the reset course functionality, delete all the * questionnaire responses for course $data->courseid. * - * @param object $data the data submitted from the reset course. + * @param stdClass $data the data submitted from the reset course. * @return array status array */ function questionnaire_reset_userdata($data) { @@ -1157,15 +1184,13 @@ function questionnaire_reset_userdata($data) { * Obtains the automatic completion state for this questionnaire based on the condition * in questionnaire settings. * - * @param object $course Course - * @param object $cm Course-module + * @param stdClass $course Course + * @param stdClass $cm Course-module * @param int $userid User ID * @param bool $type Type of comparison (or/and; can be used as return value if no conditions) * @return bool True if completed, false if not, $type if conditions not set. * * $course is unused, but API requires it. Suppress PHPMD warning. - * - * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ function questionnaire_get_completion_state($course, $cm, $userid, $type) { global $DB; @@ -1217,8 +1242,8 @@ function mod_questionnaire_core_calendar_provide_event_action(calendar_event $ev * Called after the activity and module have been created. Use this to copy any images if the questionnaire was created from another * questionnaire survey. * - * @param $data - * @param $course + * @param stdClass $data + * @param stdClass $course * @throws coding_exception */ function mod_questionnaire_coursemodule_edit_post_actions($data, $course) { diff --git a/locallib.php b/locallib.php index f17cbd98..1472a821 100644 --- a/locallib.php +++ b/locallib.php @@ -15,27 +15,16 @@ // along with Moodle. If not, see . /** + * Updates the contents of the survey with the provided data. If no data is provided, it checks for posted data. + * * This library replaces the phpESP application with Moodle specific code. It will eventually * replace all of the phpESP application, removing the dependency on that. - */ - -/** - * Updates the contents of the survey with the provided data. If no data is provided, - * it checks for posted data. - * - * @param int $surveyid The id of the survey to update. - * @param string $old_tab The function that was being executed. - * @param object $sdata The data to update the survey with. * - * @return string|boolean The function to go to, or false on error. - * - */ - -/** * @package mod_questionnaire * @copyright 2016 Mike Churchward (mike.churchward@poetgroup.org) * @author Mike Churchward * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * */ defined('MOODLE_INTERNAL') || die(); @@ -87,6 +76,11 @@ 2 => get_string('autonumberpages', 'questionnaire'), 3 => get_string('autonumberpagesandquestions', 'questionnaire')); +/** + * Return the choice values for the content. + * @param string $content + * @return stdClass + */ function questionnaire_choice_values($content) { // If we run the content through format_text first, any filters we want to use (e.g. multilanguage) should work. @@ -157,7 +151,11 @@ function questionnaire_get_js_module() { } /** - * Get all the questionnaire responses for a user + * Get all the questionnaire responses for a user. + * @param int $questionnaireid + * @param int $userid + * @param bool $complete + * @return array */ function questionnaire_get_user_responses($questionnaireid, $userid, $complete=true) { global $DB; @@ -227,8 +225,12 @@ function questionnaire_get_context($cmid) { return $context; } -// This function *really* shouldn't be needed, but since sometimes we can end up with -// orphaned surveys, this will clean them up. +/** + * This function *really* shouldn't be needed, but since sometimes we can end up with + * orphaned surveys, this will clean them up. + * @return bool + * @throws dml_exception + */ function questionnaire_cleanup() { global $DB; @@ -246,6 +248,12 @@ function questionnaire_cleanup() { return true; } +/** + * Delete the survey. + * @param int $sid + * @param int $questionnaireid + * @return bool + */ function questionnaire_delete_survey($sid, $questionnaireid) { global $DB; $status = true; @@ -283,6 +291,12 @@ function questionnaire_delete_survey($sid, $questionnaireid) { return $status; } +/** + * Delete the response. + * @param stdClass $response + * @param string $questionnaire + * @return bool + */ function questionnaire_delete_response($response, $questionnaire='') { global $DB; $status = true; @@ -315,6 +329,11 @@ function questionnaire_delete_response($response, $questionnaire='') { return $status; } +/** + * Delete all responses for the questionnaire. + * @param int $qid + * @return bool + */ function questionnaire_delete_responses($qid) { global $DB; @@ -330,6 +349,11 @@ function questionnaire_delete_responses($qid) { return true; } +/** + * Delete all dependencies for the questionnaire. + * @param int $qid + * @return bool + */ function questionnaire_delete_dependencies($qid) { global $DB; @@ -340,6 +364,12 @@ function questionnaire_delete_dependencies($qid) { return true; } +/** + * Get a survey selection records. + * @param int $courseid + * @param string $type + * @return array|false + */ function questionnaire_get_survey_list($courseid=0, $type='') { global $DB; @@ -389,6 +419,12 @@ function questionnaire_get_survey_list($courseid=0, $type='') { return $DB->get_records_sql($sql, $params); } +/** + * Get survey selection list. + * @param int $courseid + * @param string $type + * @return array + */ function questionnaire_get_survey_select($courseid=0, $type='') { global $OUTPUT, $DB; @@ -425,6 +461,12 @@ function questionnaire_get_survey_select($courseid=0, $type='') { return $surveylist; } +/** + * Return the language string for the specified question type. + * @param int $id + * @return lang_string|mixed|string + * @throws coding_exception + */ function questionnaire_get_type ($id) { switch ($id) { case 1: @@ -459,8 +501,6 @@ function questionnaire_get_type ($id) { * @param object $questionnaire * @return void */ - /* added by JR 16 march 2009 based on lesson_process_post_save script */ - function questionnaire_set_events($questionnaire) { // Adding the questionnaire to the eventtable. global $DB; @@ -512,14 +552,15 @@ function questionnaire_set_events($questionnaire) { /** * Get users who have not completed the questionnaire * - * @global object - * @uses CONTEXT_MODULE * @param object $cm - * @param int $group single groupid + * @param int $sid + * @param bool $group single groupid * @param string $sort - * @param int $startpage - * @param int $pagecount + * @param bool $startpage + * @param bool $pagecount * @return object the userrecords + * @throws coding_exception + * @throws dml_exception */ function questionnaire_get_incomplete_users($cm, $sid, $group = false, @@ -569,6 +610,8 @@ function questionnaire_get_incomplete_users($cm, $sid, /** * Called by HTML editor in showrespondents and Essay question. Based on question/essay/renderer. * Pending general solution to using the HTML editor outside of moodleforms in Moodle pages. + * @param int $context + * @return array */ function questionnaire_get_editor_options($context) { return array( @@ -581,8 +624,11 @@ function questionnaire_get_editor_options($context) { ); } -// Get the parent of a child question. -// TODO - This needs to be refactored or removed. +/** + * Get the parent of a child question. + * @param stdClass $question + * @return array + */ function questionnaire_get_parent ($question) { global $DB; $qid = $question->id; @@ -688,7 +734,11 @@ function questionnaire_get_child_positions ($questions) { return $childpositions; } -// Check that the needed page breaks are present to separate child questions. +/** + * Check that the needed page breaks are present to separate child questions. + * @param stdClass $questionnaire + * @return false|lang_string|string + */ function questionnaire_check_page_breaks($questionnaire) { global $DB; $msg = ''; @@ -805,6 +855,10 @@ function questionnaire_check_page_breaks($questionnaire) { /** * Code snippet used to set up the questionform. + * @param stdClass $questionnaire + * @param int $qid + * @param int $qtype + * @return mixed|\mod_questionnaire\question\question */ function questionnaire_prep_for_questionform($questionnaire, $qid, $qtype) { $context = context_module::instance($questionnaire->cm->id); diff --git a/mod_form.php b/mod_form.php index 64760bb7..ebbcff35 100644 --- a/mod_form.php +++ b/mod_form.php @@ -14,22 +14,25 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * print the form to add or edit a questionnaire-instance - * - * @author Mike Churchward - * @license http://www.gnu.org/copyleft/gpl.html GNU Public License - * @package questionnaire - */ - defined('MOODLE_INTERNAL') || die(); require_once($CFG->dirroot.'/course/moodleform_mod.php'); require_once($CFG->dirroot.'/mod/questionnaire/questionnaire.class.php'); require_once($CFG->dirroot.'/mod/questionnaire/locallib.php'); +/** + * print the form to add or edit a questionnaire-instance + * + * @package mod_questionnaire + * @author Mike Churchward + * @copyright 2016 onward Mike Churchward (mike.churchward@poetgroup.org) + * @license http://www.gnu.org/copyleft/gpl.html GNU Public License + */ class mod_questionnaire_mod_form extends moodleform_mod { + /** + * Form definition. + */ protected function definition() { global $COURSE; global $questionnairetypes, $questionnairerespondents, $questionnaireresponseviewers, $autonumbering; @@ -145,6 +148,10 @@ protected function definition() { $this->add_action_buttons(); } + /** + * Pre-process form data. + * @param array $defaultvalues + */ public function data_preprocessing(&$defaultvalues) { global $DB; if (empty($defaultvalues['opendate'])) { @@ -171,7 +178,6 @@ public function data_preprocessing(&$defaultvalues) { /** * Enforce validation rules here - * * @param array $data array of ("fieldname"=>value) of submitted data * @param array $files array of uploaded files "element_name"=>tmp_file_path * @return array @@ -188,12 +194,21 @@ public function validation($data, $files) { return $errors; } + /** + * Add any completion rules for the form. + * @return string[] + */ public function add_completion_rules() { $mform =& $this->_form; $mform->addElement('checkbox', 'completionsubmit', '', get_string('completionsubmit', 'questionnaire')); return array('completionsubmit'); } + /** + * True if the completion rule is enabled. + * @param array $data + * @return bool + */ public function completion_rule_enabled($data) { return !empty($data['completionsubmit']); } diff --git a/myreport.php b/myreport.php index 41ddc0cf..ea8dea75 100644 --- a/myreport.php +++ b/myreport.php @@ -14,8 +14,15 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -// This page shows results of a questionnaire to a student. - +/** + * This page shows results of a questionnaire to a student. + * + * @package mod_questionnaire + * @copyright 2016 Mike Churchward (mike.churchward@poetgroup.org) + * @author Mike Churchward + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * + */ require_once("../../config.php"); require_once($CFG->dirroot.'/mod/questionnaire/questionnaire.class.php'); diff --git a/preview.php b/preview.php index 23a81884..aec2adeb 100644 --- a/preview.php +++ b/preview.php @@ -14,7 +14,14 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -// This page displays a non-completable instance of questionnaire. +/** + * This page displays a non-completable instance of questionnaire. + * + * @package mod_questionnaire + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @copyright 2016 onward Mike Churchward (mike.churchward@poetgroup.org) + * @author Mike Churchward + */ require_once("../../config.php"); require_once($CFG->dirroot.'/mod/questionnaire/questionnaire.class.php'); diff --git a/print.php b/print.php index 6c43f650..c5b49a49 100644 --- a/print.php +++ b/print.php @@ -14,6 +14,15 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +/** + * The main page to print a questionnaire. + * + * @package mod_questionnaire + * @copyright 2016 Mike Churchward (mike.churchward@poetgroup.org) + * @author Mike Churchward + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * + */ require_once("../../config.php"); require_once($CFG->dirroot.'/mod/questionnaire/questionnaire.class.php'); diff --git a/qsettings.php b/qsettings.php index 82e169e0..22fae579 100644 --- a/qsettings.php +++ b/qsettings.php @@ -14,7 +14,13 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -// This page prints a particular instance of questionnaire. +/** + * This page handles the question settings. + * + * @package mod_questionnaire + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @copyright 2016 Mike Churchward (mike.churchward@poetopensource.org) + */ require_once("../../config.php"); require_once($CFG->dirroot.'/mod/questionnaire/questionnaire.class.php'); diff --git a/questionnaire.class.php b/questionnaire.class.php index abd437f5..c6f00569 100644 --- a/questionnaire.class.php +++ b/questionnaire.class.php @@ -14,17 +14,18 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +defined('MOODLE_INTERNAL') || die(); + +require_once($CFG->dirroot.'/mod/questionnaire/locallib.php'); + /** + * Provided the main API functions for questionnaire. + * * @package mod_questionnaire * @copyright 2016 Mike Churchward (mike.churchward@poetgroup.org) * @author Mike Churchward * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - -defined('MOODLE_INTERNAL') || die(); - -require_once($CFG->dirroot.'/mod/questionnaire/locallib.php'); - class questionnaire { // Class Properties. @@ -52,9 +53,14 @@ class questionnaire { // Class Methods. - /* - * The class constructor - * + /** + * The constructor. + * @param stdClass $course + * @param stdClass $cm + * @param int $id + * @param null|stdClass $questionnaire + * @param bool $addquestions + * @throws dml_exception */ public function __construct(&$course, &$cm, $id = 0, $questionnaire = null, $addquestions = true) { global $DB; @@ -98,7 +104,8 @@ public function __construct(&$course, &$cm, $id = 0, $questionnaire = null, $add /** * Adding a survey record to the object. - * + * @param int $sid + * @param null $survey */ public function add_survey($sid = 0, $survey = null) { global $DB; @@ -112,6 +119,7 @@ public function add_survey($sid = 0, $survey = null) { /** * Adding questions to the object. + * @param bool $sid */ public function add_questions($sid = false) { global $DB; @@ -153,7 +161,6 @@ public function add_questions($sid = false) { * Load all response information for this user. * * @param int $userid - * @throws dml_exception */ public function add_user_responses($userid = null) { global $USER, $DB; @@ -176,10 +183,9 @@ public function add_user_responses($userid = null) { /** * Load the specified response information. * - * @param $responseid - * @throws dml_exception + * @param int $responseid */ - public function add_response($responseid) { + public function add_response(int $responseid) { global $DB; // Empty questionnaires cannot have responses. @@ -194,21 +200,20 @@ public function add_response($responseid) { /** * Load the response information from a submitted web form. * - * @param $formdata - * @throws dml_exception + * @param stdClass $formdata */ - public function add_response_from_formdata($formdata) { + public function add_response_from_formdata(stdClass $formdata) { $this->responses[0] = mod_questionnaire\responsetype\response\response::response_from_webform($formdata, $this->questions); } /** * Return a response object from a submitted mobile app form. * - * @param $appdata + * @param stdClass $appdata * @param int $sec * @return bool|\mod_questionnaire\responsetype\response\response */ - public function build_response_from_appdata($appdata, $sec=0) { + public function build_response_from_appdata(stdClass $appdata, $sec=0) { $questions = []; if ($sec == 0) { $questions = $this->questions; @@ -222,15 +227,15 @@ public function build_response_from_appdata($appdata, $sec=0) { /** * Add the renderer to the questionnaire object. - * @param \plugin_renderer_base $renderer The module renderer, extended from core renderer. + * @param plugin_renderer_base $renderer The module renderer, extended from core renderer. */ - public function add_renderer($renderer) { + public function add_renderer(plugin_renderer_base $renderer) { $this->renderer = $renderer; } /** * Add the templatable page to the questionnaire object. - * @param \renderable, \templatable $page The page to rendere, implementing core classes. + * @param templatable $page The page to render, implementing core classes. */ public function add_page($page) { $this->page = $page; @@ -254,6 +259,9 @@ public function pages_autonumbered() { return (!empty($this->autonum) && (($this->autonum == 2) || ($this->autonum == 3))); } + /** + * The main module view function. + */ public function view() { global $CFG, $USER, $PAGE; @@ -314,12 +322,24 @@ public function view() { } } + /** + * Delete the specified response, and insert a new one. + * @param int $rid + * @param int $sec + * @param int $quser + * @return bool|int + */ public function delete_insert_response($rid, $sec, $quser) { $this->response_delete($rid, $sec); $this->rid = $this->response_insert((object)['sec' => $sec, 'rid' => $rid], $quser); return $this->rid; } + /** + * Commit the response. + * @param int $rid + * @param int $quser + */ public function commit_submission_response($rid, $quser) { $this->response_commit($rid); // If it was a previous save, rid is in the form... @@ -354,7 +374,7 @@ public function commit_submission_response($rid, $quser) { /** * Update the grade for this questionnaire and user. * - * @param $userid + * @param int $userid */ private function update_grades($userid) { if ($this->grade != 0) { @@ -368,12 +388,9 @@ private function update_grades($userid) { } } - /* - * Function to view an entire responses data. - * - */ /** - * @param $rid + * Function to view an entire responses data. + * @param int $rid * @param string $referer * @param string $resps * @param bool $compare @@ -419,7 +436,6 @@ public function view_response($rid, $referer= '', $resps = '', $compare = false, /** * Function to view all loaded responses. - * @throws coding_exception */ public function view_all_responses() { $this->print_survey_start('', 1, 1, 0); @@ -437,18 +453,36 @@ public function view_all_responses() { } // Access Methods. + + /** + * True if the questionnaire is active. + * @return bool + */ public function is_active() { return (!empty($this->survey)); } + /** + * True if the questionnaire is open. + * @return bool + */ public function is_open() { return ($this->opendate > 0) ? ($this->opendate < time()) : true; } + /** + * True if the questionnaire is closed. + * @return bool + */ public function is_closed() { return ($this->closedate > 0) ? ($this->closedate < time()) : false; } + /** + * True if the specified user can complete this questionnaire. + * @param int $userid + * @return bool + */ public function user_can_take($userid) { if (!$this->is_active() || !$this->user_is_eligible($userid)) { @@ -462,6 +496,11 @@ public function user_can_take($userid) { } } + /** + * True if the specified user is eligible to complete this questionnaire. + * @param int $userid + * @return bool + */ public function user_is_eligible($userid) { return ($this->capabilities->view && $this->capabilities->submit); } @@ -471,7 +510,6 @@ public function user_is_eligible($userid) { * @param int $userid * @param bool $asnotification Return as a rendered notification. * @return bool|string - * @throws coding_exception */ public function user_access_messages($userid = 0, $asnotification = false) { global $USER; @@ -526,6 +564,11 @@ public function user_access_messages($userid = 0, $asnotification = false) { return $message; } + /** + * True if the specified user has a saved response for this questionnaire. + * @param int $userid + * @return bool + */ public function user_has_saved_response($userid) { global $DB; @@ -533,6 +576,11 @@ public function user_has_saved_response($userid) { ['questionnaireid' => $this->id, 'userid' => $userid, 'complete' => 'n']); } + /** + * True if the specified user can complete this questionnaire at this time. + * @param int $userid + * @return bool + */ public function user_time_for_new_attempt($userid) { global $DB; @@ -589,10 +637,19 @@ public function user_time_for_new_attempt($userid) { return $cantake; } + /** + * True if the accessing course contains the actual questionnaire, as opposed to an instance of a public questionnaire. + * @return bool + */ public function is_survey_owner() { return (!empty($this->survey->courseid) && ($this->course->id == $this->survey->courseid)); } + /** + * True if the user can view the specified response. + * @param int $rid + * @return bool|void + */ public function can_view_response($rid) { global $USER, $DB; @@ -653,12 +710,11 @@ public function can_view_response($rid) { /** * True if the user can view the responses to this questionnaire, and there are valid responses. - * @param null $usernumresp + * @param null|int $usernumresp * @return bool - * @throws coding_exception */ public function can_view_all_responses($usernumresp = null) { - global $USER, $DB, $SESSION; + global $USER, $SESSION; $owner = $this->is_survey_owner(); $numresp = $this->count_submissions(); @@ -690,9 +746,9 @@ public function can_view_all_responses($usernumresp = null) { /** * True if the user can view all of the responses to this questionnaire any time, and there are valid responses. - * @param null $usernumresp + * @param bool $grouplogic + * @param bool $respslogic * @return bool - * @throws coding_exception */ public function can_view_all_responses_anytime($grouplogic = true, $respslogic = true) { // Can view if you are a valid group user, this is the owning course, and there are responses, and you have no @@ -702,9 +758,10 @@ public function can_view_all_responses_anytime($grouplogic = true, $respslogic = /** * True if the user can view all of the responses to this questionnaire any time, and there are valid responses. - * @param null $usernumresp + * @param null|int $usernumresp + * @param bool $grouplogic + * @param bool $respslogic * @return bool - * @throws coding_exception */ public function can_view_all_responses_with_restrictions($usernumresp, $grouplogic = true, $respslogic = true) { // Can view if you are a valid group user, this is the owning course, and there are responses, and you can view @@ -717,6 +774,12 @@ public function can_view_all_responses_with_restrictions($usernumresp, $grouplog } + /** + * Return the number of submissions for this questionnaire. + * @param bool $userid + * @param int $groupid + * @return int + */ public function count_submissions($userid=false, $groupid=0) { global $DB; @@ -761,7 +824,6 @@ public function count_submissions($userid=false, $groupid=0) { * @param int|bool $userid * @param int $groupid * @return array - * @throws dml_exception */ public function get_responses($userid=false, $groupid=0) { global $DB; @@ -803,6 +865,11 @@ public function get_responses($userid=false, $groupid=0) { return $DB->get_records_sql($sql, $params); } + /** + * True if any of the questions are required. + * @param int $section + * @return bool + */ private function has_required($section = 0) { if (empty($this->questions)) { return false; @@ -841,7 +908,8 @@ public function has_dependencies() { } /** - * @param $questionid + * Get a list of all dependent questions. + * @param int $questionid * @return array */ public function get_all_dependants($questionid) { @@ -872,7 +940,8 @@ public function get_all_dependants($questionid) { } /** - * @param $questionid + * Get a list of all dependent questions. + * @param int $questionid * @return array */ public function get_dependants($questionid) { @@ -892,8 +961,8 @@ public function get_dependants($questionid) { /** * Function to sort descendants array in get_dependants function. - * @param $a - * @param $b + * @param mixed $a + * @param mixed $b * @return int */ private static function cmp($a, $b) { @@ -927,7 +996,7 @@ public function get_dependants_and_choices() { /** * Load needed parent question information into the dependencies structure for the requested question. - * @param $question + * @param \mod_questionnaire\question\question $question * @return bool */ public function load_parents($question) { @@ -975,8 +1044,8 @@ public function load_parents($question) { /** * Determine the next valid page and return it. Return false if no valid next page. - * @param $secnum - * @param $rid + * @param int $secnum + * @param int $rid * @return int | bool */ public function next_page($secnum, $rid) { @@ -996,8 +1065,9 @@ public function next_page($secnum, $rid) { } /** - * @param $secnum - * @param $rid + * Determine the previous valid page and return it. Return false if no valid previous page. + * @param int $secnum + * @param int $rid * @return int | bool */ public function prev_page($secnum, $rid) { @@ -1014,8 +1084,9 @@ public function prev_page($secnum, $rid) { } /** - * @param $response - * @param $userid + * Return the correct action to a next page request. + * @param mod_questionnaire\responsetype\response\response $response + * @param int $userid * @return bool|int|string */ public function next_page_action($response, $userid) { @@ -1029,8 +1100,9 @@ public function next_page_action($response, $userid) { } /** - * @param $response - * @param $userid + * Return the correct action to a previous page request. + * @param mod_questionnaire\responsetype\response\response $response + * @param int $userid * @return bool|int */ public function previous_page_action($response, $userid) { @@ -1039,11 +1111,10 @@ public function previous_page_action($response, $userid) { } /** - * @param $response - * @param $userid + * Handle updating an existing response. + * @param mod_questionnaire\responsetype\response\response $response + * @param int $userid * @return bool|int - * @throws coding_exception - * @throws dml_exception */ public function existing_response_action($response, $userid) { $this->response_delete($response->rid, $response->sec); @@ -1052,8 +1123,8 @@ public function existing_response_action($response, $userid) { /** * Are there any eligible questions to be displayed on the specified page/section. - * @param $secnum The section number to check. - * @param $rid The current response id. + * @param int $secnum The section number to check. + * @param int $rid The current response id. * @return boolean */ public function eligible_questions_on_page($secnum, $rid) { @@ -1070,6 +1141,12 @@ public function eligible_questions_on_page($secnum, $rid) { // Display Methods. + /** + * The main display method for the survey. Adds HTML to the templates. + * @param int $quser + * @param bool $userid + * @return string|void + */ public function print_survey($quser, $userid=false) { global $SESSION, $CFG; @@ -1201,11 +1278,11 @@ public function print_survey($quser, $userid=false) { } /** - * @param $formdata + * Print the entire survey page. + * @param stdClass $formdata * @param int $section * @param string $message * @return bool|void - * @throws coding_exception */ private function survey_render(&$formdata, $section = 1, $message = '') { @@ -1265,6 +1342,16 @@ private function survey_render(&$formdata, $section = 1, $message = '') { return; } + /** + * Print the start of the survey page. + * @param string $message + * @param int $section + * @param int $numsections + * @param bool $hasrequired + * @param string $rid + * @param bool $blankquestionnaire + * @param string $outputtarget + */ private function print_survey_start($message, $section, $numsections, $hasrequired, $rid='', $blankquestionnaire=false, $outputtarget = 'html') { global $CFG, $DB; @@ -1413,6 +1500,11 @@ private function print_survey_start($message, $section, $numsections, $hasrequir } } + /** + * Print the end of the survey page. + * @param int $section + * @param int $numsections + */ private function print_survey_end($section, $numsections) { // If no pages autonumbering. if (!$this->pages_autonumbered()) { @@ -1427,7 +1519,15 @@ private function print_survey_end($section, $numsections) { } } - // Blankquestionnaire : if we are printing a blank questionnaire. + /** + * Display a survey suitable for printing. + * @param int $courseid + * @param string $message + * @param string $referer + * @param int $rid + * @param bool $blankquestionnaire If we are printing a blank questionnaire. + * @return false|void + */ public function survey_print_render($courseid, $message = '', $referer='', $rid=0, $blankquestionnaire=false) { global $DB, $CFG; @@ -1536,6 +1636,11 @@ public function survey_print_render($courseid, $message = '', $referer='', $rid= return; } + /** + * Update an existing survey. + * @param stdClass $sdata + * @return bool|int + */ public function survey_update($sdata) { global $DB; @@ -1604,7 +1709,11 @@ public function survey_update($sdata) { return($this->survey->id); } - /* Creates an editable copy of a survey. */ + /** + * Creates an editable copy of a survey. + * @param int $owner + * @return bool|int + */ public function survey_copy($owner) { global $DB; @@ -1708,12 +1817,12 @@ public function survey_copy($owner) { // RESPONSE LIBRARY. /** - * @param $section - * @param $formdata + * Check that all questions have been answered in a suitable way. + * @param int $section + * @param stdClass $formdata * @param bool $checkmissing * @param bool $checkwrongformat * @return string - * @throws coding_exception */ private function response_check_format($section, $formdata, $checkmissing = true, $checkwrongformat = true) { $missing = 0; @@ -1779,6 +1888,11 @@ private function response_check_format($section, $formdata, $checkmissing = true return ($message); } + /** + * Delete the spcified response. + * @param int $rid + * @param null|int $sec + */ private function response_delete($rid, $sec = null) { global $DB; @@ -1822,9 +1936,9 @@ private function response_delete($rid, $sec = null) { } /** - * @param $rid + * Commit the specified response. + * @param int $rid * @return bool - * @throws dml_exception */ private function response_commit($rid) { global $DB; @@ -1846,7 +1960,6 @@ private function response_commit($rid) { * Get the latest response id for the user, or verify that the given response id is valid. * @param int $userid * @return int - * @throws dml_exception */ public function get_latest_responseid($userid) { global $DB; @@ -1861,7 +1974,11 @@ public function get_latest_responseid($userid) { } } - // Returns the number of the section in which questions have been answered in a response. + /** + * Returns the number of the section in which questions have been answered in a response. + * @param int $rid + * @return int + */ private function response_select_max_sec($rid) { global $DB; @@ -1873,7 +1990,11 @@ private function response_select_max_sec($rid) { return $max; } - // Returns the position of the last answered question in a response. + /** + * Returns the position of the last answered question in a response. + * @param int $rid + * @return int + */ private function response_select_max_pos($rid) { global $DB; @@ -2063,9 +2184,8 @@ public function get_notifiable_users($userid) { /** * Return a formatted string containing all the questions and answers for a specific submission. - * @param $rid + * @param int $rid * @return string - * @throws coding_exception */ private function get_full_submission_for_notifications($rid) { $responses = $this->get_full_submission_for_export($rid); @@ -2085,7 +2205,7 @@ private function get_full_submission_for_notifications($rid) { /** * Construct the response data for a given response and return a structured export. - * @param $rid + * @param int $rid * @return string * @throws coding_exception */ @@ -2096,7 +2216,7 @@ public function get_structured_response($rid) { /** * Return a JSON structure containing all the questions and answers for a specific submission. - * @param $rid + * @param int $rid * @return array */ private function get_full_submission_for_export($rid) { @@ -2206,8 +2326,6 @@ private function get_formatted_answers_for_emails($answers) { * @param int $rid The id of the response record. * @param string $email The comma separated list of emails to send to. * @return bool - * @throws coding_exception - * @throws dml_exception */ private function response_send_email($rid, $email) { global $CFG; @@ -2263,12 +2381,11 @@ private function response_send_email($rid, $email) { } /** + * Insert the provided response. * @param object $responsedata An object containing all data for the response. * @param int $userid * @param bool $resume * @return bool|int - * @throws coding_exception - * @throws dml_exception */ public function response_insert($responsedata, $userid, $resume=false) { global $DB; @@ -2313,6 +2430,11 @@ public function response_insert($responsedata, $userid, $resume=false) { return($responsedata->rid); } + /** + * Get the answers for the all response types. + * @param int $rid + * @return array + */ private function response_select($rid) { // Response_bool (yes/no). $values = \mod_questionnaire\responsetype\boolean::response_select($rid); @@ -2335,6 +2457,9 @@ private function response_select($rid) { return($values); } + /** + * Redirect to the appropriate finish page. + */ private function response_goto_thankyou() { global $CFG, $USER, $DB; @@ -2398,6 +2523,10 @@ private function response_goto_thankyou() { return; } + /** + * Redirect to the provided url. + * @param string $url + */ private function response_goto_saved($url) { global $CFG; $resumesurvey = get_string('resumesurvey', 'questionnaire'); @@ -2413,6 +2542,13 @@ private function response_goto_saved($url) { // Survey Results Methods. + /** + * Add the navigation to the responses page. + * @param int $currrid + * @param int $currentgroupid + * @param stdClass $cm + * @param bool $byresponse + */ public function survey_results_navbar_alpha($currrid, $currentgroupid, $cm, $byresponse) { global $CFG, $DB; @@ -2571,7 +2707,15 @@ public function survey_results_navbar_alpha($currrid, $currentgroupid, $cm, $byr } } - // Display responses for current user (your responses). + /** + * Display responses for current user (your responses). + * @param int $currrid + * @param int $userid + * @param int $instance + * @param array $resps + * @param string $reporttype + * @param string $sid + */ public function survey_results_navbar_student($currrid, $userid, $instance, $resps, $reporttype='myreport', $sid='') { global $DB; $stranonymous = get_string('anonymous', 'questionnaire'); @@ -2641,11 +2785,10 @@ public function survey_results_navbar_student($currrid, $userid, $instance, $res * error string. * @param string $rid * @param bool $uid + * @param bool $pdf * @param string $currentgroupid * @param string $sort * @return string|void - * @throws coding_exception - * @throws dml_exception */ public function survey_results($rid = '', $uid=false, $pdf = false, $currentgroupid='', $sort='') { global $SESSION, $DB; @@ -2783,12 +2926,9 @@ public function survey_results($rid = '', $uid=false, $pdf = false, $currentgrou /** * Get unique list of question types used in the current survey. - * - * @author: Guy Thomas - * @param int $surveyid + * author: Guy Thomas * @param bool $uniquebytable * @return array - * @throws moodle_exception */ protected function get_survey_questiontypes($uniquebytable = false) { @@ -2823,8 +2963,7 @@ protected function choice_types() { /** * Return all the fields to be used for users in questionnaire sql. - * - * @author: Guy Thomas + * author: Guy Thomas * @return array|string */ protected function user_fields() { @@ -2839,10 +2978,11 @@ protected function user_fields() { /** * Get all survey responses in one go. - * - * @author: Guy Thomas + * author: Guy Thomas * @param string $rid * @param string $userid + * @param bool $groupid + * @param int $showincompletes * @return array */ protected function get_survey_all_responses($rid = '', $userid = '', $groupid = false, $showincompletes = 0) { @@ -2894,18 +3034,14 @@ public function survey_is_public_master() { /** * Process individual row for csv output - * @param array $outputrow output row + * @param array $row * @param stdClass $resprow resultset row * @param int $currentgroupid * @param array $questionsbyposition * @param int $nbinfocols * @param int $numrespcols + * @param int $showincompletes * @return array - * @throws Exception - * @throws coding_exception - * @throws dml_exception - * @throws dml_missing_record_exception - * @throws dml_multiple_records_exception */ protected function process_csv_row(array &$row, stdClass $resprow, @@ -3041,9 +3177,17 @@ protected function process_csv_row(array &$row, return $positioned; } - /* {{{ proto array survey_generate_csv(int surveyid) - Exports the results of a survey to an array. - */ + /** + * Exports the results of a survey to an array. + * @param int $currentgroupid + * @param string $rid + * @param string $userid + * @param int $choicecodes + * @param int $choicetext + * @param int $showincompletes + * @param int $rankaverages + * @return array + */ public function generate_csv($currentgroupid, $rid='', $userid='', $choicecodes=1, $choicetext=0, $showincompletes=0, $rankaverages=0) { global $DB; @@ -3465,7 +3609,6 @@ public function generate_csv($currentgroupid, $rid='', $userid='', $choicecodes= * @param int $movetopos The position to move question to. * */ - public function move_question($moveqid, $movetopos) { global $DB; @@ -3492,6 +3635,17 @@ public function move_question($moveqid, $movetopos) { return false; } + /** + * Render the response analysis page. + * @param int $rid + * @param array $resps + * @param bool $compare + * @param bool $isgroupmember + * @param bool $allresponses + * @param int $currentgroupid + * @param array $filteredsections + * @return array|string + */ public function response_analysis($rid, $resps, $compare, $isgroupmember, $allresponses, $currentgroupid, $filteredsections = null) { global $DB, $CFG; @@ -3837,16 +3991,17 @@ public function response_analysis($rid, $resps, $compare, $isgroupmember, $allre } // Mobile support area. + /** - * @param $userid - * @param $sec - * @param $completed - * @param $submit + * Save the data from the mobile app. + * @param int $userid + * @param int $sec + * @param bool $completed + * @param int $rid + * @param bool $submit + * @param string $action * @param array $responses * @return array - * @throws coding_exception - * @throws dml_exception - * @throws moodle_exception */ public function save_mobile_data($userid, $sec, $completed, $rid, $submit, $action, array $responses) { global $DB, $CFG; // Do not delete "$CFG". @@ -3883,6 +4038,11 @@ public function save_mobile_data($userid, $sec, $completed, $rid, $submit, $acti return $ret; } + /** + * Get all of the areas that can have files. + * @return array + * @throws dml_exception + */ public function get_all_file_areas() { global $DB; diff --git a/questions.php b/questions.php index 20a1c876..5a59b557 100644 --- a/questions.php +++ b/questions.php @@ -14,6 +14,14 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +/** + * This page handles the main question editing screen. + * + * @package mod_questionnaire + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @copyright 2016 Mike Churchward (mike.churchward@poetopensource.org) + */ + require_once("../../config.php"); require_once($CFG->dirroot.'/mod/questionnaire/questionnaire.class.php'); require_once($CFG->dirroot.'/mod/questionnaire/classes/question/question.php'); // Needed for question type constants. diff --git a/report.php b/report.php index 7822234c..1d55b610 100755 --- a/report.php +++ b/report.php @@ -14,6 +14,15 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +/** + * The main report page for a questionnaire. + * + * @package mod_questionnaire + * @copyright 2016 Mike Churchward (mike.churchward@poetgroup.org) + * @author Mike Churchward + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * + */ require_once("../../config.php"); require_once($CFG->dirroot.'/mod/questionnaire/questionnaire.class.php'); @@ -818,6 +827,7 @@ } /** + * Return a pdf object. * @return pdf */ function questionnaire_report_start_pdf() { diff --git a/savefileformat.php b/savefileformat.php index 5c6a6d15..cb01d211 100644 --- a/savefileformat.php +++ b/savefileformat.php @@ -31,8 +31,9 @@ * @param string $dataformat A dataformat name * @param array $columns An ordered map of column keys and labels * @param Iterator $iterator An iterator over the records, usually a RecordSet - * @param function $callback An option function applied to each record before writing - * @param mixed $extra An optional value which is passed into the callback function + * @param array $users + * @param array $emails + * @param string $redirect */ function save_as_dataformat($filename, $dataformat, $columns, $iterator, $users = [], $emails = [], $redirect = '') { global $CFG, $OUTPUT; diff --git a/settings.php b/settings.php index 1b61f757..732ed0b5 100644 --- a/settings.php +++ b/settings.php @@ -17,9 +17,10 @@ /** * Setting page for questionaire module * - * @package mod - * @subpackage questionnaire + * @package mod_questionnaire * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @copyright 2016 onward Mike Churchward (mike.churchward@poetgroup.org) + * @author Mike Churchward */ defined('MOODLE_INTERNAL') || die; diff --git a/show_nonrespondents.php b/show_nonrespondents.php index 15707946..23ec5dc1 100644 --- a/show_nonrespondents.php +++ b/show_nonrespondents.php @@ -15,11 +15,11 @@ // along with Moodle. If not, see . /** - * + * Show the non-respondents to a questionnaire. * @author Joseph Rézeau (copied from feedback plugin show_nonrespondents by original author Andreas Grabs) + * @copyright 2016 Mike Churchward (mike.churchward@poetopensource.org) * @license http://www.gnu.org/copyleft/gpl.html GNU Public License - * @package mod - * @subpackage questionnaire + * @package mod_questionnaire * */ diff --git a/tests/behat/behat_mod_questionnaire.php b/tests/behat/behat_mod_questionnaire.php index 88769895..c3be55c2 100644 --- a/tests/behat/behat_mod_questionnaire.php +++ b/tests/behat/behat_mod_questionnaire.php @@ -115,7 +115,7 @@ public function i_add_a_question_and_i_fill_the_form_with($questiontype, TableNo * * @Given /^I click the "([^"]*)" radio button$/ * - * @param string $radiogroupname The "id" attribute of the radio button. + * @param int $radioid */ public function i_click_the_radio_button($radioid) { $session = $this->getSession(); @@ -357,7 +357,7 @@ private function add_response_data($qid, $sid) { * @param array $data Array of data record row arrays. The first row contains the field names. * @param string $datatable The name of the data table to insert records into. * @param string $mapvar The name of the object variable to store oldid / newid mappings (optional). - * @param string $replvars Array of key/value pairs where key is the mapvar and value is the record field + * @param array|null $replvars Array of key/value pairs where key is the mapvar and value is the record field * to replace with mapped values. * @return null */ diff --git a/tests/csvexport_test.php b/tests/csvexport_test.php index 461c16d0..dd164e71 100644 --- a/tests/csvexport_test.php +++ b/tests/csvexport_test.php @@ -14,23 +14,14 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Test performance of questionnaire. - * @author Guy Thomas - * @copyright Copyright (c) 2015 Moodlerooms Inc. (http://www.moodlerooms.com) - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die(); - /** * Performance test for questionnaire module. + * @package mod_questionnaire * @group mod_questionnaire * @author Guy Thomas * @copyright Copyright (c) 2015 Moodlerooms Inc. (http://www.moodlerooms.com) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - class mod_questionnaire_csvexport_test extends advanced_testcase { public function setUp(): void { @@ -88,6 +79,10 @@ public function test_csvexport() { } } + /** + * Return the expected output. + * @return string[] + */ private function expected_complete_output() { return ["Institution Department Course Group Full name Username Q01_Text Box 1000 Q02_Essay Box 1002 " . "Q03_Numeric 1004 Q04_Date 1006 Q05_Radio Buttons 1008 Q06_Drop Down 1010 Q07_Check Boxes 1012->four " . @@ -107,6 +102,10 @@ private function expected_complete_output() { "27/12/2017 wind three 0 0 0 0 0 0 0 0 0 1 1 2 3 4 5 1 2 3 4 "]; } + /** + * Return the exepected incomplete output. + * @return string[] + */ private function expected_incomplete_output() { return ["Institution Department Course Group Full name Username Complete Q01_Text Box 1000 " . "Q02_Essay Box 1002 " . diff --git a/tests/generator/lib.php b/tests/generator/lib.php index f2cdcb82..fa0d52bd 100644 --- a/tests/generator/lib.php +++ b/tests/generator/lib.php @@ -14,16 +14,6 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * mod_questionnaire data generator - * - * @package mod_questionnaire - * @copyright 2015 Mike Churchward (mike@churchward.ca) - * @author Mike Churchward - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - - defined('MOODLE_INTERNAL') || die(); use mod_questionnaire\generator\question_response, @@ -33,6 +23,14 @@ global $CFG; require_once($CFG->dirroot.'/mod/questionnaire/locallib.php'); +/** + * The mod_questionnaire data generator. + * + * @package mod_questionnaire + * @copyright 2015 Mike Churchward (mike@churchward.ca) + * @author Mike Churchward + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ class mod_questionnaire_generator extends testing_module_generator { /** @@ -51,23 +49,18 @@ class mod_questionnaire_generator extends testing_module_generator { protected $questionnaires = []; /** - * To be called from data reset code only, - * do not use in tests. + * To be called from data reset code only, do not use in tests. * @return void */ public function reset() { $this->questioncount = 0; - $this->responsecount = 0; - $this->questionnaires = []; - parent::reset(); } /** * Acessor for questionnaires. - * * @return array */ public function questionnaires() { @@ -118,9 +111,9 @@ public function create_instance($record = null, array $options = null) { /** * Create a survey instance with data from an existing questionnaire object. - * @param object $questionnaire - * @param array $options - * @return int + * @param questionnaire $questionnaire + * @param array $record + * @return bool|int */ public function create_content($questionnaire, $record = array()) { global $DB; @@ -205,6 +198,11 @@ public function create_question(questionnaire $questionnaire, $record = null, $d /** * Create a questionnaire with questions and response data for use in other tests. + * @param stdClass $course + * @param null|int $qtype + * @param array $questiondata + * @param null|array|stdClass $choicedata + * @return questionnaire */ public function create_test_questionnaire($course, $qtype = null, $questiondata = array(), $choicedata = null) { $questionnaire = $this->create_instance(array('course' => $course->id)); @@ -222,6 +220,12 @@ public function create_test_questionnaire($course, $qtype = null, $questiondata /** * Create a reponse to the supplied question. + * @param questionnaire $questionnaire + * @param question $question + * @param int|array $respval + * @param int $userid + * @param int $section + * @return false|mixed|stdClass */ public function create_question_response($questionnaire, $question, $respval, $userid = 1, $section = 1) { global $DB; @@ -238,6 +242,9 @@ public function create_question_response($questionnaire, $question, $respval, $u /** * Need to create a method to access a private questionnaire method. * TO DO - may not need this with above "TO DO". + * @param questionnaire $questionnaire + * @param int $responseid + * @return mixed */ private function response_commit($questionnaire, $responseid) { $method = new ReflectionMethod('questionnaire', 'response_commit'); @@ -247,7 +254,7 @@ private function response_commit($questionnaire, $responseid) { /** * Validate choice question type - * @param $data + * @param array $data * @throws coding_exception */ protected function validate_question_choice($data) { @@ -258,7 +265,7 @@ protected function validate_question_choice($data) { /** * Validate radio question type - * @param $data + * @param array $data * @throws coding_exception */ protected function validate_question_radio($data) { @@ -269,7 +276,7 @@ protected function validate_question_radio($data) { /** * Validate checkbox question type - * @param $data + * @param array $data * @throws coding_exception */ protected function validate_question_check($data) { @@ -280,7 +287,7 @@ protected function validate_question_check($data) { /** * Validate rating question type - * @param $data + * @param array $data * @throws coding_exception */ protected function validate_question_rate($data) { @@ -292,8 +299,7 @@ protected function validate_question_rate($data) { /** * Thrown an error if the question isn't receiving the data it should receive. * @param string $typeid - * @param $data - * @throws coding_exception + * @param array $data */ protected function validate_question($typeid, $data) { if ($typeid == QUESCHOOSE) { @@ -311,7 +317,7 @@ protected function validate_question($typeid, $data) { * Add choices to question. * * @param \mod_questionnaire\question\question $question - * @param stdClass $data + * @param array $data */ protected function add_question_choices($question, $data) { foreach ($data as $content) { @@ -331,9 +337,9 @@ protected function add_question_choices($question, $data) { } /** - * TODO - use question object * Does this question have choices. - * @param $typeid + * TODO - use question object + * @param int $typeid * @return bool */ public function question_has_choices($typeid) { @@ -341,6 +347,11 @@ public function question_has_choices($typeid) { return in_array($typeid, $choicequestions); } + /** + * Return a string value for the int id. + * @param int $qtypeid + * @return string + */ public function type_str($qtypeid) { switch ($qtypeid) { case QUESYESNO: @@ -379,6 +390,11 @@ public function type_str($qtypeid) { return $qtype; } + /** + * Return a display string for the int id. + * @param int $qtypeid + * @return string + */ public function type_name($qtypeid) { switch ($qtypeid) { case QUESYESNO: @@ -417,6 +433,11 @@ public function type_name($qtypeid) { return $qtype; } + /** + * Add the response choice. + * @param \mod_questionnaire\responsetype\response\response $questionresponse + * @param int $responseid + */ protected function add_response_choice($questionresponse, $responseid) { global $DB; @@ -545,9 +566,8 @@ public function create_response($questionresponses, $record = null, $complete = /** - * @param int $number - * * Generate an array of assigned options; + * @param int $number */ public function assign_opts($number = 5) { static $curpos = 0; @@ -575,12 +595,12 @@ public function assign_opts($number = 5) { } /** + * Generate a response. * @param questionnaire $questionnaire * @param \mod_questionnaire\question\question[] $questions - * @param $userid - * @param $complete + * @param int $userid + * @param bool $complete * @return stdClass - * @throws coding_exception */ public function generate_response($questionnaire, $questions, $userid, $complete = true) { $responses = []; @@ -637,8 +657,15 @@ public function generate_response($questionnaire, $questions, $userid, $complete return $this->create_response($responses, ['questionnaireid' => $questionnaire->id, 'userid' => $userid], $complete); } + /** + * Create fully defined questionnaires into the test database. + * @param int $coursecount + * @param int $studentcount + * @param int $questionnairecount + * @param int $questionspertype + */ public function create_and_fully_populate($coursecount = 4, $studentcount = 20, $questionnairecount = 2, - $questionspertype = 5) { + $questionspertype = 5) { global $DB; $dg = $this->datagenerator; @@ -725,6 +752,5 @@ public function create_and_fully_populate($coursecount = 4, $studentcount = 20, } } } - } } diff --git a/tests/generator_test.php b/tests/generator_test.php index 43557a53..2a07bc66 100644 --- a/tests/generator_test.php +++ b/tests/generator_test.php @@ -26,7 +26,7 @@ defined('MOODLE_INTERNAL') || die(); /** - * Unit tests for {@link questionnaire_generator_testcase}. + * Unit tests for questionnaire_generator_testcase. * @group mod_questionnaire */ class mod_questionnaire_generator_testcase extends advanced_testcase { diff --git a/tests/lib_test.php b/tests/lib_test.php index 71840863..e70974ba 100644 --- a/tests/lib_test.php +++ b/tests/lib_test.php @@ -32,7 +32,7 @@ require_once($CFG->dirroot.'/mod/questionnaire/classes/question/question.php'); /** - * Unit tests for {@link questionnaire_lib_testcase}. + * Unit tests for questionnaire_lib_testcase. * @group mod_questionnaire */ class mod_questionnaire_lib_testcase extends advanced_testcase { diff --git a/tests/questiontypes_test.php b/tests/questiontypes_test.php index 5d08c99b..be7aff5e 100644 --- a/tests/questiontypes_test.php +++ b/tests/questiontypes_test.php @@ -31,7 +31,7 @@ require_once($CFG->dirroot.'/mod/questionnaire/locallib.php'); /** - * Unit tests for {@link questionnaire_questiontypes_testcase}. + * Unit tests for questionnaire_questiontypes_testcase. * @group mod_questionnaire */ class mod_questionnaire_questiontypes_testcase extends advanced_testcase { @@ -93,6 +93,13 @@ public function test_create_question_yesno() { // General tests to call from specific tests above. + /** + * Create a test question. + * @param int $qtype + * @param question $questionclass + * @param array $questiondata + * @param null|array $choicedata + */ private function create_test_question($qtype, $questionclass, $questiondata = array(), $choicedata = null) { global $DB; @@ -139,6 +146,13 @@ private function create_test_question($qtype, $questionclass, $questiondata = ar } } + /** + * Create a test question with choices. + * @param int $qtype + * @param question $questionclass + * @param array $questiondata + * @param null|array $choicedata + */ private function create_test_question_with_choices($qtype, $questionclass, $questiondata = array(), $choicedata = null) { if ($choicedata === null) { $choicedata = array( diff --git a/tests/responsetypes_test.php b/tests/responsetypes_test.php index e6d5a730..9c48b01c 100644 --- a/tests/responsetypes_test.php +++ b/tests/responsetypes_test.php @@ -33,7 +33,7 @@ require_once($CFG->dirroot . '/mod/questionnaire/tests/questiontypes_test.php'); /** - * Unit tests for {@link questionnaire_responsetypes_testcase}. + * Unit tests for questionnaire_responsetypes_testcase. * @group mod_questionnaire */ class mod_questionnaire_responsetypes_testcase extends advanced_testcase { @@ -285,6 +285,14 @@ public function test_create_response_rank() { // General tests to call from specific tests above. + /** + * Create a test questionnaire. + * + * @param int $qtype + * @param array $questiondata + * @param null $choicedata + * @return questionnaire + */ public function create_test_questionnaire($qtype, $questiondata = [], $choicedata = null) { $this->resetAfterTest(); @@ -304,6 +312,15 @@ public function create_test_questionnaire($qtype, $questiondata = [], $choicedat return $questionnaire; } + /** + * General assertions for responses. + * + * @param int $questionnaireid + * @param int $responseid + * @param int $userid + * @param int $attemptcount + * @param int $responsecount + */ private function response_tests($questionnaireid, $responseid, $userid, $attemptcount = 1, $responsecount = 1) { global $DB; diff --git a/version.php b/version.php index c32ae2e2..3149ea46 100644 --- a/version.php +++ b/version.php @@ -19,6 +19,7 @@ * * @package mod_questionnaire * @author Mike Churchward + * @copyright 2016 Mike Churchward (mike.churchward@poetopensource.org) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ diff --git a/view.php b/view.php index 9f3f400b..e71007d1 100644 --- a/view.php +++ b/view.php @@ -14,6 +14,15 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +/** + * This main view page for a questionnaire. + * + * @package mod_questionnaire + * @copyright 2016 Mike Churchward (mike.churchward@poetgroup.org) + * @author Mike Churchward + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * + */ require_once("../../config.php"); require_once($CFG->dirroot.'/mod/questionnaire/locallib.php'); require_once($CFG->libdir . '/completionlib.php');