thematic.lib.php 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This file contains class used like library, provides functions for thematic option inside attendance tool. It's also used like model to thematic_controller (MVC pattern)
  5. * @author Christian Fasanando <christian1827@gmail.com>
  6. * @author Julio Montoya <gugli100@gmail.com> SQL fixes,
  7. * By the way there are 3 tables that are mixed,
  8. * there should be 3 different classes Thematic, ThematicAdvanced and Thematic plan and a controller
  9. * @package chamilo.course_progress
  10. */
  11. /**
  12. * Thematic class can be used to instanciate objects or as a library for thematic control
  13. * @package chamilo.course_progress
  14. */
  15. class Thematic
  16. {
  17. private $session_id;
  18. private $thematic_id;
  19. private $thematic_title;
  20. private $thematic_content;
  21. private $thematic_plan_id;
  22. private $thematic_plan_title;
  23. private $thematic_plan_description;
  24. private $thematic_plan_description_type;
  25. private $thematic_advance_id;
  26. private $attendance_id;
  27. private $thematic_advance_content;
  28. private $start_date;
  29. private $duration;
  30. public function __construct() {}
  31. /**
  32. * Get the total number of thematic inside current course and current session
  33. * @see SortableTable#get_total_number_of_items()
  34. */
  35. public function get_number_of_thematics() {
  36. $tbl_thematic = Database :: get_course_table(TABLE_THEMATIC);
  37. $condition_session = '';
  38. if (!api_get_session_id()) {
  39. $condition_session = api_get_session_condition(0);
  40. }
  41. $sql = "SELECT COUNT(id) AS total_number_of_items FROM $tbl_thematic WHERE active = 1 $condition_session ";
  42. $res = Database::query($sql);
  43. $res = Database::query($sql);
  44. $obj = Database::fetch_object($res);
  45. return $obj->total_number_of_items;
  46. }
  47. /**
  48. * Get the thematics to display on the current page (fill the sortable-table)
  49. * @param int offset of first user to recover
  50. * @param int Number of users to get
  51. * @param int Column to sort on
  52. * @param string Order (ASC,DESC)
  53. * @see SortableTable#get_table_data($from)
  54. */
  55. public function get_thematic_data($from, $number_of_items, $column, $direction) {
  56. $tbl_thematic = Database :: get_course_table(TABLE_THEMATIC);
  57. $condition_session = '';
  58. if (!api_get_session_id()) {
  59. $condition_session = api_get_session_condition(0);
  60. }
  61. $column = intval($column);
  62. $from = intval($from);
  63. $number_of_items = intval($number_of_items);
  64. if (!in_array($direction, array('ASC','DESC'))) {
  65. $direction = 'ASC';
  66. }
  67. $sql = "SELECT id AS col0, title AS col1, display_order AS col2, session_id FROM $tbl_thematic
  68. WHERE active = 1 $condition_session
  69. ORDER BY col2 LIMIT $from,$number_of_items ";
  70. $res = Database::query($sql);
  71. $thematics = array ();
  72. $param_gradebook = '';
  73. if (isset($_SESSION['gradebook'])) {
  74. $param_gradebook = '&gradebook='.$_SESSION['gradebook'];
  75. }
  76. $user_info = api_get_user_info(api_get_user_id());
  77. while ($thematic = Database::fetch_row($res)) {
  78. $session_star = '';
  79. if (api_get_session_id() == $thematic[3]) {
  80. $session_star = api_get_session_image(api_get_session_id(), $user_info['status']);
  81. }
  82. $thematic[1] = '<a href="index.php?'.api_get_cidreq().'&action=thematic_details&thematic_id='.$thematic[0].$param_gradebook.'">'.Security::remove_XSS($thematic[1], STUDENT).$session_star.'</a>';
  83. if (api_is_allowed_to_edit(null, true)) {
  84. $actions = '';
  85. if (api_get_session_id()) {
  86. if (api_get_session_id() == $thematic[3]) {
  87. $actions .= '<a href="index.php?'.api_get_cidreq().'&action=thematic_plan_list&thematic_id='.$thematic[0].$param_gradebook.'">'.Display::return_icon('lesson_plan.png',get_lang('ThematicPlan'),'','22').'</a>&nbsp;';
  88. $actions .= '<a href="index.php?'.api_get_cidreq().'&action=thematic_advance_list&thematic_id='.$thematic[0].$param_gradebook.'">'.Display::return_icon('lesson_plan_calendar.png',get_lang('ThematicAdvance'),'','22').'</a>&nbsp;';
  89. $actions .= '<a href="index.php?'.api_get_cidreq().'&action=thematic_edit&thematic_id='.$thematic[0].$param_gradebook.'">'.Display::return_icon('edit.png',get_lang('Edit'),'',22).'</a>';
  90. $actions .= '<a onclick="javascript:if(!confirm(\''.get_lang('AreYouSureToDelete').'\')) return false;" href="index.php?'.api_get_cidreq().'&action=thematic_delete&thematic_id='.$thematic[0].$param_gradebook.'">'.Display::return_icon('delete.png',get_lang('Delete'),'',22).'</a>';
  91. } else {
  92. $actions .= Display::return_icon('lesson_plan_na.png',get_lang('ThematicPlan'),'',22).'&nbsp;';
  93. $actions .= Display::return_icon('lesson_plan_calendar_na.png',get_lang('ThematicAdvance'),'',22).'&nbsp;';
  94. $actions .= Display::return_icon('edit_na.png',get_lang('Edit'),'',22);
  95. $actions .= Display::return_icon('delete_na.png',get_lang('Delete'),'',22).'&nbsp;';
  96. $actions .= Display::url(Display::return_icon('cd.gif', get_lang('Copy')), 'index.php?'.api_get_cidreq().'&action=thematic_copy&thematic_id='.$thematic[0].$param_gradebook);
  97. }
  98. } else {
  99. $actions .= '<a href="index.php?'.api_get_cidreq().'&action=thematic_plan_list&thematic_id='.$thematic[0].$param_gradebook.'">'.Display::return_icon('lesson_plan.png',get_lang('ThematicPlan'),'','22').'</a>&nbsp;';
  100. $actions .= '<a href="index.php?'.api_get_cidreq().'&action=thematic_advance_list&thematic_id='.$thematic[0].$param_gradebook.'">'.Display::return_icon('lesson_plan_calendar.png',get_lang('ThematicAdvance'),'','22').'</a>&nbsp;';
  101. if ($thematic[2] > 1) {
  102. $actions .= '<a href="'.api_get_self().'?action=moveup&'.api_get_cidreq().'&thematic_id='.$thematic[0].$param_gradebook.'">'.Display::return_icon('up.png', get_lang('Up'),'',22).'</a>';
  103. } else {
  104. $actions .= Display::return_icon('up_na.png','&nbsp;','',22);
  105. }
  106. if ($thematic[2] < self::get_max_thematic_item()) {
  107. $actions .= '<a href="'.api_get_self().'?action=movedown&a'.api_get_cidreq().'&thematic_id='.$thematic[0].$param_gradebook.'">'.Display::return_icon('down.png',get_lang('Down'),'',22).'</a>';
  108. } else {
  109. $actions .= Display::return_icon('down_na.png','&nbsp;','',22);
  110. }
  111. $actions .= '<a href="index.php?'.api_get_cidreq().'&action=thematic_edit&thematic_id='.$thematic[0].$param_gradebook.'">'.Display::return_icon('edit.png',get_lang('Edit'),'',22).'</a>';
  112. $actions .= '<a onclick="javascript:if(!confirm(\''.get_lang('AreYouSureToDelete').'\')) return false;" href="index.php?'.api_get_cidreq().'&action=thematic_delete&thematic_id='.$thematic[0].$param_gradebook.'">'.Display::return_icon('delete.png',get_lang('Delete'),'',22).'</a>';
  113. }
  114. $thematics[] = array($thematic[0], $thematic[1], $actions);
  115. }
  116. }
  117. return $thematics;
  118. }
  119. /**
  120. * Get the maximum display order of the thematic item
  121. * @return int Maximum display order
  122. */
  123. public function get_max_thematic_item($use_session = true) {
  124. // Database table definition
  125. $tbl_thematic = Database :: get_course_table(TABLE_THEMATIC);
  126. $session_id = api_get_session_id();
  127. if ($use_session) {
  128. $condition_session = api_get_session_condition($session_id);
  129. } else {
  130. $condition_session = '';
  131. }
  132. $sql = "SELECT MAX(display_order) FROM $tbl_thematic WHERE active = 1 $condition_session";
  133. $rs = Database::query($sql);
  134. $row = Database::fetch_array($rs);
  135. return $row[0];
  136. }
  137. /**
  138. * Move a thematic
  139. *
  140. * @param string Direction (up, down)
  141. * @param int Thematic id
  142. */
  143. public function move_thematic($direction, $thematic_id) {
  144. // Database table definition
  145. $tbl_thematic = Database :: get_course_table(TABLE_THEMATIC);
  146. // sort direction
  147. if ($direction == 'up') {
  148. $sortorder = 'DESC';
  149. } else {
  150. $sortorder = 'ASC';
  151. }
  152. $session_id = api_get_session_id();
  153. $condition_session = api_get_session_condition($session_id);
  154. $sql = "SELECT id, display_order FROM $tbl_thematic WHERE active = 1 $condition_session ORDER BY display_order $sortorder";
  155. $res = Database::query($sql);
  156. $found = false;
  157. //Variable definition
  158. $current_id = 0;
  159. $next_id = 0;
  160. while ($row = Database::fetch_array($res)) {
  161. if ($found && empty($next_id)) {
  162. $next_id = intval($row['id']);
  163. $next_display_order = intval($row['display_order']);
  164. }
  165. if ($row['id'] == $thematic_id) {
  166. $current_id = intval($thematic_id);
  167. $current_display_order = intval($row['display_order']);
  168. $found = true;
  169. }
  170. }
  171. // get last done thematic advance before move thematic list
  172. $last_done_thematic_advance = $this->get_last_done_thematic_advance();
  173. if (!empty($next_display_order) && !empty($current_id)) {
  174. $sql = "UPDATE $tbl_thematic SET display_order = $next_display_order WHERE id = $current_id ";
  175. Database::query($sql);
  176. }
  177. if (!empty($current_display_order) && !empty($next_id)) {
  178. $sql = "UPDATE $tbl_thematic SET display_order = $current_display_order WHERE id = $next_id ";
  179. Database::query($sql);
  180. }
  181. // update done advances with de current thematic list
  182. $update_done_advances = $this->update_done_thematic_advances($last_done_thematic_advance);
  183. }
  184. /**
  185. * get thematic list
  186. * @param int Thematic id (optional), get list by id
  187. * @return array Thematic data
  188. */
  189. public function get_thematic_list($thematic_id = null, $course_code = null, $session_id = null) {
  190. // set current course and session
  191. if (isset($course_code)) {
  192. $course_info = api_get_course_info($course_code);
  193. $tbl_thematic = Database :: get_course_table(TABLE_THEMATIC, $course_info['dbName']);
  194. } else {
  195. $tbl_thematic = Database :: get_course_table(TABLE_THEMATIC);
  196. }
  197. if (isset($session_id)) {
  198. $session_id = intval($session_id);
  199. } else {
  200. $session_id = api_get_session_id();
  201. }
  202. $data = array();
  203. $condition = '';
  204. if (isset($thematic_id)) {
  205. $thematic_id = intval($thematic_id);
  206. $condition = " WHERE id = $thematic_id AND active = 1 ";
  207. } else {
  208. $condition_session = '';
  209. if (empty($session_id)) {
  210. $condition_session = api_get_session_condition(0);
  211. }
  212. $condition = " WHERE active = 1 $condition_session ";
  213. }
  214. $sql = "SELECT * FROM $tbl_thematic $condition ORDER BY display_order ";
  215. $res = Database::query($sql);
  216. if (Database::num_rows($res) > 0) {
  217. if (!empty($thematic_id)) {
  218. $data = Database::fetch_array($res,'ASSOC');
  219. } else {
  220. while ($row = Database::fetch_array($res,'ASSOC')) {
  221. $data[$row['id']] = $row;
  222. }
  223. }
  224. }
  225. return $data;
  226. }
  227. /**
  228. * insert or update a thematic
  229. * @return int last thematic id
  230. */
  231. public function thematic_save() {
  232. global $_course;
  233. // definition database table
  234. $tbl_thematic = Database::get_course_table(TABLE_THEMATIC);
  235. // protect data
  236. $id = intval($this->thematic_id);
  237. $title = Database::escape_string($this->thematic_title);
  238. $content = Database::escape_string($this->thematic_content);
  239. $session_id = intval($this->session_id);
  240. $user_id = api_get_user_id();
  241. // get the maximum display order of all the glossary items
  242. $max_thematic_item = $this->get_max_thematic_item(false);
  243. if (empty($id)) {
  244. // insert
  245. $sql = "INSERT INTO $tbl_thematic(title, content, active, display_order, session_id) VALUES ('$title', '$content', 1, ".(intval($max_thematic_item)+1).", $session_id) ";
  246. Database::query($sql);
  247. $last_id = Database::insert_id();
  248. if (Database::affected_rows()) {
  249. // save inside item property table
  250. $last_id = Database::insert_id();
  251. api_item_property_update($_course, 'thematic', $last_id,"ThematicAdded", $user_id);
  252. }
  253. } else {
  254. // update
  255. $sql = "UPDATE $tbl_thematic SET title = '$title', content = '$content', session_id = $session_id WHERE id = $id ";
  256. Database::query($sql);
  257. $last_id = $id;
  258. if (Database::affected_rows()) {
  259. // save inside item property table
  260. api_item_property_update($_course, 'thematic', $last_id,"ThematicUpdated", $user_id);
  261. }
  262. }
  263. return $last_id;
  264. }
  265. /**
  266. * Delete logically (set active field to 0) a thematic
  267. * @param int|array One or many thematic ids
  268. * @return int Affected rows
  269. */
  270. public function thematic_destroy($thematic_id) {
  271. global $_course;
  272. $tbl_thematic = Database::get_course_table(TABLE_THEMATIC);
  273. $affected_rows = 0;
  274. $user_id = api_get_user_id();
  275. if (is_array($thematic_id)) {
  276. foreach ($thematic_id as $id) {
  277. $id = intval($id);
  278. $sql = "UPDATE $tbl_thematic SET active = 0 WHERE id = $id";
  279. Database::query($sql);
  280. $affected_rows += Database::affected_rows();
  281. if (!empty($affected_rows)) {
  282. // update row item property table
  283. api_item_property_update($_course, 'thematic', $id,"ThematicDeleted", $user_id);
  284. //api_item_property_update($_course, TOOL_COURSE_PROGRESS, $id,"delete", $user_id);
  285. }
  286. }
  287. } else {
  288. $thematic_id = intval($thematic_id);
  289. $sql = "UPDATE $tbl_thematic SET active = 0 WHERE id = $thematic_id";
  290. Database::query($sql);
  291. $affected_rows = Database::affected_rows();
  292. if (!empty($affected_rows)) {
  293. // update row item property table
  294. //api_item_property_update($_course, TOOL_COURSE_PROGRESS, $thematic_id,"delete", $user_id);
  295. api_item_property_update($_course, 'thematic', $thematic_id,"ThematicDeleted", $user_id);
  296. }
  297. }
  298. return $affected_rows;
  299. }
  300. public function copy($thematic_id) {
  301. $thematic = self::get_thematic_list($thematic_id, api_get_course_id(), 0);
  302. $thematic_copy = new Thematic();
  303. $thematic_copy->set_thematic_attributes('', $thematic['title'].' - '.get_lang('Copy'), $thematic['content'], api_get_session_id());
  304. $new_thematic_id = $thematic_copy->thematic_save();
  305. if (!empty($new_thematic_id)) {
  306. $thematic_advanced = self::get_thematic_advance_by_thematic_id($thematic_id);
  307. if(!empty($thematic_advanced)) {
  308. foreach($thematic_advanced as $item) {
  309. $thematic = new Thematic();
  310. $thematic->set_thematic_advance_attributes(0, $new_thematic_id, 0, $item['content'], $item['start_date'], $item['duration']);
  311. $thematic->thematic_advance_save();
  312. }
  313. }
  314. $thematic_plan = self::get_thematic_plan_data($thematic_id);
  315. if (!empty($thematic_plan)) {
  316. foreach ($thematic_plan as $item) {
  317. $thematic = new Thematic();
  318. $thematic->set_thematic_plan_attributes($new_thematic_id, $item['title'], $item['description'], $item['description_type']);
  319. $thematic->thematic_plan_save();
  320. }
  321. }
  322. }
  323. }
  324. /**
  325. * Get the total number of thematic advance inside current course
  326. * @see SortableTable#get_total_number_of_items()
  327. */
  328. public function get_number_of_thematic_advances() {
  329. global $thematic_id;
  330. $tbl_thematic_advance = Database :: get_course_table(TABLE_THEMATIC_ADVANCE);
  331. $sql = "SELECT COUNT(id) AS total_number_of_items FROM $tbl_thematic_advance WHERE thematic_id = $thematic_id ";
  332. $res = Database::query($sql);
  333. $res = Database::query($sql);
  334. $obj = Database::fetch_object($res);
  335. return $obj->total_number_of_items;
  336. }
  337. /**
  338. * Get the thematic advances to display on the current page (fill the sortable-table)
  339. * @param int offset of first user to recover
  340. * @param int Number of users to get
  341. * @param int Column to sort on
  342. * @param string Order (ASC,DESC)
  343. * @see SortableTable#get_table_data($from)
  344. */
  345. public function get_thematic_advance_data($from, $number_of_items, $column, $direction) {
  346. global $thematic_id;
  347. $tbl_thematic_advance = Database :: get_course_table(TABLE_THEMATIC_ADVANCE);
  348. $thematic_data = self::get_thematic_list($thematic_id);
  349. $column = intval($column);
  350. $from = intval($from);
  351. $number_of_items = intval($number_of_items);
  352. if (!in_array($direction, array('ASC','DESC'))) {
  353. $direction = 'ASC';
  354. }
  355. $data = array();
  356. if (api_is_allowed_to_edit(null, true)) {
  357. $sql = "SELECT id AS col0, start_date AS col1, duration AS col2, content AS col3 FROM $tbl_thematic_advance
  358. WHERE thematic_id = $thematic_id
  359. ORDER BY col$column $direction LIMIT $from,$number_of_items ";
  360. $list = api_get_item_property_by_tool('thematic_advance', api_get_course_id(), api_get_session_id());
  361. $elements = array();
  362. foreach ($list as $value) {
  363. $elements[] = $value['ref'];
  364. }
  365. $res = Database::query($sql);
  366. $i = 1;
  367. while ($thematic_advance = Database::fetch_row($res)) {
  368. if(in_array($thematic_advance[0], $elements)) {
  369. $thematic_advance[1] = api_get_local_time($thematic_advance[1]);
  370. $thematic_advance[1] = api_format_date($thematic_advance[1], DATE_TIME_FORMAT_LONG);
  371. $actions = '';
  372. $actions .= '<a href="index.php?'.api_get_cidreq().'&action=thematic_advance_edit&thematic_id='.$thematic_id.'&thematic_advance_id='.$thematic_advance[0].'">'.Display::return_icon('edit.png',get_lang('Edit'),'',22).'</a>';
  373. $actions .= '<a onclick="javascript:if(!confirm(\''.get_lang('AreYouSureToDelete').'\')) return false;" href="index.php?'.api_get_cidreq().'&action=thematic_advance_delete&thematic_id='.$thematic_id.'&thematic_advance_id='.$thematic_advance[0].'">'.Display::return_icon('delete.png',get_lang('Delete'),'',22).'</a></center>';
  374. $data[] = array($i, $thematic_advance[1], $thematic_advance[2], $thematic_advance[3], $actions);
  375. $i++;
  376. }
  377. }
  378. }
  379. return $data;
  380. }
  381. /**
  382. * get thematic advance data by tematic id
  383. * @param int Thematic id
  384. * @param string Course code (optional)
  385. * @return array data
  386. */
  387. public function get_thematic_advance_by_thematic_id($thematic_id, $course_code = null) {
  388. $course_info = api_get_course_info($course_code);
  389. // set current course
  390. if (isset($course_code)) {
  391. $tbl_thematic_advance = Database::get_course_table(TABLE_THEMATIC_ADVANCE, $course_info['dbName']);
  392. } else {
  393. $tbl_thematic_advance = Database::get_course_table(TABLE_THEMATIC_ADVANCE);
  394. }
  395. $thematic_id = intval($thematic_id);
  396. $data = array();
  397. $sql = "SELECT * FROM $tbl_thematic_advance WHERE thematic_id = $thematic_id ";
  398. $elements = array();
  399. $list = api_get_item_property_by_tool('thematic_advance', $course_info['code'], api_get_session_id());
  400. foreach($list as $value) {
  401. $elements[] = $value['ref'];
  402. }
  403. $res = Database::query($sql);
  404. if (Database::num_rows($res) > 0) {
  405. while ($row = Database::fetch_array($res, 'ASSOC')) {
  406. if (in_array($row['id'], $elements)) {
  407. $data[] = $row;
  408. }
  409. }
  410. }
  411. return $data;
  412. }
  413. /**
  414. * get thematic advance list
  415. * @param int Thematic advance id (optional), get data by thematic advance list
  416. * @param string Course code (optional)
  417. * @return array data
  418. */
  419. public function get_thematic_advance_list($thematic_advance_id = null, $course_code = null, $force_session_id = false) { // set current course
  420. $course_info = api_get_course_info($course_code);
  421. if (isset($course_code)) {
  422. $tbl_thematic_advance = Database::get_course_table(TABLE_THEMATIC_ADVANCE, $course_info['dbName']);
  423. $tbl_thematic = Database::get_course_table(TABLE_THEMATIC,$course_info['dbName']);
  424. } else {
  425. $tbl_thematic_advance = Database::get_course_table(TABLE_THEMATIC_ADVANCE);
  426. $tbl_thematic = Database::get_course_table(TABLE_THEMATIC);
  427. }
  428. $data = array();
  429. $condition = '';
  430. if (isset($thematic_advance_id)) {
  431. $thematic_advance_id = intval($thematic_advance_id);
  432. $condition = " AND a.id = $thematic_advance_id ";
  433. }
  434. /*if ($force_session_id) {
  435. $sql = "SELECT a.* FROM $tbl_thematic_advance a INNER JOIN $tbl_thematic t ON t.id = a.thematic_id WHERE 1 $condition AND t.session_id = ".api_get_session_id()." ORDER BY start_date ";
  436. } else {
  437. $sql = "SELECT * FROM $tbl_thematic_advance a WHERE 1 $condition ORDER BY start_date ";
  438. }*/
  439. $sql = "SELECT * FROM $tbl_thematic_advance a WHERE 1 $condition ORDER BY start_date ";
  440. $elements = array();
  441. if ($force_session_id) {
  442. $list = api_get_item_property_by_tool('thematic_advance', $course_info['code'], api_get_session_id());
  443. foreach($list as $value) {
  444. $elements[$value['ref']]= $value;
  445. }
  446. }
  447. $res = Database::query($sql);
  448. if (Database::num_rows($res) > 0) {
  449. if (!empty($thematic_advance_id)) {
  450. $data = Database::fetch_array($res);
  451. } else {
  452. // group all data group by thematic id
  453. $tmp = array();
  454. while ($row = Database::fetch_array($res, 'ASSOC')) {
  455. $tmp[] = $row['thematic_id'];
  456. if (in_array($row['thematic_id'], $tmp)) {
  457. if ($force_session_id) {
  458. if (in_array($row['id'], array_keys($elements))) {
  459. $row['session_id'] = $elements[$row['id']]['id_session'];
  460. $data[$row['thematic_id']][$row['id']] = $row;
  461. }
  462. } else {
  463. $data[$row['thematic_id']][$row['id']] = $row;
  464. }
  465. }
  466. }
  467. }
  468. }
  469. return $data;
  470. }
  471. /**
  472. * insert or update a thematic advance
  473. * @todo problem
  474. * @return int last thematic advance id
  475. */
  476. public function thematic_advance_save() {
  477. global $_course;
  478. // definition database table
  479. $tbl_thematic_advance = Database::get_course_table(TABLE_THEMATIC_ADVANCE);
  480. // protect data
  481. $id = intval($this->thematic_advance_id);
  482. $tematic_id = intval($this->thematic_id);
  483. $attendance_id = intval($this->attendance_id);
  484. $content = Database::escape_string($this->thematic_advance_content);
  485. $start_date = Database::escape_string($this->start_date);
  486. $duration = intval($this->duration);
  487. $user_id = api_get_user_id();
  488. if (empty($id)) {
  489. // Insert
  490. $sql = "INSERT INTO $tbl_thematic_advance (thematic_id, attendance_id, content, start_date, duration) VALUES ($tematic_id, $attendance_id, '$content', '".api_get_utc_datetime($start_date)."', '$duration') ";
  491. Database::query($sql);
  492. $last_id = Database::insert_id();
  493. if (Database::affected_rows()) {
  494. api_item_property_update($_course, 'thematic_advance', $last_id,"ThematicAdvanceAdded", $user_id);
  495. }
  496. } else {
  497. // update
  498. $sql = "UPDATE $tbl_thematic_advance SET thematic_id = '$tematic_id', attendance_id = '$attendance_id', content = '$content', start_date = '".api_get_utc_datetime($start_date)."', duration = '$duration' WHERE id = $id ";
  499. Database::query($sql);
  500. if (Database::affected_rows()) {
  501. api_item_property_update($_course, 'thematic_advance', $id, "ThematicAdvanceUpdated", $user_id);
  502. }
  503. }
  504. return $last_id;
  505. }
  506. /**
  507. * delete thematic advance
  508. * @param int Thematic advance id
  509. * @return int Affected rows
  510. */
  511. public function thematic_advance_destroy($thematic_advance_id) {
  512. global $_course;
  513. // definition database table
  514. $tbl_thematic_advance = Database::get_course_table(TABLE_THEMATIC_ADVANCE);
  515. // protect data
  516. $thematic_advance_id = intval($thematic_advance_id);
  517. $user_id = api_get_user_id();
  518. $sql = "DELETE FROM $tbl_thematic_advance WHERE id = $thematic_advance_id ";
  519. Database::query($sql);
  520. $affected_rows = Database::affected_rows();
  521. if ($affected_rows) {
  522. api_item_property_update($_course, 'thematic_advance', $thematic_advance_id,"ThematicAdvanceDeleted", $user_id);
  523. }
  524. return $affected_rows;
  525. }
  526. /**
  527. * get thematic plan data
  528. * @param int Thematic id (optional), get data by thematic id
  529. * @param int Thematic plan description type (optional), get data by description type
  530. * @return array Thematic plan data
  531. */
  532. public function get_thematic_plan_data($thematic_id = null, $description_type = null) {
  533. // definition database table
  534. $tbl_thematic_plan = Database::get_course_table(TABLE_THEMATIC_PLAN);
  535. $tbl_thematic = Database::get_course_table(TABLE_THEMATIC);
  536. $data = array();
  537. $condition = '';
  538. if (isset($thematic_id)) {
  539. $thematic_id = intval($thematic_id);
  540. $condition .= " AND thematic_id = $thematic_id ";
  541. }
  542. if (isset($description_type)) {
  543. $description_type = intval($description_type);
  544. $condition .= " AND description_type = $description_type ";
  545. }
  546. $session_condition = '';
  547. if (!api_get_session_id()) {
  548. $session_condition .= ' AND t.session_id = 0';
  549. }
  550. $sql = "SELECT tp.id, thematic_id, tp.title, description, description_type, t.session_id
  551. FROM $tbl_thematic_plan tp INNER JOIN $tbl_thematic t ON (t.id=tp.thematic_id)
  552. WHERE 1 $condition $session_condition ";
  553. $items = $elements_to_show = $elements_to_show_values = array();
  554. $items = api_get_item_property_by_tool('thematic_plan', api_get_course_id(), api_get_session_id());
  555. $elements_to_show = array();
  556. foreach($items as $value) {
  557. $elements_to_show[$value['ref']] = $value;
  558. }
  559. $elements_to_show_values = array_keys($elements_to_show);
  560. $rs = Database::query($sql);
  561. if (Database::num_rows($rs) > 0) {
  562. if (!isset($thematic_id) && !isset($description_type)) {
  563. // group all data group by thematic id
  564. $tmp = array();
  565. while ($row = Database::fetch_array($rs,'ASSOC')) {
  566. if (!in_array($row['id'], $elements_to_show_values) && !api_get_session_id()) {
  567. continue;
  568. }
  569. $tmp[] = $row['thematic_id'];
  570. if (in_array($row['thematic_id'], $tmp)) {
  571. $row['session_id'] =isset($elements_to_show[$row['id']]) ? $elements_to_show[$row['id']]['id_session']: 0;
  572. $data[$row['thematic_id']][$row['description_type']] = $row;
  573. }
  574. }
  575. } else {
  576. while ($row = Database::fetch_array($rs,'ASSOC')) {
  577. if (!in_array($row['id'], $elements_to_show_values) && !api_get_session_id()) {
  578. continue;
  579. }
  580. $row['session_id'] =isset($elements_to_show[$row['id']]) ? $elements_to_show[$row['id']]['id_session']: 0;
  581. $data[] = $row;
  582. }
  583. }
  584. }
  585. return $data;
  586. }
  587. /**
  588. * insert or update a thematic plan
  589. * @return int affected rows
  590. */
  591. public function thematic_plan_save() {
  592. global $_course;
  593. // definition database table
  594. $tbl_thematic_plan = Database::get_course_table(TABLE_THEMATIC_PLAN);
  595. // protect data
  596. $thematic_id = intval($this->thematic_id);
  597. $title = Database::escape_string($this->thematic_plan_title);
  598. $description = Database::escape_string($this->thematic_plan_description);
  599. $description_type = intval($this->thematic_plan_description_type);
  600. $user_id = api_get_user_id();
  601. $session_id = api_get_session_id();
  602. $list = api_get_item_property_by_tool('thematic_plan', api_get_course_id(), api_get_session_id());
  603. $elements_to_show = array();
  604. foreach($list as $value) {
  605. $elements_to_show[]= $value['ref'];
  606. }
  607. $condition = '';
  608. if (!empty($elements_to_show)) {
  609. $condition = "AND id IN (".implode(',', $elements_to_show).") ";
  610. }
  611. // check thematic plan type already exists
  612. $sql = "SELECT id FROM $tbl_thematic_plan WHERE thematic_id = $thematic_id AND description_type = $description_type ";
  613. $rs = Database::query($sql);
  614. $affected_rows = 0;
  615. if (Database::num_rows($rs) > 0) {
  616. //if (!empty($thematic_plan_data)) {
  617. $row_thematic_plan = Database::fetch_array($rs);
  618. $thematic_plan_id = $row_thematic_plan['id'];
  619. //Checking the session
  620. $thematic_plan_data = api_get_item_property_info(api_get_course_int_id(), 'thematic_plan', $thematic_plan_id);
  621. $update = false;
  622. if (in_array($thematic_plan_id, $elements_to_show)) {
  623. $update = true;
  624. }
  625. if ($update) {
  626. // update
  627. $upd = "UPDATE $tbl_thematic_plan SET title = '$title', description = '$description' WHERE id = $thematic_plan_id";
  628. Database::query($upd);
  629. $affected_rows = Database::affected_rows();
  630. if ($affected_rows) {
  631. api_item_property_update($_course, 'thematic_plan', $thematic_plan_id, "ThematicPlanUpdated", $user_id);
  632. }
  633. } else {
  634. // insert
  635. $ins = "INSERT INTO $tbl_thematic_plan(thematic_id, title, description, description_type) VALUES($thematic_id, '$title', '$description', $description_type) ";
  636. Database::query($ins);
  637. $last_id = Database::insert_id();
  638. $affected_rows = Database::affected_rows();
  639. if ($affected_rows) {
  640. api_item_property_update($_course, 'thematic_plan', $last_id,"ThematicPlanAdded", $user_id);
  641. }
  642. }
  643. } else {
  644. // insert
  645. $ins = "INSERT INTO $tbl_thematic_plan(thematic_id, title, description, description_type) VALUES($thematic_id, '$title', '$description', $description_type) ";
  646. Database::query($ins);
  647. $last_id = Database::insert_id();
  648. $affected_rows = Database::affected_rows();
  649. if ($affected_rows) {
  650. api_item_property_update($_course, 'thematic_plan', $last_id,"ThematicPlanAdded", $user_id);
  651. }
  652. }
  653. return $affected_rows;
  654. }
  655. /**
  656. * delete a thematic plan description
  657. * @param int Thematic id
  658. * @param int Description type
  659. * @return int Affected rows
  660. */
  661. public function thematic_plan_destroy($thematic_id, $description_type) {
  662. global $_course;
  663. // definition database table
  664. $tbl_thematic_plan = Database::get_course_table(TABLE_THEMATIC_PLAN);
  665. // protect data
  666. $thematic_id = intval($thematic_id);
  667. $description_type = intval($description_type);
  668. $user_id = api_get_user_id();
  669. // get thematic plan id
  670. $thematic_plan_data = $this->get_thematic_plan_data($thematic_id, $description_type);
  671. $thematic_plan_id = $thematic_plan_data[0]['id'];
  672. // delete
  673. $sql = "DELETE FROM $tbl_thematic_plan WHERE thematic_id = $thematic_id AND description_type = $description_type ";
  674. Database::query($sql);
  675. $affected_rows = Database::affected_rows();
  676. if ($affected_rows) {
  677. api_item_property_update($_course, 'thematic_plan', $thematic_plan_id,"ThematicPlanDeleted", $user_id);
  678. }
  679. return $affected_rows;
  680. }
  681. /**
  682. * Get next description type for a new thematic plan description (option 'others')
  683. * @param int Thematic id
  684. * @return int New Description type
  685. */
  686. public function get_next_description_type($thematic_id) {
  687. // definition database table
  688. $tbl_thematic_plan = Database::get_course_table(TABLE_THEMATIC_PLAN);
  689. // protect data
  690. $thematic_id = intval($thematic_id);
  691. $description_type = intval($description_type);
  692. $next_description_type = 0;
  693. $sql = "SELECT MAX(description_type) as max FROM $tbl_thematic_plan WHERE thematic_id = $thematic_id AND description_type >= ".ADD_THEMATIC_PLAN." ";
  694. $rs = Database::query($sql);
  695. $row = Database::fetch_array($rs);
  696. $last_description_type = $row['max'];
  697. if (isset($last_description_type)) {
  698. $row = Database::fetch_array($rs);
  699. $next_description_type = $last_description_type + 1;
  700. } else {
  701. $next_description_type = ADD_THEMATIC_PLAN;
  702. }
  703. return $next_description_type;
  704. }
  705. /**
  706. * update done thematic advances from thematic details interface
  707. * @param int Thematic id
  708. * @return int Affected rows
  709. */
  710. public function update_done_thematic_advances($thematic_advance_id) {
  711. global $_course;
  712. $thematic_data = $this->get_thematic_list(null, api_get_course_id());
  713. $thematic_advance_data = $this->get_thematic_advance_list(null, api_get_course_id(), true);
  714. $tbl_thematic_advance = Database::get_course_table(TABLE_THEMATIC_ADVANCE);
  715. $affected_rows = 0;
  716. $user_id = api_get_user_id();
  717. $all = array();
  718. //var_dump($thematic_advance_data);
  719. if (!empty($thematic_data)) {
  720. foreach ($thematic_data as $thematic) {
  721. $thematic_id = $thematic['id'];
  722. if (!empty($thematic_advance_data[$thematic['id']])) {
  723. foreach ($thematic_advance_data[$thematic['id']] as $thematic_advance) {
  724. $all[] = $thematic_advance['id'];
  725. }
  726. }
  727. }
  728. }
  729. $error = null;
  730. $a_thematic_advance_ids = array();
  731. if (!empty($thematic_data)) {
  732. foreach ($thematic_data as $thematic) {
  733. $my_affected_rows = 0;
  734. $thematic_id = $thematic['id'];
  735. if (!empty($thematic_advance_data[$thematic['id']])) {
  736. foreach ($thematic_advance_data[$thematic['id']] as $thematic_advance) {
  737. $item_info = api_get_item_property_info(api_get_course_int_id(), 'thematic_advance', $thematic_advance['id']);
  738. //var_dump($item_info );
  739. if ($item_info['id_session'] == api_get_session_id()) {
  740. $a_thematic_advance_ids[] = $thematic_advance['id'];
  741. // update done thematic for previous advances ((done_advance = 1))
  742. $upd = "UPDATE $tbl_thematic_advance set done_advance = 1 WHERE id = ".$thematic_advance['id']." ";
  743. Database::query($upd);
  744. $my_affected_rows = Database::affected_rows();
  745. $affected_rows += $my_affected_rows;
  746. //if ($my_affected_rows) {
  747. api_item_property_update($_course, 'thematic_advance', $thematic_advance['id'], "ThematicAdvanceDone", $user_id);
  748. //}
  749. if ($thematic_advance['id'] == $thematic_advance_id) {
  750. break 2;
  751. }
  752. }
  753. }
  754. }
  755. }
  756. }
  757. // Update done thematic for others advances (done_advance = 0)
  758. if (!empty($a_thematic_advance_ids) && count($a_thematic_advance_ids) > 0) {
  759. $diff = array_diff($all, $a_thematic_advance_ids);
  760. if (!empty($diff)) {
  761. $upd = "UPDATE $tbl_thematic_advance set done_advance = 0 WHERE id IN(".implode(',',$diff).") ";
  762. Database::query($upd);
  763. }
  764. // update item_property
  765. $tbl_item_property = Database::get_course_table(TABLE_ITEM_PROPERTY);
  766. $session_id = api_get_session_id();
  767. // get all thematic advance done
  768. $rs_thematic_done = Database::query("SELECT ref FROM $tbl_item_property WHERE tool='thematic_advance' AND lastedit_type='ThematicAdvanceDone' AND id_session = $session_id ");
  769. if (Database::num_rows($rs_thematic_done) > 0) {
  770. while ($row_thematic_done = Database::fetch_array($rs_thematic_done)) {
  771. $ref = $row_thematic_done['ref'];
  772. if (in_array($ref, $a_thematic_advance_ids)) { continue; }
  773. // update items
  774. Database::query("UPDATE $tbl_item_property SET lastedit_date='".api_get_utc_datetime()."', lastedit_type='ThematicAdvanceUpdated', lastedit_user_id = $user_id WHERE tool='thematic_advance' AND ref=$ref AND id_session = $session_id ");
  775. }
  776. }
  777. }
  778. return $affected_rows;
  779. }
  780. /**
  781. * Get last done thematic advance from thematic details interface
  782. * @return int Last done thematic advance id
  783. */
  784. public function get_last_done_thematic_advance() {
  785. $thematic_data = $this->get_thematic_list();
  786. $thematic_advance_data = $this->get_thematic_advance_list(null, api_get_course_id(), true);
  787. $a_thematic_advance_ids = array();
  788. $last_done_advance_id = 0;
  789. if (!empty($thematic_data)) {
  790. foreach ($thematic_data as $thematic) {
  791. $thematic_id = $thematic['id'];
  792. if (!empty($thematic_advance_data[$thematic['id']])) {
  793. foreach ($thematic_advance_data[$thematic['id']] as $thematic_advance) {
  794. if ($thematic_advance['done_advance'] == 1) {
  795. $a_thematic_advance_ids[] = $thematic_advance['id'];
  796. }
  797. }
  798. }
  799. }
  800. }
  801. if (!empty($a_thematic_advance_ids)) {
  802. $last_done_advance_id = array_pop($a_thematic_advance_ids);
  803. $last_done_advance_id = intval($last_done_advance_id);
  804. }
  805. return $last_done_advance_id;
  806. }
  807. /**
  808. * Get next thematic advance not done from thematic details interface
  809. * @return int next thematic advance not done
  810. */
  811. public function get_next_thematic_advance_not_done() {
  812. $thematic_data = $this->get_thematic_list();
  813. $thematic_advance_data = $this->get_thematic_advance_list();
  814. $a_thematic_advance_ids = array();
  815. $next_advance_not_done = 0;
  816. if (!empty($thematic_data)) {
  817. foreach ($thematic_data as $thematic) {
  818. $thematic_id = $thematic['id'];
  819. if (!empty($thematic_advance_data[$thematic['id']])) {
  820. foreach ($thematic_advance_data[$thematic['id']] as $thematic_advance) {
  821. if ($thematic_advance['done_advance'] == 0) {
  822. $a_thematic_advance_ids[] = $thematic_advance['id'];
  823. }
  824. }
  825. }
  826. }
  827. }
  828. if (!empty($a_thematic_advance_ids)) {
  829. $next_advance_not_done = array_shift($a_thematic_advance_ids);
  830. $next_advance_not_done = intval($next_advance_not_done);
  831. }
  832. return $next_advance_not_done;
  833. }
  834. /**
  835. * Get total average of thematic advances
  836. * @param string Course code (optional)
  837. * @param int Session id (optional)
  838. * @return float Average of thematic advances
  839. */
  840. public function get_total_average_of_thematic_advances($course_code = null, $session_id = null) {
  841. if (api_get_session_id()) {
  842. $thematic_data = $this->get_thematic_list(null, api_get_course_id());
  843. } else {
  844. $thematic_data = $this->get_thematic_list(null, api_get_course_id(), 0);
  845. }
  846. $new_thematic_data = array();
  847. if (!empty($thematic_data)) {
  848. foreach ($thematic_data as $item) {
  849. $new_thematic_data[] = $item;
  850. }
  851. $thematic_data = $new_thematic_data;
  852. }
  853. $thematic_advance_data = $this->get_thematic_advance_list(null, $course_code, true);
  854. $a_average_of_advances_by_thematic = array();
  855. $total_average = 0;
  856. if (!empty($thematic_data)) {
  857. foreach ($thematic_data as $thematic) {
  858. $thematic_id = $thematic['id'];
  859. $a_average_of_advances_by_thematic[$thematic_id] = $this->get_average_of_advances_by_thematic($thematic_id, $course_code);
  860. }
  861. }
  862. // calculate total average
  863. if (!empty($a_average_of_advances_by_thematic)) {
  864. $count_tematics = count($thematic_data);
  865. $score = array_sum($a_average_of_advances_by_thematic);
  866. $total_average = round(($score*100)/($count_tematics*100));
  867. }
  868. return $total_average;
  869. }
  870. /**
  871. * Get average of advances by thematic
  872. * @param int Thematic id
  873. * @param string Course code (optional)
  874. * @return float Average of thematic advances
  875. */
  876. public function get_average_of_advances_by_thematic($thematic_id, $course_code = null) {
  877. $thematic_advance_data = $this->get_thematic_advance_by_thematic_id($thematic_id, $course_code);
  878. $average = 0;
  879. if (!empty($thematic_advance_data)) {
  880. // get all done advances by thematic
  881. $advances = array();
  882. $count_done_advances = 0;
  883. $average = 0;
  884. foreach ($thematic_advance_data as $thematic_advance) {
  885. if ($thematic_advance['done_advance'] == 1) {
  886. $count_done_advances++;
  887. }
  888. $advances[] = $thematic_advance['done_advance'];
  889. }
  890. // calculate average by thematic
  891. $count_total_advances = count($advances);
  892. $average = round(($count_done_advances*100)/$count_total_advances);
  893. }
  894. return $average;
  895. }
  896. /**
  897. * set attributes for fields of thematic table
  898. * @param int Thematic id
  899. * @param string Thematic title
  900. * @param string Thematic content
  901. * @param int Session id
  902. * @return void
  903. */
  904. public function set_thematic_attributes($id = null, $title = '', $content = '', $session_id = 0) {
  905. $this->thematic_id = $id;
  906. $this->thematic_title = $title;
  907. $this->thematic_content = $content;
  908. $this->session_id = $session_id;
  909. }
  910. /**
  911. * set attributes for fields of thematic_plan table
  912. * @param int Thematic id
  913. * @param string Thematic plan title
  914. * @param string Thematic plan description
  915. * @param int Thematic plan description type
  916. * @return void
  917. */
  918. public function set_thematic_plan_attributes($thematic_id = 0, $title = '', $description = '', $description_type = 0) {
  919. $this->thematic_id = $thematic_id;
  920. $this->thematic_plan_title = $title;
  921. $this->thematic_plan_description = $description;
  922. $this->thematic_plan_description_type = $description_type;
  923. }
  924. /**
  925. * set attributes for fields of thematic_advance table
  926. * @param int Thematic advance id
  927. * @param int Thematic id
  928. * @param int Attendance id
  929. * @param string Content
  930. * @param string Date and time
  931. * @param int Duration in hours
  932. * @return void
  933. */
  934. public function set_thematic_advance_attributes($id = null, $thematic_id = 0, $attendance_id = 0, $content = '', $start_date = '0000-00-00 00:00:00', $duration = 0) {
  935. $this->thematic_advance_id = $id;
  936. $this->thematic_id = $thematic_id;
  937. $this->attendance_id = $attendance_id;
  938. $this->thematic_advance_content = $content;
  939. $this->start_date = $start_date;
  940. $this->duration = $duration;
  941. }
  942. /**
  943. * set thematic id
  944. * @param int Thematic id
  945. * @return void
  946. */
  947. public function set_thematic_id($thematic_id) {
  948. $this->thematic_id = $thematic_id;
  949. }
  950. /**
  951. * get thematic id
  952. * @return void
  953. */
  954. public function get_thematic_id() {
  955. return $this->thematic_id;
  956. }
  957. /**
  958. * Get thematic plan titles by default
  959. * @return array
  960. */
  961. public function get_default_thematic_plan_title() {
  962. $default_thematic_plan_titles = array();
  963. $default_thematic_plan_titles[1]= get_lang('Objectives');
  964. $default_thematic_plan_titles[2]= get_lang('SkillToAcquire');
  965. $default_thematic_plan_titles[3]= get_lang('Methodology');
  966. $default_thematic_plan_titles[4]= get_lang('Infrastructure');
  967. $default_thematic_plan_titles[5]= get_lang('Assessment');
  968. $default_thematic_plan_titles[6]= get_lang('Others');
  969. return $default_thematic_plan_titles;
  970. }
  971. /**
  972. * Get thematic plan icons by default
  973. * @return array
  974. */
  975. public function get_default_thematic_plan_icon() {
  976. $default_thematic_plan_icon = array();
  977. $default_thematic_plan_icon[1]= 'icons/32/objective.png';
  978. $default_thematic_plan_icon[2]= 'icons/32/skills.png';
  979. $default_thematic_plan_icon[3]= 'icons/32/strategy.png';
  980. $default_thematic_plan_icon[4]= 'icons/32/laptop.png';
  981. $default_thematic_plan_icon[5]= 'icons/32/assessment.png';
  982. $default_thematic_plan_icon[6]= 'icons/32/wizard.png';
  983. return $default_thematic_plan_icon;
  984. }
  985. /**
  986. * Get questions by default for help
  987. * @return array
  988. */
  989. public function get_default_question() {
  990. $question = array();
  991. $question[1]= get_lang('ObjectivesQuestions');
  992. $question[2]= get_lang('SkillToAcquireQuestions');
  993. $question[3]= get_lang('MethodologyQuestions');
  994. $question[4]= get_lang('InfrastructureQuestions');
  995. $question[5]= get_lang('AssessmentQuestions');
  996. return $question;
  997. }
  998. /**
  999. * buid a string datetime from array
  1000. * @param array array containing data e.g: $array('Y'=>'2010', 'F' => '02', 'd' => '10', 'H' => '12', 'i' => '30')
  1001. * @return string date and time e.g: '2010-02-10 12:30:00'
  1002. */
  1003. public function build_datetime_from_array($array) {
  1004. $year = '0000';
  1005. $month = $day = $hours = $minutes = $seconds = '00';
  1006. if (isset($array['Y']) && isset($array['F']) && isset($array['d']) && isset($array['H']) && isset($array['i'])) {
  1007. $year = $array['Y'];
  1008. $month = $array['F'];
  1009. if (intval($month) < 10 ) $month = '0'.$month;
  1010. $day = $array['d'];
  1011. if (intval($day) < 10 ) $day = '0'.$day;
  1012. $hours = $array['H'];
  1013. if (intval($hours) < 10 ) $hours = '0'.$hours;
  1014. $minutes = $array['i'];
  1015. if (intval($minutes) < 10 ) $minutes = '0'.$minutes;
  1016. }
  1017. if (checkdate($month,$day,$year)) {
  1018. $datetime = $year.'-'.$month.'-'.$day.' '.$hours.':'.$minutes.':'.$seconds;
  1019. }
  1020. return $datetime;
  1021. }
  1022. }