public function subscribeUser($id_user, $level, $waiting, $date_begin_validity = FALSE, $date_expire_validity = FALSE) { if ($this->id_edition != 0) { require_once _lms_ . '/lib/lib.edition.php'; $edition_man = new EditionManager(); return $edition_man->subscribeUserToEdition($id_user, $this->id_course, $this->id_edition, $level, $waiting, $date_begin_validity, $date_expire_validity); } elseif ($this->id_date != 0) { require_once _lms_ . '/lib/lib.date.php'; $date_man = new DateManager(); return $date_man->subscribeUserToDate($id_user, $this->id_course, $this->id_date, $level, $waiting, $date_begin_validity, $date_expire_validity); } else { require_once _lms_ . '/lib/lib.subscribe.php'; $subscribe_man = new CourseSubscribe_Manager(); return $subscribe_man->subscribeUserToCourse($id_user, $this->id_course, $level, $waiting, $date_begin_validity, $date_expire_validity); } }
protected function _subscribeUsersToCatalogue($data) { require_once _lms_ . '/lib/lib.course.php'; require_once _lms_ . '/lib/lib.subscribe.php'; require_once _lms_ . '/lib/lib.edition.php'; require_once _lms_ . '/lib/lib.date.php'; $subscribe_man = new CourseSubscribe_Manager(); $edition_man = new EditionManager(); $date_man = new DateManager(); $user_subscribed = array(); $user_waiting = array(); //check users who are already subscribed in any selected course $arr_courses = array(); foreach ($data as $value) { list($id_user, $id_course, $id_edition, $id_date) = $value; $arr_courses[] = $id_course; } $arr_editions = $edition_man->getCourseEditions($arr_courses); $arr_classrooms = $date_man->getCourseDate($arr_courses); //get subscriptions to courses and editions $already_courses = $subscribe_man->getCourseSubscribedUserIdst($arr_courses, true); $already_editions = $edition_man->getEditionSubscribed($arr_editions, true); $already_classrooms = $date_man->getDatesSubscribed(array_keys($arr_classrooms), true); //subscribe users $count_u = 0; $count_e = 0; $count_d = 0; $lv_user = 3; //only students can be managed for multiple subscriptions $waiting = false; //no waiting condition reset($data); foreach ($data as $value) { list($id_user, $id_course, $id_edition, $id_date) = $value; $_u_subscribed = false; if ($id_date) { if (!isset($already_classrooms[$id_date][$id_user])) { //subscribe to classroom $res = $date_man->subscribeUserToDate($id_user, $id_course, $id_date, $lv_user, $waiting); if ($res) { $count_d++; } if ($res) { $_u_subscribed = true; } // user subscribed } } elseif ($id_edition) { if (!isset($already_editions[$id_edition][$id_user])) { //subscribe to edition $res = $edition_man->subscribeUserToEdition($id_user, $id_course, $id_edition, $lv_user, $waiting); if ($res) { $count_e++; } if ($res) { $_u_subscribed = true; } // user subscribed } } else { if (!isset($already_courses[$id_course][$id_user])) { //subscribe to course $res = $subscribe_man->subscribeUserToCourse($id_user, $id_course, $lv_user, $waiting); if ($res) { $count_u++; } if ($res) { $_u_subscribed = true; } // user subscribed } } if ($_u_subscribed) { // user subscribed $docebo_course = new DoceboCourse($id_course); $level_idst =& $docebo_course->getCourseLevel($id_course); if (count($level_idst) == 0 || $level_idst[1] == '') { $level_idst =& $docebo_course->createCourseLevel($id_course); } $this->_addToCourseGroup($level_idst[$lv_user], $id_user); } } /* //send alerts if(!empty($user_subscribed)) { _sendSubscribedAlert($user_subscribed, $course_info); } if(!empty($user_waiting)) { _sendWaitingAlert($user_waiting, $course_info); } */ return $count_u + $count_e + $count_d; }