FilterAction.php 996 B

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