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) 2023, Afterlogic Corp.
16: *
17: * @property Module $oModule
18: */
19: class Manager extends \Aurora\System\Managers\AbstractManager
20: {
21: public function __construct(\Aurora\System\Module\AbstractModule $oModule = null)
22: {
23: parent::__construct($oModule);
24: }
25:
26: /**
27: * @param int $UserId
28: * @param string $ResourceType
29: * @param string $ResourceId
30: * @param string $IpAddress
31: * @param string $Action
32: * @param int $Time
33: * @param string $GuestPublicId
34: * @return string|bool
35: */
36: public function Create($UserId, $ResourceType, $ResourceId, $IpAddress, $Action, $Time, $GuestPublicId)
37: {
38: return ActivityHistory::create([
39: 'UserId' => $UserId,
40: 'ResourceType' => $ResourceType,
41: 'ResourceId' => $ResourceId,
42: 'IpAddress' => $IpAddress,
43: 'Action' => $Action,
44: 'Timestamp' => $Time,
45: 'GuestPublicId' => $GuestPublicId
46: ]);
47: }
48:
49: /**
50: * @param int $UserId
51: *
52: * @return array|bool
53: */
54: public function GetListByUserId($UserId)
55: {
56: return ActivityHistory::where('UserId', $UserId)->get();
57: }
58:
59: public function DeleteActivityHistory($iId)
60: {
61: $bResult = false;
62:
63: try {
64: $bResult = !!ActivityHistory::find($iId)->delete();
65: } catch (\Aurora\System\Exceptions\BaseException $oException) {
66: $this->setLastException($oException);
67: }
68:
69: return $bResult;
70: }
71:
72: /**
73: * @param int $UserId
74: * @param string $ResourceType
75: * @param string $ResourceId
76: * @param int $Offset
77: * @param int $Limit
78: *
79: * @return array|bool
80: */
81: public function GetList($UserId, $ResourceType, $ResourceId, $Offset, $Limit)
82: {
83: $oQuery = ActivityHistory::where([
84: ['UserId', '=', $UserId],
85: ['ResourceType', '=', $ResourceType],
86: ['ResourceId', '=', $ResourceId],
87: ]);
88: if ($Offset > 0) {
89: $oQuery = $oQuery->offset($Offset);
90: }
91: if ($Limit > 0) {
92: $oQuery = $oQuery->limit($Limit);
93: }
94: return $oQuery->get();
95: }
96:
97: /**
98: * @param int $UserId
99: * @param string $ResourceType
100: * @param string $ResourceId
101: *
102: * @return array|bool
103: */
104: public function GetListCount($UserId, $ResourceType, $ResourceId)
105: {
106: return ActivityHistory::where([
107: ['UserId', '=', $UserId],
108: ['ResourceType', '=', $ResourceType],
109: ['ResourceId', '=', $ResourceId],
110: ])->count();
111: }
112:
113: public function Delete($UserId, $ResourceType, $ResourceId)
114: {
115: return ActivityHistory::where([
116: ['UserId', '=', $UserId],
117: ['ResourceType', '=', $ResourceType],
118: ['ResourceId', '=', $ResourceId],
119: ])->delete();
120: }
121: }
122: