/** * Create a copy of the article, but make it a translation * of the current one. * * @param int $p_languageId * @param int $p_userId * @param string $p_name * @return Article */ public function createTranslation($p_languageId, $p_userId, $p_name) { $translator = \Zend_Registry::get('container')->getService('translator'); // Construct the duplicate article object. $articleCopy = new Article(); $articleCopy->m_data['IdPublication'] = $this->m_data['IdPublication']; $articleCopy->m_data['NrIssue'] = $this->m_data['NrIssue']; $articleCopy->m_data['NrSection'] = $this->m_data['NrSection']; $articleCopy->m_data['IdLanguage'] = $p_languageId; $articleCopy->m_data['Number'] = $this->m_data['Number']; $values = array(); // Copy some attributes $values['ShortName'] = $this->m_data['ShortName']; $values['Type'] = $this->m_data['Type']; $values['OnFrontPage'] = $this->m_data['OnFrontPage']; $values['OnSection'] = $this->m_data['OnFrontPage']; $values['Public'] = $this->m_data['Public']; $values['ArticleOrder'] = $this->m_data['ArticleOrder']; $values['comments_enabled'] = $this->m_data['comments_enabled']; $values['comments_locked'] = $this->m_data['comments_locked']; $values['rating_enabled'] = $this->m_data['rating_enabled']; // Change some attributes $values['Name'] = $p_name; $values['Published'] = 'N'; $values['IsIndexed'] = 'N'; $values['IdUser'] = $p_userId; // Create the record $success = $articleCopy->__create($values); if (!$success) { return false; } $articleCopy->setProperty('UploadDate', 'NOW()', true, true); $articleCopy->setProperty('LockUser', 'NULL', true, true); $articleCopy->setProperty('LockTime', 'NULL', true, true); // Insert an entry into the article type table. $articleCopyData = new ArticleData($articleCopy->m_data['Type'], $articleCopy->m_data['Number'], $articleCopy->m_data['IdLanguage']); $articleCopyData->create(); $origArticleData = $this->getArticleData(); $origArticleData->copyToExistingRecord($articleCopy->getArticleNumber(), $p_languageId); $logtext = $translator->trans('Article translated to $4 ($5)', array('$4' => $articleCopy->getTitle(), '$5' => $articleCopy->getLanguageName()), 'api'); Log::ArticleMessage($this, $logtext, null, 31); // geo-map processing Geo_Map::OnCreateTranslation($this->m_data['Number'], $this->m_data['IdLanguage'], $p_languageId); return $articleCopy; }
/** * Create a copy of the article, but make it a translation * of the current one. * * @param int $p_languageId * @param int $p_userId * @param string $p_name * @return Article */ public function createTranslation($p_languageId, $p_userId, $p_name) { // Construct the duplicate article object. $articleCopy = new Article(); $articleCopy->m_data['IdPublication'] = $this->m_data['IdPublication']; $articleCopy->m_data['NrIssue'] = $this->m_data['NrIssue']; $articleCopy->m_data['NrSection'] = $this->m_data['NrSection']; $articleCopy->m_data['IdLanguage'] = $p_languageId; $articleCopy->m_data['Number'] = $this->m_data['Number']; $values = array(); // Copy some attributes $values['ShortName'] = $this->m_data['ShortName']; $values['Type'] = $this->m_data['Type']; $values['OnFrontPage'] = $this->m_data['OnFrontPage']; $values['OnSection'] = $this->m_data['OnFrontPage']; $values['Public'] = $this->m_data['Public']; $values['ArticleOrder'] = $this->m_data['ArticleOrder']; $values['comments_enabled'] = $this->m_data['comments_enabled']; $values['comments_locked'] = $this->m_data['comments_locked']; // Change some attributes $values['Name'] = $p_name; $values['Published'] = 'N'; $values['IsIndexed'] = 'N'; $values['LockUser'] = 0; $values['LockTime'] = 0; $values['IdUser'] = $p_userId; // Create the record $success = $articleCopy->__create($values); if (!$success) { return false; } $articleCopy->setProperty('UploadDate', 'NOW()', true, true); // Insert an entry into the article type table. $articleCopyData = new ArticleData($articleCopy->m_data['Type'], $articleCopy->m_data['Number'], $articleCopy->m_data['IdLanguage']); $articleCopyData->create(); $origArticleData = $this->getArticleData(); $origArticleData->copyToExistingRecord($articleCopy->getArticleNumber(), $p_languageId); if (function_exists("camp_load_translation_strings")) { camp_load_translation_strings("api"); } $logtext = getGS('Article translated to "$4" ($5)', $articleCopy->getTitle(), $articleCopy->getLanguageName()); Log::ArticleMessage($this, $logtext, null, 31); // geo-map processing Geo_Map::OnCreateTranslation($this->m_data['Number'], $this->m_data['IdLanguage'], $p_languageId); return $articleCopy; } // fn createTranslation
/** * 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; }