コード例 #1
0
ファイル: Module.php プロジェクト: simple-yii2/gallery
 /**
  * Database checking
  * @return void
  */
 protected function checkDatabase()
 {
     //schema
     $db = Yii::$app->db;
     $filename = dirname(__DIR__) . '/schema/' . $db->driverName . '.sql';
     $sql = explode(';', file_get_contents($filename));
     foreach ($sql as $s) {
         if (trim($s) !== '') {
             $db->createCommand($s)->execute();
         }
     }
     //rbac
     $auth = Yii::$app->getAuthManager();
     if ($auth->getRole('Gallery') === null) {
         //gallery role
         $gallery = $auth->createRole('Gallery');
         $auth->add($gallery);
     }
     //data
     $root = Gallery::find()->roots()->one();
     if ($root === null) {
         $root = new Gallery(['title' => 'Root']);
         $root->makeRoot();
     }
 }
コード例 #2
0
 /**
  * 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);
 }
コード例 #3
0
ファイル: Menu.php プロジェクト: simple-yii2/menu
 /**
  * Make gallery alias list
  * @return array
  */
 protected static function getGalleryAliasList()
 {
     $items = [];
     foreach (\gallery\common\models\Gallery::find()->select(['alias', 'title'])->andWhere(['>', 'lft', '1'])->asArray()->all() as $row) {
         $items[$row['alias']] = $row['title'];
     }
     return $items;
 }
コード例 #4
0
 /**
  * Show gallery
  * @param string $alias 
  * @return void
  */
 public function actionIndex($alias)
 {
     $model = Gallery::findByAlias($alias);
     if ($model === null || !$model->active) {
         throw new NotFoundHttpException(Yii::t('yii', 'Page not found.'));
     }
     return $this->render('index', ['model' => $model]);
 }
コード例 #5
0
 /**
  * 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;
 }
コード例 #6
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     $this->active = true;
     $this->type = self::TYPE_SECTION;
 }
コード例 #7
0
 /**
  * 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;
 }
コード例 #8
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     $this->type = self::TYPE_COLLECTION;
 }