示例#1
0
 private function updateCommentFromRequest(Comment $comment, Request $request)
 {
     $comment->setBodyRaw($request->getRequestString("comment", ""));
     if ($comment->isByVisitor()) {
         $name = $request->getRequestString("name", "");
         $email = $request->getRequestString("email", "");
         $comment->setByVisitor($name, $email);
     }
 }
示例#2
0
 /**
  * Validates a comment for saving to the database.
  * @param Comment $comment The comment.
  * @param Text $text Errors go here.
  * @return boolean True if the comment is valid, false otherwise.
  */
 public function validateComment(Comment $comment, Text $text)
 {
     $valid = true;
     if (!Validate::stringLength($comment->getBodyRaw(), Comment::BODY_MIN_LENGTH, Comment::BODY_MAX_LENGTH)) {
         $text->addError($text->t("comments.comment") . " " . Validate::getLastError($text));
         $valid = false;
     }
     if ($comment->isByVisitor()) {
         if (!Validate::email($comment->getUserEmail())) {
             $text->addError($text->t("users.email") . " " . Validate::getLastError($text));
             $valid = false;
         }
         if (!Validate::displayName($comment->getUserDisplayName())) {
             $text->addError($text->t("users.name") . " " . Validate::getLastError($text));
             $valid = false;
         }
     }
     return $valid;
 }