actioncommreminder.class.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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. /**
  91. * @var string reminder type email, browser, sms
  92. */
  93. public $typeremind;
  94. /**
  95. * @var int User ID
  96. */
  97. public $fk_user;
  98. /**
  99. * @var int offset value
  100. */
  101. public $offsetvalue;
  102. /**
  103. * @var string y, m, d, w, h, i
  104. */
  105. public $offsetunit;
  106. /**
  107. * @var int Status
  108. */
  109. public $status;
  110. /**
  111. * @var string Last error message
  112. */
  113. public $lasterror;
  114. /**
  115. * @var int Project
  116. */
  117. public $fk_actioncomm;
  118. /**
  119. * @var int Template Mail
  120. */
  121. public $fk_email_template;
  122. // END MODULEBUILDER PROPERTIES
  123. /**
  124. * Constructor
  125. *
  126. * @param DoliDb $db Database handler
  127. */
  128. public function __construct(DoliDB $db)
  129. {
  130. global $conf;
  131. $this->db = $db;
  132. if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID')) {
  133. $this->fields['rowid']['visible'] = 0;
  134. }
  135. if (!isModEnabled('multicompany')) {
  136. $this->fields['entity']['enabled'] = 0;
  137. }
  138. }
  139. /**
  140. * Create object into database
  141. *
  142. * @param User $user User that creates
  143. * @param bool $notrigger false=launch triggers after, true=disable triggers
  144. * @return int Return integer <0 if KO, Id of created object if OK
  145. */
  146. public function create(User $user, $notrigger = false)
  147. {
  148. return $this->createCommon($user, $notrigger);
  149. }
  150. /**
  151. * Load object in memory from the database
  152. *
  153. * @param int $id Id object
  154. * @param string $ref Ref
  155. * @return int Return integer <0 if KO, 0 if not found, >0 if OK
  156. */
  157. public function fetch($id, $ref = null)
  158. {
  159. $result = $this->fetchCommon($id, $ref);
  160. return $result;
  161. }
  162. /**
  163. * Update object into database
  164. *
  165. * @param User $user User that modifies
  166. * @param bool $notrigger false=launch triggers after, true=disable triggers
  167. * @return int Return integer <0 if KO, >0 if OK
  168. */
  169. public function update(User $user, $notrigger = false)
  170. {
  171. return $this->updateCommon($user, $notrigger);
  172. }
  173. /**
  174. * Delete object in database
  175. *
  176. * @param User $user User that deletes
  177. * @param bool $notrigger false=launch triggers after, true=disable triggers
  178. * @return int Return integer <0 if KO, >0 if OK
  179. */
  180. public function delete(User $user, $notrigger = false)
  181. {
  182. return $this->deleteCommon($user, $notrigger);
  183. }
  184. /**
  185. * Return label of the status of a reminder
  186. *
  187. * @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
  188. * @return string Label of status
  189. */
  190. public function getLibStatut($mode = 0)
  191. {
  192. return $this->LibStatut($this->status, $mode);
  193. }
  194. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  195. /**
  196. * Return the status
  197. *
  198. * @param int $status Id status
  199. * @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
  200. * @return string Label of status
  201. */
  202. public static function LibStatut($status, $mode = 0)
  203. {
  204. // phpcs:enable
  205. global $langs;
  206. $labelStatus = $langs->transnoentitiesnoconv('ToDo');
  207. if ($status == 1) {
  208. $labelStatus = $langs->transnoentitiesnoconv('Done');
  209. } elseif ($status == -1) {
  210. $labelStatus = $langs->transnoentitiesnoconv('Error');
  211. }
  212. $labelStatusShort = $langs->transnoentitiesnoconv('ToDo');
  213. if ($status == 1) {
  214. $labelStatus = $langs->transnoentitiesnoconv('Done');
  215. } elseif ($status == -1) {
  216. $labelStatus = $langs->transnoentitiesnoconv('Error');
  217. }
  218. $statusType = 'status5';
  219. if ($status == 1) {
  220. $statusType = 'status4';
  221. } elseif ($status == -1) {
  222. $statusType = 'status8';
  223. }
  224. return dolGetStatus($labelStatus, $labelStatusShort, '', $statusType, $mode);
  225. }
  226. /**
  227. * Initialise object with example values
  228. * Id must be 0 if object instance is a specimen
  229. *
  230. * @return void
  231. */
  232. public function initAsSpecimen()
  233. {
  234. $this->initAsSpecimenCommon();
  235. }
  236. }