/** * @param int $thematic_id */ public function copy($thematic_id) { $thematic = self::get_thematic_list($thematic_id, api_get_course_id(), 0); $thematic_copy = new Thematic(); $thematic_copy->set_thematic_attributes('', $thematic['title'] . ' - ' . get_lang('Copy'), $thematic['content'], api_get_session_id()); $new_thematic_id = $thematic_copy->thematic_save(); if (!empty($new_thematic_id)) { $thematic_advanced = self::get_thematic_advance_by_thematic_id($thematic_id); if (!empty($thematic_advanced)) { foreach ($thematic_advanced as $item) { $thematic = new Thematic(); $thematic->set_thematic_advance_attributes(0, $new_thematic_id, 0, $item['content'], $item['start_date'], $item['duration']); $thematic->thematic_advance_save(); } } $thematic_plan = self::get_thematic_plan_data($thematic_id); if (!empty($thematic_plan)) { foreach ($thematic_plan as $item) { $thematic = new Thematic(); $thematic->set_thematic_plan_attributes($new_thematic_id, $item['title'], $item['description'], $item['description_type']); $thematic->thematic_plan_save(); } } } }
/** * This method is used for thematic plan control (update, insert or listing) * @param string Action * render to thematic_plan.php */ public function thematic_plan($action) { $courseInfo = api_get_course_info(); $thematic = new Thematic($courseInfo); $data = array(); $error = false; if (strtoupper($_SERVER['REQUEST_METHOD']) == "POST") { if (isset($_POST['action']) && ($_POST['action'] == 'thematic_plan_add' || $_POST['action'] == 'thematic_plan_edit')) { if (isset($_POST['title'])) { if ($_POST['thematic_plan_token'] == $_SESSION['thematic_plan_token']) { if (api_is_allowed_to_edit(null, true)) { $title_list = $_REQUEST['title']; $description_list = $_REQUEST['description']; $description_type = $_REQUEST['description_type']; $delete_list = $_REQUEST['delete']; foreach ($title_list as $id => $title) { $thematic_plan_id = $id; if (!$thematic->get_thematic_data_by_id($id)) { $thematic_plan_id = null; } $thematic->set_thematic_plan_attributes($_REQUEST['thematic_id'], $title, $description_list[$id], $description_type[$id], $thematic_plan_id); if (isset($delete_list[$id]) && !empty($delete_list[$id])) { $thematic->thematic_plan_delete(); } else { $affected_rows = $thematic->thematic_plan_save(); } } unset($_SESSION['thematic_plan_token']); $data['message'] = 'ok'; } $data['action'] = 'thematic_plan_list'; } } else { $error = true; $action = $_POST['action']; $data['error'] = $error; $data['thematic_plan_data'] = $thematic->get_thematic_plan_data($_POST['thematic_id'], $_POST['description_type']); $data['thematic_id'] = $_POST['thematic_id']; $data['description_type'] = $_POST['description_type']; $data['action'] = $action; $data['default_thematic_plan_title'] = $thematic->get_default_thematic_plan_title(); $data['default_thematic_plan_icon'] = $thematic->get_default_thematic_plan_icon(); $data['default_thematic_plan_question'] = $thematic->get_default_question(); $data['next_description_type'] = $thematic->get_next_description_type($_POST['thematic_id']); // render to the view $this->view->set_data($data); $this->view->set_layout('layout'); $this->view->set_template('thematic_plan'); $this->view->render(); } } } $thematic_id = intval($_GET['thematic_id']); if ($action == 'thematic_plan_list') { $data['thematic_plan_data'] = $thematic->get_thematic_plan_data($thematic_id); } $description_type = intval($_GET['description_type']); if (!empty($thematic_id) && !empty($description_type)) { if ($action == 'thematic_plan_delete') { if (api_is_allowed_to_edit(null, true)) { $affected_rows = $thematic->thematic_plan_destroy($thematic_id, $description_type); } $data['thematic_plan_data'] = $thematic->get_thematic_plan_data($thematic_id); $action = 'thematic_plan_list'; } else { $data['thematic_plan_data'] = $thematic->get_thematic_plan_data($thematic_id, $description_type); } $data['thematic_id'] = $thematic_id; $data['description_type'] = $description_type; } else { if (!empty($thematic_id) && $action == 'thematic_plan_list') { $data['thematic_plan_data'] = $thematic->get_thematic_plan_data($thematic_id); $data['thematic_id'] = $thematic_id; } } $data['thematic_id'] = $thematic_id; $data['action'] = $action; $data['default_thematic_plan_title'] = $thematic->get_default_thematic_plan_title(); $data['default_thematic_plan_icon'] = $thematic->get_default_thematic_plan_icon(); $data['next_description_type'] = $thematic->get_next_description_type($thematic_id); $data['default_thematic_plan_question'] = $thematic->get_default_question(); $data['thematic_data'] = $thematic->get_thematic_list($thematic_id); //render to the view $this->view->set_data($data); $this->view->set_layout('layout'); $this->view->set_template('thematic_plan'); $this->view->render(); exit; }
/** * This method is used for thematic plan control (update, insert or listing) * @param string $action * render to thematic_plan.php */ public function thematic_plan($action) { $thematic = new Thematic(); $data = array(); if (strtoupper($_SERVER['REQUEST_METHOD']) == "POST") { if (isset($_POST['action']) && ($_POST['action'] == 'thematic_plan_add' || $_POST['action'] == 'thematic_plan_edit')) { if (isset($_POST['title'])) { if ($_POST['thematic_plan_token'] == $_SESSION['thematic_plan_token']) { if (api_is_allowed_to_edit(null, true)) { $title_list = $_REQUEST['title']; $description_list = $_REQUEST['description']; $description_type = $_REQUEST['description_type']; for ($i = 1; $i < count($title_list) + 1; $i++) { $thematic->set_thematic_plan_attributes($_REQUEST['thematic_id'], $title_list[$i], $description_list[$i], $description_type[$i]); $thematic->thematic_plan_save(); } unset($_SESSION['thematic_plan_token']); $data['message'] = 'ok'; $saveRedirect = api_get_path(WEB_PATH) . 'main/course_progress/index.php?'; $saveRedirect .= api_get_cidreq() . '&'; $saveRedirect .= 'thematic_plan_save_message=ok'; header("Location: {$saveRedirect}"); exit; } $data['action'] = 'thematic_plan_list'; } } else { $error = true; $action = $_POST['action']; $data['error'] = $error; $data['thematic_plan_data'] = $thematic->get_thematic_plan_data($_POST['thematic_id'], $_POST['description_type']); $data['thematic_id'] = $_POST['thematic_id']; $data['description_type'] = $_POST['description_type']; $data['action'] = $action; $data['default_thematic_plan_title'] = $thematic->get_default_thematic_plan_title(); $data['default_thematic_plan_icon'] = $thematic->get_default_thematic_plan_icon(); $data['default_thematic_plan_question'] = $thematic->get_default_question(); $data['next_description_type'] = $thematic->get_next_description_type($_POST['thematic_id']); // render to the view $this->view->set_data($data); $this->view->set_layout('layout'); $this->view->set_template('thematic_plan'); $this->view->render(); } } } $thematic_id = intval($_GET['thematic_id']); if ($action == 'thematic_plan_list') { $data['thematic_plan_data'] = $thematic->get_thematic_plan_data($thematic_id); } $description_type = isset($_GET['description_type']) ? intval($_GET['description_type']) : null; if (!empty($thematic_id) && !empty($description_type)) { if ($action == 'thematic_plan_delete') { if (api_is_allowed_to_edit(null, true)) { $thematic->thematic_plan_destroy($thematic_id, $description_type); } $data['thematic_plan_data'] = $thematic->get_thematic_plan_data($thematic_id); $action = 'thematic_plan_list'; } else { $data['thematic_plan_data'] = $thematic->get_thematic_plan_data($thematic_id, $description_type); } $data['thematic_id'] = $thematic_id; $data['description_type'] = $description_type; } else { if (!empty($thematic_id) && $action == 'thematic_plan_list') { $data['thematic_plan_data'] = $thematic->get_thematic_plan_data($thematic_id); $data['thematic_id'] = $thematic_id; } } $data['thematic_id'] = $thematic_id; $data['action'] = $action; $data['default_thematic_plan_title'] = $thematic->get_default_thematic_plan_title(); $data['default_thematic_plan_icon'] = $thematic->get_default_thematic_plan_icon(); $data['next_description_type'] = $thematic->get_next_description_type($thematic_id); $data['default_thematic_plan_question'] = $thematic->get_default_question(); $data['thematic_data'] = $thematic->get_thematic_list($thematic_id); //render to the view $this->view->set_data($data); $this->view->set_layout('layout'); $this->view->set_template('thematic_plan'); $this->view->render(); exit; }
static function create_thematic($data) { //error_log('create_thematic'); $session_id = $data['session_id']; if (!empty($session_id)) { $course_list = SessionManager::get_course_list_by_session_id($session_id); if (!empty($course_list)) { $course_data = current($course_list); $course_info = api_get_course_info($course_data['code']); if (!empty($course_data)) { $thematic = new Thematic($course_info); $thematic->set_course_int_id($course_info['real_id']); $thematic->set_session_id($session_id); $thematic_info = $thematic->get_thematic_by_title($data['thematic']); if (empty($thematic_info)) { $thematic->set_thematic_attributes(null, $data['thematic'], null, $session_id); $thematic_id = $thematic->thematic_save(); error_log("Thematic added to course code: {$course_info['code']} - session_id: {$session_id}"); } else { $thematic_id = isset($thematic_info['id']) ? $thematic_info['id'] : null; error_log("Thematic id #{$thematic_id} found in course: {$course_info['code']} - session_id: {$session_id}"); } if ($thematic_id) { $thematic->set_thematic_plan_attributes($thematic_id, $data['thematic_plan'], null, 6); $thematic->thematic_plan_save(); error_log("Saving plan attributes: {$data['thematic_plan']}"); } error_log("Adding thematic id : {$thematic_id} to session: {$session_id} to course: {$course_info['code']} real_id: {$course_info['real_id']}"); if ($thematic_id) { error_log("Thematic saved: {$thematic_id}"); } else { error_log("Thematic NOT saved"); } } //if ($course_info['code'] != 'B05') { //exit; //} } else { error_log("No courses in session {$session_id} "); } } }