コード例 #1
0
ファイル: setup_test.php プロジェクト: jamesmcq/elis
 /**
  * Test elis_fullname function.
  */
 public function test_elis_fullname()
 {
     $user = new stdClass();
     $user->firstname = 'Firstname';
     $user->lastname = 'Lastname';
     $this->assertEquals('Firstname Lastname', elis_fullname($user, true));
 }
コード例 #2
0
 /**
  * Test pmnotifyroleassignhandler
  */
 public function test_pmnotifyroleassignhandler()
 {
     global $DB;
     // Setup ELIS PM configuration for notification messages on enrolment.
     elis::$config->local_elisprogram->notify_classenrol_user = 0;
     elis::$config->local_elisprogram->notify_classenrol_role = 1;
     elis::$config->local_elisprogram->fitem_id_notify_classenrol_message = '%%userenrolname%% has been enrolled in the class %%classname%%.';
     // Add the correct capability to the system level role and assign that role to the admin user.
     $admin = get_admin();
     $role = $DB->get_record('role', array('shortname' => 'editingteacher'));
     $syscontext = context_system::instance();
     $this->assertTrue(assign_capability('local/elisprogram:notify_classenrol', CAP_ALLOW, $role->id, $syscontext->id));
     $syscontext->mark_dirty();
     $this->assertGreaterThan(0, role_assign($role->id, $admin->id, $syscontext->id));
     // Assign the test user a new role in the class context.
     $testuser = $DB->get_record('user', array('id' => 100));
     $pmclass = new pmclass(100);
     $role = $DB->get_record('role', array('shortname' => 'student'));
     $context = \local_elisprogram\context\pmclass::instance($pmclass->id);
     $sink = $this->redirectMessages();
     $roleassignresult = role_assign($role->id, $testuser->id, $context->id);
     $this->assertGreaterThan(0, $roleassignresult);
     // Validate that the message was correctly sent.
     $messages = $sink->get_messages();
     $this->assertNotEmpty($messages);
     $fullname = elis_fullname($testuser);
     $expected = array('useridfrom' => $testuser->id, 'useridto' => $admin->id, 'subject' => get_string('unreadnewmessage', 'message', $fullname), 'smallmessage' => $fullname . ' has been enrolled in the class instance ' . $pmclass->idnumber . '.');
     foreach ($expected as $k => $v) {
         $this->assertEquals($v, $messages[0]->{$k});
     }
 }
コード例 #3
0
 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');
 }
コード例 #4
0
ファイル: selectpage.class.php プロジェクト: jamesmcq/elis
 function get_item_display_name($column, $item)
 {
     if (isset($item->name)) {
         return $item->name;
     } else {
         return elis_fullname($item->to_object());
     }
 }
コード例 #5
0
ファイル: table.class.php プロジェクト: jamesmcq/elis
 /**
  * Display a user's full name using Moodle's fullname function.
  * @param string $column The column's field name.
  * @param object $item The current record object.
  * @return string The users full name.
  */
 public static function display_user_fullname_item($column, $item)
 {
     if (method_exists($item, 'moodle_fullname')) {
         return $item->moodle_fullname();
     }
     if (method_exists($item, 'to_object')) {
         $item = $item->to_object();
     }
     return elis_fullname($item);
 }
コード例 #6
0
 /**
  * Returns a human friendly description of the filter used as label.
  * @param   array   $data  Filter settings
  * @return  string         Active filter label
  */
 public function get_label($data)
 {
     if (!$this->_useid) {
         return parent::get_label($data);
     } else {
         $value = $data['value'];
         $a = new object();
         $a->label = $this->_label;
         if ($cmuser = new user($value)) {
             $cmuser->load();
             $value = elis_fullname($cmuser->to_object());
         }
         $a->value = '"' . s($value) . '"';
         $a->operator = get_string('isequalto', 'filters');
         return get_string('selectlabel', 'filters', $a);
     }
 }
コード例 #7
0
ファイル: notifications.php プロジェクト: jamesmcq/elis
/**
 * Triggered when a role assignment takes place.
 * This function should use the PM configured values to send messages to appropriate users when a role assignment
 * takes place. Users will be ones configured for the context, which can include the user that is assigned and users
 * assigned to configured roles for that context. The message template used should be the one configured as well.
 *
 * @param object $eventdata the role assignment record
 * @return boolean success
 *
 */
function pm_notify_role_assign_handler($eventdata)
{
    global $CFG, $DB, $USER;
    pm_assign_instructor_from_mdl($eventdata);
    pm_assign_student_from_mdl($eventdata);
    /// Does the user receive a notification?
    $sendtouser = !empty(elis::$config->local_elisprogram->notify_classenrol_user) ? elis::$config->local_elisprogram->notify_classenrol_user : 0;
    $sendtorole = !empty(elis::$config->local_elisprogram->notify_classenrol_role) ? elis::$config->local_elisprogram->notify_classenrol_role : 0;
    $sendtosupervisor = !empty(elis::$config->local_elisprogram->notify_classenrol_supervisor) ? elis::$config->local_elisprogram->notify_classenrol_supervisor : 0;
    /// If nobody receives a notification, we're done.
    if (!$sendtouser && !$sendtorole && !$sendtosupervisor) {
        return true;
    }
    // First check if this is a standard Moodle context
    $context = context::instance_by_id($eventdata->contextid, IGNORE_MISSING);
    // If not, try checking to see if this is a custom ELIS context
    if (!$context) {
        $context = \local_eliscore\context\base::instance_by_id($eventdata->contextid, IGNORE_MISSING);
    }
    /// We get all context assigns, so check that this is a class. If not, we're done.
    //     if (!$context = context::instance_by_id($eventdata->contextid)) {
    if (!$context) {
        if (in_cron()) {
            mtrace(getstring('invalidcontext'));
        } else {
            print_error('invalidcontext');
        }
        return true;
    } else {
        if ($context->contextlevel == CONTEXT_SYSTEM) {
            // TBD: ^above was != CONTEXT_COURSE
            return true;
        }
    }
    /// Make sure this is a valid user.
    if (!($enroluser = $DB->get_record('user', array('id' => $eventdata->userid)))) {
        if (in_cron()) {
            mtrace(get_string('nomoodleuser', 'local_elisprogram'));
        } else {
            debugging(get_string('nomoodleuser', 'local_elisprogram'));
        }
        return true;
    }
    $course = null;
    /// Get the course record from the context id.
    if ($context->contextlevel == CONTEXT_COURSE && !($course = $DB->get_record('course', array('id' => $context->instanceid)))) {
        if (in_cron()) {
            mtrace(getstring('invalidcourse'));
        } else {
            print_error('invalidcourse');
        }
        return true;
    } else {
        if (empty($course) && $context->contextlevel != CONTEXT_ELIS_CLASS) {
            // TBD
            //error_log("/local/elisprogram/lib/notifications.php::pm_notify_role_assign_handler(); eventdata->contextid != CONTEXT_ELIS_CLASS");
            return true;
        }
        $name = !empty($course) ? $course->fullname : $DB->get_field(pmclass::TABLE, 'idnumber', array('id' => $context->instanceid));
        if (empty($name)) {
            return true;
        }
    }
    $message = new notification();
    /// Set up the text of the message
    $text = empty(elis::$config->local_elisprogram->notify_classenrol_message) ? get_string('notifyclassenrolmessagedef', 'local_elisprogram') : elis::$config->local_elisprogram->notify_classenrol_message;
    $search = array('%%userenrolname%%', '%%classname%%');
    $replace = array(elis_fullname($enroluser), $name);
    $text = str_replace($search, $replace, $text);
    if ($sendtouser) {
        $message->send_notification($text, $enroluser);
    }
    $users = array();
    if ($sendtorole) {
        // Get all users with the notify_classenrol capability.
        if ($roleusers = get_users_by_capability($context, 'local/elisprogram:notify_classenrol')) {
            $users = $users + $roleusers;
        }
        if ($roleusers = get_users_by_capability(context_system::instance(), 'local/elisprogram:notify_classenrol')) {
            $users = $users + $roleusers;
        }
    }
    if ($sendtosupervisor) {
        $pmuserid = pm_get_crlmuserid($eventdata->userid);
        // Get all users with the notify_classenrol capability.
        if ($supervisors = pm_get_users_by_capability('user', $pmuserid, 'local/elisprogram:notify_classenrol')) {
            $users = $users + $supervisors;
        }
    }
    foreach ($users as $user) {
        //error_log("/local/elisprogram/lib/notifications.php::pm_notify_role_assign_handler(eventdata); Sending notification to user[{$user->id}]: {$user->email}");
        $message->send_notification($text, $user, $enroluser);
    }
    /// If you don't return true, the message queue will clog and no more will be sent.
    return true;
}
コード例 #8
0
ファイル: php_report_base.php プロジェクト: jamesmcq/elis
 /**
  * Returns a persons full name.
  *
  * Wrapper for elis_fullname() function that ensures all user fields exist.
  *
  * @param object $user A {@link $USER} object to get full name of.
  * @param bool $override If true then the name will be firstname followed by lastname rather than adhering to fullnamedisplay.
  * @return string
  */
 public static function fullname($user, $override = false) {
     global $CFG;
     require_once($CFG->dirroot.'/local/eliscore/lib.php');
     return elis_fullname($user, $override);
 }
コード例 #9
0
ファイル: deepsight_testlib.php プロジェクト: jamesmcq/elis
 /**
  * Gets a page of elements from the bulklist for display.
  *
  * @param array $ids An array of IDs to get information for.
  * @return array An array of information for the requested IDs. Contains labels indexed by IDs.
  */
 protected function bulklist_get_info_for_ids(array $ids = array())
 {
     if (empty($ids)) {
         return array();
     }
     $sql = 'SELECT id, firstname, lastname FROM {local_elisprogram_usr} WHERE id IN (' . implode(', ', array_fill(0, count($ids), '?')) . ')';
     $results = $this->DB->get_recordset_sql($sql, $ids);
     $pageresults = array_flip($ids);
     foreach ($results as $result) {
         $pageresults[$result->id] = elis_fullname($result);
     }
     return $pageresults;
 }
コード例 #10
0
 /**
  * Fullname is treated as a special columname in tablelib and should always
  * be treated the same as the fullname of a user.
  * @uses $this->useridfield if the userid field is not expected to be id
  * then you need to override $this->useridfield to point at the correct
  * field for the user id.
  *
  * ELIS version.
  *
  */
 function col_fullname($row)
 {
     global $COURSE, $CFG;
     if (!$this->download) {
         $params = array('s' => 'usr', 'id' => $row->{$this->useridfield}, 'action' => 'view');
         $url = new moodle_url($this->elisurl, $params);
         if ($COURSE->id != SITEID) {
             $url->param('course', $COURSE->id);
         }
         return html_writer::link($url, elis_fullname($row));
     } else {
         return elis_fullname($row);
     }
 }
コード例 #11
0
ファイル: user.table.php プロジェクト: jamesmcq/elis
 /**
  * Gets a page of elements from the bulklist for display.
  *
  * @param array $ids An array of IDs to get information for.
  * @return array An array of information for the requested IDs. Contains labels indexed by IDs.
  */
 protected function bulklist_get_info_for_ids(array $ids = array())
 {
     if (empty($ids)) {
         return array();
     }
     list($where, $params) = $this->DB->get_in_or_equal($ids);
     $sql = 'SELECT id, firstname, lastname FROM {' . $this->main_table . '} WHERE id ' . $where;
     $results = $this->DB->get_recordset_sql($sql, $params);
     $pageresults = array_flip($ids);
     foreach ($results as $result) {
         $pageresults[$result->id] = elis_fullname($result);
     }
     return $pageresults;
 }