Inheritance: extends Flarum\Database\AbstractModel, use trait Flarum\Core\Support\EventGeneratorTrait, use trait Flarum\Core\Support\ScopeVisibilityTrait
Exemple #1
0
 /**
  * Get the guest's group, containing only the 'guests' group model.
  *
  * @return \Flarum\Core\Models\Group
  */
 public function getGroupsAttribute()
 {
     if (!isset($this->attributes['groups'])) {
         $this->attributes['groups'] = $this->relations['groups'] = Group::where('id', Group::GUEST_ID)->get();
     }
     return $this->attributes['groups'];
 }
Exemple #2
0
 /**
  * @param CreateGroup $command
  * @return Group
  * @throws PermissionDeniedException
  */
 public function handle(CreateGroup $command)
 {
     $actor = $command->actor;
     $data = $command->data;
     $this->assertCan($actor, 'createGroup');
     $group = Group::build(array_get($data, 'attributes.nameSingular'), array_get($data, 'attributes.namePlural'), array_get($data, 'attributes.color'), array_get($data, 'attributes.icon'));
     $this->events->fire(new GroupWillBeSaved($group, $actor, $data));
     $this->validator->assertValid($group->getAttributes());
     $group->save();
     $this->dispatchEventsFor($group, $actor);
     return $group;
 }
Exemple #3
0
 protected function seedGroups()
 {
     Group::unguard();
     $groups = [[Group::ADMINISTRATOR_ID, 'Admin', 'Admins', '#B72A2A', 'wrench'], [Group::GUEST_ID, 'Guest', 'Guests', null, null], [Group::MEMBER_ID, 'Member', 'Members', null, null], [static::MOD_GROUP_ID, 'Mod', 'Mods', '#80349E', 'bolt']];
     foreach ($groups as $group) {
         Group::create(['id' => $group[0], 'name_singular' => $group[1], 'name_plural' => $group[2], 'color' => $group[3], 'icon' => $group[4]]);
     }
 }
Exemple #4
0
 /**
  * {@inheritdoc}
  */
 protected function data(ServerRequestInterface $request, Document $document)
 {
     return ['groups' => Group::whereVisibleTo($request->getAttribute('actor'))->get()];
 }
Exemple #5
0
 /**
  * {@inheritdoc}
  */
 protected function data(ServerRequestInterface $request, Document $document)
 {
     return Group::all();
 }
Exemple #6
0
 protected function seedGroups()
 {
     Group::unguard();
     $groups = [['Admin', 'Admins', '#B72A2A', 'wrench'], ['Guest', 'Guests', null, null], ['Member', 'Members', null, null], ['Mod', 'Mods', '#80349E', 'bolt']];
     foreach ($groups as $group) {
         Group::create(['name_singular' => $group[0], 'name_plural' => $group[1], 'color' => $group[2], 'icon' => $group[3]]);
     }
 }
Exemple #7
0
 /**
  * Find a user by ID, optionally making sure it is visible to a certain
  * user, or throw an exception.
  *
  * @param int $id
  * @param User $actor
  * @return Group
  *
  * @throws \Illuminate\Database\Eloquent\ModelNotFoundException
  */
 public function findOrFail($id, User $actor = null)
 {
     $query = Group::where('id', $id);
     return $this->scopeVisibleTo($query, $actor)->firstOrFail();
 }