From 0d878da35fe58fb63699371fa315caee13ede2a4 Mon Sep 17 00:00:00 2001 From: Mh-Asmi Date: Thu, 15 Feb 2024 14:56:33 +0400 Subject: [PATCH] add form filter to post statics --- .../Modules/V5/DTO/PostStatsSearchFields.php | 63 ++++++++++++++++++- 1 file changed, 60 insertions(+), 3 deletions(-) diff --git a/src/Ushahidi/Modules/V5/DTO/PostStatsSearchFields.php b/src/Ushahidi/Modules/V5/DTO/PostStatsSearchFields.php index 002ea645e9..ccb6dcaf44 100644 --- a/src/Ushahidi/Modules/V5/DTO/PostStatsSearchFields.php +++ b/src/Ushahidi/Modules/V5/DTO/PostStatsSearchFields.php @@ -14,8 +14,9 @@ class PostStatsSearchFields extends PostSearchFields private $timeline_attribute; private $timeline_interval; private $include_unmapped; - - public $include_unformed; + protected $form; + protected $form_condition; + public $include_unstructured_posts; // getFilter ?? @@ -31,7 +32,23 @@ public function __construct(Request $request) $this->timeline_attribute = $request->query('timeline_attribute'); $this->timeline_interval = $request->query('timeline_interval'); $this->include_unmapped = $request->query('include_unmapped'); - $this->include_unformed = $request->query('include_unformed'); + $this->include_unstructured_posts = $request->query('include_unstructured_posts'); + $this->form_condition = "all"; + $this->form = []; // no conditions + if (!$request->has('form')) { + if ($request->has('include_unstructured_posts') && !$request->get('include_unstructured_posts')) { + $this->form_condition = "not_null"; + $this->form = []; // no conditions + } + } else { + if ($request->get('form') == 'none') { + $this->form = []; // no conditions + $this->form_condition = "null"; + } else { + $this->form_condition = "include"; + $this->form = $this->getParameterAsArray($request->get('form')); + } + } } public function groupBy(): ?string @@ -74,6 +91,7 @@ public function includeUnmapped() { return $this->include_unmapped; } + public function status(): array { @@ -82,4 +100,43 @@ public function status(): array } return parent::status(); } + + public function includeUnstructuredPosts() + { + return $this->include_unstructured_posts; + } + + public function form(): array + { + return $this->form; + } + + public function excludeFormIds($excluded_form_ids) + { + if (!empty($excluded_form_ids)) { + if (!empty($this->form)) { + $this->form = array_diff($this->form, $excluded_form_ids); + } elseif ($this->form_condition != "null") { + $this->form = $excluded_form_ids; + $this->form_condition = "exclude"; + } + } + } + + public function formCondition(): string + { + return $this->form_condition; + } + private function getParameterAsArray($parameter_value) + { + $filter_values = []; + if ($parameter_value) { + if (is_array($parameter_value)) { + $filter_values = $parameter_value; + } else { + $filter_values = explode(',', $parameter_value); + } + } + return $filter_values; + } }