mapByProperties($this->getProps(), $item); } /** * Summarize an announcement * * Includes properties with the apiSummary flag in the announcement schema. */ public function summarize(Announcement $item): array { return $this->mapByProperties($this->getSummaryProps(), $item); } /** * Map a collection of Announcements * * @see self::map */ public function mapMany(Enumerable $collection): Enumerable { $this->collection = $collection; return $collection->map(function ($item) { return $this->map($item); }); } /** * Summarize a collection of Announcements * * @see self::summarize */ public function summarizeMany(Enumerable $collection): Enumerable { $this->collection = $collection; return $collection->map(function ($item) { return $this->summarize($item); }); } /** * Map schema properties of an Announcement to an assoc array */ protected function mapByProperties(array $props, Announcement $item): array { $output = []; foreach ($props as $prop) { switch ($prop) { case '_href': $output[$prop] = $this->getApiUrl('announcements/' . $item->getId()); break; case 'url': $output[$prop] = $this->request->getDispatcher()->url( $this->request, PKPApplication::ROUTE_PAGE, $this->getUrlPath(), 'announcement', 'view', $item->getId() ); break; default: $output[$prop] = $item->getData($prop); break; } } $output = $this->schemaService->addMissingMultilingualValues($this->schema, $output, $this->getSupportedLocales()); ksort($output); return $this->withExtensions($output, $item); } protected function getUrlPath(): string { if (isset($this->context)) { return $this->context->getData('urlPath'); } return 'index'; } protected function getSupportedLocales(): array { if (isset($this->context)) { return $this->context->getSupportedFormLocales(); } return Application::get()->getRequest()->getSite()->getSupportedLocales(); } }