Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
7134 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\MyCoachCategory;
9
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
10
use LeadersLinked\Model\MyCoachCategoryJobDescription;
11
 
12
 
13
class MyCoachCategoryJobDescriptionMapper extends MapperCommon
14
{
15
    const _TABLE = 'tbl_my_coach_category_jobs_description';
16
 
17
    /**
18
     *
19
     * @var MyCoachCategoryJobDescriptionMapper
20
     */
21
    private static $_instance;
22
 
23
    /**
24
     *
25
     * @param AdapterInterface $adapter
26
     */
27
    private function __construct($adapter)
28
    {
29
        parent::__construct($adapter);
30
    }
31
 
32
    /**
33
     *
34
     * @param AdapterInterface $adapter
35
     * @return MyCoachCategoryJobDescriptionMapper
36
     */
37
    public static function getInstance($adapter)
38
    {
39
        if(self::$_instance == null) {
40
            self::$_instance = new MyCoachCategoryJobDescriptionMapper($adapter);
41
        }
42
        return self::$_instance;
43
    }
44
 
45
    /**
46
     *
47
     * @param array $job_description_ids
48
     * @return MyCoachCategoryJobDescription[]
49
     */
50
    public function fetchAllByJobDescriptionIds($job_description_ids)
51
    {
52
        $select = $this->sql->select(self::_TABLE);
53
        $select->where->in('job_description_id', $job_description_ids);
54
 
55
        //echo $select->getSqlString($this->adapter->platform);
56
 
57
        $prototype = new MyCoachCategoryJobDescription();
58
        return $this->executeFetchAllObject($select, $prototype);
59
    }
60
 
61
    /**
62
     *
63
     * @param int $category_id
64
     * @param int $job_description_id
65
     * @return MyCoachCategoryJobDescription
66
     */
67
    public function fetchOneByCategoryIdAndJobDescriptionId($category_id, $job_description_id)
68
    {
69
 
70
        $select = $this->sql->select(self::_TABLE);
71
        $select->where->equalTo('category_id', $category_id);
72
        $select->where->equalTo('job_description_id', $job_description_id);
73
 
74
        //echo $select->getSqlString($this->adapter->platform);
75
 
76
        $prototype = new MyCoachCategoryJobDescription();
77
        return $this->executeFetchOneObject($select, $prototype);
78
    }
79
 
80
    /**
81
     *
82
     * @param int $company_id
83
     * @param array $job_description_ids
84
     * @return MyCoachCategoryJobDescription[]
85
     */
86
    public function fetchAllByCompanyIdAndJobDescriptionIds($company_id, $job_description_ids)
87
    {
88
 
89
        $select = $this->sql->select(self::_TABLE);
90
        $select->where->equalTo('company_id', $company_id);
91
        $select->where->in('job_description_id', $job_description_ids);
92
 
93
 
94
        $prototype = new MyCoachCategoryJobDescription();
95
        return $this->executeFetchAllObject($select, $prototype);
96
    }
97
 
98
 
99
    /**
100
     *
101
     * @param
102
     * @return MyCoachCategoryJobDescription[]
103
     */
104
    public function fetchAllByJobDescriptionId($job_description_id)
105
    {
106
 
107
        $select = $this->sql->select(self::_TABLE);
108
        $select->where->equalTo('job_description_id', $job_description_id);
109
 
110
 
111
        $prototype = new MyCoachCategoryJobDescription();
112
        return $this->executeFetchAllObject($select, $prototype);
113
    }
114
 
115
 
116
 
117
 
118
    /**
119
     *
120
     * @param
121
     * @return MyCoachCategoryJobDescription[]
122
     */
123
    public function fetchAllByCategoryId($category_id)
124
    {
125
 
126
        $select = $this->sql->select(self::_TABLE);
127
        $select->where->equalTo('category_id', $category_id);
128
 
129
 
130
        $prototype = new MyCoachCategoryJobDescription();
131
        return $this->executeFetchAllObject($select, $prototype);
132
    }
133
 
134
    /**
135
     *
136
     * @param int $category_id
137
     * @return boolean
138
     */
139
    public function deleteAllByCategoryId($category_id)
140
    {
141
        $delete = $this->sql->delete(self::_TABLE);
142
        $delete->where->equalTo('category_id', $category_id);
143
 
144
        return $this->executeDelete($delete);
145
    }
146
 
147
    /**
148
     *
149
     * @param int $category_id
150
     * @param int $job_description_id
151
     * @return boolean
152
     */
153
    public function  deleteOneByCategoryIdAndUserId($category_id, $job_description_id)
154
    {
155
        $delete = $this->sql->delete(self::_TABLE);
156
        $delete->where->equalTo('category_id', $category_id);
157
        $delete->where->equalTo('job_description_id', $job_description_id);
158
 
159
        return $this->executeDelete($delete);
160
    }
161
 
162
 
163
    /**
164
     *
165
     * @param int $id
166
     * @return boolean
167
     */
168
    public function  delete($id)
169
    {
170
 
171
        $delete = $this->sql->delete(self::_TABLE);
172
        $delete->where->equalTo('id', $id);
173
 
174
        return $this->executeDelete($delete);
175
    }
176
 
177
    /**
178
     *
179
     * @param MyCoachCategory $record
180
     * @return boolean
181
     */
182
    public function insert($record) {
183
        $hydrator = new ObjectPropertyHydrator();
184
        $values = $hydrator->extract($record);
185
        $values = $this->removeEmpty($values);
186
 
187
        $insert = $this->sql->insert(self::_TABLE);
188
        $insert->values($values);
189
        $result = $this->executeInsert($insert);
190
        if($result) {
191
            $record->id = $this->lastInsertId;
192
        }
193
 
194
       return $result;
195
    }
196
 
197
 
198
 
199
    /**
200
     *
201
     * @param MyCoachCategory $record
202
     * @return boolean
203
     */
204
    public function update($record)
205
    {
206
        $hydrator = new ObjectPropertyHydrator();
207
        $values = $hydrator->extract($record);
208
        $values = $this->removeEmpty($values);
209
 
210
        $update = $this->sql->update(self::_TABLE);
211
        $update->set($values);
212
        $update->where->equalTo('id', $record->id);
213
 
214
 
215
        return $this->executeUpdate($update);
216
    }
217
}