Proyectos de Subversion LeadersLinked - Services

Rev

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

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