Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
blog.php
1<?php
9
13
14Loc::loadMessages(__FILE__);
15
16class Blog
17{
18 public static function getByUser(array $params)
19 {
20 $result = false;
21
22 if (
23 !isset($params["USER_ID"])
24 || intval($params["USER_ID"]) <= 0
25
26 )
27 {
28 return $result;
29 }
30
31 $siteId = (!empty($params["SITE_ID"]) ? $params["SITE_ID"] : SITE_ID);
32 $userId = intval($params["USER_ID"]);
33 $groupId = (!empty($params["GROUP_ID"]) ? $params["GROUP_ID"] : false);
34
35 $cacheIdKeysList = array(
36 "ACTIVE" => "Y",
37 "USE_SOCNET" => (isset($params["USE_SOCNET"]) && $params["USE_SOCNET"] == "Y" ? "Y" : false),
38 "GROUP_ID" => $groupId,
39 "GROUP_SITE_ID" => $siteId,
40 "OWNER_ID" => $userId,
41 );
42
43 $cacheTtl = 3153600;
44 $cacheId = 'blog_post_blog_'.md5(serialize($cacheIdKeysList));
45 $cacheDir = '/blog/form/blog/';
46
47 $cache = new \CPHPCache;
48 if($cache->initCache($cacheTtl, $cacheId, $cacheDir))
49 {
50 $result = $cache->getVars();
51 }
52 else
53 {
54 $cache->startDataCache();
55
56 if ($groupId)
57 {
58 $blogFilter = [
59 "=ACTIVE" => "Y",
60 "GROUP_ID" => $groupId,
61 "GROUP_SITE_ID" => $siteId,
62 "OWNER_ID" => $userId
63 ];
64
65 if (
66 isset($params["USE_SOCNET"])
67 && $params["USE_SOCNET"] == "Y"
68 )
69 {
70 $blogFilter["USE_SOCNET"] = "Y";
71 }
72
73 $res = \CBlog::getList([], $blogFilter);
74 $result = $res->fetch();
75 }
76
77 if (
78 !$result
80 )
81 {
82 $ideaBlogGroupIdList = array();
84 {
85 $res = \CSite::getList("sort", "desc", Array("ACTIVE" => "Y"));
86 while ($site = $res->fetch())
87 {
88 $val = Config\Option::get("idea", "blog_group_id", false, $site["LID"]);
89 if ($val)
90 {
91 $ideaBlogGroupIdList[] = $val;
92 }
93 }
94 }
95
96 if (empty($ideaBlogGroupIdList))
97 {
98 $result = \CBlog::getByOwnerID($userId);
99 }
100 else
101 {
102 $blogGroupIdList = array();
103 $res = \CBlogGroup::getList(array(), array(), false, false, array("ID"));
104 while($blogGroup = $res->fetch())
105 {
106 if (!in_array($blogGroup["ID"], $ideaBlogGroupIdList))
107 {
108 $blogGroupIdList[] = $blogGroup["ID"];
109 }
110 }
111
112 $result = \CBlog::getByOwnerID($userId, $blogGroupIdList);
113 }
114 }
115
116 $cache->endDataCache($result);
117 }
118
119 if (
120 !$result
121 && $groupId
122 && isset($params["CREATE"])
123 && $params["CREATE"] == "Y"
124 )
125 {
126 $result = \Bitrix\Socialnetwork\ComponentHelper::createUserBlog(array(
127 "BLOG_GROUP_ID" => $groupId,
128 "USER_ID" => $userId,
129 "SITE_ID" => $siteId
130 ));
131 }
132
133 return $result;
134 }
135}
static getByUser(array $params)
Definition blog.php:18
static loadMessages($file)
Definition loc.php:64
static isModuleInstalled($moduleName)