%PDF- %PDF-
Direktori : /home/bitrix/www/bitrix/modules/messageservice/lib/internal/entity/ |
Current File : //home/bitrix/www/bitrix/modules/messageservice/lib/internal/entity/message.php |
<?php namespace Bitrix\MessageService\Internal\Entity; use Bitrix\Main\Application; use Bitrix\Main\Entity; use Bitrix\Main\Type; class MessageTable extends Entity\DataManager { /** * @return string */ public static function getTableName() { return 'b_messageservice_message'; } /** * @return array */ public static function getMap() { return array( 'ID' => array( 'data_type' => 'integer', 'primary' => true, 'autocomplete' => true, ), 'TYPE' => array( 'data_type' => 'string', 'required' => true, 'validation' => array(__CLASS__, 'validateVarchar30'), ), 'SENDER_ID' => array( 'data_type' => 'string', 'required' => true, 'validation' => array(__CLASS__, 'validateVarchar50'), ), 'AUTHOR_ID' => array( 'data_type' => 'integer', 'default_value' => 0, ), 'AUTHOR' => array( 'data_type' => '\Bitrix\Main\UserTable', 'reference' => array( '=this.AUTHOR_ID' => 'ref.ID' ), 'join_type' => 'LEFT', ), 'MESSAGE_FROM' => array( 'data_type' => 'string', 'required' => true, 'validation' => array(__CLASS__, 'validateVarchar260'), ), 'MESSAGE_TO' => array( 'data_type' => 'string', 'required' => true, 'validation' => array(__CLASS__, 'validateVarchar50'), ), 'MESSAGE_HEADERS' => array( 'data_type' => 'string', 'serialized' => true ), 'MESSAGE_BODY' => array( 'data_type' => 'string', 'required' => true ), 'DATE_INSERT' => array( 'data_type' => 'datetime', 'default_value' => new Type\DateTime(), ), 'DATE_EXEC' => array( 'data_type' => 'datetime' ), 'NEXT_EXEC' => array( 'data_type' => 'datetime' ), 'SUCCESS_EXEC' => array( 'data_type' => 'string', 'default_value' => 'N', ), 'EXEC_ERROR' => array( 'data_type' => 'string' ), 'STATUS_ID' => array( 'data_type' => 'integer' ), 'EXTERNAL_ID' => array( 'data_type' => 'string', 'validation' => array(__CLASS__, 'validateVarchar128'), ) ); } public static function getDailyCount($senderId, $fromId) { $connection = Application::getConnection(); $helper = $connection->getSqlHelper(); $today = date('Y-m-d') . ' 00:00:00'; $senderId = $helper->forSql((string)$senderId); $fromId = $helper->forSql((string)$fromId); $strSql = "SELECT COUNT(*) CNT FROM b_messageservice_message WHERE SUCCESS_EXEC = 'Y' AND DATE_EXEC >= '{$today}' AND SENDER_ID = '{$senderId}' AND MESSAGE_FROM = '{$fromId}'"; $result = $connection->query($strSql)->fetch(); return is_array($result) ? (int)$result['CNT'] : 0; } public static function getAllDailyCount() { $connection = Application::getConnection(); $today = date('Y-m-d') . ' 00:00:00'; $strSql = "SELECT SENDER_ID, MESSAGE_FROM, COUNT(*) CNT FROM b_messageservice_message WHERE SUCCESS_EXEC = 'Y' AND DATE_EXEC >= '{$today}' GROUP BY SENDER_ID, MESSAGE_FROM"; $result = $connection->query($strSql); $counts = array(); while ($row = $result->fetch()) { $id = $row['SENDER_ID'] .':'. $row['MESSAGE_FROM']; $counts[$id] = (int)$row['CNT']; } return $counts; } public static function returnDeferredToQueue($senderId, $fromId) { $connection = Application::getConnection(); $helper = $connection->getSqlHelper(); $senderId = $helper->forSql((string)$senderId); $fromId = $helper->forSql((string)$fromId); $strSql = "UPDATE b_messageservice_message SET NEXT_EXEC = NULL WHERE SUCCESS_EXEC = 'N' AND NEXT_EXEC IS NOT NULL AND SENDER_ID = '{$senderId}' AND MESSAGE_FROM = '{$fromId}'"; $connection->query($strSql); return true; } /** * @return array */ public static function validateVarchar50() { return array( new Entity\Validator\Length(null, 50), ); } /** * @return array */ public static function validateVarchar260() { return array( new Entity\Validator\Length(null, 260), ); } /** * @return array */ public static function validateVarchar30() { return array( new Entity\Validator\Length(null, 30), ); } /** * @return array */ public static function validateVarchar128() { return array( new Entity\Validator\Length(null, 128), ); } }