Пример #1
0
 /**
  * This method is used for thematic control (update, insert or listing)
  * @param 	string	Action
  * render to thematic.php
  */
 public function thematic($action)
 {
     $thematic = new Thematic();
     $data = array();
     $error = false;
     $msg_add = false;
     $check = Security::check_token('request');
     $thematic_id = isset($_REQUEST['thematic_id']) ? intval($_REQUEST['thematic_id']) : null;
     $displayHeader = !empty($_REQUEST['display']) && $_REQUEST['display'] === 'no_header' ? false : true;
     if ($check) {
         switch ($action) {
             case 'thematic_add':
             case 'thematic_edit':
                 // insert or update a thematic
                 if (strtoupper($_SERVER['REQUEST_METHOD']) == "POST") {
                     if (trim($_POST['title']) !== '') {
                         if (api_is_allowed_to_edit(null, true)) {
                             $id = isset($_POST['thematic_id']) ? $_POST['thematic_id'] : null;
                             $title = trim($_POST['title']);
                             $content = trim($_POST['content']);
                             $session_id = api_get_session_id();
                             $thematic->set_thematic_attributes($id, $title, $content, $session_id);
                             $last_id = $thematic->thematic_save();
                             if ($_POST['action'] == 'thematic_add') {
                                 $action = 'thematic_details';
                                 $thematic_id = null;
                                 if ($last_id) {
                                     $data['last_id'] = $last_id;
                                 }
                             } else {
                                 $action = 'thematic_details';
                                 $thematic_id = null;
                             }
                         }
                     } else {
                         $error = true;
                         $data['error'] = $error;
                         $data['action'] = $_POST['action'];
                         $data['thematic_id'] = $_POST['thematic_id'];
                         // render to the view
                         $this->view->set_data($data);
                         $this->view->set_layout('layout');
                         $this->view->set_template('thematic');
                         $this->view->render();
                     }
                 }
                 break;
             case 'thematic_copy':
                 //Copy a thematic to a session
                 $thematic->copy($thematic_id);
                 $thematic_id = null;
                 $action = 'thematic_details';
                 break;
             case 'thematic_delete_select':
                 //Delete many thematics
                 if (strtoupper($_SERVER['REQUEST_METHOD']) == "POST") {
                     if (api_is_allowed_to_edit(null, true)) {
                         $thematic_ids = $_POST['id'];
                         $affected_rows = $thematic->thematic_destroy($thematic_ids);
                     }
                     $action = 'thematic_details';
                 }
                 break;
             case 'thematic_delete':
                 // Delete a thematic
                 if (isset($thematic_id)) {
                     if (api_is_allowed_to_edit(null, true)) {
                         $thematic->thematic_destroy($thematic_id);
                     }
                     $thematic_id = null;
                     $action = 'thematic_details';
                 }
                 break;
             case 'thematic_import_select':
                 break;
             case 'thematic_import':
                 $csv_import_array = Import::csvToArray($_FILES['file']['tmp_name']);
                 if (isset($_POST['replace']) && $_POST['replace']) {
                     // Remove current thematic.
                     $list = $thematic->get_thematic_list();
                     foreach ($list as $i) {
                         $thematic->thematic_destroy($i);
                     }
                 }
                 // Import the progress.
                 $current_thematic = null;
                 foreach ($csv_import_array as $item) {
                     $key = $item['type'];
                     switch ($key) {
                         case 'title':
                             $thematic->set_thematic_attributes(null, $item['data1'], $item['data2'], api_get_session_id());
                             $current_thematic = $thematic->thematic_save();
                             $description_type = 0;
                             break;
                         case 'plan':
                             $thematic->set_thematic_plan_attributes($current_thematic, $item['data1'], $item['data2'], $description_type);
                             $thematic->thematic_plan_save();
                             $description_type++;
                             break;
                         case 'progress':
                             $thematic->set_thematic_advance_attributes(null, $current_thematic, 0, $item['data3'], $item['data1'], $item['data2']);
                             $thematic->thematic_advance_save();
                             break;
                     }
                 }
                 $action = 'thematic_details';
                 break;
             case 'thematic_export':
                 $list = $thematic->get_thematic_list();
                 $csv = array();
                 $csv[] = array('type', 'data1', 'data2', 'data3');
                 foreach ($list as $theme) {
                     $csv[] = array('title', $theme['title'], $theme['content']);
                     $data = $thematic->get_thematic_plan_data($theme['id']);
                     if (!empty($data)) {
                         foreach ($data as $plan) {
                             $csv[] = array('plan', $plan['title'], $plan['description']);
                         }
                     }
                     $data = $thematic->get_thematic_advance_by_thematic_id($theme['id']);
                     if (!empty($data)) {
                         foreach ($data as $advance) {
                             $csv[] = array('progress', $advance['start_date'], $advance['duration'], $advance['content']);
                         }
                     }
                 }
                 Export::arrayToCsv($csv);
                 exit;
                 // Don't continue building a normal page.
                 return;
             case 'thematic_export_pdf':
                 $list = $thematic->get_thematic_list();
                 $table = array();
                 $table[] = array(get_lang('Thematic'), get_lang('ThematicPlan'), get_lang('ThematicAdvance'));
                 foreach ($list as $theme) {
                     $data = $thematic->get_thematic_plan_data($theme['id']);
                     $plan_html = null;
                     if (!empty($data)) {
                         foreach ($data as $plan) {
                             $plan_html .= '<strong>' . $plan['title'] . '</strong><br /> ' . $plan['description'] . '<br />';
                         }
                     }
                     $data = $thematic->get_thematic_advance_by_thematic_id($theme['id']);
                     $advance_html = null;
                     if (!empty($data)) {
                         foreach ($data as $advance) {
                             $advance_html .= api_convert_and_format_date($advance['start_date'], DATE_FORMAT_LONG) . ' (' . $advance['duration'] . ' ' . get_lang('HourShort') . ')<br />' . $advance['content'] . '<br />';
                         }
                     }
                     $table[] = array($theme['title'], $plan_html, $advance_html);
                 }
                 $params = array('filename' => get_lang('Thematic') . '-' . api_get_local_time(), 'pdf_title' => get_lang('Thematic'), 'add_signatures' => true, 'format' => 'A4-L', 'orientation' => 'L');
                 Export::export_table_pdf($table, $params);
                 break;
             case 'moveup':
                 $thematic->move_thematic('up', $thematic_id);
                 $action = 'thematic_details';
                 $thematic_id = null;
                 break;
             case 'movedown':
                 $thematic->move_thematic('down', $thematic_id);
                 $action = 'thematic_details';
                 $thematic_id = null;
                 break;
         }
         Security::clear_token();
     } else {
         $action = 'thematic_details';
         $thematic_id = null;
     }
     if (isset($thematic_id)) {
         $data['thematic_data'] = $thematic->get_thematic_list($thematic_id);
         $data['thematic_id'] = $thematic_id;
     }
     if ($action == 'thematic_details') {
         if (isset($thematic_id)) {
             $thematic_data_result = $thematic->get_thematic_list($thematic_id);
             if (!empty($thematic_data_result)) {
                 $thematic_data[$thematic_id] = $thematic_data_result;
             }
             $data['total_average_of_advances'] = $thematic->get_average_of_advances_by_thematic($thematic_id);
         } else {
             $thematic_data = $thematic->get_thematic_list(null, api_get_course_id(), api_get_session_id());
             $data['max_thematic_item'] = $thematic->get_max_thematic_item();
             $data['last_done_thematic_advance'] = $thematic->get_last_done_thematic_advance();
             $data['total_average_of_advances'] = $thematic->get_total_average_of_thematic_advances();
         }
         // Second column
         $thematic_plan_data = $thematic->get_thematic_plan_data();
         // Third column
         $thematic_advance_data = $thematic->get_thematic_advance_list(null, null, true);
         $data['thematic_plan_div'] = $thematic->get_thematic_plan_div($thematic_plan_data);
         $data['thematic_advance_div'] = $thematic->get_thematic_advance_div($thematic_advance_data);
         $data['thematic_plan_data'] = $thematic_plan_data;
         $data['thematic_advance_data'] = $thematic_advance_data;
         $data['thematic_data'] = $thematic_data;
     }
     $data['default_thematic_plan_title'] = $thematic->get_default_thematic_plan_title();
     $data['action'] = $action;
     $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');
     $this->view->render();
 }
Пример #2
0
 /**
  * @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();
             }
         }
     }
 }
 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} ");
         }
     }
 }