api de gestion de ticket, basé sur php-crud-api. Le but est de décorrélé les outils de gestion des données, afin
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

Condition.php 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace Tqdev\PhpCrudApi\Record\Condition;
  3. use Tqdev\PhpCrudApi\Column\Reflection\ReflectedTable;
  4. abstract class Condition
  5. {
  6. public function _and(Condition $condition): Condition
  7. {
  8. if ($condition instanceof NoCondition) {
  9. return $this;
  10. }
  11. return new AndCondition($this, $condition);
  12. }
  13. public function _or(Condition $condition): Condition
  14. {
  15. if ($condition instanceof NoCondition) {
  16. return $this;
  17. }
  18. return new OrCondition($this, $condition);
  19. }
  20. public function _not(): Condition
  21. {
  22. return new NotCondition($this);
  23. }
  24. public static function fromString(ReflectedTable $table, string $value): Condition
  25. {
  26. $condition = new NoCondition();
  27. $parts = explode(',', $value, 3);
  28. if (count($parts) < 2) {
  29. return $condition;
  30. }
  31. if (count($parts) < 3) {
  32. $parts[2] = '';
  33. }
  34. $field = $table->getColumn($parts[0]);
  35. $command = $parts[1];
  36. $negate = false;
  37. $spatial = false;
  38. if (strlen($command) > 2) {
  39. if (substr($command, 0, 1) == 'n') {
  40. $negate = true;
  41. $command = substr($command, 1);
  42. }
  43. if (substr($command, 0, 1) == 's') {
  44. $spatial = true;
  45. $command = substr($command, 1);
  46. }
  47. }
  48. if ($spatial) {
  49. if (in_array($command, ['co', 'cr', 'di', 'eq', 'in', 'ov', 'to', 'wi', 'ic', 'is', 'iv'])) {
  50. $condition = new SpatialCondition($field, $command, $parts[2]);
  51. }
  52. } else {
  53. if (in_array($command, ['cs', 'sw', 'ew', 'eq', 'lt', 'le', 'ge', 'gt', 'bt', 'in', 'is'])) {
  54. $condition = new ColumnCondition($field, $command, $parts[2]);
  55. }
  56. }
  57. if ($negate) {
  58. $condition = $condition->_not();
  59. }
  60. return $condition;
  61. }
  62. }