-
Notifications
You must be signed in to change notification settings - Fork 506
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'USH-1529' of https://github.com/ushahidi/platform into …
…USH-1529
- Loading branch information
Showing
12 changed files
with
424 additions
and
286 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
src/Ushahidi/Modules/V5/Actions/Survey/HandleSurveyOnlyParameters.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
namespace Ushahidi\Modules\V5\Actions\Survey; | ||
|
||
use Ushahidi\Modules\V5\Actions\Survey\Queries\FetchTasksBySurveyIdQuery; | ||
use Ushahidi\Modules\V5\Actions\Survey\Queries\FetchRolesCanCreateSurveyPostsQuery; | ||
|
||
trait HandleSurveyOnlyParameters | ||
{ | ||
private function addHydrateRelationships(&$survey, $only, $hydrate) | ||
{ | ||
$relations = [ | ||
'tasks' => false, | ||
'translations' => false, | ||
'enabled_languages' => false, | ||
]; | ||
|
||
foreach ($hydrate as $relation) { | ||
switch ($relation) { | ||
case 'can_create': | ||
$this->addCanCreate($survey); | ||
break; | ||
case 'tasks': | ||
$survey->tasks = $this->queryBus->handle( | ||
new FetchTasksBySurveyIdQuery( | ||
$survey->id, | ||
FetchTasksBySurveyIdQuery::DEFAULT_SORT_BY, | ||
FetchTasksBySurveyIdQuery::DEFAULT_ORDER | ||
) | ||
); | ||
$relations['tasks'] = true; | ||
break; | ||
case 'translations': | ||
$relations['translations'] = true; | ||
break; | ||
case 'enabled_languages': | ||
$survey->enabled_languages = [ | ||
'default' => $survey->base_language, | ||
'available' => $survey->translations->groupBy('language')->keys() | ||
]; | ||
$relations['enabled_languages'] = true; | ||
break; | ||
} | ||
} | ||
|
||
if (!$relations['tasks']) { | ||
$survey->tasks = null; | ||
} | ||
if (!$relations['translations']) { | ||
$survey->translations = null; | ||
} | ||
} | ||
private function addCanCreate(&$survey) | ||
{ | ||
$survey_roles = $this->queryBus->handle( | ||
new FetchRolesCanCreateSurveyPostsQuery( | ||
$survey->id, | ||
FetchRolesCanCreateSurveyPostsQuery::DEFAULT_SORT_BY, | ||
FetchRolesCanCreateSurveyPostsQuery::DEFAULT_ORDER | ||
) | ||
); | ||
$roles = []; | ||
foreach ($survey_roles as $survey_role) { | ||
$roles[] = $survey_role->role()->value('name'); | ||
} | ||
$survey->can_create = $roles; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.