PageRenderTime 38ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/core/class/datatables/schemas/DefaultSchema.php

https://bitbucket.org/speedealing/speedealing
PHP | 89 lines | 54 code | 14 blank | 21 comment | 9 complexity | dddce3166258faf4c4a38c09a2025532 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  1. <?php
  2. /* Copyright (C) 2013 Regis Houssin <regis.houssin@capnetworks.com>
  3. * Copyright (C) 2013 Herve Prot <herve.prot@symeos.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. namespace datatables\schemas;
  19. use datatables\Schema;
  20. class DefaultSchema extends Schema {
  21. /* ______________________________________________________________________ */
  22. public function __construct() {
  23. global $langs, $object;
  24. // variable to be used inside closure object
  25. $schema = $this;
  26. foreach ($object->fk_extrafields->longList as $key => $aRow) {
  27. $field = $object->fk_extrafields->fields->$aRow;
  28. if (empty($field->enable)) continue;
  29. $classname = get_class($object);
  30. // Editable element
  31. $editable = false; // Editable by default
  32. if (!empty($field->list->editable)) {
  33. $editable = array(
  34. "type" => $field->type,
  35. "name" => $aRow,
  36. "classname" => $classname,
  37. "validate" => $field->validate,
  38. "width" => (!empty($field->list->editable->width) ? $field->list->editable->width : '150px'),
  39. "height" => (!empty($field->list->editable->height) ? $field->list->editable->height : '14px')
  40. );
  41. }
  42. // Render element
  43. $render = false; // Render by default
  44. if (!empty($field->render) || !empty($field->action)) {
  45. $classname = (!empty($field->class) ? $field->class : $classname);
  46. $rendertype = (!empty($field->render->type) ? $field->render->type : $field->type);
  47. if ($rendertype != 'Text')
  48. $render = $this->element('Render' . ucfirst($rendertype), array($field, $aRow, $classname));
  49. }
  50. // Footer element
  51. $footer = ''; // Footer by default
  52. if ($field->list->searchable !== false) {
  53. if (!empty($field->values)) {
  54. $footer = $this->element('FilterSelect', array(object2array($field->values)));
  55. } else {
  56. $footer = $this->element('FilterInput', array($langs->trans('Search') . ' {:label}'));
  57. }
  58. }
  59. $this->push($aRow, array(
  60. 'label' => (!empty($field->label) ? $langs->trans($field->label) : ($field->label === false ? (string) $this->element($rendertype, array('checkall', 1, 'checkall')) : '')), //no label by default
  61. 'default' => (!empty($field->default) ? $field->default : ''),
  62. 'class' => (!empty($field->list->cssclass) ? $field->list->cssclass : ''),
  63. 'width' => (!empty($field->list->width) ? $field->list->width : false),
  64. 'type' => (!empty($field->list->static) ? 'static' : 'dynamic'), // static (no movable and never hidden)
  65. 'searchable' => (is_bool($field->list->searchable) === true ? $field->list->searchable : true), // True by default
  66. 'sortable' => (is_bool($field->list->sortable) === true ? $field->list->sortable : true), // True by default
  67. 'visible' => (is_bool($field->list->visible) === true ? $field->list->visible : true), // True by default
  68. 'editable' => $editable,
  69. 'render' => $render,
  70. 'footer' => $footer
  71. ));
  72. }
  73. }
  74. }
  75. ?>