Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
counter.php
1<?php
2
4
8
9
27class CounterTable extends Entity\DataManager
28{
34 public static function getTableName()
35 {
36 return 'b_sender_counter';
37 }
38
44 public static function getMap()
45 {
46 return [
47 'CODE' =>[
48 'data_type' => 'string',
49 'primary' => true,
50 'required' => true,
51 ],
52 'VALUE' => [
53 'data_type' => 'integer',
54 'required' => false
55 ],
56 'DATE_UPDATE' => array(
57 'data_type' => 'datetime',
58 'default_value' => new DateTime(),
59 ),
60 ];
61 }
62
70 public static function mergeData(array $insert, array $update)
71 {
72 $entity = static::getEntity();
73 $connection = $entity->getConnection();
74 $helper = $connection->getSqlHelper();
75
76 $sql = $helper->prepareMerge($entity->getDBTableName(), $entity->getPrimaryArray(), $insert, $update);
77
78 $sql = current($sql);
79 if($sql <> '')
80 {
81 $connection->queryExecute($sql);
82 $entity->cleanCache();
83 }
84 }
85
93 public static function incrementByCode($code, $increment = 1)
94 {
95 $date = new DateTime();
96 $insert = ['CODE' => $code, 'VALUE' => $increment, 'DATE_UPDATE' => $date];
97 $update = [
98 'VALUE' => new DB\SqlExpression("?# + ?i", 'VALUE', $increment),
99 'DATE_UPDATE' => $date
100 ];
101
102 static::mergeData($insert, $update);
103 }
104
111 public static function getValueByCode($code)
112 {
113 $row = static::getRow(['filter' => ['=CODE' => $code], 'cache' => ['ttl' => 36000]]);
114 return intval($row ? $row['VALUE'] : 0);
115 }
116
123 public static function resetValueByCode($code)
124 {
125 return static::delete(['CODE' => $code])->isSuccess();
126 }
127}
static incrementByCode($code, $increment=1)
Definition counter.php:93
static mergeData(array $insert, array $update)
Definition counter.php:70