Exemple #1
0
 public static function addCommentLists($fields)
 {
     if (!CModule::IncludeModule('forum') || !CModule::IncludeModule('bizproc')) {
         return false;
     }
     $ufFileId = array();
     $ufDocId = array();
     $fieldsMessage = array();
     $messageId = array();
     $error = array();
     $note = array();
     $sonetLogQuery = CSocNetLog::GetList(array(), array('ID' => $fields['LOG_ID']), false, false, array('ID', 'SOURCE_ID', 'SITE_ID', 'MESSAGE', 'USER_ID'));
     if ($sonetLog = $sonetLogQuery->fetch()) {
         $users = CBPTaskService::getWorkflowParticipants($sonetLog['MESSAGE'], CBPTaskUserStatus::Waiting);
         if (preg_match_all("/(?<=\\[USER=)(?P<id>[0-9]+)(?=\\])/", $fields['TEXT_MESSAGE'], $matches)) {
             $users = array_unique(array_merge($users, $matches['id']));
         }
         $users[] = $sonetLog['USER_ID'];
         self::setSocnetFollow($users, $sonetLog['ID'], 'Y', false, true);
         $forumId = CBPHelper::getForumId();
         if ($forumId) {
             $topicQuery = CForumTopic::GetList(array(), array('FORUM_ID' => $forumId, 'XML_ID' => 'WF_' . $sonetLog['MESSAGE']));
             if ($topicQuery && ($topic = $topicQuery->fetch())) {
                 $topicId = $topic['ID'];
             } else {
                 $arTopic = array('AUTHOR_ID' => 0, 'TITLE' => 'WF_' . $sonetLog['MESSAGE'], 'TAGS' => '', 'MESSAGE' => 'WF_' . $sonetLog['MESSAGE'], 'XML_ID' => 'WF_' . $sonetLog['MESSAGE']);
                 $arUserStart = array("ID" => $arTopic["AUTHOR_ID"], "NAME" => $GLOBALS["FORUM_STATUS_NAME"]["guest"]);
                 $GLOBALS["DB"]->StartTransaction();
                 $arTopicFields = array("TITLE" => $arTopic["TITLE"], "TAGS" => $arTopic["TAGS"], "FORUM_ID" => $forumId, "USER_START_ID" => $arUserStart["ID"], "USER_START_NAME" => $arUserStart["NAME"], "LAST_POSTER_NAME" => $arUserStart["NAME"], "XML_ID" => $arTopic["XML_ID"], "APPROVED" => "Y", "PERMISSION_EXTERNAL" => 'Q', "PERMISSION" => 'Y');
                 $topicId = CForumTopic::Add($arTopicFields);
                 if (intval($topicId) > 0) {
                     $arTopic['MESSAGE'] = strip_tags($arTopic['MESSAGE']);
                     $arFields = array("POST_MESSAGE" => $arTopic['MESSAGE'], "AUTHOR_ID" => $arUserStart["ID"], "AUTHOR_NAME" => $arUserStart["NAME"], "FORUM_ID" => $forumId, "TOPIC_ID" => $topicId, "APPROVED" => "Y", "NEW_TOPIC" => "Y", "PARAM1" => "WF", "PARAM2" => 0, "PERMISSION_EXTERNAL" => 'Q', "PERMISSION" => 'Y');
                     $startMessageId = CForumMessage::Add($arFields, false, array("SKIP_INDEXING" => "Y", "SKIP_STATISTIC" => "N"));
                     if (intVal($startMessageId) <= 0) {
                         CForumTopic::Delete($topicId);
                         $topicId = 0;
                     }
                 }
                 if (intval($topicId) <= 0) {
                     $GLOBALS["DB"]->Rollback();
                 } else {
                     $GLOBALS["DB"]->Commit();
                 }
             }
             if ($topicId) {
                 $fieldsMessage = array('POST_MESSAGE' => $fields['TEXT_MESSAGE'], 'USE_SMILES' => 'Y', 'PERMISSION_EXTERNAL' => 'Q', 'PERMISSION' => 'Y', 'APPROVED' => 'Y');
                 $tmp = false;
                 $GLOBALS['USER_FIELD_MANAGER']->editFormAddFields('SONET_COMMENT', $tmp);
                 if (is_array($tmp)) {
                     if (array_key_exists('UF_SONET_COM_DOC', $tmp)) {
                         $GLOBALS['UF_FORUM_MESSAGE_DOC'] = $tmp['UF_SONET_COM_DOC'];
                     } elseif (array_key_exists('UF_SONET_COM_FILE', $tmp)) {
                         $fieldsMessage['FILES'] = array();
                         foreach ($tmp['UF_SONET_COM_FILE'] as $fileId) {
                             $fieldsMessage['FILES'][] = array('FILE_ID' => $fileId);
                         }
                     }
                     if (array_key_exists("UF_SONET_COM_URL_PRV", $tmp)) {
                         $GLOBALS["UF_FORUM_MES_URL_PRV"] = $tmp["UF_SONET_COM_URL_PRV"];
                     }
                 }
                 $messageId = ForumAddMessage("REPLY", $forumId, $topicId, 0, $fieldsMessage, $error, $note);
                 if ($messageId > 0) {
                     $addedMessageFilesQuery = CForumFiles::getList(array('ID' => 'ASC'), array('MESSAGE_ID' => $messageId));
                     while ($addedMessageFiles = $addedMessageFilesQuery->fetch()) {
                         $ufFileId[] = $addedMessageFiles['FILE_ID'];
                     }
                     $ufDocId = $GLOBALS['USER_FIELD_MANAGER']->getUserFieldValue('FORUM_MESSAGE', 'UF_FORUM_MESSAGE_DOC', $messageId, LANGUAGE_ID);
                     $ufUrlPreview = $GLOBALS["USER_FIELD_MANAGER"]->GetUserFieldValue("FORUM_MESSAGE", "UF_FORUM_MES_URL_PRV", $messageID, LANGUAGE_ID);
                 }
             }
         }
     }
     if (!$messageId) {
         $error = Loc::getMessage('LISTS_LF_ADD_COMMENT_SOURCE_ERROR');
     }
     return array('SOURCE_ID' => $messageId, 'MESSAGE' => $fieldsMessage ? $fieldsMessage['POST_MESSAGE'] : false, 'RATING_TYPE_ID' => 'FORUM_POST', 'RATING_ENTITY_ID' => $messageId, 'ERROR' => $error, 'NOTES' => $note, 'UF' => array('FILE' => $ufFileId, 'DOC' => $ufDocId, 'URL_PREVIEW' => $ufUrlPreview));
 }
 /**
  * @param $userId
  * @return bool
  */
 public function canRead($userId)
 {
     if ($this->canRead !== null) {
         return $this->canRead;
     }
     if (($res = $this->getDataToCheck($this->entityId)) && !empty($res)) {
         list($message, $topic) = $res;
         $entityId = null;
         $entityType = null;
         if (!empty($topic["XML_ID"])) {
             $entityId = substr($topic["XML_ID"], strrpos($topic["XML_ID"], "_") + 1);
             $entityType = substr($topic["XML_ID"], 0, strrpos($topic["XML_ID"], "_"));
         }
         switch ($entityType) {
             case "TASK":
                 if (Loader::includeModule("tasks")) {
                     $connector = new TaskConnector($entityId, $this->attachedObject);
                     $this->canRead = $connector->canRead($userId);
                     return $this->canRead;
                 }
                 break;
             case "EVENT":
                 if (Loader::includeModule("calendar")) {
                     $connector = new CalendarEventConnector($entityId, $this->attachedObject);
                     $this->canRead = $connector->canRead($userId);
                     return $this->canRead;
                 }
                 break;
             case "IBLOCK":
                 if ((int) $topic["USER_ID"] > 0 && Loader::includeModule("socialnetwork")) {
                     $codes = array();
                     if (($res = \CSocNetLog::getList(array(), array("SOURCE_ID" => $entityId, "EVENT_ID" => array("photo_photo", "news", "wiki")), false, false, array("ID"))->fetch()) && $res) {
                         $db_res = \CSocNetLogRights::getList(array(), array("LOG_ID" => $res["ID"]));
                         while ($res = $db_res->fetch()) {
                             $codes[] = $res["GROUP_CODE"];
                         }
                     }
                     $this->canRead = $this->canAccess($userId, $codes);
                     return $this->canRead;
                 }
                 $this->canRead = true;
                 return $this->canRead;
             case "MEETING":
                 $this->canRead = (int) $message["FORUM_ID"] == (int) \COption::getOptionInt('meeting', 'comments_forum_id', 0, SITE_ID);
                 return $this->canRead;
             case "TIMEMAN_ENTRY":
                 if (Loader::includeModule("timeman")) {
                     $dbEntry = \CTimeManEntry::getList(array(), array("ID" => $entityId), false, false, array("ID", "USER_ID"));
                     if ($arEntry = $dbEntry->fetch()) {
                         if ($arEntry["USER_ID"] == $userId) {
                             $this->canRead = true;
                             return $this->canRead;
                         } else {
                             $arManagers = \CTimeMan::getUserManagers($arEntry["USER_ID"]);
                             $this->canRead = in_array($userId, $arManagers);
                             return $this->canRead;
                         }
                     }
                 }
                 $this->canRead = false;
                 return $this->canRead;
             case "TIMEMAN_REPORT":
                 if (Loader::includeModule("timeman")) {
                     $dbReport = \CTimeManReportFull::getList(array(), array("ID" => $entityId), array("ID", "USER_ID"));
                     if ($arReport = $dbReport->fetch()) {
                         if ($arReport["USER_ID"] == $userId) {
                             $this->canRead = true;
                             return $this->canRead;
                         } else {
                             $arManagers = \CTimeMan::getUserManagers($arReport["USER_ID"]);
                             $this->canRead = in_array($userId, $arManagers);
                             return $this->canRead;
                         }
                     }
                 }
                 $this->canRead = false;
                 return $this->canRead;
             case "WF":
                 $this->canRead = false;
                 if (Loader::includeModule("bizproc")) {
                     $currentUserId = (int) $this->getUser()->getId();
                     $participants = \CBPTaskService::getWorkflowParticipants($entityId);
                     if (in_array($currentUserId, $participants)) {
                         $this->canRead = true;
                     } else {
                         $state = \CBPStateService::getWorkflowStateInfo($entityId);
                         if ($state && $currentUserId === (int) $state['STARTED_BY']) {
                             $this->canRead = true;
                         }
                     }
                 }
                 return $this->canRead;
         }
         if ((!empty($topic["SOCNET_GROUP_ID"]) || !empty($topic["OWNER_ID"])) && Loader::includeModule("socialnetwork")) {
             if (!empty($topic["SOCNET_GROUP_ID"])) {
                 $this->canRead = \CSocNetFeatures::isActiveFeature(SONET_ENTITY_GROUP, $topic["SOCNET_GROUP_ID"], "forum") && \CSocNetFeaturesPerms::canPerformOperation($userId, SONET_ENTITY_GROUP, $topic["SOCNET_GROUP_ID"], "forum", "view");
                 return $this->canRead;
             } else {
                 $this->canRead = \CSocNetFeatures::isActiveFeature(SONET_ENTITY_USER, $topic["OWNER_ID"], "forum") && \CSocNetFeaturesPerms::canPerformOperation($userId, SONET_ENTITY_USER, $topic["OWNER_ID"], "forum", "view");
                 return $this->canRead;
             }
         }
         if ($message) {
             $user = $this->getUser();
             if ($user && $userId == $user->getId()) {
                 $userGroups = $user->getUserGroupArray();
             } else {
                 $userGroups = array(2);
             }
             /** @noinspection PhpDynamicAsStaticMethodCallInspection */
             if (\CForumUser::isAdmin($userId, $userGroups)) {
                 $this->canRead = true;
                 return $this->canRead;
             }
             /** @noinspection PhpDynamicAsStaticMethodCallInspection */
             $perms = \CForumNew::getUserPermission($message["FORUM_ID"], $userGroups);
             if ($perms >= "Y") {
                 $this->canRead = true;
                 return $this->canRead;
             }
             if ($perms < "E" || $perms < "Q" && $message["APPROVED"] != "Y") {
                 $this->canRead = false;
                 return $this->canRead;
             }
             /** @noinspection PhpDynamicAsStaticMethodCallInspection */
             $forum = \CForumNew::getByID($message["FORUM_ID"]);
             $this->canRead = $forum["ACTIVE"] == "Y";
             return $this->canRead;
         }
     }
     $this->canRead = false;
     return $this->canRead;
 }