Ejemplo n.º 1
0
/**
 * 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;
}
Ejemplo n.º 2
0
/**
 * 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;
}
Ejemplo n.º 3
0
/**
 * 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;
}
Ejemplo n.º 4
0
/**
 * 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;
}
 /**
  * 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();
     }
 }
Ejemplo n.º 6
0
/**
 * 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;
}
 /**
  * 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;
 }
Ejemplo n.º 8
0
/**
 * 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;
}
Ejemplo n.º 9
0
 /**
  * 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);
 }
 /**
  * Create the test custom profile field and owner
  *
  * @param string $contextlevelname The name of the custom context level to create the field at
  * @param string $name PM custom field shortname
  * @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 int $categoryid PM custom field category id
  * @param string $options Extra parameter, used for select options
  * @param string $defaultdata Default value.
  *
  * @return int The id of the created field
  */
 private function create_test_field($contextlevelname = 'user', $name = 'testfieldname', $datatype, $uitype, $categoryid, $options = null, $defaultdata = null)
 {
     global $CFG;
     require_once $CFG->dirroot . '/local/elisprogram/lib/setup.php';
     require_once elis::lib('data/customfield.class.php');
     // Category contextlevel.
     $contextlevel = \local_eliscore\context\helper::get_level_from_name($contextlevelname);
     $fieldcategorycontextlevel = new field_category_contextlevel(array('categoryid' => $categoryid, 'contextlevel' => $contextlevel));
     $fieldcategorycontextlevel->save();
     // Field.
     $field = new field(array('shortname' => 'testfieldshortname', 'name' => $name, 'categoryid' => $categoryid, 'datatype' => $datatype));
     $field->save();
     // Field_data if a default value needs to be set.
     if ($defaultdata !== null) {
         $classname = 'field_data_' . $datatype;
         $fielddata = new $classname(array('fieldid' => $field->id, 'data' => $defaultdata));
         $fielddata->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.
         $options = is_array($options) ? implode("\n", $options) : $options;
         $ownerdata['options'] = $options;
     }
     field_owner::ensure_field_owner_exists($field, 'manual', $ownerdata);
     return $field;
 }
Ejemplo n.º 11
0
 /**
  * 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);
 }
Ejemplo n.º 12
0
 /**
  * Create a moodle user custom field.
  * @param field_category $cat The category to create the field in.
  * @return field The created field.
  */
 public function create_user_field(field_category $cat)
 {
     global $DB;
     // Create category.
     $mcat = (object) array('name' => $cat->name, 'sortorder' => 1);
     $mcat->id = $DB->insert_record('user_info_category', $mcat);
     // Create field.
     $field = (object) array('shortname' => 'user_testfield', 'name' => 'User Test Field', 'datatype' => 'text', 'description' => '', 'descriptionformat' => 1, 'categoryid' => $mcat->id, 'sortorder' => 1, 'required' => 0, 'locked' => 0, 'visible' => 1, 'forceunique' => 0, 'signup' => 0, 'defaultdata' => '', 'defaultdataformat' => 0);
     $field->id = $DB->insert_record('user_info_field', $field);
     $manualowneroptions = array('required' => 0, 'edit_capability' => '', 'view_capability' => '', 'control' => 'text', 'columns' => 30, 'rows' => 10, 'maxlength' => 100);
     $field = new field();
     $field->shortname = 'user_testfield';
     $field->name = 'User Test Field';
     $field->datatype = 'char';
     field::ensure_field_exists_for_context_level($field, CONTEXT_ELIS_USER, $cat);
     field_owner::ensure_field_owner_exists($field, 'manual', $manualowneroptions);
     $owner = new field_owner();
     $owner->fieldid = $field->id;
     $owner->plugin = 'moodleprofile';
     $owner->exclude = pm_moodle_profile::sync_to_moodle;
     $owner->save();
     return $field;
 }
Ejemplo n.º 13
0
 /**
  * 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);
 }
Ejemplo n.º 14
0
 /**
  * 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;
 }
Ejemplo n.º 16
0
 /**
  * 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;
 }
Ejemplo n.º 17
0
/**
 * 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;
}
Ejemplo n.º 18
0
/**
 * 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);
                }
            }
        }
    }
}
 /**
  * Set up data that is needed for testing
  */
 private function set_up_required_data($assignusertouserset = true, $assigncoursetoclass = true, $assigntracktoclass = true, $initclusterprofile = false, $initusersetfielddata = true)
 {
     global $CFG, $DB;
     require_once $CFG->dirroot . '/local/elisprogram/lib/setup.php';
     require_once $CFG->dirroot . '/course/lib.php';
     require_once $CFG->dirroot . '/lib/enrollib.php';
     require_once elis::lib('data/customfield.class.php');
     require_once elispm::file('accesslib.php');
     require_once elispm::lib('data/classmoodlecourse.class.php');
     require_once elispm::lib('data/clusterassignment.class.php');
     require_once elispm::lib('data/clustertrack.class.php');
     require_once elispm::lib('data/course.class.php');
     require_once elispm::lib('data/curriculum.class.php');
     require_once elispm::lib('data/pmclass.class.php');
     require_once elispm::lib('data/track.class.php');
     require_once elispm::lib('data/user.class.php');
     require_once elispm::lib('data/userset.class.php');
     require_once elispm::lib('data/usertrack.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();
     // Set up the test course description and class instance.
     $course = new course(array('name' => 'testcoursename', 'idnumber' => 'testcourseidnumber', 'syllabus' => ''));
     $course->save();
     $pmclass = new pmclass(array('courseid' => $course->id, 'idnumber' => 'testclassidnumber'));
     $pmclass->save();
     $category = new stdClass();
     $category->name = 'testcategoryname';
     $category->id = $DB->insert_record('course_categories', $category);
     // Set up the test Moodle course.
     set_config('enrol_plugins_enabled', 'manual');
     set_config('defaultenrol', 1, 'enrol_manual');
     set_config('status', ENROL_INSTANCE_ENABLED, 'enrol_manual');
     $course = new stdClass();
     $course->category = $category->id;
     $course->shortname = 'testcourseshortname';
     $course->fullname = 'testcoursefullname';
     $course = create_course($course);
     if ($assigncoursetoclass) {
         // Assign the Moodle course to a class instance.
         $classmoodlecourse = new classmoodlecourse(array('classid' => $pmclass->id, 'moodlecourseid' => $course->id));
         $classmoodlecourse->save();
     }
     // Set up the test program and track.
     $curriculum = new curriculum(array('idnumber' => 'testcurriculumidnumber'));
     $curriculum->save();
     $track = new track(array('curid' => $curriculum->id, 'idnumber' => 'testtrackidnumber'));
     $track->save();
     if ($assigntracktoclass) {
         // Assign the test track to the test class instance.
         $trackassignment = new trackassignment(array('trackid' => $track->id, 'classid' => $pmclass->id, 'autoenrol' => 1));
         $trackassignment->save();
     }
     // Set up the test userset.
     $userset = new userset();
     $usersetdata = array('name' => 'testusersetname');
     if ($initusersetfielddata) {
         $usersetdata['field_userset_group'] = 1;
         $usersetdata['field_userset_groupings'] = 1;
     }
     $userset->set_from_data((object) $usersetdata);
     $userset->save();
     // Assign the test user to the test track.
     $usertrack = new usertrack(array('userid' => $user->id, 'trackid' => $track->id));
     $usertrack->save();
     $clustertrack = new clustertrack(array('clusterid' => $userset->id, 'trackid' => $track->id));
     $clustertrack->save();
     if ($assignusertouserset) {
         // Assign the test user to the test userset.
         $clusterassignment = new clusterassignment(array('userid' => $user->id, 'clusterid' => $userset->id, 'plugin' => 'manual'));
         $clusterassignment->save();
     }
     if ($initclusterprofile) {
         // 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' => true));
         $usersetprofile->save();
     }
     // Enrol the user in the Moodle course.
     $mdluserid = $DB->get_field('user', 'id', array('username' => 'testuserusername'));
     $roleid = create_role('testrole', 'testrole', 'testrole');
     enrol_try_internal_enrol($course->id, $mdluserid, $roleid);
     // Set up the necessary config data.
     set_config('userset_groups', 1, 'elisprogram_usetgroups');
     set_config('siteguest', '');
     // Validate setup.
     $this->assertEquals(0, $DB->count_records('groups'));
 }