1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Domains\Users; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Facades\Auth; |
6
|
|
|
use Illuminate\Support\Facades\Log; |
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
|
4 |
|
public function __construct($userID = null) |
19
|
|
|
{ |
20
|
4 |
|
$userID ? $this->userID = $userID : $this->userID = Auth::user()->user_id; |
21
|
4 |
|
} |
22
|
|
|
|
23
|
2 |
|
public function getUserCustomerFavs() |
24
|
|
|
{ |
25
|
2 |
|
$custFavs = CustomerFavs::where('user_id', $this->userID) |
26
|
|
|
->with(array('Customers' => function($query){ |
27
|
|
|
$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
|
2 |
|
public function checkForCustomerFav($custID) |
36
|
|
|
{ |
37
|
2 |
|
$isFav = CustomerFavs::where('user_id', $this->userID)->where('cust_id', $custID)->first(); |
38
|
|
|
|
39
|
2 |
|
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
|
|
|
$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 getUserActiveFileLinks() |
55
|
|
|
{ |
56
|
2 |
|
$activeLinks = FileLinks::where('user_id', $this->userID)->where('expire', '>', Carbon::now())->count(); |
57
|
|
|
|
58
|
2 |
|
Log::debug('Retrieved count of active File Links for User ID'.$this->userID.'. Data - '.$activeLinks.' found'); |
|
|
|
|
59
|
2 |
|
return $activeLinks; |
60
|
|
|
} |
61
|
|
|
|
62
|
2 |
|
public function getUserTotalLinks() |
63
|
|
|
{ |
64
|
2 |
|
$totalLinks = FileLinks::where('user_id', $this->userID)->count(); |
65
|
|
|
|
66
|
2 |
|
Log::debug('Retrieved count of total File Links for User ID'.$this->userID.'. Data - '.$totalLinks.' found'); |
|
|
|
|
67
|
2 |
|
return $totalLinks; |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|