Exemplo n.º 1
0
 private function prepareFields(array &$params, ErrorCollection $errorCollectionParam)
 {
     $result = array("FORUM_ID" => $this->topic["FORUM_ID"], "TOPIC_ID" => $this->topic["ID"], "POST_MESSAGE" => trim($params["POST_MESSAGE"]), "AUTHOR_ID" => $params["AUTHOR_ID"], "AUTHOR_NAME" => trim($params["AUTHOR_NAME"]), "AUTHOR_EMAIL" => trim($params["AUTHOR_EMAIL"]), "USE_SMILES" => $params["USE_SMILES"] == "Y" ? "Y" : "N", "APPROVED" => $this->topic["APPROVED"], "XML_ID" => $this->getEntity()->getXmlId());
     $errorCollection = new ErrorCollection();
     if (strlen($result["POST_MESSAGE"]) <= 0) {
         $errorCollection->addOne(new Error(Loc::getMessage("FORUM_CM_ERR_EMPTY_TEXT"), self::ERROR_PARAMS_MESSAGE));
     }
     if (strlen($result["AUTHOR_NAME"]) <= 0 && $result["AUTHOR_ID"] > 0) {
         $result["AUTHOR_NAME"] = self::getUserName($result["AUTHOR_ID"]);
     }
     if (strlen($result["AUTHOR_NAME"]) <= 0) {
         $errorCollection->addOne(new Error(Loc::getMessage("FORUM_CM_ERR_EMPTY_AUTHORS_NAME"), self::ERROR_PARAMS_MESSAGE));
     }
     if (is_array($params["FILES"]) && in_array($this->forum["ALLOW_UPLOAD"], array("Y", "F", "A"))) {
         $result["FILES"] = array();
         foreach ($params["FILES"] as $key => $val) {
             if (intval($val["FILE_ID"]) > 0) {
                 $val["del"] = $val["del"] == "Y" ? "Y" : "";
             }
             $result["FILES"][$key] = $val;
         }
         $res = array("FORUM_ID" => $this->forum["ID"], "TOPIC_ID" => $this->topic["ID"], "MESSAGE_ID" => 0, "USER_ID" => $result["AUTHOR_ID"], "FORUM" => $this->forum);
         if (!\CForumFiles::CheckFields($result["FILES"], $res, "NOT_CHECK_DB")) {
             $text = "File upload error.";
             if (($ex = $this->getApplication()->getException()) && $ex) {
                 $text = $ex->getString();
             }
             $errorCollection->addOne(new Error($text, self::ERROR_PARAMS_MESSAGE));
         }
     }
     if ($result["APPROVED"] != "N") {
         $result["APPROVED"] = $this->forum["MODERATION"] != "Y" || $this->getEntity()->canModerate() ? "Y" : "N";
     }
     if ($errorCollection->hasErrors()) {
         $errorCollectionParam->add($errorCollection->toArray());
         return false;
     } else {
         $GLOBALS["USER_FIELD_MANAGER"]->EditFormAddFields("FORUM_MESSAGE", $result);
         $params = $result;
         return true;
     }
 }
Exemplo n.º 2
0
 public function getErrors()
 {
     return $this->errorCollection->toArray();
 }