course_description_controller.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This file contains class used like controller, it should be included inside a dispatcher file (e.g: index.php)
  5. * @author Christian Fasanando <christian1827@gmail.com>
  6. * @package chamilo.course_description
  7. */
  8. /**
  9. * Controller script. Prepares the common background variables to give to the scripts corresponding to
  10. * the requested action
  11. * @package chamilo.course_description
  12. */
  13. class CourseDescriptionController { // extends Controller {
  14. private $toolname;
  15. private $view;
  16. /**
  17. * Constructor
  18. */
  19. public function __construct() {
  20. $this->toolname = 'course_description';
  21. $this->view = new View($this->toolname);
  22. }
  23. /**
  24. * It's used for listing course description,
  25. * render to listing view
  26. * @param boolean true for listing history (optional)
  27. * @param array message for showing by action['edit','add','destroy'] (optional)
  28. */
  29. public function listing($history=false,$messages=array()) {
  30. $course_description = new CourseDescription();
  31. $session_id = api_get_session_id();
  32. $course_description->set_session_id($session_id);
  33. $data = array();
  34. if ($history) {
  35. $course_description_data = $course_description->get_description_history(THEMATIC_ADVANCE);
  36. $data['history'] = true;
  37. } else {
  38. $course_description_data = $course_description->get_description_data();
  39. }
  40. $data['descriptions'] = $course_description_data['descriptions'];
  41. $data['default_description_titles'] = $course_description->get_default_description_title();
  42. $data['default_description_title_editable'] = $course_description->get_default_description_title_editable();
  43. $data['default_description_icon'] = $course_description->get_default_description_icon();
  44. $data['messages'] = $messages;
  45. // render to the view
  46. $this->view->set_data($data);
  47. $this->view->set_layout('layout');
  48. $this->view->set_template('listing');
  49. $this->view->render();
  50. }
  51. /**
  52. * It's used for editing a course description,
  53. * render to listing or edit view
  54. * @param int description type
  55. */
  56. public function edit($description_type) {
  57. $course_description = new CourseDescription();
  58. $session_id = api_get_session_id();
  59. $course_description->set_session_id($session_id);
  60. $data = array();
  61. if (strtoupper($_SERVER['REQUEST_METHOD']) == "POST") {
  62. if (!empty($_POST['title']) && !empty($_POST['contentDescription'])) {
  63. $check = Security::check_token();
  64. if ($check) {
  65. $title = $_POST['title'];
  66. if (api_get_setting('wcag_anysurfer_public_pages')=='true') {
  67. $content = WCAG_Rendering::prepareXHTML();
  68. } else {
  69. $content = $_POST['contentDescription'];
  70. }
  71. $description_type = $_POST['description_type'];
  72. $progress = $_POST['progress'];
  73. $course_description->set_description_type($description_type);
  74. $course_description->set_title($title);
  75. $course_description->set_content($content);
  76. $course_description->set_progress($progress);
  77. if ($description_type >= ADD_BLOCK) {
  78. $affected_rows = $course_description->update();
  79. } else {
  80. $thematic_advance = $course_description->get_data_by_description_type($description_type);
  81. if (!empty($thematic_advance)) {
  82. if ($description_type == THEMATIC_ADVANCE) {
  83. // if is thematic advance type save in history
  84. $course_description->set_title($thematic_advance['description_title']);
  85. $course_description->set_content($thematic_advance['description_content']);
  86. $course_description->set_progress($thematic_advance['progress']);
  87. $course_description->insert_stats($description_type);
  88. }
  89. $course_description->set_title($title);
  90. $course_description->set_content($content);
  91. $course_description->set_progress($progress);
  92. $affected_rows = $course_description->update();
  93. } else {
  94. $affected_rows = $course_description->insert();
  95. }
  96. }
  97. Security::clear_token();
  98. }
  99. if ($affected_rows) {
  100. $message['edit'] = true;
  101. }
  102. $this->listing(false,$message);
  103. } else {
  104. $data['error'] = 1;
  105. $data['default_description_titles'] = $course_description->get_default_description_title();
  106. $data['default_description_title_editable'] = $course_description->get_default_description_title_editable();
  107. $data['default_description_icon'] = $course_description->get_default_description_icon();
  108. $data['question'] = $course_description->get_default_question();
  109. $data['information'] = $course_description->get_default_information();
  110. $data['description_title'] = $_POST['title'];
  111. $data['description_content'] = $_POST['contentDescription'];
  112. $data['description_type'] = $_POST['description_type'];
  113. $data['progress'] = $_POST['progress'];
  114. $data['descriptions'] = $course_description->get_data_by_description_type($_POST['description_type']);
  115. // render to the view
  116. $this->view->set_data($data);
  117. $this->view->set_layout('layout');
  118. $this->view->set_template('edit');
  119. $this->view->render();
  120. }
  121. } else {
  122. if (!empty($description_type)) {
  123. $course_description_data = $course_description->get_data_by_description_type($description_type);
  124. $data['default_description_titles'] = $course_description->get_default_description_title();
  125. $data['default_description_title_editable'] = $course_description->get_default_description_title_editable();
  126. $data['default_description_icon'] = $course_description->get_default_description_icon();
  127. $data['question'] = $course_description->get_default_question();
  128. $data['information'] = $course_description->get_default_information();
  129. $data['description_title'] = $course_description_data['description_title'];
  130. $data['description_content'] = $course_description_data['description_content'];
  131. $data['description_type'] = $description_type;
  132. $data['progress'] = $course_description_data['progress'];
  133. $data['descriptions'] = $course_description->get_data_by_description_type($description_type);
  134. }
  135. // render to the view
  136. $this->view->set_data($data);
  137. $this->view->set_layout('layout');
  138. $this->view->set_template('edit');
  139. $this->view->render();
  140. }
  141. }
  142. /**
  143. * It's used for adding a course description,
  144. * render to listing or add view
  145. */
  146. public function add() {
  147. $course_description = new CourseDescription();
  148. $session_id = api_get_session_id();
  149. $course_description->set_session_id($session_id);
  150. $data = array();
  151. if (strtoupper($_SERVER['REQUEST_METHOD']) == "POST") {
  152. if (!empty($_POST['title']) && !empty($_POST['contentDescription'])) {
  153. $check = Security::check_token();
  154. if ($check) {
  155. $title = $_POST['title'];
  156. if (api_get_setting('wcag_anysurfer_public_pages')=='true') {
  157. $content = WCAG_Rendering::prepareXHTML();
  158. } else {
  159. $content = $_POST['contentDescription'];
  160. }
  161. $description_type = $_POST['description_type'];
  162. if ($description_type >= ADD_BLOCK) {
  163. $course_description->set_description_type($description_type);
  164. $course_description->set_title($title);
  165. $course_description->set_content($content);
  166. $affected_rows = $course_description->insert();
  167. }
  168. Security::clear_token();
  169. }
  170. if ($affected_rows) {
  171. $message['add'] = true;
  172. }
  173. $this->listing(false,$message);
  174. } else {
  175. $data['error'] = 1;
  176. $data['default_description_titles'] = $course_description->get_default_description_title();
  177. $data['default_description_title_editable'] = $course_description->get_default_description_title_editable();
  178. $data['default_description_icon'] = $course_description->get_default_description_icon();
  179. $data['question'] = $course_description->get_default_question();
  180. $data['information'] = $course_description->get_default_information();
  181. $data['description_title'] = $_POST['title'];
  182. $data['description_content'] = $_POST['contentDescription'];
  183. $data['description_type'] = $_POST['description_type'];
  184. $this->view->set_data($data);
  185. $this->view->set_layout('layout');
  186. $this->view->set_template('add');
  187. $this->view->render();
  188. }
  189. } else {
  190. $data['default_description_titles'] = $course_description->get_default_description_title();
  191. $data['default_description_title_editable'] = $course_description->get_default_description_title_editable();
  192. $data['default_description_icon'] = $course_description->get_default_description_icon();
  193. $data['question'] = $course_description->get_default_question();
  194. $data['information'] = $course_description->get_default_information();
  195. $data['description_type'] = $course_description->get_max_description_type();
  196. // render to the view
  197. $this->view->set_data($data);
  198. $this->view->set_layout('layout');
  199. $this->view->set_template('add');
  200. $this->view->render();
  201. }
  202. }
  203. /**
  204. * It's used for destroy a course description,
  205. * render to listing view
  206. * @param int description type
  207. */
  208. public function destroy($description_type) {
  209. $course_description = new CourseDescription();
  210. $session_id = api_get_session_id();
  211. $course_description->set_session_id($session_id);
  212. if (!empty($description_type)) {
  213. $course_description->set_description_type($description_type);
  214. $affected_rows = $course_description->delete();
  215. }
  216. if ($affected_rows) {
  217. $message['destroy'] = true;
  218. }
  219. $this->listing(false,$message);
  220. }
  221. }
  222. ?>