Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
postsocnetrights.php
1<?php
8namespace Bitrix\Blog;
9
17
18Loc::loadMessages(__FILE__);
19
36class PostSocnetRightsTable extends Entity\DataManager
37{
38 public static function getTableName()
39 {
40 return 'b_blog_socnet_rights';
41 }
42
43 public static function getMap()
44 {
45 $fieldsMap = array(
46 'ID' => array(
47 'data_type' => 'integer',
48 'primary' => true,
49 'autocomplete' => true,
50 ),
51 'POST_ID' => array(
52 'data_type' => 'integer',
53 ),
54 'POST' => array(
55 'data_type' => '\Bitrix\Blog\Post',
56 'reference' => array('=this.POST_ID' => 'ref.ID')
57 ),
58 'ENTITY_TYPE' => array(
59 'data_type' => 'string'
60 ),
61 'ENTITY_ID' => array(
62 'data_type' => 'integer',
63 ),
64 'ENTITY' => array(
65 'data_type' => 'string'
66 ),
67 );
68
69 return $fieldsMap;
70 }
71
72 public static function recalcGroupPostRights($params = array())
73 {
74 if (!is_array($params))
75 {
76 return false;
77 }
78
79 $groupId = (isset($params['groupId']) ? intval($params['groupId']) : 0);
80 $newRole = (isset($params['role']) ? $params['role'] : false);
81
82 $application = \Bitrix\Main\Application::getInstance();
83 $connection = $application->getConnection();
84
85 if (
86 $groupId <= 0
87 || empty($newRole)
88 )
89 {
90 return false;
91 }
92
93 if (!Loader::includeModule('socialnetwork'))
94 {
95 return false;
96 }
97
98 $queryRes = true;
99
100 $prevValue = \Bitrix\Blog\Item\PostSocnetRights::get($groupId);
101 if ($prevValue != $newRole)
102 {
103 $sql = "DELETE FROM ".self::getTableName()." WHERE ENTITY_TYPE = 'SG' AND ENTITY_ID = ".$groupId;
104 try
105 {
106 $connection->query($sql);
107 }
108 catch (SqlException $e)
109 {
110 $queryRes = false;
111 }
112
113 if ($queryRes)
114 {
115 $rightsList = \CBlogPost::getFullGroupRoleSet($newRole, "SG".$groupId."_");
116 $rightsList[] = 'SG'.$groupId;
117 $rightsList = array_unique($rightsList);
118
119 foreach($rightsList as $right)
120 {
121 if (!$queryRes)
122 {
123 break;
124 }
125
126 $sql = "INSERT INTO ".self::getTableName()." (POST_ID, ENTITY_TYPE, ENTITY_ID, ENTITY) ".
127 "SELECT SL.SOURCE_ID, 'SG', ".$groupId.", '".$right."' ".
128 "FROM ".LogTable::getTableName()." SL ".
129 "INNER JOIN ".LogRightTable::getTableName()." SLR ON SLR.LOG_ID = SL.ID AND SLR.GROUP_CODE = 'SG".$groupId."' ".
130 "WHERE SL.EVENT_ID IN ('".implode("', '", \Bitrix\Blog\Integration\Socialnetwork\Log::getEventIdList())."')";
131
132 try
133 {
134 $connection->query($sql);
135 }
136 catch (SqlException $e)
137 {
138 $queryRes = false;
139 }
140 }
141
142 if ($queryRes)
143 {
144 if ($connection->getType() === 'pgsql')
145 {
146 $sql = "DELETE FROM ".LogRightTable::getTableName()." ".
147 "WHERE LOG_ID IN (".
148 " SELECT ".LogTable::getTableName().".ID".
149 " FROM ".LogTable::getTableName().
150 " WHERE ".LogTable::getTableName().".EVENT_ID IN ('".implode("', '", \Bitrix\Blog\Integration\Socialnetwork\Log::getEventIdList())."')".
151 " AND ".LogRightTable::getTableName().".GROUP_CODE LIKE 'SG".$groupId."%'".
152 ");";
153 }
154 else
155 {
156 $sql = "DELETE ".LogRightTable::getTableName()." ".
157 "FROM ".LogRightTable::getTableName()." ".
158 "INNER JOIN ".LogTable::getTableName()." ON ".LogTable::getTableName().".ID = ".LogRightTable::getTableName().".LOG_ID AND ".LogTable::getTableName().".EVENT_ID IN ('".implode("', '", \Bitrix\Blog\Integration\Socialnetwork\Log::getEventIdList())."') ".
159 "WHERE GROUP_CODE LIKE 'SG".$groupId."%'";
160 }
161
162 try
163 {
164 $connection->query($sql);
165 }
166 catch (SqlException $e)
167 {
168 $queryRes = false;
169 }
170 }
171
172 if ($queryRes)
173 {
174 if ($connection->getType() === 'pgsql')
175 {
176 $sql = "DELETE FROM ".LogRightTable::getTableName()." ".
177 "WHERE LOG_ID IN (".
178 " SELECT ".LogTable::getTableName().".ID".
179 " FROM ".LogTable::getTableName().
180 " WHERE ".LogTable::getTableName().".EVENT_ID IN ('".implode("', '", \Bitrix\Blog\Integration\Socialnetwork\Log::getEventIdList())."')".
181 " AND ".LogRightTable::getTableName().".GROUP_CODE LIKE 'OSG".$groupId."%'".
182 ");";
183 }
184 else
185 {
186 $sql = "DELETE ".LogRightTable::getTableName()." ".
187 "FROM ".LogRightTable::getTableName()." ".
188 "INNER JOIN ".LogTable::getTableName()." ON ".LogTable::getTableName().".ID = ".LogRightTable::getTableName().".LOG_ID AND ".LogTable::getTableName().".EVENT_ID IN ('".implode("', '", \Bitrix\Blog\Integration\Socialnetwork\Log::getEventIdList())."') ".
189 "WHERE GROUP_CODE LIKE 'OSG".$groupId."%'";
190 }
191
192 try
193 {
194 $connection->query($sql);
195 }
196 catch (SqlException $e)
197 {
198 $queryRes = false;
199 }
200 }
201
202 if ($queryRes)
203 {
204 $sql = "INSERT INTO ".LogRightTable::getTableName()." (LOG_ID, GROUP_CODE, LOG_UPDATE) ".
205 "SELECT SL.ID, BSR.ENTITY, SL.LOG_UPDATE ".
206 "FROM ".LogTable::getTableName()." SL ".
207 "INNER JOIN ".self::getTableName()." BSR ON BSR.POST_ID = SL.SOURCE_ID AND (BSR.ENTITY LIKE 'SG".$groupId."%' OR BSR.ENTITY LIKE 'OSG".$groupId."%') ".
208 "WHERE SL.EVENT_ID IN ('".implode("', '", \Bitrix\Blog\Integration\Socialnetwork\Log::getEventIdList())."')";
209
210 try
211 {
212 $connection->query($sql);
213 }
214 catch (SqlException $e)
215 {
216 $queryRes = false;
217 }
218 }
219
220 BXClearCache(true, "/blog/getsocnetperms");
221 }
222 }
223
224 return $queryRes;
225 }
226
227 public static function deleteByEntity($value = '')
228 {
229 if ($value == '')
230 {
231 return false;
232 }
233
234 $connection = Application::getConnection();
235 $helper = $connection->getSqlHelper();
236
237 $tableName = self::getTableName();
238 $connection->queryExecute("DELETE FROM {$tableName} WHERE ENTITY = '".$helper->forSql($value)."'");
239
240 return true;
241 }
242}
static getMap()
static deleteByEntity($value='')
static recalcGroupPostRights($params=array())
static getTableName()
static getConnection($name="")
static loadMessages($file)
Definition loc.php:64