course_description_form.class.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Course description's form class definition
  5. * @package chamilo.course_description
  6. */
  7. /**
  8. * Init
  9. */
  10. namespace CourseDescription;
  11. use Security;
  12. /**
  13. * Edit/create a course description.
  14. *
  15. * @author Laurent Opprecht <laurent@opprecht.info> for the Univesity of Genevas
  16. * @license /license.txt
  17. */
  18. class CourseDescriptionForm extends \FormValidator
  19. {
  20. /**
  21. *
  22. * @param string $action
  23. * @param \CourseDescription\CourseDescription $description
  24. * @return \CourseDescription\CourseDescription
  25. */
  26. static function create($action, $description = null)
  27. {
  28. $result = new self('course_description', 'post', $action);
  29. if ($description) {
  30. $result->init($description);
  31. }
  32. return $result;
  33. }
  34. protected $course_description;
  35. function __construct($form_name = 'course_description', $method = 'post', $action = '', $target = '', $attributes = null, $track_submit = true)
  36. {
  37. parent::__construct($form_name, $method, $action, $target, $attributes, $track_submit);
  38. }
  39. /**
  40. *
  41. * @return \CourseDescription\CourseDescription
  42. *
  43. */
  44. public function get_course_description()
  45. {
  46. return $this->course_description;
  47. }
  48. public function set_course_description($value)
  49. {
  50. $this->course_description = $value;
  51. }
  52. /**
  53. *
  54. * @param \CourseDescription\CourseDescription $description
  55. */
  56. function init($description = null)
  57. {
  58. $this->set_course_description($description);
  59. $defaults = array();
  60. $defaults['title'] = $description->title;
  61. $defaults['content'] = $description->content;
  62. $this->add_header($description->get_title());
  63. $this->add_hidden('description_type', $description->get_description_type());
  64. $this->add_hidden('c_id', $description->c_id);
  65. $this->add_hidden('id', $description->id);
  66. $this->add_textfield('title', get_lang('Title'), true, array('size' => 'width: 350px;'));
  67. $this->applyFilter('title', 'html_filter');
  68. $this->add_html_editor('content', get_lang('Content'), true, false, array('ToolbarSet' => 'TrainingDescription', 'Width' => '100%', 'Height' => '200'));
  69. $this->add_button('save', get_lang('Save'), 'class="save"');
  70. $this->setDefaults($defaults);
  71. }
  72. function update_model()
  73. {
  74. $values = $this->exportValues();
  75. $course_description = $this->get_course_description();
  76. $course_description->title = $values['title'];
  77. $course_description->title = Security::remove_XSS($course_description->title);
  78. $course_description->content = $values['content'];
  79. $course_description->content = Security::remove_XSS($course_description->content, COURSEMANAGERLOWSECURITY);
  80. }
  81. function validate()
  82. {
  83. $result = parent::validate();
  84. if ($result) {
  85. $this->update_model();
  86. }
  87. return $result;
  88. }
  89. }