Newscoop\Article\LinkService::getLink PHP Метод

    public function getLink(Article $article)
    {
        if (!$article->isPublished()) {
            return null;
        }
        $link = array($this->getPublicationAliasName($article), $article->getLanguage() ? $article->getLanguage()->getCode() : null, $this->getIssueShortName($article), $this->getSectionShortName($article));
        if (!in_array($article->getType(), $this->sectionTypes)) {
            $link[] = $article->getNumber();
            $link[] = $this->getSeo($article, $article->getPublication() ? $article->getPublication()->getSeo() : array());
        }
        $link = array_map(function ($part) {
            return trim($part, '/');
        }, $link);
        $link = implode('/', $link);
        return strpos($link, 'http') === 0 ? $link : 'http://' . $link;
    }

Usage Example

Пример #1
0
 /**
  * Get document for comment
  *
  * @param Newscoop\Entity\Comment $comment
  * @return array
  */
 public function getDocument(DocumentInterface $comment)
 {
     $articleNumber = $comment->getThread();
     $language = $comment->getLanguage();
     $article = $this->em->getRepository('Newscoop\\Entity\\Article')->find(array('number' => $articleNumber, 'language' => $language->getId()));
     return array('id' => $this->getDocumentId($comment), 'number' => $comment->getId(), 'type' => 'comment', 'subject' => $comment->getSubject(), 'message' => $comment->getMessage(), 'published' => gmdate(self::DATE_FORMAT, $comment->getTimeCreated()->getTimestamp()), 'link' => sprintf('%s#comment_%d', $this->articleLinkService->getLink($article), $comment->getId()));
 }
All Usage Examples Of Newscoop\Article\LinkService::getLink