protected function execute($arguments = array(), $options = array()) { // initialize the database connection $databaseManager = new sfDatabaseManager($this->configuration); $connection = $databaseManager->getDatabase($options['connection'])->getConnection(); // add your code here $nomSourat = array('الفاتحة', 'البقرة', 'آل عمران', 'النساء', 'المائدة', 'الأنعام', 'الأعراف', 'الأنفال', 'التوبة', 'يونس', 'هود', 'يوسف', 'الرعد', 'إبراهيم', 'الحجر', 'النحل', 'الإسراء', 'الكهف', 'مريم', 'طه', 'الأنبياء', 'الحج', 'المؤمنون', 'النور', 'الفرقان', 'الشعراء', 'النمل', 'القصص', 'العنكبوت', 'الروم', 'لقمان', 'السجدة', 'الأحزاب', 'سبأ', 'فاطر', 'يس', 'الصافات', 'ص', 'الزمر', 'غافر', 'فصلت', 'الشورى', 'الزخرف', 'الدخان', 'الجاثية', 'الأحقاف', 'محمد', 'الفتح', 'الحجرات', 'ق', 'الذاريات', 'الطور', 'النجم', 'القمر', 'الرحمن', 'الواقعة', 'الحديد', ' المجادلة', 'الحشر', 'الممتحنة', 'الصف', 'الجمعة', 'المنافقون', 'التغابن', 'الطلاق', 'التحريم', 'الملك', 'القلم', 'الحاقة', 'المعارج', 'نوح', 'الجن', 'المزمل', 'المدثر', 'القيامة', 'الإنسان', 'المرسلات', 'النبأ', 'النازعات', 'عبس', 'التكوير', 'الإنفطار', 'المطففين', 'الإنشقاق', 'البروج', 'الطارق', 'الأعلى', 'الغاشية', 'الفجر', 'البلد', 'الشمس', 'الليل', 'الضحى', 'الشرح', 'التين', 'العلق', 'القدر', 'البينة', 'الزلزلة', 'العاديات', 'القارعة', 'التكاثر', 'العصر', 'الهمزة', 'الفيل', 'قريش', 'الماعون', 'الكوثر', 'الكافرون', 'النصر', 'المسد', 'الإخلاص', 'الفلق', 'الناس'); foreach ($nomSourat as $key => $value) { $key = $key + 1; $otrack = new track(); $otrack->setUserId(1); $otrack->setPlayListId(1); $otrack->setName($value); if (strlen($key) == 1) { $key = '00' . $key; } if (strlen($key) == 2) { $key = '0' . $key; } $url = 'http://www.archive.org/download/TvQuran.com__Alafasi/' . $key . '.mp3'; $otrack->setUrl($url); $otrack->save(); } }
/** * Validating that enrolling a user in a track instance triggers the enrolment * notification */ public function test_track_enrolment_sends_class_enrolment_notification() { global $CFG, $DB; require_once $CFG->dirroot . '/local/elisprogram/lib/setup.php'; require_once elispm::lib('data/curriculum.class.php'); require_once elispm::lib('data/track.class.php'); require_once elispm::lib('data/user.class.php'); // Configuration. set_config('popup_provider_elis_program_notify_pm_permitted', 1, 'message'); set_config('email_provider_elis_program_notify_pm_permitted', 1, 'message'); set_config('notify_trackenrol_user', 1, 'local_elisprogram'); $message = '%%userenrolname%% has been enrolled in the track %%trackname%%.'; set_config('notify_trackenrol_message', $message, 'local_elisprogram'); // Force refreshing of configuration. elis::$config = new elis_config(); $this->setAdminUser(); unset_config('noemailever'); // Setup. $user = new user(array('idnumber' => 'testuseridnumber', 'username' => 'testuserusername', 'firstname' => 'testuserfirstname', 'lastname' => 'testuserlastname', 'email' => '*****@*****.**', 'country' => 'CA')); $user->save(); $program = new curriculum(array('idnumber' => 'testprogramidnumber')); $program->save(); $track = new track(array('curid' => $program->id, 'idnumber' => 'testtrackidnumber', 'name' => 'testtrackname')); $track->save(); // Run the enrolment create action. $record = new stdClass(); $record->context = 'track_testtrackidnumber'; $record->user_username = '******'; $importplugin = rlip_dataplugin_factory::factory('dhimport_version1elis'); $importplugin->fslogger = new silent_fslogger(null); $sink = $this->redirectEmails(); $importplugin->track_enrolment_create($record, 'bogus', 'testtrackidnumber'); $this->assertEquals(1, count($sink->get_messages())); $sink->close(); // Validation. $mdluserid = $DB->get_field('user', 'id', array('username' => 'testuserusername')); $expectedmessage = "{$user->firstname} {$user->lastname} has been enrolled in the track {$track->name}."; $like = $DB->sql_like('fullmessagehtml', ':message'); $select = "useridto = :userid\n AND {$like}"; $this->assertTrue($DB->record_exists_select('message', $select, array('userid' => $mdluserid, 'message' => "{$expectedmessage}%"))); }
/** * Validate that the provided custom field type and value produce the * specified error message on track update * * @param string $uitype The input control / UI type * @param string $value The value to use for the custom field * @param string $message The expected error message * @param array $otherparams Other parameters to give to the field owner * @dataProvider type_error_provider */ public function test_track_update_customfield_message($uitype, $value, $message, $otherparams) { global $CFG; require_once $CFG->dirroot . '/local/elisprogram/accesslib.php'; require_once $CFG->dirroot . '/local/elisprogram/lib/data/track.class.php'; $this->create_custom_field(CONTEXT_ELIS_TRACK, $uitype, $otherparams); // Create mapping record. $this->create_mapping_record('course', 'testfieldshortname', 'customtestfieldshortname'); $programid = $this->create_test_program(); $track = new track(array('curid' => $programid, 'name' => 'testtrackname', 'idnumber' => 'testtrackidnumber')); $track->save(); $data = array('action' => 'update', 'context' => 'track', 'idnumber' => 'testtrackidnumber', 'customtestfieldshortname' => $value); $message = '[course.csv line 2] Track with idnumber "testtrackidnumber" could not be updated. ' . $message . "\n"; $this->assert_data_produces_error($data, $message, 'course'); }
/** * Validate that an appropriate error is logged when max field lengths are * exceeded during a track update action * * @param string $field The identifier for the field we are testing * @param int $length The length we are testing at * @param string $customvalue A custom value to use rather than simply repeating a character, * or null if not applicable * @dataProvider trackupdatefieldprovider */ public function test_trackupdatelogserrorwhenfieldstoolong($field, $length, $customvalue) { global $CFG, $DB; require_once $CFG->dirroot . '/local/elisprogram/lib/data/curriculum.class.php'; require_once $CFG->dirroot . '/local/elisprogram/lib/data/track.class.php'; $program = new curriculum(array('idnumber' => 'testprogramidnumber')); $program->save(); $track = new track(array('curid' => $program->id, 'idnumber' => 'testtrackidnumber')); $track->save(); $data = array('action' => 'update', 'context' => 'track', 'idnumber' => 'testtrackidnumber'); if ($customvalue !== null) { $value = $customvalue; } else { $value = str_repeat('a', $length); } $data[$field] = $value; $maxlength = $length - 1; $expectederror = "{$field} value of \"{$value}\" exceeds the maximum field length of {$maxlength}.\n"; $this->assert_data_produces_error($data, $expectederror, 'course'); }
continue; } // not in database $last_build_date = time(); $timestamp = timestamp_from_preg('/(\\d\\d-\\d\\d-\\d\\d\\d\\d)/', $podcast); if ($timestamp == 0) { $timestamp = filemtime($podcast_directory . "/" . $podcast); } $getID3 = new getID3(); $ThisFileInfo = $getID3->analyze("./" . $podcast_directory . "/" . $podcast); $duration = @$ThisFileInfo['playtime_string']; $filename = str_replace("_", " ", $podcast); if (preg_match('/.*?-(.*?)-(.*?)-.*?/', $filename, $matches)) { $current_track->content["author"] = trim($matches[1]); $current_track->content["title"] = trim($matches[2]); } $current_track->content["subtitle"] = basename($podcast, ".mp3"); $current_track->content["filesize"] = filesize("./" . $podcast_directory . "/" . $podcast); $current_track->content["url"] = $base_url . "/" . $podcast_directory . "/" . $podcast; $current_track->content["duration"] = $duration; $current_track->content["timestamp"] = $timestamp; $tracks[] = $current_track; $current_track->save($podcast); } $redis->set("last_build_date", $last_build_date); uasort($tracks, "by_custom_date"); include 'header.php'; foreach ($tracks as $track) { $track->get_xml(); } include 'footer.php';
/** * Validate that enrolling a user into a user set via IP auto-enrolls them in * an associated track, and any associated programs or class instances */ public function test_userset_enrolment_creates_track_enrolment() { global $CFG, $DB; require_once $CFG->dirroot . '/local/elisprogram/lib/setup.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/curriculumcourse.class.php'); require_once elispm::lib('data/curriculumstudent.class.php'); require_once elispm::lib('data/pmclass.class.php'); require_once elispm::lib('data/student.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'); // Make sure no emails are sent. set_config('noemailever', true); // Set up data. // Test user. $user = new user(array('idnumber' => 'testuseridnumber', 'username' => 'testuserusername', 'firstname' => 'testuserfirstname', 'firstname' => 'testuserfirstname', 'lastname' => 'testuserlastname', 'email' => '*****@*****.**', 'country' => 'CA')); $user->save(); // Test user set. $userset = new userset(array('name' => 'testusersetname')); $userset->save(); // Test program and track. $program = new curriculum(array('idnumber' => 'testprogramidnumber')); $program->save(); $track = new track(array('curid' => $program->id, 'idnumber' => 'testtrackidnumber')); $track->save(); // Associate the userset to the track. $clustertrack = new clustertrack(array('clusterid' => $userset->id, 'trackid' => $track->id, 'autoenrol' => 1)); $clustertrack->save(); // Test course and class. $course = new course(array('name' => 'testcoursename', 'idnumber' => 'testcourseidnumber', 'syllabus' => '')); $course->save(); $class = new pmclass(array('courseid' => $course->id, 'idnumber' => 'testclass1idnumber')); $class->save(); // Associate course to the program. $curriculumcourse = new curriculumcourse(array('curriculumid' => $program->id, 'courseid' => $course->id)); $curriculumcourse->save(); // Associate track to the test class. $trackassignment = new trackassignment(array('trackid' => $track->id, 'classid' => $class->id, 'autoenrol' => 1)); $trackassignment->save(); // Run the assignment create action. $record = new stdClass(); $record->context = 'userset_testusersetname'; $record->user_username = '******'; $importplugin = rlip_dataplugin_factory::factory('dhimport_version1elis'); $importplugin->fslogger = new silent_fslogger(null); $importplugin->cluster_enrolment_create($record, 'bogus', 'testusersetname'); // Validation. // Userset assignment should trigger track assignment. $this->assertTrue($DB->record_exists(usertrack::TABLE, array('userid' => $user->id, 'trackid' => $track->id))); // Track assignment should trigger program assignment. $this->assertTrue($DB->record_exists(curriculumstudent::TABLE, array('userid' => $user->id, 'curriculumid' => $program->id))); // Track assignment should create a class enrolment. $this->assertTrue($DB->record_exists(student::TABLE, array('userid' => $user->id, 'classid' => $class->id))); }
/** * Validate that track-class associations can be created during a class instance * update action * * @param mixed $autoenrol The appropriate autoenrol value specified * @param int $dbautoenrol The value expected to be set in the db for autoenrol * @dataProvider autoenrol_provider */ public function test_associate_track_during_class_update($autoenrol, $dbautoenrol) { global $CFG, $DB; require_once $CFG->dirroot . '/local/elisprogram/lib/setup.php'; require_once elispm::lib('data/course.class.php'); require_once elispm::lib('data/curriculum.class.php'); require_once elispm::lib('data/curriculumcourse.class.php'); require_once elispm::lib('data/pmclass.class.php'); require_once elispm::lib('data/track.class.php'); // Create the course description. $course = new course(array('name' => 'testcoursename', 'idnumber' => 'testcourseidnumber', 'syllabus' => '')); $course->save(); // Create the class instance. $pmclass = new pmclass(array('courseid' => $course->id, 'idnumber' => 'testclassidnumber')); $pmclass->save(); // Create the curriculum / program. $curriculum = new curriculum(array('idnumber' => 'testcurriculumidnumber')); $curriculum->save(); // Associate the course description to the program. $curriculumcourse = new curriculumcourse(array('curriculumid' => $curriculum->id, 'courseid' => $course->id)); $curriculumcourse->save(); // Create the track. $track = new track(array('curid' => $curriculum->id, 'idnumber' => 'testtrackidnumber')); $track->save(); // Run the class instance update action. $record = new stdClass(); $record->assignment = 'testcourseidnumber'; $record->idnumber = 'testclassidnumber'; $record->track = 'testtrackidnumber'; if ($autoenrol !== null) { $record->autoenrol = $autoenrol; } $importplugin = rlip_dataplugin_factory::factory('dhimport_version1elis'); $importplugin->fslogger = new silent_fslogger(null); $importplugin->class_update($record, 'bogus'); // Validation. $classid = $DB->get_field(pmclass::TABLE, 'id', array('idnumber' => 'testclassidnumber')); $this->assertTrue($DB->record_exists(trackassignment::TABLE, array('trackid' => $track->id, 'classid' => $classid, 'autoenrol' => $dbautoenrol))); }
/** * Initialize a new track object * @param int $curid A curriculum record ID */ protected function inittrack($curid) { $data = array('curid' => $curid, 'idnumber' => '__fcH__TESTID001__', 'name' => 'Test Track 1'); $newtrack = new track($data); $newtrack->save(); $this->ttrackid = $newtrack->id; }
/** * Validate that mappings are applied during the class instance update action */ public function test_mapping_applied_during_class_update() { global $CFG, $DB; require_once $CFG->dirroot . '/course/lib.php'; require_once $CFG->dirroot . '/local/eliscore/lib/data/customfield.class.php'; require_once $CFG->dirroot . '/local/elisprogram/accesslib.php'; require_once $CFG->dirroot . '/local/elisprogram/lib/data/classmoodlecourse.class.php'; require_once $CFG->dirroot . '/local/elisprogram/lib/data/course.class.php'; require_once $CFG->dirroot . '/local/elisprogram/lib/data/curriculum.class.php'; require_once $CFG->dirroot . '/local/elisprogram/lib/data/pmclass.class.php'; require_once $CFG->dirroot . '/local/elisprogram/lib/data/track.class.php'; $this->init_mapping(); $customfieldid = $this->create_custom_field(CONTEXT_ELIS_CLASS); $pmcourse = new course(array('name' => 'testcoursename', 'idnumber' => 'testcourseidnumber', 'syllabus' => '')); $pmcourse->save(); $program = new curriculum(array('idnumber' => 'testprogramidnumber')); $program->save(); $track = new track(array('curid' => $program->id, 'idnumber' => 'testtrackidnumber')); $track->save(); $category = new stdClass(); $category->name = 'testcategoryname'; $category->id = $DB->insert_record('course_categories', $category); $course = new stdClass(); $course->category = $category->id; $course->shortname = 'testcourseshortname'; $course->fullname = 'testcoursefullname'; $course = create_course($course); $pmclass = new pmclass(array('courseid' => $pmcourse->id, 'idnumber' => 'testclassidnumber')); $pmclass->save(); // Run the class create update. $record = new stdClass(); $record->customaction = 'update'; $record->customcontext = 'class'; $record->customidnumber = 'testclassidnumber'; $record->customstartdate = 'Jan/02/2012'; $record->customenddate = 'Jan/02/2012'; $record->customstarttimehour = '2'; $record->customstarttimeminute = '10'; $record->customendtimehour = '2'; $record->customendtimeminute = '10'; $record->custommaxstudents = '2'; $record->customenrol_from_waitlist = '1'; $record->customassignment = 'testcourseidnumber'; $record->customtrack = 'testtrackidnumber'; $record->customautoenrol = '1'; $record->customlink = 'testcourseshortname'; $record->customtestfieldshortname = '1'; $this->run_pmentity_import((array) $record); // Validation. $data = array('courseid' => $pmcourse->id, 'idnumber' => 'testclassidnumber', 'startdate' => rlip_timestamp(0, 0, 0, 1, 2, 2012), 'enddate' => rlip_timestamp(0, 0, 0, 1, 2, 2012), 'starttimehour' => 2, 'starttimeminute' => 10, 'endtimehour' => 2, 'endtimeminute' => 10, 'maxstudents' => 2, 'enrol_from_waitlist' => 1); $this->assertTrue($DB->record_exists(pmclass::TABLE, $data)); $this->assertTrue($DB->record_exists(trackassignment::TABLE, array('classid' => $pmclass->id, 'trackid' => $track->id, 'autoenrol' => 1))); $this->assertTrue($DB->record_exists(classmoodlecourse::TABLE, array('classid' => $pmclass->id, 'moodlecourseid' => $course->id))); $instance = \local_elisprogram\context\pmclass::instance(1); $this->assertTrue($DB->record_exists(field_data_int::TABLE, array('fieldid' => $customfieldid, 'contextid' => $instance->id, 'data' => 1))); }
/** * Create an ELIS track * @param curriculum &$cur An ELIS program to assign the track to. * @param field &$field A custom field to set when creating program. * @return track The created track. */ public function create_track(curriculum &$cur, field &$field) { $data = new stdClass(); $data->curid = $cur->id; $data->idnumber = 'TRK1'; $data->name = 'Track 1'; $data->description = 'Track Description'; $data->startdate = 0; $data->enddate = '0'; $fieldvar = 'field_' . $field->shortname; $data->{$fieldvar} = 'test field data'; $trk = new track(); $trk->set_from_data($data); $trk->save(); return $trk; }
/** * Validate that users can be unenrolled from tracks * * @param string $username A sample user's username, or null if not used in the import * @param string $email A sample user's email, or null if not used in the import * @param string $idnumber A sample user's idnumber, or null if not used in the import * @dataProvider user_identifier_provider */ public function test_elis_user_track_unenrolment_import($actioncreate, $actiondelete, $username, $email, $idnumber) { global $CFG, $DB; require_once $CFG->dirroot . '/local/elisprogram/lib/setup.php'; require_once elispm::lib('data/curriculum.class.php'); require_once elispm::lib('data/track.class.php'); require_once elispm::lib('data/user.class.php'); require_once elispm::lib('data/usertrack.class.php'); $user = new user(array('idnumber' => 'testuseridnumber', 'username' => 'testuserusername', 'firstname' => 'testuserfirstname', 'lastname' => 'testuserlastname', 'email' => '*****@*****.**', 'country' => 'CA')); $user->save(); $program = new curriculum(array('idnumber' => 'testprogramidnumber')); $program->save(); $track = new track(array('curid' => $program->id, 'idnumber' => 'testtrackidnumber')); $track->save(); $usertrack = new usertrack(array('userid' => $user->id, 'trackid' => $track->id)); $usertrack->save(); // Validate setup. $this->assertTrue($DB->record_exists(usertrack::TABLE, array('userid' => $user->id, 'trackid' => $track->id))); // Run the track enrolment delete action. $record = new stdClass(); $record->action = $actiondelete; $record->context = 'track_testtrackidnumber'; if ($username != null) { $record->user_username = $user->username; } if ($email != null) { $record->user_email = $user->email; } if ($idnumber != null) { $record->user_idnumber = $user->idnumber; } $importplugin = rlip_dataplugin_factory::factory('dhimport_version1elis'); $importplugin->fslogger = new silent_fslogger(null); $importplugin->process_record('enrolment', (object) $record, 'bogus'); // Validation. $this->assertEquals(0, $DB->count_records(usertrack::TABLE)); }
function track_update($record, $filename) { global $DB, $CFG; $message = ""; //field length checking $lengthcheck = $this->check_track_field_lengths($record, $filename); if (!$lengthcheck) { return false; } if (isset($record->idnumber)) { if (isset($record->assignment)) { $message = "track with idnumber \"{$record->idnumber}\" was not re-assigned to program with idnumber \"{$record->assignment}\" because moving tracks between programs is not supported."; } if (!($id = $DB->get_field(track::TABLE, 'id', array('idnumber' => $record->idnumber)))) { $this->fslogger->log_failure("idnumber value of \"{$record->idnumber}\" does not refer to a valid track.", 0, $filename, $this->linenumber, $record, "track"); return false; } } if (!$this->validate_track_data('update', $record, $filename)) { return false; } $record = $this->add_custom_field_prefixes($record); //custom field validation if (!$this->validate_custom_field_data('update', $record, $filename, 'track')) { return false; } $record->id = $id; $record->timemodified = time(); $track = new track(); $track->set_from_data($record); $track->save(); //log success $success_message = "Track with idnumber \"{$record->idnumber}\" successfully updated."; $this->fslogger->log_success($success_message, 0, $filename, $this->linenumber); return true; }
/** * Validate that create actions are converted to updates for tracks when the * "createorupdate" flag is enabled */ public function test_elis_createorupdate_updates_track() { global $CFG, $DB; require_once $CFG->dirroot . '/local/elisprogram/lib/data/curriculum.class.php'; require_once $CFG->dirroot . '/local/elisprogram/lib/data/track.class.php'; // Set up initial conditions. set_config('createorupdate', 1, 'dhimport_version1elis'); $program = new curriculum(array('name' => 'testprogramname', 'idnumber' => 'testprogramidnumber')); $program->save(); // Create the test track. $track = new track(array('curid' => $program->id, 'name' => 'testtrackname', 'idnumber' => 'testtrackidnumber', 'startdate' => rlip_timestamp(0, 0, 0, 1, 1, 2012))); $track->save(); // Run the track create action. $record = new stdClass(); $record->action = 'create'; $record->context = 'track'; $record->idnumber = 'testtrackidnumber'; $record->startdate = 'Jan/02/2012'; $importplugin = rlip_dataplugin_factory::factory('dhimport_version1elis'); $importplugin->fslogger = new silent_fslogger(null); $importplugin->process_record('course', $record, 'bogus'); // Validation. $this->assertTrue($DB->record_exists(track::TABLE, array('name' => 'testtrackname', 'idnumber' => 'testtrackidnumber', 'startdate' => rlip_timestamp(0, 0, 0, 1, 2, 2012)))); }
/** * Clone a track * @param array $options options for cloning. Valid options are: * - 'targetcurriculum': the curriculum id to associate the clones with * (default: same as original track) * - 'classmap': a mapping of class IDs to use from the original track to * the cloned track. If a class from the original track is not mapped, a * new class will be created * - 'moodlecourse': whether or not to clone Moodle courses (if they were * autocreated). Values can be (default: "copyalways"): * - "copyalways": always copy course * - "copyautocreated": only copy autocreated courses * - "autocreatenew": autocreate new courses from course template * - "link": link to existing course * @return array array of array of object IDs created. Key in outer array * is type of object (plural). Key in inner array is original object ID, * value is new object ID. Outer array also has an entry called 'errors', * which is an array of any errors encountered when duplicating the * object. */ function duplicate(array $options = array()) { $objs = array('errors' => array()); if (isset($options['targetcluster'])) { $userset = $options['targetcluster']; if (!is_object($userset) || !is_a($userset, 'userset')) { $options['targetcluster'] = $userset = new userset($userset); } } // Due to lazy loading, we need to pre-load this object $this->load(); // clone main track object $clone = new track($this); unset($clone->id); if (isset($options['targetcurriculum'])) { $clone->curid = $options['targetcurriculum']; } $idnumber = $clone->idnumber; $name = $clone->name; if (isset($userset)) { $to_append = ' - ' . $userset->name; // if cluster specified, append cluster's name to course $idnumber = append_once($idnumber, $to_append, array('maxlength' => 95)); $name = append_once($name, $to_append, array('maxlength' => 250)); } //get a unique idnumber $clone->idnumber = generate_unique_identifier(track::TABLE, 'idnumber', $idnumber, array('idnumber' => $idnumber)); if ($clone->idnumber != $idnumber) { //get the suffix appended and add it to the name $parts = explode('.', $clone->idnumber); $suffix = end($parts); $clone->name = $name . '.' . $suffix; } else { $clone->name = $name; } $clone->autocreate = false; // avoid warnings $clone->save(); $objs['tracks'] = array($this->id => $clone->id); // associate with target cluster (if any) if (isset($userset)) { clustertrack::associate($userset->id, $clone->id); } // copy classes $clstrks = track_assignment_get_listing($this->id); if ($clstrks->valid() === true) { $objs['classes'] = array(); if (!isset($options['classmap'])) { $options['classmap'] = array(); } foreach ($clstrks as $clstrkdata) { $newclstrk = new trackassignment($clstrkdata); $newclstrk->trackid = $clone->id; unset($newclstrk->id); if (isset($options['classmap'][$clstrkdata->clsid])) { // use existing duplicate class $class = new pmclass($options['classmap'][$clstrkdata->clsid]); } else { // no existing duplicate -> duplicate class $class = new pmclass($clstrkdata->clsid); $rv = $class->duplicate($options); if (isset($rv['errors']) && !empty($rv['errors'])) { $objs['errors'] = array_merge($objs['errors'], $rv['errors']); } if (isset($rv['classes'])) { $objs['classes'] = $objs['classes'] + $rv['classes']; } } $newclstrk->classid = $class->id; $newclstrk->courseid = $class->courseid; $newclstrk->save(); } } unset($clstrks); return $objs; }
/** * Test creating a new track entity with a default role assignment defined. */ public function test_createtrackwithdefaultroleassignment() { global $DB, $USER; list($rcid, $reid) = $this->create_roles('track'); // Setup the editor role to be the default role for the track context. elis::$config->local_elisprogram->default_track_role_id = $reid; $sysctx = context_system::instance(); // Assign the test user the creator role. role_assign($rcid, $USER->id, $sysctx->id); // Create a new track entity. $data = array('curid' => '1', 'idnumber' => 'track100', 'name' => 'track100', 'description' => 'track100'); $obj = new track($data); $obj->save(); // Initialize a new track management page and invoke the code that handles default role assignments. $page = new trackpage(); $page->after_cm_entity_add($obj); $trackctx = \local_elisprogram\context\track::instance($obj->id); $params = array('roleid' => $reid, 'userid' => $USER->id, 'contextid' => $trackctx->id); $this->assertTrue($DB->record_exists('role_assignments', $params)); }
/** * Performs track update * @throws moodle_exception If there was an error in passed parameters. * @throws data_object_exception If there was an error creating the entity. * @param array $data The incoming data parameter. * @return array An array of parameters, if successful. */ public static function track_update(array $data) { global $USER, $DB; if (static::require_elis_dependencies() !== true) { throw new moodle_exception('ws_function_requires_elis', 'local_datahub'); } // Parameter validation. $params = self::validate_parameters(self::track_update_parameters(), array('data' => $data)); // Context validation. $context = context_user::instance($USER->id); self::validate_context($context); $data = (object) $data; $record = new stdClass(); $record = $data; // need all custom fields, etc. // Initialize version1elis importplugin for utility functions. $importplugin = rlip_dataplugin_factory::factory('dhimport_version1elis'); // Validate if (empty($data->idnumber) || !($trkid = $DB->get_field(track::TABLE, 'id', array('idnumber' => $data->idnumber)))) { throw new data_object_exception('ws_track_update_fail_invalid_idnumber', 'local_datahub', '', $data); } unset($record->idnumber); // Capability checking. require_capability('local/elisprogram:track_edit', \local_elisprogram\context\track::instance($trkid)); if (isset($data->startdate)) { $startdate = $importplugin->parse_date($data->startdate); if (empty($startdate)) { throw new data_object_exception('ws_track_update_fail_invalid_startdate', 'local_datahub', '', $data); } else { $record->startdate = $startdate; } } if (isset($data->enddate)) { $enddate = $importplugin->parse_date($data->enddate); if (empty($enddate)) { throw new data_object_exception('ws_track_update_fail_invalid_enddate', 'local_datahub', '', $data); } else { $record->enddate = $enddate; } } $track = new track($trkid); $track->load(); $track->set_from_data($record); $track->save(); // Respond. if (!empty($track->id)) { $trackrec = (array) $DB->get_record(track::TABLE, array('id' => $track->id)); $trackobj = $track->to_array(); // convert multi-valued custom field arrays to comma-separated listing $fields = self::get_track_custom_fields(); foreach ($fields as $field) { // Generate name using custom field prefix. $fullfieldname = data_object_with_custom_fields::CUSTOM_FIELD_PREFIX . $field->shortname; if ($field->multivalued && isset($trackobj[$fullfieldname]) && is_array($trackobj[$fullfieldname])) { $trackobj[$fullfieldname] = implode(',', $trackobj[$fullfieldname]); } } return array('messagecode' => get_string('ws_track_update_success_code', 'local_datahub'), 'message' => get_string('ws_track_update_success_msg', 'local_datahub'), 'record' => array_merge($trackrec, $trackobj)); } else { throw new data_object_exception('ws_track_update_fail', 'local_datahub'); } }
/** * Test failure conditions. * @dataProvider dataprovider_failure * @expectedException moodle_exception * @param array $track The incoming track data. */ public function test_failure(array $track) { global $DB; $this->give_permissions(array('local/elisprogram:track_create')); // Setup program. $datagen = new elis_program_datagenerator($DB); $program = $datagen->create_program(array('idnumber' => 'test_program_idnumber', 'name' => 'ProgramName')); // Setup duplicate track. $duptrk = new track(array('idnumber' => 'DupTrackIdnumber', 'name' => 'DupTrackName', 'curid' => $program->id)); $duptrk->save(); $response = local_datahub_elis_track_create::track_create($track); }
/** * Validate that mappings are applied during the track enrolment delete action */ public function test_mapping_applied_during_track_enrolment_delete() { global $CFG, $DB; require_once $CFG->dirroot . '/local/elisprogram/lib/data/curriculum.class.php'; require_once $CFG->dirroot . '/local/elisprogram/lib/data/track.class.php'; $this->init_mapping(); $userid = $this->create_test_user(); $program = new curriculum(array('idnumber' => 'testprogramidnumber')); $program->save(); $track = new track(array('curid' => $program->id, 'idnumber' => 'testtrackidnumber')); $track->save(); $usertrack = new usertrack(array('trackid' => $track->id, 'userid' => $userid)); $usertrack->save(); // Run the track enrolment delete action. $record = new stdClass(); $record->customaction = 'delete'; $record->customcontext = 'track_testtrackidnumber'; $record->customuser_username = '******'; $record->customuser_email = '*****@*****.**'; $record->customuser_idnumber = 'testuseridnumber'; $this->run_enrolment_import((array) $record); // Validation. $this->assertEquals(0, $DB->count_records(usertrack::TABLE)); }
/** * Tests contexts in track data object. * * Covers: * local/elisprogram/lib/data/track.class.php:291 */ public function test_deletetrack() { $this->setup_curriculum(); $data = new stdClass(); $data->curid = 1; $data->idnumber = 'TRK1'; $data->name = 'Track 1'; $data->description = 'Track Description'; $data->startdate = 0; $data->enddate = '0'; $trk = new track(); $trk->set_from_data($data); $trk->save(); $trk = new track($trk->id); $trk->delete(); }
/** * Validate that deleting a userset deletes all appropriate associations */ public function test_delete_elis_userset_deletes_associations() { global $CFG, $DB; // Entities. require_once $CFG->dirroot . '/local/elisprogram/lib/setup.php'; require_once elispm::lib('data/userset.class.php'); require_once elispm::lib('data/user.class.php'); require_once elispm::lib('data/curriculum.class.php'); require_once elispm::lib('data/track.class.php'); require_once elis::lib('data/customfield.class.php'); // Associations. require_once elispm::lib('data/clusterassignment.class.php'); require_once elispm::lib('data/clustercurriculum.class.php'); require_once elispm::lib('data/clustertrack.class.php'); require_once elispm::file('enrol/userset/moodleprofile/userset_profile.class.php'); // For context level access. require_once elispm::file('accesslib.php'); $origfieldcount = $DB->count_records(field::TABLE); // Set up user set. $userset = new userset(array('name' => 'testusersetname')); $userset->save(); // Set up other entities and associations. // Cluster enrolment. $user = new user(array('idnumber' => 'testuseridnumber', 'username' => 'testuserusername', 'firstname' => 'testuserfirstname', 'lastname' => 'testuserlastname', 'email' => '*****@*****.**', 'country' => 'CA')); $user->save(); $clusterassignment = new clusterassignment(array('clusterid' => $userset->id, 'userid' => $user->id)); $clusterassignment->save(); // Cluster-curriculum assignment. $curriculum = new curriculum(array('idnumber' => 'testcurriculumidnumber')); $curriculum->save(); $clustercurriculum = new clustercurriculum(array('clusterid' => $userset->id, 'curriculumid' => $curriculum->id)); $clustercurriculum->save(); // Cluster-track assignment. $track = new track(array('curid' => $curriculum->id, 'idnumber' => 'testtrackidnumber')); $track->save(); $clustertrack = new clustertrack(array('clusterid' => $userset->id, 'trackid' => $track->id)); $clustertrack->save(); // Custom field. $field = new field(array('name' => 'testfieldname', 'categoryid' => 9999)); $field->save(); $context = \local_elisprogram\context\userset::instance($userset->id); $data = new field_data_int(array('contextid' => $context->id, 'fieldid' => $field->id, 'data' => 1)); $data->save(); // Cluster profile criteria. $clusterprofile = new userset_profile(array('clusterid' => $userset->id, 'fieldid' => $field->id, 'value' => 0)); $clusterprofile->save(); // Validate setup. $this->assertEquals(1, $DB->count_records(userset::TABLE)); $this->assertEquals(1, $DB->count_records(user::TABLE)); $this->assertEquals(1, $DB->count_records(clusterassignment::TABLE)); $this->assertEquals(1, $DB->count_records(curriculum::TABLE)); $this->assertEquals(1, $DB->count_records(clustercurriculum::TABLE)); $this->assertEquals(1, $DB->count_records(track::TABLE)); $this->assertEquals(1, $DB->count_records(clustertrack::TABLE)); $this->assertEquals(1 + $origfieldcount, $DB->count_records(field::TABLE)); $this->assertEquals(1, $DB->count_records(field_data_int::TABLE)); $this->assertEquals(1, $DB->count_records(userset_profile::TABLE)); // Run the import. $data = array('action' => 'delete'); $this->run_core_userset_import($data, true); // Validation. $this->assertEquals(0, $DB->count_records(userset::TABLE)); $this->assertEquals(1, $DB->count_records(user::TABLE)); $this->assertEquals(0, $DB->count_records(clusterassignment::TABLE)); $this->assertEquals(1, $DB->count_records(curriculum::TABLE)); $this->assertEquals(0, $DB->count_records(clustercurriculum::TABLE)); $this->assertEquals(1, $DB->count_records(track::TABLE)); $this->assertEquals(0, $DB->count_records(clustertrack::TABLE)); $this->assertEquals(1 + $origfieldcount, $DB->count_records(field::TABLE)); $this->assertEquals(0, $DB->count_records(field_data_int::TABLE)); $this->assertEquals(0, $DB->count_records(userset_profile::TABLE)); }
/** * 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')); }