/** * @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 advance control (update, insert or listing) * render to thematic_advance.php * @param string $action * */ public function thematic_advance($action) { $thematic = new Thematic(); $attendance = new Attendance(); $data = array(); $displayHeader = !empty($_REQUEST['display']) && $_REQUEST['display'] === 'no_header' ? false : true; // get data for attendance input select $attendance_list = $attendance->get_attendances_list(); $attendance_select = array(); $attendance_select[0] = get_lang('SelectAnAttendance'); foreach ($attendance_list as $attendance_id => $attendance_data) { $attendance_select[$attendance_id] = $attendance_data['name']; } $thematic_id = intval($_REQUEST['thematic_id']); $thematic_advance_id = isset($_REQUEST['thematic_advance_id']) ? intval($_REQUEST['thematic_advance_id']) : null; $thematic_advance_data = array(); switch ($action) { case 'thematic_advance_delete': if (!empty($thematic_advance_id)) { if (api_is_allowed_to_edit(null, true)) { $thematic->thematic_advance_destroy($thematic_advance_id); } header('Location: index.php'); exit; } break; case 'thematic_advance_list': if (!api_is_allowed_to_edit(null, true)) { echo ''; exit; } if (isset($_REQUEST['start_date_type']) && $_REQUEST['start_date_type'] == 1 && empty($_REQUEST['start_date_by_attendance']) || !empty($_REQUEST['duration_in_hours']) && !is_numeric($_REQUEST['duration_in_hours'])) { if ($_REQUEST['start_date_type'] == 1 && empty($_REQUEST['start_date_by_attendance'])) { $start_date_error = true; $data['start_date_error'] = $start_date_error; } if (!empty($_REQUEST['duration_in_hours']) && !is_numeric($_REQUEST['duration_in_hours'])) { $duration_error = true; $data['duration_error'] = $duration_error; } $data['action'] = $_REQUEST['action']; $data['thematic_id'] = $_REQUEST['thematic_id']; $data['attendance_select'] = $attendance_select; if (isset($_REQUEST['thematic_advance_id'])) { $data['thematic_advance_id'] = $_REQUEST['thematic_advance_id']; $thematic_advance_data = $thematic->get_thematic_advance_list($_REQUEST['thematic_advance_id']); $data['thematic_advance_data'] = $thematic_advance_data; } } else { if (api_is_allowed_to_edit(null, true)) { $thematic_advance_id = isset($_REQUEST['thematic_advance_id']) ? $_REQUEST['thematic_advance_id'] : null; $thematic_id = $_REQUEST['thematic_id']; $content = isset($_REQUEST['content']) ? $_REQUEST['content'] : null; $duration = isset($_REQUEST['duration_in_hours']) ? $_REQUEST['duration_in_hours'] : null; if (isset($_REQUEST['start_date_type']) && $_REQUEST['start_date_type'] == 2) { $start_date = $_REQUEST['custom_start_date']; $attendance_id = 0; } else { $start_date = isset($_REQUEST['start_date_by_attendance']) ? $_REQUEST['start_date_by_attendance'] : null; $attendance_id = isset($_REQUEST['attendance_select']) ? $_REQUEST['attendance_select'] : null; } $thematic->set_thematic_advance_attributes($thematic_advance_id, $thematic_id, $attendance_id, $content, $start_date, $duration); $affected_rows = $thematic->thematic_advance_save(); if ($affected_rows) { // get last done thematic advance before move thematic list $last_done_thematic_advance = $thematic->get_last_done_thematic_advance(); // update done advances with de current thematic list if (!empty($last_done_thematic_advance)) { $thematic->update_done_thematic_advances($last_done_thematic_advance); } } } } break; default: $thematic_advance_data = $thematic->get_thematic_advance_list($thematic_advance_id); break; } // get calendar select by attendance id $calendar_select = array(); if (!empty($thematic_advance_data)) { if (!empty($thematic_advance_data['attendance_id'])) { $attendance_calendar = $attendance->get_attendance_calendar($thematic_advance_data['attendance_id']); if (!empty($attendance_calendar)) { foreach ($attendance_calendar as $calendar) { $calendar_select[$calendar['date_time']] = $calendar['date_time']; } } } } $data['action'] = $action; $data['thematic_id'] = $thematic_id; $data['thematic_advance_id'] = $thematic_advance_id; $data['attendance_select'] = $attendance_select; $data['thematic_advance_data'] = $thematic_advance_data; $data['calendar_select'] = $calendar_select; $layoutName = $displayHeader ? 'layout' : 'layout_no_header'; // render to the view $this->view->set_data($data); $this->view->set_layout($layoutName); $this->view->set_template('thematic_advance'); $this->view->render(); }