get user enroll day and enrolled period of a given course with given user id

StackOverflow https://stackoverflow.com/questions/21898101

  •  13-10-2022
  •  | 
  •  

Вопрос

I working on send email when user manually enrolled to course.,by now i can send a email when user enroll to the system what i want to know is send enrollment expire date with the email,so if i can get from database that will work for me..,(any other method which can get this insie enroll unction also fine)

this is where i try to pass this parameters

 public function enrol_user(stdClass $instance, $userid, $roleid = NULL, $timestart = 0, $timeend = 0, $status = NULL, $recovergrades = NULL) {
    global $DB;

    $alreadyenroled = $DB->record_exists('user_enrolments', array('enrolid' => $instance->id, 'userid' => $userid));
    parent::enrol_user($instance, $userid, $roleid, $timestart, $timeend, $status, $recovergrades);
    if (!$alreadyenroled && $instance->customint4) {
        // Don't email immediately - give the admin a chance to remove users
        // who were added by mistake
        $this->queue_welcome_message($instance->id, $userid,$timestart,$timeend);
    }
}

 protected function queue_welcome_message($instanceid, $userid,$timestart,$timeend) {
    global $DB;

    if ($DB->record_exists('enrol_manual_email', array('instanceid' => $instanceid,
                                                       'userid' => $userid,'ts' => $timestart,'te' => $timeend))) {
        return;
    }

    $ins = new stdClass();
    $ins->instanceid = $instanceid;
    $ins->userid = $userid;
    ////edit lasitha
    $ins->ts = $timestart;
    $ins->te = $timeend;
    $DB->insert_record('enrol_manual_email', $ins);
}
Это было полезно?

Решение 2

This code helps me to get what i want to get

$user_enroll_data = $DB->get_record('user_enrolments', array('enrolid'=>$instance->id, 'userid'=>$user->id));

$normal_st_date=date('Y-m-d', $user_enroll_data->timestart);//course start date
$normal_end_date=date('Y-m-d',$user_enroll_data->timeend);//course end date

Другие советы

The best way to do this, so that it won't break when you update your Moodle site to a new version, would be to create a new local plugin ( http://docs.moodle.org/dev/Local_plugins ). Then you can make use of the Moodle events API ( http://docs.moodle.org/dev/Events_API ) to subscribe to 'user_enrolled' events.

The data you get from the events API will include the field 'timeend' (from the table mdl_user_enrolments) which is the timestamp of when the enrolment will expire. If this field is '0', then it means the enrolment will not expire. If it is any other value, then you can call:

userdate($data->timeend, get_string('strftimedate'));

to format this as a date.

(See '/lang/en/langconfig.php' for other time formats you can use - note also, this date will be based on the timezone of the current logged in user - you may need to use the 'timezone' parameter of 'userdate', if you want to make sure it is the right timezone for the receiving user).

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top