Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

MDL-37792 Conditions: Interests condition offered but not implemented

  • Loading branch information...
commit 6fea7a5f0283f97e86884f7f9afb02e194fe687f 1 parent f29e62c
@sammarshallou sammarshallou authored
View
3  lib/conditionlib.php
@@ -613,7 +613,6 @@ public static function get_condition_user_fields() {
'email' => get_user_field_name('email'),
'city' => get_user_field_name('city'),
'country' => get_user_field_name('country'),
- 'interests' => get_user_field_name('interests'),
'url' => get_user_field_name('url'),
'icq' => get_user_field_name('icq'),
'skype' => get_user_field_name('skype'),
@@ -1297,7 +1296,7 @@ private function is_field_condition_met($operator, $uservalue, $value) {
* @param int $fieldid the user profile field id
* @return string the user value, or false if user does not have a user field value yet
*/
- private function get_cached_user_profile_field($userid, $fieldid) {
+ protected function get_cached_user_profile_field($userid, $fieldid) {
global $USER, $DB, $CFG;
if ($userid === 0) {
View
10 lib/db/upgrade.php
@@ -1660,5 +1660,15 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2013021902.00);
}
+ if ($oldversion < 2013022201.00) {
+ // Delete entries regarding invalid 'idnumber' option which breaks course.
+ $DB->delete_records('course_sections_avail_fields', array('userfield' => 'idnumber'));
+ $DB->delete_records('course_modules_avail_fields', array('userfield' => 'idnumber'));
+ // Clear course cache (will be rebuilt on first visit) in case of changes to these.
+ rebuild_course_cache(0, true);
+
+ upgrade_main_savepoint(true, 2013022201.00);
+ }
+
return true;
}
View
51 lib/tests/conditionlib_test.php
@@ -735,5 +735,56 @@ public function test_section_is_available() {
$this->assertFalse($ci->is_available($text, false, $USER->id + 1));
$this->assertFalse($ci->is_available($text, true, $USER->id + 1));
}
+
+ /**
+ * Tests user fields to ensure that the list of provided fields includes only
+ * fields which the equivalent function can be used to obtain the value of.
+ */
+ public function test_condition_user_fields() {
+ global $CFG, $DB, $USER;
+
+ // Set up basic data.
+ $courseid = $this->make_course();
+ $cmid = $this->make_course_module($courseid);
+ $ci = new condition_info_testwrapper(
+ (object)array('id' => $cmid), CONDITION_MISSING_EVERYTHING);
+
+ // Add a custom user profile field. Unfortunately there is no back-end
+ // API for adding profile fields without having an actual form and doing
+ // redirects and stuff! These are the default text field parameters.
+ require_once($CFG->dirroot . '/user/profile/lib.php');
+ $field = (object)array(
+ 'shortname' => 'myfield', 'name' => 'My field', 'required' => 0,
+ 'locked' => 0, 'forceunique' => 0, 'signup' => 0,
+ 'visible' => PROFILE_VISIBLE_ALL,
+ 'datatype' => 'text', 'description' => 'A field of mine',
+ 'descriptionformat' => FORMAT_HTML, 'defaultdata' => '',
+ 'defaultdataformat' => FORMAT_HTML, 'param1' => 30, 'param2' => 2048,
+ 'param3' => 0, 'param4' => '', 'param5' => '');
+ $customfieldid = $DB->insert_record('user_info_field', $field);
+
+ // Get list of condition user fields.
+ $fields = condition_info::get_condition_user_fields();
+
+ // Check custom field is included.
+ $this->assertEquals('My field', $fields[$customfieldid]);
+
+ // For all other fields, check it actually works to get data from them.
+ foreach ($fields as $fieldid => $name) {
+ // Not checking the result, just that it's possible to get it
+ // without error.
+ $ci->get_cached_user_profile_field($USER->id, $fieldid);
+ }
+ }
}
+
+/**
+ * Test wrapper used only to make protected functions public so they can be
+ * tested.
+ */
+class condition_info_testwrapper extends condition_info {
+ public function get_cached_user_profile_field($userid, $fieldid) {
+ return parent::get_cached_user_profile_field($userid, $fieldid);
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.