3 use wcf\data\conversation\Conversation
;
4 use wcf\data\conversation\ConversationAction
;
5 use wcf\data\user\UserProfile
;
6 use wcf\system\breadcrumb\Breadcrumb
;
7 use wcf\system\conversation\ConversationHandler
;
8 use wcf\system\exception\IllegalLinkException
;
9 use wcf\system\exception\NamedUserException
;
10 use wcf\system\exception\UserInputException
;
11 use wcf\system\request\LinkHandler
;
13 use wcf\util\HeaderUtil
;
14 use wcf\util\StringUtil
;
17 * Shows the conversation form.
20 * @copyright 2009-2012 WoltLab GmbH
21 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
22 * @package com.woltlab.wcf.conversation
24 * @category Community Framework
26 class ConversationAddForm
extends MessageForm
{
28 * @see wcf\page\AbstractPage::$enableTracking
30 public $enableTracking = true;
33 * @see wcf\form\MessageForm::$attachmentObjectType
35 public $attachmentObjectType = 'com.woltlab.wcf.conversation.message';
38 * @see wcf\page\AbstractPage::$loginRequired
40 public $loginRequired = true;
43 * @see wcf\page\AbstractPage::$neededModules
45 public $neededModules = array('MODULE_CONVERSATION');
48 * @see wcf\page\AbstractPage::$neededPermissions
50 public $neededPermissions = array('user.conversation.canUseConversation');
53 * participants (comma separated user names)
56 public $participants = '';
59 * invisible participants (comma separated user names)
62 public $invisibleParticipants = '';
71 * true, if participants can add new participants
74 public $participantCanInvite = 0;
77 * participants (user ids)
80 public $participantIDs = array();
83 * invisible participants (user ids)
86 public $invisibleParticipantIDs = array();
89 * @see wcf\page\IPage::readParameters()
91 public function readParameters() {
92 parent
::readParameters();
94 // check max pc permission
95 if (ConversationHandler
::getInstance()->getConversationCount() >= WCF
::getSession()->getPermission('user.conversation.maxConversations')) {
96 throw new NamedUserException(WCF
::getLanguage()->get('wcf.conversation.error.mailboxIsFull'));
99 if (isset($_REQUEST['userID'])) {
100 $userID = intval($_REQUEST['userID']);
101 $user = UserProfile
::getUserProfile($userID);
102 if ($user === null ||
$user->userID
== WCF
::getUser()->userID
) {
103 throw new IllegalLinkException();
108 Conversation
::validateParticipant($user);
110 catch (UserInputException
$e) {
111 throw new NamedUserException(WCF
::getLanguage()->getDynamicVariable('wcf.conversation.participants.error.'.$e->getType(), array('errorData' => array('username' => $user->username
))));
114 $this->participants
= $user->username
;
119 * @see wcf\form\IForm::readFormParameters()
121 public function readFormParameters() {
122 parent
::readFormParameters();
124 if (isset($_POST['draft'])) $this->draft
= (bool) $_POST['draft'];
125 if (isset($_POST['participantCanInvite'])) $this->participantCanInvite
= (bool) $_POST['participantCanInvite'];
126 if (isset($_POST['participants'])) $this->participants
= StringUtil
::trim($_POST['participants']);
127 if (isset($_POST['invisibleParticipants'])) $this->invisibleParticipants
= StringUtil
::trim($_POST['invisibleParticipants']);
131 * @see wcf\form\IForm::validate()
133 public function validate() {
134 if (empty($this->participants
) && empty($this->invisibleParticipants
) && !$this->draft
) {
135 throw new UserInputException('participants');
138 $this->participantIDs
= Conversation
::validateParticipants($this->participants
);
139 $this->invisibleParticipantIDs
= Conversation
::validateParticipants($this->invisibleParticipants
, 'invisibleParticipants');
142 $intersection = array_intersect($this->participantIDs
, $this->invisibleParticipantIDs
);
143 if (!empty($intersection)) $this->invisibleParticipantIDs
= array_diff($this->invisibleParticipantIDs
, $intersection);
145 if (empty($this->participantIDs
) && empty($this->invisibleParticipantIDs
) && !$this->draft
) {
146 throw new UserInputException('participants');
149 // check number of participants
150 if (count($this->participantIDs
) +
count($this->invisibleParticipantIDs
) > WCF
::getSession()->getPermission('user.conversation.maxParticipants')) {
151 throw new UserInputException('participants', 'tooManyParticipants');
158 * @see wcf\form\IForm::save()
160 public function save() {
165 'subject' => $this->subject
,
167 'userID' => WCF
::getUser()->userID
,
168 'username' => WCF
::getUser()->username
,
169 'isDraft' => ($this->draft ?
1 : 0),
170 'participantCanInvite' => $this->participantCanInvite
173 $data['draftData'] = serialize(array(
174 'participants' => $this->participantIDs
,
175 'invisibleParticipants' => $this->invisibleParticipantIDs
179 $conversationData = array(
181 'attachmentHandler' => $this->attachmentHandler
,
182 'messageData' => array(
183 'message' => $this->text
187 $conversationData['participants'] = $this->participantIDs
;
188 $conversationData['invisibleParticipants'] = $this->invisibleParticipantIDs
;
191 $this->objectAction
= new ConversationAction(array(), 'create', $conversationData);
192 $resultValues = $this->objectAction
->executeAction();
196 HeaderUtil
::redirect(LinkHandler
::getInstance()->getLink('Conversation', array(
197 'object' => $resultValues['returnValues']
203 * @see wcf\page\IPage::readData()
205 public function readData() {
209 WCF
::getBreadcrumbs()->add(new Breadcrumb(WCF
::getLanguage()->get('wcf.conversation.conversations'), LinkHandler
::getInstance()->getLink('ConversationList')));
213 * @see wcf\page\IPage::assignVariables()
215 public function assignVariables() {
216 parent
::assignVariables();
218 WCF
::getTPL()->assign(array(
219 'participantCanInvite' => $this->participantCanInvite
,
220 'participants' => $this->participants
,
221 'invisibleParticipants' => $this->invisibleParticipants