Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 1 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 www 1
<?php
2
declare(strict_types=1);
3
 
4
namespace LeadersLinked\Mapper;
5
 
6
use Laminas\Db\Adapter\AdapterInterface;
7
use Laminas\Db\ResultSet\HydratingResultSet;
8
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
9
use Laminas\Paginator\Paginator;
10
use Laminas\Paginator\Adapter\DbSelect;
11
 
12
use LeadersLinked\Model\PushTemplate;
13
use LeadersLinked\Mapper\Common\MapperCommon;
14
 
15
class PushTemplateMapper extends MapperCommon
16
{
17
    const _TABLE = 'tbl_push_templates';
18
 
19
 
20
    /**
21
     *
22
     * @var PushTemplateMapper
23
     */
24
    private static $_instance;
25
 
26
    /**
27
     *
28
     * @param AdapterInterface $adapter
29
     */
30
    private function __construct($adapter)
31
    {
32
        parent::__construct($adapter);
33
    }
34
 
35
    /**
36
     *
37
     * @param AdapterInterface $adapter
38
     * @return \LeadersLinked\Mapper\PushTemplateMapper
39
     */
40
    public static function getInstance($adapter)
41
    {
42
        if(self::$_instance == null) {
43
            self::$_instance = new PushTemplateMapper($adapter);
44
        }
45
        return self::$_instance;
46
    }
47
 
48
    /**
49
     *
50
     * @param int $id
51
     * @return  PushTemplate
52
     */
53
    public function fetchOne($id)
54
    {
55
        $prototype = new PushTemplate();
56
        $select = $this->sql->select(self::_TABLE);
57
        $select->where->equalTo('id', $id);
58
        $select->limit(1);
59
 
60
        return $this->executeFetchOneObject($select, $prototype);
61
    }
62
 
63
    /**
64
     *
65
     * @param string $uuid
66
     * @return  PushTemplate
67
     */
68
    public function fetchOneByUuid($uuid)
69
    {
70
        $prototype = new PushTemplate();
71
        $select = $this->sql->select(self::_TABLE);
72
        $select->where->equalTo('uuid', $uuid);
73
        $select->limit(1);
74
 
75
        return $this->executeFetchOneObject($select, $prototype);
76
    }
77
 
78
    /**
79
     *
80
     * @param string $type
81
     * @return  PushTemplate[]
82
     */
83
    public function fetchAllActiveByType($type)
84
    {
85
        $prototype = new PushTemplate();
86
        $select = $this->sql->select(self::_TABLE);
87
        $select->where->equalTo('status', PushTemplate::STATUS_ACTIVE);
88
        $select->where->equalTo('type', $type);
89
        $select->limit(1);
90
 
91
        return $this->executeFetchAllObject($select, $prototype);
92
    }
3639 efrain 93
 
1 www 94
 
95
    /**
96
     *
3639 efrain 97
 
98
     * @return  PushTemplate[]
99
     */
100
    public function fetchAllDefault()
101
    {
102
        $prototype = new PushTemplate();
103
        $select = $this->sql->select(self::_TABLE);
104
        $select->where->isNull('push_template_default_id');
105
        $select->limit(1);
106
 
107
        return $this->executeFetchAllObject($select, $prototype);
108
    }
109
 
110
 
111
 
112
 
113
    /**
114
     *
1 www 115
     * @param string $search
116
     * @param int $page
117
     * @param int $records_per_page
118
     * @param string $order_field
119
     * @param string $order_direction
120
     * @return Paginator
121
     */
122
    public function fetchAllDataTable($search, $page = 1, $records_per_page = 10, $order_field= 'title', $order_direction = 'ASC')
123
    {
124
        $prototype = new PushTemplate();
125
        $select = $this->sql->select(self::_TABLE);
126
 
127
        if($search) {
128
            $select->where->like('id', '%' . $search . '%')->or->like('title', '%' . $search . '%');
129
        }
130
        $select->order($order_field . ' ' . $order_direction);
131
 
132
        $hydrator   = new ObjectPropertyHydrator();
133
        $resultset  = new HydratingResultSet($hydrator, $prototype);
134
 
135
        $adapter = new DbSelect($select, $this->sql, $resultset);
136
        $paginator = new Paginator($adapter);
137
        $paginator->setItemCountPerPage($records_per_page);
138
        $paginator->setCurrentPageNumber($page);
139
 
140
 
141
        return $paginator;
142
    }
143
 
144
 
145
    /**
146
     *
147
     * @param PushTemplate $pushTemplate
148
     * @return boolean
149
     */
150
    public function update($pushTemplate)
151
    {
152
        $hydrator = new ObjectPropertyHydrator();
153
        $values = $hydrator->extract($pushTemplate);
154
 
155
        $update = $this->sql->update(self::_TABLE);
156
        $update->set($values);
157
        $update->where->equalTo('id', $pushTemplate->id);
158
 
159
        return $this->executeUpdate($update);
160
    }
161
 
162
 
163
 
164
    /**
165
     *
166
     * @return boolean
167
     */
168
    public function truncate()
169
    {
170
        $sql = sprintf('TRUNCATE TABLE `%s` ', self::_TABLE);
171
        return $this->executeSentenceWithParameters($sql);
172
    }
173
 
174
}