예제 #1
0
 /**
  * Test sync-ing an ELIS User Profile field to a DELETED Moodle User Profile field
  */
 public function test_syncpmuserfieldtodeletedmoodleprofilefield()
 {
     global $CFG, $DB;
     require_once $CFG->dirroot . '/user/profile/definelib.php';
     $this->load_csv_data();
     // Set PM Custom User field(s) to Sync to Moodle.
     $ctxlvl = CONTEXT_ELIS_USER;
     $fields = field::get_for_context_level($ctxlvl);
     foreach ($fields as $field) {
         $fieldobj = new field($field);
         if (!isset($fieldobj->owners['moodle_profile'])) {
             $fieldobj->owners['moodle_profile'] = new stdClass();
         }
         $owner = new field_owner($fieldobj->owners['moodle_profile']);
         $owner->exclude = pm_moodle_profile::sync_from_moodle;
         $owner->save();
         $fieldobj->save();
     }
     // Read a record.
     $src = new user(103, null, array(), false, array());
     $src->reset_custom_field_list();
     // Modify the data.
     $src->firstname = 'Testuser';
     $src->lastname = 'One';
     $src->field_sometext = 'boo';
     $src->field_sometextfrompm = 'bla';
     $src->save();
     // Delete some custom Moodle Profile field(s) to cause old error (pre ELIS-4499).
     $fields = field::get_for_context_level($ctxlvl);
     foreach ($fields as $field) {
         $fieldobj = new field($field);
         if ($moodlefield = $DB->get_record('user_info_field', array('shortname' => $fieldobj->shortname))) {
             profile_delete_field($moodlefield->id);
         }
     }
     // Run the library sync - throws errors not exceptions :(.
     $CFG->mnet_localhost_id = 1;
     // ???
     $mu = cm_get_moodleuser(103);
     try {
         $result = pm_moodle_user_to_pm($mu);
         $this->assertTrue($result);
     } catch (Exception $ex) {
         $this->assertTrue(false, $ex->message);
     }
 }
예제 #2
0
 function save_field_data()
 {
     static $loopdetect;
     if (!empty($loopdetect)) {
         return true;
     }
     field_data::set_for_context_from_datarecord('user', $this);
     $loopdetect = true;
     events_trigger('user_updated', cm_get_moodleuser($this->id));
     $loopdetect = false;
     return true;
 }
예제 #3
0
/**
 *
 */
function cm_update_student_enrolment()
{
    global $CURMAN;
    //for every student
    $select = 'completestatusid = ' . STUSTATUS_NOTCOMPLETE . ' AND endtime > 0 AND endtime < ' . time();
    $students = $CURMAN->db->get_records_select(STUTABLE, $select);
    if (!empty($students)) {
        foreach ($students as $s) {
            $a = $CURMAN->db->get_field('crlm_class', 'idnumber', 'id', $s->classid);
            $subject = get_string('incomplete_course_subject', 'block_curr_admin');
            $message = get_string('incomplete_course_message', 'block_curr_admin', $a);
            $user = cm_get_moodleuser($s->userid);
            $from = get_admin();
            notification::notify($message, $user, $from);
            email_to_user($user, $from, $subject, $message);
            $s->completetime = 0;
            $s->completestatusid = STUSTATUS_FAILED;
            $CURMAN->db->update_record(STUTABLE, $s);
        }
    }
    return true;
}
예제 #4
0
 /**
  *
  * @global <type> $CURMAN
  */
 public function add()
 {
     global $CURMAN;
     if (empty($this->position)) {
         //SELECT MIN(userid) FROM eli_crlm_wait_list WHERE 1
         $sql = 'SELECT ' . sql_max('position') . ' as max 
                 FROM ' . $CURMAN->db->prefix_table(WATLSTTABLE) . ' as wl
                 WHERE wl.classid = ' . $this->classid;
         $max_record = get_record_sql($sql);
         $max = $max_record->max;
         $this->position = $max + 1;
     }
     $subject = get_string('waitlist', 'block_curr_admin');
     $cmclass = new cmclass($this->classid);
     $message = get_string('added_to_waitlist_message', 'block_curr_admin', $cmclass->idnumber);
     $user = cm_get_moodleuser($this->userid);
     $from = get_admin();
     // Send a notification and e-mail only if the Moodle user exists
     if ($user != null) {
         notification::notify($message, $user, $from);
         email_to_user($user, $from, $subject, $message);
     }
     parent::add();
 }
예제 #5
0
 public function send_notification($message = '', $userto = null, $userfrom = null, $logevent = false)
 {
     global $USER;
     /// Handle parameters:
     if (!empty($userto)) {
         $this->userto = $userto;
     } else {
         if (empty($this->userto)) {
             print_error('message_nodestinationuser', 'block_curr_admin');
             return false;
         }
     }
     if (!empty($userfrom)) {
         $this->userfrom = $userfrom;
     } else {
         if (empty($this->userfrom)) {
             $this->userfrom = $USER;
         }
     }
     if ($message != '') {
         $this->fullmessage = $message;
     }
     /// Check for the user object type. If a CM User was sent in, need to get the Moodle object.
     //todo: convert this code to use "is_a"
     $tocmuserid = false;
     if (get_class($this->userto) == 'user') {
         $tocmuserid = $this->userto->id;
         if (!($this->userto = cm_get_moodleuser($this->userto->id))) {
             debugging(get_string('nomoodleuser', 'block_curr_admin'));
         }
     }
     if (get_class($this->userfrom) == 'user') {
         if (!($this->userfrom = cm_get_moodleuser($this->userfrom->id))) {
             debugging(get_string('nomoodleuser', 'block_curr_admin'));
             $this->userfrom = get_admin();
         }
     }
     /// Handle unset variables:
     $this->name = $this->name == '' ? $this->defname : $this->name;
     $this->subject = $this->subject == '' ? $this->defsubject : $this->subject;
     $eventname = 'message_send';
     if (!empty($this->userto)) {
         events_trigger($eventname, $this);
     }
     /// Insert a notification log if we have data for it.
     if ($logevent !== false) {
         if (!empty($logevent->event)) {
             $newlog = new Object();
             $newlog->event = $logevent->event;
             if (isset($logevent->userid)) {
                 $newlog->userid = $logevent->userid;
             } else {
                 if ($tocmuserid === false) {
                     $newlog->userid = !empty($this->userto) ? cm_get_crlmuserid($this->userto->id) : 0;
                     //TBD: this should never happen!?!
                 } else {
                     $newlog->userid = $tocmuserid;
                 }
             }
             //if the log entry specifies which user triggered the event,
             //store that info
             //NOTE: Do not use $userfrom because that is the message sender
             //but not necessarily the user whose criteria triggered the event
             if (isset($logevent->fromuserid)) {
                 $newlog->fromuserid = $logevent->fromuserid;
             }
             if (isset($logevent->instance)) {
                 $newlog->instance = $logevent->instance;
             }
             if (isset($logevent->data)) {
                 $newlog->data = $logevent->data;
             }
             if (isset($logevent->timecreated)) {
                 $newlog->timecreated = $logevent->timecreated;
             } else {
                 $newlog->timecreated = time();
             }
             insert_record('crlm_notification_log', $newlog);
         }
     }
 }