/**
  * function ::create ($data)
  */
 public static function create($data)
 {
     $now = strtotime('now');
     $username = Yii::$app->user->identity->username;
     $model = new GeneralInfoTranslation();
     if ($model->load($data)) {
         if ($log = new UserLog()) {
             $log->username = $username;
             $log->action = "Create";
             $log->object_class = "GeneralInfoTranslation";
             $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->content = FileUtils::copyContentImages(['content' => $model->content, '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 = GeneralInfoTranslation::find();
     if (!empty($params['general_info_id'])) {
         $query->where(['general_info_id' => $params['general_info_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, 'general_info_id' => $this->general_info_id, 'language_id' => $this->language_id]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'content', $this->content])->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_keywords', $this->meta_keywords])->andFilterWhere(['like', 'meta_description', $this->meta_description])->andFilterWhere(['like', 'image_path', $this->image_path]);
     return $dataProvider;
 }
 /**
  * Finds the GeneralInfoTranslation model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return GeneralInfoTranslation the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = GeneralInfoTranslation::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
示例#4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getGeneralInfoTranslations()
 {
     return $this->hasMany(GeneralInfoTranslation::className(), ['general_info_id' => 'id']);
 }
示例#5
0
 /**
  * Deletes an existing GeneralInfo 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 (GeneralInfoTranslation::findAll(['general_info_id' => $model->id]) as $item) {
             $item->delete();
         }
         $model->delete();
         return $this->goBack(Url::previous());
     } else {
         throw new NotFoundHttpException();
     }
 }