mod quiz: MDL-3156 Add an option to display the current user's photo and name on...
authortjhunt <tjhunt>
Wed, 7 Jan 2009 06:32:13 +0000 (06:32 +0000)
committertjhunt <tjhunt>
Wed, 7 Jan 2009 06:32:13 +0000 (06:32 +0000)
lang/en_utf8/help/quiz/showuserpicture.html [new file with mode: 0644]
lang/en_utf8/quiz.php
mod/quiz/attemptlib.php
mod/quiz/db/install.xml
mod/quiz/db/upgrade.php
mod/quiz/mod_form.php
mod/quiz/review.php
mod/quiz/settingstree.php
mod/quiz/version.php
theme/standard/styles_layout.css

diff --git a/lang/en_utf8/help/quiz/showuserpicture.html b/lang/en_utf8/help/quiz/showuserpicture.html
new file mode 100644 (file)
index 0000000..9aa1197
--- /dev/null
@@ -0,0 +1,7 @@
+<h1>Show the user's picture</h1>
+
+<p>If you enable this option, the student's name and picture will be
+   shown on-screen during the attempt, and on the review screen.</p>
+
+<p>One example when you might want to do this is in invigilated (proctored) exams
+   to make it easier to check that the user is logged in as themself.</p>
index 664190df8e9daa533eb5c6d64c04c40cabe3e528..2ecde429eeef90eda464378a13238932b028440d 100644 (file)
@@ -155,6 +155,7 @@ $string['configpopup'] = 'Use JavaScript tricks to try to restrict copy and past
 $string['configrequirepassword'] = 'Students must enter this password before they can attempt the quiz.';
 $string['configrequiresubnet'] = 'Students can only attempt the quiz from these computers.';
 $string['configreviewoptions'] = 'These options control what information users can see when they review a quiz attempt or look at the quiz reports.';
+$string['configshowuserpicture'] = 'Show the user\'s picture on screen during attempts.';
 $string['configshufflequestions'] = 'If you enable this option, then the order of questions in  the quiz will be randomly shuffled each time a student attempts the quiz.';
 $string['configshufflewithin'] = 'If you enable this option, then the parts making up the individual questions will be randomly shuffled each time a student starts an attempt at this quiz, provided the option is also enabled in the question settings.';
 $string['configtimelimit'] = 'Default time limit for quizzes in minutes. 0 mean no time limit.';
@@ -642,6 +643,7 @@ $string['shownoattempts'] = 'Show students with no attempts';
 $string['shownoattemptsonly'] = 'Show only students with no attempts';
 $string['showquestiontext'] = 'Show question text in the question list';
 $string['showteacherattempts'] = 'Show teacher attempts';
+$string['showuserpicture'] = 'Show the user\'s picture';
 $string['shuffle'] = 'Shuffle';
 $string['shuffleanswers'] = 'Shuffle answers';
 $string['shufflequestions'] = 'Shuffle questions';
index 541fe508c6dc4b8cfb8a5d5cb7333e4ccf7529c8..47fa2c720bff1108f72a45b555530787121f75c7 100644 (file)
@@ -896,6 +896,17 @@ abstract class quiz_nav_panel_base {
 
     abstract protected function get_end_bits();
 
+    protected function get_user_picture() {
+        global $DB;
+        $user = $DB->get_record('user', array('id' => $this->attemptobj->get_userid()));
+        $output = '';
+        $output .= '<div id="user-picture" class="clearfix">';
+        $output .= print_user_picture($user, $this->attemptobj->get_courseid(), NULL, 0, true, false);
+        $output .= ' ' . fullname($user);
+        $output .= '</div>';
+        return $output;
+    }
+
     protected function get_question_state_classes($question) {
         // The current status of the question.
         $classes = $this->attemptobj->get_question_status($question->id);
@@ -914,8 +925,12 @@ abstract class quiz_nav_panel_base {
 
     public function display() {
         $strquiznavigation = get_string('quiznavigation', 'quiz');
-        $content = $this->get_question_buttons() . "\n" . '<div class="othernav">' .
-                "\n" . $this->get_end_bits() . "\n</div>\n";
+        $content = '';
+        if ($this->attemptobj->get_quiz()->showuserpicture) {
+            $content .= $this->get_user_picture() . "\n";
+        }
+        $content .= $this->get_question_buttons() . "\n";
+        $content .= '<div class="othernav">' . "\n" . $this->get_end_bits() . "\n</div>\n";
         print_side_block($strquiznavigation, $content, NULL, NULL, '', array('id' => 'quiznavigation'), $strquiznavigation);
     }
 }
index 0901e614a47380e109eee3192b19e4aaca6de326..d819845f0700cc5d1dbf63702f43217e16c6c719 100755 (executable)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8" ?>
-<XMLDB PATH="mod/quiz/db" VERSION="20081121" COMMENT="XMLDB file for Moodle mod/quiz"
+<XMLDB PATH="mod/quiz/db" VERSION="20090107" COMMENT="XMLDB file for Moodle mod/quiz"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
 >
@@ -32,7 +32,8 @@
         <FIELD NAME="subnet" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="password" NEXT="popup"/>
         <FIELD NAME="popup" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="subnet" NEXT="delay1"/>
         <FIELD NAME="delay1" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="popup" NEXT="delay2"/>
-        <FIELD NAME="delay2" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="delay1"/>
+        <FIELD NAME="delay2" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="delay1" NEXT="showuserpicture"/>
+        <FIELD NAME="showuserpicture" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="Option to show the user's picture during the attempt and on the review page." PREVIOUS="delay2"/>
       </FIELDS>
       <KEYS>
         <KEY NAME="primary" TYPE="primary" FIELDS="id"/>
index a72b24718d4688fbe3d1d83964c1335d0ac5ac9d..6c813ccc9a0a83e09d6fcfeeba6b950cfb4b8906 100644 (file)
@@ -212,6 +212,21 @@ function xmldb_quiz_upgrade($oldversion) {
         upgrade_mod_savepoint($result, 2008112101, 'quiz');
     }
 
+    if ($result && $oldversion < 2009010700) {
+
+    /// Define field showuserpicture to be added to quiz
+        $table = new xmldb_table('quiz');
+        $field = new xmldb_field('showuserpicture', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, null, null, '0', 'delay2');
+
+    /// Conditionally launch add field showuserpicture
+        if (!$dbman->field_exists($table, $field)) {
+            $dbman->add_field($table, $field);
+        }
+
+    /// quiz savepoint reached
+        upgrade_mod_savepoint($result, 2009010700, 'quiz');
+    }
+
     return $result;
 }
 
index aa16ff235b032db8d0aea06431fb07de49d9c787..05dce8451febe8ec82ec4408b23eabd49532bece 100644 (file)
@@ -98,6 +98,11 @@ class mod_quiz_mod_form extends moodleform_mod {
         $mform->setAdvanced('shuffleanswers', $quizconfig->fix_shuffleanswers);
         $mform->setDefault('shuffleanswers', $quizconfig->shuffleanswers);
 
+        $mform->addElement('selectyesno', 'showuserpicture', get_string('showuserpicture', 'quiz'));
+        $mform->setHelpButton('showuserpicture', array('showuserpicture', get_string('showuserpicture', 'quiz'), 'quiz'));
+        $mform->setAdvanced('showuserpicture', $quizconfig->fix_showuserpicture);
+        $mform->setDefault('showuserpicture', $quizconfig->showuserpicture);
+
 //-------------------------------------------------------------------------------
         $mform->addElement('header', 'attemptshdr', get_string('attempts', 'quiz'));
         $attemptoptions = array('0' => get_string('unlimited'));
index 7b885fa5df25acfd521e9a10e0f70e6d57b0ef4d..9c48ac108fee9b5c7f12a86aa2c4bdc1a3ea5c32 100644 (file)
 /// First we assemble all the rows that are appopriate to the current situation in
 /// an array, then later we only output the table if there are any rows to show.
     $rows = array();
-    if ($attemptobj->get_userid() <> $USER->id) {
+    if (!$attemptobj->get_quiz()->showuserpicture && $attemptobj->get_userid() <> $USER->id) {
+    /// If showuserpicture is true, the picture is shown elsewhere, so don't repeat it.
         $student = $DB->get_record('user', array('id' => $attemptobj->get_userid()));
         $picture = print_user_picture($student, $attemptobj->get_courseid(), $student->picture, false, true);
         $rows[] = '<tr><th scope="row" class="cell">' . $picture . '</th><td class="cell"><a href="' .
index 1c43d72c3710e7a6ef7e55ab1998c88676ffb08c..231def4692d9d95fabc2f3f8cdd363b8f7e9923b 100644 (file)
@@ -86,6 +86,11 @@ $quizsettings->add(new admin_setting_yesno_with_advanced('quiz/shuffleanswers',
         get_string('shufflewithin', 'quiz'), get_string('configshufflewithin', 'quiz'),
         array('value' => 1, 'fix' => false)));
 
+// showuserpicture
+$quizsettings->add(new admin_setting_yesno_with_advanced('quiz/showuserpicture',
+        get_string('showuserpicture', 'quiz'), get_string('configshowuserpicture', 'quiz'),
+        array('value' => 0, 'fix' => false)));
+
 // attempts
 $options = array(get_string('unlimited'));
 for ($i = 1; $i <= 6; $i++) {
index dc5a66bfabaee55ddd871430004ac8bc755f9948..be12a4ee8d68e1b1981b60780144ddd0b1134b6d 100644 (file)
@@ -5,7 +5,7 @@
 //  This fragment is called by moodle_needs_upgrading() and /admin/index.php
 ////////////////////////////////////////////////////////////////////////////////
 
-$module->version  = 2008112101;   // The (date) version of this module
+$module->version  = 2009010700;   // The (date) version of this module
 $module->requires = 2008072401;   // Requires this Moodle version
 $module->cron     = 0;            // How often should cron check this module (seconds)?
 
index 431ff370b5a94a91585fa52d02f1b313edb59968..4452d9d35a055d5a1a501622f9feca4d055d4c37 100644 (file)
@@ -4438,6 +4438,14 @@ table.quizreviewsummary td.cell {
   cursor: pointer;
   white-space: normal;
 }
+#quiznavigation #user-picture {
+    margin: 0.5em 0;
+}
+#quiznavigation #user-picture img {
+    width: auto;
+    height: auto;
+    float: left;
+}
 #quiznavigation .othernav {
   clear: both;
 }