Пример #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
 /**
  * Making alias list for specified menu item type
  * @param integer $type Menu item type
  * @return void
  */
 public function actionAlias($type)
 {
     return Json::encode(['type' => (int) $type, 'items' => Menu::getAliasList($type)]);
 }
Пример #5
0
?>

	<?php 
echo $form->field($model, 'name');
?>

	<?php 
echo $form->field($model, 'type')->dropDownList(Menu::getTypeList(), $typeOptions);
?>

	<?php 
echo $form->field($model, 'url', $urlOptions);
?>

	<?php 
echo $form->field($model, 'alias', $aliasOptions)->dropDownList(Menu::getAliasList($model->type));
?>

	<div class="form-group">
		<div class="col-sm-offset-3 col-sm-6">
			<?php 
echo Html::submitButton(Yii::t('menu', 'Save'), ['class' => 'btn btn-primary']);
?>
			<?php 
echo Html::a(Yii::t('menu', 'Cancel'), ['index', 'id' => $id], ['class' => 'btn btn-default']);
?>
		</div>
	</div>

<?php 
ActiveForm::end();