Campaigns.php
2 years ago
Cities.php
2 years ago
Countries.php
2 years ago
Device_Browsers.php
2 years ago
Device_OSS.php
2 years ago
Device_Types.php
2 years ago
Filter.php
2 years ago
Pages.php
2 years ago
Referrers.php
2 years ago
Rows.php
2 years ago
Filter.php
79 lines
| 1 | <?php |
| 2 | |
| 3 | namespace IAWP_SCOPED\IAWP\Rows; |
| 4 | |
| 5 | /** @internal */ |
| 6 | class Filter |
| 7 | { |
| 8 | private $filter; |
| 9 | public function __construct(array $filter) |
| 10 | { |
| 11 | $this->filter = $filter; |
| 12 | } |
| 13 | public function filter() : array |
| 14 | { |
| 15 | return $this->filter; |
| 16 | } |
| 17 | public function method() : string |
| 18 | { |
| 19 | if ($this->filter['column'] === $this->filter['database_column']) { |
| 20 | return 'having'; |
| 21 | } else { |
| 22 | return 'where'; |
| 23 | } |
| 24 | } |
| 25 | public function column() : string |
| 26 | { |
| 27 | return $this->filter['database_column']; |
| 28 | } |
| 29 | public function operator() : string |
| 30 | { |
| 31 | $operator = $this->filter['operator']; |
| 32 | $result = ''; |
| 33 | if ($operator === 'equal' || $operator === 'is' || $operator === 'exact' || $operator === 'on') { |
| 34 | $result = '='; |
| 35 | } |
| 36 | if ($operator === 'contains') { |
| 37 | $result = 'like'; |
| 38 | } |
| 39 | if ($operator === 'isnt') { |
| 40 | $result = '!='; |
| 41 | } |
| 42 | if ($operator === 'greater' || $operator === 'after') { |
| 43 | $result = '>'; |
| 44 | } |
| 45 | if ($operator === 'lesser' || $operator === 'before') { |
| 46 | $result = '<'; |
| 47 | } |
| 48 | if ($this->filter['inclusion'] === 'exclude') { |
| 49 | if ($result === '=') { |
| 50 | return '!='; |
| 51 | } elseif ($result === '!=') { |
| 52 | return '='; |
| 53 | } elseif ($result === '>') { |
| 54 | return '<='; |
| 55 | } elseif ($result === '<') { |
| 56 | return '>='; |
| 57 | } elseif ($result === 'like') { |
| 58 | return 'not like'; |
| 59 | } |
| 60 | } |
| 61 | return $result; |
| 62 | } |
| 63 | public function value() : string |
| 64 | { |
| 65 | if ($this->filter['operator'] === 'contains') { |
| 66 | return '%' . $this->filter['operand'] . '%'; |
| 67 | } |
| 68 | if ($this->filter['database_column'] === 'cached_date') { |
| 69 | try { |
| 70 | $date = \DateTime::createFromFormat('U', $this->filter['operand']); |
| 71 | } catch (\Throwable $e) { |
| 72 | $date = new \DateTime(); |
| 73 | } |
| 74 | return $date->format('Y-m-d'); |
| 75 | } |
| 76 | return $this->filter['operand']; |
| 77 | } |
| 78 | } |
| 79 |