Newscoop\Service\Implementation\TemplateSearchServiceDoctrine::getArticlePage PHP Method

getArticlePage() public method

Get the page for article to be used as a template.
public getArticlePage ( Section | Int $section, Output | integer | string $output ) : string
$section Newscoop\Entity\Section | Int The section object or the id of the issue for whom the template is needed.
$output Newscoop\Entity\Output | integer | string The object Output, the id or the Name of the Output for whom the template is needed.
return string The full path of the template.
    public function getArticlePage($section, $output)
    {
        /** Get the id if an Output object tis supplied */
        /* @var $output Output */
        $outputId = $output;
        if ($output instanceof Output) {
            $outputId = $output->getId();
        }
        /** Get the id if an Section object tis supplied */
        /* @var $section Section */
        $sectionId = $section;
        if ($section instanceof Section) {
            $sectionId = $section->getId();
        }
        /* @var $outputSettingSection OutputSettingsSection */
        $outputSettingSection = $this->getOutputSettingSectionService()->findBySectionAndOutput($sectionId, $outputId);
        if (!is_null($outputSettingSection) && !is_null($resource = $outputSettingSection->getArticlePage())) {
            return $this->getResourceFullPath($resource);
        }
        if (!$section instanceof Section) {
            $section = $this->getSectionService()->findById($section);
        }
        /* @var $issue Issue */
        $issue = $section->getIssue();
        $issueId = $issue->getId();
        $publicationId = $issue->getPublicationId();
        $em = $this->getManager();
        $q = $em->createQueryBuilder();
        $q->select(array('oi', 'ot'))->from(OutputSettingsTheme::NAME, 'ot')->from(OutputSettingsIssue::NAME_1, 'oi')->where('ot.themePath = oi.themePath')->andWhere('ot.publication = :publication')->andWhere('ot.publication = :publication')->andWhere('ot.output = :output')->andWhere('oi.output = :output')->andWhere('oi.issue = :issue')->setParameter('output', $outputId)->setParameter('issue', $issueId)->setParameter('publication', $publicationId);
        $results = $q->getQuery()->getResult();
        if (count($results) < 2) {
            return '';
        }
        /* @var $outputSettingTheme OutputSettingsTheme */
        list(, $outputSettingTheme) = each($results);
        /* @var $outputSettingIssue OutputSettingsIssue */
        list(, $outputSettingIssue) = each($results);
        if (!is_null($resource = $outputSettingIssue->getArticlePage())) {
            return $this->getResourceFullPath($resource);
        }
        return $this->getResourceFullPath($outputSettingTheme->getArticlePage());
    }