/** * Parses the given request and returns the corresponding route and parameters. * @param UrlManager $manager the URL manager * @param Request $request the request component * @return array|bool the parsing result. The route and the parameters are returned as an array. * If false, it means this rule cannot be used to parse this path info. * @throws NotFoundHttpException */ public function parseRequest($manager, $request) { $this->currentLanguage = Language::getCurrent(); $this->pathInfo = $request->getPathInfo(); if ($this->pathInfo == $this->albumsRoute) { if ($this->disableDefault) { throw new NotFoundHttpException(); } if (!empty($request->getQueryParams()['id'])) { $id = $request->getQueryParams()['id']; $album = GalleryAlbum::findOne($id); if (!$album) { return false; } $translation = $album->getTranslation($this->currentLanguage->id); if ($translation) { if (!empty($translation->seoUrl)) { throw new NotFoundHttpException(); } } } } if (!empty($this->prefix)) { if (strpos($this->pathInfo, $this->prefix) === 0) { $this->pathInfo = substr($this->pathInfo, strlen($this->prefix)); } else { return false; } } $this->initRoutes($this->pathInfo); if (!empty($this->prefix) && $this->routesCount == 1) { return [$this->albumsRoute, []]; } else { if ($this->routesCount == 2) { $seoUrl = $this->routes[1]; /* @var SeoData $seoData */ $seoData = SeoData::find()->where(['entity_name' => GalleryAlbumTranslation::className(), 'seo_url' => $seoUrl])->one(); if ($seoData) { /* @var GalleryAlbum $album */ $album = GalleryAlbum::find()->joinWith('translations translation')->where(['translation.id' => $seoData->entity_id, 'translation.language_id' => $this->currentLanguage->id])->one(); if ($album) { return [$this->albumsRoute, ['id' => $album->id]]; } } } } return false; }
/** * Parses the given request and returns the corresponding route and parameters. * @param UrlManager $manager the URL manager * @param Request $request the request component * @return array|bool the parsing result. The route and the parameters are returned as an array. * If false, it means this rule cannot be used to parse this path info. * @throws NotFoundHttpException */ public function parseRequest($manager, $request) { $this->currentLanguage = Language::getCurrent(); $this->pathInfo = $request->getPathInfo(); if ($this->pathInfo == $this->categoryRoute || $this->pathInfo == $this->productRoute) { Yii::$app->urlManager->language = $this->currentLanguage; if ($this->createUrl(Yii::$app->urlManager, $this->pathInfo, $request->getQueryParams())) { throw new NotFoundHttpException(Yii::t('yii', 'Page not found.')); } else { if ($this->pathInfo == $this->productRoute && empty($request->getQueryParams()['id'])) { throw new NotFoundHttpException(Yii::t('yii', 'Page not found.')); } } } if (!empty($this->prefix)) { if (strpos($this->pathInfo, $this->prefix) === 0) { $this->pathInfo = substr($this->pathInfo, strlen($this->prefix)); } else { return false; } } $this->initRoutes($this->pathInfo); if (!empty($this->prefix) && $this->routesCount == 1) { return [$this->categoryRoute, []]; } $categoryId = null; for ($i = 1; $i < $this->routesCount; $i++) { if ($i === $this->routesCount - 1) { if ($product = $this->findProductBySeoUrl($this->routes[$i], $categoryId)) { return ['/' . $this->productRoute, ['id' => $product->id]]; } else { if ($category = $this->findCategoryBySeoUrl($this->routes[$i], $categoryId)) { return ['/' . $this->categoryRoute, ['id' => $category->id]]; } else { return false; } } } else { if ($category = $this->findCategoryBySeoUrl($this->routes[$i], $categoryId)) { $categoryId = $category->id; } else { return false; } } } return false; }
echo Url::to(['remove', 'id' => $article->id]); ?> " class="glyphicon glyphicon-remove text-danger btn btn-default btn-sm"> </a> </td> </tr> <?php } ?> </tbody> <?php } ?> </table> <!-- TODO: languageId --> <a href="<?php echo Url::to(['/articles/article/save', 'languageId' => Language::getCurrent()->id]); ?> " class="btn btn-primary pull-right"> <i class="fa fa-user-plus"></i> <?php echo Yii::t('articles', 'Add'); ?> </a> </div> </div> </div> </div>
<?php } ?> </a> </td> <td> <?php echo Html::a($article->translation->name, ['/articles/article/save', 'articleId' => $article->id, 'languageId' => Language::getCurrent()->id]); ?> </td> <td> <?php if (!empty($article->category->translation->name)) { ?> <?php echo Html::a($article->category->translation->name, ['/articles/category/save', 'categoryId' => $article->category_id, 'languageId' => Language::getCurrent()->id]); ?> <?php } else { ?> <span><?php echo Yii::t('articles', 'Without category'); ?> </span> <?php } ?> </td> <td> <?php echo Yii::$app->formatter->asRelativeTime($article->created_at);
$content = ''; $number = 3; $i = 0; foreach ($model->images as $image) { if (!empty($image)) { if ($i < $number) { $content .= Html::img($image->small, ['class' => 'img-circle']); $i++; } } } return Html::a($content, Url::toRoute(['add-image', 'id' => $model->id, 'languageId' => Language::getCurrent()->id])); }, 'label' => Yii::t('shop', 'Images'), 'format' => 'html', 'contentOptions' => ['class' => 'col-md-1 project-people']], ['headerOptions' => ['class' => 'text-center col-md-1'], 'attribute' => \Yii::t('shop', 'Status'), 'value' => function ($model) { switch ($model->status) { case Product::STATUS_ON_MODERATION: return Html::button(Yii::$app->user->can('moderateProductCreation') ? Html::a(\Yii::t('shop', 'On moderation'), Url::toRoute(['save', 'id' => $model->id, 'languageId' => Language::getCurrent()->id]), ['class' => '']) : Html::tag('span', \Yii::t('shop', 'On moderation')), ['class' => 'col-md-12 btn btn-warning btn-xs']); break; case Product::STATUS_DECLINED: return Html::tag('p', \Yii::t('shop', 'Declined'), ['class' => 'col-md-12 btn btn-danger btn-xs']); break; case Product::STATUS_SUCCESS: return Html::tag('p', \Yii::t('shop', 'Success'), ['class' => 'col-md-12 btn btn-primary btn-xs']); break; default: return $model->status; } }, 'label' => Yii::t('shop', 'Status'), 'format' => 'html', 'filter' => Html::activeDropDownList($searchModel, 'status', [Product::STATUS_ON_MODERATION => \Yii::t('shop', 'On moderation'), Product::STATUS_DECLINED => \Yii::t('shop', 'Declined'), Product::STATUS_SUCCESS => \Yii::t('shop', 'Success')], ['class' => 'form-control', 'prompt' => 'Любой статус']), 'contentOptions' => ['class' => 'project-title text-center col-md-1']], ['headerOptions' => ['class' => 'text-center col-md-2'], 'attribute' => \Yii::t('shop', 'Manage'), 'value' => function ($model) { return ManageButtons::widget(['model' => $model]); }, 'format' => 'raw', 'contentOptions' => ['class' => 'col-md-2 text-center']]]]); ?> <?php
<?php /** * @author Albert Gainutdinov <*****@*****.**> * * @var $this yii\web\View * @var $availabilities bl\cms\shop\common\entities\ProductAvailability */ use bl\cms\shop\widgets\ManageButtons; use bl\multilang\entities\Language; use yii\bootstrap\Html; use yii\helpers\ArrayHelper; use yii\helpers\Url; $this->title = Yii::t('shop', 'Product availabilities'); $currentLanguage = Language::getCurrent(); ?> <div class="panel panel-default"> <div class="panel-heading"> <i class="glyphicon glyphicon-list"></i> <?php echo Html::encode($this->title); ?> </div> <div class="panel-body"> <p> <?php echo Html::a(Yii::t('shop', 'Add'), ['save'], ['class' => 'btn btn-primary btn-xs pull-right']);
<?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']);
<?php echo !empty($product->ownerProfile->name) ? $product->ownerProfile->name : ''; ?> <?php echo !empty($product->ownerProfile->surname) ? $product->ownerProfile->surname : ''; ?> </td> <?php } ?> <td style="vertical-align: middle;"> <?php if (!empty($product->category->translation->title)) { ?> <?php echo Html::a($product->category->translation->title, ['/shop/category/save', 'id' => $product->category_id, 'languageId' => Language::getCurrent()->id]); ?> <?php } else { ?> <span><?php echo Yii::t('shop', 'Without parent'); ?> </span> <?php } ?> </td> <td style="vertical-align: middle;"> <?php echo Yii::$app->formatter->asRelativeTime($product->creation_time);
} return $content; }, 'label' => Yii::t('shop', 'Title'), 'format' => 'html', 'contentOptions' => ['class' => 'project-title col-md-3']], ['headerOptions' => ['class' => 'text-center col-md-3'], 'attribute' => 'parent_id', 'filter' => ArrayHelper::map(Category::find()->all(), 'id', 'translation.title'), 'value' => 'parent.translation.title', 'label' => Yii::t('shop', 'Parent category'), 'format' => 'html', 'contentOptions' => ['class' => 'project-title col-md-3']], ['headerOptions' => ['class' => 'text-center col-md-2'], 'attribute' => 'images', 'value' => function ($model) { $content = ''; if (!empty($model->cover)) { $content .= Html::img('/images/shop-category/' . $model->cover . '-small.jpg', ['class' => 'img-circle']); } if (!empty($model->thumbnail)) { $content .= Html::img('/images/shop-category/' . $model->thumbnail . '-small.jpg', ['class' => 'img-circle']); } if (!empty($model->menu_item)) { $content .= Html::img('/images/shop-category/' . $model->menu_item . '-small.jpg', ['class' => 'img-circle']); } return Html::a($content, Url::toRoute(['add-image', 'categoryId' => $model->id, 'languageId' => Language::getCurrent()->id])); }, 'label' => Yii::t('shop', 'Images'), 'format' => 'html', 'contentOptions' => ['class' => 'col-md-2 project-people']], ['headerOptions' => ['class' => 'text-center col-md-1'], 'format' => 'html', 'attribute' => 'show', 'filter' => [1 => \Yii::t('shop', 'On'), 0 => \Yii::t('shop', 'Off')], 'label' => Yii::t('shop', 'Show'), 'contentOptions' => ['class' => 'text-center col-md-1'], 'value' => function ($model) { return Html::a(Html::tag('i', '', ['class' => $model->show ? 'glyphicon glyphicon-ok text-primary' : 'glyphicon glyphicon-minus text-danger']), Url::to(['switch-show', 'id' => $model->id]), ['class' => 'category-nav']); }], ['headerOptions' => ['class' => 'text-center col-md-2'], 'attribute' => \Yii::t('shop', 'Manage'), 'value' => function ($model) { return ManageButtons::widget(['model' => $model]); }, 'format' => 'raw', 'contentOptions' => ['class' => 'col-md-2 text-center']]]]); ?> <?php Pjax::end(); ?> <?php echo Html::a(Html::tag('i', '', ['class' => 'fa fa-user-plus']) . Yii::t('shop', 'Create Category'), ['save', 'languageId' => Language::getCurrent()->id], ['class' => 'btn btn-primary btn-xs pull-right']); ?> </div> </div>
/** * @param integer $attrId * @param integer $languageId * @return mixed * @throws Exception */ public function actionAddValue($attrId, $languageId) { if (!empty($attrId)) { $languageId = empty($languageId) ? Language::getCurrent()->id : $languageId; $model = new ShopAttributeValue(); $modelTranslation = new ShopAttributeValueTranslation(); $attributeTextureModel = new AttributeTextureForm(); if (Yii::$app->request->post()) { if ($modelTranslation->load(Yii::$app->request->post())) { $model->attribute_id = $attrId; if (ShopAttribute::findOne($attrId)->type_id == 3 || ShopAttribute::findOne($attrId)->type_id == 4) { $colorTexture = new ShopAttributeValueColorTexture(); if (ShopAttribute::findOne($attrId)->type_id == 3) { if ($attributeTextureModel->load(Yii::$app->request->post())) { $colorTexture->color = $attributeTextureModel->color; } } elseif (ShopAttribute::findOne($attrId)->type_id == 4) { if ($attributeTextureModel->load(Yii::$app->request->post())) { $attributeTextureModel->imageFile = UploadedFile::getInstance($attributeTextureModel, 'imageFile'); $colorTexture->texture = $attributeTextureModel->upload(); } } $colorTexture->save(); $modelTranslation->value = $colorTexture->id; } if ($model->save()) { $modelTranslation->value_id = $model->id; $modelTranslation->language_id = $languageId; if ($modelTranslation->save()) { if (\Yii::$app->request->isPjax) { $searchAttributeValueModel = new SearchAttributeValue(); $dataProviderAttributeValue = $searchAttributeValueModel->search(Yii::$app->request->queryParams); return $this->renderPartial('add-value', ['dataProvider' => $dataProviderAttributeValue, 'attribute' => ShopAttribute::findOne($attrId), 'selectedLanguage' => Language::findOne($languageId), 'valueModel' => new ShopAttributeValue(), 'valueModelTranslation' => new ShopAttributeValueTranslation(), 'attributeTextureModel' => $attributeTextureModel]); } else { return $this->redirect(Url::toRoute(['save', 'attrId' => $attrId, 'languageId' => $languageId])); } } } else { throw new Exception($model->errors); } } } else { return $this->render(Url::toRoute(['add-value', 'attrId' => $attrId, 'languageId' => $languageId])); } } }
?> </h1> <p> <?php echo Html::a(Yii::t('shop', 'Create attribute'), Url::toRoute(['save', 'languageId' => Language::getCurrent()->id]), ['class' => 'btn btn-success']); ?> </p> </div> <div class="panel-body"> <?php Pjax::begin(); ?> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterRowOptions' => ['class' => 'm-b-sm m-t-sm'], 'options' => ['class' => 'project-list'], 'tableOptions' => ['id' => 'my-grid', 'class' => 'table table-hover'], 'summary' => "", 'columns' => [['attribute' => 'Id', 'value' => 'id', 'headerOptions' => ['class' => 'text-center'], 'contentOptions' => ['class' => 'text-center']], ['headerOptions' => ['class' => 'text-center col-md-2'], 'attribute' => 'title', 'value' => 'translation.title', 'label' => Yii::t('shop', 'Title'), 'format' => 'text', 'contentOptions' => ['class' => 'text-center project-title col-md-2']], ['attribute' => 'type', 'value' => function ($model) { return \Yii::t('shop', $model->type->title); }], ['attribute' => 'created_at', 'value' => 'created_at'], ['attribute' => 'updated_at', 'value' => 'updated_at'], ['headerOptions' => ['class' => 'text-center col-md-2'], 'attribute' => \Yii::t('shop', 'Manage'), 'value' => function ($model) { global $product; $product = $model; $languages = Language::findAll(['active' => true]); $list = Html::a('<span class="glyphicon glyphicon-remove"></span>', Url::toRoute(['remove', 'id' => $model->id]), ['title' => Yii::t('yii', 'Delete'), 'class' => 'btn btn-danger pull-right pjax']) . Html::tag('div', Html::a('Edit', Url::toRoute(['save', 'attrId' => $model->id, "languageId" => Language::getCurrent()->id]), ['class' => 'col-md-8 btn btn-default ']) . Html::a('<span class="caret"></span>', Url::toRoute(['save', 'attrId' => $model->id, "languageId" => Language::getCurrent()->id]), ['class' => 'block col-md-4 btn btn-default dropdown-toggle', 'type' => 'button', 'id' => 'dropdownMenu1', 'data-toggle' => 'dropdown', 'aria-haspopup' => 'true', 'aria-expanded' => 'true']) . Html::ul(ArrayHelper::map($languages, 'id', 'name'), ['item' => function ($item, $index) { return Html::tag('li', Html::a($item, Url::toRoute(['save', 'attrId' => $GLOBALS['product']->id, "languageId" => $index]), []), []); }, 'class' => 'dropdown-menu', 'aria-labelledby' => 'dropdownMenu1']), ['class' => 'btn-group pull-left']); return $list; }, 'format' => 'raw', 'contentOptions' => ['class' => 'col-md-2 text-center']]]]); ?> <?php Pjax::end(); ?> </div> </div>
echo Html::encode($this->title); ?> </h1> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'options' => ['class' => 'project-list'], 'summary' => "", 'columns' => [['class' => 'yii\\grid\\SerialColumn'], ['headerOptions' => ['class' => 'text-center col-md-1'], 'attribute' => 'product.articulus', 'value' => function ($model) { if (!empty($model->product->articulus)) { return $model->product->articulus; } return ''; }, 'label' => Yii::t('shop', 'Articulus'), 'format' => 'html', 'contentOptions' => ['class' => 'project-title']], ['headerOptions' => ['class' => 'text-center col-md-6'], 'attribute' => 'product.translation.title', 'value' => function ($model) { if (!empty($model->product->translation->title)) { $content = !empty($model->product->translation->title) ? Html::a(Html::tag('h3', $model->product->translation->title), Url::toRoute(['/shop/product/show', 'id' => $model->product->id, 'languageId' => Language::getCurrent()->id]), ['class' => "text-success"]) : ''; $content .= !empty($model->product->category->translation->title) ? Html::tag('p', Html::tag('small', Yii::t('shop', 'Category') . ': ' . Html::a($model->product->category->translation->title, Url::toRoute(['/shop/category/show', 'id' => $model->product->category_id, 'languageId' => Language::getCurrent()->id]), ['class' => 'text-info'])), ['class' => 'text-info']) : ''; $content .= !empty($model->product->translation->description) ? $model->product->translation->description : ''; return $content; } return ''; }, 'label' => Yii::t('shop', 'Title'), 'format' => 'html'], ['headerOptions' => ['class' => 'text-center col-md-2'], 'attribute' => 'image', 'value' => function ($model) { $imageUrl = !empty($model->product->image) ? $model->product->image->small : '/images/default.jpg'; return Html::a(Html::img(Url::toRoute([$imageUrl])), Url::toRoute(['/shop/product/show', 'id' => $model->product->id, 'languageId' => Language::getCurrent()->id])); }, 'label' => Yii::t('shop', 'Image'), 'format' => 'html', 'contentOptions' => ['class' => 'col-md-4 text-center']], ['headerOptions' => ['class' => 'text-center col-md-3'], 'value' => function ($model) { $deleteButton = Html::a(Yii::t('shop', 'Remove from favorites'), Url::to(['/shop/favorite-product/remove', 'productId' => $model->product_id]), ['class' => 'btn btn-warning col-md-12 m-t-xs']); $goToButton = Html::a(Yii::t('shop', 'Go to product'), Url::to(['/shop/product/show', 'id' => $model->product_id]), ['class' => 'btn btn-primary col-md-12']); return $goToButton . $deleteButton; }, 'format' => 'raw', 'contentOptions' => ['class' => 'text-center']]]]); ?> </div>
} ?> <?php } ?> </td> <td class="text-center"> <?php echo Html::a('', ['switch-show', 'id' => $image->id], ['class' => $image->show ? 'glyphicon glyphicon-ok text-primary' : 'glyphicon glyphicon-minus text-danger']); ?> </td> <td> <?php echo Html::a('', ['edit', 'id' => $image->id, 'langId' => Language::getCurrent()->id], ['class' => 'glyphicon glyphicon-edit text-warning btn btn-default btn-sm']); ?> </td> <td> <?php echo Html::a('', ['remove', 'id' => $image->id], ['class' => 'glyphicon glyphicon-remove text-danger btn btn-default btn-sm']); ?> </td> </tr> <?php } ?> </tbody> <?php }
/** * Adds basic info for product model. * * Users which have 'updateOwnProduct' permission can add or edit basic info only for Product models that have been created by their. * Users which have 'updateProduct' permission can can add or edit basic info for all Product models. * * @param integer $id * @param integer $languageId * @return mixed * @throws ForbiddenHttpException */ public function actionAddBasic($id = null, int $languageId) { if (!empty($languageId)) { $selectedLanguage = Language::findOne($languageId); } else { $selectedLanguage = Language::getCurrent(); } if (!empty($id)) { $product = Product::findOne($id); if (\Yii::$app->user->can('updateProduct', ['productOwner' => $product->owner])) { $products_translation = ProductTranslation::find()->where(['product_id' => $id, 'language_id' => $languageId])->one(); if (empty($products_translation)) { $products_translation = new ProductTranslation(); } } else { throw new ForbiddenHttpException(); } } else { if (\Yii::$app->user->can('createProduct')) { $this->trigger(self::EVENT_BEFORE_CREATE_PRODUCT); $product = new Product(); $products_translation = new ProductTranslation(); } else { throw new ForbiddenHttpException(); } } if (Yii::$app->request->isPost) { $product->load(Yii::$app->request->post()); if ($product->isNewRecord) { $product->owner = Yii::$app->user->id; if (\Yii::$app->user->can('createProductWithoutModeration')) { $product->status = Product::STATUS_SUCCESS; } if ($product->validate()) { $product->save(); $this->trigger(self::EVENT_AFTER_CREATE_PRODUCT, new ProductEvent(['productId' => $product->id, 'userId' => Yii::$app->user->id, 'time' => $product->creation_time])); } } $this->trigger(self::EVENT_BEFORE_EDIT_PRODUCT, new ProductEvent(['productId' => $product->id, 'userId' => Yii::$app->user->id, 'time' => $products_translation->update_time])); $products_translation->load(Yii::$app->request->post()); if ($product->validate() && $products_translation->validate()) { if (empty($products_translation->seoUrl)) { $products_translation->seoUrl = Inflector::slug($products_translation->title); } $products_translation->product_id = $product->id; $products_translation->language_id = $selectedLanguage->id; $products_translation->save(); $product->save(); $this->trigger(self::EVENT_AFTER_EDIT_PRODUCT, new ProductEvent(['productId' => $product->id, 'userId' => Yii::$app->user->id, 'time' => $products_translation->update_time])); } } if (Yii::$app->request->isPjax) { return $this->renderPartial('add-basic', ['languages' => Language::find()->all(), 'selectedLanguage' => $selectedLanguage, 'product' => $product, 'products_translation' => $products_translation, 'params_translation' => new ParamTranslation()]); } else { return $this->render('save', ['viewName' => 'add-basic', 'selectedLanguage' => $selectedLanguage, 'product' => $product, 'languages' => Language::find()->all(), 'params' => ['languages' => Language::find()->all(), 'selectedLanguage' => $selectedLanguage, 'product' => $product, 'products_translation' => $products_translation, 'categories' => CategoryTranslation::find()->where(['language_id' => $selectedLanguage->id])->all(), 'params_translation' => new ParamTranslation()]]); } }
?> </td> <td> <?php echo ManageButtons::widget(['model' => $country]); ?> </td> </tr> <?php } ?> </tbody> <?php } ?> </table> <a href="<?php echo Url::to(['/shop/country/save', 'languageId' => Language::getCurrent()->id]); ?> " class="btn btn-primary pull-right"> <i class="fa fa-user-plus"></i> <?php echo Yii::t('shop', 'Add country'); ?> </a> </div> </div> </div> </div>