dolibarr  17.0.4
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 (!isModEnabled('multicompany') && 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  return $resultcreate;
133  }
134 
142  public function fetch($id, $ref = null)
143  {
144  $result = $this->fetchCommon($id, $ref);
145  return $result;
146  }
147 
159  public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
160  {
161  global $conf;
162 
163  dol_syslog(__METHOD__, LOG_DEBUG);
164 
165  $records = array();
166 
167  $sql = "SELECT ";
168  $sql .= $this->getFieldList('t');
169  $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as t";
170  if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
171  $sql .= " WHERE t.entity IN (".getEntity($this->element).")";
172  } else {
173  $sql .= " WHERE 1 = 1";
174  }
175  // Manage filter
176  $sqlwhere = array();
177  if (count($filter) > 0) {
178  foreach ($filter as $key => $value) {
179  if ($key == 't.rowid') {
180  $sqlwhere[] = $key." = ".((int) $value);
181  } elseif (in_array($this->fields[$key]['type'], array('date', 'datetime', 'timestamp'))) {
182  $sqlwhere[] = $key." = '".$this->db->idate($value)."'";
183  } elseif ($key == 'customsql') {
184  $sqlwhere[] = $value;
185  } elseif (strpos($value, '%') === false) {
186  $sqlwhere[] = $key." IN (".$this->db->sanitize($this->db->escape($value)).")";
187  } else {
188  $sqlwhere[] = $key." LIKE '%".$this->db->escape($value)."%'";
189  }
190  }
191  }
192  if (count($sqlwhere) > 0) {
193  $sql .= " AND (".implode(" ".$filtermode." ", $sqlwhere).")";
194  }
195 
196  if (!empty($sortfield)) {
197  $sql .= $this->db->order($sortfield, $sortorder);
198  }
199  if (!empty($limit)) {
200  $sql .= $this->db->plimit($limit, $offset);
201  }
202 
203  $resql = $this->db->query($sql);
204  if ($resql) {
205  $num = $this->db->num_rows($resql);
206  $i = 0;
207  while ($i < ($limit ? min($limit, $num) : $num)) {
208  $obj = $this->db->fetch_object($resql);
209 
210  $record = new self($this->db);
211  $record->setVarsFromFetchObj($obj);
212 
213  $records[$record->id] = $record;
214 
215  $i++;
216  }
217  $this->db->free($resql);
218 
219  return $records;
220  } else {
221  $this->errors[] = 'Error '.$this->db->lasterror();
222  dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
223 
224  return -1;
225  }
226  }
227 
235  public function update(User $user, $notrigger = false)
236  {
237  return $this->updateCommon($user, $notrigger);
238  }
239 
247  public function delete(User $user, $notrigger = false)
248  {
249  return $this->deleteCommon($user, $notrigger);
250  }
251 
262  public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
263  {
264  global $conf, $langs, $hookmanager;
265 
266  if (!empty($conf->dol_no_mouse_hover)) {
267  $notooltip = 1; // Force disable tooltips
268  }
269 
270  $result = '';
271 
272  $label = img_picto('', $this->picto).' <u>'.$langs->trans("PartnershipType").'</u>';
273  if (isset($this->status)) {
274  $label .= ' '.$this->getLibStatut(5);
275  }
276  $label .= '<br>';
277  $label .= '<b>'.$langs->trans('Code').':</b> '.$this->code;
278  $label .= '<br><b>'.$langs->trans('Label').':</b> '.$this->label;
279 
280  //$url = dol_buildpath('/partnership/partnership_card.php', 1).'?id='.$this->id;
281  $url = '';
282 
283  if ($option != 'nolink') {
284  // Add param to save lastsearch_values or not
285  $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
286  if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
287  $add_save_lastsearch_values = 1;
288  }
289  if ($url && $add_save_lastsearch_values) {
290  $url .= '&save_lastsearch_values=1';
291  }
292  }
293 
294  $linkclose = '';
295  if (empty($notooltip)) {
296  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
297  $label = $langs->trans("ShowMyObject");
298  $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
299  }
300  $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
301  $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
302  } else {
303  $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
304  }
305 
306  if ($option == 'nolink' || empty($url)) {
307  $linkstart = '<span';
308  } else {
309  $linkstart = '<a href="'.$url.'"';
310  }
311  $linkstart .= $linkclose.'>';
312  if ($option == 'nolink' || empty($url)) {
313  $linkend = '</span>';
314  } else {
315  $linkend = '</a>';
316  }
317 
318  $result .= $linkstart;
319 
320  if (empty($this->showphoto_on_popup)) {
321  if ($withpicto) {
322  $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);
323  }
324  } else {
325  if ($withpicto) {
326  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
327 
328  list($class, $module) = explode('@', $this->picto);
329  $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
330  $filearray = dol_dir_list($upload_dir, "files");
331  $filename = $filearray[0]['name'];
332  if (!empty($filename)) {
333  $pospoint = strpos($filearray[0]['name'], '.');
334 
335  $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
336  if (empty($conf->global->{strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS'})) {
337  $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>';
338  } else {
339  $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>';
340  }
341 
342  $result .= '</div>';
343  } else {
344  $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);
345  }
346  }
347  }
348 
349  if ($withpicto != 2) {
350  $result .= $this->ref;
351  }
352 
353  $result .= $linkend;
354  //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
355 
356  global $action, $hookmanager;
357  $hookmanager->initHooks(array('myobjectdao'));
358  $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
359  $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
360  if ($reshook > 0) {
361  $result = $hookmanager->resPrint;
362  } else {
363  $result .= $hookmanager->resPrint;
364  }
365 
366  return $result;
367  }
368 
375  public function info($id)
376  {
377  $sql = "SELECT rowid, date_creation as datec, tms as datem,";
378  $sql .= " fk_user_creat, fk_user_modif";
379  $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as t";
380  $sql .= " WHERE t.rowid = ".((int) $id);
381 
382  $result = $this->db->query($sql);
383  if ($result) {
384  if ($this->db->num_rows($result)) {
385  $obj = $this->db->fetch_object($result);
386  $this->id = $obj->rowid;
387 
388  $this->user_creation_id = $obj->fk_user_creat;
389  $this->user_modification_id = $obj->fk_user_modif;
390  $this->date_creation = $this->db->jdate($obj->datec);
391  $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
392  }
393 
394  $this->db->free($result);
395  } else {
396  dol_print_error($this->db);
397  }
398  }
399 
406  public function initAsSpecimen()
407  {
408  // Set here init that are not commonf fields
409  // $this->property1 = ...
410  // $this->property2 = ...
411 
412  $this->initAsSpecimenCommon();
413  }
414 }
$object ref
Definition: info.php:78
Parent class of all other business classes (invoices, contracts, proposals, orders,...
getFieldList($alias='')
Function to concat keys of fields.
fetchCommon($id, $ref=null, $morewhere='')
Load object in memory from the database.
createCommon(User $user, $notrigger=false)
Create object into database.
deleteCommon(User $user, $notrigger=false, $forcechilddeletion=0)
Delete object in database.
updateCommon(User $user, $notrigger=false)
Update object into database.
Class to manage Dolibarr database access.
Class to manage partnership type.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
__construct(DoliDB $db)
Constructor.
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionaly the picto)
fetch($id, $ref=null)
Load object in memory from the database.
update(User $user, $notrigger=false)
Update object into database.
info($id)
Load the info information in the object.
create(User $user, $notrigger=false)
Create object into database.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter=array(), $filtermode='AND')
Load list of objects in memory from the database.
Class to manage Dolibarr users.
Definition: user.class.php:47
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("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->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:745
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition: files.lib.php:61
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
$conf db
API class for accounts.
Definition: inc.php:41