1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
notifyemail.php
См. документацию.
1<?php
2namespace Bitrix\Idea;
3
6
7Loc::loadMessages(__FILE__);
8
25class NotifyEmailTable extends Entity\DataManager
26{
27 const SUBSCRIBE_TYPE_ALL = 'ALL';
28 const SUBSCRIBE_TYPE_NEW_IDEAS = 'NEW IDEAS';
29 const ENTITY_TYPE_IDEA = 'IDEA';
30 const ENTITY_TYPE_CATEGORY = 'CATEGORY';
36 public static function getFilePath()
37 {
38 return __FILE__;
39 }
40
46 public static function getTableName()
47 {
48 return 'b_idea_email_subscribe';
49 }
50
56 public static function getMap()
57 {
58 return array(
59 'USER_ID' => array(
60 'data_type' => 'integer',
61 'primary' => true,
62 'title' => Loc::getMessage('IDEA_NOTIFY_EMAIL_USER_ID'),
63 ),
64 'SUBSCRIBE_TYPE' => array(
65 'data_type' => 'enum',
66 'required' => true,
67 'values' => array(self::SUBSCRIBE_TYPE_ALL, self::SUBSCRIBE_TYPE_NEW_IDEAS),
68 'title' => Loc::getMessage('IDEA_NOTIFY_EMAIL_SUBSCRIBE_TYPE')
69 ),
70 'ENTITY_TYPE' => array(
71 'data_type' => 'enum',
72 'primary' => true,
73 'values' => array(self::ENTITY_TYPE_IDEA, self::ENTITY_TYPE_CATEGORY),
74 'title' => Loc::getMessage('IDEA_NOTIFY_EMAIL_ENTITY_TYPE')
75 ),
76 'ENTITY_CODE' => array(
77 'data_type' => 'string',
78 'primary' => true,
79
80 'title' => Loc::getMessage('IDEA_NOTIFY_EMAIL_ENTITY_CODE')
81 ),
82 'USER' => array(
83 'data_type' => 'Bitrix\Main\User',
84 'reference' => array(
85 '=this.USER_ID' => 'ref.ID'
86 ),
87 ),
88 new \Bitrix\Main\Entity\ExpressionField(
89 'LOWER_ENTITY_CODE',
90 'LOWER(%s)',
91 'ENTITY_CODE'
92 ),
93 'ASCENDED_CATEGORIES' => array(
94 'data_type' => 'Bitrix\Iblock\Section',
95 'reference' => array(
96 '=this.ENTITY_TYPE' => array('?', 'CATEGORY'),
97 '=this.LOWER_ENTITY_CODE' => 'ref.CODE'
98 ),
99 )
100 );
101 }
102}
103
105{
106 protected static $cache = array();
107 protected $IblockID = null;
108 protected $userID = null;
109
110 function __construct($IblockID = null)
111 {
112 if ($IblockID > 0)
113 {
114 $this->IblockID = $IblockID;
115 \CIdeaManagment::getInstance()->idea()->setCategoryListId($IblockID);
116 }
117 else
118 $this->IblockID = \CIdeaManagment::getInstance()->idea()->getCategoryListID();
119 global $USER;
120 $this->userID = $USER->getID();
121 }
122
123 protected function getCacheId($params = array())
124 {
125 if (array_key_exists("IDEA", $params))
126 {
127 $id = "IDEA_".$params["IDEA"];
128 }
129 else
130 {
131 $id = "CATEGORY_".$this->IblockID.(empty($params["CATEGORY"]) ? "" : "_".$params["CATEGORY"]);
132 }
133
134 return $id;
135 }
136
137 public function addCategory($category, $subscribeType = NotifyEmailTable::SUBSCRIBE_TYPE_NEW_IDEAS)
138 {
139 if ($this->IblockID > 0 && $this->userID > 0)
140 {
141 $db_res = NotifyEmailTable::getList(array(
142 "filter" => array(
143 "USER_ID" => $this->userID,
145 "ENTITY_CODE" => (empty($category) ? "" : $category)
146 )));
147 if ($db_res->getSelectedRowsCount() <= 0)
148 {
149 $db_res = NotifyEmailTable::add(array(
150 "USER_ID" => $this->userID,
153 "ENTITY_CODE" => (empty($category) ? "" : $category)
154 ));
155 }
156 return $db_res;
157 }
158 return false;
159 }
160
161 public function deleteCategory($category)
162 {
163 if ($this->userID > 0)
164 {
165 return NotifyEmailTable::delete(array(
166 "USER_ID" => $this->userID,
168 "ENTITY_CODE" => (empty($category) ? "" : $category)
169 ));
170 }
171 return false;
172 }
173
174 public function addIdea($id)
175 {
176 if ($this->userID > 0)
177 {
178 $db_res = NotifyEmailTable::getList(array(
179 "filter" => array(
180 "USER_ID" => $this->userID,
181 "ENTITY_TYPE" => NotifyEmailTable::ENTITY_TYPE_IDEA,
182 "ENTITY_CODE" => $id.""
183 )));
184 if (!(!!$db_res && ($res = $db_res->fetch()) && !empty($res)))
185 {
186 $db_res = NotifyEmailTable::add(array(
187 "USER_ID" => $this->userID,
188 "SUBSCRIBE_TYPE" => NotifyEmailTable::SUBSCRIBE_TYPE_ALL,
189 "ENTITY_TYPE" => NotifyEmailTable::ENTITY_TYPE_IDEA,
190 "ENTITY_CODE" => $id.""
191 ));
192 return $db_res;
193 }
194 return $res;
195 }
196 return false;
197 }
198
199 public function deleteIdea($id)
200 {
201
202 if ($this->userID > 0)
203 {
204 return NotifyEmailTable::delete(array(
205 "USER_ID" => $this->userID,
206 "ENTITY_TYPE" => NotifyEmailTable::ENTITY_TYPE_IDEA,
207 "ENTITY_CODE" => $id
208 ));
209 }
210 return false;
211 }
212
213 protected function checkCache($userId, $params = array())
214 {
215 if (!array_key_exists($userId, self::$cache))
216 self::$cache[$userId] = array();
217 $id = $this->getCacheId($params);
218 return (array_key_exists($id, self::$cache[$userId]) ? self::$cache[$userId][$id] : false);
219 }
220
221 protected function setCache($userId, $params = array(), $data = array())
222 {
223 if (!array_key_exists($userId, self::$cache))
224 self::$cache[$userId] = array();
225 $id = $this->getCacheId($params);
226 self::$cache[$userId][$id] = $data;
227 return true;
228 }
229
230 public function getAscendedCategories($category = null, $userId = null)
231 {
232 $return = false;
233 $userId = ($userId === null ? $this->userID : $userId);
234 if ($this->IblockID > 0 && $userId > 0)
235 {
236 $cache = $this->checkCache($userId, array("CATEGORY" => $category));
237 if (!!$cache)
238 {
239 $return = $cache;
240 }
241 else if (empty($category))
242 {
243 $return = array();
244 $db_res = NotifyEmailTable::getList(array(
245 "filter" => array(
246 "USER_ID" => $userId,
248 "=ENTITY_CODE" => NULL
249 )
250 ));
251 while ($res = $db_res->fetch())
252 array_push($return, $res);
253 }
254 else if (is_string($category) && ($categories = \CIdeaManagment::getInstance()->idea()->getCategoryList()) && !empty($categories))
255 {
256 $category = mb_strtoupper($category);
257 if (array_key_exists($category, $categories))
258 {
259 $return = array();
260 $category = $categories[$category];
261 $db_res = NotifyEmailTable::getList(array(
262 "filter" => array(
263 "=USER_ID" => $userId,
265 "=ASCENDED_CATEGORIES.IBLOCK_ID" => \CIdeaManagment::getInstance()->idea()->getCategoryListID(),
266 "<=ASCENDED_CATEGORIES.DEPTH_LEVEL" => $category["DEPTH_LEVEL"],
267 "<=ASCENDED_CATEGORIES.LEFT_MARGIN" => $category["LEFT_MARGIN"],
268 ">=ASCENDED_CATEGORIES.RIGHT_MARGIN" => $category["RIGHT_MARGIN"]
269 )
270 ));
271 while ($res = $db_res->fetch())
272 array_push($return, $res);
273 }
274 }
275 $this->setCache($userId, array("CATEGORY" => $category), $return);
276 }
277 return $return;
278 }
279
280}
281?>
$db_res
Определения options_user_settings.php:8
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
getCacheId($params=array())
Определения notifyemail.php:123
setCache($userId, $params=array(), $data=array())
Определения notifyemail.php:221
__construct($IblockID=null)
Определения notifyemail.php:110
deleteCategory($category)
Определения notifyemail.php:161
addCategory($category, $subscribeType=NotifyEmailTable::SUBSCRIBE_TYPE_NEW_IDEAS)
Определения notifyemail.php:137
static $cache
Определения notifyemail.php:106
deleteIdea($id)
Определения notifyemail.php:199
getAscendedCategories($category=null, $userId=null)
Определения notifyemail.php:230
addIdea($id)
Определения notifyemail.php:174
checkCache($userId, $params=array())
Определения notifyemail.php:213
const ENTITY_TYPE_CATEGORY
Определения notifyemail.php:30
const SUBSCRIBE_TYPE_NEW_IDEAS
Определения notifyemail.php:28
static getMap()
Определения notifyemail.php:56
const ENTITY_TYPE_IDEA
Определения notifyemail.php:29
static getFilePath()
Определения notifyemail.php:36
const SUBSCRIBE_TYPE_ALL
Определения notifyemail.php:27
static getTableName()
Определения notifyemail.php:46
$data['IS_AVAILABLE']
Определения .description.php:13
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$res
Определения filter_act.php:7
global $USER
Определения csv_new_run.php:40
Определения notifyemail.php:2
Определения ufield.php:9
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799