dolibarr 18.0.6
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
29require_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 public $active;
69
70
71 public $fields=array(
72 'rowid' =>array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>10),
73 'entity' =>array('type'=>'integer', 'label'=>'Entity', 'default'=>1, 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>15, 'index'=>1),
74 'code' =>array('type'=>'varchar(32)', 'label'=>'Code', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>20),
75 'label' =>array('type'=>'varchar(64)', 'label'=>'Label', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>25, 'showoncombobox'=>1),
76 'active' =>array('type'=>'integer', 'label'=>'Active', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>30),
77 );
78
79
80
86 public function __construct(DoliDB $db)
87 {
88 global $conf, $langs;
89
90 $this->db = $db;
91
92 if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields['rowid'])) {
93 $this->fields['rowid']['visible'] = 0;
94 }
95 if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
96 $this->fields['entity']['enabled'] = 0;
97 }
98
99 // Example to show how to set values of fields definition dynamically
100 /*if ($user->hasRight('mymodule', 'myobject', 'read')) {
101 $this->fields['myfield']['visible'] = 1;
102 $this->fields['myfield']['noteditable'] = 0;
103 }*/
104
105 // Unset fields that are disabled
106 foreach ($this->fields as $key => $val) {
107 if (isset($val['enabled']) && empty($val['enabled'])) {
108 unset($this->fields[$key]);
109 }
110 }
111
112 // Translate some data of arrayofkeyval
113 if (is_object($langs)) {
114 foreach ($this->fields as $key => $val) {
115 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
116 foreach ($val['arrayofkeyval'] as $key2 => $val2) {
117 $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
118 }
119 }
120 }
121 }
122 }
123
131 public function create(User $user, $notrigger = false)
132 {
133 $resultcreate = $this->createCommon($user, $notrigger);
134 return $resultcreate;
135 }
136
144 public function fetch($id, $ref = null)
145 {
146 $result = $this->fetchCommon($id, $ref);
147 return $result;
148 }
149
161 public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
162 {
163 global $conf;
164
165 dol_syslog(__METHOD__, LOG_DEBUG);
166
167 $records = array();
168
169 $sql = "SELECT ";
170 $sql .= $this->getFieldList('t');
171 $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as t";
172 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
173 $sql .= " WHERE t.entity IN (".getEntity($this->element).")";
174 } else {
175 $sql .= " WHERE 1 = 1";
176 }
177 // Manage filter
178 $sqlwhere = array();
179 if (count($filter) > 0) {
180 foreach ($filter as $key => $value) {
181 if ($key == 't.rowid') {
182 $sqlwhere[] = $key." = ".((int) $value);
183 } elseif (in_array($this->fields[$key]['type'], array('date', 'datetime', 'timestamp'))) {
184 $sqlwhere[] = $key." = '".$this->db->idate($value)."'";
185 } elseif ($key == 'customsql') {
186 $sqlwhere[] = $value;
187 } elseif (strpos($value, '%') === false) {
188 $sqlwhere[] = $key." IN (".$this->db->sanitize($this->db->escape($value)).")";
189 } else {
190 $sqlwhere[] = $key." LIKE '%".$this->db->escape($value)."%'";
191 }
192 }
193 }
194 if (count($sqlwhere) > 0) {
195 $sql .= " AND (".implode(" ".$filtermode." ", $sqlwhere).")";
196 }
197
198 if (!empty($sortfield)) {
199 $sql .= $this->db->order($sortfield, $sortorder);
200 }
201 if (!empty($limit)) {
202 $sql .= $this->db->plimit($limit, $offset);
203 }
204
205 $resql = $this->db->query($sql);
206 if ($resql) {
207 $num = $this->db->num_rows($resql);
208 $i = 0;
209 while ($i < ($limit ? min($limit, $num) : $num)) {
210 $obj = $this->db->fetch_object($resql);
211
212 $record = new self($this->db);
213 $record->setVarsFromFetchObj($obj);
214
215 $records[$record->id] = $record;
216
217 $i++;
218 }
219 $this->db->free($resql);
220
221 return $records;
222 } else {
223 $this->errors[] = 'Error '.$this->db->lasterror();
224 dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
225
226 return -1;
227 }
228 }
229
237 public function update(User $user, $notrigger = false)
238 {
239 return $this->updateCommon($user, $notrigger);
240 }
241
249 public function delete(User $user, $notrigger = false)
250 {
251 return $this->deleteCommon($user, $notrigger);
252 }
253
264 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
265 {
266 global $conf, $langs, $hookmanager;
267
268 if (!empty($conf->dol_no_mouse_hover)) {
269 $notooltip = 1; // Force disable tooltips
270 }
271
272 $result = '';
273
274 $label = img_picto('', $this->picto).' <u>'.$langs->trans("PartnershipType").'</u>';
275 if (isset($this->status)) {
276 $label .= ' '.$this->getLibStatut(5);
277 }
278 $label .= '<br>';
279 $label .= '<b>'.$langs->trans('Code').':</b> '.$this->code;
280 $label .= '<br><b>'.$langs->trans('Label').':</b> '.$this->label;
281
282 //$url = dol_buildpath('/partnership/partnership_card.php', 1).'?id='.$this->id;
283 $url = '';
284
285 if ($option != 'nolink') {
286 // Add param to save lastsearch_values or not
287 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
288 if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
289 $add_save_lastsearch_values = 1;
290 }
291 if ($url && $add_save_lastsearch_values) {
292 $url .= '&save_lastsearch_values=1';
293 }
294 }
295
296 $linkclose = '';
297 if (empty($notooltip)) {
298 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
299 $label = $langs->trans("ShowMyObject");
300 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
301 }
302 $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
303 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
304 } else {
305 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
306 }
307
308 if ($option == 'nolink' || empty($url)) {
309 $linkstart = '<span';
310 } else {
311 $linkstart = '<a href="'.$url.'"';
312 }
313 $linkstart .= $linkclose.'>';
314 if ($option == 'nolink' || empty($url)) {
315 $linkend = '</span>';
316 } else {
317 $linkend = '</a>';
318 }
319
320 $result .= $linkstart;
321
322 if (empty($this->showphoto_on_popup)) {
323 if ($withpicto) {
324 $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);
325 }
326 } else {
327 if ($withpicto) {
328 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
329
330 list($class, $module) = explode('@', $this->picto);
331 $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
332 $filearray = dol_dir_list($upload_dir, "files");
333 $filename = $filearray[0]['name'];
334 if (!empty($filename)) {
335 $pospoint = strpos($filearray[0]['name'], '.');
336
337 $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
338 if (empty($conf->global->{strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS'})) {
339 $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>';
340 } else {
341 $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>';
342 }
343
344 $result .= '</div>';
345 } else {
346 $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);
347 }
348 }
349 }
350
351 if ($withpicto != 2) {
352 $result .= $this->ref;
353 }
354
355 $result .= $linkend;
356 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
357
358 global $action, $hookmanager;
359 $hookmanager->initHooks(array('myobjectdao'));
360 $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
361 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
362 if ($reshook > 0) {
363 $result = $hookmanager->resPrint;
364 } else {
365 $result .= $hookmanager->resPrint;
366 }
367
368 return $result;
369 }
370
377 public function info($id)
378 {
379 $sql = "SELECT rowid, date_creation as datec, tms as datem,";
380 $sql .= " fk_user_creat, fk_user_modif";
381 $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as t";
382 $sql .= " WHERE t.rowid = ".((int) $id);
383
384 $result = $this->db->query($sql);
385 if ($result) {
386 if ($this->db->num_rows($result)) {
387 $obj = $this->db->fetch_object($result);
388 $this->id = $obj->rowid;
389
390 $this->user_creation_id = $obj->fk_user_creat;
391 $this->user_modification_id = $obj->fk_user_modif;
392 $this->date_creation = $this->db->jdate($obj->datec);
393 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
394 }
395
396 $this->db->free($result);
397 } else {
398 dol_print_error($this->db);
399 }
400 }
401
408 public function initAsSpecimen()
409 {
410 // Set here init that are not commonf fields
411 // $this->property1 = ...
412 // $this->property2 = ...
413
414 $this->initAsSpecimenCommon();
415 }
416}
$object ref
Definition info.php:78
Parent class of all other business classes (invoices, contracts, proposals, orders,...
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.
getFieldList($alias='', $excludefields=array())
Function to concat keys of fields.
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.
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:62
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.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.