Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 698 | Rev 700 | 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;
8
use LeadersLinked\Model\RecruitCandidate;
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
     *
21
     * @var RecruitmentSelectionMapper
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
50
     * @return RecruitmentCandidate
51
     */
52
    public function fetchOne($id)
53
    {
54
        $prototype = new RecruitmentCandidate();
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
66
     * @return RecruitmentCandidate
67
     */
68
    public function fetchOneByUuid($uuid)
69
    {
70
        $prototype = new RecruitmentCandidate();
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
     *
80
     * @param int $company_id
81
     * @return RecruitmentCandidate
82
     */
83
    public function fetchAllByCompanyId($company_id)
84
    {
85
        $prototype = new RecruitmentCandidate();
86
 
87
        $select = $this->sql->select(self::_TABLE);
88
        $select->where->equalTo('company_id', $company_id);
89
        $select->order('name');
90
 
91
        return $this->executeFetchAllObject($select, $prototype);
92
    }
93
 
686 eleazar 94
     /**
95
     *
96
     * @param int $company_id
97
     * @param int $selection_id
98
     * @param int $user_id
99
     * @return RecruitmentSelectionVacancy
100
     */
101
    public function fetchAllByCompanyIdAndSelectionIdAndUserId($company_id, $selection_id, $user_id)
102
    {
103
        $prototype = new RecruitmentSelectionVacancy();
104
 
105
        $select = $this->sql->select(self::_TABLE);
106
        $select->where->equalTo('company_id', $company_id);
107
        $select->where->equalTo('selection_id', $selection_id);
108
        $select->where->equalTo('user_id', $user_id);
109
 
110
 
111
        return $this->executeFetchOneObject($select, $prototype);
112
    }
647 efrain 113
 
686 eleazar 114
 
647 efrain 115
    /**
116
     *
117
     * @param RecruitmentCandidate $form
118
     * @return boolean
119
     */
120
    public function insert($form)
121
    {
122
        $hydrator = new ObjectPropertyHydrator();
123
        $values = $hydrator->extract($form);
124
        $values = $this->removeEmpty($values);
125
 
126
        $insert = $this->sql->insert(self::_TABLE);
698 eleazar 127
        $insert->values($values);
699 eleazar 128
        return [
129
            $hydrator->extract($form),
130
            $values,
131
        ];
697 eleazar 132
        return $insert->getSqlString($this->adapter->platform);
696 eleazar 133
 
647 efrain 134
        $result = $this->executeInsert($insert);
135
        if($result) {
136
            $form->id = $this->lastInsertId;
137
        }
138
        return $result;
139
    }
140
 
141
    /**
142
     *
143
     * @param RecruitmentCandidate $form
144
     * @return boolean
145
     */
146
    public function update($form)
147
    {
148
        $hydrator = new ObjectPropertyHydrator();
149
        $values = $hydrator->extract($form);
150
        $values = $this->removeEmpty($values);
151
 
152
        $update = $this->sql->update(self::_TABLE);
153
        $update->set($values);
154
        $update->where->equalTo('id', $form->id);
155
 
156
        return $this->executeUpdate($update);
157
    }
158
 
159
    /**
160
     *
161
     * @param int $form_id
162
     * @return boolean
163
     */
164
    public function delete($form_id)
165
    {
166
        $delete = $this->sql->delete(self::_TABLE);
167
        $delete->where->equalTo('id', $form_id);
168
 
169
        return $this->executeDelete($delete);
170
    }
171
 
172
 
173
    /**
174
     *
175
     * @param int $companyId
176
     * @param string $search
177
     * @param int $page
178
     * @param int $records_per_page
179
     * @param string $order_field
180
     * @param string $order_direction
181
     * @return Paginator
182
     */
183
    public function fetchAllDataTableByCompanyId($companyId, $search, $page = 1, $records_per_page = 10, $order_field= 'name', $order_direction = 'ASC')
184
    {
185
        $prototype = new RecruitmentCandidate();
186
        $select = $this->sql->select(self::_TABLE);
187
        $select->where->equalTo('company_id', $companyId);
188
 
189
        if($search) {
190
            $select->where->like('name', '%' . $search . '%');
191
        }
192
        $select->order($order_field . ' ' . $order_direction);
193
 
194
        //echo $select->getSqlString($this->adapter->platform); exit;
195
 
196
        $hydrator   = new ObjectPropertyHydrator();
197
        $resultset  = new HydratingResultSet($hydrator, $prototype);
198
 
199
        $adapter = new DbSelect($select, $this->sql, $resultset);
200
        $paginator = new Paginator($adapter);
201
        $paginator->setItemCountPerPage($records_per_page);
202
        $paginator->setCurrentPageNumber($page);
203
 
204
 
205
        return $paginator;
206
    }
207
 
208
 
209
}