Пример #1
0
 /**
  * Sets usedImagesIds property
  */
 private function setUsedImagesIds()
 {
     // clean junction table
     ImageGallery::deleteAll('image_id IS NULL');
     // return array populated with image_ids
     $this->usedImagesIds = ImageGallery::find()->select('image_id')->andWhere(['gallery_id' => $this->item_id])->column();
 }
Пример #2
0
 public function beforeDelete()
 {
     if (parent::beforeDelete()) {
         $items = ImageGallery::find()->where(['ebay_item_id' => $this->ebay_item_id])->all();
         foreach ($items as $item) {
             $item->delete();
         }
         return true;
     } else {
         return false;
     }
 }
Пример #3
0
 /**
  * Returns array of photos with delete button of given gallery
  * @return array
  */
 public function getPhotosWithControl()
 {
     $imageGalleries = ImageGallery::find()->andWhere(['gallery_id' => $this->item_id])->orderBy('item_order')->all();
     $photosArray = [];
     /** @var ImageGallery $imageGallery */
     foreach ($imageGalleries as $imageGallery) {
         if ($imageGallery->image) {
             $photosArray[$imageGallery->id] = ['content' => $this->renderPhotoWithControl($imageGallery->image)];
         }
     }
     return $photosArray;
 }
Пример #4
0
 public function addImagesToDB($item, $ebayitemid)
 {
     if (array_key_exists('PictureURL', $item['Item'])) {
         foreach ($item['Item']['PictureURL'] as $field) {
             $image = new ImageGallery();
             $image->ebay_item_id = $ebayitemid;
             $image->image_url = $field;
             $image->save();
         }
     }
 }
Пример #5
0
 /**
  * Removes photo from gallery
  * @param $gid
  * @param $pid
  * @return \yii\web\Response
  * @throws \Exception
  */
 public function actionRemovePhoto($gid, $pid)
 {
     /** @var ImageGallery $imageGallery */
     $imageGallery = ImageGallery::findOne(['gallery_id' => $gid, 'image_id' => $pid]);
     $imageGallery->delete();
     return $this->redirect(['photos', 'id' => $gid]);
 }
Пример #6
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getImageGalleries()
 {
     return $this->hasMany(ImageGallery::className(), ['gallery_id' => 'id'])->orderBy('item_order');
 }
Пример #7
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getImageGalleries()
 {
     return $this->hasMany(ImageGallery::className(), ['image_id' => 'id']);
 }