/** * 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(); }
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; } }
/** * 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; }
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(); } } }
/** * 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]); }
/** * @return \yii\db\ActiveQuery */ public function getImageGalleries() { return $this->hasMany(ImageGallery::className(), ['gallery_id' => 'id'])->orderBy('item_order'); }
/** * @return \yii\db\ActiveQuery */ public function getImageGalleries() { return $this->hasMany(ImageGallery::className(), ['image_id' => 'id']); }