Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 4776 | 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
     *
5050 efrain 65
     * @param string $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
    }
5050 efrain 76
 
77
 
78
    /**
79
     *
80
     * @param string $email
81
     * @return RecruitmentSelectionCandidate
82
     */
83
    public function fetchOneByEmail($email)
84
    {
85
        $prototype = new RecruitmentSelectionCandidate();
86
        $select = $this->sql->select(self::_TABLE);
87
        $select->where->equalTo('email', $email);
88
 
89
        return $this->executeFetchOneObject($select, $prototype);
90
    }
647 efrain 91
 
92
    /**
93
     *
94
     * @param int $company_id
704 eleazar 95
     * @return RecruitmentSelectionCandidate
647 efrain 96
     */
97
    public function fetchAllByCompanyId($company_id)
98
    {
704 eleazar 99
        $prototype = new RecruitmentSelectionCandidate();
647 efrain 100
 
101
        $select = $this->sql->select(self::_TABLE);
102
        $select->where->equalTo('company_id', $company_id);
1059 eleazar 103
        $select->order('first_name');
647 efrain 104
 
105
        return $this->executeFetchAllObject($select, $prototype);
106
    }
721 eleazar 107
 
4776 efrain 108
 
863 eleazar 109
 
647 efrain 110
 
111
    /**
112
     *
4776 efrain 113
     * @param RecruitmentSelectionCandidate $record
647 efrain 114
     * @return boolean
115
     */
4776 efrain 116
    public function insert($record)
647 efrain 117
    {
118
        $hydrator = new ObjectPropertyHydrator();
4776 efrain 119
        $values = $hydrator->extract($record);
647 efrain 120
        $values = $this->removeEmpty($values);
121
 
122
        $insert = $this->sql->insert(self::_TABLE);
698 eleazar 123
        $insert->values($values);
696 eleazar 124
 
647 efrain 125
        $result = $this->executeInsert($insert);
126
        if($result) {
4776 efrain 127
            $record->id = $this->lastInsertId;
647 efrain 128
        }
129
        return $result;
130
    }
131
 
132
    /**
133
     *
4776 efrain 134
     * @param RecruitmentSelectionCandidate $record
647 efrain 135
     * @return boolean
136
     */
4776 efrain 137
    public function update($record)
647 efrain 138
    {
139
        $hydrator = new ObjectPropertyHydrator();
4776 efrain 140
        $values = $hydrator->extract($record);
647 efrain 141
        $values = $this->removeEmpty($values);
142
 
143
        $update = $this->sql->update(self::_TABLE);
144
        $update->set($values);
4776 efrain 145
        $update->where->equalTo('id', $record->id);
647 efrain 146
 
147
        return $this->executeUpdate($update);
148
    }
149
 
150
    /**
151
     *
4776 efrain 152
     * @param int $id
647 efrain 153
     * @return boolean
154
     */
4776 efrain 155
    public function delete($id)
647 efrain 156
    {
157
        $delete = $this->sql->delete(self::_TABLE);
4776 efrain 158
        $delete->where->equalTo('id', $id);
647 efrain 159
 
160
        return $this->executeDelete($delete);
161
    }
162
 
163
 
164
    /**
165
     *
166
     * @param int $companyId
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($companyId, $search, $page = 1, $records_per_page = 10, $order_field= 'name', $order_direction = 'ASC')
175
    {
704 eleazar 176
        $prototype = new RecruitmentSelectionCandidate();
647 efrain 177
        $select = $this->sql->select(self::_TABLE);
178
        $select->where->equalTo('company_id', $companyId);
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
}