Esempio n. 1
0
 public function addComment($authorId, array $data)
 {
     $this->loadBlogPostData();
     $commentFields = array("POST_ID" => $this->entityId, "BLOG_ID" => $this->blogPostData['BLOG_ID'], "POST_TEXT" => $data['text'], "DATE_CREATE" => new DateTime(), "PARENT_ID" => false, "AUTHOR_ID" => $authorId, "HAS_PROPS" => 'Y');
     if (!empty($data['fileId'])) {
         $commentFields['UF_BLOG_COMMENT_FILE'] = array($data['fileId']);
     } elseif (!empty($data['versionId'])) {
         $commentFields['UF_BLOG_COMMENT_FH'] = $data['versionId'];
     }
     $comId = \CBlogComment::add($commentFields);
     if (!$comId) {
         return;
     }
     if (method_exists("CBlogComment", "addLiveComment")) {
         /** @noinspection PhpDynamicAsStaticMethodCallInspection */
         \CBlogComment::addLiveComment($comId, array("MODE" => "PULL_MESSAGE"));
     }
     BXClearCache(true, "/blog/comment/" . $this->entityId . "/");
     if (!Loader::includeModule('socialnetwork')) {
         return;
     }
     $query = \CSocNetLog::getList(array("ID" => "DESC"), array("EVENT_ID" => array("blog_post", "blog_post_important"), "SOURCE_ID" => $this->entityId), false, false, array("ID", "TMP_ID"));
     $row = $query->fetch();
     if (!$row) {
         return;
     }
     $fieldsForSocnet = array("ENTITY_TYPE" => SONET_ENTITY_USER, "ENTITY_ID" => $this->blogPostData["AUTHOR_ID"], "EVENT_ID" => "blog_comment", "=LOG_DATE" => Application::getInstance()->getConnection()->getSqlHelper()->getCurrentDateTimeFunction(), "MESSAGE" => "file", "TEXT_MESSAGE" => "file", "URL" => "", "MODULE_ID" => false, "SOURCE_ID" => $comId, "LOG_ID" => $row["ID"], "RATING_TYPE_ID" => "BLOG_COMMENT", "RATING_ENTITY_ID" => $comId, "USER_ID" => $authorId);
     \CSocNetLogComments::add($fieldsForSocnet, false, false, false);
 }
 public function addComment($authorId, array $data)
 {
     $return = null;
     if (($res = $this->getDataToShow($authorId)) && !empty($res) && ($res2 = $this->getDataToCheck($this->entityId)) && !empty($res2)) {
         list($message, $topic, $forum) = $res2;
         $messageFields = array("POST_MESSAGE" => $data["text"], "PARAM2" => $this->entityId, "APPROVED" => "Y", "PERMISSION_EXTERNAL" => "I", "PERMISSION" => "I");
         if ($forum["DEDUPLICATION"] == "Y") {
             \CForumNew::update($forum["ID"], array("DEDUPLICATION" => "N"), false);
         }
         if (!empty($data['fileId'])) {
             $messageFields['UF_FORUM_MESSAGE_DOC'] = array($data['fileId']);
             $GLOBALS["UF_FORUM_MESSAGE_DOC"] = array($data['fileId']);
         } elseif (!empty($data['versionId'])) {
             $messageFields['UF_FORUM_MESSAGE_VER'] = $data['versionId'];
             $GLOBALS["UF_FORUM_MESSAGE_VER"] = $data['versionId'];
         }
         $comId = ForumAddMessage("REPLY", $message["FORUM_ID"], $message["TOPIC_ID"], 0, $messageFields, $strErrorMessage, $strOKMessage);
         if ($res['DUPLICATE_TO_SOCNET'] == "Y" && $comId > 0 && Loader::includeModule("socialnetwork")) {
             if ($res['DUPLICATE_TO_SOCNET'] == "Y") {
                 $arFieldsForSocnet = array("USER_ID" => $authorId, '=LOG_DATE' => $GLOBALS['DB']->currentTimeFunction(), "ENTITY_TYPE" => $res["ENTITY_TYPE"], "ENTITY_ID" => $res["ENTITY_ID"], "EVENT_ID" => $res["EVENT_ID"], "MESSAGE" => $data["text"], "TEXT_MESSAGE" => $data["text"], "URL" => $res["DETAIL_URL"], "MODULE_ID" => $res["MODULE_ID"], "SOURCE_ID" => $comId, "LOG_ID" => $res["LOG_ID"], "RATING_TYPE_ID" => "FORUM_POST", "RATING_ENTITY_ID" => $comId);
                 if (!empty($data['fileId'])) {
                     $arFieldsForSocnet['UF_SONET_COM_DOC'] = array($data['fileId']);
                     $GLOBALS["UF_SONET_COM_DOC"] = array($data['fileId']);
                 } elseif (!empty($data['versionId'])) {
                     $arFieldsForSocnet['UF_SONET_COM_VER'] = $data['versionId'];
                     $GLOBALS["UF_SONET_COM_VER"] = $data['versionId'];
                 }
                 \CSocNetLogComments::add($arFieldsForSocnet, false, false, false);
             }
         }
         if ($comId > 0 && Loader::includeModule("pull") && \CPullOptions::getNginxStatus() && $res["DETAIL_URL"] !== null) {
             \CPullWatch::addToStack("UNICOMMENTS" . $topic["XML_ID"], array('module_id' => "unicomments", 'command' => "comment", 'params' => array("AUTHOR_ID" => $authorId, "ID" => $comId, "POST_ID" => $this->entityId, "TS" => time(), "ACTION" => "REPLY", "URL" => array("LINK" => str_replace("MID=" . $this->entityId, "MID=" . $comId, $res["DETAIL_URL"])), "ENTITY_XML_ID" => $topic["XML_ID"], "APPROVED" => "Y", "NEED_REQUEST" => "Y")));
         }
     }
 }