Esempio n. 1
0
 public function translate($category, $message, $language)
 {
     $translation = (new Query())->from(Message::tableName())->leftJoin(Language::tableName(), '`' . Message::tableName() . '`.`lang_id` = `' . Language::tableName() . '`.`id`')->where(['message' => $message, 'category' => $category, Language::tableName() . '.lang_id' => $language])->one();
     if ($translation === false) {
         $translation = (new Query())->from(Message::tableName())->leftJoin(Language::tableName(), '`' . Message::tableName() . '`.`lang_id` = `' . Language::tableName() . '`.`id`')->where(['message' => $message, 'category' => $category, Language::tableName() . '.lang_id' => Language::getDefaultCode()])->one();
         if ($translation === false) {
             return false;
         }
         return $translation['translation'];
     }
     return $translation['translation'];
 }
Esempio n. 2
0
 /**
  * Returns Translations links for Update action
  * @param $model
  * @return array
  */
 public static function getUpdateItems($model, $urlPrefix)
 {
     $items = [];
     $defaultLang = \yii\fluent\models\Language::getDefault();
     $items[] = ['label' => strtoupper($defaultLang->title), 'icon' => 'fa fa-language', 'url' => [$urlPrefix . '/update', 'id' => $model->getSourceID()]];
     $langs = Language::getLangs();
     foreach ($langs as $lang) {
         if ($lang->id != $defaultLang->id) {
             $translation = $model->getTranslation($lang->id);
             $items[] = ['label' => strtoupper($lang->title), 'icon' => 'fa fa-language', 'url' => $translation === null || $translation->isNewRecord ? [$urlPrefix . '/create', 'lang_id' => $lang->id, 'source_id' => $model->getSourceID()] : [$urlPrefix . '/update', 'id' => $translation->id]];
         }
     }
     return $items;
 }
Esempio n. 3
0
 private function generateTree($root = -1)
 {
     $result = [];
     $items = MenuItem::find()->where(['root_id' => $root, 'menu_id' => $this->menu->id, 'source_id' => -1])->orderBy('order')->all();
     foreach ($items as $item) {
         $item = $item->getTranslation(Language::getCurrentLangID(), false);
         $id = $item->id;
         if ($item->source_id != -1) {
             $id = $item->source_id;
         }
         $result[] = ['label' => $item->title, 'url' => $item->link == '' ? '#' : $item->link, 'items' => $this->generateTree($id)];
     }
     return $result;
 }
Esempio n. 4
0
 /**
  * Creates a new Block model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate($source_id = -1, $lang_id = -1)
 {
     if ($lang_id == -1) {
         $lang_id = Language::getDefaultID();
     }
     $model = new Block();
     $model->source_id = $source_id;
     $model->lang_id = $lang_id;
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['index']);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Esempio n. 5
0
 /**
  * Creates a new item
  * @return mixed
  */
 public function actionCreateItem($menu_id, $source_id = -1, $lang_id = -1)
 {
     if ($lang_id == -1) {
         $lang_id = Language::getDefaultID();
     }
     $menu = $this->findModel($menu_id);
     $items = $menu->items;
     $model = new MenuItem();
     $model->menu_id = $menu_id;
     $model->source_id = $source_id;
     $model->lang_id = $lang_id;
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['items', 'id' => $menu->id]);
     } else {
         return $this->render('create_item', ['items' => $items, 'menu' => $menu, 'model' => $model]);
     }
 }
 /**
  * @inheritdoc
  */
 public function down()
 {
     $this->dropTable(Language::tableName());
 }
Esempio n. 7
0
 private function loadBlock()
 {
     $this->block = \yii\fluent\models\Block::findOne(['name' => $this->name])->getTranslation(Language::getCurrentLangID(), false);
 }
Esempio n. 8
0
 /**
  * Finds source node
  * @return $this|array|null|\yii\db\ActiveRecord
  */
 public function getSource()
 {
     if ($this->source_id == -1) {
         return $this;
     }
     return $this->find()->where(['id' => $this->getSourceID(), 'lang_id' => Language::getDefaultID()])->one();
 }
Esempio n. 9
0
 public static function getCurrentLangID()
 {
     return Language::getCurrentLang()->id;
 }
Esempio n. 10
0
 public function actionView($id)
 {
     $page = Page::findOne($id)->getTranslation(Language::getCurrentLangID(), false);
     return $this->render('view', ['page' => $page]);
 }