Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 7300 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
7244 efrain 1
<?php
2
declare(strict_types=1);
3
 
4
namespace LeadersLinked\Mapper;
5
 
6
use LeadersLinked\Mapper\Common\MapperCommon;
7
use Laminas\Db\Adapter\AdapterInterface;
8
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
9
use Laminas\Paginator\Paginator;
10
use Laminas\Db\ResultSet\HydratingResultSet;
11
use Laminas\Paginator\Adapter\DbSelect;
12
use LeadersLinked\Model\SurveyCampaign;
13
 
14
 
15
class SurveyCampaignMapper extends MapperCommon
16
{
17
    const _TABLE = 'tbl_survey_campaigns';
18
 
19
    /**
20
     *
21
     * @var SurveyCampaignMapper
22
     */
23
    private static $_instance;
24
 
25
    /**
26
     *
27
     * @param AdapterInterface $adapter
28
     */
29
    private function __construct($adapter)
30
    {
31
        parent::__construct($adapter);
32
    }
33
 
34
    /**
35
     *
36
     * @param AdapterInterface $adapter
37
     * @return SurveyCampaignMapper
38
     */
39
    public static function getInstance($adapter)
40
    {
41
        if(self::$_instance == null) {
42
            self::$_instance = new SurveyCampaignMapper($adapter);
43
        }
44
        return self::$_instance;
45
    }
46
 
47
    /**
48
     *
49
     * @param int $id
50
     * @return SurveyCampaign
51
     */
52
    public function fetchOne($id)
53
    {
54
        $prototype = new SurveyCampaign();
55
 
56
        $select = $this->sql->select(self::_TABLE);
57
        $select->where->equalTo('id', $id);
58
 
59
        return $this->executeFetchOneObject($select, $prototype);
60
    }
61
 
62
 
63
    /**
64
     *
65
     * @param int $uuid
66
     * @return SurveyCampaign
67
     */
68
    public function fetchOneByUuid($uuid)
69
    {
70
        $prototype = new SurveyCampaign();
71
        $select = $this->sql->select(self::_TABLE);
72
        $select->where->equalTo('uuid', $uuid);
73
       // echo $select->getSqlString($this->adapter->platform); exit;
74
        return $this->executeFetchOneObject($select, $prototype);
75
    }
76
 
77
 
78
    /**
79
     *
80
     * @param int $company_id
81
     * @return SurveyCampaign
82
     */
83
    public function fetchAllByCompanyId($company_id)
84
    {
85
        $prototype = new SurveyCampaign();
86
 
87
        $select = $this->sql->select(self::_TABLE);
88
        $select->where->equalTo('company_id', $company_id);
89
        $select->where->equalTo('status', SurveyCampaign::STATUS_ACTIVE);
90
        $select->order('id');
91
 
92
        return $this->executeFetchAllObject($select, $prototype);
93
    }
7328 efrain 94
 
7244 efrain 95
 
96
 
97
    /**
98
     *
99
     * @param SurveyCampaign $record
100
     * @return boolean
101
     */
102
    public function insert($record)
103
    {
104
        $hydrator = new ObjectPropertyHydrator();
105
        $values = $hydrator->extract($record);
106
        $values = $this->removeEmpty($values);
107
 
108
        $insert = $this->sql->insert(self::_TABLE);
109
        $insert->values($values);
110
 
111
        //echo $insert->getSqlString($this->adapter->platform); exit;
112
 
113
        $result = $this->executeInsert($insert);
114
        if($result) {
115
            $record->id = $this->lastInsertId;
116
        }
117
        return $result;
118
    }
119
 
120
    /**
121
     *
122
     * @param SurveyCampaign $record
123
     * @return boolean
124
     */
125
    public function update($record)
126
    {
127
        $hydrator = new ObjectPropertyHydrator();
128
        $values = $hydrator->extract($record);
129
        $values = $this->removeEmpty($values);
130
 
131
        $update = $this->sql->update(self::_TABLE);
132
        $update->set($values);
133
        $update->where->equalTo('id', $record->id);
134
 
135
        return $this->executeUpdate($update);
136
    }
137
 
138
    /**
139
     *
140
     * @param int $id
141
     * @return boolean
142
     */
143
    public function delete($id)
144
    {
145
        $delete = $this->sql->delete(self::_TABLE);
146
        $delete->where->equalTo('id', $id);
147
 
148
        return $this->executeDelete($delete);
149
    }
150
 
151
 
7300 efrain 152
 
7244 efrain 153
    /**
154
     *
155
     * @param int $companyId
156
     * @param string $search
157
     * @param int $page
158
     * @param int $records_per_page
159
     * @param string $order_field
160
     * @param string $order_direction
161
     * @return Paginator
162
     */
7300 efrain 163
    public function fetchAllDataTableNormalByCompanyId($companyId, $search, $page = 1, $records_per_page = 10, $order_field= 'name', $order_direction = 'ASC')
7244 efrain 164
    {
165
        $prototype = new SurveyCampaign();
166
        $select = $this->sql->select(self::_TABLE);
167
        $select->where->equalTo('company_id', $companyId);
7300 efrain 168
        $select->where->equalTo('type', SurveyCampaign::TYPE_NORMAL);
7244 efrain 169
 
170
        if($search) {
171
            $select->where->like('name', '%' . $search . '%');
172
        }
173
        $select->order($order_field . ' ' . $order_direction);
174
 
175
        //echo $select->getSqlString($this->adapter->platform); exit;
176
 
177
        $hydrator   = new ObjectPropertyHydrator();
178
        $resultset  = new HydratingResultSet($hydrator, $prototype);
179
 
180
        $adapter = new DbSelect($select, $this->sql, $resultset);
181
        $paginator = new Paginator($adapter);
182
        $paginator->setItemCountPerPage($records_per_page);
183
        $paginator->setCurrentPageNumber($page);
184
 
185
 
186
        return $paginator;
187
    }
7300 efrain 188
 
189
    /**
190
     *
191
     * @param int $companyId
192
     * @param string $search
193
     * @param int $page
194
     * @param int $records_per_page
195
     * @param string $order_field
196
     * @param string $order_direction
197
     * @return Paginator
198
     */
199
    public function  fetchAllDataTableOrganizationClimateByCompanyId($companyId, $search, $page = 1, $records_per_page = 10, $order_field= 'name', $order_direction = 'ASC')
200
    {
201
        $prototype = new SurveyCampaign();
202
        $select = $this->sql->select(self::_TABLE);
203
        $select->where->equalTo('company_id', $companyId);
204
        $select->where->equalTo('type', SurveyCampaign::TYPE_ORGANIZATIONAL_CLIMATE);
205
 
206
        if($search) {
207
            $select->where->like('name', '%' . $search . '%');
208
        }
209
        $select->order($order_field . ' ' . $order_direction);
210
 
211
        //echo $select->getSqlString($this->adapter->platform); exit;
212
 
213
        $hydrator   = new ObjectPropertyHydrator();
214
        $resultset  = new HydratingResultSet($hydrator, $prototype);
215
 
216
        $adapter = new DbSelect($select, $this->sql, $resultset);
217
        $paginator = new Paginator($adapter);
218
        $paginator->setItemCountPerPage($records_per_page);
219
        $paginator->setCurrentPageNumber($page);
220
 
221
 
222
        return $paginator;
223
    }
7244 efrain 224
 
225
 
226
}