Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
logsubscribe.php
1<?php
9
12
29class LogSubscribeTable extends Entity\DataManager
30{
32 const TTL = 1209600; //60*60*24*14
33
34 private static function getTypes()
35 {
36 return array(
37 self::TYPE_COUNTER_COMMENT_PUSH
38 );
39 }
40
41 public static function getTableName()
42 {
43 return 'b_sonet_log_subscribe';
44 }
45
46 public static function getMap()
47 {
48 $fieldsMap = array(
49 'USER_ID' => array(
50 'data_type' => 'integer',
51 'primary' => true
52 ),
53 'LOG_ID' => array(
54 'data_type' => 'integer',
55 'primary' => true
56 ),
57 'TYPE' => array(
58 'data_type' => 'string',
59 'primary' => true
60 ),
61 'END_DATE' => array(
62 'data_type' => 'datetime',
63 ),
64 );
65
66 return $fieldsMap;
67 }
68
69 public static function set($params = array())
70 {
71 $userId = (isset($params['userId']) ? intval($params['userId']) : 0);
72 $logId = (isset($params['logId']) ? intval($params['logId']) : 0);
73 $type = (isset($params['type']) ? $params['type'] : '');
74
75 if (
76 $userId <= 0
77 || $logId <= 0
78 )
79 {
80 return false;
81 }
82
83 if (is_array($type))
84 {
85 $typeList = $type;
86 foreach($typeList as $type)
87 {
88 $params['type'] = $type;
89 self::set($params);
90 }
91 return true;
92 }
93
94 if (!in_array($type, self::getTypes()))
95 {
96 return false;
97 }
98
99 $connection = Application::getConnection();
100 $helper = $connection->getSqlHelper();
101
102 $insertFields = array(
103 "USER_ID" => $userId,
104 "LOG_ID" => $logId,
105 "TYPE" => $helper->forSql($type),
106 );
107
108 $updateFields = array(
109 );
110
111 if (
112 isset($params['endDate'])
113 && $params['endDate'] instanceof \Bitrix\Main\Type\DateTime
114 )
115 {
116 $insertFields["END_DATE"] = $params['endDate'];
117 $updateFields["END_DATE"] = $params['endDate'];
118 }
119 elseif (!empty($params['ttl']))
120 {
121 $endDate = \Bitrix\Main\Type\DateTime::createFromTimestamp(time() + self::TTL);
122 $insertFields["END_DATE"] = $endDate;
123 $updateFields["END_DATE"] = $endDate;
124 }
125 else
126 {
127 $updateFields["END_DATE"] = false;
128 }
129
130 $merge = $helper->prepareMerge(
131 static::getTableName(),
132 array("USER_ID", "LOG_ID", "TYPE"),
133 $insertFields,
134 $updateFields
135 );
136
137 if ($merge[0] != "")
138 {
139 $connection->query($merge[0]);
140 }
141
142 return true;
143 }
144}
static getConnection($name="")