Implement the other functionality for awards #154
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Interfaces;
|
||||
|
||||
use App\Models\Award;
|
||||
use App\Models\User;
|
||||
use App\Models\UserAward;
|
||||
|
||||
@@ -22,42 +23,50 @@ class AwardInterface
|
||||
protected $award;
|
||||
|
||||
/**
|
||||
* AwardInterface constructor.
|
||||
* @param $award
|
||||
* @var User
|
||||
*/
|
||||
public function __construct($award)
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
* AwardInterface constructor.
|
||||
* @param Award $award
|
||||
* @param User $user
|
||||
*/
|
||||
public function __construct(Award $award, User $user)
|
||||
{
|
||||
$this->award = $award;
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the award to this user, if they don't already have it
|
||||
* @param User $user
|
||||
* @return bool
|
||||
* @return bool|UserAward
|
||||
*/
|
||||
public function addAward(User $user)
|
||||
public function addAward()
|
||||
{
|
||||
$w = [
|
||||
'user_id' => $user->id,
|
||||
'user_id' => $this->user->id,
|
||||
'award_id' => $this->award->id
|
||||
];
|
||||
|
||||
$found = UserAward::where($w)->count('id');
|
||||
if($found > 0) {
|
||||
if ($found > 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Associate this award to the user now
|
||||
$award = new UserAward($w);
|
||||
$award->save();
|
||||
|
||||
return $award;
|
||||
}
|
||||
|
||||
/**
|
||||
* Each award class just needs to award
|
||||
* @param User $user
|
||||
* @return mixed
|
||||
* Each award class just needs to return true or false
|
||||
* if it should actually be awarded to a user
|
||||
* @return boolean
|
||||
*/
|
||||
public function check(User $user)
|
||||
public function check()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user