Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
logtag.php
1
<?php
8
namespace
Bitrix\Socialnetwork
;
9
10
use
Bitrix\Main\Entity
;
11
28
class
LogTagTable
extends
Entity\DataManager
29
{
30
const
ITEM_TYPE_LOG
=
'L'
;
31
const
ITEM_TYPE_COMMENT
=
'LC'
;
32
33
public
static
function
getTableName
()
34
{
35
return
'b_sonet_log_tag'
;
36
}
37
38
public
static
function
getItemTypes
()
39
{
40
return
array(
41
self::ITEM_TYPE_LOG,
42
self::ITEM_TYPE_COMMENT
43
);
44
}
45
46
public
static
function
getMap
()
47
{
48
return
array(
49
'LOG_ID'
=> array(
50
'data_type'
=>
'integer'
,
51
),
52
'LOG'
=> array(
53
'data_type'
=>
'\Bitrix\Socialnetwork\Log'
,
54
'reference'
=> array(
'=this.LOG_ID'
=>
'ref.ID'
)
55
),
56
'ITEM_TYPE'
=> array(
57
'data_type'
=>
'string'
,
58
'primary'
=>
true
,
59
),
60
'ITEM_ID'
=> array(
61
'data_type'
=>
'string'
,
62
'primary'
=>
true
,
63
),
64
'NAME'
=> array(
65
'data_type'
=>
'string'
,
66
'primary'
=>
true
67
)
68
);
69
}
70
71
public
static
function
deleteByLogId
($params = array())
72
{
73
if
(
74
!is_array($params)
75
|| empty($params[
'logId'
])
76
|| intval($params[
'logId'
]) <= 0
77
)
78
{
79
return
false
;
80
}
81
82
\Bitrix\Main\Application::getConnection()->queryExecute(
'DELETE FROM '
.self::getTableName().
' WHERE LOG_ID = '
.intval($params[
'logId'
]));
83
return
true
;
84
}
85
86
public
static
function
deleteByItem
($params = array())
87
{
88
if
(
89
!is_array($params)
90
|| empty($params[
'itemId'
])
91
|| intval($params[
'itemId'
]) <= 0
92
)
93
{
94
return
false
;
95
}
96
97
if
(
98
empty($params[
'itemType'
])
99
|| !in_array($params[
'itemType'
], self::getItemTypes())
100
)
101
{
102
$params[
'itemType'
] =
self::ITEM_TYPE_LOG
;
103
}
104
105
\Bitrix\Main\Application::getConnection()->queryExecute(
'DELETE FROM '
.self::getTableName().
' WHERE ITEM_TYPE = \''
.$params[
'itemType'
].
'\'
AND ITEM_ID =
'.intval($params['
itemId
']));
106
return true;
107
}
108
109
public static function set($params = array())
110
{
111
if (
112
!is_array($params)
113
|| empty($params['
itemId
'])
114
|| intval($params['
itemId
']) <= 0
115
|| !isset($params['
tags
'])
116
|| !is_array($params['
tags
'])
117
)
118
{
119
return false;
120
}
121
122
if (
123
empty($params['
itemType
'])
124
|| !in_array($params['
itemType
'], self::getItemTypes())
125
)
126
{
127
$params['
itemType
'] = self::ITEM_TYPE_LOG;
128
}
129
130
if ($params['
itemType
'] == self::ITEM_TYPE_LOG)
131
{
132
$params['
logId
'] = intval($params['
itemId
']);
133
}
134
elseif (
135
empty($params['
logId
'])
136
|| intval($params['
logId
']) <= 0
137
)
138
{
139
$res = LogCommentTable::getList(array(
140
'
filter
' => array(
141
'
ID
' => intval($params['
itemId
'])
142
),
143
'
select
' => array('
LOG_ID
')
144
));
145
if ($logEntry = $res->fetch())
146
{
147
$params['
logId
'] = intval($logEntry['
LOG_ID
']);
148
}
149
}
150
151
if (
152
empty($params['
logId
'])
153
|| intval($params['
logId
']) <= 0
154
)
155
{
156
return false;
157
}
158
159
self::deleteByItem(array(
160
'
itemType
' => $params['
itemType
'],
161
'
itemId
' => intval($params['
itemId
'])
162
));
163
164
$addedLowerCaseTagsList = [];
165
166
foreach($params['
tags
'] as $tag)
167
{
168
$lowerCaseTag = toLower($tag);
169
if (in_array($lowerCaseTag, $addedLowerCaseTagsList))
170
{
171
continue;
172
}
173
self::add(array(
174
'
ITEM_TYPE
' => $params['
itemType
'],
175
'
ITEM_ID
' => intval($params['
itemId
']),
176
'
LOG_ID
' => intval($params['
logId
']),
177
'
NAME
' => $tag
178
));
179
$addedLowerCaseTagsList[] = $lowerCaseTag; // index requirement;
180
}
181
182
return true;
183
}
184
}
Bitrix\Main\ORM\Entity
Definition
entity.php:26
Bitrix\Socialnetwork\LogTagTable
Definition
logtag.php:29
Bitrix\Socialnetwork\LogTagTable\getItemTypes
static getItemTypes()
Definition
logtag.php:38
Bitrix\Socialnetwork\LogTagTable\deleteByLogId
static deleteByLogId($params=array())
Definition
logtag.php:71
Bitrix\Socialnetwork\LogTagTable\getMap
static getMap()
Definition
logtag.php:46
Bitrix\Socialnetwork\LogTagTable\ITEM_TYPE_COMMENT
const ITEM_TYPE_COMMENT
Definition
logtag.php:31
Bitrix\Socialnetwork\LogTagTable\ITEM_TYPE_LOG
const ITEM_TYPE_LOG
Definition
logtag.php:30
Bitrix\Socialnetwork\LogTagTable\deleteByItem
static deleteByItem($params=array())
Definition
logtag.php:86
Bitrix\Socialnetwork\LogTagTable\getTableName
static getTableName()
Definition
logtag.php:33
Bitrix\Socialnetwork
modules
socialnetwork
lib
logtag.php
Создано системой
1.10.0