public function saveData($aTagData) { $aTagData['name'] = StringUtil::normalize($aTagData['name']); if ($this->iTagId === null) { $oTag = new Tag(); } else { $oTag = TagQuery::create()->findPk($this->iTagId); } $this->validate($aTagData); if (!Flash::noErrors()) { throw new ValidationException(); } $sStringName = "tag.{$aTagData['name']}"; if ($oTag->getName() !== $aTagData['name']) { //Rename Strings for the tag $sOldStringName = "tag.{$oTag->getName()}"; foreach (TranslationQuery::create()->filterByStringKey($sOldStringName)->find() as $oString) { $sLanguageId = $oString->getLanguageId(); //You can’t technically rename strings because string_key is the PKEY so we delete it and re-generate $oString->delete(); $oString = new Translation(); $oString->setStringKey($sStringName); $oString->setLanguageId($sLanguageId); $oString->save(); } $oTag->setName($aTagData['name']); } foreach ($aTagData['edited_languages'] as $iIndex => $sLanguageId) { TranslationPeer::addOrUpdateString($sStringName, $aTagData['text'][$iIndex], $sLanguageId); } $oTag->save(); }
public static function addOrUpdateString($sStringKey, $sContent, $sLanguageId = null) { if ($sLanguageId === null) { $sLanguageId = Session::language(); } $oString = TranslationQuery::create()->findPk(array($sLanguageId, $sStringKey)); if (!$sContent) { if ($oString !== null) { $oString->delete(); } return; } if ($oString === null) { $oString = new Translation(); $oString->setLanguageId($sLanguageId); $oString->setStringKey($sStringKey); } $oString->setText($sContent); $oString->save(); }
public function saveData($aStringData) { $this->validate($aStringData); if (!Flash::noErrors()) { throw new ValidationException(); } $oConnection = Propel::getConnection(); foreach (LanguageQuery::create()->orderById()->find() as $oLanguage) { $oUpdateCriteria = new Criteria(); $oUpdateCriteria->add(TranslationPeer::LANGUAGE_ID, $oLanguage->getId()); $oUpdateCriteria->add(TranslationPeer::STRING_KEY, $this->sStringId); if (isset($aStringData['text_' . $oLanguage->getId()])) { $sText = trim($aStringData['text_' . $oLanguage->getId()]); $oString = TranslationQuery::create()->findPk(array($oLanguage->getId(), $this->sStringId)); if ($sText === '') { if ($oString !== null) { $oString->delete(); } continue; } if ($oString === null) { $oString = new Translation(); $oString->setLanguageId($oLanguage->getId()); $oString->setStringKey($aStringData['string_key']); } else { if ($this->sStringId !== null && $this->sStringId !== $aStringData['string_key']) { $oString->setStringKey($aStringData['string_key']); BasePeer::doUpdate($oUpdateCriteria, $oString->buildCriteria(), $oConnection); } } $oString->setText($sText); $oString->save(); } else { $oString = TranslationQuery::create()->findPk(array($oLanguage->getId(), $this->sStringId)); if ($oString === null) { continue; } if ($this->sStringId !== null && $this->sStringId !== $aStringData['string_key']) { $oString->setStringKey($aStringData['string_key']); BasePeer::doUpdate($oUpdateCriteria, $oString->buildCriteria(), $oConnection); } } } // check sidebar reload criteria $sNameSpaceOld = TranslationPeer::getNameSpaceFromStringKey($this->sStringId); $sNameSpaceNew = TranslationPeer::getNameSpaceFromStringKey($aStringData['string_key']); // if both are the same the sidebar is not effected $bSidebarHasChanged = false; if ($sNameSpaceOld !== $sNameSpaceNew) { // if there was an old name space then we have to check whether it was the last string with this namespace if ($sNameSpaceOld !== null && !TranslationPeer::nameSpaceExists($sNameSpaceOld)) { $bSidebarHasChanged = true; } // if the new exits only once it has been created and the sidebar needs to be relaoded if ($sNameSpaceNew !== null && TranslationPeer::countNameSpaceByName($sNameSpaceNew) === 1) { $bSidebarHasChanged = true; } } $this->sStringId = $aStringData['string_key']; return array('id' => $this->sStringId, self::SIDEBAR_CHANGED => $bSidebarHasChanged); }