dolibarr 24.0.0-beta
commonfieldsinexport.inc.php
1<?php
2/* Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
3 */
4'
5@phan-var-force DolibarrModules $this
6@phan-var-force int $r
7';
8
14if (empty($keyforclass) || empty($keyforclassfile) || empty($keyforelement)) {
15 //print $keyforclass.' - '.$keyforclassfile.' - '.$keyforelement;
16 dol_print_error(null, 'include of file commonfieldsinexport.inc.php was done but var $keyforclass or $keyforclassfile or $keyforelement was not set');
17 exit;
18}
19if (empty($keyforalias)) {
20 $keyforalias = 't';
21}
22
23dol_include_once($keyforclassfile);
24if (class_exists($keyforclass)) {
26 $tmpobject = new $keyforclass($this->db); // @phpstan-ignore property.nonObject
27 '@phan-var-force CommonObject $tmpobject';
28
29
30 // Add common fields
31 foreach ($tmpobject->fields as $keyfield => $valuefield) {
32 $fieldname = $keyforalias.'.'.$keyfield;
33 $fieldlabel = ucfirst($valuefield['label']);
34 $typeFilter = "Text";
35 $typefield = preg_replace('/\‍(.*$/', '', $valuefield['type']); // double(24,8) -> double
36 switch ($typefield) {
37 case 'int':
38 case 'integer':
39 case 'double':
40 case 'price':
41 $typeFilter = "Numeric";
42 break;
43 case 'date':
44 case 'datetime':
45 case 'timestamp':
46 $typeFilter = "Date";
47 break;
48 case 'boolean':
49 $typeFilter = "Boolean";
50 break;
51 /*
52 * case 'sellist':
53 * $tmp='';
54 * $tmpparam=jsonOrUnserialize($obj->param); // $tmp ay be array 'options' => array 'c_currencies:code_iso:code_iso' => null
55 * if ($tmpparam['options'] && is_array($tmpparam['options'])) {
56 * $tmpkeys=array_keys($tmpparam['options']);
57 * $tmp=array_shift($tmpkeys);
58 * }
59 * if (preg_match('/[a-z0-9_]+:[a-z0-9_]+:[a-z0-9_]+/', $tmp)) $typeFilter="List:".$tmp;
60 * break;
61 */
62 }
63 $helpfield = '';
64 if (!empty($valuefield['help'])) {
65 $helpfield = preg_replace('/\‍(.*$/', '', $valuefield['help']);
66 }
67 if ($valuefield['enabled']) {
68 $this->export_fields_array[$r][$fieldname] = $fieldlabel;
69 $this->export_TypeFields_array[$r][$fieldname] = $typeFilter;
70 $this->export_entities_array[$r][$fieldname] = $keyforelement;
71 $this->export_help_array[$r][$fieldname] = $helpfield;
72 }
73 }
74} else {
75 dol_print_error($this->db, 'Failed to find class '.$keyforclass.', even after the include of '.$keyforclassfile);
76}
77// End add common fields
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...