Example #1
0
 function can_do_default()
 {
     global $USER;
     $id = $this->required_param('id', PARAM_INT);
     // TODO: Ugly, this needs to be overhauled
     $cpage = new pmclasspage();
     return $cpage->_has_capability('local/elisreports:view', $id) || instructor::user_is_instructor_of_class(cm_get_crlmuserid($USER->id), $id);
 }
 /**
  * Enrol the instructors associated with the class into the attached Moodle
  * course.
  *
  * @param none
  * @return bool True on success, False otherwise.
  */
 function data_enrol_instructors()
 {
     if (empty($this->classid) || empty($this->moodlecourseid) || !empty($this->siteconfig) && !file_exists($this->siteconfig)) {
         return false;
     }
     $instructors = instructor::find(new field_filter('classid', $this->classid));
     if (elis::$config->local_elisprogram->default_instructor_role && $instructors->valid()) {
         /// At this point we must switch over the other Moodle site's DB config, if needed
         if (!empty($this->siteconfig)) {
             // TBD: implement this in the future if needed in v2
             //$cfgbak = moodle_load_config($this->siteconfig);
         }
         /// This has to be put here in case we have a site config reload.
         $CFG = $GLOBALS['CFG'];
         if (!($context = context_course::instance($this->moodlecourseid))) {
             return false;
         }
         $plugin = enrol_get_plugin('elis');
         $enrol = $plugin->get_or_create_instance($this->_db->get_record('course', array('id' => $this->moodlecourseid)));
         foreach ($instructors as $instructor) {
             /// Make sure that a Moodle account exists for this user already.
             $user = $instructor->users;
             if (!($muser = $user->get_moodleuser())) {
                 if (!($muserid = $user->synchronize_moodle_user(true, true))) {
                     throw new Exception(get_string('errorsynchronizeuser', self::LANG_FILE));
                 }
             } else {
                 $muserid = $muser->id;
             }
             if (!is_enrolled($context, $muserid)) {
                 $plugin->enrol_user($enrol, $muserid, elis::$config->local_elisprogram->default_instructor_role, 0, 0);
             }
         }
         /// Reset $CFG object.
         if (!empty($this->siteconfig)) {
             // TBD: implement this in the future if needed in v2
             //moodle_load_config($cfgbak->dirroot . '/config.php');
         }
     }
     $instructors->close();
     return true;
 }
 function get_item_display_instructor($column, $class)
 {
     if ($instructors = instructor::get_instructors($class->id)) {
         $ins = array();
         foreach ($instructors as $instructor) {
             $ins[] = elis_fullname($instructor);
         }
         return implode('<br />', $ins);
     }
     return get_string('course_catalog_time_na', 'local_elisprogram');
 }
Example #4
0
 /**
  * When a role is selected from the sync configuration, create class
  * enrolments for the specified role assignments.
  */
 static function instructor_sync_role_set()
 {
     require_once CURMAN_DIRLOCATION . '/lib/instructor.class.php';
     global $CURMAN;
     $contextlevel = context_level_base::get_custom_context_level('class', 'block_curr_admin');
     // find all class role assignments
     $sql = "SELECT ra.id, cu.id AS userid, ctx.instanceid AS classid\n                  FROM {$CURMAN->db->prefix_table('role_assignments')} ra\n                  JOIN {$CURMAN->db->prefix_table('user')} mu ON ra.userid = mu.id\n                  JOIN {$CURMAN->db->prefix_table('crlm_user')} cu ON mu.idnumber = cu.idnumber\n                  JOIN {$CURMAN->db->prefix_table('context')} ctx ON ctx.id = ra.contextid\n                 WHERE ctx.contextlevel = {$contextlevel}\n                   AND ra.roleid = {$CURMAN->config->enrolment_role_sync_instructor_role}";
     $instructorswanted = $CURMAN->db->get_records_sql($sql);
     $instructorswanted = $instructorswanted ? $instructorswanted : array();
     foreach ($instructorswanted as $instructor) {
         unset($instructor->id);
         if (!instructor::user_is_instructor_of_class($instructor->userid, $instructor->classid)) {
             $instructor = new instructor($instructor);
             $instructor->add();
         }
     }
     return true;
 }
 /**
  * Returns the edit ins form.
  *
  * @return string HTML for the form.
  */
 function get_edit_form($insid, $sort = '', $dir = '', $startrec = 0, $perpage = 0, $namesearch = '', $alpha = '')
 {
     $output = '';
     $ins = new instructor($insid);
     $output .= $ins->edit_form_html($insid);
     return $output;
 }
Example #6
0
 /**
  * Count the available students not already attached to this course.
  *
  * @param string $namesearch  name of the users being searched for
  * @param string $alpha       starting letter of the user being searched for
  * @return  int  count of users.
  */
 function count_users_avail($namesearch = '', $alpha = '')
 {
     $params = array();
     $FULLNAME = $this->_db->sql_concat('usr.firstname', "' '", 'usr.lastname');
     $FULLNAME_LIKE = $this->_db->sql_like($FULLNAME, ':name_like', FALSE);
     $IDNUMBER_LIKE = $this->_db->sql_like('usr.idnumber', ':id_like', FALSE);
     $LASTNAME_STARTSWITH = $this->_db->sql_like('usr.lastname', ':lastname_startswith', FALSE);
     $select = 'SELECT COUNT(usr.id) ';
     $tables = 'FROM {' . user::TABLE . '} usr ';
     $join = 'LEFT JOIN {' . student::TABLE . '} stu ';
     $on = 'ON stu.userid = usr.id AND stu.classid = :clsid ';
     $where = 'stu.id IS NULL';
     $params['clsid'] = $this->classid;
     if (!empty($namesearch)) {
         $namesearch = trim($namesearch);
         $where .= ' AND ((' . $FULLNAME_LIKE . ') OR (' . $IDNUMBER_LIKE . ')) ';
         $params['name_like'] = "%{$namesearch}%";
         $params['id_like'] = "%{$namesearch}%";
     }
     if ($alpha) {
         $where .= ' AND (' . $LASTNAME_STARTSWITH . ') ';
         $params['lastname_startswith'] = "{$alpha}%";
     }
     if (empty(elis::$config->local_elisprogram->legacy_show_inactive_users)) {
         $where .= ' AND usr.inactive = 0 ';
     }
     $uids = array();
     if ($users = $this->get_students()) {
         foreach ($users as $user) {
             $uids[] = $user->id;
         }
     }
     unset($users);
     if ($users = $this->get_waiting()) {
         foreach ($users as $user) {
             $uids[] = $user->id;
         }
     }
     unset($users);
     $ins = new instructor();
     if ($users = $ins->get_instructors($this->classid)) {
         foreach ($users as $user) {
             $uids[] = $user->id;
         }
     }
     unset($users);
     if (!empty($uids)) {
         $where .= ' AND usr.id NOT IN ( ' . implode(', ', $uids) . ' ) ';
     }
     $where = 'WHERE ' . $where . ' ';
     // *** TBD ***
     // TODO: Ugly, this needs to be overhauled
     $cpage = new pmclasspage();
     if (!$cpage->_has_capability('local/elisprogram:class_enrol', $this->classid)) {
         //perform SQL filtering for the more "conditional" capability
         $allowed_clusters = pmclass::get_allowed_clusters($this->classid);
         if (empty($allowed_clusters)) {
             $where .= 'AND 0=1';
         } else {
             $cluster_filter = implode(',', $allowed_clusters);
             // *** TBD ***
             $where .= 'AND usr.id IN (
                          SELECT userid FROM {' . clusterassignment::TABLE . "}\n                             WHERE clusterid IN ({$cluster_filter}))";
         }
     }
     $sql = $select . $tables . $join . $on . $where;
     return $this->_db->count_records_sql($sql, $params);
 }
 function can_do_default()
 {
     global $USER;
     $id = $this->required_param('id', PARAM_INT);
     return cmclasspage::_has_capability('block/curr_admin:viewreports', $id) || instructor::user_is_instructor_of_class(cm_get_crlmuserid($USER->id), $id);
 }
 /**
  * Enrol the test user in the provided context
  *
  * @param string $contextlevel The string descriptor of the context level
  * @param string $role The shortname of the import record's role column
  */
 private function create_enrolment($contextlevel, $role)
 {
     global $CFG, $DB;
     require_once $CFG->dirroot . '/local/elisprogram/lib/setup.php';
     switch ($contextlevel) {
         case 'curriculum':
             // Program enrolment.
             require_once elispm::lib('data/curriculumstudent.class.php');
             $data = array('curriculumid' => 1, 'userid' => 1);
             $curriculumstudent = new curriculumstudent($data);
             $curriculumstudent->save();
             break;
         case 'track':
             // Track enrolment.
             require_once elispm::lib('data/usertrack.class.php');
             $data = array('trackid' => 1, 'userid' => 1);
             $usertrack = new usertrack($data);
             $usertrack->save();
             break;
         case 'cluster':
             // User set enrolment.
             require_once elispm::lib('data/clusterassignment.class.php');
             $data = array('clusterid' => 1, 'userid' => 1);
             $clusterassignment = new clusterassignment($data);
             $clusterassignment->save();
             break;
         case 'class':
             if ($role == 'instructor') {
                 // Class instance instructor enrolment.
                 require_once elispm::lib('data/instructor.class.php');
                 $data = array('classid' => 1, 'userid' => 1);
                 $instructor = new instructor($data);
                 $instructor->save();
             } else {
                 // Class instance student enrolment.
                 require_once elispm::lib('data/student.class.php');
                 $data = array('classid' => 1, 'userid' => 1);
                 $student = new student($data);
                 $student->save();
             }
             break;
         case 'user':
             // Moodle user role assignment.
             $roleid = $DB->get_field('role', 'id', array('shortname' => $role));
             $userid = $DB->get_field('user', 'id', array('idnumber' => 'testuseridnumber'));
             $context = context_user::instance($userid);
             role_assign($roleid, $userid, $context->id);
             break;
         default:
             break;
     }
 }
 function get_header_entries()
 {
     global $CFG, $CURMAN;
     $header_array = array();
     // Add a course/class name if available
     $classid = 0;
     $cls_setting = php_report_filtering_get_active_filter_values($this->get_report_shortname(), 'classid', $this->filter);
     if (!empty($cls_setting[0]['value'])) {
         $classid = $cls_setting[0]['value'];
         $cmclass = new cmclass($classid);
         // Course name
         $header_obj = new stdClass();
         $header_obj->label = get_string('header_course', $this->lang_file) . ':';
         $header_obj->value = $cmclass->course->name;
         $header_obj->css_identifier = '';
         $header_array[] = $header_obj;
         // Class name
         $header_obj = new stdClass();
         $header_obj->label = get_string('header_class', $this->lang_file) . ':';
         $header_obj->value = $cmclass->idnumber;
         $header_obj->css_identifier = '';
         $header_array[] = $header_obj;
     }
     // If we are displaying a class, show date range and instructors
     if (!empty($classid)) {
         // Add dates if available
         if (!empty($cmclass)) {
             $startdate = $cmclass->startdate;
             $enddate = $cmclass->enddate;
             // Add start date if available
             if (!empty($startdate)) {
                 $header_obj = new stdClass();
                 $header_obj->label = get_string('header_start_date', $this->lang_file) . ':';
                 $header_obj->value = $this->userdate($startdate, get_string('strftimedaydate'));
                 $header_obj->css_identifier = '';
                 $header_array[] = $header_obj;
             }
             // Add end date if available
             if (!empty($enddate)) {
                 $header_obj = new stdClass();
                 $header_obj->label = get_string('header_end_date', $this->lang_file) . ':';
                 $header_obj->value = $this->userdate($enddate, get_string('strftimedaydate'));
                 $header_obj->css_identifier = '';
                 $header_array[] = $header_obj;
             }
         }
         // Add instructor names
         $instructor_records = instructor::get_instructors($classid);
         if (!empty($instructor_records)) {
             $instructors = '';
             foreach ($instructor_records as $record) {
                 $userpage = new usermanagementpage(array('id' => $record->id, 'action' => 'view'));
                 $instructors .= '<span class="external_report_link"><a href="' . $userpage->get_url() . '">' . fullname($record) . '</a></span><br />';
             }
             $header_obj = new stdClass();
             $header_obj->label = get_string('header_instructors', $this->lang_file) . ':';
             $header_obj->value = $instructors == '' ? 'Not Available' : $instructors;
             $header_obj->css_identifier = '';
             $header_array[] = $header_obj;
         }
     }
     return $header_array;
 }
Example #10
0
 /**
  * Delete an instructor class instance assignment
  *
  * @param object $record One record of import data
  * @param string $filename The import file name, used for logging
  * @param string $idnumber The idnumber of the class instance
  *
  * @return boolean true on success, otherwise false
  * @uses   $CFG
  * @uses   $DB
  */
 function class_enrolment_delete_instructor($record, $filename, $idnumber)
 {
     global $CFG, $DB;
     require_once $CFG->dirroot . '/local/elisprogram/lib/setup.php';
     require_once elispm::lib('data/pmclass.class.php');
     require_once elispm::lib('data/instructor.class.php');
     require_once elispm::lib('data/user.class.php');
     if (!($crsid = $DB->get_field(pmclass::TABLE, 'id', array('idnumber' => $idnumber)))) {
         $this->fslogger->log_failure("instance value of \"{$idnumber}\" does not refer to a valid instance of a class context.", 0, $filename, $this->linenumber, $record, "enrolment");
         return false;
     }
     $userid = $this->get_userid_from_record($record, $filename);
     // string to describe the user
     $user_descriptor = $this->get_user_descriptor($record, false, 'user_');
     if (!$DB->record_exists(instructor::TABLE, array('classid' => $crsid, 'userid' => $userid))) {
         $this->fslogger->log_failure("User with {$user_descriptor} is not enrolled in " . "class instance \"{$idnumber}\" as instructor.", 0, $filename, $this->linenumber, $record, "enrolment");
         return false;
     }
     if (!$this->validate_class_enrolment_data('delete', $record, $filename)) {
         return false;
     }
     // obtain the cluster / userset id
     $classid = $DB->get_field(pmclass::TABLE, 'id', array('idnumber' => $idnumber));
     // delete the association
     $studentid = $DB->get_field(instructor::TABLE, 'id', array('userid' => $userid, 'classid' => $classid));
     $instructor = new instructor($studentid);
     $instructor->load();
     $instructor->delete();
     // log success
     $success_message = "User with {$user_descriptor} successfully unenrolled from class instance \"{$idnumber}\" as an instructor.";
     $this->fslogger->log_success($success_message, 0, $filename, $this->linenumber);
     return true;
 }
Example #11
0
 function can_do_edit()
 {
     global $USER;
     $id = $this->required_param('id', PARAM_INT);
     return $this->_has_capability('local/elisprogram:class_edit') || instructor::user_is_instructor_of_class(pm_get_crlmuserid($USER->id), $id);
 }
Example #12
0
 /**
  * Test ignoring user who was manually enrolled and has the instructor role assigned.
  */
 public function test_ignore_instructor_user_not_enrolled_by_elis()
 {
     global $DB;
     $this->resetAfterTest(true);
     $this->load_csv_data();
     $this->set_config_instructor_role();
     $enrolinstance = null;
     // Define user and course objects
     $user = new stdClass();
     $user->id = 101;
     $context = context_course::instance(100);
     $course = new stdClass();
     $course->id = $context->instanceid;
     // Enrol user manually and give them the instructor role
     $role = $DB->get_record('role', array('shortname' => 'teacher'));
     $plugin = enrol_get_plugin('manual');
     $plugin->add_instance($course);
     $this->getDataGenerator()->enrol_user($user->id, $course->id, $role->id, 'manual');
     // Call instructor delete method
     $instructor = new instructor(array('userid' => 104, 'classid' => 100));
     $instructor->delete();
     $result = is_enrolled($context, $user, '', true);
     $this->assertTrue($result);
 }
 /**
  * Validate that create actions are converted to updates for instructor enrolments when the
  * "createorupdate" flag is enabled
  */
 public function test_elis_createorupdate_updates_instructor_enrolment()
 {
     global $CFG, $DB;
     require_once $CFG->dirroot . '/local/elisprogram/lib/data/course.class.php';
     require_once $CFG->dirroot . '/local/elisprogram/lib/data/pmclass.class.php';
     require_once $CFG->dirroot . '/local/elisprogram/lib/data/instructor.class.php';
     require_once $CFG->dirroot . '/local/elisprogram/lib/data/user.class.php';
     // Set up initial conditions.
     set_config('createorupdate', 1, 'dhimport_version1elis');
     // Create the test course.
     $course = new course(array('name' => 'testcoursename', 'idnumber' => 'testcourseidnumber', 'syllabus' => ''));
     $course->save();
     // Create the test class.
     $class = new pmclass(array('courseid' => $course->id, 'idnumber' => 'testclassidnumber'));
     $class->save();
     // Create the test user.
     $user = new user(array('username' => 'testuserusername', 'email' => '*****@*****.**', 'idnumber' => 'testuseridnumber', 'firstname' => 'testuserfirstname', 'lastname' => 'testuserlastname', 'country' => 'CA'));
     $user->save();
     // Create the instructor enrolment user.
     $instructor = new instructor(array('classid' => $class->id, 'userid' => $user->id, 'completetime' => rlip_timestamp(0, 0, 0, 1, 1, 2012)));
     $instructor->save();
     // Run the instructor enrolment create action.
     $record = new stdClass();
     $record->action = 'create';
     $record->context = 'class_testclassidnumber';
     $record->user_username = '******';
     $record->role = 'instructor';
     $record->completetime = 'Jan/02/2012';
     $importplugin = rlip_dataplugin_factory::factory('dhimport_version1elis');
     $importplugin->fslogger = new silent_fslogger(null);
     $importplugin->process_record('enrolment', $record, 'bogus');
     // Validation.
     $this->assertTrue($DB->record_exists(instructor::TABLE, array('classid' => $class->id, 'userid' => $user->id, 'completetime' => rlip_timestamp(0, 0, 0, 1, 2, 2012))));
 }
 /**
  * Test table doesn't show assigned students or instructors
  * @dataProvider dataprovider_available_doesnt_show_students_instructors
  * @param array $associations An array of arrays of parameters to construct student associations.
  * @param int $tableclassid The ID of the class we're managing.
  * @param array $expectedresults The expected page of results.
  */
 public function test_available_doesnt_show_students_instructors($students, $instructors, $tableclassid, $expectedresults)
 {
     global $USER, $DB, $CFG;
     $userbackup = $USER;
     // Set up permissions.
     $USER = $this->setup_permissions_test();
     $this->give_permission_for_context($USER->id, 'local/elisprogram:assign_class_instructor', context_system::instance());
     // Create associations.
     foreach ($students as $student) {
         $student = new student($student);
         $student->save();
     }
     foreach ($instructors as $instructor) {
         $instructor = new instructor($instructor);
         $instructor->save();
     }
     $table = new deepsight_datatable_instructor_available_mock($DB, 'test', 'http://localhost', 'testuniqid');
     $table->set_classid($tableclassid);
     $actualresults = $table->get_search_results(array(), array(), 0, 20);
     $this->assert_search_results($expectedresults, count($expectedresults), $actualresults);
     // Restore user.
     $USER = $userbackup;
 }
 function get_item_display_instructor($column, $class)
 {
     if ($instructors = instructor::get_instructors($class->id)) {
         $ins = array();
         foreach ($instructors as $instructor) {
             $ins[] = cm_fullname($instructor);
         }
         return implode('<br />', $ins);
     } else {
         return 'n/a';
     }
 }
Example #16
0
 function delete()
 {
     if (!empty($this->id)) {
         //clean make the delete cascade into association records
         $filter = new field_filter('classid', $this->id);
         instructor::delete_records($filter, $this->_db);
         student::delete_records($filter, $this->_db);
         trackassignment::delete_records($filter, $this->_db);
         classmoodlecourse::delete_records($filter, $this->_db);
         student_grade::delete_records($filter, $this->_db);
         waitlist::delete_records($filter, $this->_db);
         parent::delete();
         $context = \local_elisprogram\context\pmclass::instance($this->id);
         $context->delete();
     }
 }
Example #17
0
 /**
  * Determines whether the current user is allowed to create, edit, and delete associations
  * between a user (instructor) and a class
  *
  * @param    int      $userid    The id of the user being associated to the class
  * @param    int      $classid   The id of the class we are associating the user to
  * @uses     $DB
  * @uses     $USER;
  * @return   boolean             True if the current user has the required permissions, otherwise false
  */
 public static function can_manage_assoc($userid, $classid)
 {
     global $DB, $USER;
     // TODO: Ugly, this needs to be overhauled
     $cpage = new pmclasspage();
     if (!instructorpage::can_enrol_into_class($classid)) {
         //the users who satisfty this condition are a superset of those who can manage associations
         return false;
     } else {
         if ($cpage->_has_capability('local/elisprogram:assign_class_instructor', $classid)) {
             //current user has the direct capability
             return true;
         }
     }
     //get the context for the "indirect" capability
     $context = pm_context_set::for_user_with_capability('cluster', 'local/elisprogram:assign_userset_user_class_instructor', $USER->id);
     $allowed_clusters = array();
     $allowed_clusters = instructor::get_allowed_clusters($classid);
     //query to get users associated to at least one enabling cluster
     $cluster_select = '';
     if (empty($allowed_clusters)) {
         $cluster_select = '0=1';
     } else {
         $cluster_select = 'clusterid IN (' . implode(',', $allowed_clusters) . ')';
     }
     $select = "userid = ? AND {$cluster_select}";
     //user just needs to be in one of the possible clusters
     if ($DB->record_exists_select(clusterassignment::TABLE, $select, array($userid))) {
         return true;
     }
     return false;
 }
 /**
  * Enrol the instructors associated with the class into the attached Moodle
  * course.
  *
  * @param none
  * @return bool True on success, False otherwise.
  */
 function data_enrol_instructors()
 {
     if (empty($this->classid) || empty($this->moodlecourseid) || !empty($this->siteconfig) && !file_exists($this->siteconfig)) {
         return false;
     }
     $ins = new instructor();
     global $CURMAN;
     if ($CURMAN->config->default_instructor_role && ($instructors = $ins->get_instructors($this->classid))) {
         /// At this point we must switch over the other Moodle site's DB config, if needed
         if (!empty($this->siteconfig)) {
             $cfgbak = moodle_load_config($this->siteconfig);
         }
         /// This has to be put here in case we have a site config reload.
         $CFG = $GLOBALS['CFG'];
         $CURMAN = $GLOBALS['CURMAN'];
         $db = $GLOBALS['db'];
         if (!($context = get_context_instance(CONTEXT_COURSE, $this->moodlecourseid))) {
             return false;
         }
         foreach ($instructors as $instructor) {
             /// Make sure that a Moodle account exists for this user already.
             $user = new user($instructor->id);
             if (!($muser = $CURMAN->db->get_record('user', 'idnumber', addslashes($user->idnumber)))) {
                 $muser = addslashes_recursive($muser);
                 /// Create a new record.
                 $muser = new stdClass();
                 $muser->idnumber = $user->idnumber;
                 $muser->username = $user->uname;
                 $muser->passwword = $user->passwd;
                 $muser->firstname = $user->firstname;
                 $muser->lastname = $user->lastname;
                 $muser->auth = 'manual';
                 $muser->timemodified = time();
                 $muser->id = $CURMAN->db->insert_record('user', $muser);
             }
             /// If we have a vald Moodle user account, apply the role.
             if (!empty($muser->id)) {
                 role_assign($CURMAN->config->default_instructor_role, $muser->id, 0, $context->id, 0, 0, 0, 'manual');
             }
         }
         /// Reset $CFG object.
         if (!empty($this->siteconfig)) {
             moodle_load_config($cfgbak->dirroot . '/config.php');
         }
     }
     return true;
 }
Example #19
0
 function delete()
 {
     $status = true;
     if (!empty($this->id)) {
         instructor::delete_for_class($this->id);
         student::delete_for_class($this->id);
         trackassignmentclass::delete_for_class($this->id);
         classmoodlecourse::delete_for_class($this->id);
         student_grade::delete_for_class($this->id);
         attendance::delete_for_class($this->id);
         taginstance::delete_for_class($this->id);
         waitlist::delete_for_class($this->id);
         classmoodlecourse::delete_for_class($this->id);
         $level = context_level_base::get_custom_context_level('class', 'block_curr_admin');
         $result = delete_context($level, $this->id);
         $status = $this->data_delete_record();
     }
     return $status;
 }
Example #20
0
 public function delete()
 {
     global $CFG;
     $muser = $this->get_moodleuser();
     if (empty($muser) || !is_primary_admin($muser->id)) {
         // delete associated data
         require_once elis::lib('data/data_filter.class.php');
         $filter = new field_filter('userid', $this->id);
         curriculumstudent::delete_records($filter, $this->_db);
         student::delete_records($filter, $this->_db);
         student_grade::delete_records($filter, $this->_db);
         waitlist::delete_records($filter, $this->_db);
         instructor::delete_records($filter, $this->_db);
         usertrack::delete_records($filter, $this->_db);
         clusterassignment::delete_records($filter, $this->_db);
         //delete association to Moodle user, if applicable
         require_once elispm::lib('data/usermoodle.class.php');
         $filter = new field_filter('cuserid', $this->id);
         usermoodle::delete_records($filter, $this->_db);
         // Delete Moodle user.
         if (!empty($muser)) {
             delete_user($muser);
         }
         parent::delete();
         $context = \local_elisprogram\context\user::instance($this->id);
         $context->delete();
     }
 }
Example #21
0
 /**
  * When a role is selected from the sync configuration, create class
  * enrolments for the specified role assignments.
  */
 static function instructor_sync_role_set()
 {
     global $DB;
     $roleid = get_config('elisprogram_enrolrolesync', 'instructor_role');
     if (empty($roleid)) {
         //not configured
         return;
     }
     //include dependencies
     require_once elispm::lib('data/instructor.class.php');
     // find all class role assignments
     $sql = "SELECT ra.id, cu.id AS userid, ctx.instanceid AS classid\n                  FROM {role_assignments} ra\n                  JOIN {user} mu ON ra.userid = mu.id\n                  JOIN {" . user::TABLE . "} cu ON mu.idnumber = cu.idnumber\n                  JOIN {context} ctx ON ctx.id = ra.contextid\n                  LEFT JOIN {" . instructor::TABLE . "} inst\n                    ON cu.id = inst.userid\n                    AND ctx.instanceid = inst.classid\n                 WHERE ctx.contextlevel = :contextlevel\n                   AND ra.roleid = :roleid\n                   AND inst.id IS NULL";
     $params = array('contextlevel' => CONTEXT_ELIS_CLASS, 'roleid' => $roleid);
     $instructorswanted = $DB->get_recordset_sql($sql, $params);
     $instructorswanted = $instructorswanted ? $instructorswanted : array();
     //iterate and add where needed
     foreach ($instructorswanted as $instructor) {
         unset($instructor->id);
         $instructor = new instructor($instructor);
         $instructor->assigntime = time();
         try {
             $instructor->save();
         } catch (Exception $e) {
             //validation failed
         }
     }
     return true;
 }
Example #22
0
 /**
  * Actually process the uploaded CSV organization file upon successful upload.
  *
  * NOTE: A lot o code here is borrowed / modified from Moodle.
  *
  * @see Moodle:/admin/uploaduser.php
  *
  * @uses $CURMAN
  * @param array $fieldata A PHP upload file array (i.e. from the $_FILES superglobal).
  * @param bool  $update   Flag for updating existing records.
  * @param bool  $verbose  Flag for verbose output.
  * @return string Output for display.
  */
 function process_input_data($filedata, $update = false, $verbose = false)
 {
     global $CURMAN;
     $output = '';
     /// Don't check for a valid mime/type as this is causing errors for the client.
     /*
             if (!in_array($filedata['type'], $this->valid_mimetypes)) {
                 return 'The file format uploaded was incorrect';
             }
     */
     if ($filedata['size'] === 0) {
         return get_string('uploaded_empty_file', 'block_curr_admin');
     }
     /**
      * Large files are likely to take their time and memory. Let PHP know
      * that we'll take longer, and that the process should be recycled soon
      * to free up memory.
      */
     @set_time_limit(0);
     @cm_raise_memory_limit('192M');
     if (function_exists('apache_child_terminate')) {
         @apache_child_terminate();
     }
     $csv_encode = '/\\&\\#44/';
     $csv_delimiter = "\\,";
     $csv_delimiter2 = ",";
     $data = '';
     $file = @fopen($filedata['tmp_name'], 'rb');
     if ($file) {
         while (!feof($file)) {
             $data .= fread($file, 1024);
         }
         fclose($file);
     }
     if (empty($data)) {
         return get_string('no_data_file', 'block_curr_admin');
     }
     /**
      * Removes the BOM from unicode string - see http://unicode.org/faq/utf_bom.html
      *
      * Borrowed from Moodle code - /lib/textlib.class.php
      */
     $bom = "";
     if (strpos($data, $bom) === 0) {
         $data = substr($data, strlen($bom));
     }
     /**
      * Fix Mac/DOS newlines
      *
      * Borrowed from Moodle code - /admin/uploaduser.php
      */
     $data = preg_replace('!\\r\\n?!', "\n", $data);
     $fp = fopen($filedata['tmp_name'], 'w');
     fwrite($fp, $data);
     fclose($fp);
     $fp = fopen($filedata['tmp_name'], 'r');
     /**
      * The required and optional fields we're looking for in the CSV file.
      */
     $required = array('studentid' => 1, 'class' => 1, 'trainernum' => 1, 'startdate' => 1, 'enddate' => 1);
     $optional = array('firstname' => 1, 'lastname' => 1, 'curriculum' => 1, 'status' => 1, 'completed' => 1, 'grade' => 1, 'frequency' => 1, 'timeperiod' => 1);
     $colpos = array();
     $header = split($csv_delimiter, fgets($fp, 1024));
     // Check for valid field names
     foreach ($header as $i => $h) {
         $h = trim($h);
         $header[$i] = $h;
         // remove whitespace
         $h = ereg_replace('^\\"|\\"$', '', $h);
         // strip encapsulating quotes
         $header[$i] = $h;
         if (isset($required[$h])) {
             $required[$h] = 0;
             $colpos[$i] = $h;
         } else {
             if (isset($optional[$h])) {
                 $colpos[$i] = $h;
             }
         }
     }
     /// Check for required fields
     foreach ($required as $key => $value) {
         if ($value) {
             //required field missing
             return get_string('missing_required_field', 'block_curr_admin', $key);
         }
     }
     $linenum = 2;
     // since header is line 1
     $stusnew = 0;
     $stuserror = 0;
     $stusupdated = 0;
     $timenow = time();
     while (!feof($fp)) {
         //Note: commas within a field should be encoded as &#44 (for comma separated csv files)
         //Note: semicolon within a field should be encoded as &#59 (for semicolon separated csv files)
         $line = split($csv_delimiter, fgets($fp, 1024));
         foreach ($line as $key => $value) {
             if (isset($colpos[$key])) {
                 /// decode encoded commas and strip enapsulating quotes
                 $record[$colpos[$key]] = preg_replace($csv_encode, $csv_delimiter2, trim($value));
                 $record[$colpos[$key]] = ereg_replace('^\\"|\\"$', '', $record[$colpos[$key]]);
             }
         }
         /// Got organization data
         if ($record[$header[0]]) {
             $done = false;
             $users = $CURMAN->db->get_records(USRTABLE, 'idnumber', $record['studentid']);
             $user = NULL;
             /// Don't worry about the actual type. Just worry about the idnumber.
             if (!empty($users)) {
                 $user = current($users);
             }
             /// Only proceed if this student and instructor users actually exists.
             if (!empty($user->id)) {
                 $crsidnumber = $record['class'];
                 $dateparts = explode('/', $record['startdate']);
                 $startdate = mktime(0, 0, 0, $dateparts[1], $dateparts[0], $dateparts[2]);
                 $dateparts = explode('/', $record['enddate']);
                 $enddate = mktime(0, 0, 0, $dateparts[1], $dateparts[0], $dateparts[2]);
                 /// Check if the class as specified exists...
                 $clsidnumber = $record['class'];
                 if (!($class = $CURMAN->db->get_record(CLSTABLE, 'idnumber', $clsidnumber))) {
                     $clsidnumber = $record['class'] . '-' . $record['trainernum'];
                     /// Need to check for old classes that didn't have dates, and remove them.
                     if ($class = $CURMAN->db->get_record(CLSTABLE, 'idnumber', $clsidnumber)) {
                         $class = new cmclass($class);
                         $class->delete();
                     }
                     /// If the class doesn't exist, we have to create it first.
                     $datepart = date('Ymd', $startdate);
                     $clsidnumber = $record['class'] . '-' . $record['trainernum'] . '-' . $datepart;
                     $class = $CURMAN->db->get_record(CLSTABLE, 'idnumber', $clsidnumber);
                 }
                 if (empty($class->id) || $update && !empty($class->id)) {
                     if ($course = $CURMAN->db->get_record(CRSTABLE, 'idnumber', $crsidnumber)) {
                         /// Do we need to add / update curriculum info for this course???
                         if (isset($record['curriculum'])) {
                             if ($cur = $CURMAN->db->get_record(CURTABLE, 'idnumber', $record['curriculum'])) {
                                 $curcrs = $CURMAN->db->get_record(CURCRSTABLE, 'curriculumid', $cur->id, 'courseid', $course->id);
                                 if (!$update && empty($curcrs->id) || $update && !empty($curcrs->id)) {
                                     $cmcrec = array('curriculumid' => $cur->id, 'courseid' => $course->id);
                                     if (!empty($record['frequency'])) {
                                         $cmcrec['frequency'] = $record['frequency'];
                                     }
                                     if (!empty($record['timeperiod'])) {
                                         $cmcrec['timeperiod'] = $record['timeperiod'];
                                     }
                                     if (empty($curcrs->id)) {
                                         $curcrs = new curriculum($cmcrec);
                                     } else {
                                         $curcrs = new curriculum($curcrs->id);
                                         foreach ($cmcrec as $key => $val) {
                                             $curcrs->{$key} = $val;
                                         }
                                     }
                                     $a = new object();
                                     $a->courseid = $course->idnumber;
                                     $a->coursename = $course->name;
                                     $a->curid = $cur->idnumber;
                                     if ($update && !empty($curcrs->id)) {
                                         if ($curcrs->data_update_record() && $verbose) {
                                             $output .= get_string('updated_curriculum_course_info', 'block_curr_admin');
                                         }
                                     } else {
                                         if ($curcrs->data_insert_record() && $verbose) {
                                             $output .= get_string('added_curriculum_course_info', 'block_curr_admin');
                                         }
                                     }
                                 }
                             }
                         }
                         $clsrec = array('courseid' => $course->id, 'idnumber' => $clsidnumber, 'startdate' => $startdate, 'enddate' => $enddate);
                         if (empty($class->id)) {
                             $class = new cmclass($clsrec);
                         } else {
                             $class = new cmclass($class->id);
                             foreach ($clsrec as $key => $val) {
                                 $class->{$key} = $val;
                             }
                         }
                         if ($update && !empty($class->id)) {
                             if ($class->data_update_record() && $verbose) {
                                 $output .= get_string('updated_class_info', 'block_curr_admin') . $class->idnumber . '<br /><br />' . "\n";
                             }
                         } else {
                             if ($class->data_insert_record() && $verbose) {
                                 $output .= get_string('added_class_info', 'block_curr_admin') . $class->idnumber . '<br /><br />' . "\n";
                             }
                         }
                         if (empty($class->id) && $verbose) {
                             $output .= get_string('error_class_not_created', 'block_curr_admin') . $class->idnumber . '<br /><br />' . "\n";
                         }
                     } else {
                         if ($verbose) {
                             $output .= get_string('error_course_not_found', 'block_curr_admin') . $crsidnumber . '<br /><br />' . "\n";
                         }
                     }
                 }
                 /// Only proceed if we have an actual class here...
                 if (!empty($class->id)) {
                     $instructors = $CURMAN->db->get_records(USRTABLE, 'idnumber', $record['trainernum']);
                     $instructor = NULL;
                     /// Don't worry about the actual type. Just worry about the idnumber.
                     if (!empty($instructors)) {
                         $instructor = current($instructors);
                     }
                     if (!empty($instructor->id) && !$CURMAN->db->record_exists(INSTABLE, 'classid', $class->id, 'userid', $instructor->id)) {
                         $insrec = array('classid' => $class->id, 'userid' => $instructor->id);
                         $newins = new instructor($insrec);
                         if ($newins->data_insert_record() && $verbose) {
                             $output .= get_string('added_instructor_class', 'block_curr_admin', cm_fullname($instructor)) . $class->idnumber . '<br /><br />' . "\n";
                         }
                     }
                     $student = $CURMAN->db->get_record(STUTABLE, 'classid', $class->id, 'userid', $user->id);
                     $a = new object();
                     $a->name = cm_fullname($user);
                     $a->id = $class->idnumber;
                     if (!$update && empty($student->id) || $update && !empty($student->id)) {
                         $sturec = array('classid' => $class->id, 'userid' => $user->id);
                         if (isset($record['status'])) {
                             $sturec['completestatusid'] = intval($record['status']);
                         }
                         if (!isset($record['completed'])) {
                             $sturec['completetime'] = $enddate;
                         } else {
                             $d = explode('/', $record['completed']);
                             if (count($d) == 3) {
                                 $day = $d[0];
                                 $month = $d[1];
                                 $year = $d[2];
                                 $timestamp = mktime(0, 0, 0, $month, $day, $year);
                                 $sturec['completetime'] = $timestamp;
                             }
                         }
                         if (isset($record['grade'])) {
                             $sturec['grade'] = intval($record['grade']);
                         }
                         if (empty($student->id)) {
                             $student = new student($sturec);
                         } else {
                             $student = new student($student->id);
                             foreach ($sturec as $key => $val) {
                                 $student->{$key} = $val;
                             }
                         }
                         if ($update && !empty($student->id)) {
                             if ($student->data_update_record() && $verbose) {
                                 $output .= get_string('update_enrolment_info', 'block_curr_admin', $a) . '<br /><br />' . "\n";
                             }
                         } else {
                             if ($student->data_insert_record() && $verbose) {
                                 $output .= get_string('add_enrolment_info', 'block_curr_admin', $a) . '<br /><br />' . "\n";
                             }
                         }
                     } else {
                         $student = NULL;
                         if ($verbose) {
                             $output .= get_string('existing_enrolment_info', 'block_curr_admin') . '<br /><br />' . "\n";
                         }
                     }
                     if (!empty($student->id)) {
                         $done = true;
                     }
                 }
             } else {
                 $output .= get_string('error_studentid_not_found', 'block_curr_admin') . $record['studentid'] . '<br /><br />' . "\n";
             }
             if ($update && $done) {
                 $stusupdated++;
             } else {
                 if (!$update && $done) {
                     $stusnew++;
                 } else {
                     $stuserror++;
                 }
             }
         }
     }
     if (!empty($output)) {
         $output .= '<br /><br />';
     }
     if (!$stusnew && !$stusupdated && !$stuserror) {
         $output .= get_string('nothing_done', 'block_curr_admin');
     }
     if ($stusnew > 0) {
         $output .= get_string('added_new_students', 'block_curr_admin', $stusnew);
     }
     if ($stusupdated > 0) {
         $output .= get_string('updated_existing_students', 'block_curr_admin', $stusupdated);
     }
     if ($stuserror > 0) {
         $output .= get_string('error_not_processed', 'block_curr_admin', $stuserror);
     }
     return $output;
 }
Example #23
0
 function count_users_avail($namesearch = '', $alpha = '')
 {
     global $CFG, $CURMAN, $USER;
     $LIKE = $CURMAN->db->sql_compare();
     $FULLNAME = sql_concat('usr.firstname', "' '", 'usr.lastname');
     $select = 'SELECT COUNT(usr.id) ';
     $tables = 'FROM ' . $CURMAN->db->prefix_table(USRTABLE) . ' usr ';
     $join = 'LEFT JOIN ' . $CURMAN->db->prefix_table(STUTABLE) . ' stu ';
     $on = "ON stu.userid = usr.id AND stu.classid = {$this->classid} ";
     $where = 'stu.id IS NULL';
     if (!empty($namesearch)) {
         $namesearch = trim($namesearch);
         $where .= (!empty($where) ? ' AND ' : '') . "({$FULLNAME} {$LIKE} '%{$namesearch}%') OR " . "(usr.idnumber {$LIKE} '%{$namesearch}%') ";
     }
     if ($alpha) {
         $where .= (!empty($where) ? ' AND ' : '') . "({$FULLNAME} {$LIKE} '{$alpha}%') ";
     }
     $uids = array();
     if ($users = $this->get_students()) {
         foreach ($users as $user) {
             $uids[] = $user->id;
         }
     }
     if ($users = $this->get_waiting()) {
         foreach ($users as $user) {
             $uids[] = $user->id;
         }
     }
     $ins = new instructor();
     if ($users = $ins->get_instructors()) {
         foreach ($users as $user) {
             $uids[] = $user->id;
         }
     }
     if (!empty($uids)) {
         $where .= (!empty($where) ? ' AND ' : '') . 'usr.id NOT IN ( ' . implode(', ', $uids) . ' ) ';
     }
     if (!empty($where)) {
         $where = 'WHERE ' . $where . ' ';
     }
     if (!cmclasspage::_has_capability('block/curr_admin:class:enrol', $this->classid)) {
         //perform SQL filtering for the more "conditional" capability
         $allowed_clusters = cmclass::get_allowed_clusters($this->classid);
         if (empty($allowed_clusters)) {
             $where .= 'AND 0=1';
         } else {
             $cluster_filter = implode(',', $allowed_clusters);
             $where .= "AND usr.id IN (\n                             SELECT userid FROM " . $CURMAN->db->prefix_table(CLSTUSERTABLE) . "\n                             WHERE clusterid IN ({$cluster_filter}))";
         }
     }
     $sql = $select . $tables . $join . $on . $where;
     return $CURMAN->db->count_records_sql($sql);
 }
Example #24
0
/**
 *
 * Triggered when a role unassignment takes place.
 * @param $eventdata
 * @return unknown_type
 */
function pm_notify_role_unassign_handler($eventdata)
{
    global $CFG, $DB;
    //make sure we have course manager roles defined
    if (empty($CFG->coursecontact)) {
        return true;
    }
    //retrieve the list of role ids we want to sync to curriculum admin
    $valid_instructor_roles = explode(',', $CFG->coursecontact);
    //make sure we actually care about the current role
    if (!in_array($eventdata->roleid, $valid_instructor_roles)) {
        return true;
    }
    //prevent removal from curriculum admin if the user still has an appropriate role in Moodle
    foreach ($valid_instructor_roles as $valid_instructor_role) {
        if (user_has_role_assignment($eventdata->userid, $eventdata->roleid, $eventdata->contextid)) {
            return true;
        }
    }
    //retrieve the course context
    if (!($course_context = $DB->get_record('context', array('contextlevel' => CONTEXT_COURSE, 'id' => $eventdata->contextid)))) {
        return true;
    }
    //if the course is not tied to any curriculum admin classes, then we are done
    $associated_classes = $DB->get_recordset(classmoodlecourse::TABLE, array('moodlecourseid' => $course_context->instanceid));
    if ($associated_classes->valid() !== true) {
        return true;
    }
    //retrieve the curriculum admin user's id
    if (!($crlm_userid = pm_get_crlmuserid($eventdata->userid))) {
        return true;
    }
    //clear out instructor assignments in all associated classes
    foreach ($associated_classes as $associated_class) {
        if ($instructor_record = $DB->get_record(instructor::TABLE, array('classid' => $associated_class->classid, 'userid' => $crlm_userid))) {
            $delete_record = new instructor($instructor_record->id);
            $delete_record->delete();
        }
    }
    unset($associated_classes);
    return true;
}
Example #25
0
 public function delete()
 {
     global $CFG;
     $result = false;
     $muser = cm_get_moodleuserid($this->id);
     if (empty($muser) || !is_primary_admin($muser)) {
         $level = context_level_base::get_custom_context_level('user', 'block_curr_admin');
         $result = attendance::delete_for_user($this->id);
         $result = $result && curriculumstudent::delete_for_user($this->id);
         $result = $result && instructor::delete_for_user($this->id);
         $result = $result && student::delete_for_user($this->id);
         $result = $result && student_grade::delete_for_user($this->id);
         $result = $result && usertrack::delete_for_user($this->id);
         $result = $result && usercluster::delete_for_user($this->id);
         $result = $result && clusterassignment::delete_for_user($this->id);
         $result = $result && waitlist::delete_for_user($this->id);
         $result = $result && delete_context($level, $this->id);
         // Delete Moodle user.
         if ($muser = get_record('user', 'idnumber', $this->idnumber, 'mnethostid', $CFG->mnet_localhost_id, 'deleted', 0)) {
             $result = $result && delete_user($muser);
         }
         $result = $result && parent::delete();
     }
     return $result;
 }
 /**
  * Validate that the role field is handled as needed during unassignment
  *
  * @param string $role The input value for the role field
  * @dataProvider role_provider
  */
 public function test_elis_user_instructor_unenrolment_handles_role($role)
 {
     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/instructor.class.php');
     require_once elispm::lib('data/pmclass.class.php');
     require_once elispm::lib('data/user.class.php');
     set_config('coursecontact', 'teacher,editingteacher');
     set_config('default_instructor_role', 'teacher', 'local_elisprogram');
     $user = new user(array('idnumber' => 'testuseridnumber', 'username' => 'testuserusername', 'firstname' => 'testuserfirstname', 'lastname' => 'testuserlastname', 'email' => '*****@*****.**', 'country' => 'CA'));
     $user->save();
     $course = new course(array('name' => 'testcoursename', 'idnumber' => 'testcourseidnumber', 'syllabus' => ''));
     $course->save();
     $class = new pmclass(array('courseid' => $course->id, 'idnumber' => 'testclassidnumber'));
     $class->save();
     $instructor = new instructor(array('userid' => $user->id, 'classid' => $class->id));
     $instructor->save();
     // Validate setup.
     $this->assertTrue($DB->record_exists(instructor::TABLE, array('userid' => $user->id, 'classid' => $class->id)));
     // Run the instructor assignment delete action.
     $record = new stdClass();
     $record->context = 'class_testclassidnumber';
     $record->user_username = '******';
     $record->role = $role;
     $importplugin = rlip_dataplugin_factory::factory('dhimport_version1elis');
     $importplugin->fslogger = new silent_fslogger(null);
     $importplugin->class_enrolment_delete($record, 'bogus', 'testclassidnumber');
     // Validation.
     $this->assertEquals(0, $DB->count_records(instructor::TABLE));
 }
Example #27
0
 /**
  * Gets filter sql for permissions.
  * @return array An array consisting of additional WHERE conditions, and parameters.
  */
 protected function get_filter_sql_permissions()
 {
     global $DB;
     $additionalfilters = array();
     $additionalfiltersparams = array();
     // If appropriate limit selection to users belonging to clusters for which the user can manage instructor assignments.
     // TODO: Ugly, this needs to be overhauled.
     $cpage = new pmclasspage();
     if (!$cpage->_has_capability('local/elisprogram:assign_class_instructor', $this->classid)) {
         // Perform SQL filtering for the more "conditional" capability.
         $allowedclusters = instructor::get_allowed_clusters($this->classid);
         if (empty($allowedclusters)) {
             $additionalfilters[] = 'FALSE';
         } else {
             list($usersetinoreq, $usersetinoreqparams) = $DB->get_in_or_equal($allowedclusters);
             $clusterfilter = 'SELECT userid FROM {' . clusterassignment::TABLE . '} WHERE clusterid ' . $usersetinoreq;
             $additionalfilters[] = 'element.id IN (' . $clusterfilter . ')';
             $additionalfiltersparams = array_merge($additionalfiltersparams, $usersetinoreqparams);
         }
     }
     return array($additionalfilters, $additionalfiltersparams);
 }
 function get_header_entries($export_format)
 {
     global $CFG, $USER;
     $header_array = array();
     // Add a course/class name if available
     $classid = 0;
     $cls_setting = php_report_filtering_get_active_filter_values($this->get_report_shortname(), 'classid', $this->filter);
     $cmclass = null;
     if (!empty($cls_setting[0]['value'])) {
         $classid = $cls_setting[0]['value'];
         $cmclass = new pmclass($classid);
         // Course name
         $header_obj = new stdClass();
         $header_obj->label = get_string('header_course', $this->lang_file) . ':';
         $header_obj->value = $cmclass->course->name;
         $header_obj->css_identifier = '';
         $header_array[] = $header_obj;
         // Class name
         $header_obj = new stdClass();
         $header_obj->label = get_string('header_class', $this->lang_file) . ':';
         $header_obj->value = $cmclass->idnumber;
         $header_obj->css_identifier = '';
         $header_array[] = $header_obj;
     }
     // If we are displaying a class, show date range and instructors
     if (!empty($classid)) {
         // Add dates if available
         if (!empty($cmclass)) {
             $cmclass = $cmclass->to_object();
             // TBD: no date data w/o?!?!
             //error_log("class_roster::get_header_entries() dates: {$startdate} ~ {$enddate}");
             // Add start date if available
             if (!empty($cmclass->startdate)) {
                 $header_obj = new stdClass();
                 $header_obj->label = get_string('header_start_date', $this->lang_file) . ':';
                 $header_obj->value = $this->pmclassdate($cmclass, 'start');
                 $header_obj->css_identifier = '';
                 $header_array[] = $header_obj;
             }
             // Add end date if available
             if (!empty($cmclass->enddate)) {
                 $header_obj = new stdClass();
                 $header_obj->label = get_string('header_end_date', $this->lang_file) . ':';
                 $header_obj->value = $this->pmclassdate($cmclass, 'end');
                 $header_obj->css_identifier = '';
                 $header_array[] = $header_obj;
             }
         }
         // Add instructor names
         $instructor = new instructor(array('userid' => $USER->id, 'classid' => $classid));
         $instructor_records = $instructor->get_instructors($classid);
         if (!empty($instructor_records)) {
             $instructors = '';
             foreach ($instructor_records as $record) {
                 $userpage = new userpage(array('id' => $record->id, 'action' => 'view'));
                 $instructors .= '<span class="external_report_link"><a href="' . $userpage->url . '">' . php_report::fullname($record) . '</a></span><br />';
             }
             $header_obj = new stdClass();
             $header_obj->label = get_string('header_instructors', $this->lang_file) . ':';
             $header_obj->value = $instructors == '' ? 'Not Available' : $instructors;
             $header_obj->css_identifier = '';
             $header_array[] = $header_obj;
         }
     }
     return $header_array;
 }
 /**
  * Validate that mappings are applied during the instructor enrolment delete action
  */
 public function test_mapping_applied_during_instructor_enrolment_delete()
 {
     global $CFG, $DB;
     require_once $CFG->dirroot . '/local/elisprogram/lib/data/course.class.php';
     require_once $CFG->dirroot . '/local/elisprogram/lib/data/instructor.class.php';
     require_once $CFG->dirroot . '/local/elisprogram/lib/data/pmclass.class.php';
     $this->init_mapping();
     $userid = $this->create_test_user();
     $course = new course(array('name' => 'testcoursename', 'idnumber' => 'testcourseidnumber', 'syllabus' => ''));
     $course->save();
     $pmclass = new pmclass(array('courseid' => $course->id, 'idnumber' => 'testclassidnumber'));
     $pmclass->save();
     $instructor = new instructor(array('classid' => $pmclass->id, 'userid' => $userid));
     $instructor->save();
     // Run the instructor enrolment delete action.
     $record = new stdClass();
     $record->customaction = 'delete';
     $record->customcontext = 'class_testclassidnumber';
     $record->customuser_username = '******';
     $record->customuser_email = '*****@*****.**';
     $record->customuser_idnumber = 'testuseridnumber';
     $record->customrole = 'instructor';
     $this->run_enrolment_import((array) $record);
     // Validation.
     $this->assertEquals(0, $DB->count_records(instructor::TABLE));
 }
 function can_do_edit()
 {
     global $USER;
     $id = $this->required_param('id', PARAM_INT);
     return $this->_has_capability('block/curr_admin:class:edit') || instructor::user_is_instructor_of_class(cm_get_crlmuserid($USER->id), $id);
 }