1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Circles - Bring cloud-users closer together. |
8
|
|
|
* |
9
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
10
|
|
|
* later. See the COPYING file. |
11
|
|
|
* |
12
|
|
|
* @author Maxence Lange <[email protected]> |
13
|
|
|
* @copyright 2021 |
14
|
|
|
* @license GNU AGPL version 3 or any later version |
15
|
|
|
* |
16
|
|
|
* This program is free software: you can redistribute it and/or modify |
17
|
|
|
* it under the terms of the GNU Affero General Public License as |
18
|
|
|
* published by the Free Software Foundation, either version 3 of the |
19
|
|
|
* License, or (at your option) any later version. |
20
|
|
|
* |
21
|
|
|
* This program is distributed in the hope that it will be useful, |
22
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
23
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
24
|
|
|
* GNU Affero General Public License for more details. |
25
|
|
|
* |
26
|
|
|
* You should have received a copy of the GNU Affero General Public License |
27
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
28
|
|
|
* |
29
|
|
|
*/ |
30
|
|
|
|
31
|
|
|
|
32
|
|
|
namespace OCA\Circles\Listeners\Examples; |
33
|
|
|
|
34
|
|
|
|
35
|
|
|
use daita\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Logger; |
36
|
|
|
use OCA\Circles\AppInfo\Application; |
37
|
|
|
use OCA\Circles\Events\CircleGenericEvent; |
38
|
|
|
use OCA\Circles\Events\RequestingCircleMemberEvent; |
39
|
|
|
use OCA\Circles\Model\Member; |
40
|
|
|
use OCA\Circles\Service\ConfigService; |
41
|
|
|
use OCP\EventDispatcher\Event; |
42
|
|
|
use OCP\EventDispatcher\IEventListener; |
43
|
|
|
|
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Class ExampleRequestingCircleMember |
47
|
|
|
* |
48
|
|
|
* @package OCA\Circles\Listeners\Examples |
49
|
|
|
*/ |
50
|
|
|
class ExampleRequestingCircleMember implements IEventListener { |
51
|
|
|
|
52
|
|
|
|
53
|
|
|
use TNC22Logger; |
54
|
|
|
|
55
|
|
|
|
56
|
|
|
/** @var ConfigService */ |
57
|
|
|
private $configService; |
58
|
|
|
|
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* ExampleRequestingCircleMember constructor. |
62
|
|
|
* |
63
|
|
|
* @param ConfigService $configService |
64
|
|
|
*/ |
65
|
|
|
public function __construct(ConfigService $configService) { |
66
|
|
|
$this->configService = $configService; |
67
|
|
|
|
68
|
|
|
$this->setup('app', Application::APP_ID); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @param Event $event |
74
|
|
|
*/ |
75
|
|
|
public function handle(Event $event): void { |
76
|
|
|
if (!$event instanceof RequestingCircleMemberEvent) { |
77
|
|
|
return; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
if ($this->configService->getAppValue(ConfigService::EVENT_EXAMPLES) !== '1') { |
81
|
|
|
return; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
$prefix = '[Example Event] (ExampleRequestingCircleMember) '; |
85
|
|
|
|
86
|
|
|
if ($event->getType() === CircleGenericEvent::INVITED) { |
87
|
|
|
$info = 'A new member have been invited to a Circle. '; |
88
|
|
|
} else { |
89
|
|
|
$info = 'A new member is requesting to join a Circle. '; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
$circle = $event->getCircle(); |
93
|
|
|
$member = $event->getMember(); |
94
|
|
|
$info .= 'circleId: ' . $circle->getSingleId() . '; userId: ' . $member->getUserId() . '; userType: ' |
95
|
|
|
. Member::$TYPE[$member->getUserType()] . '; singleId: ' . $member->getSingleId() |
96
|
|
|
. '; memberId: ' . $member->getId() . '; isLocal: ' . json_encode($member->isLocal()) . '; '; |
97
|
|
|
|
98
|
|
|
$this->log(3, $prefix . $info); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
|