Newscoop\Service\Implementation\ThemeManagementServiceLocal::getArticleTypes PHP Method

getArticleTypes() public method

Author: mihaibalaceanu
public getArticleTypes ( Theme $theme ) : object
$theme Newscoop\Entity\Theme
return object
    public function getArticleTypes(Theme $theme)
    {
        Validation::notEmpty($theme, 'theme');
        $xml = $this->loadXML($this->toFullPath($theme, $this->themeConfigFileName));
        $ret = new \stdClass();
        // getting the article types
        foreach ($xml->xpath('/' . self::TAG_ROOT . '/' . self::TAG_ARTICLE_TYPE) as $artType) {
            $artTypeName = (string) $this->readAttribute($artType, self::ATTR_ARTICLE_TYPE_NAME);
            // set article type name on return array
            $ret->{$artTypeName} = new \stdClass();
            // getting the article type fields
            foreach ($xml->xpath('/' . self::TAG_ROOT . '/' . self::TAG_ARTICLE_TYPE . '[@' . self::ATTR_ARTICLE_TYPE_NAME . '=(\'' . $artTypeName . '\')]/*') as $artTypeField) {
                try {
                    $ret->{$artTypeName}->{(string) $artTypeField[self::ATTR_ARTICLE_TYPE_FILED_NAME]} = (object) array(self::ATTR_ARTICLE_TYPE_FILED_TYPE => (string) $artTypeField[self::ATTR_ARTICLE_TYPE_FILED_TYPE], self::ATTR_ARTICLE_TYPE_FILED_LENGTH => (string) $artTypeField[self::ATTR_ARTICLE_TYPE_FILED_LENGTH]);
                } catch (\Exception $e) {
                }
            }
        }
        return $ret;
    }