Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 1277 | Rev 1286 | 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
 
1278 eleazar 109
      /**
110
     *
111
     * @return RecruitmentSelectionCandidate[]
112
     */
113
    public function fetchAllActives() {
114
        $prototype = new RecruitmentSelectionCandidate();
115
        $select = $this->sql->select(self::_TABLE);
116
        $select->where->equalTo('status', RecruitmentSelectionCandidate::STATUS_ACEPTED);
117
        $select->order('first_name');
1276 eleazar 118
 
1278 eleazar 119
        return $this->executeFetchAllObject($select, $prototype);
120
    }
121
 
1276 eleazar 122
    /**
123
     *
124
     * @param int $candidate_id
125
     * @return RecruitmentSelectionCandidates[]
126
     */
127
    public function fetchAllByVacancyIdAndStatus($vacancy_id)
128
    {
129
        $prototype = new RecruitmentSelectionCandidates();
130
 
131
        $select = $this->sql->select(self::_TABLE);
132
        $select->where->equalTo('vacancy_id', $vacancy_id);
133
        $select->where->equalTo('status', RecruitmentSelectionCandidates::STATUS_ACCEPTED);
134
        $select->order('first_name');
135
 
136
        return $this->executeFetchAllObject($select, $prototype);
137
    }
138
 
863 eleazar 139
     /**
140
     *
141
     * @param int $company_id
142
     * @param int $vacancy_id
143
     * @return RecruitmentSelectioncandidate[]
144
     */
145
    public function fetchAllByCompanyIdAndVacancyId($company_id, $vacancy_id)
146
    {
147
        $prototype = new RecruitmentSelectioncandidate();
148
 
149
        $select = $this->sql->select(self::_TABLE);
150
        $select->where->equalTo('company_id', $company_id);
1012 eleazar 151
        $select->where->equalTo('vacancy_id', $vacancy_id);
1063 eleazar 152
        $select->order(['first_name']);
863 eleazar 153
 
1063 eleazar 154
       // echo $select->getSqlString($this->adapter->platform); exit;
863 eleazar 155
 
156
        return $this->executeFetchAllObject($select, $prototype);
157
    }
647 efrain 158
 
686 eleazar 159
     /**
160
     *
161
     * @param int $company_id
162
     * @param int $selection_id
163
     * @param int $user_id
707 eleazar 164
     * @return RecruitmentSelectionCandidate
686 eleazar 165
     */
1012 eleazar 166
    public function fetchAllByCompanyIdAndSelectionIdAndUserId($company_id, $vacancy_id, $user_id)
686 eleazar 167
    {
704 eleazar 168
        $prototype = new RecruitmentSelectionCandidate();
686 eleazar 169
 
170
        $select = $this->sql->select(self::_TABLE);
171
        $select->where->equalTo('company_id', $company_id);
1012 eleazar 172
        $select->where->equalTo('vacancy_id', $vacancy_id);
686 eleazar 173
        $select->where->equalTo('user_id', $user_id);
174
 
175
 
176
        return $this->executeFetchOneObject($select, $prototype);
177
    }
647 efrain 178
 
686 eleazar 179
 
647 efrain 180
    /**
181
     *
720 eleazar 182
     * @param RecruitmentSelectionCandidate $candidate
647 efrain 183
     * @return boolean
184
     */
720 eleazar 185
    public function insert($candidate)
647 efrain 186
    {
187
        $hydrator = new ObjectPropertyHydrator();
720 eleazar 188
        $values = $hydrator->extract($candidate);
647 efrain 189
        $values = $this->removeEmpty($values);
190
 
191
        $insert = $this->sql->insert(self::_TABLE);
698 eleazar 192
        $insert->values($values);
696 eleazar 193
 
647 efrain 194
        $result = $this->executeInsert($insert);
195
        if($result) {
720 eleazar 196
            $candidate->id = $this->lastInsertId;
647 efrain 197
        }
198
        return $result;
199
    }
200
 
201
    /**
202
     *
720 eleazar 203
     * @param RecruitmentSelectionCandidate $candidate
647 efrain 204
     * @return boolean
205
     */
720 eleazar 206
    public function update($candidate)
647 efrain 207
    {
208
        $hydrator = new ObjectPropertyHydrator();
720 eleazar 209
        $values = $hydrator->extract($candidate);
647 efrain 210
        $values = $this->removeEmpty($values);
211
 
212
        $update = $this->sql->update(self::_TABLE);
213
        $update->set($values);
720 eleazar 214
        $update->where->equalTo('id', $candidate->id);
647 efrain 215
 
216
        return $this->executeUpdate($update);
217
    }
218
 
219
    /**
220
     *
221
     * @param int $form_id
222
     * @return boolean
223
     */
224
    public function delete($form_id)
225
    {
226
        $delete = $this->sql->delete(self::_TABLE);
227
        $delete->where->equalTo('id', $form_id);
228
 
229
        return $this->executeDelete($delete);
230
    }
231
 
232
 
233
    /**
234
     *
235
     * @param int $companyId
236
     * @param string $search
237
     * @param int $page
238
     * @param int $records_per_page
239
     * @param string $order_field
240
     * @param string $order_direction
241
     * @return Paginator
242
     */
243
    public function fetchAllDataTableByCompanyId($companyId, $search, $page = 1, $records_per_page = 10, $order_field= 'name', $order_direction = 'ASC')
244
    {
704 eleazar 245
        $prototype = new RecruitmentSelectionCandidate();
647 efrain 246
        $select = $this->sql->select(self::_TABLE);
247
        $select->where->equalTo('company_id', $companyId);
248
 
249
        if($search) {
250
            $select->where->like('name', '%' . $search . '%');
251
        }
252
        $select->order($order_field . ' ' . $order_direction);
253
 
254
        //echo $select->getSqlString($this->adapter->platform); exit;
255
 
256
        $hydrator   = new ObjectPropertyHydrator();
257
        $resultset  = new HydratingResultSet($hydrator, $prototype);
258
 
259
        $adapter = new DbSelect($select, $this->sql, $resultset);
260
        $paginator = new Paginator($adapter);
261
        $paginator->setItemCountPerPage($records_per_page);
262
        $paginator->setCurrentPageNumber($page);
263
 
264
 
265
        return $paginator;
266
    }
267
 
268
 
269
}