Esempio n. 1
0
 function do_postreply()
 {
     $aErrorOptions = array('redirect_to' => array('main', sprintf('fDocumentId=%d', $this->oDocument->getId())));
     $iThreadId = KTUtil::arrayGet($_REQUEST, 'fThreadId');
     $oThread = DiscussionThread::get($iThreadId);
     $this->oValidator->notError($oThread, $aErrorOptions);
     $aErrorOptions = array('redirect_to' => array('viewthread', sprintf('fDocumentId=%d&fThreadId=%d', $this->oDocument->getId(), $oThread->getId())));
     $aErrorOptions['message'] = _kt("No subject provided");
     $sSubject = KTUtil::arrayGet($_REQUEST, 'subject');
     $sSubject = $this->oValidator->validateString($sSubject, $aErrorOptions);
     $aErrorOptions['message'] = _kt("No body provided");
     $sBody = KTUtil::arrayGet($_REQUEST, 'body');
     $sBody = $this->oValidator->validateString($sBody, $aErrorOptions);
     // Start the transaction comment creation
     $this->startTransaction();
     // Create comment
     $oComment = DiscussionComment::createFromArray(array('threadid' => $oThread->getId(), 'userid' => $this->oUser->getId(), 'subject' => $sSubject, 'body' => KTUtil::formatPlainText($sBody)));
     $aErrorOptions['message'] = _kt("There was an error adding the comment to the thread");
     $this->oValidator->notError($oComment, $aErrorOptions);
     // Update thread
     $oThread->setLastCommentId($oComment->getId());
     $oThread->incrementNumberOfReplies();
     $res = $oThread->update();
     // add to searchable_text.
     $sTable = KTUtil::getTableName('comment_searchable_text');
     $aSearch = array('comment_id' => $oComment->getId(), 'document_id' => $this->oDocument->getId(), 'body' => sprintf("%s %s", KTUtil::formatPlainText($sBody), $sSubject));
     DBUtil::autoInsert($sTable, $aSearch, array('noid' => true));
     $aErrorOptions['message'] = _kt("There was an error updating the thread with the new comment");
     $this->oValidator->notError($res, $aErrorOptions);
     $oKTTriggerRegistry = KTTriggerRegistry::getSingleton();
     $aTriggers = $oKTTriggerRegistry->getTriggers('discussion', 'postValidate');
     foreach ($aTriggers as $aTrigger) {
         $sTrigger = $aTrigger[0];
         $oTrigger = new $sTrigger();
         $aInfo = array("document" => $this->oDocument, "comment" => $oComment);
         $oTrigger->setInfo($aInfo);
         $ret = $oTrigger->postValidate();
         if (PEAR::isError($ret)) {
             $this->oValidator->notError($res, $aErrorOptions);
         }
     }
     // Thread and comment created correctly, commit to database
     $this->commitTransaction();
     $this->successRedirectTo('viewThread', _kt("Reply posted"), sprintf('fDocumentId=%d&fThreadId=%d', $this->oDocument->getId(), $oThread->getId()));
     exit(0);
 }