category_form.class.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Link category form class definition
  5. * @package chamilo.link
  6. */
  7. /**
  8. * Init
  9. */
  10. namespace Link;
  11. /**
  12. * Edit/create a LinkCategory.
  13. *
  14. * @author Laurent Opprecht <laurent@opprecht.info> for the Univesity of Genevas
  15. * @license /license.txt
  16. */
  17. class CategoryForm extends \FormValidator
  18. {
  19. protected $category;
  20. function __construct($form_name = 'category', $method = 'post', $action = '', $target = '', $attributes = null, $track_submit = true)
  21. {
  22. parent::__construct($form_name, $method, $action, $target, $attributes, $track_submit);
  23. }
  24. /**
  25. *
  26. * @return object
  27. */
  28. public function get_category()
  29. {
  30. return $this->category;
  31. }
  32. public function set_category($value)
  33. {
  34. $this->category = $value;
  35. }
  36. /**
  37. *
  38. * @param \Link\LinkCategory $category
  39. */
  40. function init($category = null)
  41. {
  42. $this->set_category($category);
  43. $defaults = array();
  44. $defaults['category_title'] = $category->category_title;
  45. $defaults['category_description'] = $category->description;
  46. $this->addElement('hidden', 'c_id', $category->c_id);
  47. $this->addElement('hidden', 'id', $category->id);
  48. $this->addElement('hidden', 'session_id', $category->session_id);
  49. $form_name = $category->id ? get_lang('ModifyCategory') : get_lang('AddCategory');
  50. $this->add_header($form_name);
  51. $this->add_textfield('category_title', get_lang('Title'));
  52. $this->addRule('category_title', get_lang('Required'), 'required');
  53. $this->addElement('textarea', 'category_description', get_lang('Description'));
  54. $this->addElement('button', 'save', get_lang('Save'), array('class' => 'btn save'));
  55. $this->setDefaults($defaults);
  56. }
  57. function update_model()
  58. {
  59. $values = $this->exportValues();
  60. $category = $this->get_category();
  61. $category->category_title = $values['category_title'];
  62. $category->description = $values['category_description'];
  63. }
  64. }