2016-03-12 14:18:28 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* UserRepository.php
|
2016-04-01 16:44:46 +02:00
|
|
|
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
2016-03-12 14:18:28 +01:00
|
|
|
*
|
2016-10-05 06:52:15 +02:00
|
|
|
* This software may be modified and distributed under the terms of the
|
|
|
|
* Creative Commons Attribution-ShareAlike 4.0 International License.
|
|
|
|
*
|
|
|
|
* See the LICENSE file for details.
|
2016-03-12 14:18:28 +01:00
|
|
|
*/
|
|
|
|
|
2016-05-20 12:41:23 +02:00
|
|
|
declare(strict_types = 1);
|
|
|
|
|
2016-03-12 14:18:28 +01:00
|
|
|
namespace FireflyIII\Repositories\User;
|
|
|
|
|
|
|
|
|
|
|
|
use FireflyIII\Models\Role;
|
|
|
|
use FireflyIII\User;
|
2016-04-03 07:07:17 +02:00
|
|
|
use Illuminate\Support\Collection;
|
2016-03-12 14:18:28 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class UserRepository
|
|
|
|
*
|
|
|
|
* @package FireflyIII\Repositories\User
|
|
|
|
*/
|
|
|
|
class UserRepository implements UserRepositoryInterface
|
|
|
|
{
|
|
|
|
|
2016-04-03 07:07:17 +02:00
|
|
|
/**
|
|
|
|
* @return Collection
|
|
|
|
*/
|
|
|
|
public function all(): Collection
|
|
|
|
{
|
|
|
|
return User::orderBy('id', 'DESC')->get(['users.*']);
|
|
|
|
}
|
|
|
|
|
2016-03-12 14:18:28 +01:00
|
|
|
/**
|
|
|
|
* @param User $user
|
|
|
|
* @param string $role
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function attachRole(User $user, string $role): bool
|
|
|
|
{
|
|
|
|
$admin = Role::where('name', 'owner')->first();
|
|
|
|
$user->attachRole($admin);
|
2016-03-28 19:50:24 +02:00
|
|
|
$user->save();
|
2016-03-12 14:18:28 +01:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function count(): int
|
|
|
|
{
|
2016-04-26 08:09:10 +02:00
|
|
|
return $this->all()->count();
|
2016-03-12 14:18:28 +01:00
|
|
|
}
|
2016-03-14 20:38:23 +01:00
|
|
|
}
|