commonfieldsinexport.inc.php 2.0 KB

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