Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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