Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 1893 | Rev 3454 | 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;
650 eleazar 8
use LeadersLinked\Model\RecruitmentSelectionVacancy;
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 RecruitmentSelectionVacancyMapper extends MapperCommon
16
{
17
    const _TABLE = 'tbl_recruitment_selection';
18
 
19
    /**
20
     *
21
     * @var RecruitmentSelectionSelectionMapper
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 RecruitmentSelectionVacancyMapper
38
     */
39
    public static function getInstance($adapter)
40
    {
41
        if(self::$_instance == null) {
42
            self::$_instance = new RecruitmentSelectionVacancyMapper($adapter);
43
        }
44
        return self::$_instance;
45
    }
46
 
47
    /**
48
     *
49
     * @param int $id
1893 efrain 50
     * @return RecruitmentSelectionVacancy
647 efrain 51
     */
52
    public function fetchOne($id)
53
    {
650 eleazar 54
        $prototype = new RecruitmentSelectionVacancy();
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
1893 efrain 66
     * @return RecruitmentSelectionVacancy
647 efrain 67
     */
68
    public function fetchOneByUuid($uuid)
69
    {
650 eleazar 70
        $prototype = new RecruitmentSelectionVacancy();
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
     *
80
     * @param int $company_id
1893 efrain 81
     * @return RecruitmentSelectionVacancy
647 efrain 82
     */
83
    public function fetchAllByCompanyId($company_id)
84
    {
650 eleazar 85
        $prototype = new RecruitmentSelectionVacancy();
647 efrain 86
 
87
        $select = $this->sql->select(self::_TABLE);
88
        $select->where->equalTo('company_id', $company_id);
1998 eleazar 89
        $select->where->equalTo('status', RecruitmentSelectionVacancy::STATUS_ACTIVE);
647 efrain 90
        $select->order('name');
91
 
92
        return $this->executeFetchAllObject($select, $prototype);
93
    }
992 eleazar 94
 
95
     /**
96
     *
97
     * @param int $company_id
1893 efrain 98
     * @return RecruitmentSelectionVacancy
992 eleazar 99
     */
100
    public function fetchOneByCompanyId($company_id)
101
    {
102
        $prototype = new RecruitmentSelectionVacancy();
103
 
104
        $select = $this->sql->select(self::_TABLE);
105
        $select->where->equalTo('company_id', $company_id);
106
        $select->order('name');
107
 
993 eleazar 108
        return $this->executeFetchOneObject($select, $prototype);
992 eleazar 109
    }
647 efrain 110
 
111
 
112
    /**
113
     *
1893 efrain 114
     * @param RecruitmentSelectionVacancy $form
647 efrain 115
     * @return boolean
116
     */
117
    public function insert($form)
118
    {
119
        $hydrator = new ObjectPropertyHydrator();
120
        $values = $hydrator->extract($form);
121
        $values = $this->removeEmpty($values);
122
 
123
        $insert = $this->sql->insert(self::_TABLE);
124
        $insert->values($values);
125
 
126
        $result = $this->executeInsert($insert);
127
        if($result) {
128
            $form->id = $this->lastInsertId;
129
        }
130
        return $result;
131
    }
132
 
133
    /**
134
     *
1893 efrain 135
     * @param RecruitmentSelectionVacancy $form
647 efrain 136
     * @return boolean
137
     */
138
    public function update($form)
139
    {
140
        $hydrator = new ObjectPropertyHydrator();
141
        $values = $hydrator->extract($form);
142
        $values = $this->removeEmpty($values);
143
 
144
        $update = $this->sql->update(self::_TABLE);
145
        $update->set($values);
146
        $update->where->equalTo('id', $form->id);
147
        return $this->executeUpdate($update);
148
    }
149
 
150
    /**
151
     *
152
     * @param int $form_id
153
     * @return boolean
154
     */
155
    public function delete($form_id)
156
    {
157
        $delete = $this->sql->delete(self::_TABLE);
158
        $delete->where->equalTo('id', $form_id);
159
 
160
        return $this->executeDelete($delete);
161
    }
162
 
163
 
164
    /**
165
     *
166
     * @param int $company_id
167
     * @param string $search
168
     * @param int $page
169
     * @param int $records_per_page
170
     * @param string $order_field
171
     * @param string $order_direction
172
     * @return Paginator
173
     */
174
    public function fetchAllDataTableByCompanyId($company_id, $search, $page = 1, $records_per_page = 10, $order_field= 'name', $order_direction = 'ASC')
175
    {
650 eleazar 176
        $prototype = new RecruitmentSelectionVacancy();
647 efrain 177
        $select = $this->sql->select(self::_TABLE);
178
        $select->where->equalTo('company_id', $company_id);
179
 
180
        if($search) {
181
            $select->where->like('name', '%' . $search . '%');
182
        }
183
        $select->order($order_field . ' ' . $order_direction);
184
 
185
        //echo $select->getSqlString($this->adapter->platform); exit;
186
 
187
        $hydrator   = new ObjectPropertyHydrator();
188
        $resultset  = new HydratingResultSet($hydrator, $prototype);
189
 
190
        $adapter = new DbSelect($select, $this->sql, $resultset);
191
        $paginator = new Paginator($adapter);
192
        $paginator->setItemCountPerPage($records_per_page);
193
        $paginator->setCurrentPageNumber($page);
194
 
195
 
196
        return $paginator;
197
    }
198
 
199
 
200
}