Skip to content

Commit

Permalink
Merge pull request #99 from biglotteryfund/rework-our-people
Browse files Browse the repository at this point in the history
Rework our people endpoint
  • Loading branch information
davidrapson authored Oct 30, 2018
2 parents 84f5ff0 + c33c8c0 commit 4d99f90
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 25 deletions.
3 changes: 1 addition & 2 deletions config/element-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ function getFundingProgramme($locale, $slug)
/**
* API Endpoint: Get our people
*/
function getOurPeople($locale, $slug = null)
function getOurPeople($locale)
{
normaliseCacheHeaders();

Expand All @@ -321,7 +321,6 @@ function getOurPeople($locale, $slug = null)
'elementType' => Entry::class,
'criteria' => [
'site' => $locale,
'slug' => $slug,
'section' => 'people',
'status' => EntryHelpers::getVersionStatuses(),
],
Expand Down
6 changes: 2 additions & 4 deletions lib/ContentHelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@

class ContentHelpers
{
public static function getCommonDetailFields(Entry $entry, $locale)
public static function getCommonDetailFields(Entry $entry, $status, $locale)
{
list('entry' => $entry, 'status' => $status) = EntryHelpers::getDraftOrVersionOfEntry($entry);

return [
'id' => $entry->id,
'status' => $status,
'slug' => $entry->slug,
'status' => $status,
'postDate' => $entry->postDate,
'dateCreated' => $entry->dateCreated,
'dateUpdated' => $entry->dateUpdated,
Expand Down
44 changes: 26 additions & 18 deletions lib/People.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,40 @@ public function __construct($locale)
public function transform(Entry $entry)
{
list('entry' => $entry, 'status' => $status) = EntryHelpers::getDraftOrVersionOfEntry($entry);
$common = ContentHelpers::getCommonDetailFields($entry, $this->locale);

$documents = $entry->documents->one();
$common = ContentHelpers::getCommonDetailFields($entry, $status, $this->locale);

return array_merge($common, [
'people' => array_map(function ($person) {
$image = $person->personPhoto->one() ?? null;
return [
'name' => $person->personName,
'role' => $person->personRole ?? null,
'image' => Images::extractImageUrl($person->personPhoto),
'bio' => $person->personBio
'image' => $image ? [
// Is the source image large or small?
// Used to determine what layout to use
'type' => $image->width > 500 ? 'large' : 'small',
'url' => Images::imgixUrl(
$image->url,
['fit' => 'crop', 'crop' => 'entropy', 'max-w' => 1200]
),
] : null,
'bio' => $person->personBio,
];
}, $entry->people->all() ?? []),
'documents' => $documents ? [
'title' => $documents->documentsTitle,
'files' => array_map(function ($document) {
$file = $document->documentFile->one();
return [
'label' => $document->documentTitle,
'caption' => $document->documentDescription ?? null,
'href' => $file->url,
'filetype' => $file->kind,
'filesize' => StringHelpers::formatBytes($file->size, $precision = 0),
];
}, $documents->documents->all() ?? []),
] : null
'documentGroups' => array_map(function ($group) {
return [
'title' => $group->documentsTitle,
'files' => array_map(function ($file) {
return [
'label' => $file->title,
'href' => $file->url,
'filetype' => $file->extension,
'filesize' => StringHelpers::formatBytes($file->size, $precision = 0),
];
}, $group->documentsFiles->all() ?? []),
'extraContent' => $group->documentsExtra ?? null,
];
}, $entry->documentGroups->all() ?? []),
]);
}
}
3 changes: 2 additions & 1 deletion lib/Research.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public function __construct($locale)
public function transform(Entry $entry)
{
list('entry' => $entry, 'status' => $status) = EntryHelpers::getDraftOrVersionOfEntry($entry);
$common = ContentHelpers::getCommonDetailFields($entry, $this->locale);
$common = ContentHelpers::getCommonDetailFields($entry, $status, $this->locale);

$researchMeta = $entry->researchMeta->one();

$heroImageField = Images::extractImage($entry->heroImage);
Expand Down

0 comments on commit 4d99f90

Please sign in to comment.