Apply PSR-12 code style (#145)
[GitHub/WoltLab/com.woltlab.wcf.conversation.git] / files / lib / system / event / listener / UserGroupAddCanBeAddedAsConversationParticipantListener.class.php
1 <?php
2
3 namespace wcf\system\event\listener;
4
5 use wcf\acp\form\UserGroupAddForm;
6 use wcf\acp\form\UserGroupEditForm;
7 use wcf\data\user\group\UserGroup;
8 use wcf\system\WCF;
9
10 /**
11 * Handles 'canBeAddedAsConversationParticipant' setting.
12 *
13 * @author Marcel Werk
14 * @copyright 2001-2019 WoltLab GmbH
15 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
16 * @package WoltLabSuite\Core\System\Event\Listener
17 */
18 class UserGroupAddCanBeAddedAsConversationParticipantListener implements IParameterizedEventListener
19 {
20 /**
21 * instance of UserGroupAddForm
22 * @var UserGroupAddForm|UserGroupEditForm
23 */
24 protected $eventObj;
25
26 /**
27 * true if group can be added as participant
28 * @var boolean
29 */
30 protected $canBeAddedAsConversationParticipant = 0;
31
32 /**
33 * @inheritDoc
34 */
35 public function execute($eventObj, $className, $eventName, array &$parameters)
36 {
37 $this->eventObj = $eventObj;
38
39 if ($this->eventObj instanceof UserGroupEditForm && \is_object($this->eventObj->group)) {
40 switch ($this->eventObj->group->groupType) {
41 case UserGroup::EVERYONE:
42 case UserGroup::GUESTS:
43 case UserGroup::USERS:
44 return;
45 }
46 }
47
48 $this->{$eventName}();
49 }
50
51 /**
52 * Handles the assignVariables event.
53 */
54 protected function assignVariables()
55 {
56 WCF::getTPL()->assign([
57 'canBeAddedAsConversationParticipant' => $this->canBeAddedAsConversationParticipant,
58 ]);
59 }
60
61 /**
62 * Handles the readData event.
63 * This is only called in UserGroupEditForm.
64 */
65 protected function readData()
66 {
67 if (empty($_POST)) {
68 $this->canBeAddedAsConversationParticipant = $this->eventObj->group->canBeAddedAsConversationParticipant;
69 }
70 }
71
72 /**
73 * Handles the readFormParameters event.
74 */
75 protected function readFormParameters()
76 {
77 if (isset($_POST['canBeAddedAsConversationParticipant'])) {
78 $this->canBeAddedAsConversationParticipant = \intval($_POST['canBeAddedAsConversationParticipant']);
79 }
80 }
81
82 /**
83 * Handles the save event.
84 */
85 protected function save()
86 {
87 $this->eventObj->additionalFields = \array_merge($this->eventObj->additionalFields, [
88 'canBeAddedAsConversationParticipant' => $this->canBeAddedAsConversationParticipant,
89 ]);
90 }
91 }