Пример #1
0
 public function executeComponent()
 {
     try {
         /*
         			if (IsModuleInstalled("disk"))
         			{
         				\Bitrix\Disk\Internals\Diag::getInstance()
         //					->setExclusiveUserId(45)
         					->setEnableTimeTracker(true)
         					->setMemoryBehavior(\Bitrix\Disk\Internals\Diag::MEMORY_PRINT_DIFF)
         					->setSqlBehavior(\Bitrix\Disk\Internals\Diag::SQL_COUNT)
         					->collectDebugInfo($this->componentId, $this->getName());
         			}
         */
         $this->checkRequiredParams();
         $this->feed = new \Bitrix\Forum\Comments\Feed($this->arParams["FORUM_ID"], array("type" => $this->arParams["ENTITY_TYPE"], "id" => $this->arParams["ENTITY_ID"], "xml_id" => $this->arParams["ENTITY_XML_ID"]));
         $this->forum = $this->feed->getForum();
         if (array_key_exists("PERMISSION", $this->arParams)) {
             $this->feed->setPermission($this->arParams["PERMISSION"]);
         }
         if (array_key_exists("ALLOW_EDIT_OWN_MESSAGE", $this->arParams)) {
             $this->feed->setEditOwn($this->arParams["ALLOW_EDIT_OWN_MESSAGE"] == "ALL" || $this->arParams["ALLOW_EDIT_OWN_MESSAGE"] === "LAST");
         }
         $this->arParams["ALLOW_EDIT_OWN_MESSAGE"] = $this->feed->getEntity()->canEditOwn() ? "ALL" : "N";
         if (!$this->errorCollection->hasErrors() && $this->feed->canRead()) {
             $this->bindObjects();
             $this->prepareParams();
             foreach (GetModuleEvents('forum', 'OnCommentsInit', true) as $arEvent) {
                 ExecuteModuleEventEx($arEvent, array(&$this));
             }
             if (!$this->checkPreview() && $this->checkActions() === false) {
                 foreach (GetModuleEvents('forum', 'OnCommentError', true) as $arEvent) {
                     ExecuteModuleEventEx($arEvent, array(&$this));
                 }
             }
             ob_start();
             $this->__includeComponent();
             $output = ob_get_clean();
             foreach (GetModuleEvents('forum', 'OnCommentsDisplayTemplate', true) as $arEvent) {
                 ExecuteModuleEventEx($arEvent, array(&$output, $this->arParams, $this->arResult));
             }
             echo $output;
         } else {
             $this->showError();
         }
         if (IsModuleInstalled("disk")) {
             \Bitrix\Disk\Internals\Diag::getInstance()->logDebugInfo($this->componentId, $this->getName());
         }
     } catch (Exception $e) {
         $this->handleException($e);
     }
 }
Пример #2
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;
     }
 }
Пример #3
0
 public function hasErrors()
 {
     return $this->errorCollection->hasErrors();
 }