dolibarr 21.0.0-alpha
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 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
9 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <https://www.gnu.org/licenses/>.
23 */
24
31require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
32
33
38{
42 public $table_element = 'c_partnership_type';
43
47 public $element = 'partnership_type';
48
52 public $picto = 'generic';
53
57 public $code;
58
62 public $label;
63
64 public $active;
65
66
67 public $fields = array(
68 'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 10),
69 'entity' => array('type' => 'integer', 'label' => 'Entity', 'default' => '1', 'enabled' => 1, 'visible' => -2, 'notnull' => 1, 'position' => 15, 'index' => 1),
70 'code' => array('type' => 'varchar(32)', 'label' => 'Code', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 20),
71 'label' => array('type' => 'varchar(64)', 'label' => 'Label', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 25, 'showoncombobox' => 1),
72 'active' => array('type' => 'integer', 'label' => 'Active', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 30),
73 );
74
75
76
82 public function __construct(DoliDB $db)
83 {
84 global $conf, $langs;
85
86 $this->db = $db;
87
88 $this->ismultientitymanaged = 1;
89
90 if (!getDolGlobalString('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->hasRight('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 = 0)
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
160 public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
161 {
162 global $conf;
163
164 dol_syslog(__METHOD__, LOG_DEBUG);
165
166 $records = array();
167
168 $sql = "SELECT ";
169 $sql .= $this->getFieldList('t');
170 $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as t";
171 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
172 $sql .= " WHERE t.entity IN (".getEntity($this->element).")";
173 } else {
174 $sql .= " WHERE 1 = 1";
175 }
176
177 // Manage filter
178 $errormessage = '';
179 $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
180 if ($errormessage) {
181 $this->errors[] = $errormessage;
182 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
183 return -1;
184 }
185
186 if (!empty($sortfield)) {
187 $sql .= $this->db->order($sortfield, $sortorder);
188 }
189 if (!empty($limit)) {
190 $sql .= $this->db->plimit($limit, $offset);
191 }
192
193 $resql = $this->db->query($sql);
194 if ($resql) {
195 $num = $this->db->num_rows($resql);
196 $i = 0;
197 while ($i < ($limit ? min($limit, $num) : $num)) {
198 $obj = $this->db->fetch_object($resql);
199
200 $record = new self($this->db);
201 $record->setVarsFromFetchObj($obj);
202
203 $records[$record->id] = $record;
204
205 $i++;
206 }
207 $this->db->free($resql);
208
209 return $records;
210 } else {
211 $this->errors[] = 'Error '.$this->db->lasterror();
212 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
213
214 return -1;
215 }
216 }
217
225 public function update(User $user, $notrigger = 0)
226 {
227 return $this->updateCommon($user, $notrigger);
228 }
229
237 public function delete(User $user, $notrigger = 0)
238 {
239 return $this->deleteCommon($user, $notrigger);
240 }
241
252 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
253 {
254 global $conf, $langs, $hookmanager;
255
256 if (!empty($conf->dol_no_mouse_hover)) {
257 $notooltip = 1; // Force disable tooltips
258 }
259
260 $result = '';
261
262 $label = img_picto('', $this->picto).' <u>'.$langs->trans("PartnershipType").'</u>';
263 if (isset($this->status)) {
264 $label .= ' '.$this->getLibStatut(5);
265 }
266 $label .= '<br>';
267 $label .= '<b>'.$langs->trans('Code').':</b> '.$this->code;
268 $label .= '<br><b>'.$langs->trans('Label').':</b> '.$this->label;
269
270 //$url = dol_buildpath('/partnership/partnership_card.php', 1).'?id='.$this->id;
271 $url = '';
272
273 if ($option != 'nolink') {
274 // Add param to save lastsearch_values or not
275 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
276 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
277 $add_save_lastsearch_values = 1;
278 }
279 if ($url && $add_save_lastsearch_values) {
280 $url .= '&save_lastsearch_values=1';
281 }
282 }
283
284 $linkclose = '';
285 if (empty($notooltip)) {
286 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
287 $label = $langs->trans("ShowMyObject");
288 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
289 }
290 $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
291 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
292 } else {
293 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
294 }
295
296 if ($option == 'nolink' || empty($url)) {
297 $linkstart = '<span';
298 } else {
299 $linkstart = '<a href="'.$url.'"';
300 }
301 $linkstart .= $linkclose.'>';
302 if ($option == 'nolink' || empty($url)) {
303 $linkend = '</span>';
304 } else {
305 $linkend = '</a>';
306 }
307
308 $result .= $linkstart;
309
310 if (empty($this->showphoto_on_popup)) {
311 if ($withpicto) {
312 $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);
313 }
314 } else {
315 if ($withpicto) {
316 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
317
318 list($class, $module) = explode('@', $this->picto);
319 $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
320 $filearray = dol_dir_list($upload_dir, "files");
321 $filename = $filearray[0]['name'];
322 if (!empty($filename)) {
323 $pospoint = strpos($filearray[0]['name'], '.');
324
325 $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
326 if (!getDolGlobalString(strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS')) {
327 $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>';
328 } else {
329 $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>';
330 }
331
332 $result .= '</div>';
333 } else {
334 $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);
335 }
336 }
337 }
338
339 if ($withpicto != 2) {
340 $result .= $this->ref;
341 }
342
343 $result .= $linkend;
344 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
345
346 global $action, $hookmanager;
347 $hookmanager->initHooks(array('myobjectdao'));
348 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
349 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
350 if ($reshook > 0) {
351 $result = $hookmanager->resPrint;
352 } else {
353 $result .= $hookmanager->resPrint;
354 }
355
356 return $result;
357 }
358
365 public function getLibStatut($mode = 0)
366 {
367 return '';
368 }
369
376 public function info($id)
377 {
378 $sql = "SELECT rowid, date_creation as datec, tms as datem,";
379 $sql .= " fk_user_creat, fk_user_modif";
380 $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as t";
381 $sql .= " WHERE t.rowid = ".((int) $id);
382
383 $result = $this->db->query($sql);
384 if ($result) {
385 if ($this->db->num_rows($result)) {
386 $obj = $this->db->fetch_object($result);
387
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 return $this->initAsSpecimenCommon();
415 }
416}
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Definition security.php:626
$object ref
Definition info.php:79
Parent class of all other business classes (invoices, contracts, proposals, orders,...
createCommon(User $user, $notrigger=0)
Create object in the database.
getFieldList($alias='', $excludefields=array())
Function to concat keys of fields.
updateCommon(User $user, $notrigger=0)
Update object into database.
initAsSpecimenCommon()
Initialise object with example values Id must be 0 if object instance is a specimen.
fetchCommon($id, $ref=null, $morewhere='', $noextrafields=0)
Load object in memory from the database.
deleteCommon(User $user, $notrigger=0, $forcechilddeletion=0)
Delete object in 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.
getLibStatut($mode=0)
Return the label of the status.
__construct(DoliDB $db)
Constructor.
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionally the picto)
fetch($id, $ref=null)
Load object in memory from the database.
update(User $user, $notrigger=0)
Update object into database.
info($id)
Load the info information in the object.
create(User $user, $notrigger=0)
Create object into database.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, $filter='', $filtermode='AND')
Load list of objects in memory from the database.
Class to manage Dolibarr users.
dol_dir_list($utf8_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:63
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
dol_print_error($db=null, $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.