Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add form filter to post statics #4723

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 60 additions & 3 deletions src/Ushahidi/Modules/V5/DTO/PostStatsSearchFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ??

Expand All @@ -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
Expand Down Expand Up @@ -74,6 +91,7 @@ public function includeUnmapped()
{
return $this->include_unmapped;
}


public function status(): array
{
Expand All @@ -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;
}
}
Loading