glossary_form.class.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Glossay form class definition
  5. * @package chamilo.glossary
  6. */
  7. /**
  8. * Init
  9. */
  10. namespace Glossary;
  11. use Chamilo;
  12. /**
  13. * Form to edit/Create glossary entries.
  14. *
  15. * @license /licence.txt
  16. * @author Laurent Opprecht <laurent@opprecht.info>
  17. */
  18. class GlossaryForm extends \FormValidator
  19. {
  20. /**
  21. *
  22. * @param string $action
  23. * @param \Glossary\Glossary $item
  24. * @return \Glossary\GlossaryForm
  25. */
  26. static function create($action, $item = null)
  27. {
  28. $result = new self('glossary', 'post', $action);
  29. if ($item) {
  30. $result->init($item);
  31. }
  32. return $result;
  33. }
  34. protected $glossary;
  35. function __construct($form_name = 'glossary', $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 \Glossary\Glossary
  42. */
  43. public function get_glossary()
  44. {
  45. return $this->glossary;
  46. }
  47. public function set_glossary($value)
  48. {
  49. $this->glossary = $value;
  50. }
  51. /**
  52. *
  53. * @param \Glossary\Glossary $glossary
  54. */
  55. function init($glossary = null)
  56. {
  57. $this->set_glossary($glossary);
  58. $defaults = array();
  59. $defaults['name'] = $glossary->name;
  60. $defaults['description'] = $glossary->description;
  61. $this->add_hidden('c_id', $glossary->c_id);
  62. $this->add_hidden('id', $glossary->id);
  63. $this->add_hidden('session_id', $glossary->session_id);
  64. $this->add_hidden(Request::PARAM_SEC_TOKEN, Access::instance()->get_token());
  65. $form_name = $glossary->id ? get_lang('TermEdit') : get_lang('TermAddNew');
  66. $this->add_header($form_name);
  67. $this->add_textfield('name', get_lang('TermName'), $required = true, array('class' => 'span3'));
  68. $this->add_html_editor('description', get_lang('TermDefinition'), true, array('ToolbarSet' => 'Glossary', 'Width' => '90%', 'Height' => '300'));
  69. $this->add_button('save', get_lang('Save'), array('class' => 'btn save'));
  70. $this->setDefaults($defaults);
  71. }
  72. function update_model()
  73. {
  74. $values = $this->exportValues();
  75. $glossary = $this->get_glossary();
  76. $glossary->name = $values['name'];
  77. $glossary->description = $values['description'];
  78. }
  79. function validate()
  80. {
  81. $result = parent::validate();
  82. if ($result) {
  83. $this->update_model();
  84. }
  85. return $result;
  86. }
  87. }