function _plgListingAfterSave(&$model) { // Limit running this for new/edited listings. Not deletion of images or other listing actions. if ($this->c->name == 'listings' && in_array($this->c->action, array('_save'))) { include_once PATH_ROOT . 'administrator' . DS . 'components' . DS . 'com_joomfish' . DS . 'models' . DS . 'ContentObject.php'; $lang =& JFactory::getLanguage(); $language = $lang->getTag(); $jfm =& JoomFishManager::getInstance(); $contentElement = $jfm->getContentElement('content'); $actContentObject = new ContentObject($jfm->getLanguageID($language), $contentElement); $object = (object) $model->data['Listing']; $actContentObject->loadFromContentID($object->id); $actContentObject->copyContentToTranslation($object, $object); $actContentObject->setPublished($this->autoPublishTranslation); //Automatically publishes the translations $actContentObject->store(); if ($jfm->getCfg("transcaching", 1)) { // clean the cache! $cache = $jfm->getCache($language); $cache->clean(); } } }
/** * This method copies originals content items to one selected language * * @param unknown_type $original2languageInfo * @param unknown_type $phase * @param unknown_type $statecheck_i * @param unknown_type $message * @return array Information result array */ function copyOriginalToLanguage($original2languageInfo, &$phase, &$state_catid, $language_id, $overwrite, &$message) { $db = JFactory::getDBO(); $jfManager = JoomFishManager::getInstance(); $sql = ''; switch ($phase) { case 1: $original2languageInfo = array(); $sql = "select distinct CONCAT('" . $db->getPrefix() . "',reference_table) from #__jf_content"; $db->setQuery($sql); $tablesWithTranslations = $db->loadResultArray(); $sql = "SHOW TABLES"; $db->setQuery($sql); $tables = $db->loadResultArray(); $allContentElements = $jfManager->getContentElements(); foreach ($allContentElements as $catid => $ce) { $ceInfo = array(); $ceInfo['name'] = $ce->Name; $ceInfo['catid'] = $catid; $ceInfo['total'] = '??'; $ceInfo['existing'] = '??'; $ceInfo['processed'] = '0'; $ceInfo['copied'] = '0'; $ceInfo['copy'] = false; $contentTable = $ce->getTable(); $tablename = $db->getPrefix() . $contentTable->Name; if (in_array($tablename, $tables)) { // get total count of table entries $sql = 'SELECT COUNT(*) FROM ' . $tablename . ' AS c'; if ($contentTable->Filter != '') { $sql .= ' WHERE ' . $contentTable->Filter; } $db->setQuery($sql); $ceInfo['total'] = $db->loadResult(); } $original2languageInfo[$catid] = $ceInfo; } $phase = 1; // stays with 1 as the second phase needs the bottom to be clicked $message = JText::_('COPY2LANGUAGE_INFO'); break; case 2: if ($state_catid != '') { // removing all content information which are not to be copied! $celements = explode(',', $state_catid); if (count($celements) < count($original2languageInfo)) { $shortList = array(); foreach ($celements as $element) { $shortList[$element] = $original2languageInfo[$element]; } $original2languageInfo = $shortList; } } $phase = 3; case 3: if ($state_catid != '') { $celements = explode(',', $state_catid); // copy the information per content element file, starting with the first in the list $catid = array_shift($celements); $catidCompleted = false; // coyping the information from the selected content element if ($catid != '' && $language_id != 0) { // get's the config settings on how to store original files $storeOriginalText = $jfManager->getCfg('storageOfOriginal') == 'md5' ? false : true; // make sure we are only transfering data within parts (max 100 items at a time) $ceInfo =& $original2languageInfo[$catid]; if (intval($ceInfo['processed']) < intval($ceInfo['total'])) { $contentElement = $jfManager->getContentElement($catid); $db->setQuery($contentElement->createContentSQL($language_id, null, $ceInfo['processed'], 10, array())); $rows = $db->loadObjectList(); if ($db->getErrorNum()) { JError::raiseError(500, JTEXT::_('Invalid Content SQL : ') . $db->getErrorMsg()); return false; } else { for ($i = 0; $i < count($rows); $i++) { $contentObject = new ContentObject($language_id, $contentElement); $contentObject->readFromRow($rows[$i]); if ($overwrite || $contentObject->translation_id == 0) { $contentObject->copyContentToTranslation($rows[$i], $rows[$i]); $contentObject->store(); $ceInfo['copied'] += 1; } $rows[$i] = $contentObject; } $ceInfo['processed'] += $i; if ($ceInfo['processed'] >= $ceInfo['total']) { $catidCompleted = true; } } } } if ($catidCompleted) { if (count($celements) > 0) { $state_catid = implode(',', $celements); } else { $state_catid = ''; } } } $message = JText::_('COPY2LANGUAGE_PROCESS'); if ($state_catid == '') { $phase = 4; // Successfully finished phase 3 $message = JText::_('COPY2LANGUAGE_COMPLETED'); } break; } return $original2languageInfo; }