示例#1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = ShopAttribute::find();
     // add conditions that should always apply here
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     // grid filtering conditions
     $query->andFilterWhere(['id' => $this->id, 'type_id' => $this->type_id, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     return $dataProvider;
 }
示例#2
0
use yii\widgets\ActiveForm;
use yii\widgets\Pjax;
?>

<?php 
Pjax::begin(['enablePushState' => false, 'timeout' => 5000]);
?>

<?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' => ['id', ['label' => \Yii::t('shop', 'Title'), 'value' => 'translation.title'], ['attribute' => 'value', 'value' => function ($model) {
    $attribute = ShopAttribute::findOne($model->attribute_id);
    if ($attribute->type_id == 3) {
        $color = ShopAttributeValueColorTexture::findOne($model->translation->value)->color;
        return Html::tag('div', '', ['style' => 'width: 50px; height: 50px; background-color:' . $color]);
    }
    if (ShopAttribute::findOne($model->attribute_id)->type_id == 4) {
        return ShopAttributeValueColorTexture::getTexture($model->translation->value);
    }
    return $model->translation->value;
}, 'format' => 'raw']]]);
?>

<div class="shop-attribute-value-form">

    <?php 
$valueForm = ActiveForm::begin(['method' => 'post', 'options' => ['data-pjax' => true, 'enctype' => 'multipart/form-data'], 'action' => ['attribute/add-value', 'attrId' => $attribute->id, 'languageId' => $selectedLanguage->id]]);
?>

    <?php 
echo $valueForm->field($valueModelTranslation, 'title')->textInput(['maxlength' => true]);
?>
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getShopAttributes()
 {
     return $this->hasMany(ShopAttribute::className(), ['type_id' => 'id']);
 }
 /**
  * @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]));
         }
     }
 }
 /**
  * @inheritdoc
  */
 public function rules()
 {
     return [[['attribute_id'], 'integer'], [['attribute_id'], 'exist', 'skipOnError' => true, 'targetClass' => ShopAttribute::className(), 'targetAttribute' => ['attribute_id' => 'id']]];
 }