dolibarr  13.0.2
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
29 require_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@monmodule';
58 
59 
60  const STATUS_DISABLED = 0;
61  const STATUS_ENABLED = 1;
62 
63 
64 
89  // BEGIN MODULEBUILDER PROPERTIES
93  public $fields = array(
94  'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'visible'=>-1, 'enabled'=>1, 'position'=>1, 'notnull'=>1, 'index'=>1, 'comment'=>'Id',),
95  'entity' => array('type'=>'integer', 'label'=>'Entity', 'visible'=>-1, 'enabled'=>1, 'position'=>20, 'notnull'=>1, 'index'=>1,),
96  'label' => array('type'=>'varchar(255)', 'label'=>'Label', 'visible'=>1, 'enabled'=>1, 'position'=>30, 'notnull'=>1),
97  'email' => array('type'=>'varchar(255)', 'label'=>'Email', 'visible'=>1, 'enabled'=>1, 'position'=>40, 'notnull'=>-1),
98  'private' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'User', 'visible'=>-1, 'enabled'=>1, 'position'=>50, 'default'=>'0', 'notnull'=>1),
99  'signature' => array('type'=>'text', 'label'=>'Signature', 'visible'=>3, 'enabled'=>1, 'position'=>400, 'notnull'=>-1, 'index'=>1,),
100  'position' => array('type'=>'integer', 'label'=>'Position', 'visible'=>1, 'enabled'=>1, 'position'=>405, 'notnull'=>-1, 'index'=>1,),
101  'date_creation' => array('type'=>'datetime', 'label'=>'DateCreation', 'visible'=>-1, 'enabled'=>1, 'position'=>500, 'notnull'=>1,),
102  'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'visible'=>-1, 'enabled'=>1, 'position'=>500, 'notnull'=>1,),
103  'active' => array('type'=>'integer', 'label'=>'Status', 'visible'=>1, 'enabled'=>1, 'default'=>1, 'position'=>1000, 'notnull'=>1, 'index'=>1, 'arrayofkeyval'=>array(0=>'Disabled', 1=>'Enabled')),
104  );
105 
109  public $rowid;
110 
114  public $entity;
115 
119  public $label;
120 
121  public $email;
122 
126  public $date_creation;
127 
128  public $tms;
129  public $private;
130  public $signature;
131  public $position;
132  public $active;
133  // END MODULEBUILDER PROPERTIES
134 
135 
141  public function __construct(DoliDB $db)
142  {
143  global $conf;
144 
145  $this->db = $db;
146 
147  if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID)) $this->fields['rowid']['visible'] = 0;
148  if (empty($conf->multicompany->enabled)) $this->fields['entity']['enabled'] = 0;
149  }
150 
158  public function create(User $user, $notrigger = false)
159  {
160  return $this->createCommon($user, $notrigger);
161  }
162 
170  public function createFromClone(User $user, $fromid)
171  {
172  global $hookmanager, $langs;
173  $error = 0;
174 
175  dol_syslog(__METHOD__, LOG_DEBUG);
176 
177  $object = new self($this->db);
178 
179  $this->db->begin();
180 
181  // Load source object
182  $object->fetchCommon($fromid);
183  // Reset some properties
184  unset($object->id);
185  unset($object->fk_user_creat);
186  unset($object->import_key);
187 
188  // Clear fields
189  $object->ref = "copy_of_".$object->ref;
190  $object->title = $langs->trans("CopyOf")." ".$object->title;
191  // ...
192 
193  // Create clone
194  $object->context['createfromclone'] = 'createfromclone';
195  $result = $object->createCommon($user);
196  if ($result < 0) {
197  $error++;
198  $this->error = $object->error;
199  $this->errors = $object->errors;
200  }
201 
202  unset($object->context['createfromclone']);
203 
204  // End
205  if (!$error) {
206  $this->db->commit();
207  return $object;
208  } else {
209  $this->db->rollback();
210  return -1;
211  }
212  }
213 
221  public function fetch($id, $ref = null)
222  {
223  $result = $this->fetchCommon($id, $ref);
224  if ($result > 0 && !empty($this->table_element_line)) $this->fetchLines();
225  return $result;
226  }
227 
233  public function fetchLines()
234  {
235  $this->lines = array();
236 
237  // Load lines with object EmailSenderProfileLine
238 
239  return count($this->lines) ? 1 : 0;
240  }
241 
249  public function update(User $user, $notrigger = false)
250  {
251  return $this->updateCommon($user, $notrigger);
252  }
253 
261  public function delete(User $user, $notrigger = false)
262  {
263  return $this->deleteCommon($user, $notrigger);
264  }
265 
272  public function getNomUrl($withpicto = 0)
273  {
274  global $db, $conf, $langs;
275  global $dolibarr_main_authentication, $dolibarr_main_demo;
276  global $menumanager;
277 
278  $result = '';
279  $companylink = '';
280 
281  $label = $this->label;
282 
283  $url = '';
284  //$url = dol_buildpath('/monmodule/emailsenderprofile_card.php',1).'?id='.$this->id;
285 
286  $linkstart = '';
287  $linkend = '';
288 
289  if ($withpicto) {
290  $result .= ($linkstart.img_object($label, 'label', 'class="classfortooltip"').$linkend);
291  if ($withpicto != 2) $result .= ' ';
292  }
293  $result .= $linkstart.$this->label.$linkend;
294  return $result;
295  }
296 
303  public function getLibStatut($mode = 0)
304  {
305  return $this->LibStatut($this->active, $mode);
306  }
307 
308  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
316  public static function LibStatut($status, $mode = 0)
317  {
318  global $langs;
319 
320  if ($status == 1) {
321  $label = $labelshort = $langs->trans('Enabled');
322  } else {
323  $label = $labelshort = $langs->trans('Disabled');
324  }
325 
326  $statusType = 'status'.$status;
327  if ($status == self::STATUS_ENABLED) $statusType = 'status4';
328 
329  return dolGetStatus($label, $labelshort, '', $statusType, $mode);
330  }
331 
338  public function info($id)
339  {
340  $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
341  $sql .= ' fk_user_creat, fk_user_modif';
342  $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
343  $sql .= ' WHERE t.rowid = '.$id;
344  $result = $this->db->query($sql);
345  if ($result)
346  {
347  if ($this->db->num_rows($result))
348  {
349  $obj = $this->db->fetch_object($result);
350  $this->id = $obj->rowid;
351  if ($obj->fk_user_author)
352  {
353  $cuser = new User($this->db);
354  $cuser->fetch($obj->fk_user_author);
355  $this->user_creation = $cuser;
356  }
357 
358  if ($obj->fk_user_valid)
359  {
360  $vuser = new User($this->db);
361  $vuser->fetch($obj->fk_user_valid);
362  $this->user_validation = $vuser;
363  }
364 
365  if ($obj->fk_user_cloture)
366  {
367  $cluser = new User($this->db);
368  $cluser->fetch($obj->fk_user_cloture);
369  $this->user_cloture = $cluser;
370  }
371 
372  $this->date_creation = $this->db->jdate($obj->datec);
373  $this->date_modification = $this->db->jdate($obj->datem);
374  $this->date_validation = $this->db->jdate($obj->datev);
375  }
376 
377  $this->db->free($result);
378  } else {
379  dol_print_error($this->db);
380  }
381  }
382 
389  public function initAsSpecimen()
390  {
391  $this->initAsSpecimenCommon();
392  }
393 }
394 
398 /*
399 class EmailSenderProfileLine
400 {
401  // @var int ID
402  public $id;
403  // @var mixed Sample line property 1
404  public $prop1;
405  // @var mixed Sample line property 2
406  public $prop2;
407 }
408 */
deleteCommon(User $user, $notrigger=false, $forcechilddeletion=0)
Delete object in database.
fetch($id, $ref=null)
Load object in memory from the database.
foreach($object->fields as $key=> $val) if(is_array($extrafields->attributes[$object->table_element]['label'])&&count($extrafields->attributes[$object->table_element]['label']) > 0) $object fields
getNomUrl($withpicto=0)
Return a link to the object card (with optionaly the picto)
create(User $user, $notrigger=false)
Create object into database.
Class to manage Dolibarr users.
Definition: user.class.php:44
Class to manage Dolibarr database access.
initAsSpecimenCommon()
Initialise object with example values Id must be 0 if object instance is a specimen.
createCommon(User $user, $notrigger=false)
Create object into database.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
$conf db
API class for accounts.
Definition: inc.php:54
fetchLines()
Load object lines in memory from the database.
__construct(DoliDB $db)
Constructor.
update(User $user, $notrigger=false)
Update object into database.
static LibStatut($status, $mode=0)
Return the status.
getLibStatut($mode=0)
Retourne le libelle du status d&#39;un user (actif, inactif)
info($id)
Charge les informations d&#39;ordre info dans l&#39;objet commande.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
updateCommon(User $user, $notrigger=false)
Update object into database.
createFromClone(User $user, $fromid)
Clone and object into another one.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dolGetStatus($statusLabel= '', $statusLabelShort= '', $html= '', $statusType= 'status0', $displayMode=0, $url= '', $params=array())
Output the badge of a status.
Class for EmailSenderProfile.
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)
fetchCommon($id, $ref=null, $morewhere= '')
Load object in memory from the database.