Merge branch 'w27_MDL-34121_m23_killbackupmess' of git://github.com/skodak/moodle...
authorEloy Lafuente (stronk7) <stronk7@moodle.org>
Mon, 2 Jul 2012 16:16:54 +0000 (18:16 +0200)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Mon, 2 Jul 2012 16:16:54 +0000 (18:16 +0200)
118 files changed:
admin/tool/customlang/db/upgrade.php
auth/manual/db/upgrade.php
auth/mnet/db/upgrade.php
blocks/community/db/upgrade.php
blocks/completionstatus/block_completionstatus.php
blocks/feedback/block_feedback.php
blocks/html/db/upgrade.php
blocks/navigation/db/upgrade.php
blocks/settings/db/upgrade.php
calendar/delete.php
cohort/edit_form.php
course/completion.php
course/completion_form.php
course/externallib.php
course/tests/externallib_test.php [new file with mode: 0644]
enrol/authorize/db/upgrade.php
enrol/database/db/upgrade.php
enrol/flatfile/db/upgrade.php
enrol/guest/db/upgrade.php
enrol/imsenterprise/db/upgrade.php
enrol/mnet/db/upgrade.php
enrol/paypal/db/upgrade.php
enrol/self/lib.php
files/renderer.php
filter/mediaplugin/db/upgrade.php
filter/tex/db/upgrade.php
grade/grading/form/guide/js/guide.js
grade/grading/form/rubric/db/upgrade.php
lang/en/completion.php
lib/accesslib.php
lib/adminlib.php
lib/completion/completion_criteria_grade.php
lib/cronlib.php
lib/db/upgrade.php
lib/dml/tests/dml_test.php
lib/filelib.php
lib/form/filemanager.js
lib/navigationlib.php
lib/pluginlib.php
lib/tests/accesslib_test.php
message/output/email/db/upgrade.php
message/output/jabber/db/upgrade.php
message/output/popup/db/upgrade.php
mod/assign/db/upgrade.php
mod/assign/feedback/comments/db/upgrade.php
mod/assign/feedback/file/db/upgrade.php
mod/assign/submission/comments/db/upgrade.php
mod/assign/submission/file/db/upgrade.php
mod/assign/submission/onlinetext/db/upgrade.php
mod/assignment/db/upgrade.php
mod/assignment/type/upload/assignment.class.php
mod/assignment/version.php
mod/book/db/upgrade.php
mod/chat/db/upgrade.php
mod/choice/db/upgrade.php
mod/data/db/upgrade.php
mod/feedback/db/upgrade.php
mod/feedback/item/multichoice/lib.php
mod/folder/db/upgrade.php
mod/forum/db/upgrade.php
mod/forum/lib.php
mod/forum/post.php
mod/forum/post_form.php
mod/forum/search.php
mod/glossary/db/upgrade.php
mod/glossary/print.php
mod/imscp/db/upgrade.php
mod/label/db/upgrade.php
mod/lesson/db/upgrade.php
mod/lti/db/upgrade.php
mod/page/db/upgrade.php
mod/quiz/accessmanager.php
mod/quiz/cronlib.php
mod/quiz/db/install.xml
mod/quiz/db/upgrade.php
mod/quiz/report/attemptsreport_options.php
mod/quiz/report/overview/db/upgrade.php
mod/quiz/report/reportlib.php
mod/quiz/report/statistics/db/upgrade.php
mod/resource/db/upgrade.php
mod/scorm/datamodels/aicclib.php
mod/scorm/db/upgrade.php
mod/scorm/lib.php
mod/scorm/locallib.php
mod/scorm/styles.css
mod/survey/db/upgrade.php
mod/survey/view.php
mod/url/db/upgrade.php
mod/wiki/db/upgrade.php
mod/wiki/lang/en/wiki.php
mod/wiki/parser/markups/wikimarkup.php
mod/workshop/db/upgrade.php
mod/workshop/form/accumulative/db/upgrade.php
mod/workshop/form/comments/db/upgrade.php
mod/workshop/form/numerrors/db/upgrade.php
mod/workshop/form/rubric/db/upgrade.php
portfolio/googledocs/db/upgrade.php
portfolio/picasa/db/upgrade.php
question/format.php
question/type/calculated/db/upgrade.php
question/type/essay/db/upgrade.php
question/type/match/db/upgrade.php
question/type/multianswer/db/upgrade.php
question/type/multichoice/db/upgrade.php
question/type/numerical/db/upgrade.php
repository/googledocs/db/upgrade.php
repository/picasa/db/upgrade.php
theme/base/style/filemanager.css
theme/formal_white/db/upgrade.php
theme/splash/config.php
theme/splash/javascript/colourswitcher.js [new file with mode: 0644]
theme/splash/layout/general.php
theme/splash/layout/report.php
theme/splash/lib.php
theme/splash/style/pagelayout.css
user/edit.php
version.php
webservice/tests/helpers.php [new file with mode: 0644]

index efe645e..07c7e3b 100644 (file)
@@ -30,5 +30,9 @@ function xmldb_tool_customlang_upgrade($oldversion) {
     $dbman = $DB->get_manager();
 
 
+    // Moodle v2.3.0 release upgrade line
+    // Put any upgrade step following this
+
+
     return true;
 }
index 82aab0a..46fd720 100644 (file)
@@ -33,5 +33,9 @@ function xmldb_auth_manual_upgrade($oldversion) {
     $dbman = $DB->get_manager();
 
 
+    // Moodle v2.3.0 release upgrade line
+    // Put any upgrade step following this
+
+
     return true;
 }
index fa5d157..d10cda5 100644 (file)
@@ -34,5 +34,9 @@ function xmldb_auth_mnet_upgrade($oldversion) {
     $dbman = $DB->get_manager();
 
 
+    // Moodle v2.3.0 release upgrade line
+    // Put any upgrade step following this
+
+
     return true;
 }
index e3eb9a4..53e2222 100644 (file)
@@ -46,5 +46,9 @@
 function xmldb_block_community_upgrade($oldversion) {
     global $CFG, $DB;
 
+    // Moodle v2.3.0 release upgrade line
+    // Put any upgrade step following this
+
+
     return true;
 }
index 07a7b47..0daec7c 100644 (file)
@@ -171,7 +171,7 @@ class block_completionstatus extends block_base {
             $a = new stdClass();
             $a->first = $prerequisites_complete;
             $a->second = count($prerequisites);
-            $shtml .= get_string('firstofsecond', 'block_completionstatus', $a);
+            $phtml .= get_string('firstofsecond', 'block_completionstatus', $a);
             $phtml .= '</td></tr>';
 
             $shtml = $phtml . $shtml;
index 75a5126..5d41a50 100644 (file)
@@ -4,7 +4,7 @@ if (is_file($CFG->dirroot.'/mod/feedback/lib.php')) {
     define('FEEDBACK_BLOCK_LIB_IS_OK', true);
 }
 
-class block_feedback extends block_base {
+class block_feedback extends block_list {
 
     function init() {
         $this->title = get_string('feedback', 'block_feedback');
@@ -21,10 +21,13 @@ class block_feedback extends block_base {
             return $this->content;
         }
 
+        $this->content = new stdClass;
+        $this->content->items = array();
+        $this->content->icons = array();
+        $this->content->footer = '';
+
         if (!defined('FEEDBACK_BLOCK_LIB_IS_OK')) {
-            $this->content = new stdClass;
-            $this->content->text = get_string('missing_feedback_module', 'block_feedback');
-            $this->content->footer = '';
+            $this->content->items = array(get_string('missing_feedback_module', 'block_feedback'));
             return $this->content;
         }
 
@@ -33,9 +36,7 @@ class block_feedback extends block_base {
             $courseid = SITEID;
         }
 
-        $this->content = new stdClass;
-        $this->content->text = '';
-        $this->content->footer = '';
+        $icon = '<img src="'.$OUTPUT->pix_url('icon', 'feedback') . '" class="icon" alt="" />';
 
 
         if (empty($this->instance->pageid)) {
@@ -47,8 +48,7 @@ class block_feedback extends block_base {
             foreach ($feedbacks as $feedback) {
                 $url = new moodle_url($baseurl);
                 $url->params(array('id'=>$feedback->cmid, 'courseid'=>$courseid));
-                $icon = '<img src="'.$OUTPUT->pix_url('icon', 'feedback') . '" class="icon" alt="" />&nbsp;';
-                $this->content->text = ' <a href="'.$url->out().'">'.$icon.$feedback->name.'</a>';
+                $this->content->items[] = '<a href="'.$url->out().'">'.$icon.$feedback->name.'</a>';
             }
         }
 
index 8eec672..54bb53d 100644 (file)
@@ -32,5 +32,9 @@
 function xmldb_block_html_upgrade($oldversion) {
     global $CFG, $DB;
 
+    // Moodle v2.3.0 release upgrade line
+    // Put any upgrade step following this
+
+
     return true;
 }
index 4ad9818..32c5d8d 100644 (file)
@@ -58,5 +58,9 @@ function xmldb_block_navigation_upgrade($oldversion, $block) {
     // Moodle v2.2.0 release upgrade line
     // Put any upgrade step following this
 
+    // Moodle v2.3.0 release upgrade line
+    // Put any upgrade step following this
+
+
     return true;
 }
\ No newline at end of file
index 65c265c..feb241a 100644 (file)
@@ -58,5 +58,9 @@ function xmldb_block_settings_upgrade($oldversion, $block) {
     // Moodle v2.2.0 release upgrade line
     // Put any upgrade step following this
 
+    // Moodle v2.3.0 release upgrade line
+    // Put any upgrade step following this
+
+
     return true;
 }
\ No newline at end of file
index 24edd48..e79e945 100644 (file)
@@ -108,7 +108,7 @@ $repeatspan = '';
 if (!empty($event->eventrepeats) && $event->eventrepeats > 0) {
     $url = new moodle_url(CALENDAR_URL.'delete.php', array('id'=>$event->repeatid, 'confirm'=>true, 'repeats'=>true));
     $buttons .= $OUTPUT->single_button($url, get_string('deleteall'));
-    $repeatspan = '<br /><br /><span>'.get_string('youcandeleteallrepeats', 'calendar').'</span>';
+    $repeatspan = '<br /><br /><span>'.get_string('youcandeleteallrepeats', 'calendar', $event->eventrepeats).'</span>';
 }
 
 // And add the cancel button
index 249212c..d449980 100644 (file)
@@ -49,7 +49,7 @@ class cohort_edit_form extends moodleform {
         $mform->addElement('select', 'contextid', get_string('context', 'role'), $options);
 
         $mform->addElement('text', 'idnumber', get_string('idnumber', 'cohort'), 'maxlength="254" size="50"');
-        $mform->setType('name', PARAM_RAW); // idnumbers are plain text, must not be changed
+        $mform->setType('idnumber', PARAM_RAW); // idnumbers are plain text, must not be changed
 
         $mform->addElement('editor', 'description_editor', get_string('description', 'cohort'), null, $editoroptions);
         $mform->setType('description_editor', PARAM_RAW);
index 3d4e17b..a25c2af 100644 (file)
@@ -141,16 +141,6 @@ if ($form->is_cancelled()){
     $aggregation->setMethod($data->role_aggregation);
     $aggregation->save();
 
-    // Update course total passing grade
-    if (!empty($data->criteria_grade)) {
-        if ($grade_item = grade_category::fetch_course_category($course->id)->grade_item) {
-            $grade_item->gradepass = $data->criteria_grade_value;
-            if (method_exists($grade_item, 'update')) {
-                $grade_item->update('course/completion.php');
-            }
-        }
-    }
-
     add_to_log($course->id, 'course', 'completion updated', 'completion.php?id='.$course->id);
 
     $url = new moodle_url('/course/view.php', array('id' => $course->id));
index 0a5b543..951776a 100644 (file)
@@ -179,10 +179,13 @@ class course_completion_form extends moodleform {
         $criteria->config_form_display($mform);
 
         // Completion on course grade
-        $mform->addElement('header', 'grade', get_string('grade'));
+        $mform->addElement('header', 'grade', get_string('coursegrade', 'completion'));
 
         // Grade enable and passing grade
         $course_grade = $DB->get_field('grade_items', 'gradepass', array('courseid' => $course->id, 'itemtype' => 'course'));
+        if (!$course_grade) {
+            $course_grade = '0.00000';
+        }
         $criteria = new completion_criteria_grade($params);
         $criteria->config_form_display($mform, $course_grade);
 
index e14ce90..41c5ab4 100644 (file)
@@ -904,9 +904,10 @@ class core_course_external extends external_api {
                                          '"parent" (int) the parent category id,'.
                                          '"idnumber" (string) category idnumber'.
                                          ' - user must have \'moodle/category:manage\' to search on idnumber,'.
-                                         '"visible" (int) whether the category is visible or not'.
+                                         '"visible" (int) whether the returned categories must be visible or hidden. If the key is not passed,
+                                             then the function return all categories that the user can see.'.
                                          ' - user must have \'moodle/category:manage\' or \'moodle/category:viewhiddencategories\' to search on visible,'.
-                                         '"theme" (string) category theme'.
+                                         '"theme" (string) only return the categories having this theme'.
                                          ' - user must have \'moodle/category:manage\' to search on theme'),
                             'value' => new external_value(PARAM_RAW, 'the value to match')
                         )
@@ -1017,10 +1018,22 @@ class core_course_external extends external_api {
                 if ($categories and !empty($params['addsubcategories'])) {
                     $newcategories = array();
 
+                    // Check if we required visible/theme checks.
+                    $additionalselect = '';
+                    $additionalparams = array();
+                    if (isset($conditions['visible'])) {
+                        $additionalselect .= ' AND visible = :visible';
+                        $additionalparams['visible'] = $conditions['visible'];
+                    }
+                    if (isset($conditions['theme'])) {
+                        $additionalselect .= ' AND theme= :theme';
+                        $additionalparams['theme'] = $conditions['theme'];
+                    }
+
                     foreach ($categories as $category) {
-                        $sqllike = $DB->sql_like('path', ':path');
-                        $sqlparams = array('path' => $category->path.'/%'); // It will NOT include the specified category.
-                        $subcategories = $DB->get_records_select('course_categories', $sqllike, $sqlparams);
+                        $sqlselect = $DB->sql_like('path', ':path') . $additionalselect;
+                        $sqlparams = array('path' => $category->path.'/%') + $additionalparams; // It will NOT include the specified category.
+                        $subcategories = $DB->get_records_select('course_categories', $sqlselect, $sqlparams);
                         $newcategories = $newcategories + $subcategories;   // Both arrays have integer as keys.
                     }
                     $categories = $categories + $newcategories;
diff --git a/course/tests/externallib_test.php b/course/tests/externallib_test.php
new file mode 100644 (file)
index 0000000..ac3c4d9
--- /dev/null
@@ -0,0 +1,570 @@
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * External course functions unit tests
+ *
+ * @package    core_course
+ * @category   external
+ * @copyright  2012 Jerome Mouneyrac
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+global $CFG;
+
+require_once($CFG->dirroot . '/webservice/tests/helpers.php');
+
+/**
+ * External course functions unit tests
+ *
+ * @package    core_course
+ * @category   external
+ * @copyright  2012 Jerome Mouneyrac
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class core_course_external_testcase extends externallib_advanced_testcase {
+
+    /**
+     * Tests set up
+     */
+    protected function setUp() {
+        global $CFG;
+        require_once($CFG->dirroot . '/course/externallib.php');
+    }
+
+    /**
+     * Test create_categories
+     */
+    public function test_create_categories() {
+
+        global $DB;
+
+        $this->resetAfterTest(true);
+
+        // Set the required capabilities by the external function
+        $contextid = context_system::instance()->id;
+        $roleid = $this->assignUserCapability('moodle/category:manage', $contextid);
+
+        // Create base categories.
+        $category1 = new stdClass();
+        $category1->name = 'Root Test Category 1';
+        $category2 = new stdClass();
+        $category2->name = 'Root Test Category 2';
+        $category2->idnumber = 'rootcattest2';
+        $category2->desc = 'Description for root test category 1';
+        $category2->theme = 'base';
+        $categories = array(
+            array('name' => $category1->name, 'parent' => 0),
+            array('name' => $category2->name, 'parent' => 0, 'idnumber' => $category2->idnumber,
+                'description' => $category2->desc, 'theme' => $category2->theme)
+        );
+
+        $createdcats = core_course_external::create_categories($categories);
+
+        // Initially confirm that base data was inserted correctly.
+        $this->assertEquals($category1->name, $createdcats[0]['name']);
+        $this->assertEquals($category2->name, $createdcats[1]['name']);
+
+        // Save the ids.
+        $category1->id = $createdcats[0]['id'];
+        $category2->id = $createdcats[1]['id'];
+
+        // Create on sub category.
+        $category3 = new stdClass();
+        $category3->name = 'Sub Root Test Category 3';
+        $subcategories = array(
+            array('name' => $category3->name, 'parent' => $category1->id)
+        );
+
+        $createdsubcats = core_course_external::create_categories($subcategories);
+
+        // Confirm that sub categories were inserted correctly.
+        $this->assertEquals($category3->name, $createdsubcats[0]['name']);
+
+        // Save the ids.
+        $category3->id = $createdsubcats[0]['id'];
+
+        // Calling the ws function should provide a new sortorder to give category1,
+        // category2, category3. New course categories are ordered by id not name.
+        $category1 = $DB->get_record('course_categories', array('id' => $category1->id));
+        $category2 = $DB->get_record('course_categories', array('id' => $category2->id));
+        $category3 = $DB->get_record('course_categories', array('id' => $category3->id));
+
+        $this->assertGreaterThanOrEqual($category1->sortorder, $category3->sortorder);
+        $this->assertGreaterThanOrEqual($category2->sortorder, $category3->sortorder);
+
+        // Call without required capability
+        $this->unassignUserCapability('moodle/category:manage', $contextid, $roleid);
+        $this->setExpectedException('required_capability_exception');
+        $createdsubcats = core_course_external::create_categories($subcategories);
+
+    }
+
+    /**
+     * Test delete categories
+     */
+    public function test_delete_categories() {
+        global $DB;
+
+        $this->resetAfterTest(true);
+
+        // Set the required capabilities by the external function
+        $contextid = context_system::instance()->id;
+        $roleid = $this->assignUserCapability('moodle/category:manage', $contextid);
+
+        $category1  = self::getDataGenerator()->create_category();
+        $category2  = self::getDataGenerator()->create_category(
+                array('parent' => $category1->id));
+        $category3  = self::getDataGenerator()->create_category();
+        $category4  = self::getDataGenerator()->create_category(
+                array('parent' => $category3->id));
+        $category5  = self::getDataGenerator()->create_category(
+                array('parent' => $category4->id));
+
+        //delete category 1 and 2 + delete category 4, category 5 moved under category 3
+        core_course_external::delete_categories(array(
+            array('id' => $category1->id, 'recursive' => 1),
+            array('id' => $category4->id)
+        ));
+
+        //check $category 1 and 2 are deleted
+        $notdeletedcount = $DB->count_records_select('course_categories',
+            'id IN ( ' . $category1->id . ',' . $category2->id . ',' . $category4->id . ')');
+        $this->assertEquals(0, $notdeletedcount);
+
+        //check that $category5 as $category3 for parent
+        $dbcategory5 = $DB->get_record('course_categories', array('id' => $category5->id));
+        $this->assertEquals($dbcategory5->path, $category3->path . '/' . $category5->id);
+
+         // Call without required capability
+        $this->unassignUserCapability('moodle/category:manage', $contextid, $roleid);
+        $this->setExpectedException('required_capability_exception');
+        $createdsubcats = core_course_external::delete_categories(
+                array(array('id' => $category3->id)));
+    }
+
+    /**
+     * Test get categories
+     */
+    public function test_get_categories() {
+        global $DB;
+
+        $this->resetAfterTest(true);
+        $category1data['idnumber'] = 'idnumbercat1';
+        $category1data['name'] = 'Category 1 for PHPunit test';
+        $category1data['description'] = 'Category 1 description';
+        $category1data['descriptionformat'] = FORMAT_MOODLE;
+        $category1  = self::getDataGenerator()->create_category($category1data);
+        $category2  = self::getDataGenerator()->create_category(
+                array('parent' => $category1->id));
+        $category6  = self::getDataGenerator()->create_category(
+                array('parent' => $category1->id, 'visible' => 0));
+        $category3  = self::getDataGenerator()->create_category();
+        $category4  = self::getDataGenerator()->create_category(
+                array('parent' => $category3->id));
+        $category5  = self::getDataGenerator()->create_category(
+                array('parent' => $category4->id));
+
+        // Set the required capabilities by the external function.
+        $context = context_system::instance();
+        $roleid = $this->assignUserCapability('moodle/category:manage', $context->id);
+
+        // Retrieve category1 + sub-categories except not visible ones
+        $categories = core_course_external::get_categories(array(
+            array('key' => 'id', 'value' => $category1->id),
+            array('key' => 'visible', 'value' => 1)), 1);
+
+        // Check we retrieve the good total number of categories.
+        $this->assertEquals(2, count($categories));
+
+        // Check the return values
+        $this->assertEquals($categories[0]['id'], $category1->id);
+        $this->assertEquals($categories[0]['idnumber'], $category1->idnumber);
+        $this->assertEquals($categories[0]['name'], $category1->name);
+        $this->assertEquals($categories[0]['description'], $category1->description);
+        $this->assertEquals($categories[0]['descriptionformat'], FORMAT_HTML);
+
+        // Check different params.
+        $categories = core_course_external::get_categories(array(
+            array('key' => 'id', 'value' => $category1->id),
+            array('key' => 'idnumber', 'value' => $category1->idnumber),
+            array('key' => 'visible', 'value' => 1)), 0);
+        $this->assertEquals(1, count($categories));
+
+        // Retrieve categories from parent.
+        $categories = core_course_external::get_categories(array(
+            array('key' => 'parent', 'value' => $category3->id)), 1);
+        $this->assertEquals(2, count($categories));
+
+        // Retrieve all categories.
+        $categories = core_course_external::get_categories();
+        $this->assertEquals($DB->count_records('course_categories'), count($categories));
+
+        // Call without required capability (it will fail cause of the search on idnumber).
+        $this->unassignUserCapability('moodle/category:manage', $context->id, $roleid);
+        $this->setExpectedException('moodle_exception');
+        $categories = core_course_external::get_categories(array(
+            array('key' => 'id', 'value' => $category1->id),
+            array('key' => 'idnumber', 'value' => $category1->idnumber),
+            array('key' => 'visible', 'value' => 1)), 0);
+    }
+
+    /**
+     * Test update_categories
+     */
+    public function test_update_categories() {
+        global $DB;
+
+        $this->resetAfterTest(true);
+
+        // Set the required capabilities by the external function
+        $contextid = context_system::instance()->id;
+        $roleid = $this->assignUserCapability('moodle/category:manage', $contextid);
+
+        // Create base categories.
+        $category1data['idnumber'] = 'idnumbercat1';
+        $category1data['name'] = 'Category 1 for PHPunit test';
+        $category1data['description'] = 'Category 1 description';
+        $category1data['descriptionformat'] = FORMAT_MOODLE;
+        $category1  = self::getDataGenerator()->create_category($category1data);
+        $category2  = self::getDataGenerator()->create_category(
+                array('parent' => $category1->id));
+        $category3  = self::getDataGenerator()->create_category();
+        $category4  = self::getDataGenerator()->create_category(
+                array('parent' => $category3->id));
+        $category5  = self::getDataGenerator()->create_category(
+                array('parent' => $category4->id));
+
+        // We update all category1 attribut.
+        // Then we move cat4 and cat5 parent: cat3 => cat1
+        $categories = array(
+            array('id' => $category1->id,
+                'name' => $category1->name . '_updated',
+                'idnumber' => $category1->idnumber . '_updated',
+                'description' => $category1->description . '_updated',
+                'descriptionformat' => FORMAT_HTML,
+                'theme' => $category1->theme),
+            array('id' => $category4->id, 'parent' => $category1->id));
+
+        core_course_external::update_categories($categories);
+
+        // Check the values were updated.
+        $dbcategories = $DB->get_records_select('course_categories',
+                'id IN (' . $category1->id . ',' . $category2->id . ',' . $category2->id
+                . ',' . $category3->id . ',' . $category4->id . ',' . $category5->id .')');
+        $this->assertEquals($category1->name . '_updated',
+                $dbcategories[$category1->id]->name);
+        $this->assertEquals($category1->idnumber . '_updated',
+                $dbcategories[$category1->id]->idnumber);
+        $this->assertEquals($category1->description . '_updated',
+                $dbcategories[$category1->id]->description);
+        $this->assertEquals(FORMAT_HTML, $dbcategories[$category1->id]->descriptionformat);
+
+        // Check that category4 and category5 have been properly moved.
+        $this->assertEquals('/' . $category1->id . '/' . $category4->id,
+                $dbcategories[$category4->id]->path);
+        $this->assertEquals('/' . $category1->id . '/' . $category4->id . '/' . $category5->id,
+                $dbcategories[$category5->id]->path);
+
+        // Call without required capability.
+        $this->unassignUserCapability('moodle/category:manage', $contextid, $roleid);
+        $this->setExpectedException('required_capability_exception');
+        core_course_external::update_categories($categories);
+    }
+
+    /**
+     * Test create_courses
+     */
+    public function test_create_courses() {
+        global $DB;
+
+        $this->resetAfterTest(true);
+
+        // Set the required capabilities by the external function
+        $contextid = context_system::instance()->id;
+        $roleid = $this->assignUserCapability('moodle/course:create', $contextid);
+        $this->assignUserCapability('moodle/course:visibility', $contextid, $roleid);
+
+        $category  = self::getDataGenerator()->create_category();
+
+        // Create base categories.
+        $course1['fullname'] = 'Test course 1';
+        $course1['shortname'] = 'Testcourse1';
+        $course1['categoryid'] = $category->id;
+        $course2['fullname'] = 'Test course 2';
+        $course2['shortname'] = 'Testcourse2';
+        $course2['categoryid'] = $category->id;
+        $course2['idnumber'] = 'testcourse2idnumber';
+        $course2['summary'] = 'Description for course 2';
+        $course2['summaryformat'] = FORMAT_MOODLE;
+        $course2['format'] = 'weeks';
+        $course2['showgrades'] = 1;
+        $course2['newsitems'] = 3;
+        $course2['startdate'] = 32882306400; // 01/01/3012
+        $course2['numsections'] = 4;
+        $course2['maxbytes'] = 100000;
+        $course2['showreports'] = 1;
+        $course2['visible'] = 0;
+        $course2['hiddensections'] = 0;
+        $course2['groupmode'] = 0;
+        $course2['groupmodeforce'] = 0;
+        $course2['defaultgroupingid'] = 0;
+        $course2['enablecompletion'] = 1;
+        $course2['completionstartonenrol'] = 1;
+        $course2['completionnotify'] = 1;
+        $course2['lang'] = 'en';
+        $course2['forcetheme'] = 'base';
+        $courses = array($course1, $course2);
+
+        $createdcourses = core_course_external::create_courses($courses);
+
+        // Check that right number of courses were created.
+        $this->assertEquals(2, count($createdcourses));
+
+        // Check that the courses were correctly created.
+        foreach ($createdcourses as $createdcourse) {
+            $dbcourse = $DB->get_record('course', array('id' => $createdcourse['id']));
+
+            if ($createdcourse['shortname'] == $course2['shortname']) {
+                $this->assertEquals($dbcourse->fullname, $course2['fullname']);
+                $this->assertEquals($dbcourse->shortname, $course2['shortname']);
+                $this->assertEquals($dbcourse->category, $course2['categoryid']);
+                $this->assertEquals($dbcourse->idnumber, $course2['idnumber']);
+                $this->assertEquals($dbcourse->summary, $course2['summary']);
+                $this->assertEquals($dbcourse->summaryformat, $course2['summaryformat']);
+                $this->assertEquals($dbcourse->format, $course2['format']);
+                $this->assertEquals($dbcourse->showgrades, $course2['showgrades']);
+                $this->assertEquals($dbcourse->newsitems, $course2['newsitems']);
+                $this->assertEquals($dbcourse->startdate, $course2['startdate']);
+                $this->assertEquals($dbcourse->numsections, $course2['numsections']);
+                $this->assertEquals($dbcourse->maxbytes, $course2['maxbytes']);
+                $this->assertEquals($dbcourse->showreports, $course2['showreports']);
+                $this->assertEquals($dbcourse->visible, $course2['visible']);
+                $this->assertEquals($dbcourse->hiddensections, $course2['hiddensections']);
+                $this->assertEquals($dbcourse->groupmode, $course2['groupmode']);
+                $this->assertEquals($dbcourse->groupmodeforce, $course2['groupmodeforce']);
+                $this->assertEquals($dbcourse->defaultgroupingid, $course2['defaultgroupingid']);
+                $this->assertEquals($dbcourse->completionnotify, $course2['completionnotify']);
+                $this->assertEquals($dbcourse->lang, $course2['lang']);
+
+                if (!empty($CFG->allowcoursethemes)) {
+                    $this->assertEquals($dbcourse->theme, $course2['forcetheme']);
+                }
+
+                if (completion_info::is_enabled_for_site()) {
+                    $this->assertEquals($dbcourse->enablecompletion, $course2['enabledcompletion']);
+                    $this->assertEquals($dbcourse->completionstartonenrol, $course2['completionstartonenrol']);
+                } else {
+                    $this->assertEquals($dbcourse->enablecompletion, 0);
+                    $this->assertEquals($dbcourse->completionstartonenrol, 0);
+                }
+
+            } else if ($createdcourse['shortname'] == $course1['shortname']) {
+                $courseconfig = get_config('moodlecourse');
+                $this->assertEquals($dbcourse->fullname, $course1['fullname']);
+                $this->assertEquals($dbcourse->shortname, $course1['shortname']);
+                $this->assertEquals($dbcourse->category, $course1['categoryid']);
+                $this->assertEquals($dbcourse->summaryformat, FORMAT_HTML);
+                $this->assertEquals($dbcourse->format, $courseconfig->format);
+                $this->assertEquals($dbcourse->showgrades, $courseconfig->showgrades);
+                $this->assertEquals($dbcourse->newsitems, $courseconfig->newsitems);
+                $this->assertEquals($dbcourse->numsections, $courseconfig->numsections);
+                $this->assertEquals($dbcourse->maxbytes, $courseconfig->maxbytes);
+                $this->assertEquals($dbcourse->showreports, $courseconfig->showreports);
+                $this->assertEquals($dbcourse->hiddensections, $courseconfig->hiddensections);
+                $this->assertEquals($dbcourse->groupmode, $courseconfig->groupmode);
+                $this->assertEquals($dbcourse->groupmodeforce, $courseconfig->groupmodeforce);
+                $this->assertEquals($dbcourse->defaultgroupingid, 0);
+            } else {
+                throw moodle_exception('Unexpected shortname');
+            }
+        }
+
+        // Call without required capability
+        $this->unassignUserCapability('moodle/course:create', $contextid, $roleid);
+        $this->setExpectedException('required_capability_exception');
+        $createdsubcats = core_course_external::create_courses($courses);
+    }
+
+    /**
+     * Test delete_courses
+     */
+    public function test_delete_courses() {
+        global $DB, $USER;
+
+        $this->resetAfterTest(true);
+
+        // Admin can delete a course.
+        $this->setAdminUser();
+        // Validate_context() will fail as the email is not set by $this->setAdminUser().
+        $USER->email = 'emailtopass@contextvalidation.me';
+
+        $course1  = self::getDataGenerator()->create_course();
+        $course2  = self::getDataGenerator()->create_course();
+        $course3  = self::getDataGenerator()->create_course();
+
+        // Delete courses.
+        core_course_external::delete_courses(array($course1->id, $course2->id));
+
+        // Check $course 1 and 2 are deleted.
+        $notdeletedcount = $DB->count_records_select('course',
+            'id IN ( ' . $course1->id . ',' . $course2->id . ')');
+        $this->assertEquals(0, $notdeletedcount);
+
+         // Fail when the user is not allow to access the course (enrolled) or is not admin.
+        $this->setGuestUser();
+        $this->setExpectedException('require_login_exception');
+        $createdsubcats = core_course_external::delete_courses(array($course3->id));
+    }
+
+    /**
+     * Test get_courses
+     */
+    public function test_get_courses () {
+        global $DB;
+
+        $this->resetAfterTest(true);
+
+        $coursedata['idnumber'] = 'idnumbercourse1';
+        $coursedata['fullname'] = 'Course 1 for PHPunit test';
+        $coursedata['summary'] = 'Course 1 description';
+        $coursedata['summaryformat'] = FORMAT_MOODLE;
+        $course1  = self::getDataGenerator()->create_course($coursedata);
+        $course2  = self::getDataGenerator()->create_course();
+        $course3  = self::getDataGenerator()->create_course();
+
+        // Set the required capabilities by the external function.
+        $context = context_system::instance();
+        $roleid = $this->assignUserCapability('moodle/course:view', $context->id);
+        $this->assignUserCapability('moodle/course:update',
+                context_course::instance($course1->id)->id, $roleid);
+        $this->assignUserCapability('moodle/course:update',
+                context_course::instance($course2->id)->id, $roleid);
+        $this->assignUserCapability('moodle/course:update',
+                context_course::instance($course3->id)->id, $roleid);
+
+        $courses = core_course_external::get_courses(array('ids' =>
+            array($course1->id, $course2->id)));
+
+        // Check we retrieve the good total number of categories.
+        $this->assertEquals(2, count($courses));
+
+        // Check the return values for course 1
+        $dbcourse = $DB->get_record('course', array('id' => $course1->id));
+        $this->assertEquals($courses[0]['id'], $dbcourse->id);
+        $this->assertEquals($courses[0]['idnumber'], $coursedata['idnumber']);
+        $this->assertEquals($courses[0]['fullname'], $coursedata['fullname']);
+        $this->assertEquals($courses[0]['summary'], $coursedata['summary']);
+        $this->assertEquals($courses[0]['summaryformat'], FORMAT_HTML);
+        $this->assertEquals($courses[0]['shortname'], $dbcourse->shortname);
+        $this->assertEquals($courses[0]['categoryid'], $dbcourse->category);
+        $this->assertEquals($courses[0]['format'], $dbcourse->format);
+        $this->assertEquals($courses[0]['showgrades'], $dbcourse->showgrades);
+        $this->assertEquals($courses[0]['newsitems'], $dbcourse->newsitems);
+        $this->assertEquals($courses[0]['startdate'], $dbcourse->startdate);
+        $this->assertEquals($courses[0]['numsections'], $dbcourse->numsections);
+        $this->assertEquals($courses[0]['maxbytes'], $dbcourse->maxbytes);
+        $this->assertEquals($courses[0]['showreports'], $dbcourse->showreports);
+        $this->assertEquals($courses[0]['visible'], $dbcourse->visible);
+        $this->assertEquals($courses[0]['hiddensections'], $dbcourse->hiddensections);
+        $this->assertEquals($courses[0]['groupmode'], $dbcourse->groupmode);
+        $this->assertEquals($courses[0]['groupmodeforce'], $dbcourse->groupmodeforce);
+        $this->assertEquals($courses[0]['defaultgroupingid'], $dbcourse->defaultgroupingid);
+        $this->assertEquals($courses[0]['completionnotify'], $dbcourse->completionnotify);
+        $this->assertEquals($courses[0]['lang'], $dbcourse->lang);
+        $this->assertEquals($courses[0]['forcetheme'], $dbcourse->theme);
+        $this->assertEquals($courses[0]['completionstartonenrol'], $dbcourse->completionstartonenrol);
+        $this->assertEquals($courses[0]['enablecompletion'], $dbcourse->enablecompletion);
+        $this->assertEquals($courses[0]['completionstartonenrol'], $dbcourse->completionstartonenrol);
+
+        // Get all courses in the DB
+        $courses = core_course_external::get_courses(array());
+        $this->assertEquals($DB->count_records('course'), count($courses));
+    }
+
+    /**
+     * Test get_course_contents
+     */
+    public function test_get_course_contents() {
+        $this->resetAfterTest(true);
+
+        $course  = self::getDataGenerator()->create_course();
+        $forum = $this->getDataGenerator()->create_module('forum', array('course'=>$course->id));
+        $forumcm = get_coursemodule_from_id('forum', $forum->cmid);
+        $forumcontext = context_module::instance($forum->cmid);
+        $data = $this->getDataGenerator()->create_module('data', array('assessed'=>1, 'scale'=>100, 'course'=>$course->id));
+        $datacontext = context_module::instance($data->cmid);
+        $datacm = get_coursemodule_from_instance('page', $data->id);
+        $page = $this->getDataGenerator()->create_module('page', array('course'=>$course->id));
+        $pagecontext = context_module::instance($page->cmid);
+        $pagecm = get_coursemodule_from_instance('page', $page->id);
+
+        // Set the required capabilities by the external function.
+        $context = context_course::instance($course->id);
+        $roleid = $this->assignUserCapability('moodle/course:view', $context->id);
+        $this->assignUserCapability('moodle/course:update', $context->id, $roleid);
+
+        $courses = core_course_external::get_course_contents($course->id, array());
+
+        // Check that the course has the 3 created modules
+        $this->assertEquals(3, count($courses[0]['modules']));
+    }
+
+    /**
+     * Test duplicate_course
+     */
+    public function test_duplicate_course() {
+        $this->resetAfterTest(true);
+
+        // Create one course with three modules.
+        $course  = self::getDataGenerator()->create_course();
+        $forum = $this->getDataGenerator()->create_module('forum', array('course'=>$course->id));
+        $forumcm = get_coursemodule_from_id('forum', $forum->cmid);
+        $forumcontext = context_module::instance($forum->cmid);
+        $data = $this->getDataGenerator()->create_module('data', array('assessed'=>1, 'scale'=>100, 'course'=>$course->id));
+        $datacontext = context_module::instance($data->cmid);
+        $datacm = get_coursemodule_from_instance('page', $data->id);
+        $page = $this->getDataGenerator()->create_module('page', array('course'=>$course->id));
+        $pagecontext = context_module::instance($page->cmid);
+        $pagecm = get_coursemodule_from_instance('page', $page->id);
+
+        // Set the required capabilities by the external function.
+        $coursecontext = context_course::instance($course->id);
+        $categorycontext = context_coursecat::instance($course->category);
+        $roleid = $this->assignUserCapability('moodle/course:create', $categorycontext->id);
+        $this->assignUserCapability('moodle/course:view', $categorycontext->id, $roleid);
+        $this->assignUserCapability('moodle/restore:restorecourse', $categorycontext->id, $roleid);
+        $this->assignUserCapability('moodle/backup:backupcourse', $coursecontext->id, $roleid);
+        $this->assignUserCapability('moodle/backup:configure', $coursecontext->id, $roleid);
+        // Optional capabilities to copy user data.
+        $this->assignUserCapability('moodle/backup:userinfo', $coursecontext->id, $roleid);
+        $this->assignUserCapability('moodle/restore:userinfo', $categorycontext->id, $roleid);
+
+        $newcourse['fullname'] = 'Course duplicate';
+        $newcourse['shortname'] = 'courseduplicate';
+        $newcourse['categoryid'] = $course->category;
+        $newcourse['visible'] = true;
+        $newcourse['options'][] = array('name' => 'users', 'value' => true);
+
+        $duplicate = core_course_external::duplicate_course($course->id, $newcourse['fullname'],
+                $newcourse['shortname'], $newcourse['categoryid'], $newcourse['visible'], $newcourse['options']);
+
+        // Check that the course has been duplicated.
+        $this->assertEquals($newcourse['shortname'], $duplicate['shortname']);
+    }
+}
index 9a11f48..ad71ff7 100644 (file)
@@ -26,5 +26,9 @@ function xmldb_enrol_authorize_upgrade($oldversion) {
     $dbman = $DB->get_manager();
 
 
+    // Moodle v2.3.0 release upgrade line
+    // Put any upgrade step following this
+
+
     return true;
 }
index c21880c..7aae081 100644 (file)
@@ -30,5 +30,9 @@ function xmldb_enrol_database_upgrade($oldversion) {
     $dbman = $DB->get_manager();
 
 
+    // Moodle v2.3.0 release upgrade line
+    // Put any upgrade step following this
+
+
     return true;
 }
index b8e4a73..67785c2 100644 (file)
@@ -32,5 +32,9 @@ function xmldb_enrol_flatfile_upgrade($oldversion) {
     $dbman = $DB->get_manager();
 
 
+    // Moodle v2.3.0 release upgrade line
+    // Put any upgrade step following this
+
+
     return true;
 }
index b19b5a6..b14e8f8 100644 (file)
@@ -40,6 +40,10 @@ function xmldb_enrol_guest_upgrade($oldversion) {
         upgrade_plugin_savepoint(true, 2011112901, 'enrol', 'guest');
     }
 
+    // Moodle v2.3.0 release upgrade line
+    // Put any upgrade step following this
+
+
     return true;
 }
 
index a348d69..39b8fdc 100644 (file)
@@ -31,6 +31,10 @@ function xmldb_enrol_imsenterprise_upgrade($oldversion) {
     $dbman = $DB->get_manager();
 
 
+    // Moodle v2.3.0 release upgrade line
+    // Put any upgrade step following this
+
+
     return true;
 }
 
index 6564435..8c70236 100644 (file)
@@ -32,5 +32,9 @@ function xmldb_enrol_mnet_upgrade($oldversion) {
     $dbman = $DB->get_manager();
 
 
+    // Moodle v2.3.0 release upgrade line
+    // Put any upgrade step following this
+
+
     return true;
 }
index b66c655..8bcb41f 100644 (file)
@@ -47,5 +47,9 @@ function xmldb_enrol_paypal_upgrade($oldversion) {
     $dbman = $DB->get_manager();
 
 
+    // Moodle v2.3.0 release upgrade line
+    // Put any upgrade step following this
+
+
     return true;
 }
index 2e425a6..32c9d48 100644 (file)
@@ -291,7 +291,7 @@ class enrol_self_plugin extends enrol_plugin {
         if ($rusers) {
             $contact = reset($rusers);
         } else {
-            $contact = get_admin();
+            $contact = generate_email_supportuser();
         }
 
         //directly emailing welcome message rather than using messaging
index 33a70f6..78096e2 100644 (file)
@@ -455,10 +455,10 @@ class core_files_renderer extends plugin_renderer_base {
      */
     private function fm_print_restrictions($fm) {
         $maxbytes = display_size($fm->options->maxbytes);
-        if (empty($options->maxfiles) || $options->maxfiles == -1) {
+        if (empty($fm->options->maxfiles) || $fm->options->maxfiles == -1) {
             $maxsize = get_string('maxfilesize', 'moodle', $maxbytes);
         } else {
-            $strparam = (object)array('size' => $maxbytes, 'attachments' => $options->maxfiles);
+            $strparam = (object)array('size' => $maxbytes, 'attachments' => $fm->options->maxfiles);
             $maxsize = get_string('maxsizeandattachments', 'moodle', $strparam);
         }
         // TODO MDL-32020 also should say about 'File types accepted'
index c77415f..a9c7964 100644 (file)
@@ -54,5 +54,9 @@ function xmldb_filter_mediaplugin_upgrade($oldversion) {
         upgrade_plugin_savepoint(true, 2011121200, 'filter', 'mediaplugin');
     }
 
+    // Moodle v2.3.0 release upgrade line
+    // Put any upgrade step following this
+
+
     return true;
 }
index fea5c3d..74b0ef5 100644 (file)
@@ -33,5 +33,9 @@ function xmldb_filter_tex_upgrade($oldversion) {
     $dbman = $DB->get_manager();
 
 
+    // Moodle v2.3.0 release upgrade line
+    // Put any upgrade step following this
+
+
     return true;
 }
index 783ee46..1f1cd90 100644 (file)
@@ -4,7 +4,7 @@ M.gradingform_guide = {};
  * This function is called for each guide on page.
  */
 M.gradingform_guide.init = function(Y, options) {
-    var currentfocus = null;
+    var currentfocus = Y.one('.markingguideremark');
 
     Y.all('.markingguideremark').on('blur', function(e) {
         currentfocus = e.currentTarget;
index e60160d..7c1d214 100644 (file)
@@ -38,5 +38,9 @@ function xmldb_gradingform_rubric_upgrade($oldversion) {
     // Moodle v2.2.0 release upgrade line
     // Put any upgrade step following this
 
+    // Moodle v2.3.0 release upgrade line
+    // Put any upgrade step following this
+
+
     return true;
 }
index 0683c79..9a9d10c 100644 (file)
@@ -110,6 +110,7 @@ $string['courseprerequisites']='Course prerequisites';
 $string['coursesavailable']='Courses available';
 $string['coursesavailableexplaination']='<i>Course completion criteria must be set for a course to appear in this list</i>';
 $string['criteria']='Criteria';
+$string['criteriagradenote'] = 'Please note that updating the required grade here will not update the current course pass grade.';
 $string['criteriagroup']='Criteria group';
 $string['criteriarequiredall']='All criteria below are required';
 $string['criteriarequiredany']='Any criteria below are required';
@@ -124,6 +125,8 @@ $string['datepassed']='Date passed';
 $string['daysafterenrolment']='Days after enrolment';
 $string['durationafterenrolment']='Duration after enrolment';
 $string['fraction']='Fraction';
+$string['gradexrequired']='{$a} required';
+$string['graderequired']='Grade required';
 $string['inprogress']='In progress';
 $string['manualcompletionby']='Manual completion by';
 $string['manualselfcompletion']='Manual self completion';
@@ -136,7 +139,6 @@ $string['nocriteriaset']='No completion criteria set for this course';
 $string['notenroled']='You are not enrolled in this course';
 $string['notyetstarted']='Not yet started';
 $string['overallcriteriaaggregation']='Overall criteria type aggregation';
-$string['passinggrade']='Passing grade';
 $string['pending']='Pending';
 $string['periodpostenrolment']='Period post enrolment';
 $string['prerequisites']='Prerequisites';
index fcd91b8..de180b4 100644 (file)
@@ -1961,6 +1961,9 @@ function is_enrolled(context $context, $user = null, $withcapability = '', $only
             $coursecontext->reload_if_dirty();
             if (isset($USER->enrol['enrolled'][$coursecontext->instanceid])) {
                 if ($USER->enrol['enrolled'][$coursecontext->instanceid] > time()) {
+                    if ($withcapability and !has_capability($withcapability, $context, $userid)) {
+                        return false;
+                    }
                     return true;
                 }
             }
index 4aff653..5062c99 100644 (file)
@@ -452,7 +452,7 @@ function get_used_table_names() {
 
         if ($loaded and $tables = $structure->getTables()) {
             foreach($tables as $table) {
-                $table_names[] = strtolower($table->name);
+                $table_names[] = strtolower($table->getName());
             }
         }
     }
index 6bc32ed..56a4d0f 100644 (file)
@@ -62,8 +62,9 @@ class completion_criteria_grade extends completion_criteria {
      */
     public function config_form_display(&$mform, $data = null) {
         $mform->addElement('checkbox', 'criteria_grade', get_string('enable'));
-        $mform->addElement('text', 'criteria_grade_value', get_string('passinggrade', 'completion'));
+        $mform->addElement('text', 'criteria_grade_value', get_string('graderequired', 'completion'));
         $mform->setDefault('criteria_grade_value', $data);
+        $mform->addElement('static', 'criteria_grade_value_note', '', get_string('criteriagradenote', 'completion'));
 
         if ($this->id) {
             $mform->setDefault('criteria_grade', 1);
@@ -128,7 +129,7 @@ class completion_criteria_grade extends completion_criteria {
      * @return  string
      */
     public function get_title() {
-        return get_string('grade');
+        return get_string('coursegrade', 'completion');
     }
 
     /**
@@ -137,7 +138,8 @@ class completion_criteria_grade extends completion_criteria {
      * @return string
      */
     public function get_title_detailed() {
-        return (float) $this->gradepass . '% required';
+        $graderequired = round($this->gradepass, 2).'%';
+        return get_string('gradexrequired', 'completion', $graderequired);
     }
 
     /**
@@ -156,15 +158,16 @@ class completion_criteria_grade extends completion_criteria {
      * @return string
      */
     public function get_status($completion) {
-        // Cast as floats to get rid of excess decimal places
-        $grade = (float) $this->get_grade($completion);
-        $gradepass = (float) $this->gradepass;
+        $grade = $this->get_grade($completion);
+        $graderequired = $this->get_title_detailed();
 
         if ($grade) {
-            return $grade.'% ('.$gradepass.'% to pass)';
+            $grade = round($grade, 2).'%';
         } else {
-            return $gradepass.'% to pass';
+            $grade = get_string('nograde');
         }
+
+        return $grade.' ('.$graderequired.')';
     }
 
     /**
@@ -231,11 +234,11 @@ class completion_criteria_grade extends completion_criteria {
     public function get_details($completion) {
         $details = array();
         $details['type'] = get_string('coursegrade', 'completion');
-        $details['criteria'] = get_string('passinggrade', 'completion');
-        $details['requirement'] = ((float)$this->gradepass).'%';
+        $details['criteria'] = get_string('graderequired', 'completion');
+        $details['requirement'] = round($this->gradepass, 2).'%';
         $details['status'] = '';
 
-        $grade = (float)$this->get_grade($completion);
+        $grade = round($this->get_grade($completion), 2);
         if ($grade) {
             $details['status'] = $grade.'%';
         }
index b034760..84bb65c 100644 (file)
@@ -212,7 +212,7 @@ function cron_run() {
                                                  p.id as prefid
                                             FROM {user} u
                                             JOIN {user_preferences} p ON u.id=p.userid
-                                           WHERE p.name='create_password' AND p.value='1' AND u.email !='' AND u.suspended = 0 AND u.auth != 'nologin'");
+                                           WHERE p.name='create_password' AND p.value='1' AND u.email !='' AND u.suspended = 0 AND u.auth != 'nologin' AND u.deleted = 0");
 
         // note: we can not send emails to suspended accounts
         foreach ($newusers as $newuser) {
@@ -709,7 +709,7 @@ function notify_login_failures() {
         mtrace('Emailing admins about '. $count .' failed login attempts');
         foreach ($recip as $admin) {
             //emailing the admins directly rather than putting these through the messaging system
-            email_to_user($admin,get_admin(), $subject, $body);
+            email_to_user($admin, generate_email_supportuser(), $subject, $body);
         }
     }
 
index b737428..372910c 100644 (file)
@@ -895,5 +895,9 @@ function xmldb_main_upgrade($oldversion) {
     }
 
 
+    // Moodle v2.3.0 release upgrade line
+    // Put any upgrade step following this
+
+
     return true;
 }
index e431b91..a5ad8c2 100644 (file)
@@ -308,6 +308,7 @@ class dml_testcase extends database_driver_testcase {
 
     function test_fix_sql_params() {
         $DB = $this->tdb;
+        $prefix = $DB->get_prefix();
 
         $table = $this->get_test_table();
         $tablename = $table->getName();
@@ -315,13 +316,13 @@ class dml_testcase extends database_driver_testcase {
         // Correct table placeholder substitution
         $sql = "SELECT * FROM {{$tablename}}";
         $sqlarray = $DB->fix_sql_params($sql);
-        $this->assertEquals("SELECT * FROM {$DB->get_prefix()}".$tablename, $sqlarray[0]);
+        $this->assertEquals("SELECT * FROM {$prefix}".$tablename, $sqlarray[0]);
 
         // Conversions of all param types
         $sql = array();
-        $sql[SQL_PARAMS_NAMED]  = "SELECT * FROM {$DB->get_prefix()}testtable WHERE name = :param1, course = :param2";
-        $sql[SQL_PARAMS_QM]     = "SELECT * FROM {$DB->get_prefix()}testtable WHERE name = ?, course = ?";
-        $sql[SQL_PARAMS_DOLLAR] = "SELECT * FROM {$DB->get_prefix()}testtable WHERE name = \$1, course = \$2";
+        $sql[SQL_PARAMS_NAMED]  = "SELECT * FROM {$prefix}testtable WHERE name = :param1, course = :param2";
+        $sql[SQL_PARAMS_QM]     = "SELECT * FROM {$prefix}testtable WHERE name = ?, course = ?";
+        $sql[SQL_PARAMS_DOLLAR] = "SELECT * FROM {$prefix}testtable WHERE name = \$1, course = \$2";
 
         $params = array();
         $params[SQL_PARAMS_NAMED]  = array('param1'=>'first record', 'param2'=>1);
@@ -921,12 +922,12 @@ class dml_testcase extends database_driver_testcase {
         $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
         $dbman->create_table($table);
 
-        $data = array(array('id' => 1, 'course' => 3, 'name' => 'record1', 'onetext'=>'abc'),
-            array('id' => 2, 'course' => 3, 'name' => 'record2', 'onetext'=>'abcd'),
-            array('id' => 3, 'course' => 5, 'name' => 'record3', 'onetext'=>'abcde'));
+        $data = array(array('course' => 3, 'name' => 'record1', 'onetext'=>'abc'),
+            array('course' => 3, 'name' => 'record2', 'onetext'=>'abcd'),
+            array('course' => 5, 'name' => 'record3', 'onetext'=>'abcde'));
 
-        foreach ($data as $record) {
-            $DB->insert_record($tablename, $record);
+        foreach ($data as $key=>$record) {
+            $data[$key]['id'] = $DB->insert_record($tablename, $record);
         }
 
         // standard recordset iteration
@@ -990,11 +991,79 @@ class dml_testcase extends database_driver_testcase {
             $this->assertEquals($e->errorcode, 'textconditionsnotallowed');
         }
 
+        // Test nested iteration.
+        $rs1 = $DB->get_recordset($tablename);
+        $i = 0;
+        foreach($rs1 as $record1) {
+            $rs2 = $DB->get_recordset($tablename);
+            $i++;
+            $j = 0;
+            foreach($rs2 as $record2) {
+                $j++;
+            }
+            $rs2->close();
+            $this->assertEquals($j, count($data));
+        }
+        $rs1->close();
+        $this->assertEquals($i, count($data));
+
         // notes:
         //  * limits are tested in test_get_recordset_sql()
         //  * where_clause() is used internally and is tested in test_get_records()
     }
 
+    public function test_get_recordset_static() {
+        $DB = $this->tdb;
+        $dbman = $DB->get_manager();
+
+        $table = $this->get_test_table();
+        $tablename = $table->getName();
+
+        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
+        $table->add_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
+        $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
+        $dbman->create_table($table);
+
+        $DB->insert_record($tablename, array('course' => 1));
+        $DB->insert_record($tablename, array('course' => 2));
+        $DB->insert_record($tablename, array('course' => 3));
+        $DB->insert_record($tablename, array('course' => 4));
+
+        $rs = $DB->get_recordset($tablename, array(), 'id');
+
+        $DB->set_field($tablename, 'course', 666, array('course'=>1));
+        $DB->delete_records($tablename, array('course'=>2));
+
+        $i = 0;
+        foreach($rs as $record) {
+            $i++;
+            $this->assertEquals($i, $record->course);
+        }
+        $rs->close();
+        $this->assertEquals(4, $i);
+
+        // Now repeat with limits because it may use different code.
+        $DB->delete_records($tablename, array());
+
+        $DB->insert_record($tablename, array('course' => 1));
+        $DB->insert_record($tablename, array('course' => 2));
+        $DB->insert_record($tablename, array('course' => 3));
+        $DB->insert_record($tablename, array('course' => 4));
+
+        $rs = $DB->get_recordset($tablename, array(), 'id', '*', 0, 3);
+
+        $DB->set_field($tablename, 'course', 666, array('course'=>1));
+        $DB->delete_records($tablename, array('course'=>2));
+
+        $i = 0;
+        foreach($rs as $record) {
+            $i++;
+            $this->assertEquals($i, $record->course);
+        }
+        $rs->close();
+        $this->assertEquals(3, $i);
+    }
+
     public function test_get_recordset_iterator_keys() {
         $DB = $this->tdb;
         $dbman = $DB->get_manager();
@@ -1009,11 +1078,11 @@ class dml_testcase extends database_driver_testcase {
         $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
         $dbman->create_table($table);
 
-        $data = array(array('id'=> 1, 'course' => 3, 'name' => 'record1'),
-            array('id'=> 2, 'course' => 3, 'name' => 'record2'),
-            array('id'=> 3, 'course' => 5, 'name' => 'record3'));
-        foreach ($data as $record) {
-            $DB->insert_record($tablename, $record);
+        $data = array(array('course' => 3, 'name' => 'record1'),
+            array('course' => 3, 'name' => 'record2'),
+            array('course' => 5, 'name' => 'record3'));
+        foreach ($data as $key=>$record) {
+            $data[$key]['id'] = $DB->insert_record($tablename, $record);
         }
 
         // Test repeated numeric keys are returned ok
@@ -4128,6 +4197,43 @@ class dml_testcase extends database_driver_testcase {
         $this->assertEquals(0, $DB->count_records($tablename)); // finally rolled back
 
         $DB->delete_records($tablename);
+
+        // Test interactions of recordset and transactions - this causes problems in SQL Server.
+        $table2 = $this->get_test_table('2');
+        $tablename2 = $table2->getName();
+
+        $table2->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
+        $table2->add_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
+        $table2->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
+        $dbman->create_table($table2);
+
+        $DB->insert_record($tablename, array('course'=>1));
+        $DB->insert_record($tablename, array('course'=>2));
+        $DB->insert_record($tablename, array('course'=>3));
+
+        $DB->insert_record($tablename2, array('course'=>5));
+        $DB->insert_record($tablename2, array('course'=>6));
+        $DB->insert_record($tablename2, array('course'=>7));
+        $DB->insert_record($tablename2, array('course'=>8));
+
+        $rs1 = $DB->get_recordset($tablename);
+        $i = 0;
+        foreach ($rs1 as $record1) {
+            $i++;
+            $rs2 = $DB->get_recordset($tablename2);
+            $j = 0;
+            foreach ($rs2 as $record2) {
+                $t = $DB->start_delegated_transaction();
+                $DB->set_field($tablename, 'course', $record1->course+1, array('id'=>$record1->id));
+                $DB->set_field($tablename2, 'course', $record2->course+1, array('id'=>$record2->id));
+                $t->allow_commit();
+                $j++;
+            }
+            $rs2->close();
+            $this->assertEquals(4, $j);
+        }
+        $rs1->close();
+        $this->assertEquals(3, $i);
     }
 
     function test_transactions_forbidden() {
index e814fee..523c643 100644 (file)
@@ -721,9 +721,16 @@ function file_save_draft_area_files($draftitemid, $contextid, $component, $filea
     if (!isset($options['maxfiles'])) {
         $options['maxfiles'] = -1; // unlimited
     }
-    if (!isset($options['maxbytes'])) {
+    if (!isset($options['maxbytes']) || $options['maxbytes'] == USER_CAN_IGNORE_FILE_SIZE_LIMITS) {
         $options['maxbytes'] = 0; // unlimited
     }
+    $allowreferences = true;
+    if (isset($options['return_types']) && !($options['return_types'] & FILE_REFERENCE)) {
+        // we assume that if $options['return_types'] is NOT specified, we DO allow references.
+        // this is not exactly right. BUT there are many places in code where filemanager options
+        // are not passed to file_save_draft_area_files()
+        $allowreferences = false;
+    }
 
     $draftfiles = $fs->get_area_files($usercontext->id, 'user', 'draft', $draftitemid, 'id');
     $oldfiles   = $fs->get_area_files($contextid, $component, $filearea, $itemid, 'id');
@@ -755,6 +762,9 @@ function file_save_draft_area_files($draftitemid, $contextid, $component, $filea
             }
 
             if ($file->is_external_file()) {
+                if (!$allowreferences) {
+                    continue;
+                }
                 $repoid = $file->get_repository_id();
                 if (!empty($repoid)) {
                     $file_record['repositoryid'] = $repoid;
@@ -856,6 +866,9 @@ function file_save_draft_area_files($draftitemid, $contextid, $component, $filea
             }
 
             if ($file->is_external_file()) {
+                if (!$allowreferences) {
+                    continue;
+                }
                 $repoid = $file->get_repository_id();
                 if (!empty($repoid)) {
                     $file_record['repositoryid'] = $repoid;
index f1f88b2..d81d5d9 100644 (file)
@@ -975,7 +975,7 @@ M.form_filemanager.init = function(Y, options) {
     var manager = new FileManagerHelper(options);
     var dndoptions = {
         filemanager: manager,
-        acceptedtypes: options.accepted_types,
+        acceptedtypes: options.filepicker.accepted_types,
         clientid: options.client_id,
         author: options.author,
         maxfiles: options.maxfiles,
index 58629dd..82b3ad9 100644 (file)
@@ -1924,6 +1924,9 @@ class global_navigation extends navigation_node {
         $activities = array();
 
         foreach ($sections as $key => $section) {
+            // Clone and unset summary to prevent $SESSION bloat (MDL-31802).
+            $sections[$key] = clone($section);
+            unset($sections[$key]->summary);
             $sections[$key]->hasactivites = false;
             if (!array_key_exists($section->section, $modinfo->sections)) {
                 continue;
index 75a8186..43de510 100644 (file)
@@ -811,7 +811,7 @@ class available_update_checker {
         }
 
         if (empty($response['forbranch']) or $response['forbranch'] !== moodle_major_version(true)) {
-            throw new available_update_checker_exception('err_response_target_version', $response['target']);
+            throw new available_update_checker_exception('err_response_target_version', $response['forbranch']);
         }
     }
 
index ac51a37..6d7bc4e 100644 (file)
@@ -147,6 +147,59 @@ class accesslib_testcase extends advanced_testcase {
         }
     }
 
+    /**
+     * Test if user is enrolled in a course
+     * @return void
+     */
+    public function test_is_enrolled() {
+        global $DB;
+
+        // Generate data
+        $user = $this->getDataGenerator()->create_user();
+        $course = $this->getDataGenerator()->create_course();
+        $coursecontext = context_course::instance($course->id);
+        $role = $DB->get_record('role', array('shortname'=>'student'));
+
+        // There should be a manual enrolment as part of the default install
+        $plugin = enrol_get_plugin('manual');
+        $instance = $DB->get_record('enrol', array(
+            'courseid' => $course->id,
+            'enrol' => 'manual',
+        ));
+        $this->assertNotEquals($instance, false);
+
+        // Enrol the user in the course
+        $plugin->enrol_user($instance, $user->id, $role->id);
+
+        // We'll test with the mod/assign:submit capability
+        $capability= 'mod/assign:submit';
+        $this->assertTrue($DB->record_exists('capabilities', array('name' => $capability)));
+
+        // Switch to our user
+        $this->setUser($user);
+
+        // Ensure that the user has the capability first
+        $this->assertTrue(has_capability($capability, $coursecontext, $user->id));
+
+        // We first test whether the user is enrolled on the course as this
+        // seeds the cache, then we test for the capability
+        $this->assertTrue(is_enrolled($coursecontext, $user, '', true));
+        $this->assertTrue(is_enrolled($coursecontext, $user, $capability));
+
+        // Prevent the capability for this user role
+        assign_capability($capability, CAP_PROHIBIT, $role->id, $coursecontext);
+        $coursecontext->mark_dirty();
+        $this->assertFalse(has_capability($capability, $coursecontext, $user->id));
+
+        // Again, we seed the cache first by checking initial enrolment,
+        // and then we test the actual capability
+        $this->assertTrue(is_enrolled($coursecontext, $user, '', true));
+        $this->assertFalse(is_enrolled($coursecontext, $user, $capability));
+
+        // We need variable states to be reset for the next test
+        $this->resetAfterTest(true);
+    }
+
     /**
      * Test logged in test.
      * @return void
index dd79b5c..da3d22a 100644 (file)
@@ -36,6 +36,10 @@ function xmldb_message_email_upgrade($oldversion) {
     // Moodle v2.2.0 release upgrade line
     // Put any upgrade step following this
 
+    // Moodle v2.3.0 release upgrade line
+    // Put any upgrade step following this
+
+
     return true;
 }
 
index d884f25..eb78904 100644 (file)
@@ -36,6 +36,10 @@ function xmldb_message_jabber_upgrade($oldversion) {
     // Moodle v2.2.0 release upgrade line
     // Put any upgrade step following this
 
+    // Moodle v2.3.0 release upgrade line
+    // Put any upgrade step following this
+
+
     return true;
 }
 
index 63a4f73..ef556ee 100644 (file)
@@ -36,6 +36,10 @@ function xmldb_message_popup_upgrade($oldversion) {
     // Moodle v2.2.0 release upgrade line
     // Put any upgrade step following this
 
+    // Moodle v2.3.0 release upgrade line
+    // Put any upgrade step following this
+
+
     return true;
 }
 
index e918367..de7a154 100644 (file)
@@ -47,6 +47,10 @@ function xmldb_assign_upgrade($oldversion) {
         upgrade_mod_savepoint(true, 2012051700, 'assign');
     }
 
+    // Moodle v2.3.0 release upgrade line
+    // Put any upgrade step following this
+
+
     return true;
 }
 
index 9321ecc..97409c6 100644 (file)
  */
 function xmldb_assignfeedback_comments_upgrade($oldversion) {
     // do the upgrades
+    // Moodle v2.3.0 release upgrade line
+    // Put any upgrade step following this
+
+
     return true;
 }
 
index cf6594e..e59722d 100644 (file)
  */
 function xmldb_assignfeedback_file_upgrade($oldversion) {
     // do the upgrades
+    // Moodle v2.3.0 release upgrade line
+    // Put any upgrade step following this
+
+
     return true;
 }
 
index 6bc5bce..565fc0f 100644 (file)
  * @return bool
  */
 function xmldb_assignsubmission_comments_upgrade($oldversion) {
+    // Moodle v2.3.0 release upgrade line
+    // Put any upgrade step following this
+
+
     return true;
 }
 
index b00f57b..a86a5fb 100644 (file)
  * @return bool
  */
 function xmldb_assignsubmission_file_upgrade($oldversion) {
+    // Moodle v2.3.0 release upgrade line
+    // Put any upgrade step following this
+
+
     return true;
 }
 
index 183e602..056c0bb 100644 (file)
  * @return bool
  */
 function xmldb_assignsubmission_onlinetext_upgrade($oldversion) {
+    // Moodle v2.3.0 release upgrade line
+    // Put any upgrade step following this
+
+
     return true;
 }
 
index 6608b6c..aa605cc 100644 (file)
@@ -29,6 +29,46 @@ function xmldb_assignment_upgrade($oldversion) {
     // Moodle v2.2.0 release upgrade line
     // Put any upgrade step following this
 
+    // Moodle v2.3.0 release upgrade line
+    // Put any upgrade step following this
+
+    if ($oldversion < 2012061701) {
+        // Fixed/updated numfiles field in assignment_submissions table to count the actual
+        // number of files has been uploaded when sendformarking is disabled
+        upgrade_set_timeout(600);  // increase excution time for in large sites
+        $fs = get_file_storage();
+
+        // Fetch the moduleid for use in the course_modules table
+        $moduleid = $DB->get_field('modules', 'id', array('name' => 'assignment'), MUST_EXIST);
+
+        $selectcount = 'SELECT COUNT(s.id) ';
+        $select      = 'SELECT s.id, cm.id AS cmid ';
+        $query       = 'FROM {assignment_submissions} s
+                        JOIN {assignment} a ON a.id = s.assignment
+                        JOIN {course_modules} cm ON a.id = cm.instance AND cm.module = :moduleid
+                        WHERE assignmenttype = :assignmenttype';
+
+        $params = array('moduleid' => $moduleid, 'assignmenttype' => 'upload');
+
+        $countsubmissions = $DB->count_records_sql($selectcount.$query, $params);
+        $submissions = $DB->get_recordset_sql($select.$query, $params);
+
+        $pbar = new progress_bar('assignmentupgradenumfiles', 500, true);
+        $i = 0;
+        foreach ($submissions as $sub) {
+            $i++;
+            if ($context = context_module::instance($sub->cmid)) {
+                $sub->numfiles = count($fs->get_area_files($context->id, 'mod_assignment', 'submission', $sub->id, 'sortorder', false));
+                $DB->update_record('assignment_submissions', $sub);
+            }
+            $pbar->update($i, $countsubmissions, "Counting files of submissions ($i/$countsubmissions)");
+        }
+        $submissions->close();
+
+        // assignment savepoint reached
+        upgrade_mod_savepoint(true, 2012061701, 'assignment');
+    }
+
     return true;
 }
 
index 6971120..83afeb4 100644 (file)
@@ -395,8 +395,8 @@ class assignment_upload extends assignment_base {
 
     /**
      * Counts all complete (real) assignment submissions by enrolled students. This overrides assignment_base::count_real_submissions().
-     * This is necessary for advanced file uploads where we need to check that the data2 field is equal to "submitted" to determine
-     * if a submission is complete.
+     * This is necessary for tracked advanced file uploads where we need to check that the data2 field is equal to ASSIGNMENT_STATUS_SUBMITTED
+     * to determine if a submission is complete.
      *
      * @param  int $groupid (optional) If nonzero then count is restricted to this group
      * @return int          The number of submissions
@@ -411,13 +411,19 @@ class assignment_upload extends assignment_base {
         list($enroledsql, $params) = get_enrolled_sql($context, 'mod/assignment:view', $groupid);
         $params['assignmentid'] = $this->cm->instance;
 
-        // Get ids of users enrolled in the given course.
+        $query = '';
+        if ($this->drafts_tracked() and $this->isopen()) {
+            $query = ' AND ' . $DB->sql_compare_text('s.data2') . " = '"  . ASSIGNMENT_STATUS_SUBMITTED . "'";
+        } else {
+            // Count on submissions with files actually uploaded
+            $query = " AND s.numfiles > 0";
+        }
         return $DB->count_records_sql("SELECT COUNT('x')
                                          FROM {assignment_submissions} s
                                     LEFT JOIN {assignment} a ON a.id = s.assignment
                                    INNER JOIN ($enroledsql) u ON u.id = s.userid
-                                        WHERE s.assignment = :assignmentid AND
-                                              s.data2 = 'submitted'", $params);
+                                        WHERE s.assignment = :assignmentid" .
+                                              $query, $params);
     }
 
     function print_responsefiles($userid, $return=false) {
@@ -581,6 +587,7 @@ class assignment_upload extends assignment_base {
             $formdata = file_postupdate_standard_filemanager($formdata, 'files', $options, $this->context, 'mod_assignment', 'submission', $submission->id);
             $updates = new stdClass();
             $updates->id = $submission->id;
+            $updates->numfiles = count($fs->get_area_files($this->context->id, 'mod_assignment', 'submission', $submission->id, 'sortorder', false));
             $updates->timemodified = time();
             $DB->update_record('assignment_submissions', $updates);
             add_to_log($this->course->id, 'assignment', 'upload',
index c7c7c2d..7d69e8f 100644 (file)
@@ -25,7 +25,7 @@
 
 defined('MOODLE_INTERNAL') || die();
 
-$module->version   = 2012061700;       // The current module version (Date: YYYYMMDDXX)
+$module->version   = 2012061701;       // The current module version (Date: YYYYMMDDXX)
 $module->requires  = 2012061700;    // Requires this Moodle version
 $module->component = 'mod_assignment'; // Full name of the plugin (used for diagnostics)
 $module->cron      = 60;
index 735116c..3fb1085 100644 (file)
@@ -37,5 +37,9 @@ function xmldb_book_upgrade($oldversion) {
     // Moodle v2.2.0 release upgrade line
     // Put any upgrade step following this
 
+    // Moodle v2.3.0 release upgrade line
+    // Put any upgrade step following this
+
+
     return true;
 }
index 2b9ad1d..c716494 100644 (file)
@@ -29,6 +29,10 @@ function xmldb_chat_upgrade($oldversion) {
     // Moodle v2.2.0 release upgrade line
     // Put any upgrade step following this
 
+    // Moodle v2.3.0 release upgrade line
+    // Put any upgrade step following this
+
+
     return true;
 }
 
index f86bbe4..e46ab79 100644 (file)
@@ -29,6 +29,10 @@ function xmldb_choice_upgrade($oldversion) {
     // Moodle v2.2.0 release upgrade line
     // Put any upgrade step following this
 
+    // Moodle v2.3.0 release upgrade line
+    // Put any upgrade step following this
+
+
     return true;
 }
 
index a84c883..745d0cb 100644 (file)
@@ -29,6 +29,10 @@ function xmldb_data_upgrade($oldversion) {
     // Moodle v2.2.0 release upgrade line
     // Put any upgrade step following this
 
+    // Moodle v2.3.0 release upgrade line
+    // Put any upgrade step following this
+
+
     return true;
 }
 
index c4ededd..fd0d9a5 100644 (file)
@@ -43,6 +43,10 @@ function xmldb_feedback_upgrade($oldversion) {
     // Moodle v2.2.0 release upgrade line
     // Put any upgrade step following this
 
+    // Moodle v2.3.0 release upgrade line
+    // Put any upgrade step following this
+
+
     return true;
 }
 
index 3e5501f..33955c1 100644 (file)
@@ -561,6 +561,9 @@ class feedback_item_multichoice extends feedback_item_base {
 
     public function create_value($data) {
         $vallist = $data;
+        if (is_array($vallist)) {
+            $vallist = array_unique($vallist);
+        }
         return trim($this->item_array_to_string($vallist));
     }
 
index 7a2b6e2..d996b61 100644 (file)
@@ -55,5 +55,9 @@ function xmldb_folder_upgrade($oldversion) {
     // Moodle v2.2.0 release upgrade line
     // Put any upgrade step following this
 
+    // Moodle v2.3.0 release upgrade line
+    // Put any upgrade step following this
+
+
     return true;
 }
index d493b2b..4c2f297 100644 (file)
@@ -50,6 +50,10 @@ function xmldb_forum_upgrade($oldversion) {
     // Moodle v2.2.0 release upgrade line
     // Put any upgrade step following this
 
+    // Moodle v2.3.0 release upgrade line
+    // Put any upgrade step following this
+
+
     return true;
 }
 
index 1f70499..812172a 100644 (file)
@@ -27,6 +27,7 @@ defined('MOODLE_INTERNAL') || die();
 require_once($CFG->libdir.'/filelib.php');
 require_once($CFG->libdir.'/eventslib.php');
 require_once($CFG->dirroot.'/user/selector/lib.php');
+require_once($CFG->dirroot.'/mod/forum/post_form.php');
 
 /// CONSTANTS ///////////////////////////////////////////////////////////
 
@@ -99,7 +100,8 @@ function forum_add_instance($forum, $mform = null) {
             $discussion = $DB->get_record('forum_discussions', array('id'=>$discussion->id), '*', MUST_EXIST);
             $post = $DB->get_record('forum_posts', array('id'=>$discussion->firstpost), '*', MUST_EXIST);
 
-            $post->message = file_save_draft_area_files($draftid, $modcontext->id, 'mod_forum', 'post', $post->id, array('subdirs'=>true), $post->message);
+            $post->message = file_save_draft_area_files($draftid, $modcontext->id, 'mod_forum', 'post', $post->id,
+                    mod_forum_post_form::attachment_options($forum), $post->message);
             $DB->set_field('forum_posts', 'message', $post->message, array('id'=>$post->id));
         }
     }
@@ -196,7 +198,8 @@ function forum_update_instance($forum, $mform) {
             $discussion = $DB->get_record('forum_discussions', array('id'=>$discussion->id), '*', MUST_EXIST);
             $post = $DB->get_record('forum_posts', array('id'=>$discussion->firstpost), '*', MUST_EXIST);
 
-            $post->message = file_save_draft_area_files($draftid, $modcontext->id, 'mod_forum', 'post', $post->id, array('subdirs'=>true), $post->message);
+            $post->message = file_save_draft_area_files($draftid, $modcontext->id, 'mod_forum', 'post', $post->id,
+                    mod_forum_post_form::editor_options(), $post->message);
         }
 
         $post->subject       = $forum->name;
@@ -4230,7 +4233,8 @@ function forum_add_attachment($post, $forum, $cm, $mform=null, &$message=null) {
 
     $info = file_get_draft_area_info($post->attachments);
     $present = ($info['filecount']>0) ? '1' : '';
-    file_save_draft_area_files($post->attachments, $context->id, 'mod_forum', 'attachment', $post->id);
+    file_save_draft_area_files($post->attachments, $context->id, 'mod_forum', 'attachment', $post->id,
+            mod_forum_post_form::attachment_options($forum));
 
     $DB->set_field('forum_posts', 'attachment', $present, array('id'=>$post->id));
 
@@ -4262,7 +4266,8 @@ function forum_add_new_post($post, $mform, &$message) {
     $post->attachment = "";
 
     $post->id = $DB->insert_record("forum_posts", $post);
-    $post->message = file_save_draft_area_files($post->itemid, $context->id, 'mod_forum', 'post', $post->id, array('subdirs'=>true), $post->message);
+    $post->message = file_save_draft_area_files($post->itemid, $context->id, 'mod_forum', 'post', $post->id,
+            mod_forum_post_form::editor_options(), $post->message);
     $DB->set_field('forum_posts', 'message', $post->message, array('id'=>$post->id));
     forum_add_attachment($post, $forum, $cm, $mform, $message);
 
@@ -4308,7 +4313,8 @@ function forum_update_post($post, $mform, &$message) {
         $discussion->timestart = $post->timestart;
         $discussion->timeend   = $post->timeend;
     }
-    $post->message = file_save_draft_area_files($post->itemid, $context->id, 'mod_forum', 'post', $post->id, array('subdirs'=>true), $post->message);
+    $post->message = file_save_draft_area_files($post->itemid, $context->id, 'mod_forum', 'post', $post->id,
+            mod_forum_post_form::editor_options(), $post->message);
     $DB->set_field('forum_posts', 'message', $post->message, array('id'=>$post->id));
 
     $DB->update_record('forum_discussions', $discussion);
@@ -4371,7 +4377,8 @@ function forum_add_discussion($discussion, $mform=null, &$message=null, $userid=
     // TODO: Fix the calling code so that there always is a $cm when this function is called
     if (!empty($cm->id) && !empty($discussion->itemid)) {   // In "single simple discussions" this may not exist yet
         $context = get_context_instance(CONTEXT_MODULE, $cm->id);
-        $text = file_save_draft_area_files($discussion->itemid, $context->id, 'mod_forum', 'post', $post->id, array('subdirs'=>true), $post->message);
+        $text = file_save_draft_area_files($discussion->itemid, $context->id, 'mod_forum', 'post', $post->id,
+                mod_forum_post_form::editor_options(), $post->message);
         $DB->set_field('forum_posts', 'message', $text, array('id'=>$post->id));
     }
 
index 15a386d..20528d0 100644 (file)
@@ -510,7 +510,7 @@ require_once('post_form.php');
 $mform_post = new mod_forum_post_form('post.php', array('course'=>$course, 'cm'=>$cm, 'coursecontext'=>$coursecontext, 'modcontext'=>$modcontext, 'forum'=>$forum, 'post'=>$post));
 
 $draftitemid = file_get_submitted_draft_itemid('attachments');
-file_prepare_draft_area($draftitemid, $modcontext->id, 'mod_forum', 'attachment', empty($post->id)?null:$post->id);
+file_prepare_draft_area($draftitemid, $modcontext->id, 'mod_forum', 'attachment', empty($post->id)?null:$post->id, mod_forum_post_form::attachment_options($forum));
 
 //load data into form NOW!
 
@@ -550,7 +550,7 @@ if (forum_is_subscribed($USER->id, $forum->id)) {
 }
 
 $draftid_editor = file_get_submitted_draft_itemid('message');
-$currenttext = file_prepare_draft_area($draftid_editor, $modcontext->id, 'mod_forum', 'post', empty($post->id) ? null : $post->id, array('subdirs'=>true), $post->message);
+$currenttext = file_prepare_draft_area($draftid_editor, $modcontext->id, 'mod_forum', 'post', empty($post->id) ? null : $post->id, mod_forum_post_form::editor_options(), $post->message);
 $mform_post->set_data(array(        'attachments'=>$draftitemid,
                                     'general'=>$heading,
                                     'subject'=>$post->subject,
index b475684..c710567 100644 (file)
@@ -29,6 +29,41 @@ require_once($CFG->libdir.'/formslib.php');
 
 class mod_forum_post_form extends moodleform {
 
+    /**
+     * Returns the options array to use in filemanager for forum attachments
+     *
+     * @param stdClass $forum
+     * @return array
+     */
+    public static function attachment_options($forum) {
+        global $COURSE, $PAGE, $CFG;
+        $maxbytes = get_user_max_upload_file_size($PAGE->context, $CFG->maxbytes, $COURSE->maxbytes, $forum->maxbytes);
+        return array(
+            'subdirs' => 0,
+            'maxbytes' => $maxbytes,
+            'maxfiles' => $forum->maxattachments,
+            'accepted_types' => '*',
+            'return_types' => FILE_INTERNAL
+        );
+    }
+
+    /**
+     * Returns the options array to use in forum text editor
+     *
+     * @return array
+     */
+    public static function editor_options() {
+        global $COURSE, $PAGE, $CFG;
+        // TODO: add max files and max size support
+        $maxbytes = get_user_max_upload_file_size($PAGE->context, $CFG->maxbytes, $COURSE->maxbytes);
+        return array(
+            'maxfiles' => EDITOR_UNLIMITED_FILES,
+            'maxbytes' => $maxbytes,
+            'trusttext'=> true,
+            'return_types'=> FILE_INTERNAL | FILE_EXTERNAL
+        );
+    }
+
     function definition() {
 
         global $CFG;
@@ -40,13 +75,6 @@ class mod_forum_post_form extends moodleform {
         $modcontext    = $this->_customdata['modcontext'];
         $forum         = $this->_customdata['forum'];
         $post          = $this->_customdata['post'];
-        // if $forum->maxbytes == '0' means we should use $course->maxbytes
-        if ($forum->maxbytes == '0') {
-            $forum->maxbytes = $course->maxbytes;
-        }
-        // TODO: add max files and max size support
-        $editoroptions = array('maxfiles' => EDITOR_UNLIMITED_FILES, 'trusttext'=>true,
-            'context'=>$modcontext, 'return_types'=>FILE_INTERNAL | FILE_EXTERNAL);
 
         $mform->addElement('header', 'general', '');//fill in the data depending on page params later using set_data
         $mform->addElement('text', 'subject', get_string('subject', 'forum'), 'size="48"');
@@ -54,7 +82,7 @@ class mod_forum_post_form extends moodleform {
         $mform->addRule('subject', get_string('required'), 'required', null, 'client');
         $mform->addRule('subject', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
 
-        $mform->addElement('editor', 'message', get_string('message', 'forum'), null, $editoroptions);
+        $mform->addElement('editor', 'message', get_string('message', 'forum'), null, self::editor_options());
         $mform->setType('message', PARAM_RAW);
         $mform->addRule('message', get_string('required'), 'required', null, 'client');
 
@@ -82,12 +110,7 @@ class mod_forum_post_form extends moodleform {
             }
 
         if (!empty($forum->maxattachments) && $forum->maxbytes != 1 && has_capability('mod/forum:createattachment', $modcontext))  {  //  1 = No attachments at all
-            $mform->addElement('filemanager', 'attachments', get_string('attachment', 'forum'), null,
-                array('subdirs'=>0,
-                      'maxbytes'=>$forum->maxbytes,
-                      'maxfiles'=>$forum->maxattachments,
-                      'accepted_types'=>'*',
-                      'return_types'=>FILE_INTERNAL));
+            $mform->addElement('filemanager', 'attachments', get_string('attachment', 'forum'), null, self::attachment_options($forum));
             $mform->addHelpButton('attachments', 'attachment', 'forum');
         }
 
index daa7bdc..ebbc99f 100644 (file)
@@ -369,11 +369,11 @@ function forum_print_big_search_form($course) {
     }
 
     echo '<input name="timetorestrict" type="checkbox" value="1" alt="'.get_string('searchdateto', 'forum').'" onclick="return lockoptions(\'searchform\', \'timetorestrict\', timetoitems)" ' .$datetochecked. ' /> ';
-    $selectors = html_writer::select_time('days', 'fromday', $dateto)
-               . html_writer::select_time('months', 'frommonth', $dateto)
-               . html_writer::select_time('years', 'fromyear', $dateto)
-               . html_writer::select_time('hours', 'fromhour', $dateto)
-               . html_writer::select_time('minutes', 'fromminute', $dateto);
+    $selectors = html_writer::select_time('days', 'today', $dateto)
+               . html_writer::select_time('months', 'tomonth', $dateto)
+               . html_writer::select_time('years', 'toyear', $dateto)
+               . html_writer::select_time('hours', 'tohour', $dateto)
+               . html_writer::select_time('minutes', 'tominute', $dateto);
     echo $selectors;
 
     echo '<input type="hidden" name="htoday" value="0" />';
index ccebcd2..48e85b8 100644 (file)
@@ -44,6 +44,10 @@ function xmldb_glossary_upgrade($oldversion) {
         upgrade_mod_savepoint(true, 2012022000, 'glossary');
     }
 
+    // Moodle v2.3.0 release upgrade line
+    // Put any upgrade step following this
+
+
     return true;
 }
 
index 8421481..d0d08aa 100644 (file)
@@ -11,7 +11,7 @@ $offset        = optional_param('offset', 0, PARAM_INT);              // number
 $displayformat = optional_param('displayformat',-1, PARAM_INT);
 
 $mode    = required_param('mode', PARAM_ALPHA);             // mode to show the entries
-$hook    = optional_param('hook','ALL', PARAM_ALPHANUM);   // what to show
+$hook    = optional_param('hook','ALL', PARAM_CLEAN);       // what to show
 $sortkey = optional_param('sortkey','UPDATE', PARAM_ALPHA); // Sorting key
 
 $url = new moodle_url('/mod/glossary/print.php', array('id'=>$id));
index 2b027f7..e4c4b0a 100644 (file)
@@ -35,5 +35,9 @@ function xmldb_imscp_upgrade($oldversion) {
     // Moodle v2.2.0 release upgrade line
     // Put any upgrade step following this
 
+    // Moodle v2.3.0 release upgrade line
+    // Put any upgrade step following this
+
+
     return true;
 }
index 0511d0f..a083759 100644 (file)
@@ -55,6 +55,10 @@ function xmldb_label_upgrade($oldversion) {
     // Moodle v2.2.0 release upgrade line
     // Put any upgrade step following this
 
+    // Moodle v2.3.0 release upgrade line
+    // Put any upgrade step following this
+
+
     return true;
 }
 
index 04b0b8f..0cc8e03 100644 (file)
@@ -61,6 +61,10 @@ function xmldb_lesson_upgrade($oldversion) {
     // Moodle v2.2.0 release upgrade line
     // Put any upgrade step following this
 
+    // Moodle v2.3.0 release upgrade line
+    // Put any upgrade step following this
+
+
     return true;
 }
 
index 2b5f1bc..9fd4e13 100644 (file)
@@ -68,6 +68,10 @@ function xmldb_lti_upgrade($oldversion) {
     // Moodle v2.2.0 release upgrade line
     // Put any upgrade step following this
 
+    // Moodle v2.3.0 release upgrade line
+    // Put any upgrade step following this
+
+
     return true;
 }
 
index 4a81df9..b1c4e91 100644 (file)
@@ -55,5 +55,9 @@ function xmldb_page_upgrade($oldversion) {
     // Moodle v2.2.0 release upgrade line
     // Put any upgrade step following this
 
+    // Moodle v2.3.0 release upgrade line
+    // Put any upgrade step following this
+
+
     return true;
 }
index 9c0f148..11efebd 100644 (file)
@@ -445,7 +445,7 @@ class quiz_access_manager {
      */
     public function back_to_view_page($output, $message = '') {
         if ($this->attempt_must_be_in_popup()) {
-            echo $output->close_attempt_popup($message, $this->quizobj->view_url());
+            echo $output->close_attempt_popup($this->quizobj->view_url(), $message);
             die();
         } else {
             redirect($this->quizobj->view_url(), $message);
index eab7b0f..111419c 100644 (file)
@@ -125,10 +125,19 @@ class mod_quiz_overdue_attempt_updater {
         ) group_by_results
            JOIN {quiz_attempts} quiza ON quiza.id = group_by_results.attemptid
 
-          WHERE (state = 'inprogress' AND (:timenow1 > usertimeclose OR
-                                           :timenow2 > quiza.timestart + usertimelimit))
-             OR (state = 'overdue'    AND (:timenow3 > graceperiod + usertimeclose OR
-                                           :timenow4 > graceperiod + quiza.timestart + usertimelimit))
+          WHERE (
+                state = 'inprogress' AND (
+                    (usertimeclose > 0 AND :timenow1 > usertimeclose) OR
+                    (usertimelimit > 0 AND :timenow2 > quiza.timestart + usertimelimit)
+                )
+            )
+          OR
+            (
+                state = 'overdue' AND (
+                    (usertimeclose > 0 AND :timenow3 > graceperiod + usertimeclose) OR
+                    (usertimelimit > 0 AND :timenow4 > graceperiod + quiza.timestart + usertimelimit)
+                )
+            )
 
        ORDER BY course, quiz",
 
index 0c15b60..fd12420 100644 (file)
@@ -74,7 +74,7 @@
         <KEY NAME="primary" TYPE="primary" FIELDS="id" NEXT="quiz"/>
         <KEY NAME="quiz" TYPE="foreign" FIELDS="quiz" REFTABLE="quiz" REFFIELDS="id" PREVIOUS="primary" NEXT="userid"/>
         <KEY NAME="userid" TYPE="foreign" FIELDS="userid" REFTABLE="user" REFFIELDS="id" PREVIOUS="quiz" NEXT="uniqueid"/>
-        <KEY NAME="uniqueid" TYPE="foreign-unique" FIELDS="uniqueid" REFTABLE="question_attempts" REFFIELDS="id" PREVIOUS="userid"/>
+        <KEY NAME="uniqueid" TYPE="foreign-unique" FIELDS="uniqueid" REFTABLE="question_usages" REFFIELDS="id" PREVIOUS="userid"/>
       </KEYS>
       <INDEXES>
         <INDEX NAME="quiz-userid-attempt" UNIQUE="true" FIELDS="quiz, userid, attempt"/>
index d3a8e72..b0a4a4f 100644 (file)
@@ -327,6 +327,10 @@ function xmldb_quiz_upgrade($oldversion) {
         upgrade_mod_savepoint(true, 2012040206, 'quiz');
     }
 
+    // Moodle v2.3.0 release upgrade line
+    // Put any upgrade step following this
+
+
     return true;
 }
 
index cca3d30..ffd4287 100644 (file)
@@ -105,7 +105,7 @@ class mod_quiz_attempts_report_options {
         $this->cm     = $cm;
         $this->course = $course;
 
-        $this->usercanseegrades = quiz_report_should_show_grades($quiz);
+        $this->usercanseegrades = quiz_report_should_show_grades($quiz, context_module::instance($cm->id));
     }
 
     /**
index eefc978..f8aa7c8 100644 (file)
@@ -38,5 +38,9 @@ function xmldb_quiz_overview_upgrade($oldversion) {
     // Moodle v2.2.0 release upgrade line.
     // Put any upgrade step following this.
 
+    // Moodle v2.3.0 release upgrade line
+    // Put any upgrade step following this
+
+
     return true;
 }
index 9bfa402..d3e4e99 100644 (file)
@@ -401,9 +401,10 @@ function quiz_no_questions_message($quiz, $cm, $context) {
  * Should the grades be displayed in this report. That depends on the quiz
  * display options, and whether the quiz is graded.
  * @param object $quiz the quiz settings.
+ * @param context $context the quiz context.
  * @return bool
  */
-function quiz_report_should_show_grades($quiz) {
+function quiz_report_should_show_grades($quiz, context $context) {
     if ($quiz->timeclose && time() > $quiz->timeclose) {
         $when = mod_quiz_display_options::AFTER_CLOSE;
     } else {
@@ -413,5 +414,5 @@ function quiz_report_should_show_grades($quiz) {
 
     return quiz_has_grades($quiz) &&
             ($reviewoptions->marks >= question_display_options::MARK_AND_MAX ||
-            has_capability('moodle/grade:viewhidden', $this->context));
+            has_capability('moodle/grade:viewhidden', $context));
 }
index f3a7871..144d95a 100644 (file)
@@ -63,6 +63,10 @@ function xmldb_quiz_statistics_upgrade($oldversion) {
         upgrade_plugin_savepoint(true, 2012061801, 'quiz', 'statistics');
     }
 
+    // Moodle v2.3.0 release upgrade line
+    // Put any upgrade step following this
+
+
     return true;
 }
 
index fc6245e..383e888 100644 (file)
@@ -55,5 +55,9 @@ function xmldb_resource_upgrade($oldversion) {
     // Moodle v2.2.0 release upgrade line
     // Put any upgrade step following this
 
+    // Moodle v2.3.0 release upgrade line
+    // Put any upgrade step following this
+
+
     return true;
 }
index 43369fe..f079950 100644 (file)
@@ -197,7 +197,10 @@ function scorm_parse_aicc($scorm) {
                 if (preg_match($regexp, $rows[$i], $matches)) {
                     for ($j=0; $j<count($columns->columns); $j++) {
                         if ($j != $columns->mastercol) {
-                            $courses[$courseid]->elements[substr(trim($matches[$j+1]), 1 , -1)]->parent = substr(trim($matches[$columns->mastercol+1]), 1, -1);
+                            $element = substr(trim($matches[$j+1]), 1 , -1);
+                            if (!empty($element)) {
+                                $courses[$courseid]->elements[$element]->parent = substr(trim($matches[$columns->mastercol+1]), 1, -1);
+                            }
                         }
                     }
                 }
@@ -275,58 +278,61 @@ function scorm_parse_aicc($scorm) {
                     } else {
                         $sco->parent = $element->parent;
                     }
+                    $sco->launch = '';
+                    $sco->scormtype = '';
+                    $sco->previous = 0;
+                    $sco->next = 0;
+                    $id = null;
+                    // Is it an Assignable Unit (AU)?
                     if (isset($element->file_name)) {
                         $sco->launch = $element->file_name;
                         $sco->scormtype = 'sco';
-                        $sco->previous = 0;
-                        $sco->next = 0;
-                        $id = null;
-                        if ($oldscoid = scorm_array_search('identifier', $sco->identifier, $oldscoes)) {
-                            $sco->id = $oldscoid;
-                            $DB->update_record('scorm_scoes', $sco);
-                            $id = $oldscoid;
-                            $DB->delete_records('scorm_scoes_data', array('scoid'=>$oldscoid));
-                            unset($oldscoes[$oldscoid]);
-                        } else {
-                            $id = $DB->insert_record('scorm_scoes', $sco);
+                    }
+                    if ($oldscoid = scorm_array_search('identifier', $sco->identifier, $oldscoes)) {
+                        $sco->id = $oldscoid;
+                        $DB->update_record('scorm_scoes', $sco);
+                        $id = $oldscoid;
+                        $DB->delete_records('scorm_scoes_data', array('scoid'=>$oldscoid));
+                        unset($oldscoes[$oldscoid]);
+                    } else {
+                        $id = $DB->insert_record('scorm_scoes', $sco);
+                    }
+                    if (!empty($id)) {
+                        $scodata = new stdClass();
+                        $scodata->scoid = $id;
+                        if (isset($element->web_launch)) {
+                            $scodata->name = 'parameters';
+                            $scodata->value = $element->web_launch;
+                            $dataid = $DB->insert_record('scorm_scoes_data', $scodata);
                         }
-                        if (!empty($id)) {
-                            $scodata = new stdClass();
-                            $scodata->scoid = $id;
-                            if (isset($element->web_launch)) {
-                                $scodata->name = 'parameters';
-                                $scodata->value = $element->web_launch;
-                                $dataid = $DB->insert_record('scorm_scoes_data', $scodata);
-                            }
-                            if (isset($element->prerequisites)) {
-                                $scodata->name = 'prerequisites';
-                                $scodata->value = $element->prerequisites;
-                                $dataid = $DB->insert_record('scorm_scoes_data', $scodata);
-                            }
-                            if (isset($element->max_time_allowed)) {
-                                $scodata->name = 'max_time_allowed';
-                                $scodata->value = $element->max_time_allowed;
-                                $dataid = $DB->insert_record('scorm_scoes_data', $scodata);
-                            }
-                            if (isset($element->time_limit_action)) {
-                                $scodata->name = 'time_limit_action';
-                                $scodata->value = $element->time_limit_action;
-                                $dataid = $DB->insert_record('scorm_scoes_data', $scodata);
-                            }
-                            if (isset($element->mastery_score)) {
-                                $scodata->name = 'mastery_score';
-                                $scodata->value = $element->mastery_score;
-                                $dataid = $DB->insert_record('scorm_scoes_data', $scodata);
-                            }
-                            if (isset($element->core_vendor)) {
-                                $scodata->name = 'datafromlms';
-                                $scodata->value = preg_replace('/<cr>/i', "\r\n", $element->core_vendor);
-                                $dataid = $DB->insert_record('scorm_scoes_data', $scodata);
-                            }
+                        if (isset($element->prerequisites)) {
+                            $scodata->name = 'prerequisites';
+                            $scodata->value = $element->prerequisites;
+                            $dataid = $DB->insert_record('scorm_scoes_data', $scodata);
+                        }
+                        if (isset($element->max_time_allowed)) {
+                            $scodata->name = 'max_time_allowed';
+                            $scodata->value = $element->max_time_allowed;
+                            $dataid = $DB->insert_record('scorm_scoes_data', $scodata);
                         }
-                        if ($launch==0) {
-                            $launch = $id;
+                        if (isset($element->time_limit_action)) {
+                            $scodata->name = 'time_limit_action';
+                            $scodata->value = $element->time_limit_action;
+                            $dataid = $DB->insert_record('scorm_scoes_data', $scodata);
                         }
+                        if (isset($element->mastery_score)) {
+                            $scodata->name = 'mastery_score';
+                            $scodata->value = $element->mastery_score;
+                            $dataid = $DB->insert_record('scorm_scoes_data', $scodata);
+                        }
+                        if (isset($element->core_vendor)) {
+                            $scodata->name = 'datafromlms';
+                            $scodata->value = preg_replace('/<cr>/i', "\r\n", $element->core_vendor);
+                            $dataid = $DB->insert_record('scorm_scoes_data', $scodata);
+                        }
+                    }
+                    if ($launch==0) {
+                        $launch = $id;
                     }
                 }
             }
index a7bcbd7..a85397f 100644 (file)
@@ -60,6 +60,10 @@ function xmldb_scorm_upgrade($oldversion) {
         upgrade_mod_savepoint(true, 2012032101, 'scorm');
     }
 
+    // Moodle v2.3.0 release upgrade line
+    // Put any upgrade step following this
+
+
     return true;
 }
 
index 7b395f5..822d3e2 100644 (file)
@@ -150,7 +150,7 @@ function scorm_add_instance($scorm, $mform=null) {
 
     scorm_parse($record, true);
 
-    scorm_grade_item_update($record);
+    scorm_grade_item_update($record, null, false);
 
     return $record->id;
 }
@@ -646,9 +646,10 @@ function scorm_upgrade_grades() {
  * @uses GRADE_TYPE_NONE
  * @param object $scorm object with extra cmidnumber
  * @param mixed $grades optional array/object of grade(s); 'reset' means reset grades in gradebook
+ * @param boolean $updatecompletion  set whether to update completion stuff
  * @return object grade_item
  */
-function scorm_grade_item_update($scorm, $grades=null) {
+function scorm_grade_item_update($scorm, $grades=null, $updatecompletion=true) {
     global $CFG, $DB;
     require_once($CFG->dirroot.'/mod/scorm/locallib.php');
     if (!function_exists('grade_update')) { //workaround for buggy PHP versions
@@ -680,15 +681,16 @@ function scorm_grade_item_update($scorm, $grades=null) {
     }
 
     // Update activity completion if applicable
-    // Get course info
-    $course = new object();
-    $course->id = $scorm->course;
-
-    $cm = get_coursemodule_from_instance('scorm', $scorm->id, $course->id);
-    // CM will be false if this has been run from scorm_add_instance
-    if ($cm) {
-        $completion = new completion_info($course);
-        $completion->update_state($cm, COMPLETION_COMPLETE);
+    if ($updatecompletion) {
+        // Get course info
+        $course = new stdClass();
+        $course->id = $scorm->course;
+
+        $cm = get_coursemodule_from_instance('scorm', $scorm->id, $course->id);
+        if (!empty($cm)) {
+            $completion = new completion_info($course);
+            $completion->update_state($cm, COMPLETION_COMPLETE);
+        }
     }
 
     return grade_update('mod/scorm', $scorm->course, 'mod', 'scorm', $scorm->id, 0, $grades, $params);
index 7065221..c48c467 100644 (file)
@@ -1338,7 +1338,8 @@ function scorm_get_toc($user,$scorm,$cmid,$toclink=TOCJSLINK,$currentorg='',$sco
                 $isvisible = true;
             }
             if ($parents[$level] != $sco->parent) {
-                if ($newlevel = array_search($sco->parent,$parents)) {
+                $newlevel = array_search($sco->parent,$parents);
+                if ($newlevel !== false) {
                     for ($i=0; $i<($level-$newlevel); $i++) {
                         $result->toc .= "\t\t</li></ul></li>\n";
                     }
index ef37f94..16080c0 100644 (file)
@@ -28,6 +28,7 @@
 #page-mod-scorm-player.pagelayout-popup #page-content .region-content {padding: 0px; }
 #page-mod-scorm-player.pagelayout-popup #page-wrapper {width:100%;}
 #page-mod-scorm-player .yui-layout-scroll div.yui-layout-bd {overflow:visible;}
+#page-mod-scorm-player .yui-layout-unit-left div.yui-layout-bd {overflow:auto;}
 
 .path-mod-scorm.forcejavascript .scorm-center { display:none;}
 .path-mod-scorm.forcejavascript .toc { display:none;}
index 3a10f28..10c6ef8 100644 (file)
@@ -29,6 +29,10 @@ function xmldb_survey_upgrade($oldversion) {
     // Moodle v2.2.0 release upgrade line
     // Put any upgrade step following this
 
+    // Moodle v2.3.0 release upgrade line
+    // Put any upgrade step following this
+
+
     return true;
 }
 
index 6eb9551..cfb421a 100644 (file)
@@ -109,7 +109,7 @@ $completion->set_module_viewed($cm);
         } else {
 
             echo $OUTPUT->box(format_module_intro('survey', $survey, $cm->id), 'generalbox', 'intro');
-            echo $OUTPUT->spacer(array('height'=>30, 'width'=>1, 'br'=>true)); // should be done with CSS instead
+            echo $OUTPUT->spacer(array('height'=>30, 'width'=>1), true);  // should be done with CSS instead
 
             $questions = $DB->get_records_list("survey_questions", "id", explode(',', $survey->questions));
             $questionorder = explode(",", $survey->questions);
@@ -122,7 +122,7 @@ $completion->set_module_viewed($cm);
                         $table->align = array ("left");
                         $table->data[] = array(s($answer->answer1));//no html here, just plain text
                         echo html_writer::table($table);
-                        echo $OUTPUT->spacer(clone($spacer)) . '<br />';
+                        echo $OUTPUT->spacer(array('height'=>30, 'width'=>1), true);
                     }
                 }
             }
index 88e0ba0..5449ecb 100644 (file)
@@ -55,5 +55,9 @@ function xmldb_url_upgrade($oldversion) {
     // Moodle v2.2.0 release upgrade line
     // Put any upgrade step following this
 
+    // Moodle v2.3.0 release upgrade line
+    // Put any upgrade step following this
+
+
     return true;
 }
index c8ac218..9925711 100644 (file)
@@ -45,5 +45,9 @@ function xmldb_wiki_upgrade($oldversion) {
     // Moodle v2.2.0 release upgrade line
     // Put any upgrade step following this
 
+    // Moodle v2.3.0 release upgrade line
+    // Put any upgrade step following this
+
+
     return true;
 }
index 4815ba3..9781d7b 100644 (file)
@@ -195,6 +195,7 @@ $string['searchcontent'] = 'Search in page content';
 $string['searchresult'] = 'Search results:';
 $string['searchwikis'] = 'Search wikis';
 $string['special'] = 'Special';
+$string['tableofcontents'] = 'Table of contents';
 $string['tagsdeleted'] = 'Wiki tags have been deleted';
 $string['tagtitle'] = 'See the "{$a}" tag';
 $string['teacherrating'] = 'Teacher rating';
index 30976db..cf7a2b3 100644 (file)
@@ -239,7 +239,7 @@ abstract class wiki_markup_parser extends generic_parser {
             $i++;
         }
 
-        $this->returnvalues['toc'] = "<div class=\"wiki-toc\"><p class=\"wiki-toc-title\">Table of contents</p>$toc</div>";
+        $this->returnvalues['toc'] = "<div class=\"wiki-toc\"><p class=\"wiki-toc-title\">" . get_string('tableofcontents', 'wiki') . "</p>$toc</div>";
     }
 
     /**
index 6f848b9..061d599 100644 (file)
@@ -87,5 +87,9 @@ function xmldb_workshop_upgrade($oldversion) {
         upgrade_mod_savepoint(true, 2012041701, 'workshop');
     }
 
+    // Moodle v2.3.0 release upgrade line
+    // Put any upgrade step following this
+
+
     return true;
 }
index 5ff3a28..fd8065d 100644 (file)
@@ -38,5 +38,9 @@ function xmldb_workshopform_accumulative_upgrade($oldversion) {
     // Moodle v2.2.0 release upgrade line
     // Put any upgrade step following this
 
+    // Moodle v2.3.0 release upgrade line
+    // Put any upgrade step following this
+
+
     return true;
 }
index 07100d5..a369ae9 100644 (file)
@@ -38,5 +38,9 @@ function xmldb_workshopform_comments_upgrade($oldversion) {
     // Moodle v2.2.0 release upgrade line
     // Put any upgrade step following this
 
+    // Moodle v2.3.0 release upgrade line
+    // Put any upgrade step following this
+
+
     return true;
 }
index 3da3066..459abbb 100644 (file)
@@ -38,5 +38,9 @@ function xmldb_workshopform_numerrors_upgrade($oldversion) {
     // Moodle v2.2.0 release upgrade line
     // Put any upgrade step following this
 
+    // Moodle v2.3.0 release upgrade line
+    // Put any upgrade step following this
+
+
     return true;
 }
index 62927bf..968f8e5 100644 (file)
@@ -38,5 +38,9 @@ function xmldb_workshopform_rubric_upgrade($oldversion) {
     // Moodle v2.2.0 release upgrade line
     // Put any upgrade step following this
 
+    // Moodle v2.3.0 release upgrade line
+    // Put any upgrade step following this
+
+
     return true;
 }
index 01420b5..39164bf 100644 (file)
@@ -39,6 +39,10 @@ function xmldb_portfolio_googledocs_upgrade($oldversion) {
         upgrade_plugin_savepoint(true, 2012053001, 'portfolio', 'googledocs');
     }
 
+    // Moodle v2.3.0 release upgrade line
+    // Put any upgrade step following this
+
+
     return true;
 }
 
index 38df9d5..cb1eeb7 100644 (file)
@@ -39,6 +39,10 @@ function xmldb_portfolio_picasa_upgrade($oldversion) {
         upgrade_plugin_savepoint(true, 2012053001, 'portfolio', 'picasa');
     }
 
+    // Moodle v2.3.0 release upgrade line
+    // Put any upgrade step following this
+
+
     return true;
 }
 
index 2e3e3e2..0ccdbce 100644 (file)
@@ -539,7 +539,10 @@ class qformat_default {
         if (is_readable($filename)) {
             $filearray = file($filename);
 
-            /// Check for Macintosh OS line returns (ie file on one line), and fix
+            // If the first line of the file starts with a UTF-8 BOM, remove it.
+            $filearray[0] = textlib::trim_utf8_bom($filearray[0]);
+
+            // Check for Macintosh OS line returns (ie file on one line), and fix.
             if (preg_match("~\r~", $filearray[0]) AND !preg_match("~\n~", $filearray[0])) {
                 return explode("\r", $filearray[0]);
             } else {
index f141e02..3d7bc0c 100644 (file)
@@ -40,6 +40,10 @@ function xmldb_qtype_calculated_upgrade($oldversion) {
     // Moodle v2.2.0 release upgrade line
     // Put any upgrade step following this
 
+    // Moodle v2.3.0 release upgrade line
+    // Put any upgrade step following this
+
+
     return true;
 }
 
index 6d60323..0441751 100644 (file)
@@ -90,6 +90,10 @@ function xmldb_qtype_essay_upgrade($oldversion) {
         upgrade_plugin_savepoint(true, 2011102702, 'qtype', 'essay');
     }
 
+    // Moodle v2.3.0 release upgrade line
+    // Put any upgrade step following this
+
+
     return true;
 }
 
index 6277068..b99732c 100644 (file)
@@ -40,5 +40,9 @@ function xmldb_qtype_match_upgrade($oldversion) {
     // Moodle v2.2.0 release upgrade line
     // Put any upgrade step following this
 
+    // Moodle v2.3.0 release upgrade line
+    // Put any upgrade step following this
+
+
     return true;
 }
index 8c7e04e..a83470f 100644 (file)
@@ -40,5 +40,9 @@ function xmldb_qtype_multianswer_upgrade($oldversion) {
     // Moodle v2.2.0 release upgrade line
     // Put any upgrade step following this
 
+    // Moodle v2.3.0 release upgrade line
+    // Put any upgrade step following this
+
+
     return true;
 }
index 41b56bf..48b658f 100644 (file)
@@ -40,5 +40,9 @@ function xmldb_qtype_multichoice_upgrade($oldversion) {
     // Moodle v2.2.0 release upgrade line
     // Put any upgrade step following this
 
+    // Moodle v2.3.0 release upgrade line
+    // Put any upgrade step following this
+
+
     return true;
 }
index 43db9a6..3336f4d 100644 (file)
@@ -37,5 +37,9 @@ function xmldb_qtype_numerical_upgrade($oldversion) {
     $dbman = $DB->get_manager();
 
 
+    // Moodle v2.3.0 release upgrade line
+    // Put any upgrade step following this
+
+
     return true;
 }
index 80a77a6..7c78301 100644 (file)
@@ -42,6 +42,10 @@ function xmldb_repository_googledocs_upgrade($oldversion) {
         upgrade_plugin_savepoint(true, 2012053000, 'repository', 'googledocs');
     }
 
+    // Moodle v2.3.0 release upgrade line
+    // Put any upgrade step following this
+
+
     return true;
 }
 
index 1cd2f2a..3d50bba 100644 (file)
@@ -42,6 +42,10 @@ function xmldb_repository_picasa_upgrade($oldversion) {
         upgrade_plugin_savepoint(true, 2012053000, 'repository', 'picasa');
     }
 
+    // Moodle v2.3.0 release upgrade line
+    // Put any upgrade step following this
+
+
     return true;
 }
 
index 86d0446..9285edc 100644 (file)
@@ -252,8 +252,8 @@ a.ygtvspacer:hover {color: transparent;text-decoration: none;}
 
 .file-picker.fp-select .uneditable {display:none;}
 .file-picker.fp-select .fp-select-loading {display:none;}
-.file-picker .fp-select.loading .fp-select-loading {display:block;}
-.file-picker .fp-select.loading form {display:none;}
+.file-picker.fp-select.loading .fp-select-loading {display:block;}
+.file-picker.fp-select.loading form {display:none;}
 
  /*
  * File Manager
index aeb58d2..fccbb15 100644 (file)
@@ -76,5 +76,9 @@ function xmldb_theme_formal_white_upgrade($oldversion) {
         upgrade_plugin_savepoint(true, 2012051503, 'theme', 'formal_white');
     }
 
+    // Moodle v2.3.0 release upgrade line
+    // Put any upgrade step following this
+
+
     return true;
 }
\ No newline at end of file
index f9bca28..c428ce5 100644 (file)
@@ -33,10 +33,10 @@ $THEME->sheets = array(
     'pagelayout',
     'core',
     'menus',
-    'red',
-    'green',
-    'blue',
     'orange',
+    'blue',
+    'green',
+    'red',
     'settings',
 );
 
@@ -53,48 +53,57 @@ $THEME->layouts = array(
     'standard' => array(
         'file' => 'general.php',
         'regions' => array('side-pre', 'side-post'),
-        'defaultregion' => 'side-pre'
+        'defaultregion' => 'side-pre',
+        'options' => array('langmenu'=>true),
     ),
     // Course page
     'course' => array(
         'file' => 'general.php',
         'regions' => array('side-pre', 'side-post'),
-        'defaultregion' => 'side-pre'
+        'defaultregion' => 'side-pre',
+        'options' => array('langmenu'=>true),
     ),
     // Course page
     'coursecategory' => array(
         'file' => 'general.php',
         'regions' => array('side-pre', 'side-post'),
-        'defaultregion' => 'side-pre'
+        'defaultregion' => 'side-pre',
+        'options' => array('langmenu'=>true),
     ),
     'incourse' => array(
         'file' => 'general.php',
         'regions' => array('side-pre', 'side-post'),
-        'defaultregion' => 'side-pre'
+        'defaultregion' => 'side-pre',
+        'options' => array('langmenu'=>true),
     ),
     'frontpage' => array(
         'file' => 'general.php',
         'regions' => array('side-pre', 'side-post'),
-        'defaultregion' => 'side-pre'
+        'defaultregion' => 'side-pre',
+        'options' => array('langmenu'=>true),
     ),
     'admin' => array(
         'file' => 'general.php',
         'regions' => array('side-pre'),
-        'defaultregion' => 'side-pre'
+        'defaultregion' => 'side-pre',
+        'options' => array('langmenu'=>true),
     ),
     'mydashboard' => array(
         'file' => 'general.php',
         'regions' => array('side-pre', 'side-post'),
-        'defaultregion' => 'side-pre'
+        'defaultregion' => 'side-pre',
+        'options' => array('langmenu'=>true),
     ),
     'mypublic' => array(
         'file' => 'general.php',
         'regions' => array('side-pre', 'side-post'),
-        'defaultregion' => 'side-pre'
+        'defaultregion' => 'side-pre',
+        'options' => array('langmenu'=>true),
     ),
     'login' => array(
         'file' => 'general.php',
-        'regions' => array()
+        'regions' => array(),
+        'options' => array('langmenu'=>true),
     ),
     // Pages that appear in pop-up windows - no navigation, no blocks, no header.
     'popup' => array(
@@ -137,8 +146,11 @@ $THEME->layouts = array(
     'report' => array(
         'file' => 'report.php',
         'regions' => array('side-pre'),
-        'defaultregion' => 'side-pre'
+        'defaultregion' => 'side-pre',
+        'options' => array('langmenu'=>true),
     ),
 );
 
 $THEME->csspostprocess = 'splash_process_css';
+
+$THEME->javascripts = array('colourswitcher');
diff --git a/theme/splash/javascript/colourswitcher.js b/theme/splash/javascript/colourswitcher.js
new file mode 100644 (file)
index 0000000..578f96b
--- /dev/null
@@ -0,0 +1,63 @@
+YUI.add('moodle-theme_splash-colourswitcher', function(Y) {
+
+// Available colours
+var COLOURS = ['red','green','blue','orange'];
+
+/**
+ * Splash theme colour switcher class.
+ * Initialise this class by calling M.theme_splash.init
+ */
+var ColourSwitcher = function() {
+    ColourSwitcher.superclass.constructor.apply(this, arguments);
+};
+ColourSwitcher.prototype = {
+    /**
+     * Constructor for this class
+     * @param {object} config
+     */
+    initializer : function(config) {
+        var i, c;
+        // Attach events to the links to change colours so we can do it with
+        // JavaScript without refreshing the page
+        for (i in COLOURS) {
+            c = COLOURS[i];
+            // Check if this is the current colour
+            if (Y.one(document.body).hasClass('splash-'+c)) {
+                this.set('colour', c);
+            }
+            Y.all(config.div+' .colour-'+c).on('click', this.setColour, this, c);
+        }
+    },
+    /**
+     * Sets the colour being used for the splash theme
+     * @param {Y.Event} e The event that fired
+     * @param {string} colour The new colour
+     */
+    setColour : function(e, colour) {
+        // Prevent the event from refreshing the page
+        e.preventDefault();
+        // Switch over the CSS classes on the body
+        Y.one(document.body).replaceClass('splash-'+this.get('colour'), 'splash-'+colour);
+        // Update the current colour
+        this.set('colour', colour);
+        // Store the users selection (Uses AJAX to save to the database)
+        M.util.set_user_preference('theme_splash_chosen_colour', colour);
+    }
+};
+// Make the colour switcher a fully fledged YUI module
+Y.extend(ColourSwitcher, Y.Base, ColourSwitcher.prototype, {
+    NAME : 'Splash theme colour switcher',
+    ATTRS : {
+        colour : {
+            value : 'red'
+        }
+    }
+});
+// Our splash theme namespace
+M.theme_splash = M.theme_splash || {};
+// Initialisation function for the colour switcher
+M.theme_splash.initColourSwitcher = function(cfg) {
+    return new ColourSwitcher(cfg);
+}
+
+}, '@VERSION@', {requires:['base','node']});
index 4763983..3def7ed 100644 (file)
@@ -107,7 +107,12 @@ echo $OUTPUT->doctype() ?>
         alt="orange" /></a></li>
         </ul>
         </div>
-        <?php echo $OUTPUT->lang_menu();?>
+        <?php
+        if (!empty($PAGE->layout_options['langmenu'])) {
+            echo $OUTPUT->lang_menu();
+        }
+            echo $PAGE->headingmenu
+        ?>
         </div>
         <div id="logobox">
         <?php
index 2602e64..10d7390 100644 (file)
@@ -107,7 +107,12 @@ echo $OUTPUT->doctype() ?>
         alt="orange" /></a></li>
         </ul>
         </div>
-        <?php echo $OUTPUT->lang_menu();?>
+        <?php
+        if (!empty($PAGE->layout_options['langmenu'])) {
+            echo $OUTPUT->lang_menu();
+        }
+        echo $PAGE->headingmenu
+        ?>
         </div>
         <div id="logobox">
         <?php
index 191ec32..f9f1fb6 100644 (file)
@@ -90,12 +90,14 @@ function splash_set_customcss($css, $customcss) {
 /**
  * Adds the JavaScript for the colour switcher to the page.
  *
+ * The colour switcher is a YUI moodle module that is located in
+ *     theme/splash/yui/splash/splash.js
+ *
  * @param moodle_page $page
  */
 function splash_initialise_colourswitcher(moodle_page $page) {
     user_preference_allow_ajax_update('theme_splash_chosen_colour', PARAM_ALPHA);
-    $page->requires->yui_module('moodle-theme_splash-colourswitcher',
-     'M.theme_splash.initColourSwitcher', array(array('div'=>'#colourswitcher')));
+    $page->requires->yui_module('moodle-theme_splash-colourswitcher', 'M.theme_splash.initColourSwitcher', array(array('div'=>'#colourswitcher')));
 }
 
 /**
index bfb4f6e..eca577c 100644 (file)
@@ -199,7 +199,6 @@ p.prolog a:link {
     margin:10px 0 0 15px;
 }
 .logininfo{
-    background:url([[pix:theme|loginicon]]) left no-repeat;
     color:#fff;
     margin:0;
     padding:10px 10px 10px 40px;
@@ -213,7 +212,7 @@ p.prolog a:link {
 }
 #headermenu .langmenu{
     position:relative;
-    top:35px;
+    top:30px;
     width:210px;
 }
 a,
index ca52ed3..b3cedb2 100644 (file)
@@ -181,7 +181,8 @@ if ($usernew = $userform->get_data()) {
     $email_changed_html = '';
 
     if ($CFG->emailchangeconfirmation) {
-        // Handle change of email carefully for non-trusted users
+        // Users with 'moodle/user:update' can change their email address immediately
+        // Other users require a confirmation email
         if (isset($usernew->email) and $user->email != $usernew->email && !has_capability('moodle/user:update', $systemcontext)) {
             $a = new stdClass();
             $a->newemail = $usernew->preference_newemail = $usernew->email;
@@ -235,7 +236,7 @@ if ($usernew = $userform->get_data()) {
     // save custom profile fields data
     profile_save_data($usernew);
 
-    // If email was changed, send confirmation email now
+    // If email was changed and confirmation is required, send confirmation email now
     if ($email_changed && $CFG->emailchangeconfirmation) {
         $temp_user = fullclone($user);
         $temp_user->email = $usernew->preference_newemail;
@@ -249,7 +250,8 @@ if ($usernew = $userform->get_data()) {
         $emailupdatetitle = get_string('emailupdatetitle', 'auth', $a);
 
         //email confirmation directly rather than using messaging so they will definitely get an email
-        if (!$mail_results = email_to_user($temp_user, get_admin(), $emailupdatetitle, $emailupdatemessage)) {
+        $supportuser = generate_email_supportuser();
+        if (!$mail_results = email_to_user($temp_user, $supportuser, $emailupdatetitle, $emailupdatemessage)) {
             die("could not send email!");
         }
     }
index 0a9d706..728ef4d 100644 (file)
@@ -34,7 +34,7 @@ $version  = 2012062500.01;              // 2012062500    = branching date YYYYMM
                                         //         RR    = release increments - 00 in DEV branches
                                         //           .XX = incremental changes
 
-$release  = '2.3 (Build: 20120625)';    // Human-friendly version name
+$release  = '2.3+ (Build: 20120701)';   // Human-friendly version name
 
 $branch   = '23';                       // this version's branch
 $maturity = MATURITY_STABLE;            // this version's maturity level
diff --git a/webservice/tests/helpers.php b/webservice/tests/helpers.php
new file mode 100644 (file)
index 0000000..161a1b7
--- /dev/null
@@ -0,0 +1,82 @@
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * This file contains helper classes for testing the web service and external files.
+ *
+ * @package    core_webservice
+ * @copyright  2012 Jerome Mouneyrac
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+/**
+ * Helper base class for external tests. Helpfull to test capabilities.
+ *
+ * @package    core_webservice
+ * @copyright  2012 Jerome Mouneyrac
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+abstract class externallib_advanced_testcase extends advanced_testcase {
+
+    /**
+     * Assign a capability to $USER
+     * The function creates a student $USER if $USER->id is empty
+     *
+     * @param string $capability capability name
+     * @param int $contextid
+     * @param int $roleid
+     * @return int the role id - mainly returned for creation, so calling function can reuse it
+     */
+    public static function assignUserCapability($capability, $contextid, $roleid = null) {
+        global $USER;
+
+        // Create a new student $USER if $USER doesn't exist
+        if (empty($USER->id)) {
+            $user  = self::getDataGenerator()->create_user();
+            self::setUser($user);
+        }
+
+        if (empty($roleid)) {
+            $roleid = create_role('Dummy role', 'dummyrole', 'dummy role description');
+        }
+
+        assign_capability($capability, CAP_ALLOW, $roleid, $contextid);
+
+        role_assign($roleid, $USER->id, $contextid);
+
+        accesslib_clear_all_caches_for_unit_testing();
+
+        return $roleid;
+    }
+
+    /**
+     * Unassign a capability to $USER
+     *
+     * @param string $capability capability name
+     * @param int $contextid
+     * @param int $roleid
+     */
+    public static function unassignUserCapability($capability, $contextid, $roleid) {
+        global $USER;
+
+        unassign_capability($capability, $roleid, $contextid);
+
+        accesslib_clear_all_caches_for_unit_testing();
+    }
+}
+