dolibarr 18.0.6
dolresource.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2013-2015 Jean-François Ferry <jfefe@aternatik.fr>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
24require_once DOL_DOCUMENT_ROOT."/core/class/commonobject.class.php";
25require_once DOL_DOCUMENT_ROOT."/core/lib/functions2.lib.php";
26
31{
35 public $element = 'dolresource';
36
40 public $table_element = 'resource';
41
45 public $picto = 'resource';
46
47
51 public $fk_code_type_resource;
52
53 public $type_label;
54
58 public $description;
59
60 public $fk_country;
61
62
63 // Variable for a link of resource
64
68 public $resource_id;
69 public $resource_type;
70 public $element_id;
71 public $element_type;
72 public $busy;
73 public $mandatory;
77 public $fk_user_create;
78 public $tms = '';
79
83 public $cache_code_type_resource = array();
84
88 public $oldcopy;
89
90
96 public function __construct($db)
97 {
98 $this->db = $db;
99 }
100
108 public function create($user, $notrigger = 0)
109 {
110 global $conf, $langs, $hookmanager;
111 $error = 0;
112
113 // Clean parameters
114
115 if (isset($this->ref)) {
116 $this->ref = trim($this->ref);
117 }
118 if (isset($this->description)) {
119 $this->description = trim($this->description);
120 }
121 if (!is_numeric($this->country_id)) {
122 $this->country_id = 0;
123 }
124 if (isset($this->fk_code_type_resource)) {
125 $this->fk_code_type_resource = trim($this->fk_code_type_resource);
126 }
127 if (isset($this->note_public)) {
128 $this->note_public = trim($this->note_public);
129 }
130 if (isset($this->note_private)) {
131 $this->note_private = trim($this->note_private);
132 }
133
134
135 // Insert request
136 $sql = "INSERT INTO ".MAIN_DB_PREFIX.$this->table_element."(";
137 $sql .= "entity,";
138 $sql .= "ref,";
139 $sql .= "description,";
140 $sql .= "fk_country,";
141 $sql .= "fk_code_type_resource,";
142 $sql .= "note_public,";
143 $sql .= "note_private";
144 $sql .= ") VALUES (";
145 $sql .= $conf->entity.", ";
146 $sql .= " ".(!isset($this->ref) ? 'NULL' : "'".$this->db->escape($this->ref)."'").",";
147 $sql .= " ".(!isset($this->description) ? 'NULL' : "'".$this->db->escape($this->description)."'").",";
148 $sql .= " ".($this->country_id > 0 ? $this->country_id : 'null').",";
149 $sql .= " ".(!isset($this->fk_code_type_resource) ? 'NULL' : "'".$this->db->escape($this->fk_code_type_resource)."'").",";
150 $sql .= " ".(!isset($this->note_public) ? 'NULL' : "'".$this->db->escape($this->note_public)."'").",";
151 $sql .= " ".(!isset($this->note_private) ? 'NULL' : "'".$this->db->escape($this->note_private)."'");
152 $sql .= ")";
153
154 $this->db->begin();
155
156 dol_syslog(get_class($this)."::create", LOG_DEBUG);
157 $resql = $this->db->query($sql);
158 if (!$resql) {
159 $error++; $this->errors[] = "Error ".$this->db->lasterror();
160 }
161
162 if (!$error) {
163 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
164 }
165
166 if (!$error) {
167 $action = 'create';
168
169 // Actions on extra fields
170 if (!$error) {
171 $result = $this->insertExtraFields();
172 if ($result < 0) {
173 $error++;
174 }
175 }
176 }
177
178 if (!$error && !$notrigger) {
179 // Call trigger
180 $result = $this->call_trigger('RESOURCE_CREATE', $user);
181 if ($result < 0) {
182 $error++;
183 }
184 // End call triggers
185 }
186
187 // Commit or rollback
188 if ($error) {
189 foreach ($this->errors as $errmsg) {
190 dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR);
191 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
192 }
193 $this->db->rollback();
194 return -1 * $error;
195 } else {
196 $this->db->commit();
197 return $this->id;
198 }
199 }
200
208 public function fetch($id, $ref = '')
209 {
210 global $langs;
211 $sql = "SELECT";
212 $sql .= " t.rowid,";
213 $sql .= " t.entity,";
214 $sql .= " t.ref,";
215 $sql .= " t.description,";
216 $sql .= " t.fk_country,";
217 $sql .= " t.fk_code_type_resource,";
218 $sql .= " t.note_public,";
219 $sql .= " t.note_private,";
220 $sql .= " t.tms,";
221 $sql .= " ty.label as type_label";
222 $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as t";
223 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_type_resource as ty ON ty.code=t.fk_code_type_resource";
224 if ($id) {
225 $sql .= " WHERE t.rowid = ".((int) $id);
226 } else {
227 $sql .= " WHERE t.ref = '".$this->db->escape($ref)."'";
228 }
229
230 dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
231 $resql = $this->db->query($sql);
232 if ($resql) {
233 if ($this->db->num_rows($resql)) {
234 $obj = $this->db->fetch_object($resql);
235
236 $this->id = $obj->rowid;
237 $this->entity = $obj->entity;
238 $this->ref = $obj->ref;
239 $this->description = $obj->description;
240 $this->country_id = $obj->fk_country;
241 $this->fk_code_type_resource = $obj->fk_code_type_resource;
242 $this->note_public = $obj->note_public;
243 $this->note_private = $obj->note_private;
244 $this->type_label = $obj->type_label;
245
246 // Retrieve all extrafield
247 // fetch optionals attributes and labels
248 $this->fetch_optionals();
249 }
250 $this->db->free($resql);
251
252 return $this->id;
253 } else {
254 $this->error = "Error ".$this->db->lasterror();
255 dol_syslog(get_class($this)."::fetch ".$this->error, LOG_ERR);
256 return -1;
257 }
258 }
259
260
268 public function update($user = null, $notrigger = 0)
269 {
270 global $conf, $langs, $hookmanager;
271 $error = 0;
272
273 // Clean parameters
274 if (isset($this->ref)) {
275 $this->ref = trim($this->ref);
276 }
277 if (isset($this->fk_code_type_resource)) {
278 $this->fk_code_type_resource = trim($this->fk_code_type_resource);
279 }
280 if (isset($this->description)) {
281 $this->description = trim($this->description);
282 }
283 if (!is_numeric($this->country_id)) {
284 $this->country_id = 0;
285 }
286
287 // $this->oldcopy should have been set by the caller of update (here properties were already modified)
288 if (empty($this->oldcopy)) {
289 $this->oldcopy = dol_clone($this);
290 }
291
292 // Update request
293 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET";
294 $sql .= " ref=".(isset($this->ref) ? "'".$this->db->escape($this->ref)."'" : "null").",";
295 $sql .= " description=".(isset($this->description) ? "'".$this->db->escape($this->description)."'" : "null").",";
296 $sql .= " fk_country=".($this->country_id > 0 ? $this->country_id : "null").",";
297 $sql .= " fk_code_type_resource=".(isset($this->fk_code_type_resource) ? "'".$this->db->escape($this->fk_code_type_resource)."'" : "null").",";
298 $sql .= " tms=".(dol_strlen($this->tms) != 0 ? "'".$this->db->idate($this->tms)."'" : 'null');
299 $sql .= " WHERE rowid=".((int) $this->id);
300
301 $this->db->begin();
302
303 dol_syslog(get_class($this)."::update", LOG_DEBUG);
304 $resql = $this->db->query($sql);
305 if (!$resql) {
306 $error++; $this->errors[] = "Error ".$this->db->lasterror();
307 }
308
309 if (!$error) {
310 if (!$notrigger) {
311 // Call trigger
312 $result = $this->call_trigger('RESOURCE_MODIFY', $user);
313 if ($result < 0) {
314 $error++;
315 }
316 // End call triggers
317 }
318 }
319
320 if (!$error && (is_object($this->oldcopy) && $this->oldcopy->ref !== $this->ref)) {
321 // We remove directory
322 if (!empty($conf->resource->dir_output)) {
323 $olddir = $conf->resource->dir_output."/".dol_sanitizeFileName($this->oldcopy->ref);
324 $newdir = $conf->resource->dir_output."/".dol_sanitizeFileName($this->ref);
325 if (file_exists($olddir)) {
326 $res = @rename($olddir, $newdir);
327 if (!$res) {
328 $langs->load("errors");
329 $this->error = $langs->trans('ErrorFailToRenameDir', $olddir, $newdir);
330 $error++;
331 }
332 }
333 }
334 }
335
336 if (!$error) {
337 $action = 'update';
338
339 // Actions on extra fields
340 if (!$error) {
341 $result = $this->insertExtraFields();
342 if ($result < 0) {
343 $error++;
344 }
345 }
346 }
347
348 // Commit or rollback
349 if ($error) {
350 foreach ($this->errors as $errmsg) {
351 dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
352 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
353 }
354 $this->db->rollback();
355 return -1 * $error;
356 } else {
357 $this->db->commit();
358 return 1;
359 }
360 }
361
362 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
369 public function fetch_element_resource($id)
370 {
371 // phpcs:enable
372 global $langs;
373 $sql = "SELECT";
374 $sql .= " t.rowid,";
375 $sql .= " t.resource_id,";
376 $sql .= " t.resource_type,";
377 $sql .= " t.element_id,";
378 $sql .= " t.element_type,";
379 $sql .= " t.busy,";
380 $sql .= " t.mandatory,";
381 $sql .= " t.fk_user_create,";
382 $sql .= " t.tms";
383 $sql .= " FROM ".MAIN_DB_PREFIX."element_resources as t";
384 $sql .= " WHERE t.rowid = ".((int) $id);
385
386 dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
387 $resql = $this->db->query($sql);
388 if ($resql) {
389 if ($this->db->num_rows($resql)) {
390 $obj = $this->db->fetch_object($resql);
391
392 $this->id = $obj->rowid;
393 $this->resource_id = $obj->resource_id;
394 $this->resource_type = $obj->resource_type;
395 $this->element_id = $obj->element_id;
396 $this->element_type = $obj->element_type;
397 $this->busy = $obj->busy;
398 $this->mandatory = $obj->mandatory;
399 $this->fk_user_create = $obj->fk_user_create;
400
401 if ($obj->resource_id && $obj->resource_type) {
402 $this->objresource = fetchObjectByElement($obj->resource_id, $obj->resource_type);
403 }
404 if ($obj->element_id && $obj->element_type) {
405 $this->objelement = fetchObjectByElement($obj->element_id, $obj->element_type);
406 }
407 }
408 $this->db->free($resql);
409
410 return $this->id;
411 } else {
412 $this->error = "Error ".$this->db->lasterror();
413 return -1;
414 }
415 }
416
424 public function delete($rowid, $notrigger = 0)
425 {
426 global $user, $langs, $conf;
427 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
428
429 $error = 0;
430
431 $this->db->begin();
432
433 $sql = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element;
434 $sql .= " WHERE rowid = ".((int) $rowid);
435
436 dol_syslog(get_class($this), LOG_DEBUG);
437 if ($this->db->query($sql)) {
438 $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_resources";
439 $sql .= " WHERE element_type='resource' AND resource_id = ".((int) $rowid);
440 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
441 $resql = $this->db->query($sql);
442 if (!$resql) {
443 $this->error = $this->db->lasterror();
444 $error++;
445 }
446 } else {
447 $this->error = $this->db->lasterror();
448 $error++;
449 }
450
451 // Removed extrafields
452 if (!$error) {
453 $result = $this->deleteExtraFields();
454 if ($result < 0) {
455 $error++;
456 dol_syslog(get_class($this)."::delete error -3 ".$this->error, LOG_ERR);
457 }
458 }
459
460 if (!$notrigger) {
461 // Call trigger
462 $result = $this->call_trigger('RESOURCE_DELETE', $user);
463 if ($result < 0) {
464 $error++;
465 }
466 // End call triggers
467 }
468
469 if (!$error) {
470 // We remove directory
471 $ref = dol_sanitizeFileName($this->ref);
472 if (!empty($conf->resource->dir_output)) {
473 $dir = $conf->resource->dir_output."/".dol_sanitizeFileName($this->ref);
474 if (file_exists($dir)) {
475 $res = @dol_delete_dir_recursive($dir);
476 if (!$res) {
477 $this->errors[] = 'ErrorFailToDeleteDir';
478 $error++;
479 }
480 }
481 }
482 }
483
484 if (!$error) {
485 $this->db->commit();
486 return 1;
487 } else {
488 $this->db->rollback();
489 return -1;
490 }
491 }
492
493 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
504 public function fetchAll($sortorder, $sortfield, $limit, $offset, $filter = '')
505 {
506 // phpcs:enable
507 require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
508 $extrafields = new ExtraFields($this->db);
509
510 $sql = "SELECT ";
511 $sql .= " t.rowid,";
512 $sql .= " t.entity,";
513 $sql .= " t.ref,";
514 $sql .= " t.description,";
515 $sql .= " t.fk_country,";
516 $sql .= " t.fk_code_type_resource,";
517 $sql .= " t.tms,";
518 // Add fields from extrafields
519 if (!empty($extrafields->attributes[$this->table_element]) && !empty($extrafields->attributes[$this->table_element]['label'])) {
520 foreach ($extrafields->attributes[$this->table_element]['label'] as $key => $val) {
521 $sql .= ($extrafields->attributes[$this->table_element]['type'][$key] != 'separate' ? "ef.".$key." as options_".$key.', ' : '');
522 }
523 }
524 $sql .= " ty.label as type_label";
525 $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as t";
526 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_type_resource as ty ON ty.code=t.fk_code_type_resource";
527 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$this->table_element."_extrafields as ef ON ef.fk_object=t.rowid";
528 $sql .= " WHERE t.entity IN (".getEntity('resource').")";
529 // Manage filter
530 if (!empty($filter)) {
531 foreach ($filter as $key => $value) {
532 if (strpos($key, 'date')) {
533 $sql .= " AND ".$key." = '".$this->db->idate($value)."'";
534 } elseif (strpos($key, 'ef.') !== false) {
535 $sql .= $value;
536 } else {
537 $sql .= " AND ".$key." LIKE '%".$this->db->escape($value)."%'";
538 }
539 }
540 }
541 $sql .= $this->db->order($sortfield, $sortorder);
542 if ($limit) {
543 $sql .= $this->db->plimit($limit, $offset);
544 }
545
546 dol_syslog(get_class($this)."::fetchAll", LOG_DEBUG);
547
548 $this->lines = array();
549 $resql = $this->db->query($sql);
550 if ($resql) {
551 $num = $this->db->num_rows($resql);
552 if ($num) {
553 while ($obj = $this->db->fetch_object($resql)) {
554 $line = new Dolresource($this->db);
555 $line->id = $obj->rowid;
556 $line->ref = $obj->ref;
557 $line->description = $obj->description;
558 $line->country_id = $obj->fk_country;
559 $line->fk_code_type_resource = $obj->fk_code_type_resource;
560 $line->type_label = $obj->type_label;
561
562 // fetch optionals attributes and labels
563
564 $line->fetch_optionals();
565
566 $this->lines[] = $line;
567 }
568 $this->db->free($resql);
569 }
570 return $num;
571 } else {
572 $this->error = $this->db->lasterror();
573 return -1;
574 }
575 }
576
577 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
585 public function update_element_resource($user = null, $notrigger = 0)
586 {
587 // phpcs:enable
588 global $conf, $langs;
589 $error = 0;
590
591 // Clean parameters
592 if (isset($this->resource_id)) {
593 $this->resource_id = trim($this->resource_id);
594 }
595 if (isset($this->resource_type)) {
596 $this->resource_type = trim($this->resource_type);
597 }
598 if (isset($this->element_id)) {
599 $this->element_id = trim($this->element_id);
600 }
601 if (isset($this->element_type)) {
602 $this->element_type = trim($this->element_type);
603 }
604 if (isset($this->busy)) {
605 $this->busy = trim($this->busy);
606 }
607 if (isset($this->mandatory)) {
608 $this->mandatory = trim($this->mandatory);
609 }
610
611 // Update request
612 $sql = "UPDATE ".MAIN_DB_PREFIX."element_resources SET";
613 $sql .= " resource_id=".(isset($this->resource_id) ? "'".$this->db->escape($this->resource_id)."'" : "null").",";
614 $sql .= " resource_type=".(isset($this->resource_type) ? "'".$this->db->escape($this->resource_type)."'" : "null").",";
615 $sql .= " element_id=".(isset($this->element_id) ? $this->element_id : "null").",";
616 $sql .= " element_type=".(isset($this->element_type) ? "'".$this->db->escape($this->element_type)."'" : "null").",";
617 $sql .= " busy=".(isset($this->busy) ? $this->busy : "null").",";
618 $sql .= " mandatory=".(isset($this->mandatory) ? $this->mandatory : "null").",";
619 $sql .= " tms=".(dol_strlen($this->tms) != 0 ? "'".$this->db->idate($this->tms)."'" : 'null');
620
621 $sql .= " WHERE rowid=".((int) $this->id);
622
623 $this->db->begin();
624
625 dol_syslog(get_class($this)."::update", LOG_DEBUG);
626 $resql = $this->db->query($sql);
627 if (!$resql) {
628 $error++; $this->errors[] = "Error ".$this->db->lasterror();
629 }
630
631 if (!$error) {
632 if (!$notrigger) {
633 // Call trigger
634 $result = $this->call_trigger('RESOURCE_MODIFY', $user);
635 if ($result < 0) {
636 $error++;
637 }
638 // End call triggers
639 }
640 }
641
642 // Commit or rollback
643 if ($error) {
644 foreach ($this->errors as $errmsg) {
645 dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
646 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
647 }
648 $this->db->rollback();
649 return -1 * $error;
650 } else {
651 $this->db->commit();
652 return 1;
653 }
654 }
655
656
665 public function getElementResources($element, $element_id, $resource_type = '')
666 {
667 $resources = array();
668
669 // Links beetween objects are stored in this table
670 $sql = 'SELECT rowid, resource_id, resource_type, busy, mandatory';
671 $sql .= ' FROM '.MAIN_DB_PREFIX.'element_resources';
672 $sql .= " WHERE element_id=".((int) $element_id)." AND element_type='".$this->db->escape($element)."'";
673 if ($resource_type) {
674 $sql .= " AND resource_type LIKE '%".$this->db->escape($resource_type)."%'";
675 }
676 $sql .= ' ORDER BY resource_type';
677
678 dol_syslog(get_class($this)."::getElementResources", LOG_DEBUG);
679
680 $resources = array();
681 $resql = $this->db->query($sql);
682 if ($resql) {
683 $num = $this->db->num_rows($resql);
684 $i = 0;
685 while ($i < $num) {
686 $obj = $this->db->fetch_object($resql);
687
688 $resources[$i] = array(
689 'rowid' => $obj->rowid,
690 'resource_id' => $obj->resource_id,
691 'resource_type'=>$obj->resource_type,
692 'busy'=>$obj->busy,
693 'mandatory'=>$obj->mandatory
694 );
695 $i++;
696 }
697 }
698
699 return $resources;
700 }
701
709 public function fetchElementResources($element, $element_id)
710 {
711 $resources = $this->getElementResources($element, $element_id);
712 $i = 0;
713 foreach ($resources as $nb => $resource) {
714 $this->lines[$i] = fetchObjectByElement($resource['resource_id'], $resource['resource_type']);
715 $i++;
716 }
717 return $i;
718 }
719
720
721 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
728 {
729 // phpcs:enable
730 global $langs;
731
732 if (is_array($this->cache_code_type_resource) && count($this->cache_code_type_resource)) {
733 return 0; // Cache deja charge
734 }
735
736 $sql = "SELECT rowid, code, label, active";
737 $sql .= " FROM ".MAIN_DB_PREFIX."c_type_resource";
738 $sql .= " WHERE active > 0";
739 $sql .= " ORDER BY rowid";
740 dol_syslog(get_class($this)."::load_cache_code_type_resource", LOG_DEBUG);
741 $resql = $this->db->query($sql);
742 if ($resql) {
743 $num = $this->db->num_rows($resql);
744 $i = 0;
745 while ($i < $num) {
746 $obj = $this->db->fetch_object($resql);
747
748 $label = ($langs->trans("ResourceTypeShort".$obj->code) != ("ResourceTypeShort".$obj->code) ? $langs->trans("ResourceTypeShort".$obj->code) : ($obj->label != '-' ? $obj->label : ''));
749 $this->cache_code_type_resource[$obj->rowid]['code'] = $obj->code;
750 $this->cache_code_type_resource[$obj->rowid]['label'] = $label;
751 $this->cache_code_type_resource[$obj->rowid]['active'] = $obj->active;
752 $i++;
753 }
754 return $num;
755 } else {
756 dol_print_error($this->db);
757 return -1;
758 }
759 }
760
768 public function getTooltipContentArray($params)
769 {
770 global $langs;
771
772 $langs->load('resource');
773
774 $datas = [];
775
776 $datas['picto'] = img_picto('', $this->picto).' <u>'.$langs->trans("Resource").'</u>';
777 $datas['ref'] = '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
778 /*if (isset($this->status)) {
779 $datas['status'] = '<br><b>' . $langs->trans("Status").":</b> ".$this->getLibStatut(5);
780 }*/
781 if (isset($this->type_label)) {
782 $datas['label'] = '<br><b>'.$langs->trans("ResourceType").":</b> ".$this->type_label;
783 }
784
785 return $datas;
786 }
787
799 public function getNomUrl($withpicto = 0, $option = '', $get_params = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
800 {
801 global $conf, $langs, $hookmanager;
802
803 $result = '';
804 $params = [
805 'id' => $this->id,
806 'objecttype' => $this->element,
807 ];
808 $classfortooltip = 'classfortooltip';
809 $dataparams = '';
810 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
811 $classfortooltip = 'classforajaxtooltip';
812 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
813 $label = '';
814 } else {
815 $label = implode($this->getTooltipContentArray($params));
816 }
817
818 $url = DOL_URL_ROOT.'/resource/card.php?id='.$this->id;
819
820 if ($option != 'nolink') {
821 // Add param to save lastsearch_values or not
822 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
823 if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
824 $add_save_lastsearch_values = 1;
825 }
826 if ($add_save_lastsearch_values) {
827 $url .= '&save_lastsearch_values=1';
828 }
829 }
830
831 $linkclose = '';
832 if (empty($notooltip)) {
833 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
834 $label = $langs->trans("ShowMyObject");
835 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
836 }
837 $linkclose .= ($label ? ' title="'.dol_escape_htmltag($label, 1).'"' : ' title="tocomplete"');
838 $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
839 } else {
840 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
841 }
842
843 $linkstart = '<a href="'.$url.$get_params.'"';
844 $linkstart .= $linkclose.'>';
845 $linkend = '</a>';
846 /*$linkstart = '<a href="'.DOL_URL_ROOT.'/resource/card.php?id='.$this->id.$get_params.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
847 $linkend = '</a>';*/
848
849 $result .= $linkstart;
850 if ($withpicto) {
851 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), (($withpicto != 2) ? 'class="paddingright"' : ''), 0, 0, $notooltip ? 0 : 1);
852 }
853 if ($withpicto != 2) {
854 $result .= $this->ref;
855 }
856 $result .= $linkend;
857
858 global $action;
859 $hookmanager->initHooks(array($this->element . 'dao'));
860 $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
861 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
862 if ($reshook > 0) {
863 $result = $hookmanager->resPrint;
864 } else {
865 $result .= $hookmanager->resPrint;
866 }
867 return $result;
868 }
869
870
877 public function getLibStatut($mode = 0)
878 {
879 return $this->LibStatut($this->status, $mode);
880 }
881
882 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
890 public static function LibStatut($status, $mode = 0)
891 {
892 // phpcs:enable
893 return '';
894 }
895
896 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
902 public function load_state_board()
903 {
904 // phpcs:enable
905 $this->nb = array();
906
907 $sql = "SELECT count(r.rowid) as nb";
908 $sql .= " FROM ".MAIN_DB_PREFIX."resource as r";
909 $sql .= " WHERE r.entity IN (".getEntity('resource').")";
910
911 $resql = $this->db->query($sql);
912 if ($resql) {
913 while ($obj = $this->db->fetch_object($resql)) {
914 $this->nb["dolresource"] = $obj->nb;
915 }
916 $this->db->free($resql);
917 return 1;
918 } else {
919 dol_print_error($this->db);
920 $this->error = $this->db->error();
921 return -1;
922 }
923 }
924}
$object ref
Definition info.php:78
Parent class of all other business classes (invoices, contracts, proposals, orders,...
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this->array_options This method is in most cases call...
deleteExtraFields()
Delete all extra fields values for the current object.
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
call_trigger($triggerName, $user)
Call trigger based on this instance.
DAO Resource object.
update_element_resource($user=null, $notrigger=0)
Update element resource into database.
fetch_element_resource($id)
Load data of link in memory from database.
getElementResources($element, $element_id, $resource_type='')
Return an array with resources linked to the element.
create($user, $notrigger=0)
Create object into database.
fetch($id, $ref='')
Load object in memory from database.
fetchElementResources($element, $element_id)
Return an int number of resources linked to the element.
load_state_board()
Charge indicateurs this->nb de tableau de bord.
getTooltipContentArray($params)
getTooltipContentArray
load_cache_code_type_resource()
Load in cache resource type code (setup in dictionary)
update($user=null, $notrigger=0)
Update object into database.
static LibStatut($status, $mode=0)
Return the status.
__construct($db)
Constructor.
getNomUrl($withpicto=0, $option='', $get_params='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return clicable link of object (with eventually picto)
fetchAll($sortorder, $sortfield, $limit, $offset, $filter='')
Load resource objects into $this->lines.
getLibStatut($mode=0)
Return the label of the status.
Class to manage standard extra fields.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
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)
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
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_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
fetchObjectByElement($element_id, $element_type, $element_ref='')
Fetch an object from its id and element_type Inclusion of classes is automatic.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.