Пример #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('Menu') === null) {
         //menu role
         $menu = $auth->createRole('Menu');
         $auth->add($menu);
     }
     //data
     $root = Menu::find()->roots()->one();
     if ($root === null) {
         $root = new Menu(['name' => 'Root']);
         $root->makeRoot();
     }
 }
Пример #2
0
 /**
  * Get main menu items
  * @param boolean $activeOnly 
  * @return array
  */
 public static function getItems($activeOnly = true)
 {
     $root = models\Menu::find()->roots()->one();
     $query = $root->children();
     if ($activeOnly) {
         $query->andWhere(['active' => true]);
     }
     $children = $query->all();
     $result = [];
     for ($i = 0; $i < sizeof($children); $i++) {
         $result[] = self::makeBranch($children, $i);
     }
     return $result;
 }
Пример #3
0
 /**
  * Main menu item creation
  * @return boolean
  */
 public function create($parent_id)
 {
     if (!$this->validate()) {
         return false;
     }
     $parent = Menu::findOne($parent_id);
     if ($parent === null) {
         $parent = Menu::find()->roots()->one();
     }
     if ($parent === null) {
         return false;
     }
     $this->item = new Menu();
     $this->item->setAttributes(['name' => $this->name, 'active' => $this->active, 'type' => $this->type, 'url' => $this->url, 'alias' => $this->alias], false);
     $success = $this->item->appendTo($parent, false);
     return $success;
 }
Пример #4
0
 /**
  * Main menu tree
  * @param integer|null $id Initial item id
  * @return void
  */
 public function actionIndex($id = null)
 {
     $initial = Menu::findOne($id);
     $dataProvider = new ActiveDataProvider(['query' => Menu::find()]);
     return $this->render('index', ['dataProvider' => $dataProvider, 'initial' => $initial]);
 }