103 lines
2.2 KiB
PHP
103 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App;
|
|
|
|
use App\Category;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
use Illuminate\Notifications\Notifiable;
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
|
use App\Notifications\MyOwnResetPassword as ResetPasswordNotification;
|
|
|
|
class User extends Authenticatable
|
|
{
|
|
use Notifiable, SoftDeletes;
|
|
|
|
protected $dates = ['deleted_at'];
|
|
|
|
/**
|
|
* Send the password reset notification.
|
|
*
|
|
* @param string $token
|
|
* @return void
|
|
*/
|
|
public function sendPasswordResetNotification($token)
|
|
{
|
|
$this->notify(new ResetPasswordNotification($token));
|
|
}
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $fillable = [
|
|
'title', 'firstname', 'lastname', 'street', 'location', 'phone', 'email', 'password', 'admin', 'resetPw', 'resetPwNumber'
|
|
];
|
|
|
|
/**
|
|
* The attributes that should be hidden for arrays.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $hidden = [
|
|
'password', 'remember_token',
|
|
];
|
|
|
|
public function culturecard_user(){
|
|
return $this->hasMany('App\CulturecardUser');
|
|
}
|
|
|
|
public function usercategory(){
|
|
return $this->belongsToMany('App\Usercategory');
|
|
}
|
|
|
|
public function isAdmin()
|
|
{
|
|
return $this->admin; // this looks for an admin column in your users table
|
|
}
|
|
|
|
public function singleSeatsUser(){
|
|
return $this->hasMany('App\SingleSeatsUser');
|
|
}
|
|
|
|
public function orders(){
|
|
return $this->hasMany('App\Order');
|
|
}
|
|
|
|
public function getAmountOrderedTickets(){
|
|
return $this->singleSeatsUser()->count();
|
|
}
|
|
|
|
|
|
public function getCategoryStat(){
|
|
$ssus = $this->singleSeatsUser()->get();
|
|
$userCats = [];
|
|
|
|
foreach(Category::all() as $cat){
|
|
$userCats[$cat->name] = 0;
|
|
}
|
|
|
|
|
|
foreach($ssus as $ssu){
|
|
$categories = $ssu->singleSeat()->first()->seat()->first()->event()->first()->categories()->get();
|
|
foreach($categories as $category){
|
|
$userCats[$category->name] = $userCats[$category->name] + 1/count($categories);
|
|
}
|
|
}
|
|
|
|
//normalize
|
|
$sum = 0;
|
|
foreach($userCats as $userCat){
|
|
$sum = $sum + $userCat;
|
|
}
|
|
if($sum > 0){
|
|
foreach($userCats as $key => $val){
|
|
$userCats[$key] = $val/$sum;
|
|
}
|
|
}
|
|
|
|
return ($userCats);
|
|
}
|
|
|
|
}
|