Entity.php 861 B

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. namespace Tools\Model\Entity;
  3. use Cake\ORM\Entity as CakeEntity;
  4. class Entity extends CakeEntity {
  5. /**
  6. * The main method for any enumeration, should be called statically
  7. * Now also supports reordering/filtering
  8. *
  9. * @link http://www.dereuromark.de/2010/06/24/static-enums-or-semihardcoded-attributes/
  10. * @param string $value or array $keys or NULL for complete array result
  11. * @param array $options (actual data)
  12. * @return mixed string/array
  13. */
  14. public static function enum($value, array $options, $default = null) {
  15. if ($value !== null && !is_array($value)) {
  16. if (array_key_exists($value, $options)) {
  17. return $options[$value];
  18. }
  19. return $default;
  20. }
  21. if ($value !== null) {
  22. $newOptions = array();
  23. foreach ($value as $v) {
  24. $newOptions[$v] = $options[$v];
  25. }
  26. return $newOptions;
  27. }
  28. return $options;
  29. }
  30. }