/**
  * @see	\wcf\system\importer\IImporter::import()
  */
 public function import($oldID, array $data, array $additionalData = array())
 {
     $data['userID'] = ImportHandler::getInstance()->getNewID('com.woltlab.wcf.user', $data['userID']);
     $data['commentID'] = ImportHandler::getInstance()->getNewID($this->objectTypeName, $data['commentID']);
     if (!$data['commentID']) {
         return 0;
     }
     $response = CommentResponseEditor::create($data);
     $sql = "SELECT\t\tresponseID\n\t\t\tFROM\t\twcf" . WCF_N . "_comment_response\n\t\t\tWHERE\t\tcommentID = ?\n\t\t\tORDER BY\ttime ASC, responseID ASC";
     $statement = WCF::getDB()->prepareStatement($sql, 5);
     $statement->execute(array($response->commentID));
     $responseIDs = array();
     while ($responseID = $statement->fetchColumn()) {
         $responseIDs[] = $responseID;
     }
     // update parent comment
     $sql = "UPDATE\twcf" . WCF_N . "_comment\n\t\t\tSET\tresponseIDs = ?,\n\t\t\t\tresponses = responses + 1\n\t\t\tWHERE\tcommentID = ?";
     $statement = WCF::getDB()->prepareStatement($sql);
     $statement->execute(array(serialize($responseIDs), $response->commentID));
     return $response->responseID;
 }
 /**
  * @see	\wcf\system\faker\IFaker::fake()
  */
 public function fake()
 {
     $sql = "SELECT\t\t*\n\t\t\tFROM\t\twcf" . WCF_N . "_comment\n\t\t\tWHERE\t\tobjectTypeID = ?";
     $statement = \wcf\system\WCF::getDB()->prepareStatement($sql, 1, $this->generator->numberBetween(0, $this->commentCount - 1));
     $statement->execute(array($this->objectTypeID));
     $target = $statement->fetchObject('\\wcf\\data\\comment\\Comment');
     $sql = "SELECT\t\tuserID, username, registrationDate\n\t\t\tFROM\t\twcf" . WCF_N . "_user\n\t\t\tORDER BY\tuserID ASC";
     $statement = \wcf\system\WCF::getDB()->prepareStatement($sql, 1, $this->generator->numberBetween(0, $this->userCount - 1));
     $statement->execute();
     $sender = $statement->fetchObject('\\wcf\\data\\user\\User');
     // create response
     $response = \wcf\data\comment\response\CommentResponseEditor::create(array('commentID' => $target->commentID, 'time' => $this->generator->numberBetween(max($sender->registrationDate, $target->time), TIME_NOW), 'userID' => $sender->userID, 'username' => $sender->username, 'message' => $this->generator->realText($this->generator->numberBetween(10, 5000))));
     // update response data
     $responseIDs = $target->getResponseIDs();
     if (count($responseIDs) < 3) {
         $responseIDs[] = $response->responseID;
     }
     $responses = $target->responses + 1;
     // update comment
     $commentEditor = new \wcf\data\comment\CommentEditor($target);
     $commentEditor->update(array('responseIDs' => serialize($responseIDs), 'responses' => $responses));
     // update counter
     $this->objectType->getProcessor()->updateCounter($target->objectID, 1);
 }
 /**
  * Adds a response.
  * 
  * @return	array
  */
 public function addResponse()
 {
     if (!empty($this->validationErrors)) {
         if (!empty($this->parameters['data']['username'])) {
             WCF::getSession()->register('username', $this->parameters['data']['username']);
         }
         WCF::getTPL()->assign('errorType', $this->validationErrors);
         $guestDialog = $this->getGuestDialog();
         return array('useCaptcha' => $guestDialog['useCaptcha'], 'guestDialog' => $guestDialog['template']);
     }
     // create response
     $this->createdResponse = CommentResponseEditor::create(array('commentID' => $this->comment->commentID, 'time' => TIME_NOW, 'userID' => WCF::getUser()->userID ?: null, 'username' => WCF::getUser()->userID ? WCF::getUser()->username : $this->parameters['data']['username'], 'message' => $this->parameters['data']['message']));
     // update response data
     $responseIDs = $this->comment->getResponseIDs();
     if (count($responseIDs) < 5) {
         $responseIDs[] = $this->createdResponse->responseID;
     }
     $responses = $this->comment->responses + 1;
     // update comment
     $commentEditor = new CommentEditor($this->comment);
     $commentEditor->update(array('responseIDs' => serialize($responseIDs), 'responses' => $responses));
     // update counter
     $this->commentProcessor->updateCounter($this->parameters['data']['objectID'], 1);
     // fire activity event
     $objectType = ObjectTypeCache::getInstance()->getObjectType($this->comment->objectTypeID);
     if ($this->createdResponse->userID && UserActivityEventHandler::getInstance()->getObjectTypeID($objectType->objectType . '.response.recentActivityEvent')) {
         UserActivityEventHandler::getInstance()->fireEvent($objectType->objectType . '.response.recentActivityEvent', $this->createdResponse->responseID);
     }
     // fire notification event
     if (UserNotificationHandler::getInstance()->getObjectTypeID($objectType->objectType . '.response.notification')) {
         $notificationObjectType = UserNotificationHandler::getInstance()->getObjectTypeProcessor($objectType->objectType . '.notification');
         $userID = $notificationObjectType->getOwnerID($this->comment->commentID);
         $notificationObject = new CommentResponseUserNotificationObject($this->createdResponse);
         if ($this->comment->userID != WCF::getUser()->userID) {
             UserNotificationHandler::getInstance()->fireEvent('commentResponse', $objectType->objectType . '.response.notification', $notificationObject, array($this->comment->userID), array('commentID' => $this->comment->commentID, 'objectID' => $this->comment->objectID, 'objectUserID' => $userID, 'userID' => $this->comment->userID));
         }
         // notify the container owner
         if (UserNotificationHandler::getInstance()->getObjectTypeID($objectType->objectType . '.notification')) {
             if ($userID != $this->comment->userID && $userID != WCF::getUser()->userID) {
                 UserNotificationHandler::getInstance()->fireEvent('commentResponseOwner', $objectType->objectType . '.response.notification', $notificationObject, array($userID), array('commentID' => $this->comment->commentID, 'objectID' => $this->comment->objectID, 'objectUserID' => $userID, 'userID' => $this->comment->userID));
             }
         }
     }
     if (!$this->createdResponse->userID) {
         // save user name is session
         WCF::getSession()->register('username', $this->createdResponse->username);
         // save last comment time for flood control
         WCF::getSession()->register('lastCommentTime', $this->createdResponse->time);
         // reset captcha for future requests
         if ($this->captchaObjectType) {
             $this->captchaObjectType->getProcessor()->reset();
         }
     }
     return array('commentID' => $this->comment->commentID, 'template' => $this->renderResponse($this->createdResponse), 'responses' => $responses);
 }