dolibarr 25.0.0-alpha
commonfieldsinimport.inc.php
1<?php
2/* Copyright (C) 2026 MDW <mdeweerd@users.noreply.github.com>
3 * Copyright (C) 2026 Frédéric France <frederic.france@free.fr>
4 */
5
10'@phan-var-force DolibarrModules $this';
11'@phan-var-force ?int $r';
12
13if (empty($keyforclass) || empty($keyforclassfile) || empty($keyforelement) || !isset($r)) {
14 //print $keyforclass.' - '.$keyforclassfile.' - '.$keyforelement;
15 dol_print_error(null, 'include of file commonfieldsinimport.inc.php was done but var $keyforclass or $keyforclassfile or $keyforelement or $r was not set');
16 exit;
17}
18if (empty($keyforalias)) {
19 $keyforalias = 't';
20}
21
22dol_include_once($keyforclassfile);
23if (class_exists($keyforclass)) {
25 $tmpobject = new $keyforclass($this->db);
26 '@phan-var-force CommonObject $tmpobject';
27
28 // Add common fields
29 foreach ($tmpobject->fields as $keyfield => $valuefield) {
30 $fieldname = $keyforalias.'.'.$keyfield;
31 $fieldlabel = ucfirst($valuefield['label']);
32 $typeFilter = "Text";
33 $typefield = preg_replace('/\‍(.*$/', '', $valuefield['type']); // double(24,8) -> double
34 switch ($typefield) {
35 case 'int':
36 case 'integer':
37 case 'double':
38 case 'price':
39 $typeFilter = "Numeric";
40 break;
41 case 'date':
42 case 'datetime':
43 case 'timestamp':
44 $typeFilter = "Date";
45 break;
46 case 'boolean':
47 $typeFilter = "Boolean";
48 break;
49 /*
50 * case 'sellist':
51 * $tmp='';
52 * $tmpparam=jsonOrUnserialize($obj->param); // $tmp ay be array 'options' => array 'c_currencies:code_iso:code_iso' => null
53 * if ($tmpparam['options'] && is_array($tmpparam['options'])) {
54 * $tmpkeys=array_keys($tmpparam['options']);
55 * $tmp=array_shift($tmpkeys);
56 * }
57 * if (preg_match('/[a-z0-9_]+:[a-z0-9_]+:[a-z0-9_]+/', $tmp)) $typeFilter="List:".$tmp;
58 * break;
59 */
60 }
61 $helpfield = '';
62 if (!empty($valuefield['help'])) {
63 $helpfield = preg_replace('/\‍(.*$/', '', $valuefield['help']);
64 }
65 if ($valuefield['enabled']) {
66 $this->import_fields_array[$r][$fieldname] = $fieldlabel;
67 $this->import_TypeFields_array[$r][$fieldname] = $typeFilter;
68 $this->import_entities_array[$r][$fieldname] = $keyforelement;
69 $this->import_help_array[$r][$fieldname] = $helpfield;
70 }
71 }
72} else {
73 dol_print_error($this->db, 'Failed to find class '.$keyforclass.', even after the include of '.$keyforclassfile);
74}
75// 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.