/** * Execute the console command. * * @return mixed */ public function fire() { $translationLanguageKeywords = TranslationLanguageKeywordQuery::create()->useTranslationLanguageQuery()->where('translation_language.is_active = 1')->endUse()->useTranslationKeywordQuery()->useTranslationCatalogQuery()->where("translation_catalog.name = 'general'")->endUse()->endUse()->find(); $translation_lang_keyword_arr = array(); $languages = array(); foreach ($translationLanguageKeywords as $translationLanguageKeyword) { $lang_culture = $translationLanguageKeyword->getTranslationLanguage()->getCulture(); $keyword = $translationLanguageKeyword->getTranslationKeyword()->getKeyword(); $translation = $translationLanguageKeyword->getTranslation(); if (!isset($languages[$lang_culture])) { $languages[$lang_culture] = $lang_culture; $translation_lang_keyword_arr[$lang_culture] = '<?php return [ '; } $translation_lang_keyword_arr[$lang_culture] .= "\t'" . $keyword . "' => '" . $translation . "',\n"; } $path = base_path() . "/resources/lang/"; foreach ($languages as $lang_culture) { $string = $translation_lang_keyword_arr[$lang_culture] .= '];'; $lang_path = $path . $lang_culture; if (!is_dir($lang_path)) { mkdir($lang_path); } $fp = fopen($lang_path . '/general.php', 'w'); fwrite($fp, $string); fclose($fp); } }
/** * Create TranslationKeyword list and put in session. * */ private function createList($request, $path, $page) { $translation_filter = $request->all(); $this->handleFilterRequest($translation_filter, 'translation_filter'); if (is_null($page) || $page < 1) { $page = 1; } $cnt = $this->translations->count(); $maxPages = ceil($cnt / $this->maxPerPage); if ($maxPages < $page) { $page = $maxPages; } $this->setPaginationForm($cnt, $page, $path); $language_name = $this->translationLanguage->getName(); $language_id = $this->translationLanguage->getId(); foreach ($this->translations->paginate($page, $this->maxPerPage) as $key => $translationKeyword) { $keyword_id = $translationKeyword->getId(); $this->data_arr[$keyword_id]['#'] = ($page - 1) * $this->maxPerPage + $key + 1; $this->data_arr[$keyword_id]['catalog'] = $translationKeyword->getTranslationCatalog()->getName(); $this->data_arr[$keyword_id]['keyword'] = $translationKeyword->getKeyword(); $translationLanguageKeyword = TranslationLanguageKeywordQuery::create()->where('keyword_id = ' . $keyword_id)->where('language_id = ' . $language_id)->findOne(); $this->data_arr[$keyword_id][$language_name] = is_null($translationLanguageKeyword) ? '' : $translationLanguageKeyword->getTranslation(); } }
/** * Returns a new ChildTranslationLanguageKeywordQuery object. * * @param string $modelAlias The alias of a model in the query * @param Criteria $criteria Optional Criteria to build the query from * * @return ChildTranslationLanguageKeywordQuery */ public static function create($modelAlias = null, Criteria $criteria = null) { if ($criteria instanceof ChildTranslationLanguageKeywordQuery) { return $criteria; } $query = new ChildTranslationLanguageKeywordQuery(); if (null !== $modelAlias) { $query->setModelAlias($modelAlias); } if ($criteria instanceof Criteria) { $query->mergeWith($criteria); } return $query; }
/** * If this collection has already been initialized with * an identical criteria, it returns the collection. * Otherwise if this TranslationLanguage is new, it will return * an empty collection; or if this TranslationLanguage has previously * been saved, it will retrieve related TranslationLanguageKeywords 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 TranslationLanguage. * * @param Criteria $criteria optional Criteria object to narrow the query * @param ConnectionInterface $con optional connection object * @param string $joinBehavior optional join type to use (defaults to Criteria::LEFT_JOIN) * @return ObjectCollection|ChildTranslationLanguageKeyword[] List of ChildTranslationLanguageKeyword objects */ public function getTranslationLanguageKeywordsJoinTranslationKeyword(Criteria $criteria = null, ConnectionInterface $con = null, $joinBehavior = Criteria::LEFT_JOIN) { $query = ChildTranslationLanguageKeywordQuery::create(null, $criteria); $query->joinWith('TranslationKeyword', $joinBehavior); return $this->getTranslationLanguageKeywords($query, $con); }
/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update($id, TranslationRequest $request) { $data = $request->all(); $translationKeyword = TranslationKeywordQuery::create()->findPK($id); $translationKeyword->setCatalogId($data['CatalogId']); $translationKeyword->setKeyword($data['Keyword']); $translationKeyword->save(); foreach ($data['Languages'] as $language_id => $translation) { $translationLanguageKeyword = TranslationLanguageKeywordQuery::create()->where('keyword_id = ' . $id)->where('language_id = ' . $language_id)->findOne(); if (is_null($translationLanguageKeyword)) { $translationLanguageKeyword = new TranslationLanguageKeyword(); $translationLanguageKeyword->setLanguageId($language_id); $translationLanguageKeyword->setKeywordId($id); $translationLanguageKeyword->setTranslation($translation); $translationLanguageKeyword->save(); } else { $translationLanguageKeyword->setTranslation($translation); $translationLanguageKeyword->save(); } } if ($translationKeyword->getTranslationCatalog()->getName() == 'general') { $this->rebuildTranslation(); } flash()->success("UPDATED"); session(['attribute' => \Lang::get('general.TRANSLATION')]); return redirect($this->main_page); }
/** * Performs an INSERT on the database, given a TranslationLanguageKeyword or Criteria object. * * @param mixed $criteria Criteria or TranslationLanguageKeyword object containing data that is used to create the INSERT statement. * @param ConnectionInterface $con the ConnectionInterface connection to use * @return mixed The new primary key. * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function doInsert($criteria, ConnectionInterface $con = null) { if (null === $con) { $con = Propel::getServiceContainer()->getWriteConnection(TranslationLanguageKeywordTableMap::DATABASE_NAME); } if ($criteria instanceof Criteria) { $criteria = clone $criteria; // rename for clarity } else { $criteria = $criteria->buildCriteria(); // build Criteria from TranslationLanguageKeyword object } // Set the correct dbName $query = TranslationLanguageKeywordQuery::create()->mergeWith($criteria); // use transaction because $criteria could contain info // for more than one table (I guess, conceivably) return $con->transaction(function () use($con, $query) { return $query->doInsert($con); }); }
/** * Builds a Criteria object containing the primary key for this object. * * Unlike buildCriteria() this method includes the primary key values regardless * of whether or not they have been modified. * * @throws LogicException if no primary key is defined * * @return Criteria The Criteria object containing value(s) for primary key(s). */ public function buildPkeyCriteria() { $criteria = ChildTranslationLanguageKeywordQuery::create(); $criteria->add(TranslationLanguageKeywordTableMap::COL_LANGUAGE_ID, $this->language_id); $criteria->add(TranslationLanguageKeywordTableMap::COL_KEYWORD_ID, $this->keyword_id); return $criteria; }