Exemplo n.º 1
0
 /**
  * Images relation
  * @return \yii\db\ActiveQueryInterface
  */
 public function getImages()
 {
     return $this->hasMany(SliderImage::className(), ['slider_id' => 'id'])->inverseOf('slider');
 }
Exemplo n.º 2
0
 /**
  * Object saving
  * @return boolean
  */
 public function save()
 {
     //validation
     if (!$this->validate()) {
         return false;
     }
     $object = $this->_object;
     //attributes
     $object->file = $this->file;
     $object->thumb = $this->thumb;
     $object->title = $this->title;
     $object->description = $this->description;
     $object->url = $this->url;
     //files
     Yii::$app->storage->storeObject($object);
     //saving object
     if (!$object->save(false)) {
         return false;
     }
     //image count
     $object->slider->updateImageCount();
     $slider = $object->slider;
     if ($slider !== null) {
         $slider->imageCount = SliderImage::find()->andWhere(['slider_id' => $object->slider_id])->count();
         $slider->update(false, ['imageCount']);
     }
     return true;
 }
Exemplo n.º 3
0
 /**
  * Image delete
  * @param string $id Slider image id
  * @return void
  */
 public function actionDelete($id)
 {
     $object = SliderImage::findOne($id);
     if ($object === null) {
         throw new BadRequestHttpException(Yii::t('slider', 'Image not found.'));
     }
     $slider = $object->slider;
     if ($slider === null) {
         throw new BadRequestHttpException(Yii::t('slider', 'Slider not found.'));
     }
     //object
     if ($object->delete()) {
         Yii::$app->storage->removeObject($object);
         Yii::$app->session->setFlash('success', Yii::t('slider', 'Image deleted successfully.'));
     }
     $slider->updateImageCount();
     return $this->redirect(['index', 'slider_id' => $slider->id]);
 }