/** * ELIS(TM): Enterprise Learning Intelligence Suite * Copyright (C) 2008-2012 Remote Learner.net Inc http://www.remote-learner.net * * This program 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. * * This program 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 this program. If not, see <http://www.gnu.org/licenses/>. * * @package elis * @subpackage curriculummanagement * @author Remote-Learner.net Inc * @license http://www.gnu.org/copyleft/gpl.html GNU GPL * @copyright (C) 2008-2012 Remote Learner.net Inc http://www.remote-learner.net * */ function archive_install() { global $CFG; require_once $CFG->dirroot . '/curriculum/config.php'; require_once CURMAN_DIRLOCATION . '/lib/customfield.class.php'; // setup archive field $field = new field(); $field->shortname = '_elis_curriculum_archive'; $field->name = get_string('archive_field_name', 'crlm_archive'); $field->datatype = 'bool'; $category = new field_category(); $category->name = get_string('archive_category_name', 'crlm_archive'); $field = field::ensure_field_exists_for_context_level($field, 'curriculum', $category); // make sure 'manual' is an owner if (!isset($field->owners['manual'])) { $owner = new field_owner(); $owner->fieldid = $field->id; $owner->plugin = 'manual'; $owner->param_view_capability = ''; $owner->param_edit_capability = ''; $owner->param_control = 'menu'; $owner->param_options_source = ''; $owner->add(); } $owner_options = array('required' => 0, 'edit_capability' => '', 'view_capability' => '', 'control' => 'checkbox', 'columns' => 30, 'rows' => 10, 'maxlength' => 2048, 'help_file' => 'crlm_archive/archive_curriculum'); field_owner::ensure_field_owner_exists($field, 'manual', $owner_options); return true; }
/** * Method to create ELIS field & owner objects given test data array. * * @param array $inputarray The test data array with params to build elis field object & owner * input array format: * array('field' => array(fieldparam => fieldparam_value [,...]), * 'context' => contextlevel, * 'manual' => array(fieldowners_manual_param => fomp_value [,...]), * 'moodle_profile' => array(fieldowners_moodleprofile_param => fompp_value [,...]), * ) * @return object The ELIS field object created */ public function build_elis_field_data($inputarray) { $field = new field((object) $inputarray['field']); $field->save(); $fieldcontext = new field_contextlevel(); $fieldcontext->fieldid = $field->id; $fieldcontext->contextlevel = $inputarray['context']; $fieldcontext->save(); if (isset($inputarray['manual'])) { $manual = new field_owner(); $manual->fieldid = $field->id; $manual->plugin = 'manual'; foreach ($inputarray['manual'] as $key => $val) { $manual->{'param_' . $key} = $val; } $manual->save(); } if (isset($inputarray['moodle_profile'])) { $moodleprofile = new field_owner(); $moodleprofile->fieldid = $field->id; $moodleprofile->plugin = 'moodle_profile'; foreach ($inputarray['moodle_profile'] as $key => $val) { $moodleprofile->{$key} = $val; } $moodleprofile->save(); } $field->load(); // TDB. return $field; }
/** * ELIS(TM): Enterprise Learning Intelligence Suite * Copyright (C) 2008-2012 Remote Learner.net Inc http://www.remote-learner.net * * This program 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. * * This program 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 this program. If not, see <http://www.gnu.org/licenses/>. * * @package elis * @subpackage curriculummanagement * @author Remote-Learner.net Inc * @license http://www.gnu.org/copyleft/gpl.html GNU GPL * @copyright (C) 2008-2012 Remote Learner.net Inc http://www.remote-learner.net * */ function xmldb_crlm_cluster_themes_upgrade($oldversion = 0) { global $CFG, $THEME, $db; $result = true; if ($result && $oldversion < 2010080602) { require_once $CFG->dirroot . '/curriculum/lib/customfield.class.php'; require_once $CFG->dirroot . '/curriculum/plugins/cluster_classification/lib.php'; require_once $CFG->dirroot . '/curriculum/plugins/cluster_classification/clusterclassification.class.php'; //theme priority $theme_priority_field = new field(field::get_for_context_level_with_name('cluster', 'cluster_themepriority')); if (isset($theme_priority_field->owners['manual'])) { $theme_priority_owner = new field_owner($theme_priority_field->owners['manual']); $theme_priority_owner->param_help_file = 'crlm_cluster_themes/cluster_themepriority'; $theme_priority_owner->update(); } //theme selection $theme_field = new field(field::get_for_context_level_with_name('cluster', 'cluster_theme')); if (isset($theme_field->owners['manual'])) { $theme_owner = new field_owner($theme_field->owners['manual']); $theme_owner->param_help_file = 'crlm_cluster_themes/cluster_theme'; $theme_owner->update(); } } return $result; }
/** * ELIS(TM): Enterprise Learning Intelligence Suite * Copyright (C) 2008-2012 Remote Learner.net Inc http://www.remote-learner.net * * This program 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. * * This program 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 this program. If not, see <http://www.gnu.org/licenses/>. * * @package elis * @subpackage curriculummanagement * @author Remote-Learner.net Inc * @license http://www.gnu.org/copyleft/gpl.html GNU GPL * @copyright (C) 2008-2012 Remote Learner.net Inc http://www.remote-learner.net * */ function xmldb_crlm_cluster_classification_upgrade($oldversion = 0) { global $CFG, $THEME, $db; $result = true; if ($result && $oldversion < 2010080502) { /// Define table crlm_cluster_classification to be created $table = new XMLDBTable('crlm_cluster_classification'); /// Adding fields to table crlm_cluster_classification $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null); $table->addFieldInfo('shortname', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null); $table->addFieldInfo('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null); $table->addFieldInfo('params', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null); /// Adding keys to table crlm_cluster_classification $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id')); $table->addKeyInfo('shortname_idx', XMLDB_KEY_UNIQUE, array('shortname')); /// Launch create table for crlm_cluster_classification $result = $result && create_table($table); } if ($result && $oldversion < 2010080503) { require_once $CFG->dirroot . '/curriculum/lib/customfield.class.php'; require_once $CFG->dirroot . '/curriculum/plugins/cluster_classification/lib.php'; require_once $CFG->dirroot . '/curriculum/plugins/cluster_classification/clusterclassification.class.php'; $field = new field(field::get_for_context_level_with_name('cluster', CLUSTER_CLASSIFICATION_FIELD)); // make sure we're set as owner if (!isset($field->owners['cluster_classification'])) { $owner = new field_owner(); $owner->fieldid = $field->id; $owner->plugin = 'cluster_classification'; $owner->add(); } // make sure we have a default value set if (!field_data::get_for_context_and_field(NULL, $field)) { field_data::set_for_context_and_field(NULL, $field, 'regular'); } $default = new clusterclassification(); $default->shortname = 'regular'; $default->name = get_string('cluster', 'block_curr_admin'); $default->param_autoenrol_curricula = 1; $default->param_autoenrol_tracks = 1; $default->add(); } // make sure 'manual' is an owner if ($result && $oldversion < 2010080504) { require_once $CFG->dirroot . '/curriculum/lib/customfield.class.php'; require_once $CFG->dirroot . '/curriculum/plugins/cluster_classification/lib.php'; require_once $CFG->dirroot . '/curriculum/plugins/cluster_classification/clusterclassification.class.php'; $field = new field(field::get_for_context_level_with_name('cluster', CLUSTER_CLASSIFICATION_FIELD)); $owner = new field_owner(); $owner->fieldid = $field->id; $owner->plugin = 'manual'; $owner->param_view_capability = ''; $owner->param_edit_capability = 'moodle/user:update'; $owner->param_control = 'menu'; $owner->param_options_source = 'cluster_classifications'; $owner->add(); } return $result; }
/** * Sets up the fields necessary for enabling cluster theming * * @return boolean Returns true to indicate success */ function cluster_themes_install() { //retrieve the cluster context $cluster_context = context_level_base::get_custom_context_level('cluster', 'block_curr_admin'); //set up the cluster theme category $theme_category = new field_category(); $theme_category->name = get_string('cluster_theme_category', 'crlm_cluster_themes'); //set up the theme priority field $theme_priority_field = new field(); $theme_priority_field->shortname = 'cluster_themepriority'; $theme_priority_field->name = get_string('cluster_theme_priority', 'crlm_cluster_themes'); $theme_priority_field->datatype = 'int'; //set up the field and category $theme_priority_field = field::ensure_field_exists_for_context_level($theme_priority_field, $cluster_context, $theme_category); $owner_options = array('required' => 0, 'edit_capability' => '', 'view_capability' => '', 'control' => 'text', 'columns' => 30, 'rows' => 10, 'maxlength' => 2048, 'help_file' => 'crlm_cluster_themes/cluster_themepriority'); field_owner::ensure_field_owner_exists($theme_priority_field, 'manual', $owner_options); //set up the field for selecting the applicable theme $theme_field = new field(); $theme_field->shortname = 'cluster_theme'; $theme_field->name = get_string('cluster_theme', 'crlm_cluster_themes'); $theme_field->datatype = 'char'; //set up the field and category $theme_field = field::ensure_field_exists_for_context_level($theme_field, $cluster_context, $theme_category); $owner_options = array('control' => 'menu', 'options_source' => 'themes', 'required' => 0, 'edit_capability' => '', 'view_capability' => '', 'columns' => 30, 'rows' => 10, 'maxlength' => 2048, 'help_file' => 'crlm_cluster_themes/cluster_theme'); field_owner::ensure_field_owner_exists($theme_field, 'manual', $owner_options); return true; }
/** * Set up necessary data * * @param int $numfields The number of custom fields used in auto-association */ private function init_required_data($numfields = 1) { global $CFG, $DB; require_once $CFG->dirroot . '/local/elisprogram/lib/setup.php'; require_once elis::file('eliscore/fields/moodleprofile/custom_fields.php'); require_once elis::lib('data/customfield.class.php'); require_once elispm::file('accesslib.php'); require_once elispm::lib('data/userset.class.php'); require_once $CFG->dirroot . '/user/profile/definelib.php'; require_once $CFG->dirroot . '/user/profile/field/checkbox/define.class.php'; // Set up the category only once. $fieldcategory = new field_category(array('name' => 'testcategoryname')); $fieldcategory->save(); // Ste up the target userset only once. $userset = new userset(array('name' => 'testusersetname')); $userset->save(); for ($i = 1; $i <= $numfields; $i++) { // Custom field. $field = new field(array('categoryid' => $fieldcategory->id, 'shortname' => 'testfieldshortname' . $i, 'name' => 'testfieldname' . $i, 'datatype' => 'bool')); $field->save(); // Ensure manual field owner exists for syncing. field_owner::ensure_field_owner_exists($field, 'manual'); $ownerid = $DB->get_field(field_owner::TABLE, 'id', array('fieldid' => $field->id, 'plugin' => 'manual')); $owner = new field_owner($ownerid); $owner->param_control = 'checkbox'; $owner->save(); // Ensure moodle profile field owner exists. field_owner::ensure_field_owner_exists($field, 'moodle_profile'); $DB->execute("UPDATE {" . field_owner::TABLE . "} SET exclude = ?", array(pm_moodle_profile::sync_to_moodle)); // Field context level assocation. $fieldcontextlevel = new field_contextlevel(array('fieldid' => $field->id, 'contextlevel' => CONTEXT_ELIS_USER)); $fieldcontextlevel->save(); // The associated Moodle user profile field. $profiledefinecheckbox = new profile_define_checkbox(); $data = new stdClass(); $data->datatype = 'checkbox'; $data->categoryid = 99999; $data->shortname = 'testfieldshortname' . $i; $data->name = 'testfieldname' . $i; $profiledefinecheckbox->define_save($data); $mfield = $DB->get_record('user_info_field', array('shortname' => 'testfieldshortname' . $i)); // The "cluster-profile" association. $usersetprofile = new userset_profile(array('clusterid' => $userset->id, 'fieldid' => $mfield->id, 'value' => 1)); $usersetprofile->save(); } }
/** * Test sync-ing an ELIS User Profile field to a DELETED Moodle User Profile field */ public function test_syncpmuserfieldtodeletedmoodleprofilefield() { global $CFG, $DB; require_once $CFG->dirroot . '/user/profile/definelib.php'; $this->load_csv_data(); // Set PM Custom User field(s) to Sync to Moodle. $ctxlvl = CONTEXT_ELIS_USER; $fields = field::get_for_context_level($ctxlvl); foreach ($fields as $field) { $fieldobj = new field($field); if (!isset($fieldobj->owners['moodle_profile'])) { $fieldobj->owners['moodle_profile'] = new stdClass(); } $owner = new field_owner($fieldobj->owners['moodle_profile']); $owner->exclude = pm_moodle_profile::sync_from_moodle; $owner->save(); $fieldobj->save(); } // Read a record. $src = new user(103, null, array(), false, array()); $src->reset_custom_field_list(); // Modify the data. $src->firstname = 'Testuser'; $src->lastname = 'One'; $src->field_sometext = 'boo'; $src->field_sometextfrompm = 'bla'; $src->save(); // Delete some custom Moodle Profile field(s) to cause old error (pre ELIS-4499). $fields = field::get_for_context_level($ctxlvl); foreach ($fields as $field) { $fieldobj = new field($field); if ($moodlefield = $DB->get_record('user_info_field', array('shortname' => $fieldobj->shortname))) { profile_delete_field($moodlefield->id); } } // Run the library sync - throws errors not exceptions :(. $CFG->mnet_localhost_id = 1; // ??? $mu = cm_get_moodleuser(103); try { $result = pm_moodle_user_to_pm($mu); $this->assertTrue($result); } catch (Exception $ex) { $this->assertTrue(false, $ex->message); } }
/** * ELIS(TM): Enterprise Learning Intelligence Suite * Copyright (C) 2008-2012 Remote Learner.net Inc http://www.remote-learner.net * * This program 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. * * This program 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 this program. If not, see <http://www.gnu.org/licenses/>. * * @package elis * @subpackage curriculummanagement * @author Remote-Learner.net Inc * @license http://www.gnu.org/copyleft/gpl.html GNU GPL * @copyright (C) 2008-2012 Remote Learner.net Inc http://www.remote-learner.net * */ function pre_post_test_install() { global $CFG; require_once $CFG->dirroot . '/curriculum/config.php'; require_once CURMAN_DIRLOCATION . '/lib/customfield.class.php'; $course_ctx_lvl = context_level_base::get_custom_context_level('course', 'block_curr_admin'); // Pre-test field $field = new field(); $field->shortname = '_elis_course_pretest'; $field->name = get_string('pre_test_field_name', 'crlm_pre_post_test'); $field->datatype = 'char'; $category = new field_category(); $category->name = get_string('pre_post_test_category_name', 'crlm_pre_post_test'); $field = field::ensure_field_exists_for_context_level($field, 'course', $category); // make sure 'manual' is an owner if (!isset($field->owners['manual'])) { $owner = new field_owner(); $owner->fieldid = $field->id; $owner->plugin = 'manual'; $owner->param_view_capability = ''; $owner->param_edit_capability = ''; $owner->param_control = 'menu'; $owner->param_options_source = 'completion_elements'; $owner->add(); } // Post-test field $field = new field(); $field->shortname = '_elis_course_posttest'; $field->name = get_string('post_test_field_name', 'crlm_pre_post_test'); $field->datatype = 'char'; $category = new field_category(); $category->name = get_string('pre_post_test_category_name', 'crlm_pre_post_test'); $field = field::ensure_field_exists_for_context_level($field, 'course', $category); // make sure 'manual' is an owner if (!isset($field->owners['manual'])) { $owner = new field_owner(); $owner->fieldid = $field->id; $owner->plugin = 'manual'; $owner->param_view_capability = ''; $owner->param_edit_capability = ''; $owner->param_control = 'menu'; $owner->param_options_source = 'completion_elements'; $owner->add(); } return true; }
function cluster_classification_install() { global $CFG; require_once $CFG->dirroot . '/curriculum/config.php'; require_once CURMAN_DIRLOCATION . '/lib/customfield.class.php'; require_once CURMAN_DIRLOCATION . '/plugins/cluster_classification/clusterclassification.class.php'; $cluster_ctx_lvl = context_level_base::get_custom_context_level('cluster', 'block_curr_admin'); $field = new field(); $field->shortname = CLUSTER_CLASSIFICATION_FIELD; $field->name = get_string('classification_field_name', 'crlm_cluster_classification'); $field->datatype = 'char'; $category = new field_category(); $category->name = get_string('classification_category_name', 'crlm_cluster_classification'); $field = field::ensure_field_exists_for_context_level($field, 'cluster', $category); // make sure we're set as owner if (!isset($field->owners['cluster_classification'])) { $owner = new field_owner(); $owner->fieldid = $field->id; $owner->plugin = 'cluster_classification'; $owner->add(); } // make sure 'manual' is an owner if (!isset($field->owners['manual'])) { $owner = new field_owner(); $owner->fieldid = $field->id; $owner->plugin = 'manual'; $owner->param_view_capability = ''; $owner->param_edit_capability = 'moodle/user:update'; $owner->param_control = 'menu'; $owner->param_options_source = 'cluster_classifications'; $owner->add(); } // make sure we have a default value set if (!field_data::get_for_context_and_field(NULL, $field)) { field_data::set_for_context_and_field(NULL, $field, 'regular'); } $default = new clusterclassification(); $default->shortname = 'regular'; $default->name = get_string('cluster', 'block_curr_admin'); $default->param_autoenrol_curricula = 1; $default->param_autoenrol_tracks = 1; $default->add(); return true; }
/** * ELIS(TM): Enterprise Learning Intelligence Suite * Copyright (C) 2008-2012 Remote Learner.net Inc http://www.remote-learner.net * * This program 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. * * This program 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 this program. If not, see <http://www.gnu.org/licenses/>. * * @package elis * @subpackage curriculummanagement * @author Remote-Learner.net Inc * @license http://www.gnu.org/copyleft/gpl.html GNU GPL * @copyright (C) 2008-2012 Remote Learner.net Inc http://www.remote-learner.net * */ function xmldb_crlm_cluster_groups_upgrade($oldversion = 0) { global $CFG, $THEME, $db; $result = true; if ($result && $oldversion < 2010080602) { require_once $CFG->dirroot . '/curriculum/lib/customfield.class.php'; require_once $CFG->dirroot . '/curriculum/plugins/cluster_classification/lib.php'; require_once $CFG->dirroot . '/curriculum/plugins/cluster_classification/clusterclassification.class.php'; $field = new field(field::get_for_context_level_with_name('cluster', 'cluster_group')); if (isset($field->owners['manual'])) { $owner = new field_owner($field->owners['manual']); $owner->param_help_file = 'crlm_cluster_groups/cluster_groups'; $owner->update(); } } if ($result && $oldversion < 2010080603) { //retrieve the cluster context $context = context_level_base::get_custom_context_level('cluster', 'block_curr_admin'); //get the cluster classification category $category = new field_category(); $category->name = get_string('cluster_group_category', 'crlm_cluster_groups'); $field = new field(); $field->shortname = 'cluster_groupings'; $field->name = get_string('autoenrol_groupings', 'crlm_cluster_classification'); $field->datatype = 'bool'; $field = field::ensure_field_exists_for_context_level($field, $context, $category); $owner_options = array('required' => 0, 'edit_capability' => '', 'view_capability' => '', 'control' => 'checkbox', 'columns' => 30, 'rows' => 10, 'maxlength' => 2048, 'help_file' => 'crlm_cluster_groups/cluster_groupings'); field_owner::ensure_field_owner_exists($field, 'manual', $owner_options); } if ($result && $oldversion < 2010080604) { if ($field = new field(field::get_for_context_level_with_name('cluster', 'cluster_site_course_group'))) { $field->shortname = 'cluster_groupings'; $field->update(); } } return $result; }
/** * Install function for this plugin * * @return boolean true Returns true to satisfy install procedure */ function cluster_display_priority_install() { //context level at which we are creating the new field(s) $cluster_ctx_lvl = context_level_base::get_custom_context_level('cluster', 'block_curr_admin'); $field = new field(); $field->shortname = CLUSTER_DISPLAY_PRIORITY_FIELD; $field->name = get_string('display_priority_field_name', 'crlm_cluster_display_priority'); $field->datatype = 'int'; $category = new field_category(); $category->name = get_string('display_settings_category_name', 'crlm_cluster_display_priority'); $field = field::ensure_field_exists_for_context_level($field, 'cluster', $category); // make sure 'manual' is an owner if (!isset($field->owners['manual'])) { $owner = new field_owner(); $owner->fieldid = $field->id; $owner->plugin = 'manual'; $owner->param_view_capability = ''; $owner->param_edit_capability = ''; $owner->param_control = 'text'; $owner->param_options_source = 'cluster_display_priority'; $owner->add(); } return true; }
/** * Create the test custom profile field, category and owner * * @param string $contextlevelname The name of the custom context level to create the field at * @param string $datatype The string identifier of the data type to use * @param string $uitype The string identifier of the UI / control type to use * @param boolean $multivalued Set to true to make field multivalued, otherwise false * @param mixed $options Array of menu options, or null for none * @param int $maxlength The maximum data length, or null for none * @return int The id of the created field */ private function create_test_field($contextlevelname, $datatype, $uitype, $multivalued, $options, $maxlength, $inctime) { global $CFG; require_once $CFG->dirroot . '/local/elisprogram/lib/setup.php'; require_once elis::lib('data/customfield.class.php'); // Category. $fieldcategory = new field_category(array('name' => 'testcategoryname')); $fieldcategory->save(); // Category contextlevel. $contextlevel = \local_eliscore\context\helper::get_level_from_name($contextlevelname); $fieldcategorycontextlevel = new field_category_contextlevel(array('categoryid' => $fieldcategory->id, 'contextlevel' => $contextlevel)); $fieldcategorycontextlevel->save(); // Field. $field = new field(array('shortname' => 'testfieldshortname', 'name' => 'testfieldname', 'categoryid' => $fieldcategory->id, 'datatype' => $datatype)); if ($multivalued) { // Enable multivalued ability. $field->multivalued = true; } $field->save(); // Field contextlevel. $fieldcontextlevel = new field_contextlevel(array('fieldid' => $field->id, 'contextlevel' => $contextlevel)); $fieldcontextlevel->save(); // Field owner. $ownerdata = array('control' => $uitype); if ($options !== null) { // Set options. $ownerdata['options'] = implode("\n", $options); } if ($maxlength !== null) { // Set max length. $ownerdata['maxlength'] = $maxlength; } if ($inctime !== null) { $ownerdata['inctime'] = $inctime; } field_owner::ensure_field_owner_exists($field, 'manual', $ownerdata); return $field->id; }
/** * Creates the owner record corresponding to the supplied field if it does not already exist * * @param field $field The field to create the owner for * @param string $plugin The plugin used for the owner field * @param array $params Any additional parameters to pass to the owner record */ static function ensure_field_owner_exists($field, $plugin, $params = array()) { $owners = $field->owners; if (!empty($owners[$plugin])) { return; } $owner = new field_owner(); $owner->fieldid = $field->id; $owner->plugin = $plugin; $owner->params = serialize($params); $owner->add(); }
/** * Run all upgrade steps from before elis 2.6. * * @param int $oldversion The currently installed version of the old component. * @return bool Success/Failure. */ function elisprogram_usetclassify_pre26upgradesteps($oldversion) { global $CFG, $THEME, $DB; $dbman = $DB->get_manager(); $result = true; if ($oldversion < 2011071400) { // Rename field. $field = field::find(new field_filter('shortname', '_elis_cluster_classification')); if ($field->valid()) { $field = $field->current(); $field->shortname = USERSET_CLASSIFICATION_FIELD; if ($field->name == 'Cluster classification') { // Rhe field name hasn't been changed from the old default. $field->name = get_string('classification_field_name', 'elisprogram_usetclassify'); } $field->save(); $category = $field->category; if ($category->name == 'Cluster classification') { // The field name hasn't been changed from the old default. $category->name = get_string('classification_category_name', 'elisprogram_usetclassify'); $category->save(); } } upgrade_plugin_savepoint($result, 2011071400, 'pmplugins', 'userset_classification'); } if ($result && $oldversion < 2011101200) { $field = field::find(new field_filter('shortname', USERSET_CLASSIFICATION_FIELD)); if ($field->valid()) { $field = $field->current(); if ($owner = new field_owner(!isset($field->owners) || !isset($field->owners['manual']) ? false : $field->owners['manual'])) { $owner->fieldid = $field->id; $owner->plugin = 'manual'; //$owner->exclude = 0; // TBD $owner->param_help_file = 'elisprogram_usetclassify/cluster_classification'; $owner->save(); } } upgrade_plugin_savepoint($result, 2011101200, 'pmplugins', 'userset_classification'); } if ($result && $oldversion < 2011101800) { // Userset -> 'User Set'. $field = field::find(new field_filter('shortname', USERSET_CLASSIFICATION_FIELD)); if ($field->valid()) { $field = $field->current(); if (stripos($field->name, 'Userset') !== false) { $field->name = str_ireplace('Userset', 'User Set', $field->name); $field->save(); } $category = $field->category; if (stripos($category->name, 'Userset') !== false) { $category->name = str_ireplace('Userset', 'User Set', $category->name); $category->save(); } } upgrade_plugin_savepoint($result, 2011101800, 'pmplugins', 'userset_classification'); } if ($result && $oldversion < 2011110300) { // Make sure to rename the default classification name from "Cluster" to "User set". require_once elispm::file('plugins/usetclassify/usersetclassification.class.php'); // Make sure there are no custom fields with invalid categories. pm_fix_orphaned_fields(); $field = field::find(new field_filter('shortname', USERSET_CLASSIFICATION_FIELD)); if ($field->valid()) { $field = $field->current(); $category = $field->category; $default = usersetclassification::find(new field_filter('shortname', 'regular')); if ($default->valid()) { $default = $default->current(); $default->name = get_string('cluster', 'local_elisprogram'); $default->save(); } // Upgrade field owner data for the default User Set field. $field = field::ensure_field_exists_for_context_level($field, CONTEXT_ELIS_USERSET, $category); $owners = field_owner::find(new field_filter('fieldid', $field->id)); if ($owners->valid()) { foreach ($owners as $owner) { if ($owner->plugin == 'cluster_classification') { $owner->plugin = 'userset_classification'; $owner->save(); } else { if ($owner->plugin == 'manual') { $owner->param_options_source = 'userset_classifications'; $owner->param_help_file = 'elisprogram_usetclassify/cluster_classification'; $owner->save(); } } } } upgrade_plugin_savepoint($result, 2011110300, 'pmplugins', 'userset_classification'); } } return $result; }
/** * Test rlipexport_version1elis_extrafieldsetcustomfieldbase::get_columns() */ public function test_rlipexport_version1elis_extrafieldsetcustomfieldbase_getdata() { $this->load_csv_data(); // Create Fields. // Normal Field. $fieldid1 = $this->create_custom_field('testcf1', 0, true, CONTEXT_ELIS_USER); $this->create_field_mapping('testcustomfields', 'field_' . $fieldid1, ''); $this->create_field_data($fieldid1, 'option1'); // Second Normal Field. $fieldid2 = $this->create_custom_field('testcf2', 0, true, CONTEXT_ELIS_USER); $this->create_field_mapping('testcustomfields', 'field_' . $fieldid2, ''); $this->create_field_data($fieldid2, 'option2'); // Multivalued field with multiple values. $fieldid3 = $this->create_custom_field('testcf3', 1, true, CONTEXT_ELIS_USER); $this->create_field_mapping('testcustomfields', 'field_' . $fieldid3, ''); $this->create_field_data($fieldid3, array('option1', 'option2')); // Multivalued field with single value. $fieldid4 = $this->create_custom_field('testcf4', 1, true, CONTEXT_ELIS_USER); $this->create_field_mapping('testcustomfields', 'field_' . $fieldid4, ''); $this->create_field_data($fieldid4, array('option1')); // Historical multivalued field. $fieldid5 = $this->create_custom_field('testcf5', 1, true, CONTEXT_ELIS_USER); $this->create_field_mapping('testcustomfields', 'field_' . $fieldid5, ''); $this->create_field_data($fieldid5, array('option1', 'option2')); // Update field to not multivalued to create historical multivalue state. $field = new field($fieldid5); $field->load(); $field->multivalued = 0; $field->save(); // Datetime field. $fieldid6 = $this->create_custom_field('testcf6', 0, false, CONTEXT_ELIS_USER, 'datetime'); $this->create_field_mapping('testcustomfields', 'field_' . $fieldid6, ''); $this->create_field_data($fieldid6, mktime(0, 0, 0, 7, 24, 2012)); // Datetime with time field. $fieldid7 = $this->create_custom_field('testcf7', 0, false, CONTEXT_ELIS_USER, 'datetime'); $this->create_field_mapping('testcustomfields', 'field_' . $fieldid7, ''); $this->create_field_data($fieldid7, mktime(10, 20, 30, 7, 24, 2012)); $field = new field($fieldid7); $field->load(); $fieldowner = new field_owner($field->owners['manual']->id); $fieldowner->load(); $fieldowner->param_inctime = 1; $fieldowner->save(); // Fields with HTML. $fieldid8 = $this->create_custom_field('testcf8', 0, false, CONTEXT_ELIS_USER, 'text'); $this->create_field_mapping('testcustomfields', 'field_' . $fieldid8, ''); $this->create_field_data($fieldid8, '<b>Test Text One</b>'); $fieldid9 = $this->create_custom_field('testcf9', 0, false, CONTEXT_ELIS_USER, 'textarea'); $this->create_field_mapping('testcustomfields', 'field_' . $fieldid9, ''); $this->create_field_data($fieldid9, '<i>Test Text Two</i>'); // Mock database record. $record = new stdClass(); $record->userid = 200; $record->{'custom_field_' . $fieldid1} = 'option1'; $record->{'custom_field_' . $fieldid2} = 'option2'; $record->{'custom_field_' . $fieldid3} = ''; $record->{'custom_field_' . $fieldid4} = 'option1'; $record->{'custom_field_' . $fieldid5} = ''; $record->{'custom_field_' . $fieldid6} = mktime(0, 0, 0, 7, 24, 2012); $record->{'custom_field_' . $fieldid7} = mktime(10, 20, 30, 7, 24, 2012); $record->{'custom_field_' . $fieldid8} = '<b>Test Text One</b>'; $record->{'custom_field_' . $fieldid9} = '<i>Test Text Two</i>'; // Perform Test. $enabledfields = rlipexport_version1elis_extrafields::get_enabled_fields(); $fieldset = new rlipexport_version1elis_extrafieldset_testcustomfields($enabledfields['testcustomfields']); $data = $fieldset->get_data($record); // Verify Result. $expecteddata = array('field_' . $fieldid1 => 'option1', 'field_' . $fieldid2 => 'option2', 'field_' . $fieldid3 => 'option1 / option2', 'field_' . $fieldid4 => 'option1', 'field_' . $fieldid5 => 'option1', 'field_' . $fieldid6 => 'Jul/24/2012', 'field_' . $fieldid7 => 'Jul/24/2012:10:20', 'field_' . $fieldid8 => 'TEST TEXT ONE', 'field_' . $fieldid9 => '_Test Text Two_'); $this->assertEquals($expecteddata, $data); }
/** * Return a boolean to indicate whether or not this filter is displayed * depending upon whether any custom fields are found for this user * @param string $field_type type of custom field to check * @return boolean true if the filter is to show */ function check_for_custom_fields($field_type) { // Get custom course fields by context level $context = context_level_base::get_custom_context_level($field_type, 'block_curr_admin'); $fields = field::get_for_context_level($context); $fields = $fields ? $fields : array(); $testfields = array(); foreach ($fields as $field) { //make sure the current user can access this field in at least one //course context $owners = field_owner::get_for_field($field); if (!block_php_report_field_accessible($owners)) { continue; } return true; } return false; }
/** * Set up data that is needed for testing * * @param boolean $setcustomfielddata Specify whether the userset's custom fields should be set * @param boolean $assignuser Specify whether the user should be directly assigned to the user set * @param boolean $setautoassociatefields Specity whether we should set up fields that allow userset autoassociation */ private function set_up_required_data($setcustomfielddata = true, $assignuser = true, $setautoassociatefields = false) { global $CFG, $DB; require_once $CFG->dirroot . '/local/elisprogram/lib/setup.php'; require_once elis::lib('data/customfield.class.php'); require_once elispm::file('accesslib.php'); require_once elispm::file('enrol/userset/moodleprofile/userset_profile.class.php'); require_once elispm::lib('data/clusterassignment.class.php'); require_once elispm::lib('data/user.class.php'); require_once elispm::lib('data/usermoodle.class.php'); require_once elispm::lib('data/userset.class.php'); $fieldcategoryid = $DB->get_field(field_category::TABLE, 'id', array('name' => 'Associated Group')); $this->assertNotEquals(false, $fieldcategoryid); $fieldcategory = new field_category($fieldcategoryid); $fieldcategory->load(); // Set up the test user. $user = new user(array('idnumber' => 'testuseridnumber', 'username' => 'testuserusername', 'firstname' => 'testuserfirstname', 'lastname' => 'testuserlastname', 'email' => '*****@*****.**', 'country' => 'CA')); $user->save(); $user->synchronize_moodle_user(); // We need a system-level role assignment. $roleid = create_role('systemrole', 'systemrole', 'systemrole'); $userid = $DB->get_field('user', 'id', array('username' => 'testuserusername')); $context = context_system::instance(); role_assign($roleid, $userid, $context->id); // Set up the userset. $userset = new userset(); $usersetdata = array('name' => 'testusersetname'); if ($setcustomfielddata) { $usersetdata['field_userset_group'] = 1; $usersetdata['field_userset_groupings'] = 1; } $userset->set_from_data((object) $usersetdata); $userset->save(); if ($setautoassociatefields) { // Set up a file we can use to auto-associate users to a userset. $field = new field(array('categoryid' => $fieldcategory->id, 'shortname' => 'autoassociate', 'name' => 'autoassociate', 'datatype' => 'bool')); $field->save(); // Ensure manual field owner exists for syncing. field_owner::ensure_field_owner_exists($field, 'manual'); $ownerid = $DB->get_field(field_owner::TABLE, 'id', array('fieldid' => $field->id, 'plugin' => 'manual')); $owner = new field_owner($ownerid); $owner->param_control = 'checkbox'; $owner->save(); field_owner::ensure_field_owner_exists($field, 'moodle_profile'); $DB->execute("UPDATE {" . field_owner::TABLE . "} SET exclude = ?", array(pm_moodle_profile::sync_to_moodle)); $fieldcontextlevel = new field_contextlevel(array('fieldid' => $field->id, 'contextlevel' => CONTEXT_ELIS_USER)); $fieldcontextlevel->save(); // The associated Moodle user profile field. require_once $CFG->dirroot . '/user/profile/definelib.php'; require_once $CFG->dirroot . '/user/profile/field/checkbox/define.class.php'; $profiledefinecheckbox = new profile_define_checkbox(); $data = new stdClass(); $data->datatype = 'checkbox'; $data->categoryid = 99999; $data->shortname = 'autoassociate'; $data->name = 'autoassociate'; $profiledefinecheckbox->define_save($data); $mfield = $DB->get_record('user_info_field', array('shortname' => 'autoassociate')); // The "cluster-profile" association. $usersetprofile = new userset_profile(array('clusterid' => $userset->id, 'fieldid' => $mfield->id, 'value' => 1)); $usersetprofile->save(); } if ($assignuser) { // Assign the user to the user set. $clusterassignment = new clusterassignment(array('clusterid' => $userset->id, 'userid' => $user->id, 'plugin' => 'manual')); $clusterassignment->save(); } }
private function create_test_field($name, $datatype, $control, $inctime, $maxlength, $options, $context) { $fieldcategory = new field_category(array('name' => 'testcategoryname')); $fieldcategory->save(); $field = new field(array('shortname' => $name, 'name' => $name, 'datatype' => $datatype, 'categoryid' => $fieldcategory->id)); $field->save(); $ownerdata = array('control' => $control); if ($options !== null) { $ownerdata['options'] = implode("\n", $options); } if ($maxlength !== null) { $ownerdata['maxlength'] = $maxlength; } if ($inctime !== null) { $ownerdata['inctime'] = $inctime; } // Associate fields to context levels. $fieldcontextlevel = new field_contextlevel(array('fieldid' => $field->id, 'contextlevel' => $context)); $fieldcontextlevel->save(); field_owner::ensure_field_owner_exists($field, 'manual', $ownerdata); return $field->id; }
/** * Run all upgrade steps from before elis 2.6. * * @param int $oldversion The currently installed version of the old component. * @return bool Success/Failure. */ function elisprogram_archive_pre26upgradesteps($oldversion) { $result = true; if ($result && $oldversion < 2011100700) { // rename field $field = field::find(new field_filter('shortname', '_elis_curriculum_archive')); if ($field->valid()) { $field = $field->current(); $field->shortname = ARCHIVE_FIELD; $field->name = get_string('archive_field_name', 'elisprogram_archive'); $field->save(); } upgrade_plugin_savepoint($result, 2011100700, 'pmplugins', 'archive'); } if ($result && $oldversion < 2011101200) { $field = field::find(new field_filter('shortname', ARCHIVE_FIELD)); if ($field->valid()) { $field = $field->current(); if ($owner = new field_owner(!isset($field->owners) || !isset($field->owners['manual']) ? false : $field->owners['manual'])) { $owner->fieldid = $field->id; $owner->plugin = 'manual'; //$owner->exclude = 0; // TBD $owner->param_help_file = 'elisprogram_archive/archive_program'; $owner->save(); } } upgrade_plugin_savepoint($result, 2011101200, 'pmplugins', 'archive'); } return $result; }
/** * moodle_profile_field_save_form_data - saves form specific sync settings for moodle profile fields * * @param object $form the custom field form object submitted * @param object $field the field object to save moodle_profile field_owner object for * @param object $data the submitted form data to save * @uses $DB */ function moodleprofile_field_save_form_data($form, $field, $data) { global $DB; $level = required_param('level', PARAM_ACTION); if ($level != 'user' || !isset($data->moodle_profile_exclusive)) { return; // not user context or sync was disabled } if ($data->moodle_profile_exclusive == pm_moodle_profile::sync_to_moodle || $data->moodle_profile_exclusive == pm_moodle_profile::sync_from_moodle) { if (isset($field->owners['moodle_profile'])) { $owner = new field_owner($field->owners['moodle_profile']); $owner->exclude = $data->moodle_profile_exclusive; } else { $owner = new field_owner(); $owner->fieldid = $field->id; $owner->plugin = 'moodle_profile'; $owner->exclude = $data->moodle_profile_exclusive; } $owner->save(); unset($field->owners); // force reload of owners field sync_profile_field_with_moodle($field); } else { $DB->delete_records(field_owner::TABLE, array('fieldid' => $field->id, 'plugin' => 'moodle_profile')); } }
/** * Run all upgrade steps from before elis 2.6. * * @param int $oldversion The currently installed version of the old component. * @return bool Success/Failure. */ function elisprogram_usetthemes_pre26upgradesteps($oldversion) { global $CFG, $THEME, $DB; $dbman = $DB->get_manager(); $result = true; if ($oldversion < 2011071300) { // Rename fields. $fieldnames = array('theme', 'themepriority'); foreach ($fieldnames as $fieldname) { $field = field::find(new field_filter('shortname', 'cluster_' . $fieldname)); if ($field->valid()) { $field = $field->current(); $field->shortname = '_elis_userset_' . $fieldname; $field->save(); } } upgrade_plugin_savepoint($result, 2011071300, 'pmplugins', 'userset_themes'); } if ($result && $oldversion < 2011101800) { // Userset -> 'User Set'. $fieldnames = array('theme', 'themepriority'); foreach ($fieldnames as $fieldname) { $fname = '_elis_userset_' . $fieldname; $field = field::find(new field_filter('shortname', $fname)); if ($field->valid()) { $field = $field->current(); // Add help file. if ($owner = new field_owner(!isset($field->owners) || !isset($field->owners['manual']) ? false : $field->owners['manual'])) { $owner->fieldid = $field->id; $owner->plugin = 'manual'; //$owner->exclude = 0; // TBD $owner->param_help_file = "elisprogram_usetthemes/{$fname}"; $owner->save(); } $category = $field->category; if (stripos($category->name, 'Userset') !== false) { $category->name = str_ireplace('Userset', 'User Set', $category->name); $category->save(); } } } upgrade_plugin_savepoint($result, 2011101800, 'pmplugins', 'userset_themes'); } if ($oldversion < 2013020400) { // Rename field if it is still 'Cluster Theme'. $field = field::find(new field_filter('shortname', '_elis_userset_theme')); if ($field->valid()) { $field = $field->current(); $category = $field->category; if ($category->name == 'Cluster Theme') { // The field name hasn't been changed from the old default. $category->name = get_string('userset_theme_category', 'elisprogram_usetthemes'); $category->save(); } } upgrade_plugin_savepoint($result, 2013020400, 'pmplugins', 'userset_themes'); } return $result; }
/** * Helper method for creating a custom field * * @param int $contextlevel The context level for which to create the field * @param string $uitype The input control / UI type * @param array $otherparams Other parameters to give to the field owner */ private function create_custom_field($contextlevel, $uitype, $otherparams) { global $CFG; require_once $CFG->dirroot . '/local/eliscore/lib/data/customfield.class.php'; // Category. $fieldcategory = new field_category(array('name' => 'testcategoryname')); $fieldcategory->save(); // Field. $field = new field(array('categoryid' => $fieldcategory->id, 'shortname' => 'testfieldshortname', 'name' => 'testfieldname', 'datatype' => 'text')); $field->save(); // Field-contextlevel. $fieldcontextlevel = new field_contextlevel(array('fieldid' => $field->id, 'contextlevel' => $contextlevel)); $fieldcontextlevel->save(); // Owner. $ownerparams = array_merge(array('control' => $uitype), $otherparams); field_owner::ensure_field_owner_exists($field, 'manual', $ownerparams); }
/** * Upgrade old ELIS tables. * * @param int $oldversion The old ELIS version. * @return bool Success/Failure. */ function local_elisprogram_upgrade_old_tables($oldversion) { global $DB, $CFG; $dbman = $DB->get_manager(); $result = true; if ($result && $oldversion < 2013031400) { // ELIS-8066: remove blank/empty menu options from custom field menu/checkbox and defaults using them. $customfields = $DB->get_recordset('local_eliscore_field', null, '', 'id'); foreach ($customfields as $id => $unused) { $field = new field($id); $field->load(); if (isset($field->owners['manual'])) { $manual = new field_owner($field->owners['manual']); $control = $manual->param_control; $options = $manual->param_options; if (!empty($options) && empty($manual->param_options_source) && ($control == 'menu' || $control == 'checkbox')) { $options = str_replace("\r", '', $options); // Strip CRs. $options = preg_replace("/\n+/", "\n", $options); $manual->param_options = rtrim($options, "\n"); $manual->save(); // Remove any empty defaults. $DB->delete_records_select($field->data_table(), "contextid IS NULL AND fieldid = ? AND data = ''", array($id)); } } } upgrade_plugin_savepoint($result, 2013031400, 'elis', 'program'); } // ELIS-7780: remove deprecated capabilites. if ($result && $oldversion < 2013041900) { $capstodelete = array('elis/program:viewgroupreports', 'elis/program:viewreports'); list($inorequal, $params) = $DB->get_in_or_equal($capstodelete); $where = "capability {$inorequal}"; $DB->delete_records_select('role_capabilities', $where, $params); $where = "name {$inorequal}"; $DB->delete_records_select('capabilities', $where, $params); upgrade_plugin_savepoint($result, 2013041900, 'elis', 'program'); } // Remove any duplicate user track records before attempting to apply an index. pm_fix_duplicate_usertrack_records('crlm_user_track'); if ($result && $oldversion < 2013042900) { // Add indexes to {crlm_user_track} table. $table = new xmldb_table('crlm_user_track'); if ($dbman->table_exists($table)) { // Array of indexes to drop. $dropindexes = array(new xmldb_index('any_userid_ix', XMLDB_INDEX_UNIQUE, array('userid')), new xmldb_index('any_trackid_ix', XMLDB_INDEX_UNIQUE, array('trackid')), new xmldb_index('any_userid_trackid_ix', XMLDB_INDEX_NOTUNIQUE, array('userid', 'trackid'))); foreach ($dropindexes as $index) { // Drop unwanted indexes if they exist. if ($dbman->index_exists($table, $index)) { $dbman->drop_index($table, $index); } } // Array of indexes to create. $createindexes = array(new xmldb_index('userid_ix', XMLDB_INDEX_NOTUNIQUE, array('userid')), new xmldb_index('trackid_ix', XMLDB_INDEX_NOTUNIQUE, array('trackid')), new xmldb_index('userid_trackid_ix', XMLDB_INDEX_UNIQUE, array('userid', 'trackid'))); foreach ($createindexes as $index) { // Create desired indexes as required. if (!$dbman->index_exists($table, $index)) { $dbman->add_index($table, $index); } } } upgrade_plugin_savepoint($result, 2013042900, 'elis', 'program'); } if ($result && $oldversion < 2013051500) { // Change results engine action min/max fields from integer to float. $table = new xmldb_table('crlm_results_action'); if ($dbman->table_exists($table)) { $field = new xmldb_field('minimum', XMLDB_TYPE_NUMBER, '10,5', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, 'actiontype'); $dbman->change_field_type($table, $field); $field = new xmldb_field('maximum', XMLDB_TYPE_NUMBER, '10,5', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, 'minimum'); $dbman->change_field_type($table, $field); } upgrade_plugin_savepoint($result, 2013051500, 'elis', 'program'); } if ($result && $oldversion < 2013051502) { // Define table crlm_certificate_settings to be created // Conditionally launch create table for crlm_certificate_settings. $table = new xmldb_table('crlm_certificate_settings'); if (!$dbman->table_exists($table)) { // Adding fields to table crlm_certificate_settings. $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('entity_id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); $table->add_field('entity_type', XMLDB_TYPE_CHAR, '9', null, XMLDB_NOTNULL, null, null); $table->add_field('cert_border', XMLDB_TYPE_CHAR, '200', null, XMLDB_NOTNULL, null, null); $table->add_field('cert_seal', XMLDB_TYPE_CHAR, '200', null, XMLDB_NOTNULL, null, null); $table->add_field('cert_template', XMLDB_TYPE_CHAR, '200', null, XMLDB_NOTNULL, null, null); $table->add_field('disable', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '1'); $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0'); $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0'); // Adding keys to table crlm_certificate_settings. $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); // Adding indexes to table crlm_certificate_settings. $table->add_index('ent_id_type_ix', XMLDB_INDEX_UNIQUE, array('entity_id', 'entity_type')); $dbman->create_table($table); } // Define table crlm_certificate_issued to be created. $table = new xmldb_table('crlm_certificate_issued'); // Conditionally launch create table for crlm_certificate_issued. if (!$dbman->table_exists($table)) { // Adding fields to table crlm_certificate_issued. $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('cm_userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); $table->add_field('cert_setting_id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); $table->add_field('cert_code', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, null, null); $table->add_field('timeissued', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0'); $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0'); // Adding keys to table crlm_certificate_issued. $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); // Adding indexes to table crlm_certificate_issued. $table->add_index('cert_code_ix', XMLDB_INDEX_UNIQUE, array('cert_code')); $table->add_index('cm_userid_ix', XMLDB_INDEX_NOTUNIQUE, array('cm_userid')); $dbman->create_table($table); } // ELIS savepoint reached. upgrade_plugin_savepoint($result, 2013051502, 'elis', 'program'); } // ELIS-8528: remove orphaned LOs. if ($result && $oldversion < 2013051503) { $where = 'NOT EXISTS (SELECT \'x\' FROM {crlm_course} cc WHERE cc.id = {crlm_course_completion}.courseid)'; $DB->delete_records_select('crlm_course_completion', $where); upgrade_plugin_savepoint($result, 2013051503, 'elis', 'program'); } if ($result && $oldversion < 2013082100) { // Change password field length to 255. $table = new xmldb_table('crlm_user'); $field = new xmldb_field('password', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'username'); $dbman->change_field_precision($table, $field); upgrade_plugin_savepoint($result, 2013082100, 'elis', 'program'); } if ($result && $oldversion < 2013082101) { require_once elis::file('eliscore/fields/manual/custom_fields.php'); require_once elis::file('eliscore/fields/moodleprofile/custom_fields.php'); $fieldcat = field_category::ensure_exists_for_contextlevel(get_string('moodlefields', 'local_elisprogram'), CONTEXT_ELIS_USER); $sql = 'SELECT m.id FROM {user_info_field} m WHERE NOT EXISTS( SELECT * FROM {local_eliscore_field} e WHERE e.shortname = m.shortname )'; $fieldstosync = $DB->get_records_sql($sql); foreach ($fieldstosync as $mfield) { // Create field. $efield = field::make_from_moodle_field($mfield->id, $fieldcat, pm_moodle_profile::sync_from_moodle); // Sync profile field information from Moodle into ELIS. sync_profile_field_from_moodle($efield); } upgrade_plugin_savepoint($result, 2013082101, 'elis', 'program'); } if ($result && $oldversion < 2013082103) { // ELIS-8441 & ELIS-8569: Fix Program timetocomplete & frequency defaults of '0y'. $table = new xmldb_table('crlm_curriculum'); if ($dbman->table_exists($table)) { $field = new xmldb_field('timetocomplete', XMLDB_TYPE_CHAR, '64', null, XMLDB_NOTNULL, null, null, 'timemodified'); $dbman->change_field_default($table, $field); $field = new xmldb_field('frequency', XMLDB_TYPE_CHAR, '64', null, XMLDB_NOTNULL, null, null, 'timetocomplete'); $dbman->change_field_default($table, $field); $sql = 'UPDATE {crlm_curriculum} SET timetocomplete = "" WHERE timetocomplete = "0y"'; $DB->execute($sql); $sql = 'UPDATE {crlm_curriculum} SET frequency = "" WHERE frequency = "0y"'; $DB->execute($sql); } upgrade_plugin_savepoint($result, 2013082103, 'elis', 'program'); } if ($result && $oldversion < 2013082104) { require_once dirname(__FILE__) . '/../../../lib/lib.php'; pm_set_config('notify_addedtowaitlist_user', 1); pm_set_config('notify_enroledfromwaitlist_user', 1); pm_set_config('notify_incompletecourse_user', 1); upgrade_plugin_savepoint($result, 2013082104, 'elis', 'program'); } return $result; }
/** * Initialize a custom field and field owner record. * * @param string $editcapability The capability configured as needed for editing * the custom field (empty string for context-specific capability) * @param string $viewcapability The capability configured as needed for viewing * the custom field (empty string for context-specific capability) * @return object The custom field object */ private function init_field_and_owner($editcapability, $viewcapability) { // Set up the custom field. $field = new field(array('shortname' => 'field', 'name' => 'field', 'datatype' => 'bool', 'categoryid' => 99999)); $field->save(); // Set up the field owner. $params = array('control' => 'checkbox', 'edit_capability' => $editcapability, 'view_capability' => $viewcapability); $fieldowner = new field_owner(array('fieldid' => $field->id, 'plugin' => 'manual', 'params' => serialize($params))); $fieldowner->save(); return $field; }
$fieldnamelist = @unserialize(base64_decode($fieldnamelist)); } $categories = field_category::get_for_context_level($context); $categories = $categories ? $categories : array(); // divide the fields into categories $fieldsbycategory = array(); foreach ($categories as $category) { $fieldsbycategory[$category->name] = array(); } foreach ($fields as $field) { if (is_array($fieldidlist) && in_array($field->id, $fieldidlist)) { continue; } //make sure the current user can access this field in at least one //course context $owners = field_owner::get_for_field($field); if (!block_php_report_field_accessible($owners)) { continue; } $fieldsbycategory[$field->categoryname][] = $field; } print_header($site->shortname . ': ' . get_string('selectcustomfields', $lang_file)); // show list of available fields if (empty($fieldsbycategory)) { echo '<div>' . get_string('nofieldsfound', $lang_file) . '</div>'; } else { echo '<div>' . get_string('customfields', $lang_file) . '</div>'; $table = null; $columns = array('category' => get_string('category', $lang_file), 'name' => get_string('name', $lang_file)); foreach ($columns as $column => $cdesc) { ${$column} = $cdesc;
/** * Validate that custom user fields are synched over to Moodle when PM user is created * during an import */ public function test_user_multi_custom_field_on_user_create() { global $CFG, $DB, $USER; require_once $CFG->dirroot . '/local/elisprogram/lib/setup.php'; require_once elis::lib('data/customfield.class.php'); require_once elis::file('eliscore/fields/moodleprofile/custom_fields.php'); require_once elispm::file('accesslib.php'); require_once elispm::lib('data/user.class.php'); require_once $CFG->dirroot . '/user/profile/lib.php'; require_once $CFG->dirroot . '/user/profile/definelib.php'; require_once $CFG->dirroot . '/user/profile/field/menu/define.class.php'; $CFG->filterall = true; $USER = get_admin(); $context = context_user::instance($USER->id); /* $filternames = filter_get_all_installed(); ob_start(); var_dump($filternames); $tmp = ob_get_contents(); ob_end_clean(); error_log("test_user_multi_custom_field_on_user_create: all-filters => {$tmp}"); */ // Note: >= m25 filter paths no longer prefixed with 'filter/' filter_set_global_state('multilang', TEXTFILTER_ON); filter_set_applies_to_strings('multilang', true); $multilangoption1 = '<span class="multilang" lang="en">Male</span><span class="multilang" lang="pt_br">Masculino</span>' . '<span class="multilang" lang="es">Masculino</span>'; $multilangoption2 = '<span class="multilang" lang="en">Female</span><span class="multilang" lang="pt_br">Feminino</span>' . '<span class="multilang" lang="es">Femenino</span>'; // The associated Moodle user profile field. $profiledefinemenu = new profile_define_menu(); $data = new stdClass(); $data->datatype = 'menu'; $data->categoryid = 99999; $data->shortname = 'testfieldgender'; $data->name = 'testfieldgender'; $data->param1 = "{$multilangoption1}\n{$multilangoption2}"; $data->defaultdata = $multilangoption2; $profiledefinemenu->define_save($data); // Reset cached custom fields. $user = new user(); $user->reset_custom_field_list(); // Field category. $fieldcategory = new field_category(array('name' => 'testcategoryname')); $fieldcategory->save(); // Custom field. $field = new field(array('categoryid' => $fieldcategory->id, 'shortname' => 'testfieldgender', 'name' => 'testfieldgender', 'datatype' => 'text', 'multivalued' => 1)); $field->save(); // Field owners field_owner::ensure_field_owner_exists($field, 'moodle_profile'); $manualowneroptions = array('required' => 0, 'edit_capability' => '', 'view_capability' => '', 'control' => 'menu', 'options' => "{$multilangoption1}\n{$multilangoption2}"); field_owner::ensure_field_owner_exists($field, 'manual', $manualowneroptions); // Field context level assocation. $fieldcontextlevel = new field_contextlevel(array('fieldid' => $field->id, 'contextlevel' => CONTEXT_ELIS_USER)); $fieldcontextlevel->save(); // Run the user create action. $record = new stdClass(); $record->action = 'create'; $record->idnumber = 'testuseridnumber'; $record->username = '******'; $record->firstname = 'testuserfirstname'; $record->lastname = 'testuserlastname'; $record->email = '*****@*****.**'; $record->address = 'testuseraddress'; $record->city = 'testusercity'; $record->country = 'CA'; $record->language = 'en'; $record->testfieldgender = 'Male/Female'; $importplugin = rlip_dataplugin_factory::factory('dhimport_version1elis'); $importplugin->fslogger = new silent_fslogger(null); $importplugin->process_record('user', $record, 'bogus'); // Validation. $userid = $DB->get_field(user::TABLE, 'id', array('username' => 'testuserusername')); $user = new user($userid); $user->load(); $user = $user->to_object(); /* $datars = field_data::get_for_context_and_field(\local_elisprogram\context\user::instance($user->id), 'testfieldgender'); foreach ($datars as $data) { ob_start(); var_dump($data); $tmp = ob_get_contents(); ob_end_clean(); error_log("test_user_multi_custom_field_on_user_create: data => {$tmp}"); } */ /* ob_start(); var_dump($user); $tmp = ob_get_contents(); ob_end_clean(); error_log("test_user_multi_custom_field_on_user_create: user => {$tmp}"); */ $this->assertEquals(array($multilangoption1, $multilangoption2), $user->field_testfieldgender); }
/** * Validate that the version 1 export includes custom field datetime data in the output. * * @dataProvider entity_provider */ public function test_exportincludes_customfield_datetime_data($entityname, $entitytable) { global $CFG, $DB; // Set the export to be incremental. set_config('nonincremental', 0, 'dhexport_version1elis'); $this->load_csv_data(); // Set up necessary custom field information in the database. // Create category. $categoryid = $this->create_custom_field_category(); // Create custom field. $field = $this->create_test_field($entityname, 'rlipdate', 'int', 'datetime', $categoryid); $this->create_field_mapping('testcustomfields', 'field_' . $field->id); // Create data record for custom field. $entity = $DB->get_records($entitytable); $entity = current($entity); $result = $this->update_data_record($entityname, $entity, $field, mktime(0, 0, 0, 1, 1, 2012)); // Obtain our export data based on the current DB state. $data = $this->get_export_data(); // Data validation. $this->assertEquals(2, count($data)); $row = $data[1]; $this->assertEquals(11, count($row)); $this->assertEquals('Jan/01/2012', $row[10]); // Set inctime to true. $fieldowner = new field_owner($field->owners['manual']->id); $fieldowner->load(); $fieldowner->param_inctime = 1; $fieldowner->save(); // Test with other value. $value = mktime(10, 10, 0, 1, 1, 2012); $result = $this->update_data_record($entityname, $entity, $field, $value); $data = $this->get_export_data(); $this->assertEquals(2, count($data)); $row = $data[1]; $this->assertEquals(11, count($row)); $this->assertEquals('Jan/01/2012:10:10', $row[10]); }
/** * Get custom fields * * This function returns an array of custom field names to labels, and has a few side effects * that set up data to use the custom fields later. The side effects reduce the number of * database lookups required to generate the form. * * @param array $fields An array of db records representing custom fields * @return array Custom field names mapped to labels. */ function get_custom_fields($group, $fields) { $yesno = array(1 => get_string('yes'), 0 => get_string('no')); // Array $xoptions to append to existing options['choices'] $options = array(); if (!$fields instanceof Iterator) { $fields = array(); } foreach ($fields as $field) { $field = new field($field); if (!isset($field->owners['manual'])) { error_log("multifilter.php::get_custom_fields() - no field->owners['manual'] for {$field->name} ({$field_identifier})"); continue; } $field_identifier = 'customfield-' . $field->id; $this->_fields[$group][$field_identifier] = $field; $this->record_short_field_name($field_identifier); $this->labels[$group][$field_identifier] = $field->name; $options[$field_identifier] = $field->name; $owner = new field_owner($field->owners['manual']); $params = unserialize($owner->params); //error_log("multifilter.php::get_custom_fields(): {$field_identifier} => {$params['control']} ({$this->datatypemap[$params['control']]})"); $this->fieldtofiltermap[$group][$field_identifier] = $this->datatypemap[$params['control']]; switch ($params['control']) { case 'datetime': // TBD - options required for datetime fields? $this->_choices[$field_identifier] = array('startyear' => $params['startyear'], 'stopyear' => $params['stopyear'], 'inctime' => isset($params['inctime']) ? $params['inctime'] : false); break; case 'checkbox': $this->_choices[$field_identifier] = $yesno; break; case 'menu': $choices = $owner->get_menu_options(); if (!empty($choices)) { $this->_choices[$field_identifier] = array(); foreach ($choices as $key => $choice) { $choice = trim($choice); // preserve anyvalue key => '' //$key = ($key === '') ? $key : $choice; $this->_choices[$field_identifier][$key] = $choice; } } else { error_log("multifilter::get_custom_fields() - empty menu options for fieldid = {$field->id} ... using: Yes, No"); $this->_choices[$field_identifier] = $yesno; } break; case 'text': // fall-thru case! // fall-thru case! case 'textarea': // no options required for text fields break; default: error_log("multifilter.php:: control = {$params['control']}, datatype = {$field->data_type()} not supported"); break; } } $this->sections[$group]['custom'] = $options; }
/** * Update environments and environment assignments to custom fields and * custom field data (run as a one-off during the elis program upgrade) * * If there are one or more entities (courses, classes) with environments * assigned to them, a new category and custom field is created, specific to the * appropriate context level. Then, that custom field is populated for each entity * that has and environment assigned (custom field is a single-select, where the options * are all the different environments on the site). */ function pm_migrate_environments() { global $DB; require_once elis::lib('data/customfield.class.php'); require_once elispm::lib('data/course.class.php'); require_once elispm::lib('data/pmclass.class.php'); //set up our contextlevel mapping $contextlevels = array(course::TABLE => 'course', pmclass::TABLE => 'class'); //lookup on all tags $environment_lookup = $DB->get_records('local_elisprogram_env', null, '', 'id, name'); foreach ($environment_lookup as $id => $environment) { $environment_lookup[$id] = $environment->name; } //go through each contextlevel and look for tags foreach ($contextlevels as $instancetable => $contextname) { //calculate the context level integer $contextlevel = \local_eliscore\context\helper::get_level_from_name($contextname); //make sure one or more environments are used at the current context level $select = 'environmentid != 0'; if ($DB->record_exists_select($instancetable, $select)) { //used to reference the category name $category = new field_category(array('name' => get_string('misc_category', 'local_elisprogram'))); //make sure our field for storing environments is created $field = new field(array('shortname' => "_19upgrade_{$contextname}_environment", 'name' => get_string('environment', 'local_elisprogram'), 'datatype' => 'char')); $field = field::ensure_field_exists_for_context_level($field, $contextlevel, $category); //determine environment options $options = array(); if ($records = $DB->get_recordset('local_elisprogram_env', null, 'name', 'DISTINCT name')) { foreach ($records as $record) { $options[] = $record->name; } } $options = implode("\n", $options); //set up our field owner field_owner::ensure_field_owner_exists($field, 'manual', array('control' => 'menu', 'options' => $options, 'edit_capability' => '', 'view_capability' => '')); //set up data for all relevant entries $sql = "SELECT id, environmentid\n FROM {{$instancetable}}\n WHERE environmentid != 0"; if ($records = $DB->get_recordset_sql($sql)) { foreach ($records as $record) { $contextlevel = \local_eliscore\context\helper::get_level_from_name($contextname); $contextclass = \local_eliscore\context\helper::get_class_for_level($contextlevel); $context = $contextclass::instance($record->id); $environmentid = $environment_lookup[$record->environmentid]; field_data::set_for_context_and_field($context, $field, $environmentid); } } } } }
/** * Sets up the fields necessary for enabling cluster groups * * @return boolean Returns true to indicate success */ function cluster_groups_install() { //retrieve the cluster context $cluster_context = context_level_base::get_custom_context_level('cluster', 'block_curr_admin'); //set up the cluster group category $group_category = new field_category(); $group_category->name = get_string('cluster_group_category', 'crlm_cluster_groups'); //set up the field that allows users to turn the groupings on $group_field = new field(); $group_field->shortname = 'cluster_group'; $group_field->name = get_string('cluster_group', 'crlm_cluster_groups'); $group_field->datatype = 'bool'; //set up the field and category $group_field = field::ensure_field_exists_for_context_level($group_field, $cluster_context, $group_category); //set up the field owner $owner_options = array('required' => 0, 'edit_capability' => '', 'view_capability' => '', 'control' => 'checkbox', 'columns' => 30, 'rows' => 10, 'maxlength' => 2048, 'help_file' => 'crlm_cluster_groups/cluster_groups'); field_owner::ensure_field_owner_exists($group_field, 'manual', $owner_options); //retrieve the cluster context $context = context_level_base::get_custom_context_level('cluster', 'block_curr_admin'); $field = new field(); $field->shortname = 'cluster_groupings'; $field->name = get_string('autoenrol_groupings', 'crlm_cluster_classification'); $field->datatype = 'bool'; $field = field::ensure_field_exists_for_context_level($field, $context, $group_category); $owner_options = array('required' => 0, 'edit_capability' => '', 'view_capability' => '', 'control' => 'checkbox', 'columns' => 30, 'rows' => 10, 'maxlength' => 2048, 'help_file' => 'crlm_cluster_groups/cluster_groupings'); field_owner::ensure_field_owner_exists($field, 'manual', $owner_options); return true; }