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