Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 3639 | Ir a la última revisión | | 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
    }
93
 
94
    /**
95
     *
96
     * @param string $search
97
     * @param int $page
98
     * @param int $records_per_page
99
     * @param string $order_field
100
     * @param string $order_direction
101
     * @return Paginator
102
     */
103
    public function fetchAllDataTable($search, $page = 1, $records_per_page = 10, $order_field= 'title', $order_direction = 'ASC')
104
    {
105
        $prototype = new PushTemplate();
106
        $select = $this->sql->select(self::_TABLE);
107
 
108
        if($search) {
109
            $select->where->like('id', '%' . $search . '%')->or->like('title', '%' . $search . '%');
110
        }
111
        $select->order($order_field . ' ' . $order_direction);
112
 
113
        $hydrator   = new ObjectPropertyHydrator();
114
        $resultset  = new HydratingResultSet($hydrator, $prototype);
115
 
116
        $adapter = new DbSelect($select, $this->sql, $resultset);
117
        $paginator = new Paginator($adapter);
118
        $paginator->setItemCountPerPage($records_per_page);
119
        $paginator->setCurrentPageNumber($page);
120
 
121
 
122
        return $paginator;
123
    }
124
 
125
 
126
    /**
127
     *
128
     * @param PushTemplate $pushTemplate
129
     * @return boolean
130
     */
131
    public function update($pushTemplate)
132
    {
133
        $hydrator = new ObjectPropertyHydrator();
134
        $values = $hydrator->extract($pushTemplate);
135
 
136
        $update = $this->sql->update(self::_TABLE);
137
        $update->set($values);
138
        $update->where->equalTo('id', $pushTemplate->id);
139
 
140
        return $this->executeUpdate($update);
141
    }
142
 
143
 
144
 
145
    /**
146
     *
147
     * @return boolean
148
     */
149
    public function truncate()
150
    {
151
        $sql = sprintf('TRUNCATE TABLE `%s` ', self::_TABLE);
152
        return $this->executeSentenceWithParameters($sql);
153
    }
154
 
155
}