0ce702fa79b2e6546edd4b580e0bb5486f0e78b8
[Packages/TYPO3.CMS.git] / typo3 / sysext / beuser / Classes / Domain / Repository / BackendUserSessionRepository.php
1 <?php
2 namespace TYPO3\CMS\Beuser\Domain\Repository;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2012-2013 Felix Kopp <felix-source@phorax.com>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the text file GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 * This script is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * This copyright notice MUST APPEAR in all copies of the script!
27 ***************************************************************/
28
29 /**
30 * Repository for Tx_Beuser_Domain_Model_BackendUser
31 *
32 * @author Felix Kopp <felix-source@phorax.com>
33 */
34 class BackendUserSessionRepository extends \TYPO3\CMS\Extbase\Persistence\Repository {
35
36 /**
37 * Find Sessions for specific BackendUser
38 * Delivers an Array, not an ObjectStorage!
39 *
40 * @param \TYPO3\CMS\Beuser\Domain\Model\BackendUser $backendUser
41 * @return array
42 */
43 public function findByBackendUser(\TYPO3\CMS\Beuser\Domain\Model\BackendUser $backendUser) {
44 $sessions = array();
45 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
46 'ses_id AS id, ses_iplock AS ip, ses_tstamp AS timestamp',
47 'be_sessions',
48 'ses_userid = "' . (int)$backendUser->getUid() . '"',
49 '',
50 'ses_tstamp ASC'
51 );
52 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
53 $sessions[] = array(
54 'id' => $row['id'],
55 'ip' => $row['ip'],
56 'timestamp' => new \DateTime('@' . $row['timestamp'])
57 );
58 }
59 $GLOBALS['TYPO3_DB']->sql_free_result($res);
60 return $sessions;
61 }
62
63 }