Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
gratitude.php
1<?php
9
12
13Loc::loadMessages(__FILE__);
14
16{
20
21 public static function getPropertyData()
22 {
23 static $result = null;
24
25 if ($result === null)
26 {
27 $result = [];
28
29 if (!Loader::includeModule('iblock'))
30 {
31 return $result;
32 }
33
34 $res = \Bitrix\Iblock\PropertyEnumerationTable::getList(array(
35 'select' => [ 'ID', 'VALUE', 'SORT', 'XML_ID' ],
36 'filter' => [
37 '=PROPERTY.IBLOCK_ID' => self::getIblockId(),
38 '=PROPERTY.CODE' => self::SOCIALNETWORK_GRATITUDE_PROPERTY_CODE
39 ],
40 'order' => [ 'SORT' => 'ASC' ]
41 ));
42 while ($enumFields = $res->fetch())
43 {
44 $result[$enumFields['XML_ID']] = $enumFields;
45 }
46 }
47
48 return $result;
49 }
50
51 public static function getIblockId()
52 {
53 static $result = null;
54
55 if ($result === null)
56 {
57 $result = false;
58
59 if (!Loader::includeModule('iblock'))
60 {
61 return $result;
62 }
63
64 $res = \Bitrix\Iblock\IblockTable::getList(array(
65 'filter' => [
66 '=CODE' => self::SOCIALNETWORK_GRATITUDE_IBLOCK_CODE,
67 '=IBLOCK_TYPE_ID' => self::SOCIALNETWORK_GRATITUDE_IBLOCK_TYPE_ID
68 ],
69 'select' => [ 'ID' ]
70 ));
71 if ($iblockFields = $res->fetch())
72 {
73 $result = (int)($iblockFields['ID']);
74 }
75 }
76
77 return $result;
78 }
79
80 public static function create(array $params = [])
81 {
82 global $CACHE_MANAGER;
83
84 $result = null;
85
86 if (!Loader::includeModule('iblock'))
87 {
88 return $result;
89 }
90
91 $medal = (!empty($params['medal']) ? trim($params['medal']) : '');
92 $employees = (is_array($params['employees']) && !empty($params['employees']) ? $params['employees'] : []);
93 if (
94 $medal === ''
95 || empty($employees)
96 )
97 {
98 return $result;
99 }
100
101 $gratitudesIblockId = \Bitrix\Socialnetwork\Component\LogList\Gratitude::getGratitudesIblockId();
102 if (!$gratitudesIblockId)
103 {
104 return $result;
105 }
106
107 $gratitudesPropertyData = self::getPropertyData();
108 if (!array_key_exists($medal, $gratitudesPropertyData))
109 {
110 return $result;
111 }
112
113 $gratitudeEnumFields = $gratitudesPropertyData[$medal];
114
115 $gratitudeElement = new \CIBlockElement;
116 $result = $gratitudeElement->add(
117 [
118 'IBLOCK_ID' => $gratitudesIblockId,
119 'DATE_ACTIVE_FROM' => new \Bitrix\Main\Type\DateTime(),
120 'NAME' => str_replace('#GRAT_NAME#', $gratitudeEnumFields['VALUE'], Loc::getMessage('SOCIALNETWORK_HELPER_GRATITUDE_IBLOCKELEMENT_NAME'))
121 ],
122 false,
123 false
124 );
125
126 if ($result)
127 {
128 \CIBlockElement::setPropertyValuesEx(
129 $result,
130 $gratitudesIblockId,
131 [
132 'USERS' => $employees,
133 self::SOCIALNETWORK_GRATITUDE_PROPERTY_CODE => [ 'VALUE' => $gratitudeEnumFields['ID'] ]
134 ]
135 );
136
137 if (defined("BX_COMP_MANAGED_CACHE"))
138 {
139 foreach($employees as $employeeId)
140 {
141 $CACHE_MANAGER->clearByTag('BLOG_POST_GRATITUDE_TO_USER_'.$employeeId);
142 }
143 }
144 }
145
146 return $result;
147 }
148}
149?>
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
static create(array $params=[])
Definition gratitude.php:80