public function __construct($id = -1) { if (is_null(self::$conn)) { self::$conn = mysqli_connect('localhost', 'root', 'iti', 'itians'); } if ($id != -1) { $query = "select * from track where id={$id} "; $result = mysqli_query(self::$conn, $query); $track = mysqli_fetch_assoc($result); $this->id = $track['id']; $this->name = $track['name ']; $this->sup_id = $track['psup_id ']; $this->no_course = $track['pno_course']; $this->no_stud = $track['no_stud']; $this->leader_id = $track['leader_id']; } }
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(); } }
/** * 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 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)); }
/** * 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)); }
/** * Performs track delete * @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_delete(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_delete_parameters(), array('data' => $data)); // Context validation. $context = context_user::instance($USER->id); self::validate_context($context); $data = (object) $data; // Validate if (empty($data->idnumber) || !($trkid = $DB->get_field(track::TABLE, 'id', array('idnumber' => $data->idnumber)))) { throw new data_object_exception('ws_track_delete_fail_invalid_idnumber', 'local_datahub', '', $data); } // Capability checking. require_capability('local/elisprogram:track_delete', \local_elisprogram\context\track::instance($trkid)); $track = new track($trkid); $track->delete(); // Verify deletion & respond. if (!$DB->record_exists(track::TABLE, array('idnumber' => $data->idnumber))) { return array('messagecode' => get_string('ws_track_delete_success_code', 'local_datahub'), 'message' => get_string('ws_track_delete_success_msg', 'local_datahub')); } else { throw new data_object_exception('ws_track_delete_fail', 'local_datahub'); } }
/** * Test successful track update */ public function test_success() { global $DB; // Create custom field. $fieldcat = new field_category(); $fieldcat->name = 'Test'; $fieldcat->save(); $field = new field(); $field->categoryid = $fieldcat->id; $field->shortname = 'testfield'; $field->name = 'Test Field'; $field->datatype = 'text'; $field->save(); $fieldctx = new field_contextlevel(); $fieldctx->fieldid = $field->id; $fieldctx->contextlevel = CONTEXT_ELIS_TRACK; $fieldctx->save(); $this->give_permissions(array('local/elisprogram:track_edit')); // Setup program and track. $datagen = new elis_program_datagenerator($DB); $program = $datagen->create_program(array('idnumber' => 'test_program_idnumber', 'name' => 'ProgramName')); $track = $datagen->create_track(array('idnumber' => 'testtrack', 'name' => 'testtrackname', 'curid' => $program->id)); // Perform update. $trackupdatedata = array('idnumber' => $track->idnumber, 'name' => 'testtrackname_changed', 'description' => 'testtrack description', 'field_testfield' => 'Test field'); $response = local_datahub_elis_track_update::track_update($trackupdatedata); $this->assertNotEmpty($response); $this->assertInternalType('array', $response); $this->assertArrayHasKey('messagecode', $response); $this->assertArrayHasKey('message', $response); $this->assertArrayHasKey('record', $response); $this->assertEquals(get_string('ws_track_update_success_code', 'local_datahub'), $response['messagecode']); $this->assertEquals(get_string('ws_track_update_success_msg', 'local_datahub'), $response['message']); $this->assertInternalType('array', $response['record']); $this->assertArrayHasKey('id', $response['record']); // Get Track. $updatedtrk = new track($response['record']['id']); $updatedtrk->load(); $updatedtrk = $updatedtrk->to_array(); $expecttrk = array('id' => $response['record']['id'], 'idnumber' => 'testtrack', 'name' => 'testtrackname_changed', 'curid' => $program->id, 'description' => 'testtrack description', 'field_testfield' => 'Test field'); foreach ($expecttrk as $param => $val) { $this->assertArrayHasKey($param, $updatedtrk); $this->assertEquals($val, $updatedtrk[$param]); } }
/** * 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}%"))); }
} $pathh = "/var/www/StartSync.php {$auth_id['id']} '0.0.0.0' {$new_port}"; error_log("Starting Sync server on port {$new_port} for ID: {$auth_id['id']}"); exec("php -f {$pathh} >/dev/null &"); sleep(2); $results['connection'] = array('ip' => '66.228.33.88', 'port' => $new_port); RestUtils::sendResponse(200, json_encode($results), 'application/json'); } if (isset($get_data['role']) && $get_data['role'] == 'slave') { $active_masters = $auth->get_active_masters('login, id, server_pid, port'); $active_masters_res = array(); foreach ($active_masters as $val) { if (!file_exists("/proc/{$val['server_pid']}")) { $auth->update_auth($val['id'], array('active' => 'no', 'server_pid' => null, 'port' => null)); } else { $active_masters_res[] = array('login' => $val['login'], 'id' => $val['id'], 'server_url' => '66.228.33.88', 'port' => $val['port']); } } if (isset($get_data['master_id'])) { $playlist = new playlist($dbcon); $track = new track($dbcon); $get_playlist = $playlist->get_slave_playlist($get_data['master_id'], 'id, title, description, last_update'); $get_tracks = $track->get_slave_tracks($get_playlist['id'], 't.*'); $get_playlist['tracks'] = $get_tracks; RestUtils::sendResponse(200, json_encode($get_playlist), 'application/json'); } RestUtils::sendResponse(200, json_encode($active_masters_res), 'application/json'); } } break; }
/** * Test to ensure that the auto-generated class ID number values do not overflow the maximum length of the * local_elisprogram_cls.idnumber field when multiple copies of the same class are created which require an incrementing iterator * to be appended to the idnumber value are used. */ public function test_trackautocreatevalidation_doesnotoverflowidnumberfieldwithiterators() { global $DB; $this->load_csv_data(); // Need track and userset. $userset = new stdClass(); $userset->id = 1; $userset->name = 'test'; // Set values required for auto create. $track = new track(5); $track->load(); // Testing track auto create. $track->track_auto_create(); // Force duplicate classes to be created which should have a unique iterator added to the idnumber field and // still be within the allowable field size. $track->track_auto_create(); $track->track_auto_create(); // Get most recent class records created. $records = $DB->get_records('local_elisprogram_cls', array(), "id DESC", 'id, idnumber', 0, 3); // We want to test in the order they were created. $records = array_reverse($records); $expectedvalue = substr('test-' . $track->idnumber, 0, 95); $iterator = 0; foreach ($records as $record) { $this->assertEquals($expectedvalue . ($iterator > 0 ? '.' . $iterator : ''), $record->idnumber); $iterator++; } }
/** * 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_delete($record, $filename) { global $DB, $CFG; if (isset($record->idnumber)) { if (!($track = $DB->get_record(track::TABLE, 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; } } $track = new track($track); $track->delete(); //log success $success_message = "Track with idnumber \"{$record->idnumber}\" successfully deleted."; $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)))); }
/** * 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'); }
/** * Assign a class to a track, this function also creates * and assigns the class to the curriculum default track * * @return TODO: add meaningful return value */ function add() { global $CURMAN; if (empty($this->courseid)) { $this->courseid = $CURMAN->db->get_field(CLSTABLE, 'courseid', 'id', $this->classid); } if ((empty($this->trackid) or empty($this->classid) or empty($this->courseid)) and empty($CURMAN->config->userdefinedtrack)) { cm_error('trackid and classid have not been properly initialized'); return false; } elseif ((empty($this->courseid) or empty($this->classid)) and $CURMAN->config->userdefinedtrack) { cm_error('courseid has not been properly initialized'); } if (empty($CURMAN->config->userdefinedtrack)) { if ($this->is_class_assigned_to_track()) { return false; } // Determine whether class is required $curcrsobj = new curriculumcourse(array('curriculumid' => $this->track->curid, 'courseid' => $this->classid)); // insert assignment record $this->data_insert_record(); if ($this->autoenrol && $this->is_autoenrollable()) { // autoenrol all users in the track $users = usertrack::get_users($this->trackid); if (!empty($users)) { foreach ($users as $user) { $stu_record = new object(); $stu_record->userid = $user->userid; $stu_record->user_idnumber = $user->idnumber; $stu_record->classid = $this->classid; $stu_record->enrolmenttime = time(); $enrolment = new student($stu_record); // check prerequisites and enrolment limits $enrolment->add(array('prereq' => 1, 'waitlist' => 1)); } } } } else { // Look for all the curricula course is linked to - // then pull up the default system track for each curricula - // and add class to each default system track $currculums = curriculumcourse_get_list_by_course($this->courseid); $currculums = is_array($currculums) ? $currculums : array(); foreach ($currculums as $recid => $record) { // Create default track for curriculum $trkojb = new track(array('curid' => $record->curriculumid)); $trkid = $trkojb->create_default_track(); // Create track assignment object $trkassign = new trackassignmentclass(array('trackid' => $trkid, 'classid' => $this->classid, 'courseid' => $this->courseid)); // Check if class is already assigned to default track if (!$trkassign->is_class_assigned_to_default_track()) { // Determine whether class is required $curcrsobj = new curriculumcourse(array('curriculumid' => $trkassign->track->curid, 'courseid' => $trkassign->courseid)); // Get required field and determine if class is autoenrol eligible $trkassign->autoenrol = (1 == $trkassign->cmclass->count_course_assignments($trkassign->cmclass->courseid) and true === $curcrsobj->is_course_required()) ? 1 : 0; // assign class to the curriculum's default track $trkassign->assign_class_to_default_track(); } } } events_trigger('crlm_track_class_associated', $this); return true; }
/** * 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 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))); }
/** * 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)); }
/** * Clone a curriculum. * @param array $options options for cloning. Valid options are: * - 'tracks': whether or not to clone tracks (default: false) * - 'courses': whether or not to clone courses (default: false) * - 'classes': whether or not to clone classes (default: false) * - 'moodlecourses': 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 * - 'targetcluster': the cluster id or cluster object (if any) to * associate the clones with (default: none) * @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($options = array()) { require_once CURMAN_DIRLOCATION . '/lib/track.class.php'; $objs = array('errors' => array()); if (isset($options['targetcluster'])) { $cluster = $options['targetcluster']; if (!is_object($cluster) || !is_a($cluster, 'cluster')) { $options['targetcluster'] = $cluster = new cluster($cluster); } } // clone main curriculum object $clone = new curriculum($this); unset($clone->id); if (isset($cluster)) { // if cluster specified, append cluster's name to curriculum $clone->name = $clone->name . ' - ' . $cluster->name; $clone->idnumber = $clone->idnumber . ' - ' . $cluster->name; } $clone = new curriculum(addslashes_recursive($clone)); if (!$clone->add()) { $objs['errors'][] = get_string('failclustcpycurr', 'block_curr_admin', $this); return $objs; } $objs['curricula'] = array($this->id => $clone->id); $options['targetcurriculum'] = $clone->id; // associate with target cluster (if any) if (isset($cluster)) { clustercurriculum::associate($cluster->id, $clone->id); } if (!empty($options['courses'])) { // copy courses $currcrs = curriculumcourse_get_list_by_curr($this->id); if (!empty($currcrs)) { $objs['courses'] = array(); $objs['classes'] = array(); foreach ($currcrs as $currcrsdata) { $course = new course($currcrsdata->courseid); $rv = $course->duplicate($options); if (isset($rv['errors']) && !empty($rv['errors'])) { $objs['errors'] = array_merge($objs['errors'], $rv['errors']); } if (isset($rv['courses'])) { $objs['courses'] = $objs['courses'] + $rv['courses']; } if (isset($rv['classes'])) { $objs['classes'] = $objs['classes'] + $rv['classes']; } // associate with curriculum if (isset($rv['courses'][$course->id])) { $curcrs = new curriculumcourse($currcrsdata); unset($curcrs->id); $curcrs->courseid = $rv['courses'][$course->id]; $curcrs->curriculumid = $clone->id; $curcrs->add(); } } } } if (!empty($objs['errors'])) { return $objs; } if (!empty($options['tracks'])) { // copy tracks $tracks = track_get_listing('name', 'ASC', 0, 0, '', '', $this->id); if (isset($objs['courses'])) { $options['coursemap'] = $objs['courses']; } if (!empty($tracks)) { $objs['tracks'] = array(); if (isset($objs['courses'])) { $options['coursemap'] = $objs['courses']; } if (!isset($objs['classes'])) { $objs['classes'] = array(); } foreach ($tracks as $track) { $track = new track($track); $options['classmap'] = $objs['classes']; $rv = $track->duplicate($options); if (isset($rv['errors']) && !empty($rv['errors'])) { $objs['errors'] = array_merge($objs['errors'], $rv['errors']); } if (isset($rv['tracks'])) { $objs['tracks'] = $objs['tracks'] + $rv['tracks']; } if (isset($rv['classes'])) { $objs['classes'] = $objs['classes'] + $rv['classes']; } } } } return $objs; }
/** * Do autocreate classes action. */ public function do_autocreate() { // TBD: display_autocreate() for error messages? $id = required_param('id', PARAM_INT); $track = new track($id); $track->track_auto_create(); $tmppage = new trackassignmentpage(array('id' => $id)); redirect($tmppage->url, get_string('track_success_autocreate', 'local_elisprogram')); }
/** * 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); }
/** * 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; }
/** * 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 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))); }
function __construct() { if (self::$redis === NULL) { self::$redis = new Predis\Client(); } }
function pm_course_complete($enrolment) { track::check_autoenrol_after_course_completion($enrolment); waitlist::check_autoenrol_after_course_completion($enrolment); return true; }
function action_autocreate() { $id = required_param('id', PARAM_INT); $track = new track($id); $track->track_auto_create(); $tmppage = new trackassignmentpage(array('id' => $id)); redirect($tmppage->get_url(), get_string('success_autocreate', 'block_curr_admin')); }