/** * Gallery deleting. * @param integer $id Gallery id. * @return void */ public function actionDelete($id) { $model = Gallery::findOne($id); if ($model === null) { throw new BadRequestHttpException(Yii::t('gallery', 'Item not found.')); } $parent = $model->parents(1)->one(); $collections = []; if ($model instanceof GalleryCollection) { $collections[] = $model; } $collections = array_merge($collections, $model->children()->collection()->all()); foreach ($collections as $collection) { foreach ($collection->images as $image) { $image->delete(); Yii::$app->storage->removeObject($image); } Yii::$app->storage->removeObject($collection); } if ($model->deleteWithChildren()) { Yii::$app->session->setFlash('success', Yii::t('gallery', 'Item deleted successfully.')); } $url = ['index']; if ($parent !== null && !$parent->isRoot()) { $url['id'] = $parent->id; } return $this->redirect($url); }
/** * Creates new gallery section using model attributes. * @return boolean */ public function create($parent_id) { if (!$this->validate()) { return false; } $parent = Gallery::findOne($parent_id); if ($parent === null) { $parent = Gallery::find()->roots()->one(); } if ($parent === null) { return false; } $this->object = $object = new GallerySection(['title' => $this->title]); if (!$object->appendTo($parent, false)) { return false; } $object->makeAlias(); $object->update(false, ['alias']); return true; }
/** * Creates new gallery using model attributes. * @return boolean */ public function create($parent_id) { if (!$this->validate()) { return false; } $parent = Gallery::findOne($parent_id); if ($parent === null) { $parent = Gallery::find()->roots()->one(); } if ($parent === null) { return false; } $this->object = $object = new GalleryCollection(['active' => (bool) $this->active, 'image' => empty($this->image) ? null : $this->image, 'thumb' => empty($this->thumb) ? null : $this->thumb, 'title' => $this->title, 'alias' => $this->alias, 'description' => $this->description, 'imageCount' => sizeof($this->images)]); Yii::$app->storage->storeObject($object); if (!$object->appendTo($parent, false)) { return false; } $object->makeAlias(); $object->update(false, ['alias']); $this->updateImages(); return true; }