Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
dailycounter.php
1<?php
9
13
31class DailyCounterTable extends Entity\DataManager
32{
38 public static function getTableName()
39 {
40 return 'b_sender_counter_daily';
41 }
42
48 public static function getMap()
49 {
50 return array(
51 'DATE_STAT' => array(
52 'data_type' => 'date',
53 'primary' => true,
54 ),
55 'SENT_CNT' => array(
56 'data_type' => 'integer',
57 'default_value' => 0,
58 ),
59 'TEST_SENT_CNT' => array(
60 'data_type' => 'integer',
61 'default_value' => 0,
62 ),
63 'ERROR_CNT' => array(
64 'data_type' => 'integer',
65 'default_value' => 0,
66 ),
67 'ABUSE_CNT' => array(
68 'data_type' => 'integer',
69 'default_value' => 0,
70 ),
71 );
72 }
73
81 public static function mergeData(array $insert, array $update)
82 {
83 $entity = static::getEntity();
84 $connection = $entity->getConnection();
85 $helper = $connection->getSqlHelper();
86
87 $sql = $helper->prepareMerge($entity->getDBTableName(), $entity->getPrimaryArray(), $insert, $update);
88
89 $sql = current($sql);
90 if($sql <> '')
91 {
92 $connection->queryExecute($sql);
93 $entity->cleanCache();
94 }
95 }
96
104 public static function incrementFieldValue($fieldName, $increment = 1)
105 {
106 if (!array_key_exists($fieldName, static::getMap()))
107 {
108 return;
109 }
110
111 $insert = array(
112 "DATE_STAT" => new Type\Date(),
113 $fieldName => $increment,
114 );
115
116
117 $update = array(
118 $fieldName => new DB\SqlExpression("?# + ?i", $fieldName, $increment),
119 );
120
121 static::mergeData($insert, $update);
122 }
123
130 public static function getCurrentFieldValue($fieldName)
131 {
132 if (!array_key_exists($fieldName, static::getMap()))
133 {
134 return 0;
135 }
136
137 $result = static::getRowByDate();
138 return ($result && isset($result[$fieldName])) ? (int) $result[$fieldName] : 0;
139 }
140
147 public static function getRowByDate($daysLeft = 0)
148 {
149 $date = new Type\Date;
150 if ($daysLeft)
151 {
152 $date->add("-$daysLeft day");
153 }
154
155 return static::getRow(array(
156 "filter" => array("=DATE_STAT" => $date),
157 "cache" => array("ttl" => 60)
158 ));
159 }
160}
add($interval)
Definition date.php:145
static incrementFieldValue($fieldName, $increment=1)
static mergeData(array $insert, array $update)