public function accept_unsubscribe_request_multiTask() { $_requests = Get::req('requests', DOTY_MIXED, FALSE); if (!$_requests) { //... } $res = TRUE; $smodel = new SubscriptionAlms(); $list = explode(",", $_requests); foreach ($list as $request) { list($user_id, $idCourse, $res_id, $r_type) = explode("_", $request); switch ($r_type) { case "course": $res = $smodel->unsubscribeUser($user_id, $idCourse); break; case "edition": $res = $smodel->unsubscribeUser($user_id, $idCourse, $res_id); break; case "classroom": $res = $smodel->unsubscribeUser($user_id, $idCourse, false, $res_id); break; } } $output = array('success' => $res ? TRUE : FALSE); echo $this->json->encode($output); }
/** * The action of self-unsubscription from a course (if enabled for the course), * available in the course box of the courses list */ public function self_unsubscribe() { $id_user = Docebo::user()->idst; //Get::req('id_user', DOTY_INT, Docebo::user()->idst); $id_course = Get::req('id_course', DOTY_INT, 0); $id_edition = Get::req('id_edition', DOTY_INT, 0); $id_date = Get::req('id_date', DOTY_INT, 0); $cmodel = new CourseAlms(); $cinfo = $cmodel->getCourseModDetails($id_course); //index.php?r=elearning/show $back = Get::req('back', DOTY_STRING, ""); if ($back != "") { $parts = explode('/', $back); $length = count($parts); if ($length > 0) { $parts[$length - 1] = 'show'; $back = implode('/', $parts); } } $jump_url = 'index.php?r=' . ($back ? $back : 'lms/elearning/show'); if ($cinfo['auto_unsubscribe'] == 0) { //no self unsubscribe possible for this course Util::jump_to($jump_url . '&res=err_unsub'); } $date_ok = TRUE; if ($cinfo['unsubscribe_date_limit'] != "" && $cinfo['unsubscribe_date_limit'] != "0000-00-00 00:00:00") { if ($cinfo['unsubscribe_date_limit'] < date("Y-m-d H:i:s")) { //self unsubscribing is no more allowed, go back to courselist page Util::jump_to($jump_url . '&res=err_unsub'); } } $smodel = new SubscriptionAlms(); $param = ''; if ($cinfo['auto_unsubscribe'] == 1) { //moderated self unsubscribe $res = $smodel->setUnsubscribeRequest($id_user, $id_course, $id_edition, $id_date); $param .= $res ? '&res=ok_unsub' : '&res=err_unsub'; } if ($cinfo['auto_unsubscribe'] == 2) { //directly unsubscribe user $res = $smodel->unsubscribeUser($id_user, $id_course, $id_edition, $id_date); $param .= $res ? '&res=ok_unsub' : '&res=err_unsub'; } Util::jump_to($jump_url); }