/**
  * function ::create ($data)
  */
 public static function create($data)
 {
     $now = strtotime('now');
     $username = Yii::$app->user->identity->username;
     $model = new ProductCollectionTranslation();
     if ($model->load($data)) {
         if ($log = new UserLog()) {
             $log->username = $username;
             $log->action = 'Create';
             $log->object_class = 'ProductCollectionTranslation';
             $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]);
         if ($model->save()) {
             if ($log) {
                 $log->object_pk = $model->id;
                 $log->is_success = 1;
                 $log->save();
             }
             return $model;
         }
         $model->getErrors();
         return $model;
     }
     return false;
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = ProductCollectionTranslation::find();
     if (!empty($params['product_collection_id'])) {
         $query->where(['product_collection_id' => $params['product_collection_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, 'language_id' => $this->language_id, 'product_collection_id' => $this->product_collection_id]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'description', $this->description])->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', 'image_path', $this->image_path])->andFilterWhere(['like', 'caption', $this->caption]);
     return $dataProvider;
 }
Exemplo n.º 3
0
use yii\web\View;
use yii\widgets\ActiveForm;
/* @var $this View */
/* @var $model ProductCollectionTranslation */
/* @var $form ActiveForm */
?>

<div class="product-collection-translation-form">

    <?php 
$form = ActiveForm::begin();
?>
    
    <div class="col-md-6">
        <?php 
echo $form->field($model, 'language_id')->dropDownList(array_diff_key($this->context->languages_idToName, ArrayHelper::map(ProductCollectionTranslation::find()->where(['product_collection_id' => $model->product_collection_id])->andWhere(['<>', 'id', (int) $model->id])->all(), 'language_id', 'language_id')));
?>
        <?php 
echo $form->field($model, 'product_collection_id')->textInput(['readonly' => true, 'type' => 'hidden'])->label(false);
?>
        <?php 
echo $form->field($model, 'name')->textInput(['maxlength' => true]);
?>
        <?php 
echo $form->field($model, 'caption')->textInput(['maxlength' => true]);
?>
        <?php 
// echo $form->field($model, 'search_text')->textInput(['maxlength' => true])->label()
?>
    </div>
    <div class="col-md-6">
 /**
  * Finds the ProductCollectionTranslation model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return ProductCollectionTranslation the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = ProductCollectionTranslation::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Exemplo n.º 5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getProductCollectionTranslations()
 {
     return $this->hasMany(ProductCollectionTranslation::className(), ['language_id' => 'id']);
 }