MDL-24419 (5): Coding style cleanup
This commit is contained in:
@@ -97,7 +97,7 @@ class editsection_form extends moodleform {
|
||||
if ($completion->is_enabled()) {
|
||||
$completionoptions = array();
|
||||
$modinfo = get_fast_modinfo($course);
|
||||
foreach($modinfo->cms as $id => $cm) {
|
||||
foreach ($modinfo->cms as $id => $cm) {
|
||||
// Add each course-module if it:
|
||||
// (a) has completion turned on
|
||||
// (b) does not belong to current course-section
|
||||
@@ -124,7 +124,7 @@ class editsection_form extends moodleform {
|
||||
get_string('completioncondition', 'condition'), $grouparray);
|
||||
|
||||
$count = count($fullcs->conditionscompletion) + 1;
|
||||
$this->repeat_elements(array($group), $count,array(),
|
||||
$this->repeat_elements(array($group), $count, array(),
|
||||
'conditioncompletionrepeats', 'conditioncompletionadds', 2,
|
||||
get_string('addcompletions', 'condition'), true);
|
||||
$mform->addHelpButton('conditioncompletiongroup[0]',
|
||||
@@ -147,7 +147,7 @@ class editsection_form extends moodleform {
|
||||
|
||||
if ($completion->is_enabled()) {
|
||||
$num = 0;
|
||||
foreach($fullcs->conditionscompletion as $othercmid => $state) {
|
||||
foreach ($fullcs->conditionscompletion as $othercmid => $state) {
|
||||
$groupelements = $mform->getElement('conditioncompletiongroup[' . $num . ']')->getElements();
|
||||
$groupelements[0]->setValue($othercmid);
|
||||
$groupelements[1]->setValue($state);
|
||||
|
||||
+2
-2
@@ -213,7 +213,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
if (! $sections = $modinfo->get_section_info_all()) { // No sections found
|
||||
if (!$sections = $modinfo->get_section_info_all()) { // No sections found
|
||||
$section = new stdClass;
|
||||
$section->course = $course->id; // Create a default section.
|
||||
$section->section = 0;
|
||||
@@ -222,7 +222,7 @@
|
||||
$section->id = $DB->insert_record('course_sections', $section);
|
||||
rebuild_course_cache($course->id);
|
||||
$modinfo = get_fast_modinfo($COURSE);
|
||||
if (! $sections = $modinfo->get_section_info_all()) { // Try again
|
||||
if (!$sections = $modinfo->get_section_info_all()) { // Try again
|
||||
print_error('cannotcreateorfindstructs', 'error');
|
||||
}
|
||||
}
|
||||
|
||||
+16
-16
@@ -100,7 +100,7 @@ class condition_info extends condition_info_base {
|
||||
* Gets the course-module object with full necessary data to determine availability.
|
||||
* @return object Course-module object with full data
|
||||
* @throws coding_exception If data was not supplied when constructing object
|
||||
*/
|
||||
*/
|
||||
public function get_full_course_module() {
|
||||
return $this->get_full_item();
|
||||
}
|
||||
@@ -118,7 +118,7 @@ class condition_info extends condition_info_base {
|
||||
parent::update_from_form($ci, $fromform, $wipefirst);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Used in course/lib.php because we need to disable the completion JS if
|
||||
* a completion value affects a conditional activity.
|
||||
*
|
||||
@@ -138,7 +138,7 @@ class condition_info extends condition_info_base {
|
||||
|
||||
// Activities
|
||||
foreach ($modinfo->cms as $othercm) {
|
||||
foreach ($othercm->conditionscompletion as $cmid=>$expectedcompletion) {
|
||||
foreach ($othercm->conditionscompletion as $cmid => $expectedcompletion) {
|
||||
$CONDITIONLIB_PRIVATE->usedincondition[$course->id][$cmid] = true;
|
||||
}
|
||||
}
|
||||
@@ -203,7 +203,7 @@ class condition_info_section extends condition_info_base {
|
||||
* Gets the section object with full necessary data to determine availability.
|
||||
* @return object Section object with full data
|
||||
* @throws coding_exception If data was not supplied when constructing object
|
||||
*/
|
||||
*/
|
||||
public function get_full_section() {
|
||||
return $this->get_full_item();
|
||||
}
|
||||
@@ -272,7 +272,7 @@ class condition_info_section extends condition_info_base {
|
||||
}
|
||||
} else {
|
||||
// Request is for current user - use cache
|
||||
if(!array_key_exists($this->item->course, $CONDITIONLIB_PRIVATE->groupingscache)) {
|
||||
if( !array_key_exists($this->item->course, $CONDITIONLIB_PRIVATE->groupingscache)) {
|
||||
if (has_capability('moodle/site:accessallgroups', $context)) {
|
||||
$CONDITIONLIB_PRIVATE->groupingscache[$this->item->course] = true;
|
||||
} else {
|
||||
@@ -307,13 +307,13 @@ class condition_info_section extends condition_info_base {
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility function called by modedit.php; updates the
|
||||
* course_modules_availability table based on the module form data.
|
||||
*
|
||||
* @param object $section Section object, must at minimum contain id
|
||||
* @param object $fromform Data from form
|
||||
* @param bool $wipefirst If true, wipes existing conditions
|
||||
*/
|
||||
* Utility function called by modedit.php; updates the
|
||||
* course_modules_availability table based on the module form data.
|
||||
*
|
||||
* @param object $section Section object, must at minimum contain id
|
||||
* @param object $fromform Data from form
|
||||
* @param bool $wipefirst If true, wipes existing conditions
|
||||
*/
|
||||
public static function update_section_from_form($section, $fromform, $wipefirst=true) {
|
||||
$ci = new condition_info_section($section, CONDITION_MISSING_EVERYTHING);
|
||||
parent::update_from_form($ci, $fromform, $wipefirst);
|
||||
@@ -369,10 +369,10 @@ abstract class condition_info_base {
|
||||
throw new coding_exception('Invalid parameters; item ID not included');
|
||||
}
|
||||
|
||||
// DB table to store availability conditions
|
||||
// DB table to store availability conditions
|
||||
$this->availtable = $tableprefix . '_availability';
|
||||
|
||||
// name of module/section ID field in DB
|
||||
// Name of module/section ID field in DB
|
||||
$this->idfieldname = $idfield;
|
||||
|
||||
// If not loading data, don't do anything else
|
||||
@@ -887,7 +887,7 @@ abstract class condition_info_base {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Obtains a grade score. Note that this score should not be displayed to
|
||||
* the user, because gradebook rules might prohibit that. It may be a
|
||||
* non-final score subject to adjustment later.
|
||||
@@ -986,7 +986,7 @@ abstract class condition_info_base {
|
||||
* Initialises the global cache
|
||||
* @global stdClass $CONDITIONLIB_PRIVATE
|
||||
*/
|
||||
static function init_global_cache() {
|
||||
public static function init_global_cache() {
|
||||
global $CONDITIONLIB_PRIVATE;
|
||||
$CONDITIONLIB_PRIVATE = new stdClass;
|
||||
$CONDITIONLIB_PRIVATE->usedincondition = array();
|
||||
|
||||
+1
-1
@@ -588,7 +588,7 @@ function xmldb_main_upgrade($oldversion) {
|
||||
$dbman->create_table($table);
|
||||
}
|
||||
|
||||
/// Main savepoint reached
|
||||
// Main savepoint reached
|
||||
upgrade_main_savepoint(true, 2012051100.03);
|
||||
}
|
||||
|
||||
|
||||
+5
-5
@@ -200,10 +200,10 @@ class course_modinfo extends stdClass {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets data about specific numbered section.
|
||||
* @param int $sectionnumber Number (not id) of section
|
||||
* @return section_info Information for numbered section
|
||||
*/
|
||||
* Gets data about specific numbered section.
|
||||
* @param int $sectionnumber Number (not id) of section
|
||||
* @return section_info Information for numbered section
|
||||
*/
|
||||
public function get_section_info($sectionnumber) {
|
||||
return $this->sectioninfo[$sectionnumber];
|
||||
}
|
||||
@@ -1567,7 +1567,7 @@ class section_info extends stdClass {
|
||||
}
|
||||
|
||||
// Remove default data
|
||||
foreach(self::$sectioncachedefaults as $field => $value) {
|
||||
foreach (self::$sectioncachedefaults as $field => $value) {
|
||||
// Exact compare as strings to avoid problems if some strings are set
|
||||
// to "0" etc.
|
||||
if (isset($section->{$field}) && $section->{$field} === $value) {
|
||||
|
||||
@@ -113,23 +113,24 @@ class conditionlib_testcase extends advanced_testcase {
|
||||
/**
|
||||
* Same as above test but for course_sections instead of course_modules.
|
||||
*/
|
||||
function test_section_constructor() {
|
||||
public function test_section_constructor() {
|
||||
global $DB, $CFG;
|
||||
|
||||
// Test records
|
||||
$id = $DB->insert_record('course_sections',(object)array(
|
||||
$id = $DB->insert_record('course_sections', (object)array(
|
||||
'showavailability' => 1, 'availablefrom' => 17,
|
||||
'availableuntil' => 398, 'course' => 64, 'groupingid' => 13));
|
||||
|
||||
// no ID
|
||||
// No ID
|
||||
$section = new stdClass;
|
||||
try {
|
||||
$test = new condition_info_section($section);
|
||||
$this->fail();
|
||||
} catch(coding_exception $e) {
|
||||
} catch (coding_exception $e) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
// no other data
|
||||
// No other data
|
||||
$section->id = $id;
|
||||
$test = new condition_info_section($section, CONDITION_MISSING_EVERYTHING);
|
||||
$this->assertEquals(
|
||||
@@ -138,7 +139,7 @@ class conditionlib_testcase extends advanced_testcase {
|
||||
'conditionsgrade' => array(), 'conditionscompletion' => array()),
|
||||
$test->get_full_section());
|
||||
|
||||
// just the course_sections stuff; check it doesn't request that from db
|
||||
// Just the course_sections stuff; check it doesn't request that from db
|
||||
// (by using fake values and ensuring it still has those)
|
||||
$section->showavailability = 0;
|
||||
$section->availablefrom = 2;
|
||||
@@ -153,17 +154,17 @@ class conditionlib_testcase extends advanced_testcase {
|
||||
$test->get_full_section());
|
||||
|
||||
// Now let's add some actual grade/completion conditions
|
||||
$DB->insert_record('course_sections_availability',(object)array(
|
||||
$DB->insert_record('course_sections_availability', (object)array(
|
||||
'coursesectionid' => $id,
|
||||
'sourcecmid' => 42,
|
||||
'requiredcompletion' => 2
|
||||
));
|
||||
$DB->insert_record('course_sections_availability',(object)array(
|
||||
$DB->insert_record('course_sections_availability', (object)array(
|
||||
'coursesectionid' => $id,
|
||||
'sourcecmid' => 666,
|
||||
'requiredcompletion' => 1
|
||||
));
|
||||
$DB->insert_record('course_sections_availability',(object)array(
|
||||
$DB->insert_record('course_sections_availability', (object)array(
|
||||
'coursesectionid' => $id,
|
||||
'gradeitemid' => 37,
|
||||
'grademin' => 5.5
|
||||
@@ -179,8 +180,8 @@ class conditionlib_testcase extends advanced_testcase {
|
||||
|
||||
private function make_course() {
|
||||
global $DB;
|
||||
$categoryid = $DB->insert_record('course_categories',(object)array('name'=>'conditionlibtest'));
|
||||
$courseid = $DB->insert_record('course',(object)array(
|
||||
$categoryid = $DB->insert_record('course_categories', (object)array('name'=>'conditionlibtest'));
|
||||
$courseid = $DB->insert_record('course', (object)array(
|
||||
'fullname'=>'Condition test','shortname'=>'CT1',
|
||||
'category'=>$categoryid,'enablecompletion'=>1));
|
||||
context_course::instance($courseid);
|
||||
@@ -208,7 +209,7 @@ class conditionlib_testcase extends advanced_testcase {
|
||||
global $DB;
|
||||
$record = (object)array(
|
||||
'course' => $courseid,
|
||||
'sequence' => implode(',',$cmids),
|
||||
'sequence' => implode(',', $cmids),
|
||||
'section' => $sectionnum);
|
||||
foreach ($params as $name => $value) {
|
||||
$record->{$name} = $value;
|
||||
@@ -285,7 +286,7 @@ class conditionlib_testcase extends advanced_testcase {
|
||||
$modinfo->cms[$cmid2]->conditionsgrade);
|
||||
}
|
||||
|
||||
function test_section_modinfo() {
|
||||
public function test_section_modinfo() {
|
||||
global $DB;
|
||||
|
||||
// Let's make a course
|
||||
@@ -303,12 +304,12 @@ class conditionlib_testcase extends advanced_testcase {
|
||||
'courseid' => $courseid, 'itemname' => 'frog'));
|
||||
|
||||
// One of the sections has grade and completion conditions, other doesn't
|
||||
$DB->insert_record('course_sections_availability',(object)array(
|
||||
$DB->insert_record('course_sections_availability', (object)array(
|
||||
'coursesectionid' => $sectionid2,
|
||||
'sourcecmid' => $cmid,
|
||||
'requiredcompletion'=>1
|
||||
));
|
||||
$DB->insert_record('course_sections_availability',(object)array(
|
||||
$DB->insert_record('course_sections_availability', (object)array(
|
||||
'coursesectionid' => $sectionid2,
|
||||
'gradeitemid' => $gradeitemid,
|
||||
'grademin' => 5.5
|
||||
@@ -382,7 +383,7 @@ class conditionlib_testcase extends advanced_testcase {
|
||||
$this->assertEquals(array(),$cm->conditionsgrade);
|
||||
}
|
||||
|
||||
function test_section_add_and_remove() {
|
||||
public function test_section_add_and_remove() {
|
||||
global $DB;
|
||||
|
||||
// Make course and module
|
||||
@@ -560,7 +561,7 @@ class conditionlib_testcase extends advanced_testcase {
|
||||
$this->assertEquals(get_string('requires_grade_range','condition','frog'),$text);
|
||||
}
|
||||
|
||||
function test_section_is_available() {
|
||||
public function test_section_is_available() {
|
||||
global $DB, $USER;
|
||||
$courseid = $this->make_course();
|
||||
|
||||
@@ -600,7 +601,7 @@ class conditionlib_testcase extends advanced_testcase {
|
||||
$ci = new condition_info_section((object)array('id' => $sectionid),
|
||||
CONDITION_MISSING_EVERYTHING);
|
||||
$this->assertTrue($ci->is_available($text));
|
||||
$this->assertEquals('',$text);
|
||||
$this->assertEquals('', $text);
|
||||
$timetext = userdate($time, get_string('strftimedate', 'langconfig'));
|
||||
$this->assertRegExp('~' . preg_quote($timetext) . '~', $ci->get_full_information());
|
||||
|
||||
@@ -609,7 +610,7 @@ class conditionlib_testcase extends advanced_testcase {
|
||||
$ci = new condition_info_section((object)array('id' => $sectionid),
|
||||
CONDITION_MISSING_EVERYTHING);
|
||||
$this->assertFalse($ci->is_available($text));
|
||||
$this->assertEquals('',$text);
|
||||
$this->assertEquals('', $text);
|
||||
|
||||
// Completion: first set up cm
|
||||
$sectionid = $this->make_section($courseid, array(), 5);
|
||||
@@ -707,10 +708,10 @@ class conditionlib_testcase extends advanced_testcase {
|
||||
|
||||
// Grade: ...in a range that doesn't include it
|
||||
$ci->wipe_conditions();
|
||||
$ci->add_grade_condition($gradeitemid,4,5,true);
|
||||
$ci->add_grade_condition($gradeitemid, 4, 5, true);
|
||||
condition_info_section::wipe_session_cache();
|
||||
$this->assertFalse($ci->is_available($text));
|
||||
$this->assertEquals(get_string('requires_grade_range','condition','frog'),$text);
|
||||
$this->assertEquals(get_string('requires_grade_range', 'condition', 'frog'), $text);
|
||||
|
||||
// Grouping: Not member
|
||||
$groupingid = $this->make_grouping($courseid, 'Grouping');
|
||||
|
||||
Reference in New Issue
Block a user