actioncommreminder.class.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. <?php
  2. /* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. */
  17. /**
  18. * \file class/actioncommreminder.class.php
  19. * \ingroup agenda
  20. * \brief This file is a CRUD class file for ActionCommReminder (Create/Read/Update/Delete)
  21. */
  22. // Put here all includes required by your class file
  23. require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
  24. /**
  25. * Class for ActionCommReminder
  26. */
  27. class ActionCommReminder extends CommonObject
  28. {
  29. /**
  30. * @var string ID to identify managed object
  31. */
  32. public $element = 'actioncomm_reminder';
  33. /**
  34. * @var string Name of table without prefix where object is stored
  35. */
  36. public $table_element = 'actioncomm_reminder';
  37. /**
  38. * @var array Does actioncommreminder support multicompany module ? 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
  39. */
  40. public $ismultientitymanaged = 0;
  41. /**
  42. * @var string String with name of icon for actioncommreminder. Must be the part after the 'object_' into object_actioncommreminder.png
  43. */
  44. public $picto = 'generic';
  45. const STATUS_TODO = 0;
  46. const STATUS_DONE = 1;
  47. const STATUS_ERROR = -1;
  48. /**
  49. * 'type' if the field format.
  50. * 'label' the translation key.
  51. * 'enabled' is a condition when the field must be managed.
  52. * 'visible' says if field is visible in list (Examples: 0=Not visible, 1=Visible on list and create/update/view forms, 2=Visible on list only. Using a negative value means field is not shown by default on list but can be selected for viewing)
  53. * 'notnull' is set to 1 if not null in database. Set to -1 if we must set data to null if empty ('' or 0).
  54. * 'index' if we want an index in database.
  55. * 'foreignkey'=>'tablename.field' if the field is a foreign key (it is recommended to name the field fk_...).
  56. * 'position' is the sort order of field.
  57. * 'searchall' is 1 if we want to search in this field when making a search from the quick search button.
  58. * 'isameasure' must be set to 1 if you want to have a total on list for this field. Field type must be summable like integer or double(24,8).
  59. * 'help' is a string visible as a tooltip on field
  60. * 'comment' is not used. You can store here any text of your choice. It is not used by application.
  61. * 'default' is a default value for creation (can still be replaced by the global setup of default values)
  62. * 'showoncombobox' if field must be shown into the label of combobox
  63. */
  64. // BEGIN MODULEBUILDER PROPERTIES
  65. /**
  66. * @var array Array with all fields and their property. Do not use it as a static var. It may be modified by constructor.
  67. */
  68. public $fields = array(
  69. 'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'visible'=>-1, 'enabled'=>1, 'position'=>1, 'notnull'=>1, 'index'=>1, 'comment'=>"Id",),
  70. 'entity' => array('type'=>'integer', 'label'=>'Entity', 'visible'=>0, 'enabled'=>1, 'position'=>20, 'notnull'=>1, 'index'=>1,),
  71. 'dateremind' => array('type'=>'datetime', 'label'=>'DateRemind', 'visible'=>1, 'enabled'=>1, 'position'=>60, 'notnull'=>1, 'index'=>1,),
  72. 'typeremind' => array('type'=>'varchar(32)', 'label'=>'TypeRemind', 'visible'=>-1, 'enabled'=>1, 'position'=>55, 'notnull'=>1, 'comment'=>"email, browser, sms",),
  73. 'fk_user' => array('type'=>'integer', 'label'=>'User', 'visible'=>-1, 'enabled'=>1, 'position'=>65, 'notnull'=>1, 'index'=>1,),
  74. 'offsetvalue' => array('type'=>'integer', 'label'=>'OffsetValue', 'visible'=>1, 'enabled'=>1, 'position'=>56, 'notnull'=>1,),
  75. 'offsetunit' => array('type'=>'varchar(1)', 'label'=>'OffsetUnit', 'visible'=>1, 'enabled'=>1, 'position'=>57, 'notnull'=>1, 'comment'=>"y, m, d, w, h, i",),
  76. 'status' => array('type'=>'integer', 'label'=>'Status', 'visible'=>1, 'enabled'=>1, 'position'=>58, 'notnull'=>1, 'default'=>0, 'index'=>0, 'arrayofkeyval'=>array('0'=>'ToDo', '1'=>'Done')),
  77. 'lasterror' => array('type'=>'varchar(128)', 'label'=>'LastError', 'visible'=>-1, 'enabled'=>1, 'position'=>59, 'index'=>0),
  78. 'fk_actioncomm' => array('type'=>'integer', 'label'=>'Project', 'visible'=>1, 'enabled'=>1, 'position'=>70, 'notnull'=>1, 'index'=>1,),
  79. 'fk_email_template' => array('type'=>'integer', 'label'=>'EmailTemplate', 'visible'=>1, 'enabled'=>1, 'position'=>80, 'notnull'=>0),
  80. );
  81. /**
  82. * @var int ID
  83. */
  84. public $rowid;
  85. /**
  86. * @var int Entity
  87. */
  88. public $entity;
  89. public $dateremind;
  90. public $typeremind;
  91. /**
  92. * @var int User ID
  93. */
  94. public $fk_user;
  95. public $offsetvalue;
  96. public $offsetunit;
  97. /**
  98. * @var int Status
  99. */
  100. public $status;
  101. /**
  102. * @var string Last error message
  103. */
  104. public $lasterror;
  105. /**
  106. * @var int Project
  107. */
  108. public $fk_actioncomm;
  109. /**
  110. * @var int Template Mail
  111. */
  112. public $fk_email_template;
  113. // END MODULEBUILDER PROPERTIES
  114. /**
  115. * Constructor
  116. *
  117. * @param DoliDb $db Database handler
  118. */
  119. public function __construct(DoliDB $db)
  120. {
  121. global $conf;
  122. $this->db = $db;
  123. if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID)) {
  124. $this->fields['rowid']['visible'] = 0;
  125. }
  126. if (!isModEnabled('multicompany')) {
  127. $this->fields['entity']['enabled'] = 0;
  128. }
  129. }
  130. /**
  131. * Create object into database
  132. *
  133. * @param User $user User that creates
  134. * @param bool $notrigger false=launch triggers after, true=disable triggers
  135. * @return int <0 if KO, Id of created object if OK
  136. */
  137. public function create(User $user, $notrigger = false)
  138. {
  139. return $this->createCommon($user, $notrigger);
  140. }
  141. /**
  142. * Load object in memory from the database
  143. *
  144. * @param int $id Id object
  145. * @param string $ref Ref
  146. * @return int <0 if KO, 0 if not found, >0 if OK
  147. */
  148. public function fetch($id, $ref = null)
  149. {
  150. $result = $this->fetchCommon($id, $ref);
  151. return $result;
  152. }
  153. /**
  154. * Update object into database
  155. *
  156. * @param User $user User that modifies
  157. * @param bool $notrigger false=launch triggers after, true=disable triggers
  158. * @return int <0 if KO, >0 if OK
  159. */
  160. public function update(User $user, $notrigger = false)
  161. {
  162. return $this->updateCommon($user, $notrigger);
  163. }
  164. /**
  165. * Delete object in database
  166. *
  167. * @param User $user User that deletes
  168. * @param bool $notrigger false=launch triggers after, true=disable triggers
  169. * @return int <0 if KO, >0 if OK
  170. */
  171. public function delete(User $user, $notrigger = false)
  172. {
  173. return $this->deleteCommon($user, $notrigger);
  174. }
  175. /**
  176. * Return label of the status of a reminder
  177. *
  178. * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto
  179. * @return string Label of status
  180. */
  181. public function getLibStatut($mode = 0)
  182. {
  183. return $this->LibStatut($this->status, $mode);
  184. }
  185. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  186. /**
  187. * Return the status
  188. *
  189. * @param int $status Id status
  190. * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto
  191. * @return string Label of status
  192. */
  193. public static function LibStatut($status, $mode = 0)
  194. {
  195. // phpcs:enable
  196. global $langs;
  197. $labelStatus = $langs->transnoentitiesnoconv('ToDo');
  198. if ($status == 1) {
  199. $labelStatus = $langs->transnoentitiesnoconv('Done');
  200. } elseif ($status == -1) {
  201. $labelStatus = $langs->transnoentitiesnoconv('Error');
  202. }
  203. $labelStatusShort = $langs->transnoentitiesnoconv('ToDo');
  204. if ($status == 1) {
  205. $labelStatus = $langs->transnoentitiesnoconv('Done');
  206. } elseif ($status == -1) {
  207. $labelStatus = $langs->transnoentitiesnoconv('Error');
  208. }
  209. $statusType = 'status5';
  210. if ($status == 1) {
  211. $statusType = 'status4';
  212. } elseif ($status == -1) {
  213. $statusType = 'status8';
  214. }
  215. return dolGetStatus($labelStatus, $labelStatusShort, '', $statusType, $mode);
  216. }
  217. /**
  218. * Initialise object with example values
  219. * Id must be 0 if object instance is a specimen
  220. *
  221. * @return void
  222. */
  223. public function initAsSpecimen()
  224. {
  225. $this->initAsSpecimenCommon();
  226. }
  227. }