/** * @inheritdoc */ public function run() { if (empty($this->languages)) { $this->languages = Language::find()->all(); } return $this->render('language-switcher', ['languages' => $this->languages, 'selectedLanguage' => $this->selectedLanguage, 'model' => $this->model]); }
public static function findOrDefault($languageId) { if (empty($languageId) || !($language = Language::findOne($languageId))) { $language = Language::find()->where(['lang_id' => \Yii::$app->sourceLanguage])->one(); } return $language; }
/** * Creates a new DeliveryMethod model. * If creation is successful, the browser will be redirected to the 'view' page. * @param integer $id * @param integer $languageId * @return mixed * @throws NotFoundHttpException * @throws BadRequestHttpException */ public function actionSave($id = null, $languageId) { if (!empty($languageId)) { if (!empty($id)) { $model = $this->findModel($id); if (empty($model)) { throw new NotFoundHttpException(); } $modelTranslation = $this->findModelTranslation($id, $languageId); if (empty($modelTranslation)) { $modelTranslation = new ProductAvailabilityTranslation(); } } else { $model = new ProductAvailability(); $modelTranslation = new ProductAvailabilityTranslation(); } } else { throw new BadRequestHttpException(); } if ($modelTranslation->load(Yii::$app->request->post())) { $model->save(false); $modelTranslation->availability_id = $model->id; $modelTranslation->language_id = $languageId; if ($modelTranslation->validate()) { $modelTranslation->save(); return $this->redirect(['save', 'id' => $model->id, 'languageId' => $languageId]); } } return $this->render('save', ['model' => $model, 'modelTranslation' => $modelTranslation, 'languages' => Language::find()->all(), 'selectedLanguage' => Language::findOne($languageId)]); }
/** * @inheritdoc */ public function init() { $this->languages = Language::find()->asArray()->select('lang_id')->where(['active' => true])->all(); $this->languages = ArrayHelper::getColumn($this->languages, 'lang_id'); if ($this->languages) { if (!$this->enablePrettyUrl) { throw new InvalidConfigException('Locale URL support requires enablePrettyUrl to be set to true.'); } } $this->_defaultLanguage = Yii::$app->language; parent::init(); }
public function run() { parent::run(); $parents = self::findChildren($this->className, null); $languages = Language::find()->all(); foreach ($languages as $key => $language) { if ($language->id == $this->languageId) { $this->languageId = $key; } } return $this->render('input-tree/index', ['parents' => $parents, 'form' => $this->form, 'model' => $this->model, 'attribute' => $this->attribute, 'languageId' => $this->languageId]); }
public function up() { $this->createTable('shop_product_availability', ['id' => $this->primaryKey()]); $this->createTable('shop_product_availability_translation', ['id' => $this->primaryKey(), 'availability_id' => $this->integer(2), 'language_id' => $this->integer(2), 'title' => $this->string(256), 'description' => $this->string(256)]); $language = Language::find()->where(['lang_id' => 'en-US'])->one(); $this->insert('shop_product_availability', ['id' => 1]); $this->insert('shop_product_availability_translation', ['availability_id' => 1, 'language_id' => $language->id, 'title' => 'In stock']); $this->insert('shop_product_availability', ['id' => 2]); $this->insert('shop_product_availability_translation', ['availability_id' => 2, 'language_id' => $language->id, 'title' => 'Expected']); $this->insert('shop_product_availability', ['id' => 3]); $this->insert('shop_product_availability_translation', ['availability_id' => 3, 'language_id' => $language->id, 'title' => 'To order']); $this->addColumn('shop_product', 'availability', $this->integer()); $this->addForeignKey('shop_product_availability:shop_product_availability_id', 'shop_product', 'availability', 'shop_product_availability', 'id', 'cascade', 'cascade'); }
/** * Save data action for ShopAttribute. * If user has not permissions to do this action, a 403 HTTP exception will be thrown. * * @param integer $languageId * @param integer $attrId * @return mixed * @throws ForbiddenHttpException if user has not permissions */ public function actionSave($languageId = null, $attrId = null) { if (empty($languageId)) { $languageId = Language::getCurrent()->id; } $selectedLanguage = Language::findOne($languageId); $languages = Language::find()->all(); $attributeType = ArrayHelper::toArray(ShopAttributeType::find()->all(), ['bl\\cms\\shop\\common\\entities\\ShopAttributeType' => ['id', 'title' => function ($attributeType) { return \Yii::t('shop', $attributeType->title); }]]); if (empty($attrId)) { $model = new ShopAttribute(); $modelTranslation = new ShopAttributeTranslation(); $searchAttributeValueModel = null; $dataProviderAttributeValue = null; } else { $searchAttributeValueModel = new SearchAttributeValue(); $dataProviderAttributeValue = $searchAttributeValueModel->search(Yii::$app->request->queryParams); $model = ShopAttribute::findOne($attrId); $modelTranslation = ShopAttributeTranslation::find()->where(['attr_id' => $attrId, 'language_id' => $languageId])->one(); if (empty($modelTranslation)) { $modelTranslation = new ShopAttributeTranslation(); } } if (Yii::$app->request->isPost) { $model->load(Yii::$app->request->post()); $modelTranslation->load(Yii::$app->request->post()); if ($model->validate()) { $model->save(); $modelTranslation->attr_id = $model->id; $modelTranslation->language_id = $languageId; } if ($modelTranslation->validate()) { $modelTranslation->save(); Yii::$app->getSession()->setFlash('success', 'Data were successfully modified.'); return $this->redirect(['save', 'attrId' => $model->id, 'languageId' => $languageId]); } } return $this->render('save', ['attribute' => $model, 'attributeTranslation' => $modelTranslation, 'attributeType' => $attributeType, 'languages' => $languages, 'selectedLanguage' => $selectedLanguage, 'searchModel' => $searchAttributeValueModel, 'dataProvider' => $dataProviderAttributeValue, 'valueModel' => new ShopAttributeValue(), 'valueModelTranslation' => new ShopAttributeValueTranslation(), 'attributeTextureModel' => new AttributeTextureForm()]); }
public function actionIndex() { $languages = Language::find()->all(); $createLanguageForm = new CreateLanguageForm(); return $this->render('list', ['languages' => $languages, 'createLanguageForm' => $createLanguageForm]); }
<?php /** * @author Albert Gainutdinov <*****@*****.**> */ use bl\multilang\entities\Language; use yii\bootstrap\Html; use yii\helpers\ArrayHelper; use yii\helpers\Url; global $item; $item = $model; echo Html::a('<span class="glyphicon glyphicon-remove"></span>', Url::toRoute(['delete', 'id' => $GLOBALS['item']->id]), ['title' => Yii::t('yii', 'Delete'), 'class' => 'btn btn-danger pull-right btn-xs']) . Html::tag('div', Html::a(Html::tag('span', ' ' . \Yii::t('shop', 'Edit'), ['class' => 'glyphicon glyphicon-pencil']), Url::toRoute(['save', 'id' => $GLOBALS['item']->id, "languageId" => Language::getCurrent()->id]), ['class' => 'btn btn-primary btn-xs']) . Html::a('<span class="caret"></span>', Url::toRoute(['save', 'id' => $GLOBALS['item']->id, "languageId" => Language::getCurrent()->id]), ['class' => 'btn btn-primary btn-xs dropdown-toggle', 'type' => 'button', 'id' => 'dropdownMenu1', 'data-toggle' => 'dropdown', 'aria-haspopup' => 'true', 'aria-expanded' => 'true']) . Html::ul(ArrayHelper::map(Language::find()->all(), 'id', 'name'), ['item' => function ($item, $index) { return Html::tag('li', Html::a($item, Url::toRoute(['save', 'id' => $GLOBALS['item']->id, "languageId" => $index]))); }, 'class' => 'dropdown-menu', 'aria-labelledby' => 'dropdownMenu1']), ['class' => 'btn-group pull-right m-r-xs']);
public function actionDelete($categoryId = null, $languageId = null) { $language = Language::find()->where(['id' => $languageId])->one(); if (Message::find()->where(['id' => $categoryId])->count() == 0) { SourceMessage::find()->where(['id' => $categoryId])->one()->delete(); } else { $message = Message::find()->where(['id' => $categoryId, 'language' => $language->lang_id])->one(); if (!empty($message)) { $message->delete(); } else { Yii::$app->session->setFlash('success', 'This category linked data , such a category can not be deleted.'); } } return $this->redirect(Yii::$app->request->referrer); }
/** * Users which have 'updateOwnProduct' permission can add price only for Product models that have been created by their. * Users which have 'updateProduct' permission can add price for all Product models. * * @param integer $id * @param integer $languageId * @return mixed * @throws ForbiddenHttpException */ public function actionAddPrice($id, $languageId) { if (\Yii::$app->user->can('updateProduct', ['productOwner' => Product::findOne($id)->owner])) { $price = new ProductPrice(); $priceTranslation = new ProductPriceTranslation(); $product = Product::findOne($id); $selectedLanguage = Language::findOne($languageId); if (\Yii::$app->request->isPost) { $post = \Yii::$app->request->post(); if ($price->load($post) && $priceTranslation->load($post)) { $price->product_id = $product->id; if ($price->save()) { $priceTranslation->price_id = $price->id; $priceTranslation->language_id = $selectedLanguage->id; if ($priceTranslation->save()) { $price = new ProductPrice(); $priceTranslation = new ProductPriceTranslation(); } } } } if (Yii::$app->request->isPjax) { return $this->renderPartial('add-price', ['priceList' => $product->prices, 'priceModel' => $price, 'priceTranslationModel' => $priceTranslation, 'product' => $product, 'languages' => Language::findAll(['active' => true]), 'language' => $selectedLanguage]); } return $this->render('save', ['viewName' => 'add-price', 'selectedLanguage' => Language::findOne($languageId), 'product' => $product, 'languages' => Language::find()->all(), 'params' => ['priceList' => $product->prices, 'priceModel' => $price, 'priceTranslationModel' => $priceTranslation, 'product' => $product, 'languages' => Language::findAll(['active' => true]), 'language' => $selectedLanguage]]); } else { throw new ForbiddenHttpException(\Yii::t('shop', 'You have not permission to do this action.')); } }