Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
19 / 19
100.00% covered (success)
100.00%
5 / 5
CRAP
100.00% covered (success)
100.00%
1 / 1
Session
100.00% covered (success)
100.00%
19 / 19
100.00% covered (success)
100.00%
5 / 5
5
100.00% covered (success)
100.00%
1 / 1
 getEntityMapping
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
 addConditionSessionId
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 addConditionSessionName
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 addConditionSessionDeleteInterval
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
1
 postProcess
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace BO\Zmsdb\Query;
4
5class Session extends Base
6{
7    /**
8     * @var String TABLE mysql table reference
9     */
10    const TABLE = 'sessiondata';
11
12    /**
13     * No resolving required here
14     */
15    protected $resolveLevel = 0;
16
17    const QUERY_WRITE = '
18        REPLACE INTO
19            sessiondata
20        SET
21            sessionid=?,
22            sessionname=?,
23            sessioncontent=?
24    ';
25
26    const QUERY_DELETE = '
27        DELETE FROM
28            sessiondata
29        WHERE
30            sessionid=? AND
31            sessionname=?
32    ';
33
34    public function getEntityMapping()
35    {
36        return [
37            'id' => 'session.sessionid',
38            'name' => 'session.sessionname',
39            'content' => 'session.sessioncontent'
40        ];
41    }
42
43    public function addConditionSessionId($sessionId)
44    {
45        $this->query->where('session.sessionid', '=', $sessionId);
46        return $this;
47    }
48
49    public function addConditionSessionName($sessionName)
50    {
51        $this->query->where('session.sessionname', '=', $sessionName);
52        return $this;
53    }
54
55    public function addConditionSessionDeleteInterval($deleteInSeconds)
56    {
57        $this->query->where(
58            self::expression(
59                'UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(`session`.`ts`)'
60            ),
61            '>=',
62            $deleteInSeconds
63        );
64        return $this;
65    }
66
67    /**
68     * postProcess data if necessary
69     *
70     */
71    public function postProcess($data)
72    {
73        $data[$this->getPrefixed('content')] = json_decode($data[$this->getPrefixed('content')], 1);
74        return $data;
75    }
76}