コード例 #1
0
 public function down()
 {
     $userTable = Configs::instance()->userTable;
     if ($this->db->schema->getTableSchema($userTable, true) !== null) {
         $this->dropTable($userTable);
     }
 }
コード例 #2
0
ファイル: Menu.php プロジェクト: thinkwill/yii2-admin
 /**
  * @inheritdoc
  */
 public static function getDb()
 {
     if (Configs::instance()->db !== null) {
         return Configs::instance()->db;
     } else {
         return parent::getDb();
     }
 }
コード例 #3
0
 /**
  * @inheritdoc
  */
 public function down()
 {
     $this->dropTable(Configs::instance()->menuTable);
 }
コード例 #4
0
ファイル: admin.php プロジェクト: thinkwill/yii2-admin
    )
    DROP dbo.trigger_auth_item_child;
GO
SQL;
    $command->setSql($sql)->execute();
}
if ($schema->getTableSchema($authManager->assignmentTable)) {
    $command->dropTable($authManager->assignmentTable)->execute();
}
if ($schema->getTableSchema($authManager->itemChildTable)) {
    $command->dropTable($authManager->itemChildTable)->execute();
}
if ($schema->getTableSchema($authManager->itemTable)) {
    $command->dropTable($authManager->itemTable)->execute();
}
if ($schema->getTableSchema($authManager->ruleTable)) {
    $command->dropTable($authManager->ruleTable)->execute();
}
// thinkwill/admin
if ($schema->getTableSchema(Configs::menuTable())) {
    $command->dropTable(Configs::menuTable())->execute();
}
if ($schema->getTableSchema(Configs::userTable())) {
    $command->dropTable(Configs::userTable())->execute();
}
foreach ($migrations as $migration => $path) {
    $file = Yii::getAlias($path . '/' . $migration . '.php');
    include_once $file;
    $migration = new $migration();
    $migration->up();
}
コード例 #5
0
ファイル: Helper.php プロジェクト: thinkwill/yii2-admin
 /**
  * Use to invalidate cache.
  */
 public static function invalidate()
 {
     if (Configs::cache() !== null) {
         TagDependency::invalidate(Configs::cache(), Configs::CACHE_TAG);
     }
 }
コード例 #6
0
ファイル: MenuHelper.php プロジェクト: thinkwill/yii2-admin
 /**
  * Use to get assigned menu of user.
  * @param mixed $userId
  * @param integer $root
  * @param \Closure $callback use to reformat output.
  * callback should have format like
  * 
  * ```
  * function ($menu) {
  *    return [
  *        'label' => $menu['name'],
  *        'url' => [$menu['route']],
  *        'options' => $data,
  *        'items' => $menu['children']
  *        ]
  *    ]
  * }
  * ```
  * @param boolean  $refresh
  * @return array
  */
 public static function getAssignedMenu($userId, $root = null, $callback = null, $refresh = false)
 {
     $config = Configs::instance();
     /* @var $manager \yii\rbac\BaseManager */
     $manager = Yii::$app->getAuthManager();
     $menus = Menu::find()->asArray()->indexBy('id')->all();
     $key = [__METHOD__, $userId, $manager->defaultRoles];
     $cache = $config->cache;
     if ($refresh || $cache === null || ($assigned = $cache->get($key)) === false) {
         $routes = $filter1 = $filter2 = [];
         if ($userId !== null) {
             foreach ($manager->getPermissionsByUser($userId) as $name => $value) {
                 if ($name[0] === '/') {
                     if (substr($name, -2) === '/*') {
                         $name = substr($name, 0, -1);
                     }
                     $routes[] = $name;
                 }
             }
         }
         foreach ($manager->defaultRoles as $role) {
             foreach ($manager->getPermissionsByRole($role) as $name => $value) {
                 if ($name[0] === '/') {
                     if (substr($name, -2) === '/*') {
                         $name = substr($name, 0, -1);
                     }
                     $routes[] = $name;
                 }
             }
         }
         $routes = array_unique($routes);
         sort($routes);
         $prefix = '\\';
         foreach ($routes as $route) {
             if (strpos($route, $prefix) !== 0) {
                 if (substr($route, -1) === '/') {
                     $prefix = $route;
                     $filter1[] = $route . '%';
                 } else {
                     $filter2[] = $route;
                 }
             }
         }
         $assigned = [];
         $query = Menu::find()->select(['id'])->asArray();
         if (count($filter2)) {
             $assigned = $query->where(['route' => $filter2])->column();
         }
         if (count($filter1)) {
             $query->where('route like :filter');
             foreach ($filter1 as $filter) {
                 $assigned = array_merge($assigned, $query->params([':filter' => $filter])->column());
             }
         }
         $assigned = static::requiredParent($assigned, $menus);
         if ($cache !== null) {
             $cache->set($key, $assigned, $config->cacheDuration, new TagDependency(['tags' => Configs::CACHE_TAG]));
         }
     }
     $key = [__METHOD__, $assigned, $root];
     if ($refresh || $callback !== null || $cache === null || ($result = $cache->get($key)) === false) {
         $result = static::normalizeMenu($assigned, $menus, $callback, $root);
         if ($cache !== null && $callback === null) {
             $cache->set($key, $result, $config->cacheDuration, new TagDependency(['tags' => Configs::CACHE_TAG]));
         }
     }
     return $result;
 }
コード例 #7
0
ファイル: User.php プロジェクト: thinkwill/yii2-admin
 /**
  * @inheritdoc
  */
 public static function tableName()
 {
     return Configs::instance()->userTable;
 }
コード例 #8
0
ファイル: Module.php プロジェクト: thinkwill/yii2-admin
 /**
  * Get avalible menu.
  * @return array
  */
 public function getMenus()
 {
     if ($this->_normalizeMenus === null) {
         $mid = '/' . $this->getUniqueId() . '/';
         // resolve core menus
         $this->_normalizeMenus = [];
         $config = components\Configs::instance();
         $conditions = ['user' => $config->db && $config->db->schema->getTableSchema($config->userTable), 'assignment' => ($userClass = Yii::$app->getUser()->identityClass) && is_subclass_of($userClass, 'yii\\db\\BaseActiveRecord'), 'menu' => $config->db && $config->db->schema->getTableSchema($config->menuTable)];
         foreach ($this->_coreItems as $id => $lable) {
             if (!isset($conditions[$id]) || $conditions[$id]) {
                 $this->_normalizeMenus[$id] = ['label' => Yii::t('rbac-admin', $lable), 'url' => [$mid . $id]];
             }
         }
         foreach (array_keys($this->controllerMap) as $id) {
             $this->_normalizeMenus[$id] = ['label' => Yii::t('rbac-admin', Inflector::humanize($id)), 'url' => [$mid . $id]];
         }
         // user configure menus
         foreach ($this->_menus as $id => $value) {
             if (empty($value)) {
                 unset($this->_normalizeMenus[$id]);
                 continue;
             }
             if (is_string($value)) {
                 $value = ['label' => $value];
             }
             $this->_normalizeMenus[$id] = isset($this->_normalizeMenus[$id]) ? array_merge($this->_normalizeMenus[$id], $value) : $value;
             if (!isset($this->_normalizeMenus[$id]['url'])) {
                 $this->_normalizeMenus[$id]['url'] = [$mid . $id];
             }
         }
     }
     return $this->_normalizeMenus;
 }