Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

Rev Autor Línea Nro. Línea
6749 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
 
7016 efrain 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')
6749 efrain 61
    {
62
        $prototype = new PlanningTask();
63
        $select = $this->sql->select(self::_TABLE);
7016 efrain 64
        $select->where->equalTo('company_id', $goal_id);
6749 efrain 65
        $select->where->equalTo('goal_id', $goal_id);
7016 efrain 66
 
6749 efrain 67
 
68
 
69
        if($search) {
70
            $select->where->like('title', '%' . $search . '%');
71
        }
72
        $select->order($order_field . ' ' . $order_direction);
73
 
74
 
75
 
76
        $hydrator   = new ObjectPropertyHydrator();
77
        $resultset  = new HydratingResultSet($hydrator, $prototype);
78
 
79
        $adapter = new DbSelect($select, $this->sql, $resultset);
80
        $paginator = new Paginator($adapter);
81
        $paginator->setItemCountPerPage($records_per_page);
82
        $paginator->setCurrentPageNumber($page);
83
 
84
 
85
        return $paginator;
86
    }
7016 efrain 87
 
88
    /**
7047 efrain 89
     *
90
     * @param int $goal_id
91
     * @return PlanningTask[]
92
     */
93
    public function fetchAllByGoalId($goal_id)
94
    {
95
        $prototype = new PlanningTask();
96
        $select = $this->sql->select(self::_TABLE);
97
        $select->where->equalTo('goal_id', $goal_id);
98
        $select->order('title');
99
 
100
        return $this->executeFetchAllObject($select, $prototype);
101
    }
102
 
103
 
104
    /**
7083 efrain 105
     *
106
     * @param int $objective_id
107
     * @return PlanningTask[]
108
     */
109
    public function fetchAllByObjectiveId($objective_id)
110
    {
111
        $prototype = new PlanningTask();
112
        $select = $this->sql->select(self::_TABLE);
113
        $select->where->equalTo('goal_id', $objective_id);
114
        $select->order('title');
115
 
116
        return $this->executeFetchAllObject($select, $prototype);
117
    }
118
 
119
 
120
    /**
7016 efrain 121
     *
122
     * @param int $company_id
123
     * @param int $goal_id
124
     * @return PlanningTask[]
125
     */
126
    public function fetchAllByCompanyIdAndGoalId($company_id, $goal_id)
6749 efrain 127
    {
128
        $prototype = new PlanningTask();
129
        $select = $this->sql->select(self::_TABLE);
7016 efrain 130
        $select->where->equalTo('company_id', $company_id);
131
        $select->where->equalTo('goal_id', $goal_id);
132
        $select->order('title');
133
 
6749 efrain 134
        return $this->executeFetchAllObject($select, $prototype);
135
 
136
    }
7016 efrain 137
 
138
    /**
139
     *
140
     * @param int $company_id
141
     * @param int $goal_id
142
     * @return PlanningTask[]
143
     */
144
    public function fetchAllActiveByCompanyIdAndGoalId($company_id, $goal_id)
145
    {
146
        $prototype = new PlanningTask();
147
        $select = $this->sql->select(self::_TABLE);
148
        $select->where->equalTo('company_id', $company_id);
149
        $select->where->equalTo('goal_id', $goal_id);
150
        $select->where->equalTo('status', PlanningTask::STATUS_ACTIVE);
151
        $select->order('title');
152
 
153
        return $this->executeFetchAllObject($select, $prototype);
154
 
155
    }
156
 
6749 efrain 157
 
7016 efrain 158
    /**
159
     *
160
     * @param PlanningTask $record
161
     * @return boolean
162
     */
163
    public function insert($record)
6749 efrain 164
    {
165
        $hydrator = new ObjectPropertyHydrator();
7016 efrain 166
        $values = $hydrator->extract($record);
6749 efrain 167
        $values = $this->removeEmpty($values);
7016 efrain 168
 
169
        $values['urgent'] = empty($values['urgent']) ? PlanningTask::NO : $values['urgent'];
170
        $values['priority'] = empty($values['priority']) ? PlanningTask::NO : $values['priority'];
171
        $values['cost'] = empty($values['cost']) ? 0 : $values['cost'];
172
        $values['progress'] = empty($values['progress']) ? 0 : $values['progress'];
173
 
174
 
6749 efrain 175
        $insert = $this->sql->insert(self::_TABLE);
176
        $insert->values($values);
177
 
178
 
179
        $result = $this->executeInsert($insert);
180
        if($result) {
7016 efrain 181
            $record->id = $this->lastInsertId;
6749 efrain 182
        }
183
 
184
        return $result;
185
 
186
    }
187
 
7016 efrain 188
    /**
189
     *
190
     * @param PlanningTask $record
191
     * @return boolean
192
     */
193
    public function update($record)
6749 efrain 194
    {
195
        $hydrator = new ObjectPropertyHydrator();
7016 efrain 196
        $values = $hydrator->extract($record);
6749 efrain 197
        $values = $this->removeEmpty($values);
198
 
7016 efrain 199
 
200
        $values['urgent'] = empty($values['urgent']) ? PlanningTask::NO : $values['urgent'];
201
        $values['priority'] = empty($values['priority']) ? PlanningTask::NO : $values['priority'];
202
        $values['cost'] = empty($values['cost']) ? 0 : $values['cost'];
203
        $values['progress'] = empty($values['progress']) ? 0 : $values['progress'];
204
 
6749 efrain 205
        $update = $this->sql->update(self::_TABLE);
206
        $update->set($values);
7016 efrain 207
        $update->where->equalTo('id', $record->id);
208
 
6749 efrain 209
        return $this->executeUpdate($update);
210
    }
211
 
7016 efrain 212
    /**
213
     *
214
     * @param PlanningTask $record
215
     * @return boolean
216
     */
217
    public function delete($record)
6749 efrain 218
    {
219
        $delete = $this->sql->delete(self::_TABLE);
7016 efrain 220
        $delete->where->equalTo('id', $record->id);
6749 efrain 221
 
222
        return $this->executeDelete($delete);
223
    }
224
 
7016 efrain 225
    /**
226
     *
227
     * @param string $uuid
228
     * @return PlanningTask
229
     */
6749 efrain 230
    public function fetchOneByUuid($uuid)
231
    {
232
        $prototype = new PlanningTask();
233
        $select = $this->sql->select(self::_TABLE);
234
        $select->where->equalTo('uuid', $uuid);
235
 
236
        return $this->executeFetchOneObject($select, $prototype);
237
    }
238
 
239
 
240
 
241
}