当前位置: 首页>>代码示例>>PHP>>正文


PHP Role::getOwnerRoleForBoard方法代码示例

本文整理汇总了PHP中app\Role::getOwnerRoleForBoard方法的典型用法代码示例。如果您正苦于以下问题:PHP Role::getOwnerRoleForBoard方法的具体用法?PHP Role::getOwnerRoleForBoard怎么用?PHP Role::getOwnerRoleForBoard使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在app\Role的用法示例。


在下文中一共展示了Role::getOwnerRoleForBoard方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: setOwner

 public function setOwner(User $user)
 {
     $user->forgetPermissions();
     $role = Role::getOwnerRoleForBoard($this);
     if (!$role->wasRecentlyCreated) {
         UserRole::where('role_id', $role->role_id)->delete();
     }
     $this->operated_by = $user->user_id;
     $this->save();
     return UserRole::create(['user_id' => $user->user_id, 'role_id' => $role->role_id]);
 }
开发者ID:ZiRo-,项目名称:infinity-next,代码行数:11,代码来源:Board.php

示例2: setOwner

 public function setOwner(User $user)
 {
     $user->forgetPermissions();
     $role = Role::getOwnerRoleForBoard($this);
     return UserRole::create(['user_id' => $user->user_id, 'role_id' => $role->role_id]);
 }
开发者ID:JEWSbreaking8chan,项目名称:infinity-next,代码行数:6,代码来源:Board.php

示例3: importInfinityRolesAndBoards


//.........这里部分代码省略.........
                         // Not identified!
                         default:
                             $this->error("\t\tMod {$user->username} has invalid mod type {$mod->type}.");
                             break;
                     }
                 }
             }
         }
     });
     $this->info("\tImported {$usersImported} users(s).");
     if (!$userAdmin) {
         $this->comment("\tFailed to import an admin. This may cause problems.");
     }
     unset($mods, $mod, $user);
     # BEGIN BOARD IMPORT
     $this->info("\tImporting Boards ...");
     $boardsImported = 0;
     $tBoardsTable->chunk(100, function ($boards) use(&$boardsImported, $userAdmin, $userBoardRelationships) {
         $this->line("\t\tHandling 100 boards ...");
         foreach ($boards as $tBoard) {
             // We have an array like [board_uri => [ user_id => user_role ]] in the user import.
             // This fetches the first key of the biggest item.
             $boardOwner = [];
             if (isset($userBoardRelationships[$tBoard->uri])) {
                 $boardOwner = array_keys($userBoardRelationships[$tBoard->uri], max($userBoardRelationships[$tBoard->uri]));
             }
             // Or it defaults to our admin.
             if (!isset($boardOwner[0])) {
                 $this->comment("\t\t/{$tBoard->uri}/ has no known owner, assuming it is {$userAdmin->username}.");
                 $boardOwner = $userAdmin->user_id;
             } else {
                 $boardOwner = isset($boardOwner) ? $boardOwner[0] : $userAdmin->user_id;
             }
             $hBoard = new Board(['board_uri' => $tBoard->uri, 'title' => $tBoard->title, 'description' => $tBoard->subtitle, 'created_at' => new Carbon($tBoard->time), 'created_by' => $boardOwner, 'operated_by' => $boardOwner, 'posts_total' => $tBoard->posts_total, 'is_indexed' => !!$tBoard->indexed, 'is_overboard' => !!$tBoard->indexed, 'is_worksafe' => !!$tBoard->sfw]);
             if ($hBoard->save()) {
                 ++$boardsImported;
                 if (!$tBoard->public_bans || !$tBoard->public_logs || $tBoard->public_logs == 2) {
                     $role = Role::getAnonymousRoleForBoard($hBoard);
                     $perms = [];
                     if (!$tBoard->public_bans) {
                         $perms[] = ['permission_id' => "board.bans", 'value' => false];
                     }
                     if (!$tBoard->public_logs || $tBoard->public_logs == 2) {
                         $perms[] = ['permission_id' => "board.logs", 'value' => false];
                     }
                     $role->permissionAssignments()->createMany($perms);
                 }
             } else {
                 $this->error("Failed to save /{$hBoard->board_uri}/.");
             }
         }
     });
     $this->info("\tImported {$boardsImported} board(s).");
     unset($boards, $tBoard, $hBoard);
     # BEGIN ROLE CONFIGURATION
     $this->info("\tCreating roles ...");
     $roleBoardVols = 0;
     $roleBoardOwners = 0;
     $roleBoardSkips = 0;
     // Okay, so apparently sometimes there are users that own boards that don't exist.
     // We cannot crate roles for these boards, so lets prune useless data.
     $boardsWeCareAbout = Board::select('board_uri')->whereIn('board_uri', array_keys($userBoardRelationships))->get()->pluck('board_uri');
     if ($boardsWeCareAbout->count() != count($userBoardRelationships)) {
         $this->comment("\t\tThere are " . (count($userBoardRelationships) - $boardsWeCareAbout->count()) . " board(s) which users own that do not exist!");
     }
     foreach ($boardsWeCareAbout as $board) {
         $ownerRole = null;
         $janitorRole = null;
         $roles = $userBoardRelationships[$board];
         foreach ($roles as $mod => $role) {
             // TODO
             // Pull these values from config when formal importer created.
             switch ($role) {
                 // Board volunteer
                 case 19:
                     $janitorRole = $janitorRole ?: Role::getJanitorRoleForBoard($board);
                     $userRole = new UserRole(['user_id' => $mod, 'role_id' => $janitorRole->role_id]);
                     if ($userRole->save()) {
                         ++$roleBoardVols;
                     }
                     break;
                     // Board owner
                 // Board owner
                 case 20:
                     $ownerRole = $ownerRole ?: Role::getOwnerRoleForBoard($board);
                     $userRole = new UserRole(['user_id' => $mod, 'role_id' => $ownerRole->role_id]);
                     if ($userRole->save()) {
                         ++$roleBoardOwners;
                     }
                     break;
                 default:
                     $this->line("\t\tI don't know what to do with role {$role} for user id {$mod} in {$board}.");
                     break;
             }
         }
     }
     $this->info("\t\tCreated {$roleBoardOwners} owner(s) and {$roleBoardVols} janitor(s) ");
     $this->info("\t\tPulled roles from " . count($userBoardRelationships) . " boards with relationships.");
     unset($board, $roles, $mod, $role, $userRole, $janitorRole, $ownerRole);
 }
开发者ID:LulzNews,项目名称:infinity-next,代码行数:101,代码来源:Import.php

示例4: runBoards

 public function runBoards()
 {
     $this->command->comment("\tInserting board owner roles.");
     $boardRole = $this->slugs()[Role::ID_OWNER];
     Board::chunk(50, function ($boards) {
         foreach ($boards as $board) {
             $boardRole = $board->getOwnerRole();
             if (!$boardRole) {
                 $boardRole = Role::getOwnerRoleForBoard($board);
                 $this->command->line("\t/{$board->board_uri}/ has no owner role.");
             }
             $roleModel = Role::firstOrCreate(['role' => $boardRole['role'], 'board_uri' => $board->board_uri, 'caste' => $boardRole['caste']]);
             if ($roleModel->wasRecentlyCreated) {
                 $roleModel->fill(['name' => $boardRole['name'], 'capcode' => $boardRole['capcode'], 'inherit_id' => Role::ID_OWNER, 'system' => false, 'weight' => $boardRole['weight'] + 5])->save();
             }
         }
     });
 }
开发者ID:LulzNews,项目名称:infinity-next,代码行数:18,代码来源:RoleSeeder.php


注:本文中的app\Role::getOwnerRoleForBoard方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。