Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
workgrouptag.php
1<?php
9
12
29class WorkgroupTagTable extends Entity\DataManager
30{
31 public static function getTableName()
32 {
33 return 'b_sonet_group_tag';
34 }
35
36 public static function getMap()
37 {
38 return array(
39 'GROUP_ID' => array(
40 'data_type' => 'integer',
41 'primary' => true
42 ),
43 'GROUP' => array(
44 'data_type' => '\Bitrix\Socialnetwork\Workgroup',
45 'reference' => array('=this.GROUP_ID' => 'ref.ID')
46 ),
47 'NAME' => array(
48 'data_type' => 'string',
49 'primary' => true
50 )
51 );
52 }
53
54 public static function deleteByGroupId($params = array())
55 {
56 if (
57 !is_array($params)
58 || empty($params['groupId'])
59 || intval($params['groupId']) <= 0
60 )
61 {
62 return false;
63 }
64
65 \Bitrix\Main\Application::getConnection()->queryExecute('DELETE FROM '.self::getTableName().' WHERE GROUP_ID = '.intval($params['groupId']));
66 return true;
67 }
68
69 public static function set($params = array())
70 {
71 if (
72 !is_array($params)
73 || empty($params['groupId'])
74 || intval($params['groupId']) <= 0
75 || !isset($params['tags'])
76 || !is_array($params['tags'])
77 )
78 {
79 return false;
80 }
81
83 'groupId' => intval($params['groupId'])
84 ));
85
86 foreach($params['tags'] as $tag)
87 {
88 self::processAdd(array(
89 'GROUP_ID' => intval($params['groupId']),
90 'NAME' => toLower($tag)
91 ));
92 }
93
94 return true;
95 }
96
97 protected static function processAdd(array $data)
98 {
99 try
100 {
101 self::add($data);
102 }
103 catch (SqlQueryException $exception)
104 {
105 if (!self::isDuplicateKeyError($exception))
106 {
107 throw $exception;
108 }
109 }
110 }
111
112 protected static function isDuplicateKeyError(SqlQueryException $exception)
113 {
114 return mb_strpos($exception->getDatabaseMessage(), '(1062)') !== false;
115 }
116}
static deleteByGroupId($params=array())
static isDuplicateKeyError(SqlQueryException $exception)