public function getItems($offset, $itemCountPerPage) { $resultSet = parent::getItems($offset, $itemCountPerPage); $highlighting = $resultSet->getHighlighting(); $items = []; $filter = new PreviewFilter(); foreach ($resultSet as $document) { $highlightedDoc = $highlighting->getResult($document->id); $id = $document['id']; $title = $document['title']; $content = implode(' ... ', $highlightedDoc->getField('content')); $type = ucfirst($document['content_type']); $keywords = explode(SolrAdapter::KEYWORD_DELIMITER, $document['keywords']); if ($type) { $type = $this->getTranslator()->translate($type); } if ($content) { $content = '... ' . $content . ' ...'; } else { $content = $filter->filter($document['content']); } $item = new Document($id, $title, $content, $type, $id, $keywords); $items[] = $item; } return $items; }
public function toPreview($object) { /* @var $markdown MarkdownHelper */ $markdown = $this->getView()->plugin('markdown'); $normalized = $this->normalize($object); $filter = new PreviewFilter(152); $content = $normalized->getContent(); $content = $markdown->toHtml($content); $preview = $filter->filter($content); return $preview; }
/** * @param UuidInterface $object * @param array $keys * @param string $separator * @return $this */ public function keywords(UuidInterface $object, array $keys = [], $separator = ', ') { $data = []; if (!empty($keys)) { $metadata = []; foreach ($keys as $key) { $metadata[] = implode($this->metadataManager->findMetadataByObjectAndKey($object, $key), $separator); } } else { $metadata = $this->metadataManager->findMetadataByObject($object); } foreach ($metadata as $object) { /* @var $object MetadataInterface */ $data[] = $object->getValue(); } $filter = new PreviewFilter(250); $data = implode($data, $separator); $data = $filter->filter($data); $this->getView()->headMeta()->setProperty('keywords', $data); return $this; }
protected function normalize(Collection $collection) { $data = []; foreach ($collection as $entity) { $normalized = $this->normalizer->normalize($entity); $description = $normalized->getMetadata()->getDescription(); try { $description = $this->renderService->render($description); } catch (RuntimeException $e) { // nothing to do } $authors = $entity->getRevisions()->map(function ($revision) { return $revision->getAuthor()->getId(); }); $description = $this->descriptionFilter->filter($description); $item = ['title' => $normalized->getTitle(), 'description' => $description, 'guid' => (string) $entity->getId(), 'keywords' => $normalized->getMetadata()->getKeywords(), 'categories' => $this->getCategories($entity), 'link' => $this->url()->fromRoute($normalized->getRouteName(), $normalized->getRouteParams()), 'lastModified' => $normalized->getMetadata()->getLastModified(), 'authorsCount' => count(array_unique($authors->toArray())), 'revisionsCount' => $entity->getRevisions()->count()]; $data[] = $item; } return $data; }
/** * @param string $text * @param int $length * @return string */ public function __invoke($text, $length = 152) { $filter = new PreviewFilter($length); return $filter->filter($text); }