Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 www 1
<?php
2
 
3
declare(strict_types=1);
4
 
5
namespace LeadersLinked\Mapper;
6
 
7
 
8
use Laminas\Db\Adapter\AdapterInterface;
9
use Laminas\Db\ResultSet\HydratingResultSet;
10
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
11
use Laminas\Log\LoggerInterface;
12
use Laminas\Paginator\Paginator;
13
use Laminas\Paginator\Adapter\DbSelect;
14
 
15
use LeadersLinked\Model\Push;
16
use LeadersLinked\Mapper\Common\MapperCommon;
17
 
18
 
19
class PushMapper extends MapperCommon
20
{
21
    const _TABLE = 'tbl_pushes';
22
 
23
 
24
    /**
25
     *
26
     * @var PushMapper
27
     */
28
    private static $_instance;
29
 
30
    /**
31
     *
32
     * @param AdapterInterface $adapter
33
     */
34
    private function __construct($adapter)
35
    {
36
        parent::__construct($adapter);
37
    }
38
 
39
    /**
40
     *
41
     * @param AdapterInterface $adapter
42
     * @return \LeadersLinked\Mapper\PushMapper
43
     */
44
    public static function getInstance($adapter)
45
    {
46
        if(self::$_instance == null) {
47
            self::$_instance = new PushMapper($adapter);
48
        }
49
        return self::$_instance;
50
    }
51
 
52
    /**
53
     *
54
     * @param int $id
55
     * @return  Push
56
     */
57
    public function fetchOne($id)
58
    {
59
        $prototype = new Push();
60
        $select = $this->sql->select(self::_TABLE);
61
        $select->where->equalTo('id', $id);
62
        $select->limit(1);
63
 
64
        return $this->executeFetchOneObject($select, $prototype);
65
    }
66
 
67
    /**
68
     *
69
     * @return Push[]
70
     */
71
    public function fetchBatch($batchSize = 10)
72
    {
73
 
74
        $select = $this->sql->select(self::_TABLE);
75
        $select->where->equalTo('status', Push::STATUS_PENDING);
76
        $select->order('added_on ASC');
77
        $select->limit($batchSize);
78
 
79
        $prototype = new Push();
80
        return $this->executeFetchAllObject($select, $prototype);
81
    }
82
   /**
83
     *
84
     * @param Push $push
85
     * @return boolean
86
     */
87
    public function insert($push)
88
    {
89
        $hydrator = new ObjectPropertyHydrator();
90
        $values = $hydrator->extract($push);
91
        $values = $this->removeEmpty($values);
92
 
93
        $insert = $this->sql->insert(self::_TABLE);
94
        $insert->values($values);
95
 
96
        //echo $insert->getSqlString($this->adapter->platform); exit;
97
 
98
        $result = $this->executeInsert($insert);
99
        if($result) {
100
            $push->id = $this->lastInsertId;
101
        }
102
 
103
        return $result;
104
    }
105
 
106
    /**
107
     *
108
     * @param Push $push
109
     * @return boolean
110
     */
111
    public function update($push)
112
    {
113
        $hydrator = new ObjectPropertyHydrator();
114
        $values = $hydrator->extract($push);
115
 
116
        $update = $this->sql->update(self::_TABLE);
117
        $update->set($values);
118
        $update->where->equalTo('id', $push->id);
119
 
120
        return $this->executeUpdate($update);
121
    }
122
 
123
    /**
124
     *
125
     * @param Push $push
126
     * @return boolean
127
     */
128
    public function delete($push)
129
    {
130
        $delete = $this->sql->delete(self::_TABLE);
131
        $delete->where->equalTo('id', $push->id);
132
 
133
        return $this->executeDelete($delete);
134
 
135
    }
136
 
137
    /**
138
     *
139
     * @return boolean
140
     */
141
    public function deleteAll()
142
    {
143
        $delete = $this->sql->delete(self::_TABLE);
144
 
145
        return $this->executeDelete($delete);
146
    }
147
 
148
 
149
    /**
150
     *
151
     * @return boolean
152
     */
153
    public function truncate()
154
    {
155
        $sql = sprintf('TRUNCATE TABLE `%s` ', self::_TABLE);
156
        return $this->executeSentenceWithParameters($sql);
157
    }
158
 
159
}