Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 7016 | Ir a la última revisión | | 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
    /**
7016 efrain 105
     *
106
     * @param int $company_id
107
     * @param int $goal_id
108
     * @return PlanningTask[]
109
     */
110
    public function fetchAllByCompanyIdAndGoalId($company_id, $goal_id)
6749 efrain 111
    {
112
        $prototype = new PlanningTask();
113
        $select = $this->sql->select(self::_TABLE);
7016 efrain 114
        $select->where->equalTo('company_id', $company_id);
115
        $select->where->equalTo('goal_id', $goal_id);
116
        $select->order('title');
117
 
6749 efrain 118
        return $this->executeFetchAllObject($select, $prototype);
119
 
120
    }
7016 efrain 121
 
122
    /**
123
     *
124
     * @param int $company_id
125
     * @param int $goal_id
126
     * @return PlanningTask[]
127
     */
128
    public function fetchAllActiveByCompanyIdAndGoalId($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->where->equalTo('status', PlanningTask::STATUS_ACTIVE);
135
        $select->order('title');
136
 
137
        return $this->executeFetchAllObject($select, $prototype);
138
 
139
    }
140
 
6749 efrain 141
 
7016 efrain 142
    /**
143
     *
144
     * @param PlanningTask $record
145
     * @return boolean
146
     */
147
    public function insert($record)
6749 efrain 148
    {
149
        $hydrator = new ObjectPropertyHydrator();
7016 efrain 150
        $values = $hydrator->extract($record);
6749 efrain 151
        $values = $this->removeEmpty($values);
7016 efrain 152
 
153
        $values['urgent'] = empty($values['urgent']) ? PlanningTask::NO : $values['urgent'];
154
        $values['priority'] = empty($values['priority']) ? PlanningTask::NO : $values['priority'];
155
        $values['cost'] = empty($values['cost']) ? 0 : $values['cost'];
156
        $values['progress'] = empty($values['progress']) ? 0 : $values['progress'];
157
 
158
 
6749 efrain 159
        $insert = $this->sql->insert(self::_TABLE);
160
        $insert->values($values);
161
 
162
 
163
        $result = $this->executeInsert($insert);
164
        if($result) {
7016 efrain 165
            $record->id = $this->lastInsertId;
6749 efrain 166
        }
167
 
168
        return $result;
169
 
170
    }
171
 
7016 efrain 172
    /**
173
     *
174
     * @param PlanningTask $record
175
     * @return boolean
176
     */
177
    public function update($record)
6749 efrain 178
    {
179
        $hydrator = new ObjectPropertyHydrator();
7016 efrain 180
        $values = $hydrator->extract($record);
6749 efrain 181
        $values = $this->removeEmpty($values);
182
 
7016 efrain 183
 
184
        $values['urgent'] = empty($values['urgent']) ? PlanningTask::NO : $values['urgent'];
185
        $values['priority'] = empty($values['priority']) ? PlanningTask::NO : $values['priority'];
186
        $values['cost'] = empty($values['cost']) ? 0 : $values['cost'];
187
        $values['progress'] = empty($values['progress']) ? 0 : $values['progress'];
188
 
6749 efrain 189
        $update = $this->sql->update(self::_TABLE);
190
        $update->set($values);
7016 efrain 191
        $update->where->equalTo('id', $record->id);
192
 
6749 efrain 193
        return $this->executeUpdate($update);
194
    }
195
 
7016 efrain 196
    /**
197
     *
198
     * @param PlanningTask $record
199
     * @return boolean
200
     */
201
    public function delete($record)
6749 efrain 202
    {
203
        $delete = $this->sql->delete(self::_TABLE);
7016 efrain 204
        $delete->where->equalTo('id', $record->id);
6749 efrain 205
 
206
        return $this->executeDelete($delete);
207
    }
208
 
7016 efrain 209
    /**
210
     *
211
     * @param string $uuid
212
     * @return PlanningTask
213
     */
6749 efrain 214
    public function fetchOneByUuid($uuid)
215
    {
216
        $prototype = new PlanningTask();
217
        $select = $this->sql->select(self::_TABLE);
218
        $select->where->equalTo('uuid', $uuid);
219
 
220
        return $this->executeFetchOneObject($select, $prototype);
221
    }
222
 
223
 
224
 
225
}