Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AdminSessionInfo.php
Go to the documentation of this file.
1 <?php
8 
16 {
21  protected $dateTime;
22 
28  public function __construct(
29  \Magento\Framework\Model\ResourceModel\Db\Context $context,
30  \Magento\Framework\Stdlib\DateTime $dateTime,
31  $connectionName = null
32  ) {
33  parent::__construct($context, $connectionName);
34  $this->dateTime = $dateTime;
35  }
36 
43  protected function _construct()
44  {
45  $this->_init('admin_user_session', 'id');
46  }
47 
56  public function deleteSessionsOlderThen($timestamp)
57  {
58  $this->getConnection()->delete(
59  $this->getMainTable(),
60  ['updated_at < ?' => $this->dateTime->formatDate($timestamp)]
61  );
62 
63  return $this;
64  }
65 
78  public function updateStatusByUserId(
79  $status,
80  $userId,
81  array $withStatuses = [],
82  array $excludedSessionIds = [],
83  $updateOlderThen = null
84  ) {
85  $whereStatement = [
86  'updated_at > ?' => $this->dateTime->formatDate($updateOlderThen),
87  'user_id = ?' => (int) $userId,
88  ];
89  if (!empty($excludedSessionIds)) {
90  $whereStatement['session_id NOT IN (?)'] = $excludedSessionIds;
91  }
92  if (!empty($withStatuses)) {
93  $whereStatement['status IN (?)'] = $withStatuses;
94  }
95 
96  return $this->getConnection()->update(
97  $this->getMainTable(),
98  ['status' => (int) $status],
99  $whereStatement
100  );
101  }
102 }
$status
Definition: order_status.php:8
updateStatusByUserId( $status, $userId, array $withStatuses=[], array $excludedSessionIds=[], $updateOlderThen=null)
__construct(\Magento\Framework\Model\ResourceModel\Db\Context $context, \Magento\Framework\Stdlib\DateTime $dateTime, $connectionName=null)