notebook_form.class.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. namespace Notebook;
  3. use Chamilo;
  4. /**
  5. * Form to edit/Create notebook entries.
  6. *
  7. * @license /licence.txt
  8. * @author Laurent Opprecht <laurent@opprecht.info>
  9. */
  10. class NotebookForm extends \FormValidator
  11. {
  12. /**
  13. *
  14. * @param string $action
  15. * @param \Notebook\Notebook $item
  16. * @return \Notebook\NotebookForm
  17. */
  18. static function create($action, $item = null)
  19. {
  20. $result = new self('notebook', 'post', $action);
  21. if ($item) {
  22. $result->init($item);
  23. }
  24. return $result;
  25. }
  26. protected $notebook;
  27. function __construct($form_name = 'notebook', $method = 'post', $action = '', $target = '', $attributes = null, $track_submit = true)
  28. {
  29. parent::__construct($form_name, $method, $action, $target, $attributes, $track_submit);
  30. }
  31. /**
  32. *
  33. * @return \Notebook\Notebook
  34. */
  35. public function get_notebook()
  36. {
  37. return $this->notebook;
  38. }
  39. public function set_notebook($value)
  40. {
  41. $this->notebook = $value;
  42. }
  43. /**
  44. *
  45. * @param \Notebook\Notebook $notebook
  46. */
  47. function init($notebook = null)
  48. {
  49. $this->set_notebook($notebook);
  50. $defaults = array();
  51. $defaults['title'] = $notebook->title;
  52. $defaults['description'] = $notebook->description;
  53. $this->add_hidden('c_id', $notebook->c_id);
  54. $this->add_hidden('id', $notebook->id);
  55. $this->add_hidden('session_id', $notebook->session_id);
  56. $this->add_hidden(Request::PARAM_SEC_TOKEN, Access::instance()->get_token());
  57. $form_name = $notebook->id ? get_lang('ModifyNote') : get_lang('NoteAddNew');
  58. $this->add_header($form_name);
  59. $this->add_textfield('title', get_lang('NoteTitle'), $required = true, array('class' => 'span3'));
  60. if (api_is_allowed_to_edit()) {
  61. $toolbar = array('ToolbarSet' => 'Notebook', 'Width' => '100%', 'Height' => '300');
  62. } else {
  63. $toolbar = array('ToolbarSet' => 'NotebookStudent', 'Width' => '100%', 'Height' => '300', 'UserStatus' => 'student');
  64. }
  65. $this->add_html_editor('description', get_lang('NoteComment'), true, api_is_allowed_to_edit(), $toolbar);
  66. $this->add_button('save', get_lang('Save'), array('class' => 'btn save'));
  67. $this->setDefaults($defaults);
  68. }
  69. function update_model()
  70. {
  71. $values = $this->exportValues();
  72. $notebook = $this->get_notebook();
  73. $notebook->title = $values['title'];
  74. $notebook->description = $values['description'];
  75. }
  76. function validate()
  77. {
  78. $result = parent::validate();
  79. if ($result) {
  80. $this->update_model();
  81. }
  82. return $result;
  83. }
  84. }