getPermission('mod.chat.canBroadcast'); } /** * @inheritDoc */ public function validate($parameters, Room $room, UserProfile $user = null) { if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); if (!$user->getPermission('mod.chat.canBroadcast')) throw new PermissionDeniedException(); $this->setText($this->assertParameter($parameters, 'text')); $this->validateText(); } /** * @inheritDoc */ public function execute($parameters, Room $room, UserProfile $user = null) { if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); $objectTypeID = $this->getMessageObjectTypeID('be.bastelstu.chat.messageType.broadcast'); $this->setText($this->assertParameter($parameters, 'text')); WCF::getDB()->beginTransaction(); $message = (new MessageAction([ ], 'create', [ 'data' => [ 'roomID' => $room->roomID , 'userID' => $user->userID , 'username' => $user->username , 'time' => TIME_NOW , 'objectTypeID' => $objectTypeID , 'payload' => serialize([ 'message' => $this->processor->getHtml() ]) ] , 'updateTimestamp' => true ] ) )->executeAction()['returnValues']; $this->processor->setObjectID($message->messageID); if (\wcf\system\message\embedded\object\MessageEmbeddedObjectManager::getInstance()->registerObjects($this->processor)) { (new MessageEditor($message))->update([ 'hasEmbeddedObjects' => 1 ]); } WCF::getDB()->commitTransaction(); } }