FilterAction.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. class FreshRSS_FilterAction {
  3. /** @var FreshRSS_BooleanSearch */
  4. private $booleanSearch = null;
  5. private $actions = null;
  6. private function __construct($booleanSearch, $actions) {
  7. $this->booleanSearch = $booleanSearch;
  8. $this->_actions($actions);
  9. }
  10. public function booleanSearch() {
  11. return $this->booleanSearch;
  12. }
  13. public function actions() {
  14. return $this->actions;
  15. }
  16. public function _actions($actions) {
  17. if (is_array($actions)) {
  18. $this->actions = array_unique($actions);
  19. } else {
  20. $this->actions = null;
  21. }
  22. }
  23. public function toJSON() {
  24. if (is_array($this->actions) && $this->booleanSearch != null) {
  25. return array(
  26. 'search' => $this->booleanSearch->getRawInput(),
  27. 'actions' => $this->actions,
  28. );
  29. }
  30. return [];
  31. }
  32. public static function fromJSON($json) {
  33. if (!empty($json['search']) && !empty($json['actions']) && is_array($json['actions'])) {
  34. return new FreshRSS_FilterAction(new FreshRSS_BooleanSearch($json['search']), $json['actions']);
  35. }
  36. return null;
  37. }
  38. }