Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
workgroupview.php
1<?php
9
10use Bitrix\Main;
13
30class WorkgroupViewTable extends Entity\DataManager
31{
32 public static function getTableName()
33 {
34 return 'b_sonet_group_view';
35 }
36
37 public static function getMap()
38 {
39 $fieldsMap = array(
40 'USER_ID' => array(
41 'data_type' => 'integer',
42 'primary' => true
43 ),
44 'USER' => array(
45 'data_type' => '\Bitrix\Main\User',
46 'reference' => array('=this.USER_ID' => 'ref.ID')
47 ),
48 'GROUP_ID' => array(
49 'data_type' => 'integer',
50 'primary' => true
51 ),
52 'GROUP' => array(
53 'data_type' => '\Bitrix\Socialnetwork\Workgroup',
54 'reference' => array('=this.GROUP_ID' => 'ref.ID')
55 ),
56 'DATE_VIEW' => array(
57 'data_type' => 'datetime'
58 ),
59 );
60
61 return $fieldsMap;
62 }
63
64 public static function set($params = array())
65 {
66 global $USER, $CACHE_MANAGER;
67
68 if (
69 !is_array($params)
70 || !isset($params['GROUP_ID'])
71 || intval($params['GROUP_ID']) <= 0
72 )
73 {
74 throw new Main\SystemException("Empty groupId.");
75 }
76
77 $groupId = intval($params['GROUP_ID']);
78
79 $userId = (
80 isset($params['USER_ID'])
81 && intval($params['USER_ID']) > 0
82 ? intval($params['USER_ID'])
83 : $USER->getId()
84 );
85
86 if (intval($userId) <= 0)
87 {
88 throw new Main\SystemException("Empty userId.");
89 }
90
91 $connection = \Bitrix\Main\Application::getConnection();
92 $helper = $connection->getSqlHelper();
93
94 $insertFields = array(
95 "USER_ID" => $userId,
96 "GROUP_ID" => $groupId,
97 "DATE_VIEW" => new \Bitrix\Main\DB\SqlExpression($helper->getCurrentDateTimeFunction()),
98 );
99
100 $updateFields = array(
101 "DATE_VIEW" => new \Bitrix\Main\DB\SqlExpression($helper->getCurrentDateTimeFunction()),
102 );
103
104 $merge = $helper->prepareMerge(
105 static::getTableName(),
106 array("USER_ID", "GROUP_ID"),
107 $insertFields,
108 $updateFields
109 );
110
111 if ($merge[0] != "")
112 {
113 $connection->query($merge[0]);
114 }
115
116 if(defined("BX_COMP_MANAGED_CACHE"))
117 {
118 $CACHE_MANAGER->ClearByTag("sonet_group_view_U".$userId);
119 }
120 }
121
122 public static function add(array $data)
123 {
124 throw new NotImplementedException("Use set() method of the class.");
125 }
126
127 public static function update($primary, array $data)
128 {
129 throw new NotImplementedException("Use set() method of the class.");
130 }
131}
static update($primary, array $data)