commonfieldsinexport.inc.php 2.0 KB

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