Example #1
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);
 }
 /**
  * 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 #3
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);
 }
 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');
 }
 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;
 }
Example #6
0
 /**
  * Test get_instructors function.
  */
 public function test_get_instructors()
 {
     global $DB;
     // Fixture.
     $datagenerator = new elis_program_datagenerator($DB);
     $user = $datagenerator->create_user();
     $datagenerator->assign_instructor_to_class($user->id, 1);
     // Test.
     $instructor = new instructor();
     $instructor->classid = 1;
     $instructors = $instructor->get_instructors();
     // Verify.
     $count = 0;
     foreach ($instructors as $instructoruser) {
         $this->assertEquals($user->id, $instructoruser->id);
         $count++;
     }
     $this->assertEquals(1, $count);
 }
 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';
     }
 }
 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;
 }