Exemplo n.º 1
0
 /**
  * Unenrol a user from a courses
  * @param object $user
  * @param array $courseids
  * @param int $companyid
  * @return void
  */
 public static function unenrol($user, $courseids, $companyid = null)
 {
     global $DB, $PAGE;
     foreach ($courseids as $courseid) {
         if (!$DB->get_record('iomad_courses', array('courseid' => $courseid, 'shared' => 0))) {
             $shared = true;
         } else {
             $shared = false;
         }
         $course = $DB->get_record('course', array('id' => $courseid));
         $courseenrolmentmanager = new course_enrolment_manager($PAGE, $course);
         $ues = $courseenrolmentmanager->get_user_enrolments($user->id);
         foreach ($ues as $ue) {
             if ($ue->enrolmentinstance->courseid == $courseid) {
                 $courseenrolmentmanager->unenrol_user($ue);
                 if ($shared) {
                     if (!empty($companyid)) {
                         company::remove_user_from_shared_course($courseid, $user->id, $companyid);
                     }
                 }
             }
         }
     }
 }