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 OnAfterIBlockElementDelete($fields) { $errors = array(); if (Loader::includeModule('socialnetwork')) { $states = CBPStateService::getDocumentStates(array('lists', get_called_class(), $fields['ID'])); foreach ($states as $workflowId => $state) { $sourceId = CBPStateService::getWorkflowIntegerId($workflowId); $resultQuery = CSocNetLog::getList(array(), array('EVENT_ID' => 'lists_new_element', 'SOURCE_ID' => $sourceId), false, false, array('ID')); while ($log = $resultQuery->fetch()) { CSocNetLog::delete($log['ID']); } } } CBPDocument::onDocumentDelete(array('lists', get_called_class(), $fields['ID']), $errors); }
public function canRead($userId) { if ($this->canRead !== null) { return $this->canRead; } /** @noinspection PhpDynamicAsStaticMethodCallInspection */ if (\CSocNetUser::isCurrentUserModuleAdmin()) { $this->canRead = true; return $this->canRead; } if ($comment = $this->loadLogCommentData()) { if (strpos($comment["EVENT_ID"], "crm_") === 0) { $queryLog = \CSocNetLog::getList(array(), array("ID" => intval($comment["LOG_ID"])), false, false, array("ID", "ENTITY_TYPE", "ENTITY_ID")); if (($log = $queryLog->fetch()) && Loader::includeModule("crm")) { $userPermissions = \CCrmPerms::getUserPermissions($userId); if ($log["ENTITY_TYPE"] == "CRMACTIVITY") { $bindings = \CCRMActivity::getBindings($log["ENTITY_ID"]); foreach ($bindings as $binding) { if (\CCrmAuthorizationHelper::checkReadPermission(\CCrmOwnerType::resolveName($binding["OWNER_TYPE_ID"]), $binding["OWNER_ID"], $userPermissions)) { $this->canRead = true; return $this->canRead; } } } else { if (\CCrmAuthorizationHelper::checkReadPermission(\CCrmLiveFeedEntity::resolveEntityTypeID($log["ENTITY_TYPE"]), $log["ENTITY_ID"], $userPermissions)) { $this->canRead = true; return $this->canRead; } elseif (intval($comment["LOG_ID"]) > 0 && \CSocNetLogRights::checkForUser($comment["LOG_ID"], $userId)) { $this->canRead = true; return $this->canRead; } } } } elseif (intval($comment["LOG_ID"]) > 0 && \CSocNetLogRights::checkForUser($comment["LOG_ID"], $userId)) { $this->canRead = true; return $this->canRead; } } $this->canRead = false; return $this->canRead; }
/** * Called from popup * @param string $entityType * @param int $entityId * $param array $comment */ public static function OnForumCommentIMNotify($entityType, $entityId, $comment) { if ($entityType != "WF") { return; } $logQuery = CSocNetLog::getList(array(), array("ID" => $comment["LOG_ID"], "EVENT_ID" => "lists_new_element"), false, false, array("ID", "SOURCE_ID", "URL", "TITLE", "USER_ID", "PARAMS")); if (($log = $logQuery->fetch()) && intval($log["SOURCE_ID"]) > 0) { $params = unserialize($log["PARAMS"]); $title = $log["TITLE"] . " - " . $params["ELEMENT_NAME"]; CListsLiveFeed::notifyComment(array("LOG_ID" => $log["ID"], "TO_USER_ID" => $log["USER_ID"], "FROM_USER_ID" => $comment["USER_ID"], "URL" => $log["URL"], "TITLE" => $title)); } }
public static function OnForumCommentIMNotify($entityType, $entityId, $comment) { return; if ($entityType != "WF") { return; } $logQuery = CSocNetLog::getList(array(), array("ID" => $comment["LOG_ID"], "EVENT_ID" => "lists_new_element"), false, false, array("ID", "SOURCE_ID", "URL", "TITLE", "USER_ID")); if (($log = $logQuery->fetch()) && intval($log["SOURCE_ID"]) > 0) { CListsLiveFeed::notifyComment(array("LOG_ID" => $log["ID"], "TO_USER_ID" => $log["USER_ID"], "FROM_USER_ID" => $comment["USER_ID"], "URL" => $log["URL"], "TITLE" => $log["TITLE"])); } }
public static function deleteSocnetLog(array $listWorkflowId) { if (CModule::includeModule('socialnetwork')) { foreach ($listWorkflowId as $workflowId) { $sourceId = CBPStateService::getWorkflowIntegerId($workflowId); $resultQuery = CSocNetLog::getList(array(), array('EVENT_ID' => 'lists_new_element', 'SOURCE_ID' => $sourceId), false, false, array('ID')); while ($log = $resultQuery->fetch()) { CSocNetLog::delete($log['ID']); } } } }
protected function loadLogEntryData() { $queryLog = \CSocNetLog::getList(array(), array("ID" => $this->entityId), false, false, array("ID", "ENTITY_TYPE", "ENTITY_ID", "EVENT_ID", "SOURCE_ID")); /** @noinspection PhpDynamicAsStaticMethodCallInspection */ return $this->logEntryData = $queryLog->fetch(); }
/** * @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; }