Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
workgroupfavorites.php
1<?php
9
10use Bitrix\Main;
13
41class WorkgroupFavoritesTable extends Entity\DataManager
42{
43 public static function getTableName()
44 {
45 return 'b_sonet_group_favorites';
46 }
47
52 public static function getMap()
53 {
54 $fieldsMap = array(
55 'USER_ID' => array(
56 'data_type' => 'integer',
57 'primary' => true
58 ),
59 'USER' => array(
60 'data_type' => '\Bitrix\Main\User',
61 'reference' => array('=this.USER_ID' => 'ref.ID')
62 ),
63 'GROUP_ID' => array(
64 'data_type' => 'integer',
65 'primary' => true
66 ),
67 'GROUP' => array(
68 'data_type' => '\Bitrix\Socialnetwork\Workgroup',
69 'reference' => array('=this.GROUP_ID' => 'ref.ID')
70 ),
71 'DATE_ADD' => array(
72 'data_type' => 'datetime'
73 ),
74 );
75
76 return $fieldsMap;
77 }
78
85 public static function set($params = array())
86 {
87 global $USER, $CACHE_MANAGER;
88 $res = false;
89
90 if (
91 !is_array($params)
92 || !isset($params['GROUP_ID'])
93 || intval($params['GROUP_ID']) <= 0
94 )
95 {
96 throw new Main\SystemException("Empty groupId.");
97 }
98
99 $groupId = intval($params['GROUP_ID']);
100
101 $userId = (
102 isset($params['USER_ID'])
103 && intval($params['USER_ID']) > 0
104 ? intval($params['USER_ID'])
105 : $USER->getId()
106 );
107
108 if (intval($userId) <= 0)
109 {
110 throw new Main\SystemException("Empty userId.");
111 }
112
113 $connection = \Bitrix\Main\Application::getConnection();
114 $helper = $connection->getSqlHelper();
115
116 $insertFields = array(
117 "USER_ID" => $userId,
118 "GROUP_ID" => $groupId,
119 "DATE_ADD" => new \Bitrix\Main\DB\SqlExpression($helper->getCurrentDateTimeFunction()),
120 );
121
122 $updateFields = array(
123 "DATE_ADD" => new \Bitrix\Main\DB\SqlExpression($helper->getCurrentDateTimeFunction()),
124 );
125
126 $merge = $helper->prepareMerge(
127 static::getTableName(),
128 array("USER_ID", "GROUP_ID"),
129 $insertFields,
130 $updateFields
131 );
132
133 if ($merge[0] != "")
134 {
135 $res = $connection->query($merge[0]);
136 }
137
138 if(
139 $res
140 && defined("BX_COMP_MANAGED_CACHE")
141 )
142 {
143 $CACHE_MANAGER->clearByTag("sonet_group_favorites_U".$userId);
144 }
145
146 return $res;
147 }
148
149 public static function add(array $data)
150 {
151 throw new NotImplementedException("Use set() method of the class.");
152 }
153
154 public static function update($primary, array $data)
155 {
156 throw new NotImplementedException("Use set() method of the class.");
157 }
158}