Skip to content

Commit 114723c

Browse files
authored
Merge branch 'develop' into develop
2 parents 48009e0 + 9d34dc6 commit 114723c

File tree

3 files changed

+27
-12
lines changed

3 files changed

+27
-12
lines changed

src/Ushahidi/Modules/V5/Actions/SavedSearch/Queries/FetchSavedSearchByIdQuery.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ public static function fromRequest(int $id, Request $request): self
2727
throw new \InvalidArgumentException('Id must be a positive number');
2828
}
2929
$query = new self($id);
30-
$query->addOnlyParameteresFromRequest($request, SavedSearch::ALLOWED_FIELDS, SavedSearch::ALLOWED_RELATIONSHIPS, SavedSearch::REQUIRED_FIELDS);
30+
$excluded_relations = ['posts'];
31+
$query->addOnlyParameteresFromRequest($request, SavedSearch::ALLOWED_FIELDS, SavedSearch::ALLOWED_RELATIONSHIPS, SavedSearch::REQUIRED_FIELDS, $excluded_relations);
3132
return $query;
3233
}
3334

src/Ushahidi/Modules/V5/Actions/SavedSearch/Queries/FetchSavedSearchQuery.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ public static function fromRequest(Request $request): self
2525
$query = new self();
2626
$query->setPaging($request, self::DEFAULT_SORT_BY, self::DEFAULT_ORDER, self::DEFAULT_LIMIT);
2727
$query->setSearchFields(new SavedSearchSearchFields($request));
28-
$query->addOnlyParameteresFromRequest($request, Set::ALLOWED_FIELDS, Set::ALLOWED_RELATIONSHIPS, Set::REQUIRED_FIELDS);
28+
$excluded_relations = ['posts'];
29+
$query->addOnlyParameteresFromRequest($request, Set::ALLOWED_FIELDS, Set::ALLOWED_RELATIONSHIPS, Set::REQUIRED_FIELDS, $excluded_relations);
2930
return $query;
3031
}
3132
}

src/Ushahidi/Modules/V5/Traits/OnlyParameter/QueryWithOnlyParameter.php

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
trait QueryWithOnlyParameter
88
{
9-
/**
9+
/**
1010
* @var array
1111
*/
1212
private $fields;
@@ -46,10 +46,14 @@ public function getFieldsForRelationship(): array
4646
* @param Request $request
4747
* @param array $approved_fields
4848
*/
49-
private function getOnlyValuesFromRequest(Request $request, array $allowed_fields, array $allowed_relations): void
50-
{
49+
private function getOnlyValuesFromRequest(
50+
Request $request,
51+
array $allowed_fields,
52+
array $allowed_relations,
53+
array $excluded_relations = [] // exclude them if they are not in only in request
54+
): void {
5155
$this->fields = $allowed_fields;
52-
$this->hydrates = array_keys($allowed_relations);
56+
$this->hydrates = array_diff(array_keys($allowed_relations), $excluded_relations);
5357

5458
if ($request->query('format') === 'minimal') {
5559
$this->fields = ['id', 'name', 'description', 'translations'];
@@ -88,15 +92,24 @@ private function getNeededRelations(array $allowed_relations)
8892
}
8993
}
9094
}
91-
public function addOnlyParameteresFromRequest(Request $request, array $allowed_fields, array $allowed_relations, array $required_fields): void
92-
{
93-
$this->getOnlyValuesFromRequest($request, $allowed_fields, $allowed_relations);
95+
public function addOnlyParameteresFromRequest(
96+
Request $request,
97+
array $allowed_fields,
98+
array $allowed_relations,
99+
array $required_fields,
100+
array $relations_to_prune = [] // exclude them if they are not in request
101+
): void {
102+
$this->getOnlyValuesFromRequest($request, $allowed_fields, $allowed_relations, $relations_to_prune);
94103
$this->fields = array_unique(array_merge($this->fields, $required_fields));
95104
$this->getNeededRelations($allowed_relations);
96105
}
97-
98-
public function addOnlyValues(array $fields, array $hydrates, array $allowed_relations, array $required_fields)
99-
{
106+
107+
public function addOnlyValues(
108+
array $fields,
109+
array $hydrates,
110+
array $allowed_relations,
111+
array $required_fields
112+
) {
100113
$this->fields = $fields;
101114
$this->hydrates = $hydrates;
102115
$this->fields = array_unique(array_merge($this->fields, $required_fields));

0 commit comments

Comments
 (0)