event_email_template.class.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @deprecated
  5. * Class EventEmailTemplate
  6. */
  7. class EventEmailTemplate extends Model
  8. {
  9. public $table;
  10. public $columns = [
  11. 'id',
  12. 'message',
  13. 'subject',
  14. 'event_type_name',
  15. 'activated',
  16. ];
  17. /**
  18. * Constructor.
  19. */
  20. public function __construct()
  21. {
  22. $this->table = Database::get_main_table(TABLE_EVENT_EMAIL_TEMPLATE);
  23. }
  24. /**
  25. * @param array $where_conditions
  26. *
  27. * @return array
  28. */
  29. public function get_all($where_conditions = [])
  30. {
  31. return Database::select(
  32. '*',
  33. $this->table,
  34. ['where' => $where_conditions, 'order' => 'name ASC']
  35. );
  36. }
  37. /**
  38. * Displays the title + grid.
  39. */
  40. public function display()
  41. {
  42. // action links
  43. $content = Display::actions(
  44. [
  45. [
  46. 'url' => 'event_type.php',
  47. 'content' => Display::return_icon(
  48. 'new_document.png',
  49. get_lang('Add'),
  50. [],
  51. ICON_SIZE_MEDIUM
  52. ),
  53. ],
  54. ]
  55. );
  56. $content .= Display::grid_html('event_email_template');
  57. return $content;
  58. }
  59. /**
  60. * @return array
  61. */
  62. public function get_status_list()
  63. {
  64. return [
  65. EVENT_EMAIL_TEMPLATE_ACTIVE => get_lang('Enabled'),
  66. EVENT_EMAIL_TEMPLATE_INACTIVE => get_lang('Disabled'),
  67. ];
  68. }
  69. /**
  70. * Returns a Form validator Obj.
  71. *
  72. * @param string $url
  73. * @param string $action add, edit
  74. *
  75. * @return FormValidator
  76. */
  77. public function return_form($url, $action)
  78. {
  79. $form = new FormValidator('career', 'post', $url);
  80. // Setting the form elements
  81. $header = get_lang('Add');
  82. if ($action == 'edit') {
  83. $header = get_lang('Modify');
  84. }
  85. $form->addElement('header', $header);
  86. $id = isset($_GET['id']) ? intval($_GET['id']) : '';
  87. $form->addElement('hidden', 'id', $id);
  88. $form->addElement('text', 'name', get_lang('Name'), ['size' => '70']);
  89. $form->addHtmlEditor(
  90. 'description',
  91. get_lang('Description'),
  92. false,
  93. false,
  94. [
  95. 'ToolbarSet' => 'careers',
  96. 'Width' => '100%',
  97. 'Height' => '250',
  98. ]
  99. );
  100. $status_list = $this->get_status_list();
  101. $form->addElement('select', 'status', get_lang('Status'), $status_list);
  102. if ($action == 'edit') {
  103. $form->addElement('text', 'created_at', get_lang('CreatedAt'));
  104. $form->freeze('created_at');
  105. }
  106. if ($action == 'edit') {
  107. $form->addButtonSave(get_lang('Modify'), 'submit');
  108. } else {
  109. $form->addButtonCreate(get_lang('Add'), 'submit');
  110. }
  111. // Setting the defaults
  112. $defaults = $this->get($id);
  113. if (!empty($defaults['created_at'])) {
  114. $defaults['created_at'] = api_convert_and_format_date($defaults['created_at']);
  115. }
  116. if (!empty($defaults['updated_at'])) {
  117. $defaults['updated_at'] = api_convert_and_format_date($defaults['updated_at']);
  118. }
  119. $form->setDefaults($defaults);
  120. // Setting the rules
  121. $form->addRule('name', get_lang('ThisFieldIsRequired'), 'required');
  122. return $form;
  123. }
  124. public function get_count()
  125. {
  126. $row = Database::select('count(*) as count', $this->table, [], 'first');
  127. return $row['count'];
  128. }
  129. }