/**
  * Constructor
  *
  * @param string $p_content
  */
 public function __construct($p_content, MetaArticle $p_parent, $p_fieldName, $p_articleName, $p_subtitleNumber = null, $p_headerFormatStart = null, $p_headerFormatEnd = null)
 {
     $this->m_subtitleNumber = $p_subtitleNumber;
     $this->m_subtitles = MetaSubtitle::ReadSubtitles($p_content, $p_fieldName, $p_articleName, $p_headerFormatStart, $p_headerFormatEnd);
     $this->m_sutitlesNames = array();
     foreach ($this->m_subtitles as $subtitle) {
         $this->m_sutitlesNames[] = $subtitle->name;
     }
     $cacheService = \Zend_Registry::get('container')->getService('newscoop.cache');
     $cacheKeyArticle = $cacheService->getCacheKey(array('Article', $p_parent->language->number, $p_parent->number), 'article');
     if ($cacheService->contains($cacheKeyArticle)) {
         $this->m_parent_article = $cacheService->fetch($cacheKeyArticle);
     } else {
         $this->m_parent_article = new Article($p_parent->language->number, $p_parent->number);
         $cacheService->save($cacheKeyArticle, $this->m_parent_article);
     }
     $this->m_fieldName = $p_fieldName;
     $cacheKey = $cacheService->getCacheKey(array('ArticleTypeField', $p_parent->type_name, $p_fieldName), 'article_type');
     if ($cacheService->contains($cacheKey)) {
         $this->m_articleTypeField = $cacheService->fetch($cacheKey);
     } else {
         $articleTypeField = new ArticleTypeField($p_parent->type_name, $p_fieldName);
         $cacheService->save($cacheKey, $articleTypeField);
         $this->m_articleTypeField = $articleTypeField;
     }
 }
Пример #2
0
 /**
  * Constructor
  *
  * @param string $p_content
  */
 public function __construct($p_content, MetaArticle $p_parent, $p_fieldName, $p_articleName, $p_subtitleNumber = null, $p_headerFormatStart = null, $p_headerFormatEnd = null)
 {
     $this->m_subtitleNumber = $p_subtitleNumber;
     $this->m_subtitles = MetaSubtitle::ReadSubtitles($p_content, $p_fieldName, $p_articleName, $p_headerFormatStart, $p_headerFormatEnd);
     $this->m_sutitlesNames = array();
     foreach ($this->m_subtitles as $subtitle) {
         $this->m_sutitlesNames[] = $subtitle->name;
     }
     $this->m_parent_article = new Article($p_parent->language->number, $p_parent->number);
     $this->m_fieldName = $p_fieldName;
     $this->m_articleTypeField = new ArticleTypeField($p_parent->type_name, $p_fieldName);
 }
Пример #3
0
 /**
  * Creates the list of objects. Sets the parameter $p_hasNextElements to
  * true if this list is limited and elements still exist in the original
  * list (from which this was truncated) after the last element of this
  * list.
  *
  * @param int $p_start
  * @param int $p_limit
  * @param array $p_parameters
  * @param int &$p_count
  * @return array
  */
 protected function CreateList($p_start = 0, $p_limit = 0, array $p_parameters, &$p_count)
 {
     $context = CampTemplate::singleton()->context();
     if (!$context->article->defined) {
         return array();
     }
     $articleData = new ArticleData($context->article->type_name, $context->article->number, $context->language->number);
     $customFields = $articleData->getUserDefinedColumns();
     $fieldValue = null;
     foreach ($customFields as $customField) {
         if (strtolower($customField->getPrintName()) == strtolower($p_parameters['field_name'])) {
             $p_parameters['field_name'] = $customField->getPrintName();
             $fieldValue = $articleData->getProperty('F' . $p_parameters['field_name']);
             break;
         }
     }
     if (is_null($fieldValue)) {
         return array();
     }
     $subtitles = MetaSubtitle::ReadSubtitles($fieldValue, $p_parameters['field_name'], $context->article->name);
     $p_count = count($subtitles);
     return $p_limit !== 0 ? array_slice($subtitles, $p_start, $p_limit) : array_slice($subtitles, $p_start);
 }
Пример #4
0
    /**
     * Reads the subtitles from the given content
     *
     * @param string $p_content
     * @param string $p_firstSubtitle
     * @return array of MetaSubtitle
     */
    public static function ReadSubtitles($p_content, $p_fieldName, $p_firstSubtitle = '',
    $p_headerFormatStart = null, $p_headerFormatEnd = null) {
        $result = preg_match_all('/('.MetaSubtitle::GetFindPattern().')/i', $p_content, $subtitlesNames);

        $contentParts = preg_split('/'.MetaSubtitle::GetSplitPattern().'/i', $p_content);
        $subtitlesContents = array();
        foreach ($contentParts as $index=>$contentPart) {
            $name = $index > 0 ? $subtitlesNames[3][$index-1] : $p_firstSubtitle;
            if (empty($p_headerFormatStart)) {
                $formatStart = $index > 0 ? $subtitlesNames[2][$index-1] : '';
            } else {
                $formatStart = $p_headerFormatStart;
            }
            if (empty($p_headerFormatEnd)) {
                $formatEnd = $index > 0 ? $subtitlesNames[4][$index-1] : '';
            } else {
                $formatEnd = $p_headerFormatEnd;
            }
            $subtitles[] = new MetaSubtitle($index, $p_fieldName, count($contentParts),
            $name, $contentPart, $formatStart, $formatEnd);
        }
        return $subtitles;
    }
Пример #5
0
 private function setSubtitleHandler(MetaSubtitle $p_oldSubtitle, MetaSubtitle $p_newSubtitle)
 {
     if (!$p_oldSubtitle->same_as($p_newSubtitle)) {
         $this->m_objects['subtitle'] = $p_newSubtitle;
     }
 }