1: <?php
2: /**
3: * This code is licensed under AGPLv3 license or Afterlogic Software License
4: * if commercial version of the product was purchased.
5: * For full statements of the licenses see LICENSE-AFTERLOGIC and LICENSE-AGPL3 files.
6: */
7:
8: namespace Aurora\Modules\ActivityHistory;
9:
10: use Aurora\Modules\ActivityHistory\Models\ActivityHistory;
11:
12: /**
13: * @license https://www.gnu.org/licenses/agpl-3.0.html AGPL-3.0
14: * @license https://afterlogic.com/products/common-licensing Afterlogic Software License
15: * @copyright Copyright (c) 2019, Afterlogic Corp.
16: */
17: class Manager extends \Aurora\System\Managers\AbstractManager
18: {
19: public function __construct(\Aurora\System\Module\AbstractModule $oModule = null)
20: {
21: parent::__construct($oModule);
22: }
23:
24: /**
25: * @param string $sHashID
26: * @param array $aParams
27: *
28: * @return string|bool
29: */
30: public function Create($UserId, $ResourceType, $ResourceId, $IpAddress, $Action, $Time, $GuestPublicId)
31: {
32: return ActivityHistory::create([
33: 'UserId' => $UserId,
34: 'ResourceType' => $ResourceType,
35: 'ResourceId' => $ResourceId,
36: 'IpAddress' => $IpAddress,
37: 'Action' => $Action,
38: 'Timestamp' => $Time,
39: 'GuestPublicId' => $GuestPublicId
40: ]);
41: }
42:
43: /**
44: * @param string $sHashID
45: *
46: * @return array|bool
47: */
48: public function GetListByUserId($UserId)
49: {
50: return ActivityHistory::where('UserId',$UserId)->get();
51: }
52:
53: public function DeleteActivityHistory($iId)
54: {
55: $bResult = false;
56:
57: try
58: {
59: $bResult = !!ActivityHistory::find($iId)->delete();
60: }
61: catch (\Aurora\System\Exceptions\BaseException $oException)
62: {
63: $this->setLastException($oException);
64: }
65:
66: return $bResult;
67: }
68:
69: /**
70: * @param string $sHashID
71: *
72: * @return array|bool
73: */
74: public function GetList($UserId, $ResourceType, $ResourceId, $Offset, $Limit)
75: {
76: $oQuery = ActivityHistory::where([
77: ['UserId', '=', $UserId],
78: ['ResourceType', '=', $ResourceType],
79: ['ResourceId', '=', $ResourceId],
80: ]);
81: if ($Offset > 0) {
82: $oQuery = $oQuery->offset($Offset);
83: }
84: if ($Limit > 0) {
85: $oQuery = $oQuery->limit($Limit);
86: }
87: return $oQuery->get();
88: }
89:
90: /**
91: * @param string $sHashID
92: *
93: * @return array|bool
94: */
95: public function GetListCount($UserId, $ResourceType, $ResourceId)
96: {
97: return ActivityHistory::where([
98: ['UserId', '=', $UserId],
99: ['ResourceType', '=', $ResourceType],
100: ['ResourceId', '=', $ResourceId],
101: ])->count();
102: }
103:
104: public function Delete($UserId, $ResourceType, $ResourceId)
105: {
106: return ActivityHistory::where([
107: ['UserId', '=', $UserId],
108: ['ResourceType', '=', $ResourceType],
109: ['ResourceId', '=', $ResourceId],
110: ])->delete();
111: }
112: }
113: