/**
  * 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();
     }
 }
예제 #2
0
 /**
  * Test ETL bugs fixed with ELIS-7815 & ELIS-7845
  */
 public function test_noetlerrorswithproblemlogdata()
 {
     global $DB;
     $dataset = $this->createCsvDataSet(array('log' => elis::file('elisprogram/tests/fixtures/mdl_log_elis7845_1500.csv')));
     $this->loadDataSet($dataset);
     elis::$config->eliscore_etl->last_run = 0;
     elis::$config->eliscore_etl->state = '';
     // Create existing record (NOT first)!
     $DB->insert_record('eliscore_etl_modactivity', (object) array('userid' => 409, 'courseid' => 382, 'cmid' => 12127, 'hour' => 1319659200, 'duration' => 1));
     // Run until complete.
     $prevdone = 0;
     $prevtogo = 1501;
     $prevstart = 0;
     $etlobj = new eliscore_etl_useractivity(0, false);
     do {
         $realtime = time();
         ob_start();
         $etlobj->cron();
         ob_end_clean();
         $lasttime = (int) $etlobj->state['starttime'];
         $recordsdone = $DB->count_records_select('log', "time < {$lasttime}");
         $recordstogo = $DB->count_records_select('log', "time >= {$lasttime}");
         /*
          * Uncomment to track progress.
          * echo "\n Done = {$recordsdone} ({$prevdone}), Togo = {$recordstogo} ({$prev_togo}),
          * starttime = {$lasttime} ({$prev_start})\n";
          */
         if (!$lasttime || !$recordstogo) {
             break;
         }
         $this->assertTrue($recordsdone >= $prevdone);
         $this->assertTrue($recordstogo <= $prevtogo);
         $this->assertTrue($lasttime > $prevstart);
         $prevdone = $recordsdone;
         $prevtogo = $recordstogo;
         $prevstart = $lasttime;
     } while (true);
     $etluacnt = $DB->count_records('eliscore_etl_useractivity');
     $etlumacnt = $DB->count_records('eliscore_etl_modactivity');
     $this->assertEquals(342, $etluacnt);
     $this->assertEquals(225, $etlumacnt);
 }
 /**
  * Test make_from_moodle_field function.
  *
  * @dataProvider dataprovider_make_from_moodle_field
  * @param object $mfielddata Data to create the initial moodle profile with.
  * @param array $expectedfielddata Expected data created for the field.
  * @param array $expectedmanualownerdata Expected field_owner data created.
  */
 public function test_make_from_moodle_field($mfielddata, $expectedfielddata, $expectedmanualownerdata)
 {
     require_once elis::file('eliscore/lib/data/customfield.class.php');
     require_once elis::file('eliscore/fields/moodleprofile/custom_fields.php');
     global $DB;
     $mfieldid = $DB->insert_record('user_info_field', $mfielddata);
     $fieldcat = new field_category();
     $fieldcat->name = 'Moodle Fields';
     $fieldcat->save();
     $efield = field::make_from_moodle_field($mfieldid, $fieldcat, pm_moodle_profile::sync_from_moodle);
     $efieldrec = $DB->get_record(field::TABLE, array('shortname' => $efield->shortname));
     unset($efieldrec->id);
     unset($efieldrec->sortorder);
     $expectedfielddata['categoryid'] = (string) $fieldcat->id;
     $this->assertEquals($expectedfielddata, (array) $efieldrec);
     $manualowner = $DB->get_record(field_owner::TABLE, array('fieldid' => $efield->id, 'plugin' => 'manual'));
     ksort($expectedmanualownerdata);
     $actualparams = unserialize($manualowner->params);
     ksort($actualparams);
     $this->assertEquals($expectedmanualownerdata, $actualparams);
     $this->assertTrue(moodle_profile_can_sync($efield->shortname));
     if ($mfielddata['defaultdata'] != '') {
         switch ($efield->datatype) {
             case 'bool':
                 $fielddatatype = 'int';
                 break;
             case 'datetime':
                 $fielddatatype = 'int';
                 break;
             case 'char':
                 $fielddatatype = 'char';
                 break;
             default:
                 $fielddatatype = 'text';
         }
         $fielddataclass = 'field_data_' . $fielddatatype;
         $defaultdata = $DB->get_record($fielddataclass::TABLE, array('fieldid' => $efield->id));
         $this->assertNotEmpty($defaultdata);
         $this->assertEquals($mfielddata['defaultdata'], $defaultdata->data);
     }
 }
예제 #4
0
 *
 * 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    local_elisprogram
 * @author     Remote-Learner.net Inc
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 * @copyright  (C) 2008-2013 Remote Learner.net Inc http://www.remote-learner.net
 *
 */
require_once dirname(__FILE__) . '/../../eliscore/test_config.php';
global $CFG;
require_once $CFG->dirroot . '/local/elisprogram/lib/setup.php';
// ELIS libs.
require_once elis::lib('data/customfield.class.php');
require_once elis::file('eliscore/fields/moodleprofile/custom_fields.php');
require_once elispm::lib('deprecatedlib.php');
require_once elispm::lib('data/user.class.php');
require_once elispm::lib('data/usermoodle.class.php');
require_once $CFG->dirroot . '/user/profile/lib.php';
/**
 * Test user custom fields.
 * @group local_elisprogram
 */
class usercustomfields_testcase extends elis_database_test
{
    /**
     * Load initial data from CSVs.
     */
    protected function load_csv_data()
    {
예제 #5
0
/**
 * 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;
}
예제 #6
0
파일: setup.php 프로젝트: jamesmcq/elis
     * Return the full path name for a PM file.
     */
    static function file($file)
    {
        return elis::component_file('elisprogram', $file);
    }
    /**
     * The base directory for the PM libraries.
     */
    static $libdir;
    /**
     * Return the full path name for a PM library file.
     */
    static function lib($file)
    {
        return elispm::file("lib/{$file}");
    }
    /**
     * The default database object.
     */
    static $db;
}
global $CFG;
elispm::$basedir = elis::file('elisprogram');
elispm::$libdir = elis::component_file('elisprogram', 'lib');
global $DB;
elispm::$db = $DB;
$plugin = new stdClass();
include elispm::file('version.php');
elispm::$version = $plugin->version;
elispm::$release = $plugin->release;
예제 #7
0
 /**
  * Tests local/elisprogram/scripts/fix_cluster_orphans.php
  */
 public function test_fixclusterorphans()
 {
     global $DB;
     $this->setup_usersets();
     // Create orphan usersets.
     $DB->delete_records(userset::TABLE, array('id' => 1));
     // Run.
     try {
         require_once elis::file('elisprogram/scripts/fix_cluster_orphans.php');
     } catch (Exception $e) {
         if ($e->getMessage() !== 'Constant CLI_SCRIPT already defined') {
             throw new $e();
         }
     }
 }
예제 #8
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);
 }
 * 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    local_eliscore
 * @author     Remote-Learner.net Inc
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 * @copyright  (C) 2008-2014 Remote-Learner.net Inc (http://www.remote-learner.net)
 *
 */
require_once dirname(__FILE__) . '/../test_config.php';
global $CFG;
require_once $CFG->dirroot . '/local/eliscore/lib/setup.php';
require_once elis::lib('data/customfield.class.php');
require_once elis::file('eliscore/fields/manual/custom_fields.php');
require_once $CFG->dirroot . '/lib/formslib.php';
require_once $CFG->dirroot . '/course/lib.php';
require_once $CFG->dirroot . '/user/lib.php';
/**
 * Base form that is used as a skeleton to add fields to for ELIS custom fields.
 */
class custom_field_permissions_form extends moodleform
{
    /**
     * Form definition.
     */
    public function definition()
    {
        // We don't need any pre-defined elements.
    }
예제 #10
0
파일: setup.php 프로젝트: jamesmcq/elis
    {
        global $DB;
        if (!isset($this->configs[$name])) {
            $config = new stdClass();
            // load the defaults
            if (file_exists(elis::plugin_file($name, 'defaults.php'))) {
                $defaults = array();
                include elis::plugin_file($name, 'defaults.php');
                foreach ($defaults as $key => $value) {
                    $config->{$key} = $value;
                }
            }
            $configrecs = $DB->get_recordset('config_plugins', array('plugin' => $name));
            foreach ($configrecs as $rec) {
                $key = $rec->name;
                $config->{$key} = $rec->value;
            }
            unset($configrecs);
            $this->configs[$name] = $config;
        }
        return $this->configs[$name];
    }
}
global $CFG;
elis::$basedir = "{$CFG->dirroot}/local";
elis::$libdir = elis::file('eliscore/lib');
elis::$config = new elis_config();
$plugin = new stdClass();
require elis::file('eliscore/version.php');
elis::$version = $plugin->version;
elis::$release = $plugin->release;
예제 #11
0
 /**
  * Create a user-level ELIS field from an existing Moodle user profile field.
  *
  * @param int $mfieldid The ID of a Moodle user profile field.
  * @param field_category $category An ELIS field_category object to add the new field to.
  * @param boolean $syncdir Data Sync Direction.
  *                         Possible values:
  *                             false = no syncing
  *                             pm_moodle_profile::sync_from_moodle = sync from moodle.
  *                             pm_moodle_profile::sync_to_moodle = sync to moodle.
  * @return field The new field object.
  */
 public static function make_from_moodle_field($mfieldid, field_category $category, $syncdir = false)
 {
     require_once elis::file('eliscore/fields/manual/custom_fields.php');
     require_once elis::file('eliscore/fields/moodleprofile/custom_fields.php');
     global $DB;
     // Get moodle field information.
     $mfield = $DB->get_record('user_info_field', array('id' => $mfieldid));
     if (empty($mfield)) {
         return null;
     }
     if (!defined('CONTEXT_ELIS_USER')) {
         return null;
     }
     // Initially elis field data is the same as moodle field data.
     $field = (array) $mfield;
     unset($field['id']);
     $field['datatype'] = 'text';
     $field['categoryid'] = $category->id;
     // Manual field owner data.
     $fieldmanualowner = new field_owner();
     $fieldmanualowner->plugin = 'manual';
     $fieldmanualowner->param_control = $mfield->datatype;
     $fieldmanualowner->param_required = (bool) (int) $mfield->required;
     // Set data based on moodle field's datatype.
     switch ($mfield->datatype) {
         case static::CHECKBOX:
             $field['datatype'] = 'bool';
             break;
         case static::DATETIME:
             $field['datatype'] = 'datetime';
             $fieldmanualowner->param_startyear = $mfield->param1;
             $fieldmanualowner->param_stopyear = $mfield->param2;
             $fieldmanualowner->param_inctime = $mfield->param3;
             break;
         case static::MENU:
             $field['datatype'] = 'char';
             $fieldmanualowner->param_options = $mfield->param1;
             break;
         case static::TEXTAREA:
             $fieldmanualowner->param_columns = !empty($mfield->param1) ? $mfield->param1 : 30;
             $fieldmanualowner->param_rows = !empty($mfield->param2) ? $mfield->param2 : 10;
             break;
         case static::TEXT:
             if ($mfield->param3) {
                 $fieldmanualowner->param_control = 'password';
             }
             $fieldmanualowner->param_columns = $mfield->param1;
             $fieldmanualowner->param_maxlength = $mfield->param2;
             break;
     }
     // Create field.
     $field = new field($field);
     $field->save();
     // Create moodle profile owner.
     if ($syncdir === pm_moodle_profile::sync_from_moodle || $syncdir === pm_moodle_profile::sync_from_moodle) {
         $fieldmoodleprofileowner = new field_owner(array('fieldid' => $field->id, 'plugin' => 'moodle_profile', 'exclude' => $syncdir));
         $fieldmoodleprofileowner->save();
     }
     // Create manual owner.
     $fieldmanualowner->fieldid = $field->id;
     $fieldmanualowner->save();
     // Update field context level.
     static::ensure_field_exists_for_context_level($field, CONTEXT_ELIS_USER, $category);
     // Reload field object.
     $field = new field($field->id);
     $field->load();
     if ($syncdir === pm_moodle_profile::sync_from_moodle) {
         sync_profile_field_settings_from_moodle($field);
     }
     // Set default data.
     if (isset($mfield->defaultdata) && $mfield->defaultdata !== '') {
         field_data::set_for_context_and_field(null, $field, $mfield->defaultdata);
     }
     // Reload field object.
     $field = new field($field->id);
     $field->load();
     return $field;
 }
예제 #12
0
 * 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    local_elisprogram
 * @author     Remote-Learner.net Inc
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 * @copyright  (C) 2008-2014 Remote Learner.net Inc http://www.remote-learner.net
 *
 */
require_once dirname(__FILE__) . '/../../eliscore/test_config.php';
global $CFG;
require_once $CFG->dirroot . '/local/elisprogram/lib/setup.php';
require_once elis::file('elisprogram/dashboardpage.class.php');
/**
 * Test ELIS Dashboard component info methods
 * @group local_elisprogram
 */
class elisdashboard_testcase extends elis_database_test
{
    /**
     * DataProvider for method test_get_jquery_info
     * @return array (array($files), array($infostrings), array($expected))
     */
    public function get_jquery_info_dataprovider()
    {
        return array(array(array('jquery-1.6.2.min.js'), array('name' => 'jquery'), array('jquery', '1.6.2', '')), array(array('jquery-1.6.2.js'), array('name' => 'jquery'), array('jquery', '1.6.2', '')), array(array('jquery-ui-1.8.16.custom.js'), array('name' => 'jquery-ui'), array('jquery-ui', '1.8.16', '')), array(array('jquery-ui-1.8.16.js'), array('name' => 'jquery-ui'), array('jquery-ui', '1.8.16', '')), array(array('jquery-1.9.1.min.js'), array('name' => 'jquery'), array('jquery', '1.9.1', '')), array(array('jquery-1.9.1.js'), array('name' => 'jquery'), array('jquery', '1.9.1', '')), array(array('jquery-ui-1.10.1.custom.js'), array('name' => 'jquery-ui'), array('jquery-ui', '1.10.1', '')), array(array('jquery-ui-1.10.1.js'), array('name' => 'jquery-ui'), array('jquery-ui', '1.10.1', '')));
    }
    /**