/**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = ProductTranslation::find();
     if (!empty($params['product_id'])) {
         $query->where(['product_id' => $params['product_id']]);
     }
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]);
     $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;
     }
     $query->andFilterWhere(['id' => $this->id, 'product_id' => $this->product_id, 'language_id' => $this->language_id]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'detail', $this->detail])->andFilterWhere(['like', 'shipping_detail', $this->shipping_detail])->andFilterWhere(['like', 'search_text', $this->search_text])->andFilterWhere(['like', 'page_title', $this->page_title])->andFilterWhere(['like', 'h1', $this->h1])->andFilterWhere(['like', 'meta_title', $this->meta_title])->andFilterWhere(['like', 'meta_description', $this->meta_description])->andFilterWhere(['like', 'meta_keywords', $this->meta_keywords])->andFilterWhere(['like', 'image_path', $this->image_path]);
     return $dataProvider;
 }
Example #2
0
 /**
  * function ::create ($data)
  */
 public static function create($data)
 {
     $now = strtotime('now');
     $username = Yii::$app->user->identity->username;
     $model = new ProductTranslation();
     if ($model->load($data)) {
         if ($log = new UserLog()) {
             $log->username = $username;
             $log->action = "Create";
             $log->object_class = "ProductTranslation";
             $log->created_at = $now;
             $log->is_success = 0;
             $log->save();
         }
         do {
             $path = FileUtils::generatePath($now);
         } while (file_exists(Yii::$app->params['images_folder'] . $path));
         $model->image_path = $path;
         $targetFolder = Yii::$app->params['images_folder'] . $model->image_path;
         $targetUrl = Yii::$app->params['images_url'] . $model->image_path;
         $model->description = FileUtils::copyContentImages(['content' => $model->description, 'defaultFromFolder' => Yii::$app->params['uploads_folder'], 'toFolder' => $targetFolder, 'toUrl' => $targetUrl, 'removeInputImage' => true]);
         $model->detail = FileUtils::copyContentImages(['content' => $model->detail, 'defaultFromFolder' => Yii::$app->params['uploads_folder'], 'toFolder' => $targetFolder, 'toUrl' => $targetUrl, 'removeInputImage' => true]);
         $model->shipping_detail = FileUtils::copyContentImages(['content' => $model->shipping_detail, 'defaultFromFolder' => Yii::$app->params['uploads_folder'], 'toFolder' => $targetFolder, 'toUrl' => $targetUrl, 'removeInputImage' => true]);
         if ($model->save()) {
             if ($log) {
                 $log->object_pk = $model->id;
                 $log->is_success = 1;
                 $log->save();
             }
             return $model;
         }
         $model->getErrors();
         return $model;
     }
     return false;
 }
Example #3
0
?>
    
    <div class="col-md-6">
        <?php 
echo $form->field($model, 'name')->textInput(['maxlength' => true]);
?>
        <?php 
echo $form->field($model, 'description')->widget(CKEditor::className(), ['preset' => 'standard', 'clientOptions' => ['height' => 200, 'language' => 'vi', 'uiColor' => '#E4E4E4', 'image_previewText' => '&nbsp;', 'filebrowserUploadUrl' => Url::to(['file/ckeditor-upload-image'], true)]]);
?>
        <?php 
echo $form->field($model, 'detail')->widget(CKEditor::className(), ['preset' => 'standard', 'clientOptions' => ['height' => 200, 'language' => 'vi', 'uiColor' => '#E4E4E4', 'image_previewText' => '&nbsp;', 'filebrowserUploadUrl' => Url::to(['file/ckeditor-upload-image'], true)]]);
?>
    </div>
    <div class="col-md-6">
        <?php 
echo $form->field($model, 'language_id')->dropDownList(array_diff_key($this->context->languages_idToName, ArrayHelper::map(ProductTranslation::find()->where(['product_id' => $model->product_id])->andWhere(['<>', 'id', (int) $model->id])->all(), 'language_id', 'language_id')));
?>
        <?php 
echo $form->field($model, 'page_title')->textInput(['maxlength' => true]);
?>
        <?php 
echo $form->field($model, 'h1')->textInput(['maxlength' => true]);
?>
        <?php 
echo $form->field($model, 'meta_title')->textInput(['maxlength' => true]);
?>
        <?php 
echo $form->field($model, 'meta_description')->textInput(['maxlength' => true]);
?>
        <?php 
echo $form->field($model, 'meta_keywords')->textInput(['maxlength' => true]);
 /**
  * Finds the ProductTranslation model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return ProductTranslation the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = ProductTranslation::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Example #5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getProductTranslations()
 {
     return $this->hasMany(ProductTranslation::className(), ['product_id' => 'id']);
 }
Example #6
0
 /**
  * Deletes an existing Product model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param integer $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     if ($model = $this->findModel($id)) {
         foreach (ProductTranslation::findAll(['product_id' => $model->id]) as $item) {
             $item->delete();
         }
         foreach (ProductImage::findAll(['product_id' => $model->id]) as $item) {
             $item->delete();
         }
         foreach (ProductCategoryToProduct::findAll(['product_id' => $model->id]) as $item) {
             $item->delete();
         }
         foreach (ProductCollectionToProduct::findAll(['product_id' => $model->id]) as $item) {
             $item->delete();
         }
         $model->delete();
         return $this->goBack(Url::previous());
     } else {
         throw new NotFoundHttpException();
     }
 }