Ejemplo n.º 1
0
 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();
 }
Ejemplo n.º 2
0
 private function checkStrings($sCheckLanguageId = null)
 {
     $aAllStrings = array();
     foreach (TranslationQuery::create()->orderByStringKey()->find() as $oString) {
         if (!in_array($oString->getStringKey(), $aAllStrings)) {
             $aAllStrings[] = $oString->getStringKey();
         }
     }
     $aAllLanguages = array();
     foreach (LanguageQuery::create()->orderById()->find() as $oLanguage) {
         $aAllLanguages[$oLanguage->getId()] = $oLanguage->getLanguageName();
     }
     foreach ($aAllStrings as $sStringKey) {
         foreach ($aAllLanguages as $sLanguageId => $sLanguageName) {
             if ($sCheckLanguageId && $sCheckLanguageId === $sLanguageId) {
                 continue;
             }
             $oString = TranslationPeer::getString($sStringKey, $sLanguageId, self::$EMPTY_STRING_KEY);
             if ($oString === self::$EMPTY_STRING_KEY) {
                 $sText = TranslationPeer::getString('wns.check.check_string_message', null, null, array('string_key' => $sStringKey, 'language_id' => $sLanguageId));
                 $this->log($sText, $sLanguageId, self::LOG_LEVEL_WARNING);
             }
         }
     }
     return $this->aLogMessages;
 }
Ejemplo n.º 3
0
 public function getLanguageIdsOfStrings()
 {
     $aLanguages = TranslationQuery::create()->filterByStringKey('tag.' . $this->getName())->select('LanguageId')->find()->toArray();
     if (is_array($aLanguages) && !empty($aLanguages)) {
         return $aLanguages;
     }
     return null;
 }
Ejemplo n.º 4
0
 public function getCriteria()
 {
     $oQuery = TranslationQuery::create();
     if ($this->oDelegateProxy->getNameSpace() === CriteriaListWidgetDelegate::SELECT_WITHOUT) {
         return $oQuery->filterByKeysWithoutNamespace();
     } elseif ($this->oDelegateProxy->getNameSpace() !== CriteriaListWidgetDelegate::SELECT_ALL) {
         $oQuery->filterByNamespace($this->oDelegateProxy->getNameSpace());
     }
     return $oQuery->groupByStringKey();
 }
Ejemplo n.º 5
0
 public static function getCustomListElements()
 {
     if (count(TranslationPeer::getNamespaces()) > 0) {
         $aElements = array(array('name_space' => CriteriaListWidgetDelegate::SELECT_ALL, 'title' => TranslationPeer::getString('wns.strings.select_all_title'), 'magic_column' => 'all'));
         if (TranslationQuery::create()->filterByKeysWithoutNamespace()->count() > 0) {
             $aElementsWithout = array(array('name_space' => CriteriaListWidgetDelegate::SELECT_WITHOUT, 'title' => TranslationPeer::getString('wns.strings.select_without_title'), 'magic_column' => 'without'));
             $aElements = array_merge($aElements, $aElementsWithout);
         }
         return $aElements;
     }
     return array();
 }
 /**
  * Список перевода для локали
  *
  * @param $locale
  * @return array
  */
 public static function getListForLocale($locale)
 {
     $translation_list_en = array();
     $translation_list_locale = array();
     $result = array();
     $translation_list = TranslationQuery::create()->joinWithI18n('en')->find();
     foreach ($translation_list as $translation_item) {
         /** @var Translation $translation_item */
         $translation_list_en[$translation_item->getId()]['alias'] = $translation_item->getAlias();
         $translation_list_en[$translation_item->getId()]['title'] = $translation_item->getTitle();
     }
     $translation_list = TranslationQuery::create()->joinWithI18n($locale)->find();
     foreach ($translation_list as $translation_item) {
         /** @var Translation $translation_item */
         $translation_list_locale[$translation_item->getId()] = $translation_item->getTitle();
     }
     foreach ($translation_list_en as $id => $translation_item) {
         $result[$translation_item['alias']] = isset($translation_list_locale[$id]) && $translation_list_locale[$id] ? $translation_list_locale[$id] : ($translation_item['title'] ? $translation_item['title'] : $translation_item['alias']);
     }
     return $result;
 }
 /**
  * @return \DateTime|null
  */
 public function getLatestTranslationUpdatedAt()
 {
     $result = TranslationQuery::create()->withColumn(sprintf('MAX(%s)', TranslationPeer::UPDATED_AT), 'max_updated_at')->select(array('max_updated_at'))->findOne($this->getConnection());
     return !empty($result) ? new \DateTime($result) : null;
 }
Ejemplo n.º 8
0
 public static function countNameSpaceByName($sNameSpace)
 {
     return TranslationQuery::create()->filterByStringKey("{$sNameSpace}.%", Criteria::LIKE)->count();
 }
Ejemplo n.º 9
0
 /**
  * Removes this object from datastore and sets delete attribute.
  *
  * @param PropelPDO $con
  * @return void
  * @throws PropelException
  * @throws Exception
  * @see        BaseObject::setDeleted()
  * @see        BaseObject::isDeleted()
  */
 public function delete(PropelPDO $con = null)
 {
     if ($this->isDeleted()) {
         throw new PropelException("This object has already been deleted.");
     }
     if ($con === null) {
         $con = Propel::getConnection(TranslationPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     }
     $con->beginTransaction();
     try {
         $deleteQuery = TranslationQuery::create()->filterByPrimaryKey($this->getPrimaryKey());
         $ret = $this->preDelete($con);
         // denyable behavior
         if (!(TranslationPeer::isIgnoringRights() || $this->mayOperate("delete"))) {
             throw new PropelException(new NotPermittedException("delete.by_role", array("role_key" => "languages")));
         }
         if ($ret) {
             $deleteQuery->delete($con);
             $this->postDelete($con);
             $con->commit();
             $this->setDeleted(true);
         } else {
             $con->commit();
         }
     } catch (Exception $e) {
         $con->rollBack();
         throw $e;
     }
 }
 /**
  * Returns all translations for the given file.
  *
  * @param File      $file
  * @param boolean   $onlyUpdated
  *
  * @return array
  */
 public function getTranslationsForFile($file, $onlyUpdated)
 {
     $query = TranslationQuery::create()->filterByFile($file)->joinWith('TransUnit');
     if ($onlyUpdated) {
         $query->add(null, TranslationPeer::UPDATED_AT . '>' . TranslationPeer::CREATED_AT, \Criteria::CUSTOM);
     }
     $results = $query->select(array('Content', 'TransUnit.Key'))->orderBy(TranslationPeer::ID, \Criteria::ASC)->find();
     $translations = array();
     foreach ($results as $result) {
         $translations[$result['TransUnit.Key']] = $result['Content'];
     }
     return $translations;
 }
Ejemplo n.º 11
0
 /**
  * If this collection has already been initialized with
  * an identical criteria, it returns the collection.
  * Otherwise if this Language is new, it will return
  * an empty collection; or if this Language has previously
  * been saved, it will retrieve related Translations from storage.
  *
  * This method is protected by default in order to keep the public
  * api reasonable.  You can provide public methods for those you
  * actually need in Language.
  *
  * @param Criteria $criteria optional Criteria object to narrow the query
  * @param PropelPDO $con optional connection object
  * @param string $join_behavior optional join type to use (defaults to Criteria::LEFT_JOIN)
  * @return PropelObjectCollection|Translation[] List of Translation objects
  */
 public function getTranslationsJoinUserRelatedByUpdatedBy($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
 {
     $query = TranslationQuery::create(null, $criteria);
     $query->joinWith('UserRelatedByUpdatedBy', $join_behavior);
     return $this->getTranslations($query, $con);
 }
Ejemplo n.º 12
0
 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);
 }