dolibarr 19.0.4
emailsenderprofile.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2007-2017 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2014-2016 Juanjo Menent <jmenent@2byte.es>
4 * Copyright (C) 2015 Florian Henry <florian.henry@open-concept.pro>
5 * Copyright (C) 2015 Raphaƫl Doursenaud <rdoursenaud@gpcsolutions.fr>
6 * Copyright (C) ---Put here your own copyright and developer email---
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
28// Put here all includes required by your class file
29require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
30//require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
31//require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
32
33
38{
42 public $element = 'emailsenderprofile';
43
47 public $table_element = 'c_email_senderprofile';
48
52 public $ismultientitymanaged = 1;
53
57 public $picto = 'emailsenderprofile';
58
59 public $fk_user_creat;
60
61
62 const STATUS_DISABLED = 0;
63 const STATUS_ENABLED = 1;
64
65
66
91 // BEGIN MODULEBUILDER PROPERTIES
95 public $fields = array(
96 'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'visible'=>-1, 'enabled'=>1, 'position'=>1, 'notnull'=>1, 'index'=>1, 'comment'=>'Id',),
97 'entity' => array('type'=>'integer', 'label'=>'Entity', 'visible'=>-1, 'enabled'=>1, 'position'=>20, 'notnull'=>1, 'index'=>1,),
98 'label' => array('type'=>'varchar(255)', 'label'=>'Label', 'visible'=>1, 'enabled'=>1, 'position'=>30, 'notnull'=>1),
99 'email' => array('type'=>'varchar(255)', 'label'=>'Email', 'visible'=>1, 'enabled'=>1, 'position'=>40, 'notnull'=>-1),
100 'private' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'User', 'visible'=>1, 'enabled'=>1, 'position'=>50, 'default'=>'0', 'notnull'=>1),
101 'signature' => array('type'=>'html', 'label'=>'Signature', 'visible'=>3, 'enabled'=>1, 'position'=>400, 'notnull'=>-1, 'index'=>1,),
102 'position' => array('type'=>'integer', 'label'=>'Position', 'visible'=>1, 'enabled'=>1, 'position'=>405, 'notnull'=>-1, 'index'=>1,),
103 'date_creation' => array('type'=>'datetime', 'label'=>'DateCreation', 'visible'=>-1, 'enabled'=>1, 'position'=>500, 'notnull'=>1,),
104 'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'visible'=>-1, 'enabled'=>1, 'position'=>500, 'notnull'=>1,),
105 'active' => array('type'=>'integer', 'label'=>'Status', 'visible'=>1, 'enabled'=>1, 'default'=>1, 'position'=>1000, 'notnull'=>1, 'index'=>1, 'arrayofkeyval'=>array(0=>'Disabled', 1=>'Enabled')),
106 );
107
111 public $rowid;
112
116 public $entity;
117
121 public $label;
122
123 public $email;
124
128 public $date_creation;
129
130 public $tms;
131 public $private;
132 public $signature;
133 public $position;
134 public $active;
135 // END MODULEBUILDER PROPERTIES
136
137
143 public function __construct(DoliDB $db)
144 {
145 global $conf;
146
147 $this->db = $db;
148
149 if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID')) {
150 $this->fields['rowid']['visible'] = 0;
151 }
152 if (!isModEnabled('multicompany')) {
153 $this->fields['entity']['enabled'] = 0;
154 }
155 }
156
164 public function create(User $user, $notrigger = false)
165 {
166 return $this->createCommon($user, $notrigger);
167 }
168
176 public function createFromClone(User $user, $fromid)
177 {
178 global $hookmanager, $langs;
179 $error = 0;
180
181 dol_syslog(__METHOD__, LOG_DEBUG);
182
183 $object = new self($this->db);
184
185 $this->db->begin();
186
187 // Load source object
188 $object->fetchCommon($fromid);
189 // Reset some properties
190 unset($object->id);
191 unset($object->fk_user_creat);
192 unset($object->import_key);
193
194 // Clear fields
195 $object->ref = "copy_of_".$object->ref;
196 $object->title = $langs->trans("CopyOf")." ".$object->title;
197 // ...
198
199 // Create clone
200 $object->context['createfromclone'] = 'createfromclone';
201 $result = $object->createCommon($user);
202 if ($result < 0) {
203 $error++;
204 $this->error = $object->error;
205 $this->errors = $object->errors;
206 }
207
208 unset($object->context['createfromclone']);
209
210 // End
211 if (!$error) {
212 $this->db->commit();
213 return $object;
214 } else {
215 $this->db->rollback();
216 return -1;
217 }
218 }
219
227 public function fetch($id, $ref = null)
228 {
229 $result = $this->fetchCommon($id, $ref);
230 if ($result > 0 && !empty($this->table_element_line)) {
231 $this->fetchLines();
232 }
233 return $result;
234 }
235
241 public function fetchLines()
242 {
243 $this->lines = array();
244
245 // Load lines with object EmailSenderProfileLine
246
247 return count($this->lines) ? 1 : 0;
248 }
249
257 public function update(User $user, $notrigger = false)
258 {
259 return $this->updateCommon($user, $notrigger);
260 }
261
269 public function delete(User $user, $notrigger = false)
270 {
271 return $this->deleteCommon($user, $notrigger);
272 }
273
280 public function getNomUrl($withpicto = 0)
281 {
282 global $db, $conf, $langs;
283 global $dolibarr_main_authentication, $dolibarr_main_demo;
284 global $menumanager;
285
286 $result = '';
287 $companylink = '';
288
289 $label = $this->label;
290
291 $url = '';
292 //$url = dol_buildpath('/monmodule/emailsenderprofile_card.php',1).'?id='.$this->id;
293
294 $linkstart = '';
295 $linkend = '';
296
297 if ($withpicto) {
298 $result .= ($linkstart.img_object($label, 'label', 'class="classfortooltip"').$linkend);
299 if ($withpicto != 2) {
300 $result .= ' ';
301 }
302 }
303 $result .= $linkstart.$this->label.$linkend;
304 return $result;
305 }
306
313 public function getLibStatut($mode = 0)
314 {
315 return $this->LibStatut($this->active, $mode);
316 }
317
318 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
326 public static function LibStatut($status, $mode = 0)
327 {
328 global $langs;
329
330 if ($status == 1) {
331 $label = $labelshort = $langs->transnoentitiesnoconv('Enabled');
332 } else {
333 $label = $labelshort = $langs->transnoentitiesnoconv('Disabled');
334 }
335
336 $statusType = 'status'.$status;
337 if ($status == self::STATUS_ENABLED) {
338 $statusType = 'status4';
339 }
340
341 return dolGetStatus($label, $labelshort, '', $statusType, $mode);
342 }
343
350 public function info($id)
351 {
352 $sql = "SELECT rowid, date_creation as datec, tms as datem";
353 $sql .= " FROM ".$this->db->prefix().$this->table_element." as t";
354 $sql .= " WHERE t.rowid = ".((int) $id);
355 $result = $this->db->query($sql);
356 if ($result) {
357 if ($this->db->num_rows($result)) {
358 $obj = $this->db->fetch_object($result);
359 $this->id = $obj->rowid;
360
361 $this->date_creation = $this->db->jdate($obj->datec);
362 $this->date_modification = $this->db->jdate($obj->datem);
363 }
364
365 $this->db->free($result);
366 } else {
367 dol_print_error($this->db);
368 }
369 }
370
377 public function initAsSpecimen()
378 {
379 $this->initAsSpecimenCommon();
380 }
381}
382
386/*
387class EmailSenderProfileLine
388{
389 // @var int ID
390 public $id;
391 // @var mixed Sample line property 1
392 public $prop1;
393 // @var mixed Sample line property 2
394 public $prop2;
395}
396*/
Parent class of all other business classes (invoices, contracts, proposals, orders,...
createCommon(User $user, $notrigger=false)
Create object into database.
deleteCommon(User $user, $notrigger=false, $forcechilddeletion=0)
Delete object in database.
initAsSpecimenCommon()
Initialise object with example values Id must be 0 if object instance is a specimen.
updateCommon(User $user, $notrigger=false)
Update object into database.
fetchCommon($id, $ref=null, $morewhere='', $noextrafields=0)
Load object in memory from the database.
Class to manage Dolibarr database access.
Class for EmailSenderProfile.
fetchLines()
Load object lines in memory from the database.
update(User $user, $notrigger=false)
Update object into database.
getLibStatut($mode=0)
Return the label of a given status.
getNomUrl($withpicto=0)
Return a link to the object card (with optionaly the picto)
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
fetch($id, $ref=null)
Load object in memory from the database.
info($id)
Charge les informations d'ordre info dans l'objet commande.
static LibStatut($status, $mode=0)
Return the label of a given status.
createFromClone(User $user, $fromid)
Clone and object into another one.
__construct(DoliDB $db)
Constructor.
create(User $user, $notrigger=false)
Create object into database.
Class to manage Dolibarr users.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.