dolibarr  16.0.5
partnership_type.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2002 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2008 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2009-2017 Regis Houssin <regis.houssin@inodbox.com>
5  * Copyright (C) 2016 Charlie Benke <charlie@patas-monkey.com>
6  * Copyright (C) 2018-2019 Thibault Foucart <support@ptibogxiv.net>
7  * Copyright (C) 2021 WaĆ«l Almoman <info@almoman.com>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <https://www.gnu.org/licenses/>.
21  */
22 
29 require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
30 
31 
36 {
40  public $table_element = 'c_partnership_type';
41 
45  public $element = 'partnership_type';
46 
50  public $picto = 'generic';
51 
56  public $ismultientitymanaged = 1;
57 
61  public $code;
62 
66  public $label;
67 
68 
69  public $fields=array(
70  'rowid' =>array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>10),
71  'entity' =>array('type'=>'integer', 'label'=>'Entity', 'default'=>1, 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>15, 'index'=>1),
72  'code' =>array('type'=>'varchar(32)', 'label'=>'Code', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>20),
73  'label' =>array('type'=>'varchar(64)', 'label'=>'Label', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>25, 'showoncombobox'=>1),
74  'active' =>array('type'=>'integer', 'label'=>'Active', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>30),
75  );
76 
77 
78 
84  public function __construct(DoliDB $db)
85  {
86  global $conf, $langs;
87 
88  $this->db = $db;
89 
90  if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields['rowid'])) {
91  $this->fields['rowid']['visible'] = 0;
92  }
93  if (empty($conf->multicompany->enabled) && isset($this->fields['entity'])) {
94  $this->fields['entity']['enabled'] = 0;
95  }
96 
97  // Example to show how to set values of fields definition dynamically
98  /*if ($user->rights->mymodule->myobject->read) {
99  $this->fields['myfield']['visible'] = 1;
100  $this->fields['myfield']['noteditable'] = 0;
101  }*/
102 
103  // Unset fields that are disabled
104  foreach ($this->fields as $key => $val) {
105  if (isset($val['enabled']) && empty($val['enabled'])) {
106  unset($this->fields[$key]);
107  }
108  }
109 
110  // Translate some data of arrayofkeyval
111  if (is_object($langs)) {
112  foreach ($this->fields as $key => $val) {
113  if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
114  foreach ($val['arrayofkeyval'] as $key2 => $val2) {
115  $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
116  }
117  }
118  }
119  }
120  }
121 
129  public function create(User $user, $notrigger = false)
130  {
131  $resultcreate = $this->createCommon($user, $notrigger);
132 
133  //$resultvalidate = $this->validate($user, $notrigger);
134 
135  return $resultcreate;
136  }
137 
145  public function fetch($id, $ref = null)
146  {
147  $result = $this->fetchCommon($id, $ref);
148  if ($result > 0 && !empty($this->table_element_line)) {
149  $this->fetchLines();
150  }
151  return $result;
152  }
153 
165  public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
166  {
167  global $conf;
168 
169  dol_syslog(__METHOD__, LOG_DEBUG);
170 
171  $records = array();
172 
173  $sql = "SELECT ";
174  $sql .= $this->getFieldList('t');
175  $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as t";
176  if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
177  $sql .= " WHERE t.entity IN (".getEntity($this->table_element).")";
178  } else {
179  $sql .= " WHERE 1 = 1";
180  }
181  // Manage filter
182  $sqlwhere = array();
183  if (count($filter) > 0) {
184  foreach ($filter as $key => $value) {
185  if ($key == 't.rowid') {
186  $sqlwhere[] = $key." = ".((int) $value);
187  } elseif (in_array($this->fields[$key]['type'], array('date', 'datetime', 'timestamp'))) {
188  $sqlwhere[] = $key." = '".$this->db->idate($value)."'";
189  } elseif ($key == 'customsql') {
190  $sqlwhere[] = $value;
191  } elseif (strpos($value, '%') === false) {
192  $sqlwhere[] = $key." IN (".$this->db->sanitize($this->db->escape($value)).")";
193  } else {
194  $sqlwhere[] = $key." LIKE '%".$this->db->escape($value)."%'";
195  }
196  }
197  }
198  if (count($sqlwhere) > 0) {
199  $sql .= " AND (".implode(" ".$filtermode." ", $sqlwhere).")";
200  }
201 
202  if (!empty($sortfield)) {
203  $sql .= $this->db->order($sortfield, $sortorder);
204  }
205  if (!empty($limit)) {
206  $sql .= $this->db->plimit($limit, $offset);
207  }
208 
209  $resql = $this->db->query($sql);
210  if ($resql) {
211  $num = $this->db->num_rows($resql);
212  $i = 0;
213  while ($i < ($limit ? min($limit, $num) : $num)) {
214  $obj = $this->db->fetch_object($resql);
215 
216  $record = new self($this->db);
217  $record->setVarsFromFetchObj($obj);
218 
219  $records[$record->id] = $record;
220 
221  $i++;
222  }
223  $this->db->free($resql);
224 
225  return $records;
226  } else {
227  $this->errors[] = 'Error '.$this->db->lasterror();
228  dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
229 
230  return -1;
231  }
232  }
233 
241  public function update(User $user, $notrigger = false)
242  {
243  return $this->updateCommon($user, $notrigger);
244  }
245 
253  public function delete(User $user, $notrigger = false)
254  {
255  return $this->deleteCommon($user, $notrigger);
256  //return $this->deleteCommon($user, $notrigger, 1);
257  }
258 
266  public function setDraft($user, $notrigger = 0)
267  {
268  // Protection
269  if ($this->status <= self::STATUS_DRAFT) {
270  return 0;
271  }
272 
273  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->mymodule->write))
274  || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->mymodule->mymodule_advance->validate))))
275  {
276  $this->error='Permission denied';
277  return -1;
278  }*/
279 
280  return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'PARTNERSHIPTYPE_UNVALIDATE');
281  }
282 
290  public function cancel($user, $notrigger = 0)
291  {
292  // Protection
293  if ($this->status != self::STATUS_VALIDATED) {
294  return 0;
295  }
296 
297  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->mymodule->write))
298  || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->mymodule->mymodule_advance->validate))))
299  {
300  $this->error='Permission denied';
301  return -1;
302  }*/
303 
304  return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'PARTNERSHIPTYPE_CANCEL');
305  }
306 
314  public function reopen($user, $notrigger = 0)
315  {
316  // Protection
317  if ($this->status != self::STATUS_CANCELED) {
318  return 0;
319  }
320 
321  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->mymodule->write))
322  || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->mymodule->mymodule_advance->validate))))
323  {
324  $this->error='Permission denied';
325  return -1;
326  }*/
327 
328  return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'PARTNERSHIPTYPE_REOPEN');
329  }
330 
341  public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
342  {
343  global $conf, $langs, $hookmanager;
344 
345  if (!empty($conf->dol_no_mouse_hover)) {
346  $notooltip = 1; // Force disable tooltips
347  }
348 
349  $result = '';
350 
351  $label = img_picto('', $this->picto).' <u>'.$langs->trans("PartnershipType").'</u>';
352  if (isset($this->status)) {
353  $label .= ' '.$this->getLibStatut(5);
354  }
355  $label .= '<br>';
356  $label .= '<b>'.$langs->trans('Code').':</b> '.$this->code;
357  $label .= '<br><b>'.$langs->trans('Label').':</b> '.$this->label;
358 
359  //$url = dol_buildpath('/partnership/partnership_card.php', 1).'?id='.$this->id;
360  $url = '';
361 
362  if ($option != 'nolink') {
363  // Add param to save lastsearch_values or not
364  $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
365  if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
366  $add_save_lastsearch_values = 1;
367  }
368  if ($url && $add_save_lastsearch_values) {
369  $url .= '&save_lastsearch_values=1';
370  }
371  }
372 
373  $linkclose = '';
374  if (empty($notooltip)) {
375  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
376  $label = $langs->trans("ShowMyObject");
377  $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
378  }
379  $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
380  $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
381  } else {
382  $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
383  }
384 
385  if ($option == 'nolink' || empty($url)) {
386  $linkstart = '<span';
387  } else {
388  $linkstart = '<a href="'.$url.'"';
389  }
390  $linkstart .= $linkclose.'>';
391  if ($option == 'nolink' || empty($url)) {
392  $linkend = '</span>';
393  } else {
394  $linkend = '</a>';
395  }
396 
397  $result .= $linkstart;
398 
399  if (empty($this->showphoto_on_popup)) {
400  if ($withpicto) {
401  $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
402  }
403  } else {
404  if ($withpicto) {
405  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
406 
407  list($class, $module) = explode('@', $this->picto);
408  $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
409  $filearray = dol_dir_list($upload_dir, "files");
410  $filename = $filearray[0]['name'];
411  if (!empty($filename)) {
412  $pospoint = strpos($filearray[0]['name'], '.');
413 
414  $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
415  if (empty($conf->global->{strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS'})) {
416  $result .= '<div class="floatleft inline-block valignmiddle divphotoref"><div class="photoref"><img class="photo'.$module.'" alt="No photo" border="0" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$module.'&entity='.$conf->entity.'&file='.urlencode($pathtophoto).'"></div></div>';
417  } else {
418  $result .= '<div class="floatleft inline-block valignmiddle divphotoref"><img class="photouserphoto userphoto" alt="No photo" border="0" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$module.'&entity='.$conf->entity.'&file='.urlencode($pathtophoto).'"></div>';
419  }
420 
421  $result .= '</div>';
422  } else {
423  $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
424  }
425  }
426  }
427 
428  if ($withpicto != 2) {
429  $result .= $this->ref;
430  }
431 
432  $result .= $linkend;
433  //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
434 
435  global $action, $hookmanager;
436  $hookmanager->initHooks(array('myobjectdao'));
437  $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
438  $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
439  if ($reshook > 0) {
440  $result = $hookmanager->resPrint;
441  } else {
442  $result .= $hookmanager->resPrint;
443  }
444 
445  return $result;
446  }
447 
454  public function getLabelStatus($mode = 0)
455  {
456  return $this->LibStatut($this->status, $mode);
457  }
458 
465  public function getLibStatut($mode = 0)
466  {
467  return $this->LibStatut($this->status, $mode);
468  }
469 
470  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
478  public function LibStatut($status, $mode = 0)
479  {
480  // phpcs:enable
481  if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
482  global $langs;
483  //$langs->load("mymodule@mymodule");
484  $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
485  $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
486  $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
487  $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
488  $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
489  $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
490  }
491 
492  $statusType = 'status'.$status;
493  //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
494  if ($status == self::STATUS_CANCELED) {
495  $statusType = 'status6';
496  }
497 
498  return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
499  }
500 
507  public function info($id)
508  {
509  $sql = "SELECT rowid, date_creation as datec, tms as datem,";
510  $sql .= " fk_user_creat, fk_user_modif";
511  $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as t";
512  $sql .= " WHERE t.rowid = ".((int) $id);
513 
514  $result = $this->db->query($sql);
515  if ($result) {
516  if ($this->db->num_rows($result)) {
517  $obj = $this->db->fetch_object($result);
518  $this->id = $obj->rowid;
519 
520  $this->user_creation_id = $obj->fk_user_creat;
521  $this->user_modification_id = $obj->fk_user_modif;
522  $this->date_creation = $this->db->jdate($obj->datec);
523  $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
524  }
525 
526  $this->db->free($result);
527  } else {
528  dol_print_error($this->db);
529  }
530  }
531 
538  public function initAsSpecimen()
539  {
540  // Set here init that are not commonf fields
541  // $this->property1 = ...
542  // $this->property2 = ...
543 
544  $this->initAsSpecimenCommon();
545  }
546 }
CommonObject\deleteCommon
deleteCommon(User $user, $notrigger=false, $forcechilddeletion=0)
Delete object in database.
Definition: commonobject.class.php:9406
CommonObject\setStatusCommon
setStatusCommon($user, $status, $notrigger=0, $triggercode='')
Set to a status.
Definition: commonobject.class.php:9683
db
$conf db
API class for accounts.
Definition: inc.php:41
PartnershipType\create
create(User $user, $notrigger=false)
Create object into database.
Definition: partnership_type.class.php:129
CommonObject\fetchCommon
fetchCommon($id, $ref=null, $morewhere='')
Load object in memory from the database.
Definition: commonobject.class.php:9202
PartnershipType\cancel
cancel($user, $notrigger=0)
Set cancel status.
Definition: partnership_type.class.php:290
dol_sanitizeFileName
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
Definition: functions.lib.php:1226
DoliDB
Class to manage Dolibarr database access.
Definition: DoliDB.class.php:30
PartnershipType\info
info($id)
Load the info information in the object.
Definition: partnership_type.class.php:507
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
PartnershipType\__construct
__construct(DoliDB $db)
Constructor.
Definition: partnership_type.class.php:84
ref
$object ref
Definition: info.php:77
PartnershipType\getLabelStatus
getLabelStatus($mode=0)
Return the label of the status.
Definition: partnership_type.class.php:454
PartnershipType\fetch
fetch($id, $ref=null)
Load object in memory from the database.
Definition: partnership_type.class.php:145
dol_dir_list
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0)
Scan a directory and return a list of files/directories.
Definition: files.lib.php:60
CommonObject
Parent class of all other business classes (invoices, contracts, proposals, orders,...
Definition: commonobject.class.php:44
PartnershipType\LibStatut
LibStatut($status, $mode=0)
Return the status.
Definition: partnership_type.class.php:478
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:3880
CommonObject\createCommon
createCommon(User $user, $notrigger=false)
Create object into database.
Definition: commonobject.class.php:9035
PartnershipType\update
update(User $user, $notrigger=false)
Update object into database.
Definition: partnership_type.class.php:241
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1603
CommonObject\updateCommon
updateCommon(User $user, $notrigger=false)
Update object into database.
Definition: commonobject.class.php:9308
PartnershipType\initAsSpecimen
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
Definition: partnership_type.class.php:538
PartnershipType\getLibStatut
getLibStatut($mode=0)
Return the label of the status.
Definition: partnership_type.class.php:465
User
Class to manage Dolibarr users.
Definition: user.class.php:44
dolGetStatus
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
Definition: functions.lib.php:10338
img_object
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
Definition: functions.lib.php:4211
PartnershipType\setDraft
setDraft($user, $notrigger=0)
Set draft status.
Definition: partnership_type.class.php:266
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->supplier_invoice->lire)) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
PartnershipType\fetchAll
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter=array(), $filtermode='AND')
Load list of objects in memory from the database.
Definition: partnership_type.class.php:165
PartnershipType\getNomUrl
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionaly the picto)
Definition: partnership_type.class.php:341
CommonObject\getFieldList
getFieldList($alias='')
Function to concat keys of fields.
Definition: commonobject.class.php:8987
PartnershipType
Class to manage partnership type.
Definition: partnership_type.class.php:35
PartnershipType\reopen
reopen($user, $notrigger=0)
Set back to validated status.
Definition: partnership_type.class.php:314