Beispiel #1
0
 /**
  * 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();
     }
 }
Beispiel #2
0
 /**
  * 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;
 }
 /**
  * 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;
 }
 /**
  * Gallery tree.
  * @param integer|null $id Initial item id
  * @return void
  */
 public function actionIndex($id = null)
 {
     $initial = Gallery::findOne($id);
     $dataProvider = new ActiveDataProvider(['query' => Gallery::find()]);
     return $this->render('index', ['dataProvider' => $dataProvider, 'initial' => $initial]);
 }