/** * Sets up the fields necessary for enabling cluster groups * * @return boolean Returns true to indicate success */ function xmldb_elisprogram_usetgroups_install() { // Migrate component. $oldcmp = 'pmplugins_userset_groups'; $newcmp = 'elisprogram_usetgroups'; $upgradestepfuncname = 'elisprogram_usetgroups_pre26upgradesteps'; $migrator = new \local_eliscore\install\migration\migrator($oldcmp, $newcmp, $upgradestepfuncname); if ($migrator->old_component_installed() === true) { $migrator->migrate(); } //set up the cluster group category $group_category = new field_category(); $group_category->name = get_string('userset_group_category', 'elisprogram_usetgroups'); //set up the field that allows users to turn the groupings on $group_field = new field(); $group_field->shortname = 'userset_group'; $group_field->name = get_string('userset_group', 'elisprogram_usetgroups'); $group_field->datatype = 'bool'; //set up the field and category $group_field = field::ensure_field_exists_for_context_level($group_field, CONTEXT_ELIS_USERSET, $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' => 'elisprogram_usetgroups/userset_group'); field_owner::ensure_field_owner_exists($group_field, 'manual', $owner_options); $field = new field(); $field->shortname = 'userset_groupings'; $field->name = get_string('autoenrol_groupings', 'elisprogram_usetclassify'); $field->datatype = 'bool'; $field = field::ensure_field_exists_for_context_level($field, CONTEXT_ELIS_USERSET, $group_category); $owner_options = array('required' => 0, 'edit_capability' => '', 'view_capability' => '', 'control' => 'checkbox', 'columns' => 30, 'rows' => 10, 'maxlength' => 2048, 'help_file' => 'elisprogram_usetgroups/autoenrol_groupings'); field_owner::ensure_field_owner_exists($field, 'manual', $owner_options); return true; }
/** * 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; }
/** * Install function for this plugin * * @return boolean true Returns true to satisfy install procedure */ function xmldb_elisprogram_usetthemes_install() { // Migrate component. $oldcmp = 'pmplugins_userset_themes'; $newcmp = 'elisprogram_usetthemes'; $upgradestepfuncname = 'elisprogram_usetthemes_pre26upgradesteps'; $migrator = new \local_eliscore\install\migration\migrator($oldcmp, $newcmp, $upgradestepfuncname); if ($migrator->old_component_installed() === true) { $migrator->migrate(); } //set up the cluster theme category $theme_category = new field_category(); $theme_category->name = get_string('userset_theme_category', 'elisprogram_usetthemes'); //set up the theme priority field $theme_priority_field = new field(); $theme_priority_field->shortname = '_elis_userset_themepriority'; $theme_priority_field->name = get_string('userset_theme_priority', 'elisprogram_usetthemes'); $theme_priority_field->datatype = 'int'; //set up the field and category $theme_priority_field = field::ensure_field_exists_for_context_level($theme_priority_field, CONTEXT_ELIS_USERSET, $theme_category); $owner_options = array('required' => 0, 'edit_capability' => '', 'view_capability' => '', 'control' => 'text', 'columns' => 30, 'rows' => 10, 'maxlength' => 2048, 'help_file' => 'elisprogram_usetthemes/_elis_userset_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 = '_elis_userset_theme'; $theme_field->name = get_string('userset_theme', 'elisprogram_usetthemes'); $theme_field->datatype = 'char'; //set up the field and category $theme_field = field::ensure_field_exists_for_context_level($theme_field, CONTEXT_ELIS_USERSET, $theme_category); $owner_options = array('control' => 'menu', 'options_source' => 'themes', 'required' => 0, 'edit_capability' => '', 'view_capability' => '', 'columns' => 30, 'rows' => 10, 'maxlength' => 2048, 'help_file' => 'elisprogram_usetthemes/_elis_userset_theme'); field_owner::ensure_field_owner_exists($theme_field, 'manual', $owner_options); return true; }
/** * Install function for this plugin * * @return boolean true Returns true to satisfy install procedure */ function xmldb_elisprogram_usetdisppriority_install() { global $CFG; require_once elispm::lib('setup.php'); // Migrate component. $oldcmp = 'pmplugins_userset_display_priority'; $newcmp = 'elisprogram_usetdisppriority'; $upgradestepfuncname = 'elisprogram_usetdisppriority_pre26upgradesteps'; $migrator = new \local_eliscore\install\migration\migrator($oldcmp, $newcmp, $upgradestepfuncname); if ($migrator->old_component_installed() === true) { $migrator->migrate(); } $field = new field(); $field->shortname = USERSET_DISPLAY_PRIORITY_FIELD; $field->name = get_string('display_priority_field_name', 'elisprogram_usetdisppriority'); $field->datatype = 'int'; $category = new field_category(); $category->name = get_string('display_settings_category_name', 'elisprogram_usetdisppriority'); $field = field::ensure_field_exists_for_context_level($field, CONTEXT_ELIS_USERSET, $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 = 'userset_display_priority'; $owner->param_help_file = 'elisprogram_usetdisppriority/display_priority'; $owner->save(); } 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 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; }
/** * Initialize our custom field data, and persist in the database. * * @param mixed $cl optional contextlevel to use, default null for self::contextlevel * @return object The custom field created */ protected function init_custom_field($cl = null) { // Set up our custom field. $field = new field(array('name' => 'testcustomfieldname', 'datatype' => 'char', 'multivalued' => 1)); $fieldcategory = new field_category(array('name' => 'testcategoryname')); $field = field::ensure_field_exists_for_context_level($field, $cl ? $cl : self::CONTEXTLEVEL, $fieldcategory); field_data::set_for_context_and_field(null, $field, array('value1')); return $field; }
/** * Install function for this plugin * * @return boolean true Returns true to satisfy install procedure */ function xmldb_elisprogram_preposttest_install() { global $CFG; require_once elispm::lib('setup.php'); require_once elis::lib('data/customfield.class.php'); // Migrate component. $oldcmp = 'pmplugins_pre_post_test'; $newcmp = 'elisprogram_preposttest'; $upgradestepfuncname = 'elisprogram_preposttest_pre26upgradesteps'; $migrator = new \local_eliscore\install\migration\migrator($oldcmp, $newcmp, $upgradestepfuncname); if ($migrator->old_component_installed() === true) { $migrator->migrate(); } // Pre-test field $field = new field(); $field->shortname = PRE_TEST_FIELD; $field->name = get_string('pre_test_field_name', 'elisprogram_preposttest'); $field->datatype = 'char'; $category = new field_category(); $category->name = get_string('pre_post_test_category_name', 'elisprogram_preposttest'); $field = field::ensure_field_exists_for_context_level($field, CONTEXT_ELIS_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 = 'learning_objectives'; $owner->param_help_file = 'elisprogram_preposttest/pre_test'; $owner->save(); } // Post-test field $field = new field(); $field->shortname = POST_TEST_FIELD; $field->name = get_string('post_test_field_name', 'elisprogram_preposttest'); $field->datatype = 'char'; $category = new field_category(); $category->name = get_string('pre_post_test_category_name', 'elisprogram_preposttest'); $field = field::ensure_field_exists_for_context_level($field, CONTEXT_ELIS_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 = 'learning_objectives'; $owner->param_help_file = 'elisprogram_preposttest/post_test'; $owner->save(); } 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 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; }
/** * Install function for this plugin * * @return boolean true Returns true to satisfy install procedure */ function xmldb_elisprogram_archive_install() { global $CFG; require_once elispm::lib('setup.php'); require_once elis::lib('data/customfield.class.php'); // Migrate component. $oldcmp = 'pmplugins_archive'; $newcmp = 'elisprogram_archive'; $upgradestepfuncname = 'elisprogram_archive_pre26upgradesteps'; $migrator = new \local_eliscore\install\migration\migrator($oldcmp, $newcmp, $upgradestepfuncname); if ($migrator->old_component_installed() === true) { $migrator->migrate(); } // Archive field $field = new field(); $field->shortname = ARCHIVE_FIELD; $field->name = get_string('archive_field_name', 'elisprogram_archive'); $field->datatype = 'bool'; $category = new field_category(); $category->name = get_string('archive_category_name', 'elisprogram_archive'); $field = field::ensure_field_exists_for_context_level($field, CONTEXT_ELIS_PROGRAM, $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_required = 0; $owner->param_view_capability = ''; $owner->param_edit_capability = ''; $owner->param_control = 'checkbox'; $owner->param_options_source = ''; $owner->param_help_file = 'elisprogram_archive/archive_program'; $owner->save(); } $owner_options = array('required' => 0, 'edit_capability' => '', 'view_capability' => '', 'control' => 'checkbox', 'columns' => 30, 'rows' => 10, 'maxlength' => 2048, 'help_file' => 'elisprogram_archive/archive_program'); field_owner::ensure_field_owner_exists($field, 'manual', $owner_options); 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; }
/** * 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; }
/** * 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; }
/** * Validate that the import performs user synchronization on user update */ public function test_version1importsyncsusertoelisonupdate() { global $CFG, $DB; if (!file_exists($CFG->dirroot . '/local/elisprogram/lib/setup.php')) { $this->markTestIncomplete('This test depends on the PM system'); } require_once $CFG->dirroot . '/local/elisprogram/lib/setup.php'; require_once $CFG->dirroot . '/user/profile/definelib.php'; require_once elis::lib('data/customfield.class.php'); require_once elispm::lib('data/user.class.php'); // Make sure we are not auto-assigning idnumbers. set_config('auto_assign_user_idnumber', 0, 'local_elisprogram'); elis::$config = new elis_config(); // Create Moodle custom field category. $category = new stdClass(); $category->sortorder = $DB->count_records('user_info_category') + 1; $category->id = $DB->insert_record('user_info_category', $category); // Create Moodle custom profile field. $this->create_profile_field('rliptext', 'text', $category->id); // Obtain the PM user context level. $contextlevel = CONTEXT_ELIS_USER; // Make sure the PM category and field exist. $category = new field_category(array('name' => 'rlipcategory')); $field = new field(array('shortname' => 'rliptext', 'name' => 'rliptext', 'datatype' => 'text', 'multivalued' => 0)); $field = field::ensure_field_exists_for_context_level($field, $contextlevel, $category); // Make sure the field owner is setup. 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 = 'text'; $owner->save(); // Make sure the field is set up for synchronization. field_owner::ensure_field_owner_exists($field, 'moodle_profile'); $ownerid = $DB->get_field(field_owner::TABLE, 'id', array('fieldid' => $field->id, 'plugin' => 'moodle_profile')); $owner = new field_owner($ownerid); $owner->exclude = pm_moodle_profile::sync_from_moodle; $owner->save(); // Update the user class's static cache of define user custom fields. $tempuser = new user(); $tempuser->reset_custom_field_list(); // Create the user. $this->run_core_user_import(array('idnumber' => 'rlipidnumber', 'profile_field_rliptext' => 'rliptext')); // Make sure PM user was created correctly. $this->assert_record_exists(user::TABLE, array('username' => 'rlipusername', 'idnumber' => 'rlipidnumber')); // Run the import, updating the user. $this->run_core_user_import(array('action' => 'update', 'username' => 'rlipusername', 'profile_field_rliptext' => 'rliptextupdated')); // Make sure the PM custom field data was set. $sql = "SELECT 'x'\n FROM {" . field::TABLE . "} f\n JOIN {" . field_data_text::TABLE . "} d ON f.id = d.fieldid\n WHERE f.shortname = ? AND d.data = ?"; $params = array('rliptext', 'rliptextupdated'); $exists = $DB->record_exists_sql($sql, $params); $this->assertEquals($exists, true); }
/** * ELIS-4797: Test Various Custom Field Operations */ public function test_customfieldoperations() { $contextlevels = \local_eliscore\context\helper::get_legacy_levels(); foreach ($contextlevels as $ctxname => $ctxlvl) { $category = $this->create_field_category($ctxlvl); $field = $this->create_field($category, $ctxlvl); $fieldsfetched = field::get_for_context_level($ctxlvl); $fieldfound = false; foreach ($fieldsfetched as $fieldfetched) { if ($fieldfetched->shortname === $field->shortname) { $fieldfound = true; } } $this->assertTrue($fieldfound); $fieldfetched = field::get_for_context_level_with_name($ctxlvl, $field->shortname); $this->assertEquals($field->shortname, $fieldfetched->shortname); $fieldfetched = field::ensure_field_exists_for_context_level($field, $ctxlvl, $category); $this->assertEquals($field->shortname, $fieldfetched->shortname); $catsfetched = field_category::get_for_context_level($ctxlvl); $catfound = false; foreach ($catsfetched as $catfetched) { if ($catfetched->id == $category->id) { $catfound = true; } } $this->assertTrue($catfound); if ($ctxlvl === CONTEXT_ELIS_PROGRAM) { $cur = $this->create_curriculum(); $fielddata = field_data::get_for_context_and_field(null, $field); $fielddata = $fielddata->current(); $res = $fielddata->set_for_context_from_datarecord($ctxlvl, $cur); $this->assertTrue($res); } } }
/** * Set up an ELIS custom field from a Moodle custom field. * @param object $mfield The moodle custom field object to use as reference. * @param field_category $cat The ELIS custom field category to put the field in. * @return field The created ELIS custom field. */ protected function set_up_elis_custom_field($mfield, field_category $cat) { if (empty($cat)) { $cat = $this->set_up_elis_field_category(); } $user = new user(); $user->reset_custom_field_list(); $field = new field(); $field->shortname = $mfield->shortname; $field->name = $mfield->name; $field->datatype = $mfield->datatype; field::ensure_field_exists_for_context_level($field, CONTEXT_ELIS_USER, $cat); $owner = new field_owner(); $owner->fieldid = $field->id; $owner->plugin = 'manual'; $owner->params = serialize(array('required' => false, 'edit_capability' => '', 'view_capability' => '', 'control' => 'text', 'columns' => 30, 'rows' => 10, 'maxlength' => 2048, 'startyear' => '1970', 'stopyear' => '2038', 'inctime' => '0')); $owner->save(); $owner = new field_owner(); $owner->fieldid = $field->id; $owner->plugin = 'moodle_profile'; $owner->exclude = pm_moodle_profile::sync_to_moodle; $owner->save(); return $field; }
/** * Create a test ELIS user custom field. * * @param string $name The name of the custom field. * @param int $multivalued The multivalued value to set in the field definition * @param bool $setoptions Set to true to set the available menu of choices options * @param int $ctx The context level to use for the field * @param string $control The type of control to use for the field. * * @return int The id of the created field */ protected function create_custom_field($name = 'name', $multivalued = 1, $setoptions = true, $ctx = CONTEXT_ELIS_USER, $control = 'menu') { global $CFG; // Field. $fieldparams = array('name' => $name, 'datatype' => 'char', 'multivalued' => $multivalued); $field = new field($fieldparams); $category = new field_category(array('name' => 'testcategoryname')); $field = field::ensure_field_exists_for_context_level($field, $ctx, $category); // Owner. $owneroptions = array('control' => $control); if ($setoptions) { $owneroptions['options'] = "option1\r\noption2\r\noption3"; } field_owner::ensure_field_owner_exists($field, 'manual', $owneroptions); // Default. $fielddataparams = array('contextid' => null, 'fieldid' => $field->id, 'data' => 'option3'); $data = new field_data_char($fielddataparams); $data->save(); return $field->id; }
/** * 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); } } } } }
/** * Validate that the "menu of choices" custom field type works correctly * when options are separated by a carriage return and a line feed */ public function testmenuofchoicesignorescarriagereturns() { 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::lib('data/user.class.php'); // Setup. $field = new field(array('shortname' => 'testcustomfieldshortname', 'name' => 'testcustomfieldname', 'datatype' => 'char')); $category = new field_category(array('name' => 'testcategoryname')); field::ensure_field_exists_for_context_level($field, CONTEXT_ELIS_USER, $category); $ownerparams = array('control' => 'menu', 'options' => "option1\r\noption2"); field_owner::ensure_field_owner_exists($field, 'manual', $ownerparams); // Run the create action. $record = new stdClass(); $record->action = 'create'; $record->email = '*****@*****.**'; $record->username = '******'; $record->idnumber = 'testuserid'; $record->firstname = 'testuserfirstname'; $record->lastname = 'testuserlastname'; $record->country = 'CA'; $record->testcustomfieldshortname = 'option1'; $user = new user(); $user->reset_custom_field_list(); $importplugin = rlip_dataplugin_factory::factory('dhimport_version1elis'); $importplugin->fslogger = new silent_fslogger(null); $importplugin->process_record('user', (object) $record, 'bogus'); // Validation. $user = new user(1); $user->load(); $this->assertEquals('option1', $user->field_testcustomfieldshortname); }