/** * Create a copy of this article. * * @param int $p_destPublicationId - * The destination publication ID. * @param int $p_destIssueNumber - * The destination issue number. * @param int $p_destSectionNumber - * The destination section number. * @param int $p_userId - * The user creating the copy. If null, keep the same user ID as the original. * @param mixed $p_copyTranslations - * If false (default), only this article will be copied. * If true, all translations will be copied. * If an array is passed, the translations given will be copied. * Any translations that do not exist will be ignored. * * @return Article * If $p_copyTranslations is TRUE or an array, return an array of newly created articles. * If $p_copyTranslations is FALSE, return the new Article. */ public function copy($p_destPublicationId = 0, $p_destIssueNumber = 0, $p_destSectionNumber = 0, $p_userId = null, $p_copyTranslations = false) { global $g_ado_db; // 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/ArticleAttachment.php'); $copyArticles = array(); if ($p_copyTranslations) { // Get all translations for this article $copyArticles = $this->getTranslations(); // Remove any translations that are not requested to be translated. if (is_array($p_copyTranslations)) { $tmpArray = array(); foreach ($copyArticles as $tmpArticle) { if (in_array($tmpArticle->m_data['IdLanguage'], $p_copyTranslations)) { $tmpArray[] = $tmpArticle; } } $copyArticles = $tmpArray; } } else { $copyArticles[] = $this; } $newArticleNumber = $this->__generateArticleNumber(); // geo-map copying if (0 < count($copyArticles)) { $map_user_id = $p_userId; if (is_null($map_user_id)) { $map_user_id = $this->m_data['IdUser']; } $map_artilce_src = (int)$this->m_data['Number']; $map_artilce_dest = (int)$newArticleNumber; $map_translations = array(); foreach ($copyArticles as $copyMe) { $map_translations[] = (int)$copyMe->m_data['IdLanguage']; } Geo_Map::OnArticleCopy($map_artilce_src, $map_artilce_dest, $map_translations, $map_user_id); } // Load translation file for log message. if (function_exists("camp_load_translation_strings")) { camp_load_translation_strings("api"); } $articleOrder = null; $logtext = ''; $newArticles = array(); foreach ($copyArticles as $copyMe) { // Construct the duplicate article object. $articleCopy = new Article(); $articleCopy->m_data['IdPublication'] = (int)$p_destPublicationId; $articleCopy->m_data['NrIssue'] = (int)$p_destIssueNumber; $articleCopy->m_data['NrSection'] = (int)$p_destSectionNumber; $articleCopy->m_data['IdLanguage'] = (int)$copyMe->m_data['IdLanguage']; $articleCopy->m_data['Number'] = (int)$newArticleNumber; $values = array(); // Copy some attributes $values['ShortName'] = $newArticleNumber; $values['Type'] = $copyMe->m_data['Type']; $values['OnFrontPage'] = $copyMe->m_data['OnFrontPage']; $values['OnSection'] = $copyMe->m_data['OnSection']; $values['Public'] = $copyMe->m_data['Public']; $values['ArticleOrder'] = $articleOrder; $values['Keywords'] = $copyMe->m_data['Keywords']; // Change some attributes $values['Published'] = 'N'; $values['IsIndexed'] = 'N'; $values['LockUser'] = 0; $values['LockTime'] = 0; if (!is_null($p_userId)) { $values['IdUser'] = $p_userId; } else { $values['IdUser'] = $copyMe->m_data['IdUser']; } $values['Name'] = $articleCopy->getUniqueName($copyMe->m_data['Name']); $articleCopy->__create($values); $articleCopy->setProperty('UploadDate', 'NOW()', true, true); if (is_null($articleOrder)) { $g_ado_db->Execute('LOCK TABLES Articles WRITE'); $articleOrder = $g_ado_db->GetOne('SELECT MAX(ArticleOrder) + 1 FROM Articles'); $articleCopy->setProperty('ArticleOrder', $articleOrder); $g_ado_db->Execute('UNLOCK TABLES'); } // Insert an entry into the article type table. $newArticleData = new ArticleData($articleCopy->m_data['Type'], $articleCopy->m_data['Number'], $articleCopy->m_data['IdLanguage']); $newArticleData->create(); $origArticleData = $copyMe->getArticleData(); $origArticleData->copyToExistingRecord($articleCopy->m_data['Number']); // Copy image pointers ArticleImage::OnArticleCopy($copyMe->m_data['Number'], $articleCopy->m_data['Number']); // Copy topic pointers ArticleTopic::OnArticleCopy($copyMe->m_data['Number'], $articleCopy->m_data['Number']); // Copy file pointers ArticleAttachment::OnArticleCopy($copyMe->m_data['Number'], $articleCopy->m_data['Number']); // Position the new article at the beginning of the section $articleCopy->positionAbsolute(1); $newArticles[] = $articleCopy; $languageObj = new Language($copyMe->getLanguageId()); $logtext .= getGS('Article copied to Article #$4 (publication $5, issue $6, section $7).', $articleCopy->getArticleNumber(), $articleCopy->getPublicationId(), $articleCopy->getIssueNumber(), $articleCopy->getSectionNumber()); } Log::ArticleMessage($copyMe, $logtext, null, 155); if ($p_copyTranslations) { return $newArticles; } else { return array_pop($newArticles); } } // fn copy