Beispiel #1
0
 /**
  * Called after updating/inserting course.
  *
  * @param bool $inserted true if course just inserted
  * @param object $course
  * @param object $data form data
  * @return void
  */
 public function course_updated($inserted, $course, $data)
 {
     global $DB;
     if ($inserted) {
         if (isset($data->enrol_guest_status_0)) {
             $fields = array('status' => $data->enrol_guest_status_0);
             if ($fields['status'] == ENROL_INSTANCE_ENABLED) {
                 $fields['password'] = $data->enrol_guest_password_0;
             } else {
                 if ($this->get_config('requirepassword')) {
                     $fields['password'] = generate_password(20);
                 }
             }
             $this->add_instance($course, $fields);
         } else {
             if ($this->get_config('defaultenrol')) {
                 $this->add_default_instance($course);
             }
         }
     } else {
         $instances = $DB->get_records('enrol', array('courseid' => $course->id, 'enrol' => 'guest'));
         foreach ($instances as $instance) {
             $i = $instance->id;
             if (isset($data->{'enrol_guest_status_' . $i})) {
                 $reset = $instance->status != $data->{'enrol_guest_status_' . $i};
                 $instance->status = $data->{'enrol_guest_status_' . $i};
                 $instance->timemodified = time();
                 if ($instance->status == ENROL_INSTANCE_ENABLED) {
                     if ($instance->password !== $data->{'enrol_guest_password_' . $i}) {
                         $reset = true;
                     }
                     $instance->password = $data->{'enrol_guest_password_' . $i};
                 }
                 $DB->update_record('enrol', $instance);
                 \core\event\enrol_instance_updated::create_from_record($instance)->trigger();
                 if ($reset) {
                     $context = context_course::instance($course->id);
                     $context->mark_dirty();
                 }
             }
         }
     }
 }
Beispiel #2
0
        }
        if (!$data->expirynotify) {
            // Keep previous/default value of disabled expirythreshold option.
            $data->expirythreshold = $instance->expirythreshold;
        }
        if ($instance->id) {
            $instance->roleid = $data->roleid;
            $instance->enrolperiod = $data->enrolperiod;
            $instance->expirynotify = $data->expirynotify;
            $instance->notifyall = $data->notifyall;
            $instance->expirythreshold = $data->expirythreshold;
            $instance->timemodified = time();
            $markdirty = $instance->status != $data->status;
            $instance->status = $data->status;
            $DB->update_record('enrol', $instance);
            \core\event\enrol_instance_updated::create_from_record($instance)->trigger();
            if ($markdirty) {
                $context->mark_dirty();
            }
        } else {
            $fields = array('status' => $data->status, 'roleid' => $data->roleid, 'enrolperiod' => $data->enrolperiod, 'expirynotify' => $data->expirynotify, 'notifyall' => $data->notifyall, 'expirythreshold' => $data->expirythreshold);
            $plugin->add_instance($course, $fields);
        }
        redirect($return);
    }
}
$PAGE->set_title(get_string('pluginname', 'enrol_manual'));
$PAGE->set_heading($course->fullname);
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('pluginname', 'enrol_manual'));
$mform->display();
Beispiel #3
0
 /**
  * Update instance status
  *
  * Override when plugin needs to do some action when enabled or disabled.
  *
  * @param stdClass $instance
  * @param int $newstatus ENROL_INSTANCE_ENABLED, ENROL_INSTANCE_DISABLED
  * @return void
  */
 public function update_status($instance, $newstatus)
 {
     global $DB;
     $instance->status = $newstatus;
     $DB->update_record('enrol', $instance);
     $context = context_course::instance($instance->courseid);
     \core\event\enrol_instance_updated::create_from_record($instance)->trigger();
     // Invalidate all enrol caches.
     $context->mark_dirty();
 }