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