protected function findModel($id)
 {
     if (($model = Carousel::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('页面不存在!');
     }
 }
Esempio n. 2
0
 /**
  * Создание нового элемента
  * @return \yii\db\ActiveQuery
  */
 public function createObject()
 {
     $modelCarousel = new Carousel();
     $modelCarousel->images_num = 1;
     $modelCarousel->images_label = 'carousel';
     $modelCarousel->temp = 1;
     // при создании нового меню утанавливаем флаг "временный" $modelCarousel->temp
     $modelCarousel->user_id = Yii::$app->user->id;
     $modelCarousel->save();
     Yii::$app->session->set('tempModel', 'Carousel');
     Yii::$app->session->set('tempId', $modelCarousel->id);
     return $modelCarousel ? $modelCarousel : null;
 }
Esempio n. 3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Carousel::find();
     $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;
     }
     $query->andFilterWhere(['id' => $this->id, 'is_target_self' => $this->is_target_self, 'carousel_order' => $this->carousel_order, 'status' => $this->status, 'created_date' => $this->created_date, 'modified_date' => $this->modified_date]);
     $query->andFilterWhere(['like', 'image_path', $this->image_path])->andFilterWhere(['like', 'image_link', $this->image_link])->andFilterWhere(['like', 'caption', $this->caption])->andFilterWhere(['like', 'created_by', $this->created_by])->andFilterWhere(['like', 'modified_by', $this->modified_by]);
     return $dataProvider;
 }
Esempio n. 4
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Carousel::find();
     $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;
     }
     $query->andFilterWhere(['id' => $this->id, 'images_num' => $this->images_num, 'product_id' => $this->product_id, 'user_id' => $this->user_id]);
     $query->andFilterWhere(['like', 'images_label', $this->images_label])->andFilterWhere(['like', 'header', $this->header])->andFilterWhere(['like', 'content', $this->content]);
     return $dataProvider;
 }
Esempio n. 5
0
 /**
  * @return string
  */
 public function actionDeleteAvatar()
 {
     $imageData = Json::decode(Yii::$app->request->post('imageData'));
     $modelImageForm = new ImageForm();
     $modelImageForm->deleteImage();
     if (Yii::$app->session->get('error')) {
         echo $error = Yii::$app->session->get('error');
     } else {
         $error = false;
     }
     /* @var $model \common\models\Profile */
     if ($imageData['modelName'] == 'Carousel') {
         $model = Carousel::findOne($imageData['object_id']);
     } elseif ($imageData['modelName'] == 'Product') {
         $model = Product::findOne($imageData['object_id']);
     }
     $imagesObject = $model->imagesOfObjects;
     return $this->render('@common/widgets/ImageLoad/views/_formAutoload', ['modelName' => $imageData['modelName'], 'id' => $imageData['id'], 'object_id' => $imageData['object_id'], 'images_num' => $imageData['images_num'], 'images_label' => $imageData['images_label'], 'images_temp' => $imageData['images_temp'], 'imageSmallWidth' => $imageData['imageSmallWidth'], 'imageSmallHeight' => $imageData['imageSmallHeight'], 'imagesObject' => $imagesObject, 'modelImageForm' => $modelImageForm, 'baseUrl' => $imageData['baseUrl'], 'imagePath' => $imageData['imagePath'], 'noImage' => $imageData['noImage'], 'imageClass' => $imageData['imageClass'], 'buttonDeleteClass' => $imageData['buttonDeleteClass'], 'imageContainerClass' => $imageData['imageContainerClass'], 'formImagesContainerClass' => $imageData['formImagesContainerClass'], 'error' => $error]);
 }
Esempio n. 6
0
 public function init()
 {
     parent::init();
     /* Инициализация объекта, если он есть в сессии */
     if ($this->tempModel == 'Carousel') {
         if ($this->tempModel = Carousel::findOne($this->tempId)) {
             // Если объект загружен
             $this->tempDelete = true;
             // Устанавливаем флаг tempDelete для удаления
         }
     }
     if ($this->tempModel == 'Product') {
         if ($this->tempModel = Product::findOne($this->tempId)) {
             // Если объект загружен
             $this->tempDelete = true;
             // Устанавливаем флаг tempDelete для удаления
         }
     }
 }
Esempio n. 7
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getObject()
 {
     return $this->hasOne(Carousel::className(), ['id' => 'object_id']);
 }
Esempio n. 8
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCarousels()
 {
     return $this->hasMany(Carousel::className(), ['product_id' => 'id']);
 }
Esempio n. 9
0
 /**
  * Finds the Carousel model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Carousel the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Carousel::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Esempio n. 10
0
 public function actionIndex()
 {
     //获取轮播图
     $this->view_data['carousel'] = Carousel::find()->where("status = 1")->asArray()->all();
     return $this->render("index", $this->view_data);
 }
Esempio n. 11
0
 /**
  * Finds the Carousel model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Carousel the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Carousel::findOne(['id' => $id, 'status' => [STATUS::STATUS_ACTIVE, STATUS::STATUS_INACTIVE]])) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Esempio n. 12
0
 public function actionIndex()
 {
     $carousel = Carousel::find()->all();
     return $this->render('index', ['carousel' => $carousel]);
 }