Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 539 | Rev 543 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 539 Rev 540
Línea 9... Línea 9...
9
use Laminas\Db\Sql\Expression;
9
use Laminas\Db\Sql\Expression;
10
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
10
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
11
use Laminas\Log\LoggerInterface;
11
use Laminas\Log\LoggerInterface;
12
use Laminas\Paginator\Paginator;
12
use Laminas\Paginator\Paginator;
13
use Laminas\Paginator\Adapter\DbSelect;
13
use Laminas\Paginator\Adapter\DbSelect;
14
 
-
 
15
use LeadersLinked\Model\JobDescription;
14
use LeadersLinked\Model\JobDescription;
16
use LeadersLinked\Mapper\Common\MapperCommon;
15
use LeadersLinked\Mapper\Common\MapperCommon;
17
use Laminas\Hydrator\ArraySerializableHydrator;
16
use Laminas\Hydrator\ArraySerializableHydrator;
Línea -... Línea 17...
-
 
17
 
Línea 18... Línea -...
18
 
-
 
19
 
-
 
20
 
-
 
21
class JobDescriptionMapper extends MapperCommon
18
class JobDescriptionMapper extends MapperCommon {
Línea 22... Línea -...
22
{
-
 
23
    const _TABLE = 'tbl_jobs_description';
19
 
24
 
20
    const _TABLE = 'tbl_jobs_description';
25
    
21
 
26
    /**
22
    /**
27
     *
23
     *
28
     * @var JobDescriptionMapper
24
     * @var JobDescriptionMapper
29
     */
25
     */
30
    private static $_instance;
26
    private static $_instance;
31
    
27
 
32
    /**
28
    /**
33
     *
29
     *
34
     * @param AdapterInterface $adapter
-
 
35
     */
30
     * @param AdapterInterface $adapter
36
    private function __construct($adapter)
31
     */
37
    {
32
    private function __construct($adapter) {
38
        parent::__construct($adapter);
33
        parent::__construct($adapter);
39
    }
34
    }
40
    
35
 
41
    /**
36
    /**
42
     *
37
     *
43
     * @param AdapterInterface $adapter
38
     * @param AdapterInterface $adapter
44
     * @return JobDescriptionMapper
-
 
45
     */
39
     * @return JobDescriptionMapper
46
    public static function getInstance($adapter)
40
     */
47
    {
41
    public static function getInstance($adapter) {
48
        if(self::$_instance == null) {
42
        if (self::$_instance == null) {
49
            self::$_instance = new JobDescriptionMapper($adapter);
43
            self::$_instance = new JobDescriptionMapper($adapter);
Línea 50... Línea -...
50
        }
-
 
51
        return self::$_instance;
44
        }
52
    }
45
        return self::$_instance;
53
 
46
    }
54
   
47
 
55
    /**
48
    /**
56
     *
49
     *
57
     * @param int $id
-
 
58
     * @return JobDescription
50
     * @param int $id
59
     */
51
     * @return JobDescription
60
    public function fetchOne($id)
52
     */
61
    {
53
    public function fetchOne($id) {
62
        $select = $this->sql->select(self::_TABLE);
54
        $select = $this->sql->select(self::_TABLE);
63
        $select->where->equalTo('id', $id);
55
        $select->where->equalTo('id', $id);
64
        $select->limit(1);
56
        $select->limit(1);
Línea 65... Línea 57...
65
        
57
 
66
        $prototype = new JobDescription();
58
        $prototype = new JobDescription();
67
        return $this->executeFetchOneObject($select, $prototype);
59
        return $this->executeFetchOneObject($select, $prototype);
68
    }
60
    }
69
 
61
 
70
    /**
-
 
71
     *
62
    /**
72
     * @return JobDescription[]
63
     *
73
     */
64
     * @return JobDescription[]
74
    public function fetchAllByDefault()
65
     */
75
    {
66
    public function fetchAllByDefault() {
76
        $select = $this->sql->select(self::_TABLE);
67
        $select = $this->sql->select(self::_TABLE);
77
        $select->where->isNull('company_id');
68
        $select->where->isNull('company_id');
78
        
69
 
79
        $prototype = new JobDescription();
70
        $prototype = new JobDescription();
80
        return $this->executeFetchAllObject($select, $prototype);
71
        return $this->executeFetchAllObject($select, $prototype);
81
    }
72
    }
82
    
73
 
83
    /**
74
    /**
84
     *
-
 
85
     * @param string $uuid
75
     *
86
     * @return JobDescription
76
     * @param string $uuid
87
     */
77
     * @return JobDescription
88
    public function fetchOneByUuid($uuid)
78
     */
89
    {
79
    public function fetchOneByUuid($uuid) {
90
        $select = $this->sql->select(self::_TABLE);
80
        $select = $this->sql->select(self::_TABLE);
91
        $select->where->equalTo('uuid', $uuid);
81
        $select->where->equalTo('uuid', $uuid);
92
        $select->limit(1);
-
 
93
        
82
        $select->limit(1);
94
        $prototype = new JobDescription();
83
 
95
        return $this->executeFetchOneObject($select, $prototype);
84
        $prototype = new JobDescription();
96
    }
85
        return $this->executeFetchOneObject($select, $prototype);
97
    
86
    }
98
    
87
 
99
    /**
88
    /**
100
     *
-
 
101
     * @param int $company_id
89
     *
102
     * @return JobDescription
90
     * @param int $company_id
103
     */
91
     * @return JobDescription
104
    public function fetchAllByCompanyId($company_id)
92
     */
105
    {
93
    public function fetchAllByCompanyId($company_id) {
106
        $select = $this->sql->select(self::_TABLE);
94
        $select = $this->sql->select(self::_TABLE);
107
        $select->where->equalTo('company_id', $company_id);
95
        $select->where->equalTo('company_id', $company_id);
108
        $select->order('name');
-
 
109
        
96
        $select->order('name');
110
        $prototype = new JobDescription();
97
 
111
        return $this->executeFetchAllObject($select, $prototype);
98
        $prototype = new JobDescription();
112
    }
99
        return $this->executeFetchAllObject($select, $prototype);
113
    
100
    }
114
    
101
 
115
    /**
102
    /**
116
     *
-
 
117
     * @param int $company_id
103
     *
118
     * @return JobDescription
104
     * @param int $company_id
119
     */
105
     * @return JobDescription
120
    public function fetchAllActiveByCompanyId($company_id)
106
     */
121
    {
107
    public function fetchAllActiveByCompanyId($company_id) {
122
        $select = $this->sql->select(self::_TABLE);
108
        $select = $this->sql->select(self::_TABLE);
123
        $select->where->equalTo('company_id', $company_id);
109
        $select->where->equalTo('company_id', $company_id);
124
        $select->where->equalTo('status', JobDescription::STATUS_ACTIVE);
110
        $select->where->equalTo('status', JobDescription::STATUS_ACTIVE);
Línea 125... Línea -...
125
        $select->order('name');
-
 
126
        
111
        $select->order('name');
127
        $prototype = new JobDescription();
112
 
128
        return $this->executeFetchAllObject($select, $prototype);
113
        $prototype = new JobDescription();
129
    }
114
        return $this->executeFetchAllObject($select, $prototype);
130
 
115
    }
131
 
116
 
132
    /**
117
    /**
133
     *
-
 
134
     * @param int $company_id
118
     *
135
     * @param int $job_description_id_default
119
     * @param int $company_id
136
     * @return JobDescription
120
     * @param int $job_description_id_default
137
     */
121
     * @return JobDescription
138
    public function fetchOneByCompanyId($company_id, $job_description_id_default)
122
     */
139
    {
123
    public function fetchOneByCompanyId($company_id, $job_description_id_default) {
140
        $select = $this->sql->select(self::_TABLE);
124
        $select = $this->sql->select(self::_TABLE);
141
        $select->where->equalTo('company_id', $company_id);
125
        $select->where->equalTo('company_id', $company_id);
142
        $select->where->equalTo('job_description_id_default', $job_description_id_default);
-
 
143
        $select->limit(1);
126
        $select->where->equalTo('job_description_id_default', $job_description_id_default);
144
        
127
        $select->limit(1);
145
        $prototype = new JobDescription();
128
 
146
        return $this->executeFetchOneObject($select, $prototype);
129
        $prototype = new JobDescription();
147
    }
130
        return $this->executeFetchOneObject($select, $prototype);
148
    
131
    }
149
    
132
 
150
    /**
133
    /**
151
     *
-
 
152
     * @param int $company_id
134
     *
153
     * @param int $id
135
     * @param int $company_id
154
     * @return JobDescription
136
     * @param int $id
155
     */
137
     * @return JobDescription
156
    public function fetchAllByCompanyIdWhereIdNotEqual($company_id, $id)
138
     */
157
    {
139
    public function fetchAllByCompanyIdWhereIdNotEqual($company_id, $id) {
158
        $select = $this->sql->select(self::_TABLE);
140
        $select = $this->sql->select(self::_TABLE);
159
        $select->where->equalTo('company_id', $company_id);
141
        $select->where->equalTo('company_id', $company_id);
160
        $select->where->notEqualTo('id', $id);
-
 
161
        $select->order('name');
142
        $select->where->notEqualTo('id', $id);
162
        
143
        $select->order('name');
163
        $prototype = new JobDescription();
144
 
164
        return $this->executeFetchAllObject($select, $prototype);
145
        $prototype = new JobDescription();
165
    }
146
        return $this->executeFetchAllObject($select, $prototype);
166
    
147
    }
167
    
148
 
168
    /**
149
    /**
169
     *
-
 
170
     * @param int $company_id
150
     *
171
     * @param int $id
151
     * @param int $company_id
172
     * @return JobDescription
152
     * @param int $id
173
     */
153
     * @return JobDescription
174
    public function fetchAllActiveByCompanyIdWhereIdNotEqual($company_id, $id)
154
     */
175
    {
155
    public function fetchAllActiveByCompanyIdWhereIdNotEqual($company_id, $id) {
176
        $select = $this->sql->select(self::_TABLE);
156
        $select = $this->sql->select(self::_TABLE);
177
        $select->where->equalTo('company_id', $company_id);
157
        $select->where->equalTo('company_id', $company_id);
178
        $select->where->notEqualTo('id', $id);
158
        $select->where->notEqualTo('id', $id);
Línea 179... Línea 159...
179
        $select->where->equalTo('status', JobDescription::STATUS_ACTIVE);
159
        $select->where->equalTo('status', JobDescription::STATUS_ACTIVE);
180
        $select->order('name');
160
        $select->order('name');
181
        
161
 
182
        $prototype = new JobDescription();
162
        $prototype = new JobDescription();
183
        return $this->executeFetchAllObject($select, $prototype);
163
        return $this->executeFetchAllObject($select, $prototype);
184
    }
164
    }
185
 
165
 
186
     /**
166
    /**
187
     *
167
     *
188
     * @param string $search
168
     * @param string $search
189
     * @param int $page
-
 
190
     * @param int $records_per_page
169
     * @param int $page
191
     * @param string $order_field
170
     * @param int $records_per_page
192
     * @param string $order_direction
171
     * @param string $order_field
193
     * @return Paginator
172
     * @param string $order_direction
194
     */
173
     * @return Paginator
195
    public function fetchAllDataTable($search, $page = 1, $records_per_page = 10, $order_field= 'name', $order_direction = 'ASC')
174
     */
196
    {
175
    public function fetchAllDataTable($search, $page = 1, $records_per_page = 10, $order_field = 'name', $order_direction = 'ASC') {
197
        $prototype = new JobDescription();
176
        $prototype = new JobDescription();
198
        $select = $this->sql->select(self::_TABLE);
177
        $select = $this->sql->select(self::_TABLE);
199
        $select->where->isNull('company_id');
178
        $select->where->isNull('company_id');
200
        
179
 
201
        if($search) {
180
        if ($search) {
202
            $select->where->like('name', '%' . $search . '%');
181
            $select->where->like('name', '%' . $search . '%');
203
        }
182
        }
204
        $select->order($order_field . ' ' . $order_direction);
183
        $select->order($order_field . ' ' . $order_direction);
205
        
184
 
206
        $hydrator   = new ObjectPropertyHydrator();
185
        $hydrator = new ObjectPropertyHydrator();
207
        $resultset  = new HydratingResultSet($hydrator, $prototype);
186
        $resultset = new HydratingResultSet($hydrator, $prototype);
208
        
187
 
209
        $adapter = new DbSelect($select, $this->sql, $resultset);
188
        $adapter = new DbSelect($select, $this->sql, $resultset);
Línea 210... Línea -...
210
        $paginator = new Paginator($adapter);
-
 
211
        $paginator->setItemCountPerPage($records_per_page);
189
        $paginator = new Paginator($adapter);
212
        $paginator->setCurrentPageNumber($page);
190
        $paginator->setItemCountPerPage($records_per_page);
213
        
191
        $paginator->setCurrentPageNumber($page);
214
        
192
 
215
        return $paginator;
193
 
216
    }
194
        return $paginator;
217
 
195
    }
218
    
196
 
219
    /**
197
    /**
220
     *
198
     *
221
     * @param int $companyId
199
     * @param int $companyId
222
     * @param string $search
-
 
223
     * @param int $page
200
     * @param string $search
224
     * @param int $records_per_page
201
     * @param int $page
225
     * @param string $order_field
202
     * @param int $records_per_page
226
     * @param string $order_direction
203
     * @param string $order_field
227
     * @return Paginator
204
     * @param string $order_direction
228
     */
205
     * @return Paginator
229
    public function fetchAllDataTableByCompanyId($companyId, $search, $page = 1, $records_per_page = 10, $order_field= 'name', $order_direction = 'ASC')
206
     */
230
    {
207
    public function fetchAllDataTableByCompanyId($companyId, $search, $page = 1, $records_per_page = 10, $order_field = 'name', $order_direction = 'ASC') {
231
        $prototype = new JobDescription();
208
        $prototype = new JobDescription();
232
        $select = $this->sql->select(self::_TABLE);
209
        $select = $this->sql->select(self::_TABLE);
233
        $select->where->equalTo('company_id', $companyId);
210
        $select->where->equalTo('company_id', $companyId);
234
        
211
 
235
        if($search) {
212
        if ($search) {
236
            $select->where->like('name', '%' . $search . '%');
213
            $select->where->like('name', '%' . $search . '%');
237
        }
214
        }
238
        $select->order($order_field . ' ' . $order_direction);
215
        $select->order($order_field . ' ' . $order_direction);
239
        
216
 
240
        //echo $select->getSqlString($this->adapter->platform); exit;
217
        //echo $select->getSqlString($this->adapter->platform); exit;
241
        
218
 
242
        $hydrator   = new ObjectPropertyHydrator();
219
        $hydrator = new ObjectPropertyHydrator();
243
        $resultset  = new HydratingResultSet($hydrator, $prototype);
220
        $resultset = new HydratingResultSet($hydrator, $prototype);
244
        
221
 
245
        $adapter = new DbSelect($select, $this->sql, $resultset);
-
 
246
        $paginator = new Paginator($adapter);
222
        $adapter = new DbSelect($select, $this->sql, $resultset);
247
        $paginator->setItemCountPerPage($records_per_page);
223
        $paginator = new Paginator($adapter);
248
        $paginator->setCurrentPageNumber($page);
224
        $paginator->setItemCountPerPage($records_per_page);
249
        
225
        $paginator->setCurrentPageNumber($page);
250
        
226
 
251
        return $paginator;
227
 
252
    }
228
        return $paginator;
253
    
-
 
254
    
229
    }
255
    /**
230
 
256
     *
231
    /**
257
     * @param JobDescription $jobDescription
232
     *
258
     * @return boolean
233
     * @param JobDescription $jobDescription
259
     */
234
     * @return boolean
260
    public function insert($jobDescription)
235
     */
261
    {
236
    public function insert($jobDescription) {
262
        $hydrator = new ObjectPropertyHydrator();
237
        $hydrator = new ObjectPropertyHydrator();
263
        $values = $hydrator->extract($jobDescription);
238
        $values = $hydrator->extract($jobDescription);
264
        $values = $this->removeEmpty($values);
239
        $values = $this->removeEmpty($values);
265
        $values['job_description_id_boss'] = !empty($values['job_description_id_boss']) ? $values['job_description_id_boss'] : null;
240
        $values['job_description_id_boss'] = !empty($values['job_description_id_boss']) ? $values['job_description_id_boss'] : null;
266
        
241
 
267
        
242
 
268
        $insert = $this->sql->insert(self::_TABLE);
243
        $insert = $this->sql->insert(self::_TABLE);
269
        $insert->values($values);
244
        $insert->values($values);
270
        
245
 
271
        //echo $insert->getSqlString($this->adapter->platform); exit;
-
 
272
        
246
        //echo $insert->getSqlString($this->adapter->platform); exit;
273
        
247
 
274
        $result = $this->executeInsert($insert);
248
 
275
        if($result) {
249
        $result = $this->executeInsert($insert);
276
            $jobDescription->id = $this->getLastInsertId();
250
        if ($result) {
277
        }
251
            $jobDescription->id = $this->getLastInsertId();
278
        return $result;
252
        }
279
        
253
        return $result;
280
    }
-
 
281
    
254
    }
282
    /**
255
 
283
     *
256
    /**
284
     * @param JobDescription $jobDescription
257
     *
285
     * @return boolean
258
     * @param JobDescription $jobDescription
286
     */
259
     * @return boolean
287
    public function update($jobDescription)
260
     */
288
    {
261
    public function update($jobDescription) {
289
        $hydrator = new ObjectPropertyHydrator();
262
        $hydrator = new ObjectPropertyHydrator();
290
        $values = $hydrator->extract($jobDescription);
263
        $values = $hydrator->extract($jobDescription);
291
        $values = $this->removeEmpty($values);
264
        $values = $this->removeEmpty($values);
292
        $values['job_description_id_boss'] = !empty($values['job_description_id_boss']) ? $values['job_description_id_boss'] : null;
265
        $values['job_description_id_boss'] = !empty($values['job_description_id_boss']) ? $values['job_description_id_boss'] : null;
293
        
266
 
294
        $update = $this->sql->update(self::_TABLE);
267
        $update = $this->sql->update(self::_TABLE);
295
        $update->set($values);
268
        $update->set($values);
296
        $update->where->equalTo('id', $jobDescription->id);
269
        $update->where->equalTo('id', $jobDescription->id);
297
        
270
 
298
        return $this->executeUpdate($update);
271
        return $this->executeUpdate($update);
299
    }
-
 
300
    
272
    }
301
    /**
273
 
302
     *
274
    /**
303
     * @param JobDescription $jobDescription
275
     *
304
     * @return boolean
-
 
305
     */
276
     * @param JobDescription $jobDescription
306
    public function delete($jobDescription)
-
 
Línea 307... Línea -...
307
    {
-
 
308
        $delete = $this->sql->delete(self::_TABLE);
-
 
309
        $delete->where->equalTo('id', $jobDescription->id);
-
 
310
        
-
 
311
        return $this->executeDelete($delete);
277
     * @return boolean
-
 
278
     */