當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Group::getConstants方法代碼示例

本文整理匯總了PHP中app\models\Group::getConstants方法的典型用法代碼示例。如果您正苦於以下問題:PHP Group::getConstants方法的具體用法?PHP Group::getConstants怎麽用?PHP Group::getConstants使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在app\models\Group的用法示例。


在下文中一共展示了Group::getConstants方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: run

 public function run()
 {
     $handle = fopen($this->baseDir . 'users_groups_permissions.tsv', 'r');
     $headers = fgetcsv($handle, 1024, '	');
     $entityPermissions = array_fill_keys($headers, '');
     while (($data = fgetcsv($handle, 2048, '	')) != false) {
         reset($headers);
         foreach ($data as $val) {
             $entityPermissions[$headers[key($headers)]][] = $val;
             next($headers);
         }
     }
     fclose($handle);
     $groupList = Models\Group::getConstants();
     $permissionCategories = array();
     $permissionCategoryList = array();
     $permissionCategoryID = 1;
     $permissionEntities = array();
     $permissionEntityList = array();
     $permissionEntityID = 1;
     $permissionActions = array();
     $permissionActionList = array();
     $permissionActionID = 1;
     $permissionManagementActions = array();
     $permissionManagementActionList = array();
     $permissionManagementActionID = 1;
     $handle = fopen($this->baseDir . 'permission_entities_actions.tsv', 'r');
     fgetcsv($handle, 1024, '	');
     while (($data = fgetcsv($handle, 1024, '	')) != false) {
         if (!empty($data[3])) {
             if (!isset($permissionCategoryList[$data[3]])) {
                 $permissionCategoryList[$data[3]] = $permissionCategoryID++;
                 $permissionCategories[] = ['name' => $data[3]];
             }
         }
         $permissionEntities[] = ['name' => $data[0], 'permission_category_id' => $permissionCategoryList[$data[3]]];
         $permissionEntityList[$data[0]] = $permissionEntityID;
         $tmp = explode(';', $data[1]);
         foreach ($tmp as $item) {
             $permissionActions[] = array('name' => $item, 'permission_entity_id' => $permissionEntityID);
             $permissionActionList[$data[0]][$item] = $permissionActionID++;
         }
         $tmp = explode(';', $data[2]);
         foreach ($tmp as $item) {
             $permissionManagementActions[] = array('name' => $item, 'permission_entity_id' => $permissionEntityID);
             $permissionManagementActionList[$data[0]][$item] = $permissionManagementActionID++;
         }
         $permissionEntityID++;
     }
     fclose($handle);
     $permissionGroup = array();
     $permissionManagementGroup = array();
     $permissionManagementID = 1;
     $permissionManagement = array();
     $permissionID = 1;
     $permission = array();
     $permissionListForUserInGroup = array();
     $permissionManagementListForUserInGroup = array();
     reset($entityPermissions);
     $permissionGroupList = $entityPermissions[key($entityPermissions)];
     next($entityPermissions);
     while (list($entity, $val) = each($entityPermissions)) {
         if (strpos($entity, '_management') !== false) {
             foreach ($val as $groupKey => $actions) {
                 $tmp = explode(';', $actions);
                 foreach ($tmp as $item) {
                     if (!empty($item)) {
                         $permissionManagement[] = array('permission_management_action_id' => $permissionManagementActionList[str_replace('_management', '', $entity)][$item], 'permission_recipient_type_id' => Models\PermissionRecipientType::group);
                         $permissionManagementGroup[] = array('type_id' => $groupList[$permissionGroupList[$groupKey]], 'permission_management_id' => $permissionManagementID++);
                         $permissionManagementListForUserInGroup[$groupList[$permissionGroupList[$groupKey]]][] = array('permission_management_action_id' => $permissionManagementActionList[str_replace('_management', '', $entity)][$item], 'permission_recipient_type_id' => Models\PermissionRecipientType::user);
                     }
                 }
             }
         } else {
             foreach ($val as $groupKey => $actions) {
                 $tmp = explode(';', $actions);
                 foreach ($tmp as $item) {
                     if (!empty($item)) {
                         $permission[] = array('permission_action_id' => $permissionActionList[$entity][$item], 'permission_recipient_type_id' => Models\PermissionRecipientType::group);
                         $permissionGroup[] = array('type_id' => $groupList[$permissionGroupList[$groupKey]], 'permission_id' => $permissionID++);
                         $permissionListForUserInGroup[$groupList[$permissionGroupList[$groupKey]]][] = array('permission_action_id' => $permissionActionList[$entity][$item], 'permission_recipient_type_id' => Models\PermissionRecipientType::user);
                     }
                 }
             }
         }
     }
     $permissionUser = array();
     $permissionManagementUser = array();
     $alreadyGivenPermissions = $alreadyGivenManagementPermissions = [];
     $userGroups = Models\UserGroup::all();
     foreach ($userGroups as $userGroup) {
         if (isset($permissionListForUserInGroup[$userGroup->group_id])) {
             foreach ($permissionListForUserInGroup[$userGroup->group_id] as $p) {
                 if (!isset($alreadyGivenPermissions[$userGroup->user_id][$p['permission_action_id']])) {
                     $alreadyGivenPermissions[$userGroup->user_id][$p['permission_action_id']] = true;
                     $permission[] = $p;
                     $permissionUser[] = ['type_id' => $userGroup->user_id, 'permission_id' => $permissionID++];
                 }
             }
         }
//.........這裏部分代碼省略.........
開發者ID:linguisticteam,項目名稱:laravel-boilerplate,代碼行數:101,代碼來源:PermissionSeeder.php


注:本文中的app\models\Group::getConstants方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。