*
* @param string $participants
* @param string $field
+ * @param array<integer> $existingParticipants
* @return array $result
*/
- public static function validateParticipants($participants, $field = 'participants') {
+ public static function validateParticipants($participants, $field = 'participants', array $existingParticipants = array()) {
$result = array();
$error = array();
if ($user->userID == WCF::getUser()->userID) {
throw new UserInputException($field, 'isAuthor');
}
- else if (in_array($user->userID, $result)) {
+ else if (in_array($user->userID, $existingParticipants)) {
throw new UserInputException($field, 'duplicate');
}
self::validateParticipant($user, $field);
// no error
- $result[] = $user->userID;
+ $existingParticipants[] = $result[] = $user->userID;
}
catch (UserInputException $e) {
$error[] = array('type' => $e->getType(), 'username' => $participant);
UserStorageHandler::getInstance()->reset(array(WCF::getUser()->userID), 'unreadConversationCount');
}
-
// add modification log entry
if ($this->parameters['hideConversation'] == Conversation::STATE_LEFT) {
if (empty($this->objects)) $this->readObjects();
*/
public function addParticipants() {
try {
- $participantIDs = Conversation::validateParticipants($this->parameters['participants']);
+ $participantIDs = Conversation::validateParticipants($this->parameters['participants'], 'participants', $this->conversation->getParticipantIDs(true));
}
catch (UserInputException $e) {
$errorMessage = '';
foreach ($e->getType() as $type) {
if (!empty($errorMessage)) $errorMessage .= ' ';
- $errorMessage .= WCF::getLanguage()->getDynamicVariable('wcf.conversation.participants.error.'.$type['type'], array('username' => $type['username']));
+ $errorMessage .= WCF::getLanguage()->getDynamicVariable('wcf.conversation.participants.error.'.$type['type'], array('errorData' => array('username' => $type['username'])));
}
return array(
$successMessage = '';
if (!empty($participantIDs)) {
// check for already added participants
- $participantIDs = array_diff($participantIDs, $this->conversation->getParticipantIDs());
- if (!empty($participantIDs)) {
- $data = array();
- if ($this->conversation->isDraft) {
- $draftData = unserialize($this->conversation->draftData);
- $draftData['participants'] = array_merge($draftData['participants'], $participantIDs);
- $data = array('data' => array('draftData' => serialize($draftData)));
- }
- else {
- $data = array('participants' => $participantIDs);
- }
-
- $conversationAction = new ConversationAction(array($this->conversation), 'update', $data);
- $conversationAction->executeAction();
-
- $count = count($participantIDs);
- $successMessage = WCF::getLanguage()->getDynamicVariable('wcf.conversation.edit.addParticipants.success', array('count' => $count));
-
- ConversationModificationLogHandler::getInstance()->addParticipants($this->conversation->getDecoratedObject(), $participantIDs);
-
- if (!$this->conversation->isDraft) {
- // update participant summary
- $this->conversation->updateParticipantSummary();
- }
+ $data = array();
+ if ($this->conversation->isDraft) {
+ $draftData = unserialize($this->conversation->draftData);
+ $draftData['participants'] = array_merge($draftData['participants'], $participantIDs);
+ $data = array('data' => array('draftData' => serialize($draftData)));
+ }
+ else {
+ $data = array('participants' => $participantIDs);
+ }
+
+ $conversationAction = new ConversationAction(array($this->conversation), 'update', $data);
+ $conversationAction->executeAction();
+
+ $count = count($participantIDs);
+ $successMessage = WCF::getLanguage()->getDynamicVariable('wcf.conversation.edit.addParticipants.success', array('count' => $count));
+
+ ConversationModificationLogHandler::getInstance()->addParticipants($this->conversation->getDecoratedObject(), $participantIDs);
+
+ if (!$this->conversation->isDraft) {
+ // update participant summary
+ $this->conversation->updateParticipantSummary();
}
}
* @param array<integer> $invisibleParticipantIDs
*/
public function updateParticipants(array $participantIDs, array $invisibleParticipantIDs = array()) {
- $sql = "INSERT INTO wcf".WCF_N."_conversation_to_user
- (conversationID, participantID, isInvisible)
- VALUES (?, ?, ?)";
- $statement = WCF::getDB()->prepareStatement($sql);
-
- WCF::getDB()->beginTransaction();
if (!empty($participantIDs)) {
+ WCF::getDB()->beginTransaction();
+ $sql = "INSERT INTO wcf".WCF_N."_conversation_to_user
+ (conversationID, participantID, isInvisible)
+ VALUES (?, ?, ?)
+ ON DUPLICATE KEY
+ UPDATE hideConversation = 0";
+ $statement = WCF::getDB()->prepareStatement($sql);
+
foreach ($participantIDs as $userID) {
$statement->execute(array($this->conversationID, $userID, 0));
}
+ WCF::getDB()->commitTransaction();
}
if (!empty($invisibleParticipantIDs)) {
+ WCF::getDB()->beginTransaction();
+ $sql = "INSERT INTO wcf".WCF_N."_conversation_to_user
+ (conversationID, participantID, isInvisible)
+ VALUES (?, ?, ?)";
+ $statement = WCF::getDB()->prepareStatement($sql);
+
foreach ($invisibleParticipantIDs as $userID) {
$statement->execute(array($this->conversationID, $userID, 1));
}
+ WCF::getDB()->commitTransaction();
}
- WCF::getDB()->commitTransaction();
}
/**