thematic.lib.php 47 KB

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