1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Domains\Users; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Facades\Log; |
6
|
|
|
use Illuminate\Support\Facades\Auth; |
7
|
|
|
|
8
|
|
|
use Carbon\Carbon; |
9
|
|
|
|
10
|
|
|
use App\FileLinks; |
11
|
|
|
use App\TechTipFavs; |
12
|
|
|
use App\CustomerFavs; |
13
|
|
|
|
14
|
|
|
class GetUserStats |
15
|
|
|
{ |
16
|
|
|
protected $userID; |
17
|
|
|
|
18
|
16 |
|
public function __construct($userID = null) |
19
|
|
|
{ |
20
|
16 |
|
$userID ? $this->userID = $userID : $this->userID = Auth::user()->user_id; |
21
|
16 |
|
} |
22
|
|
|
|
23
|
2 |
|
public function getUserCustomerFavs() |
24
|
|
|
{ |
25
|
2 |
|
$custFavs = CustomerFavs::where('user_id', $this->userID) |
26
|
|
|
->with(array('Customers' => function($query){ |
27
|
2 |
|
$query->select('cust_id', 'name'); |
28
|
2 |
|
})) |
29
|
2 |
|
->get(); |
30
|
|
|
|
31
|
2 |
|
Log::debug('Retrieved Customer favorites for User ID'.$this->userID.'. Data - ', array($custFavs)); |
32
|
2 |
|
return $custFavs; |
33
|
|
|
} |
34
|
|
|
|
35
|
6 |
|
public function checkForCustomerFav($custID) |
36
|
|
|
{ |
37
|
6 |
|
$isFav = CustomerFavs::where('user_id', $this->userID)->where('cust_id', $custID)->first(); |
38
|
|
|
|
39
|
6 |
|
return $isFav ? true : false; |
40
|
|
|
} |
41
|
|
|
|
42
|
2 |
|
public function getUserTechTipFavs() |
43
|
|
|
{ |
44
|
2 |
|
$tipFavs = TechTipFavs::where('user_id', $this->userID) |
45
|
|
|
->with(array('TechTips' => function($query){ |
46
|
2 |
|
$query->select('tip_id', 'subject'); |
47
|
2 |
|
})) |
48
|
2 |
|
->get(); |
49
|
|
|
|
50
|
2 |
|
Log::debug('Retrieved Tech Tip favorites for User ID'.$this->userID.'. Data - ', array($tipFavs)); |
51
|
2 |
|
return $tipFavs; |
52
|
|
|
} |
53
|
|
|
|
54
|
2 |
|
public function checkForTechTipFav($tipID) |
55
|
|
|
{ |
56
|
2 |
|
$isFav = TechTipFavs::where('user_id', $this->userID)->where('tip_id', $tipID)->first(); |
57
|
|
|
|
58
|
2 |
|
return $isFav ? true : false; |
59
|
|
|
} |
60
|
|
|
|
61
|
2 |
|
public function getUserActiveFileLinks() |
62
|
|
|
{ |
63
|
2 |
|
$activeLinks = FileLinks::where('user_id', $this->userID)->where('expire', '>', Carbon::now())->count(); |
64
|
|
|
|
65
|
2 |
|
Log::debug('Retrieved count of active File Links for User ID'.$this->userID.'. Data - './** @scrutinizer ignore-type */$activeLinks.' found'); |
66
|
2 |
|
return $activeLinks; |
67
|
|
|
} |
68
|
|
|
|
69
|
2 |
|
public function getUserTotalLinks() |
70
|
|
|
{ |
71
|
2 |
|
$totalLinks = FileLinks::where('user_id', $this->userID)->count(); |
72
|
|
|
|
73
|
2 |
|
Log::debug('Retrieved count of total File Links for User ID'.$this->userID.'. Data - './** @scrutinizer ignore-type */$totalLinks.' found'); |
74
|
2 |
|
return $totalLinks; |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|