course_description.lib.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This file contains a class used like library provides functions for
  5. * course description tool. It's also used like model to
  6. * course_description_controller (MVC pattern).
  7. *
  8. * @author Christian Fasanando <christian1827@gmail.com>
  9. *
  10. * @package chamilo.course_description
  11. */
  12. /**
  13. * Class CourseDescription course descriptions.
  14. *
  15. * @package chamilo.course_description
  16. */
  17. class CourseDescription
  18. {
  19. private $id;
  20. private $course_id;
  21. private $title;
  22. private $content;
  23. private $session_id;
  24. private $description_type;
  25. private $progress;
  26. /**
  27. * Constructor.
  28. */
  29. public function __construct()
  30. {
  31. }
  32. /**
  33. * Returns an array of objects of type CourseDescription corresponding to
  34. * a specific course, without session ids (session id = 0).
  35. *
  36. * @param int $course_id
  37. *
  38. * @return array Array of CourseDescriptions
  39. */
  40. public static function get_descriptions($course_id)
  41. {
  42. $course_id = (int) $course_id;
  43. // Get course code
  44. $course_info = api_get_course_info_by_id($course_id);
  45. if (!empty($course_info)) {
  46. $course_id = $course_info['real_id'];
  47. } else {
  48. return [];
  49. }
  50. $table = Database::get_course_table(TABLE_COURSE_DESCRIPTION);
  51. $sql = "SELECT * FROM $table
  52. WHERE c_id = $course_id AND session_id = '0'";
  53. $sql_result = Database::query($sql);
  54. $results = [];
  55. while ($row = Database::fetch_array($sql_result)) {
  56. $desc_tmp = new CourseDescription();
  57. $desc_tmp->set_id($row['id']);
  58. $desc_tmp->set_title($row['title']);
  59. $desc_tmp->set_content($row['content']);
  60. $desc_tmp->set_session_id($row['session_id']);
  61. $desc_tmp->set_description_type($row['description_type']);
  62. $desc_tmp->set_progress($row['progress']);
  63. $results[] = $desc_tmp;
  64. }
  65. return $results;
  66. }
  67. /**
  68. * Get all data of course description by session id,
  69. * first you must set session_id property with the object CourseDescription.
  70. *
  71. * @return array
  72. */
  73. public function get_description_data()
  74. {
  75. $table = Database::get_course_table(TABLE_COURSE_DESCRIPTION);
  76. $condition_session = api_get_session_condition(
  77. $this->session_id,
  78. true,
  79. true
  80. );
  81. $course_id = $this->course_id ?: api_get_course_int_id();
  82. if (empty($course_id)) {
  83. return [];
  84. }
  85. $sql = "SELECT * FROM $table
  86. WHERE c_id = $course_id $condition_session
  87. ORDER BY id ";
  88. $rs = Database::query($sql);
  89. $data = [];
  90. while ($description = Database::fetch_array($rs)) {
  91. $data['descriptions'][$description['id']] = $description;
  92. }
  93. return $data;
  94. }
  95. /**
  96. * Get all data by description and session id,
  97. * first you must set session_id property with the object CourseDescription.
  98. *
  99. * @param int $description_type Description type
  100. * @param string $courseId Course code (optional)
  101. * @param int $session_id Session id (optional)
  102. *
  103. * @return array List of fields from the descriptions found of the given type
  104. */
  105. public function get_data_by_description_type(
  106. $description_type,
  107. $courseId = null,
  108. $session_id = null
  109. ) {
  110. $table = Database::get_course_table(TABLE_COURSE_DESCRIPTION);
  111. $courseId = (int) $courseId;
  112. if (empty($courseId)) {
  113. $courseId = api_get_course_int_id();
  114. }
  115. if (!isset($session_id)) {
  116. $session_id = $this->session_id;
  117. }
  118. $condition_session = api_get_session_condition($session_id);
  119. $description_type = (int) $description_type;
  120. $sql = "SELECT * FROM $table
  121. WHERE
  122. c_id = $courseId AND
  123. description_type = '$description_type'
  124. $condition_session ";
  125. $rs = Database::query($sql);
  126. $data = [];
  127. if ($description = Database::fetch_array($rs)) {
  128. $data['description_title'] = $description['title'];
  129. $data['description_content'] = $description['content'];
  130. $data['progress'] = $description['progress'];
  131. $data['id'] = $description['id'];
  132. }
  133. return $data;
  134. }
  135. /**
  136. * @param int $id
  137. * @param string $course_code
  138. * @param int $session_id
  139. *
  140. * @return array
  141. */
  142. public function get_data_by_id($id, $course_code = '', $session_id = null)
  143. {
  144. $table = Database::get_course_table(TABLE_COURSE_DESCRIPTION);
  145. $course_id = api_get_course_int_id();
  146. $id = (int) $id;
  147. if (!isset($session_id)) {
  148. $session_id = $this->session_id;
  149. }
  150. $condition_session = api_get_session_condition($session_id);
  151. if (!empty($course_code)) {
  152. $course_info = api_get_course_info($course_code);
  153. $course_id = $course_info['real_id'];
  154. }
  155. $sql = "SELECT * FROM $table
  156. WHERE c_id = $course_id AND id='$id' $condition_session ";
  157. $rs = Database::query($sql);
  158. $data = [];
  159. if ($description = Database::fetch_array($rs)) {
  160. $data['description_type'] = $description['description_type'];
  161. $data['description_title'] = $description['title'];
  162. $data['description_content'] = $description['content'];
  163. $data['progress'] = $description['progress'];
  164. }
  165. return $data;
  166. }
  167. /**
  168. * Get maximum description type by session id,
  169. * first you must set session_id properties with the object CourseDescription.
  170. *
  171. * @return int maximum description time adding one
  172. */
  173. public function get_max_description_type()
  174. {
  175. $table = Database::get_course_table(TABLE_COURSE_DESCRIPTION);
  176. $course_id = api_get_course_int_id();
  177. $sql = "SELECT MAX(description_type) as MAX
  178. FROM $table
  179. WHERE c_id = $course_id AND session_id='".$this->session_id."'";
  180. $rs = Database::query($sql);
  181. $max = Database::fetch_array($rs);
  182. if ($max['MAX'] >= 8) {
  183. $description_type = 8;
  184. } else {
  185. $description_type = $max['MAX'] + 1;
  186. }
  187. if ($description_type < ADD_BLOCK) {
  188. $description_type = ADD_BLOCK;
  189. }
  190. return $description_type;
  191. }
  192. /**
  193. * Insert a description to the course_description table,
  194. * first you must set description_type, title, content, progress and
  195. * session_id properties with the object CourseDescription.
  196. *
  197. * @return int affected rows
  198. */
  199. public function insert()
  200. {
  201. if (empty($this->course_id)) {
  202. $course_id = api_get_course_int_id();
  203. } else {
  204. $course_id = $this->course_id;
  205. }
  206. $table = Database::get_course_table(TABLE_COURSE_DESCRIPTION);
  207. $params = [
  208. 'c_id' => $course_id,
  209. 'description_type' => $this->description_type,
  210. 'title' => $this->title,
  211. 'content' => $this->content,
  212. 'progress' => intval($this->progress),
  213. 'session_id' => $this->session_id,
  214. ];
  215. $last_id = Database::insert($table, $params);
  216. if ($last_id > 0) {
  217. $sql = "UPDATE $table SET id = iid WHERE iid = $last_id";
  218. Database::query($sql);
  219. // insert into item_property
  220. api_item_property_update(
  221. api_get_course_info(),
  222. TOOL_COURSE_DESCRIPTION,
  223. $last_id,
  224. 'CourseDescriptionAdded',
  225. api_get_user_id()
  226. );
  227. }
  228. return $last_id > 0 ? 1 : 0;
  229. }
  230. /**
  231. * Update a description, first you must set description_type, title, content, progress
  232. * and session_id properties with the object CourseDescription.
  233. *
  234. * @return int affected rows
  235. */
  236. public function update()
  237. {
  238. $table = Database::get_course_table(TABLE_COURSE_DESCRIPTION);
  239. $params = [
  240. 'title' => $this->title,
  241. 'content' => $this->content,
  242. 'progress' => intval($this->progress),
  243. ];
  244. Database::update(
  245. $table,
  246. $params,
  247. [
  248. 'id = ? AND session_id = ? AND c_id = ?' => [
  249. $this->id,
  250. $this->session_id,
  251. $this->course_id ? $this->course_id : api_get_course_int_id(),
  252. ],
  253. ]
  254. );
  255. if ($this->id > 0) {
  256. // Insert into item_property
  257. api_item_property_update(
  258. api_get_course_info(),
  259. TOOL_COURSE_DESCRIPTION,
  260. $this->id,
  261. 'CourseDescriptionUpdated',
  262. api_get_user_id()
  263. );
  264. }
  265. return 1;
  266. }
  267. /**
  268. * Delete a description, first you must set description_type and session_id
  269. * properties with the object CourseDescription.
  270. *
  271. * @return int affected rows
  272. */
  273. public function delete()
  274. {
  275. $table = Database::get_course_table(TABLE_COURSE_DESCRIPTION);
  276. $course_id = api_get_course_int_id();
  277. $sql = "DELETE FROM $table
  278. WHERE
  279. c_id = $course_id AND
  280. id = '".intval($this->id)."' AND
  281. session_id = '".intval($this->session_id)."'";
  282. $result = Database::query($sql);
  283. $affected_rows = Database::affected_rows($result);
  284. if ($this->id > 0) {
  285. //insert into item_property
  286. api_item_property_update(
  287. api_get_course_info(),
  288. TOOL_COURSE_DESCRIPTION,
  289. $this->id,
  290. 'CourseDescriptionDeleted',
  291. api_get_user_id()
  292. );
  293. }
  294. return $affected_rows;
  295. }
  296. /**
  297. * Get description titles by default.
  298. *
  299. * @return array
  300. */
  301. public function get_default_description_title()
  302. {
  303. $default_description_titles = [];
  304. $default_description_titles[1] = get_lang('Description');
  305. $default_description_titles[2] = get_lang('Objectives');
  306. $default_description_titles[3] = get_lang('Topics');
  307. $default_description_titles[4] = get_lang('Methodology');
  308. $default_description_titles[5] = get_lang('Course material');
  309. $default_description_titles[6] = get_lang('Resources');
  310. $default_description_titles[7] = get_lang('Assessment');
  311. $default_description_titles[8] = get_lang('Other');
  312. return $default_description_titles;
  313. }
  314. /**
  315. * Get description titles editable by default.
  316. *
  317. * @return array
  318. */
  319. public function get_default_description_title_editable()
  320. {
  321. $default_description_title_editable = [];
  322. $default_description_title_editable[1] = true;
  323. $default_description_title_editable[2] = true;
  324. $default_description_title_editable[3] = true;
  325. $default_description_title_editable[4] = true;
  326. $default_description_title_editable[5] = true;
  327. $default_description_title_editable[6] = true;
  328. $default_description_title_editable[7] = true;
  329. //$default_description_title_editable[8] = true;
  330. return $default_description_title_editable;
  331. }
  332. /**
  333. * Get description icons by default.
  334. *
  335. * @return array
  336. */
  337. public function get_default_description_icon()
  338. {
  339. $default_description_icon = [];
  340. $default_description_icon[1] = 'info.png';
  341. $default_description_icon[2] = 'objective.png';
  342. $default_description_icon[3] = 'topics.png';
  343. $default_description_icon[4] = 'strategy.png';
  344. $default_description_icon[5] = 'laptop.png';
  345. $default_description_icon[6] = 'teacher.png';
  346. $default_description_icon[7] = 'assessment.png';
  347. $default_description_icon[8] = 'wizard.png';
  348. return $default_description_icon;
  349. }
  350. /**
  351. * Get questions by default for help.
  352. *
  353. * @return array
  354. */
  355. public function get_default_question()
  356. {
  357. $question = [];
  358. $question[1] = get_lang('DescriptionQuestions');
  359. $question[2] = get_lang('What should the end results be when the learner has completed the course? What are the activities performed during the course?');
  360. $question[3] = get_lang('How does the course progress? Where should the learner pay special care? Are there identifiable problems in understanding different areas? How much time should one dedicate to the different areas of the course?');
  361. $question[4] = get_lang('What methods and activities help achieve the objectives of the course? What would the schedule be?');
  362. $question[5] = get_lang('Course materialQuestions');
  363. $question[6] = get_lang('ResourcesQuestions');
  364. $question[7] = get_lang('How will learners be assessed? Are there strategies to develop in order to master the topic?');
  365. //$question[8]= get_lang('What is the current progress you have reached with your learners inside your course? How much do you think is remaining in comparison to the complete program?');
  366. return $question;
  367. }
  368. /**
  369. * Get informations by default for help.
  370. *
  371. * @return array
  372. */
  373. public function get_default_information()
  374. {
  375. $information = [];
  376. $information[1] = get_lang('DescriptionInformation');
  377. $information[2] = get_lang('What are the objectives of the course (competences, skills, outcomes)?');
  378. $information[3] = get_lang('List of topics included in the training. Importance of each topic. Level of difficulty. Structure and inter-dependence of the different parts.');
  379. $information[4] = get_lang('Presentation of the activities (conference, papers, group research, labs...).');
  380. $information[5] = get_lang('Course materialInformation');
  381. $information[6] = get_lang('ResourcesInformation');
  382. $information[7] = get_lang('Criteria for skills acquisition.');
  383. //$information[8]= get_lang('The thematic advance tool allows you to organize your course through time.');
  384. return $information;
  385. }
  386. /**
  387. * Set description id.
  388. */
  389. public function set_id($id)
  390. {
  391. $this->id = $id;
  392. }
  393. /**
  394. * Set description's course id.
  395. *
  396. * @param int $id Course ID
  397. */
  398. public function set_course_id($id)
  399. {
  400. $this->course_id = intval($id);
  401. }
  402. /**
  403. * Set description title.
  404. *
  405. * @param string $title
  406. */
  407. public function set_title($title)
  408. {
  409. $this->title = $title;
  410. }
  411. /**
  412. * Set description content.
  413. *
  414. * @param string $content
  415. */
  416. public function set_content($content)
  417. {
  418. $this->content = $content;
  419. }
  420. /**
  421. * Set description session id.
  422. *
  423. * @param int $session_id
  424. */
  425. public function set_session_id($session_id)
  426. {
  427. $this->session_id = $session_id;
  428. }
  429. /**
  430. * Set description type.
  431. */
  432. public function set_description_type($description_type)
  433. {
  434. $this->description_type = $description_type;
  435. }
  436. /**
  437. * Set progress of a description.
  438. *
  439. * @param string $progress
  440. */
  441. public function set_progress($progress)
  442. {
  443. $this->progress = $progress;
  444. }
  445. /**
  446. * get description id.
  447. *
  448. * @return int
  449. */
  450. public function get_id()
  451. {
  452. return $this->id;
  453. }
  454. /**
  455. * get description title.
  456. *
  457. * @return string
  458. */
  459. public function get_title()
  460. {
  461. return $this->title;
  462. }
  463. /**
  464. * get description content.
  465. *
  466. * @return string
  467. */
  468. public function get_content()
  469. {
  470. return $this->content;
  471. }
  472. /**
  473. * get session id.
  474. *
  475. * @return int
  476. */
  477. public function get_session_id()
  478. {
  479. return $this->session_id;
  480. }
  481. /**
  482. * get description type.
  483. *
  484. * @return int
  485. */
  486. public function get_description_type()
  487. {
  488. return $this->description_type;
  489. }
  490. /**
  491. * get progress of a description.
  492. *
  493. * @return int
  494. */
  495. public function get_progress()
  496. {
  497. return $this->progress;
  498. }
  499. }