Inheritance: extends DatabaseObject
Example #1
0
 public function serializeToJson(JsonSerializationVisitor $visitor, $data, $type)
 {
     $articleData = new \ArticleData($data->type, $data->number, $data->languageId);
     if (count($articleData->getUserDefinedColumns()) == 0) {
         return null;
     }
     $fields = array();
     foreach ($articleData->getUserDefinedColumns() as $column) {
         $fields[$column->getPrintName()] = $articleData->getFieldValue($column->getPrintName());
     }
     $fields['show_on_front_page'] = $data->onFrontPage == "Y" ? 1 : 0;
     $fields['show_on_section_page'] = $data->onSection == "Y" ? 1 : 0;
     return $fields;
 }
Example #2
0
 public function serialize(VisitorInterface $visitor, $data, $type, &$visited)
 {
     if ($type != 'Newscoop\\Entity\\Article') {
         return;
     }
     $GLOBALS['g_campsiteDir'] = realpath(__DIR__ . '/../../../../../../newscoop/');
     $articleData = new \ArticleData($data->getType(), $data->getNumber(), $data->getLanguageId());
     if (count($articleData->getUserDefinedColumns()) == 0) {
         $data->setFields(null);
         return;
     }
     $fields = array();
     foreach ($articleData->getUserDefinedColumns() as $column) {
         $fields[$column->getPrintName()] = $articleData->getFieldValue($column->getPrintName());
     }
     $data->setFields($fields);
 }
Example #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);
 }
Example #4
0
    /**
     * Delete article from database.  This will
     * only delete one specific translation of the article.
     *
     * @return boolean
     */
    public function delete()
    {
        // It is an optimization to put these here because in most cases
        // you dont need these files.
        require_once($GLOBALS['g_campsiteDir'].'/classes/ArticleImage.php');
        require_once($GLOBALS['g_campsiteDir'].'/classes/ArticleTopic.php');
        require_once($GLOBALS['g_campsiteDir'].'/classes/ArticleIndex.php');
        require_once($GLOBALS['g_campsiteDir'].'/classes/ArticleAttachment.php');
        require_once($GLOBALS['g_campsiteDir'].'/classes/ArticleComment.php');
        require_once($GLOBALS['g_campsiteDir'].'/classes/ArticlePublish.php');

        // Delete scheduled publishing
        ArticlePublish::OnArticleDelete($this->m_data['Number'], $this->m_data['IdLanguage']);

        // Delete Article Comments
        ArticleComment::OnArticleDelete($this->m_data['Number'], $this->m_data['IdLanguage']);

        // is this the last translation?
        if (count($this->getLanguages()) <= 1) {
            // Delete image pointers
            ArticleImage::OnArticleDelete($this->m_data['Number']);

            // Delete topics pointers
            ArticleTopic::OnArticleDelete($this->m_data['Number']);

            // Delete file pointers
            ArticleAttachment::OnArticleDelete($this->m_data['Number']);

            // Delete indexes
            ArticleIndex::OnArticleDelete($this->getPublicationId(), $this->getIssueNumber(),
                $this->getSectionNumber(), $this->getLanguageId(), $this->getArticleNumber());
        }

        // geo-map processing
        // is this the last translation?
        if (count($this->getLanguages()) <= 1) {
            // unlink the article-map pointers
            Geo_Map::OnArticleDelete($this->m_data['Number']);
        }
        else {
            // removing non-last translation of the map poi contents
            Geo_Map::OnLanguageDelete($this->m_data['Number'], $this->m_data['IdLanguage']);
        }

        // Delete row from article type table.
        $articleData = new ArticleData($this->m_data['Type'],
            $this->m_data['Number'],
            $this->m_data['IdLanguage']);
        $articleData->delete();

        $tmpObj = clone $this; // for log
        $tmpData = $this->m_data;
        $tmpData['languageName'] = $this->getLanguageName();
        // Delete row from Articles table.
        $deleted = parent::delete();

        if ($deleted) {
            if (function_exists("camp_load_translation_strings")) {
                camp_load_translation_strings("api");
            }
            Log::ArticleMessage($tmpObj, getGS('Article deleted.'), null, 32);
        }
        $this->m_cacheUpdate = true;
        return $deleted;
    } // fn delete
Example #5
0
 /**
  * Delete article from database.  This will
  * only delete one specific translation of the article.
  *
  * @return boolean
  */
 public function delete()
 {
     // It is an optimization to put these here because in most cases
     // you dont need these files.
     require_once $GLOBALS['g_campsiteDir'] . '/classes/ArticleImage.php';
     require_once $GLOBALS['g_campsiteDir'] . '/classes/ArticleTopic.php';
     require_once $GLOBALS['g_campsiteDir'] . '/classes/ArticleIndex.php';
     require_once $GLOBALS['g_campsiteDir'] . '/classes/ArticleAttachment.php';
     require_once $GLOBALS['g_campsiteDir'] . '/classes/ArticlePublish.php';
     // Delete scheduled publishing
     ArticlePublish::OnArticleDelete($this->m_data['Number'], $this->m_data['IdLanguage']);
     $translator = \Zend_Registry::get('container')->getService('translator');
     // Delete Article Comments
     // @todo change this with DOCTRINE2 CASCADE DELETE
     $em = Zend_Registry::get('container')->getService('em');
     $repository = $em->getRepository('Newscoop\\Entity\\Comment');
     $repository->deleteArticle($this->m_data['Number'], $this->m_data['IdLanguage']);
     $repository = $em->getRepository('Newscoop\\Entity\\ArticleDatetime');
     $repository->deleteByArticle($this->m_data['Number']);
     $em->flush();
     // is this the last translation?
     if (count($this->getLanguages()) <= 1) {
         // Delete image pointers
         ArticleImage::OnArticleDelete($this->m_data['Number']);
         // Delete topics pointers
         ArticleTopic::OnArticleDelete($this->m_data['Number']);
         // Delete file pointers
         ArticleAttachment::OnArticleDelete($this->m_data['Number']);
         // Delete related articles
         ContextBox::OnArticleDelete($this->m_data['Number']);
         ContextBoxArticle::OnArticleDelete($this->m_data['Number']);
         // Delete the article from playlists
         $em = Zend_Registry::get('container')->getService('em');
         $repository = $em->getRepository('Newscoop\\Entity\\PlaylistArticle');
         $repository->deleteArticle($this->m_data['Number']);
         $em->flush();
         // Delete indexes
         ArticleIndex::OnArticleDelete($this->getPublicationId(), $this->getIssueNumber(), $this->getSectionNumber(), $this->getLanguageId(), $this->getArticleNumber());
     }
     // geo-map processing
     // is this the last translation?
     if (count($this->getLanguages()) <= 1) {
         // unlink the article-map pointers
         Geo_Map::OnArticleDelete($this->m_data['Number']);
     } else {
         // removing non-last translation of the map poi contents
         Geo_Map::OnLanguageDelete($this->m_data['Number'], $this->m_data['IdLanguage']);
     }
     // Delete row from article type table.
     $articleData = new ArticleData($this->m_data['Type'], $this->m_data['Number'], $this->m_data['IdLanguage']);
     $articleData->delete();
     $tmpObj = clone $this;
     // for log
     $tmpData = $this->m_data;
     $tmpData['languageName'] = $this->getLanguageName();
     // Delete row from Articles table.
     $deleted = parent::delete();
     if ($deleted) {
         $cacheService = \Zend_Registry::get('container')->getService('newscoop.cache');
         $cacheService->clearNamespace('article');
         Log::ArticleMessage($tmpObj, $translator->trans('Article deleted.', array(), 'api'), null, 32);
     }
     $this->m_cacheUpdate = true;
     return $deleted;
 }
Example #6
0
 /**
  * Create new article
  *
  * @param string  $articleType
  * @param integer $language
  * @param User    $user
  * @param integer $publication
  * @param array   $attributes
  * @param integer $issue
  * @param integer $section
  *
  * @return Article
  */
 public function createArticle($articleType, $language, $user, $publication, $attributes = array(), $issue = null, $section = null)
 {
     $this->checkForArticleConflicts($attributes['name'], $publication, $issue, $section);
     $article = new Article($this->em->getRepository('Newscoop\\Entity\\AutoId')->getNextArticleNumber(), $language);
     if (!$section) {
         $articleOrder = $article->getNumber();
     } else {
         $minArticleOrder = $this->em->getRepository('Newscoop\\Entity\\Article')->getMinArticleOrder($publication, $issue, $section)->getSingleScalarResult();
         $increment = $minArticleOrder > 0 ? 1 : 2;
         $this->em->getRepository('Newscoop\\Entity\\Article')->updateArticleOrder($increment, $publication, $issue, $section)->getResult();
         $articleOrder = 1;
     }
     $article->setArticleOrder($articleOrder);
     $article->setPublication($publication);
     $article->setType($articleType);
     $article->setCreator($user);
     $article->setIssueId(0);
     $article->setSectionId(0);
     if (!is_null($issue)) {
         $article->setIssueId($issue->getNumber());
         $article->setIssue($issue);
     }
     if (!is_null($section)) {
         $article->setSectionId($section->getNumber());
         $article->setSection($section);
     }
     $this->updateArticleMeta($article, $attributes);
     $article->setCommentsLocked(false);
     //TODO - add this to type
     $article->setWorkflowStatus('N');
     $article->setShortName($article->getNumber());
     $article->setLockTime(null);
     $article->setPublished(new \Datetime());
     $article->setUploaded(new \Datetime());
     $article->setLockUser();
     $article->setPublic('Y');
     $article->setIsIndexed('N');
     $this->em->persist($article);
     $this->em->flush();
     $articleData = new \ArticleData($article->getType(), $article->getNumber(), $article->getLanguageId());
     $articleData->create();
     return $article;
 }
Example #7
0
 /**
  * Add field properties to document
  *
  * @param  array $doc
  *
  * @return array
  */
 private function addDataFields(array $doc, $article)
 {
     $articleData = new \ArticleData($article->getType(), $article->getNumber(), $article->getLanguageId());
     if (count($articleData->getUserDefinedColumns()) == 0) {
         return $doc;
     }
     $fields = array();
     foreach ($articleData->getUserDefinedColumns() as $column) {
         $doc[$column->getPrintName()] = $articleData->getFieldValue($column->getPrintName());
     }
     return $doc;
 }