course_description.lib.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This file contains a class used like library provides functions for course description tool. It's also used like model to course_description_controller (MVC pattern)
  5. * @author Christian Fasanando <christian1827@gmail.com>
  6. * @package chamilo.course_description
  7. */
  8. /**
  9. * CourseDescription can be used to instanciate objects or as a library to manage course descriptions
  10. * @package chamilo.course_description
  11. */
  12. class CourseDescription
  13. {
  14. private $id;
  15. private $title;
  16. private $content;
  17. private $session_id;
  18. private $description_type;
  19. private $progress;
  20. /**
  21. * Constructor
  22. */
  23. public function __construct() {}
  24. /**
  25. * Get all data of course description by session id,
  26. * first you must set session_id property with the object CourseDescription
  27. * @return array
  28. */
  29. public function get_description_data() {
  30. $tbl_course_description = Database::get_course_table(TABLE_COURSE_DESCRIPTION);
  31. $sql = "SELECT * FROM $tbl_course_description WHERE session_id = '".$this->session_id."' ORDER BY id ";
  32. $rs = Database::query($sql, __FILE__, __LINE__);
  33. $data = array();
  34. while ($description = Database::fetch_array($rs)) {
  35. if ($description['description_type'] == THEMATIC_ADVANCE) {
  36. $description['progress_icon'] = $this->get_progress_porcent();
  37. }
  38. $data['descriptions'][$description['description_type']] = $description;
  39. //reload titles to ensure we have the last version (after edition)
  40. $data['default_description_titles'][$description['description_type']] = $description['title'];
  41. }
  42. return $data;
  43. }
  44. /**
  45. * Get all data of course description by session id,
  46. * first you must set session_id property with the object CourseDescription
  47. * @return array
  48. */
  49. public function get_description_history($description_type) {
  50. $tbl_stats_item_property = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ITEM_PROPERTY);
  51. $tbl_item_property = Database::get_course_table(TABLE_ITEM_PROPERTY);
  52. $course_id = api_get_real_course_id();
  53. $description_id = $this->get_id_by_description_type($description_type);
  54. $item_property_id = api_get_item_property_id($course_id, TOOL_COURSE_DESCRIPTION, $description_id);
  55. $sql = "SELECT tip.id, tip.course_id, tip.item_property_id, tip.title, tip.content, tip.progress, tip.lastedit_date, tip.session_id FROM $tbl_stats_item_property tip
  56. INNER JOIN $tbl_item_property ip ON ip.tool = '".TOOL_COURSE_DESCRIPTION."' AND ip.id = tip.item_property_id
  57. WHERE tip.course_id = '$course_id' AND tip.session_id = '".intval($this->session_id)."' ORDER BY tip.lastedit_date DESC";
  58. $rs = Database::query($sql, __FILE__, __LINE__);
  59. $data = array();
  60. while ($description = Database::fetch_array($rs)) {
  61. $data['descriptions'][] = $description;
  62. }
  63. return $data;
  64. }
  65. /**
  66. * Get all data by description and session id,
  67. * first you must set session_id property with the object CourseDescription
  68. * @param int description type
  69. * @return array
  70. */
  71. public function get_data_by_description_type($description_type) {
  72. $tbl_course_description = Database::get_course_table(TABLE_COURSE_DESCRIPTION);
  73. $sql = "SELECT * FROM $tbl_course_description WHERE description_type='$description_type' AND session_id='".$this->session_id."'";
  74. $rs = Database::query($sql, __FILE__, __LINE__);
  75. $data = array();
  76. if ($description = Database::fetch_array($rs)) {
  77. $data['description_title'] = $description['title'];
  78. $data['description_content'] = $description['content'];
  79. $data['progress'] = $description['progress'];
  80. }
  81. return $data;
  82. }
  83. /**
  84. * Get maximum description type by session id, first you must set session_id properties with the object CourseDescription
  85. * @return int maximum description time adding one
  86. */
  87. public function get_max_description_type() {
  88. $tbl_course_description = Database::get_course_table(TABLE_COURSE_DESCRIPTION);
  89. $sql = "SELECT MAX(description_type) as MAX FROM $tbl_course_description WHERE session_id='".$this->session_id."'";
  90. $rs = Database::query($sql, __FILE__, __LINE__);
  91. $max = Database::fetch_array($rs);
  92. $description_type = $max['MAX']+1;
  93. if ($description_type < ADD_BLOCK) {
  94. $description_type = ADD_BLOCK;
  95. }
  96. return $description_type;
  97. }
  98. /**
  99. * Insert a description to the course_description table,
  100. * first you must set description_type, title, content, progress and session_id properties with the object CourseDescription
  101. * @return int affected rows
  102. */
  103. public function insert() {
  104. $tbl_course_description = Database::get_course_table(TABLE_COURSE_DESCRIPTION);
  105. $sql = "INSERT IGNORE INTO $tbl_course_description SET description_type='".intval($this->description_type)."', title = '".Database::escape_string($this->title)."', content = '".Database::escape_string($this->content)."', progress = '".intval($this->progress)."', session_id = '".intval($this->session_id)."' ";
  106. Database::query($sql, __FILE__, __LINE__);
  107. $last_id = Database::insert_id();
  108. $affected_rows = Database::affected_rows();
  109. if ($last_id > 0) {
  110. //insert into item_property
  111. api_item_property_update(api_get_course_info(), TOOL_COURSE_DESCRIPTION, $last_id, 'CourseDescriptionAdded', api_get_user_id());
  112. }
  113. return $affected_rows;
  114. }
  115. /**
  116. * Insert a row like history inside track_e_item_property table
  117. * first you must set description_type, title, content, progress and session_id properties with the object CourseDescription
  118. * @param int description type
  119. * @return int affected rows
  120. */
  121. public function insert_stats($description_type) {
  122. $tbl_stats_item_property = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ITEM_PROPERTY);
  123. $description_id = $this->get_id_by_description_type($description_type);
  124. $course_id = api_get_real_course_id();
  125. $course_code = api_get_course_id();
  126. $item_property_id = api_get_item_property_id($course_code, TOOL_COURSE_DESCRIPTION, $description_id);
  127. $sql = "INSERT IGNORE INTO $tbl_stats_item_property SET
  128. course_id = '$course_id',
  129. item_property_id = '$item_property_id',
  130. title = '".Database::escape_string($this->title)."',
  131. content = '".Database::escape_string($this->content)."',
  132. progress = '".intval($this->progress)."',
  133. lastedit_date = '".date('Y-m-d H:i:s')."',
  134. lastedit_user_id = '".api_get_user_id()."',
  135. session_id = '".intval($this->session_id)."'";
  136. Database::query($sql, __FILE__, __LINE__);
  137. $affected_rows = Database::affected_rows();
  138. return $affected_rows;
  139. }
  140. /**
  141. * Update a description, first you must set description_type, title, content, progress
  142. * and session_id properties with the object CourseDescription
  143. * @return int affected rows
  144. */
  145. public function update() {
  146. $tbl_course_description = Database::get_course_table(TABLE_COURSE_DESCRIPTION);
  147. $sql = "UPDATE $tbl_course_description SET title = '".Database::escape_string($this->title)."', content = '".Database::escape_string($this->content)."', progress = '".$this->progress."' WHERE description_type='".intval($this->description_type)."' AND session_id = '".$this->session_id."'";
  148. Database::query($sql, __FILE__, __LINE__);
  149. $affected_rows = Database::affected_rows();
  150. $description_id = $this->get_id_by_description_type($this->description_type);
  151. if ($description_id > 0) {
  152. //insert into item_property
  153. api_item_property_update(api_get_course_info(), TOOL_COURSE_DESCRIPTION, $description_id, 'CourseDescriptionUpdated', api_get_user_id());
  154. }
  155. return $affected_rows;
  156. }
  157. /**
  158. * Delete a description, first you must set description_type and session_id properties with the object CourseDescription
  159. * @return int affected rows
  160. */
  161. public function delete() {
  162. $tbl_course_description = Database::get_course_table(TABLE_COURSE_DESCRIPTION);
  163. $description_id = $this->get_id_by_description_type($this->description_type);
  164. $sql = "DELETE FROM $tbl_course_description WHERE description_type = '".intval($this->description_type)."' AND session_id = '".intval($this->session_id)."'";
  165. Database::query($sql, __FILE__, __LINE__);
  166. $affected_rows = Database::affected_rows();
  167. if ($description_id > 0) {
  168. //insert into item_property
  169. api_item_property_update(api_get_course_info(), TOOL_COURSE_DESCRIPTION, $description_id, 'CourseDescriptionDeleted', api_get_user_id());
  170. }
  171. return $affected_rows;
  172. }
  173. /**
  174. * Get description id by description type
  175. * @param int description type
  176. * @return int description id
  177. */
  178. public function get_id_by_description_type($description_type) {
  179. $tbl_course_description = Database::get_course_table(TABLE_COURSE_DESCRIPTION);
  180. $sql = "SELECT id FROM $tbl_course_description WHERE description_type = '".intval($description_type)."'";
  181. $rs = Database::query($sql, __FILE__, __LINE__);
  182. $row = Database::fetch_array($rs);
  183. $description_id = $row['id'];
  184. return $description_id;
  185. }
  186. /**
  187. * get thematic progress in porcent for a course,
  188. * first you must set session_id property with the object CourseDescription
  189. * @param bool true for showing a icon about the progress, false otherwise (optional)
  190. * @param int Description type (optional)
  191. * @return string img html
  192. */
  193. public function get_progress_porcent($with_icon = false, $description_type = THEMATIC_ADVANCE) {
  194. $tbl_course_description = Database::get_course_table(TABLE_COURSE_DESCRIPTION);
  195. $session_id = intval($session_id);
  196. $sql = "SELECT progress FROM $tbl_course_description WHERE description_type = '".intval($description_type)."' AND session_id = '".intval($this->session_id)."' ";
  197. $rs = Database::query($sql, __FILE__, __LINE__);
  198. $progress = '';
  199. $img = '';
  200. $title = '0%';
  201. $image = 'level_0.png';
  202. if (Database::num_rows($rs) > 0) {
  203. $row = Database::fetch_array($rs);
  204. $progress = $row['progress'].'%';
  205. $image = 'level_'.$row['progress'].'.png';
  206. }
  207. if ($with_icon) {
  208. $img = Display::return_icon($image,get_lang('ThematicAdvance'),array('style'=>'vertical-align:middle'));
  209. }
  210. $progress = $img.$progress;
  211. return $progress;
  212. }
  213. /**
  214. * Get description titles by default
  215. * @return array
  216. */
  217. public function get_default_description_title() {
  218. $default_description_titles = array();
  219. $default_description_titles[1]= get_lang('GeneralDescription');
  220. $default_description_titles[2]= get_lang('Objectives');
  221. $default_description_titles[3]= get_lang('Topics');
  222. $default_description_titles[4]= get_lang('Methodology');
  223. $default_description_titles[5]= get_lang('CourseMaterial');
  224. $default_description_titles[6]= get_lang('HumanAndTechnicalResources');
  225. $default_description_titles[7]= get_lang('Assessment');
  226. $default_description_titles[8]= get_lang('ThematicAdvance');
  227. $default_description_titles[9]= get_lang('Other');
  228. return $default_description_titles;
  229. }
  230. /**
  231. * Get description titles editable by default
  232. * @return array
  233. */
  234. public function get_default_description_title_editable() {
  235. $default_description_title_editable = array();
  236. $default_description_title_editable[1] = true;
  237. $default_description_title_editable[2] = true;
  238. $default_description_title_editable[3] = true;
  239. $default_description_title_editable[4] = true;
  240. $default_description_title_editable[5] = true;
  241. $default_description_title_editable[6] = true;
  242. $default_description_title_editable[7] = true;
  243. $default_description_title_editable[8] = true;
  244. return $default_description_title_editable;
  245. }
  246. /**
  247. * Get description icons by default
  248. * @return array
  249. */
  250. public function get_default_description_icon() {
  251. $default_description_icon = array();
  252. $default_description_icon[1]= 'edu_miscellaneous.gif';
  253. $default_description_icon[2]= 'spire.gif';
  254. $default_description_icon[3]= 'kcmdf_big.gif';
  255. $default_description_icon[4]= 'misc.gif';
  256. $default_description_icon[5]= 'laptop.gif';
  257. $default_description_icon[6]= 'personal.gif';
  258. $default_description_icon[7]= 'korganizer.gif';
  259. $default_description_icon[8]= 'porcent.png';
  260. $default_description_icon[9]= 'ktip.gif';
  261. return $default_description_icon;
  262. }
  263. /**
  264. * Get questions by default for help
  265. * @return array
  266. */
  267. public function get_default_question() {
  268. $question = array();
  269. $question[1]= get_lang('GeneralDescriptionQuestions');
  270. $question[2]= get_lang('ObjectivesQuestions');
  271. $question[3]= get_lang('TopicsQuestions');
  272. $question[4]= get_lang('MethodologyQuestions');
  273. $question[5]= get_lang('CourseMaterialQuestions');
  274. $question[6]= get_lang('HumanAndTechnicalResourcesQuestions');
  275. $question[7]= get_lang('AssessmentQuestions');
  276. $question[8]= get_lang('thematicAdvanceQuestions');
  277. return $question;
  278. }
  279. /**
  280. * Get informations by default for help
  281. * @return array
  282. */
  283. public function get_default_information() {
  284. $information = array();
  285. $information[1]= get_lang('GeneralDescriptionInformation');
  286. $information[2]= get_lang('ObjectivesInformation');
  287. $information[3]= get_lang('TopicsInformation');
  288. $information[4]= get_lang('MethodologyInformation');
  289. $information[5]= get_lang('CourseMaterialInformation');
  290. $information[6]= get_lang('HumanAndTechnicalResourcesInformation');
  291. $information[7]= get_lang('AssessmentInformation');
  292. $information[8]= get_lang('ThematicAdvanceInformation');
  293. return $information;
  294. }
  295. /**
  296. * Set description id
  297. * @return void
  298. */
  299. public function set_id($id) {
  300. $this->id = $id;
  301. }
  302. /**
  303. * Set description title
  304. * @return void
  305. */
  306. public function set_title($title) {
  307. $this->title = $title;
  308. }
  309. /**
  310. * Set description content
  311. * @return void
  312. */
  313. public function set_content($content) {
  314. $this->content = $content;
  315. }
  316. /**
  317. * Set description session id
  318. * @return void
  319. */
  320. public function set_session_id($session_id) {
  321. $this->session_id = $session_id;
  322. }
  323. /**
  324. * Set description type
  325. * @return void
  326. */
  327. public function set_description_type($description_type) {
  328. $this->description_type = $description_type;
  329. }
  330. /**
  331. * Set progress of a description
  332. * @return void
  333. */
  334. public function set_progress($progress) {
  335. $this->progress = $progress;
  336. }
  337. /**
  338. * get description id
  339. * @return int
  340. */
  341. public function get_id() {
  342. return $this->id;
  343. }
  344. /**
  345. * get description title
  346. * @return string
  347. */
  348. public function get_title() {
  349. return $this->title;
  350. }
  351. /**
  352. * get description content
  353. * @return string
  354. */
  355. public function get_content() {
  356. return $this->content;
  357. }
  358. /**
  359. * get session id
  360. * @return int
  361. */
  362. public function get_session_id() {
  363. return $this->session_id;
  364. }
  365. /**
  366. * get description type
  367. * @return int
  368. */
  369. public function get_description_type() {
  370. return $this->description_type;
  371. }
  372. /**
  373. * get progress of a description
  374. * @return int
  375. */
  376. public function get_progress() {
  377. return $this->progress;
  378. }
  379. }
  380. ?>