Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 1286 | Rev 3471 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
647 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;
705 eleazar 8
use LeadersLinked\Model\RecruitmentSelectionCandidate;
647 efrain 9
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
10
use Laminas\Paginator\Paginator;
11
use Laminas\Db\ResultSet\HydratingResultSet;
12
use Laminas\Paginator\Adapter\DbSelect;
13
 
14
 
15
class RecruitmentSelectionCandidateMapper extends MapperCommon
16
{
17
    const _TABLE = 'tbl_recruitment_selection_candidates';
18
 
19
    /**
20
     *
707 eleazar 21
     * @var RecruitmentSelectionCandidateMapper
647 efrain 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 RecruitmentSelectionCandidateMapper
38
     */
39
    public static function getInstance($adapter)
40
    {
41
        if(self::$_instance == null) {
42
            self::$_instance = new RecruitmentSelectionCandidateMapper($adapter);
43
        }
44
        return self::$_instance;
45
    }
46
 
47
    /**
48
     *
49
     * @param int $id
704 eleazar 50
     * @return RecruitmentSelectionCandidate
647 efrain 51
     */
52
    public function fetchOne($id)
53
    {
704 eleazar 54
        $prototype = new RecruitmentSelectionCandidate();
647 efrain 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
704 eleazar 66
     * @return RecruitmentSelectionCandidate
647 efrain 67
     */
68
    public function fetchOneByUuid($uuid)
69
    {
704 eleazar 70
        $prototype = new RecruitmentSelectionCandidate();
647 efrain 71
        $select = $this->sql->select(self::_TABLE);
72
        $select->where->equalTo('uuid', $uuid);
73
 
74
        return $this->executeFetchOneObject($select, $prototype);
75
    }
76
 
77
    /**
78
     *
79
     * @param int $company_id
704 eleazar 80
     * @return RecruitmentSelectionCandidate
647 efrain 81
     */
82
    public function fetchAllByCompanyId($company_id)
83
    {
704 eleazar 84
        $prototype = new RecruitmentSelectionCandidate();
647 efrain 85
 
86
        $select = $this->sql->select(self::_TABLE);
87
        $select->where->equalTo('company_id', $company_id);
1059 eleazar 88
        $select->order('first_name');
647 efrain 89
 
90
        return $this->executeFetchAllObject($select, $prototype);
91
    }
721 eleazar 92
 
93
    /**
94
     *
902 eleazar 95
     * @param int $vacancy_id
721 eleazar 96
     * @return RecruitmentSelectionCandidate
97
     */
902 eleazar 98
    public function fetchAllBySelectionId($vacancy_id)
721 eleazar 99
    {
100
        $prototype = new RecruitmentSelectionCandidate();
101
 
102
        $select = $this->sql->select(self::_TABLE);
1012 eleazar 103
        $select->where->equalTo('vacancy_id', $vacancy_id);
721 eleazar 104
        $select->order('first_name');
105
 
106
        return $this->executeFetchAllObject($select, $prototype);
107
    }
863 eleazar 108
 
1286 eleazar 109
    /**
1278 eleazar 110
     *
111
     * @return RecruitmentSelectionCandidate[]
112
     */
3454 efrain 113
    public function fetchAllActive($vacancy_id) {
1278 eleazar 114
        $prototype = new RecruitmentSelectionCandidate();
115
        $select = $this->sql->select(self::_TABLE);
1286 eleazar 116
        $select->where->equalTo('vacancy_id', $vacancy_id);
1278 eleazar 117
        $select->where->equalTo('status', RecruitmentSelectionCandidate::STATUS_ACEPTED);
118
        $select->order('first_name');
1276 eleazar 119
 
1278 eleazar 120
        return $this->executeFetchAllObject($select, $prototype);
121
    }
122
 
1276 eleazar 123
    /**
124
     *
125
     * @param int $candidate_id
126
     * @return RecruitmentSelectionCandidates[]
127
     */
128
    public function fetchAllByVacancyIdAndStatus($vacancy_id)
129
    {
130
        $prototype = new RecruitmentSelectionCandidates();
131
 
132
        $select = $this->sql->select(self::_TABLE);
133
        $select->where->equalTo('vacancy_id', $vacancy_id);
134
        $select->where->equalTo('status', RecruitmentSelectionCandidates::STATUS_ACCEPTED);
135
        $select->order('first_name');
136
 
137
        return $this->executeFetchAllObject($select, $prototype);
138
    }
139
 
863 eleazar 140
     /**
141
     *
142
     * @param int $company_id
143
     * @param int $vacancy_id
144
     * @return RecruitmentSelectioncandidate[]
145
     */
146
    public function fetchAllByCompanyIdAndVacancyId($company_id, $vacancy_id)
147
    {
148
        $prototype = new RecruitmentSelectioncandidate();
149
 
150
        $select = $this->sql->select(self::_TABLE);
151
        $select->where->equalTo('company_id', $company_id);
1012 eleazar 152
        $select->where->equalTo('vacancy_id', $vacancy_id);
1063 eleazar 153
        $select->order(['first_name']);
863 eleazar 154
 
1063 eleazar 155
       // echo $select->getSqlString($this->adapter->platform); exit;
863 eleazar 156
 
157
        return $this->executeFetchAllObject($select, $prototype);
158
    }
647 efrain 159
 
686 eleazar 160
     /**
161
     *
162
     * @param int $company_id
163
     * @param int $selection_id
164
     * @param int $user_id
707 eleazar 165
     * @return RecruitmentSelectionCandidate
686 eleazar 166
     */
1012 eleazar 167
    public function fetchAllByCompanyIdAndSelectionIdAndUserId($company_id, $vacancy_id, $user_id)
686 eleazar 168
    {
704 eleazar 169
        $prototype = new RecruitmentSelectionCandidate();
686 eleazar 170
 
171
        $select = $this->sql->select(self::_TABLE);
172
        $select->where->equalTo('company_id', $company_id);
1012 eleazar 173
        $select->where->equalTo('vacancy_id', $vacancy_id);
686 eleazar 174
        $select->where->equalTo('user_id', $user_id);
175
 
176
 
177
        return $this->executeFetchOneObject($select, $prototype);
178
    }
647 efrain 179
 
686 eleazar 180
 
647 efrain 181
    /**
182
     *
720 eleazar 183
     * @param RecruitmentSelectionCandidate $candidate
647 efrain 184
     * @return boolean
185
     */
720 eleazar 186
    public function insert($candidate)
647 efrain 187
    {
188
        $hydrator = new ObjectPropertyHydrator();
720 eleazar 189
        $values = $hydrator->extract($candidate);
647 efrain 190
        $values = $this->removeEmpty($values);
191
 
192
        $insert = $this->sql->insert(self::_TABLE);
698 eleazar 193
        $insert->values($values);
696 eleazar 194
 
647 efrain 195
        $result = $this->executeInsert($insert);
196
        if($result) {
720 eleazar 197
            $candidate->id = $this->lastInsertId;
647 efrain 198
        }
199
        return $result;
200
    }
201
 
202
    /**
203
     *
720 eleazar 204
     * @param RecruitmentSelectionCandidate $candidate
647 efrain 205
     * @return boolean
206
     */
720 eleazar 207
    public function update($candidate)
647 efrain 208
    {
209
        $hydrator = new ObjectPropertyHydrator();
720 eleazar 210
        $values = $hydrator->extract($candidate);
647 efrain 211
        $values = $this->removeEmpty($values);
212
 
213
        $update = $this->sql->update(self::_TABLE);
214
        $update->set($values);
720 eleazar 215
        $update->where->equalTo('id', $candidate->id);
647 efrain 216
 
217
        return $this->executeUpdate($update);
218
    }
219
 
220
    /**
221
     *
222
     * @param int $form_id
223
     * @return boolean
224
     */
225
    public function delete($form_id)
226
    {
227
        $delete = $this->sql->delete(self::_TABLE);
228
        $delete->where->equalTo('id', $form_id);
229
 
230
        return $this->executeDelete($delete);
231
    }
232
 
233
 
234
    /**
235
     *
236
     * @param int $companyId
237
     * @param string $search
238
     * @param int $page
239
     * @param int $records_per_page
240
     * @param string $order_field
241
     * @param string $order_direction
242
     * @return Paginator
243
     */
244
    public function fetchAllDataTableByCompanyId($companyId, $search, $page = 1, $records_per_page = 10, $order_field= 'name', $order_direction = 'ASC')
245
    {
704 eleazar 246
        $prototype = new RecruitmentSelectionCandidate();
647 efrain 247
        $select = $this->sql->select(self::_TABLE);
248
        $select->where->equalTo('company_id', $companyId);
249
 
250
        if($search) {
251
            $select->where->like('name', '%' . $search . '%');
252
        }
253
        $select->order($order_field . ' ' . $order_direction);
254
 
255
        //echo $select->getSqlString($this->adapter->platform); exit;
256
 
257
        $hydrator   = new ObjectPropertyHydrator();
258
        $resultset  = new HydratingResultSet($hydrator, $prototype);
259
 
260
        $adapter = new DbSelect($select, $this->sql, $resultset);
261
        $paginator = new Paginator($adapter);
262
        $paginator->setItemCountPerPage($records_per_page);
263
        $paginator->setCurrentPageNumber($page);
264
 
265
 
266
        return $paginator;
267
    }
268
 
269
 
270
}