Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 630 | Rev 2824 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
630 efrain 1
<?php
2
 
3
declare(strict_types=1);
4
 
5
namespace LeadersLinked\Mapper;
6
 
7
use Laminas\Db\Adapter\AdapterInterface;
8
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
9
use LeadersLinked\Model\Behavior;
10
use LeadersLinked\Mapper\Common\MapperCommon;
11
 
12
class BehaviorMapper extends MapperCommon {
13
 
14
    const _TABLE = 'tbl_behaviors';
15
 
16
    /**
17
     *
18
     * @var BehaviorMapper
19
     */
20
    private static $_instance;
21
 
22
    /**
23
     *
24
     * @param AdapterInterface $adapter
25
     */
26
    private function __construct($adapter) {
27
        parent::__construct($adapter);
28
    }
29
 
30
    /**
31
     *
32
     * @param AdapterInterface $adapter
33
     * @return BehaviorMapper
34
     */
35
    public static function getInstance($adapter) {
36
        if (self::$_instance == null) {
37
            self::$_instance = new BehaviorMapper($adapter);
38
        }
39
        return self::$_instance;
40
    }
41
 
42
    /**
43
     *
44
     * @param int $id
45
     * @return Behavior
46
     */
47
    public function fetchOne($id) {
48
        $select = $this->sql->select(self::_TABLE);
49
        $select->where->equalTo('id', $id);
50
        $select->limit(1);
51
 
52
        $prototype = new Behavior();
53
        return $this->executeFetchOneObject($select, $prototype);
54
    }
55
 
56
    /**
57
     *
58
     * @param int $company_id
59
     * @param int $behavior_type_id_default
60
     * @return Behavior
61
     */
62
    public function fetchOneByCompanyId($company_id, $behavior_type_id_default) {
63
        $select = $this->sql->select(self::_TABLE);
64
        $select->where->equalTo('company_id', $company_id);
65
        $select->limit(1);
66
 
67
        $prototype = new Behavior();
68
        return $this->executeFetchOneObject($select, $prototype);
69
    }
70
 
71
    /**
72
     *
73
     * @param int $company_id
74
     * @param int $behavior_type_id_default
75
     * @return Behavior[]
76
     */
77
    public function fetchAllCompanyId($company_id) {
78
        $select = $this->sql->select(self::_TABLE);
79
        $select->where->equalTo('company_id', $company_id);
80
 
81
        $prototype = new Behavior();
82
        return $this->executeFetchAllObject($select, $prototype);
83
    }
84
 
85
    /**
86
     *
87
     * @return Behavior[]
88
     */
89
    public function fetchAllByDefault() {
90
        $select = $this->sql->select(self::_TABLE);
91
        $select->where->isNull('company_id');
92
 
93
        $prototype = new Behavior();
94
        return $this->executeFetchAllObject($select, $prototype);
95
    }
96
 
97
    /**
98
     *
99
     * @param string $uuid
100
     * @return Behavior
101
     */
102
    public function fetchOneByUuid($uuid) {
103
        $select = $this->sql->select(self::_TABLE);
104
        $select->where->equalTo('uuid', $uuid);
105
        $select->limit(1);
106
 
107
        $prototype = new Behavior();
108
        return $this->executeFetchOneObject($select, $prototype);
109
    }
110
 
111
     /**
112
     *
113
     * @param string $description
114
     * @param string $company_id
115
     * @return Behavior
116
     */
117
    public function fetchOneByDescription($description, $company_id) {
118
        $select = $this->sql->select(self::_TABLE);
119
        $select->where->equalTo('description', $description);
120
        $company_id ?
121
        $select->where->equalTo('company_id', $company_id):
122
         $select->where->isNull('company_id');
123
        $select->limit(1);
124
 
125
        $prototype = new Behavior();
126
        return $this->executeFetchOneObject($select, $prototype);
127
    }
128
 
129
 
130
 
131
    /**
132
     *
133
     * @param Behavior $behaviorType
134
     * @return boolean
135
     */
136
    public function insert($behaviorType) {
137
        $hydrator = new ObjectPropertyHydrator();
138
        $values = $hydrator->extract($behaviorType);
139
 
140
        $insert = $this->sql->insert(self::_TABLE);
141
        $insert->values($values);
142
 
143
 
144
        $result = $this->executeInsert($insert);
145
        if ($result) {
146
            $behaviorType->id = $this->lastInsertId;
147
        }
148
 
149
        return $result;
150
    }
151
 
152
    /**
153
     *
154
     * @param Behavior $behaviorType
155
     * @return boolean
156
     */
157
    public function update($behaviorType) {
2823 kerby 158
 
159
        print_r($behaviorType);
630 efrain 160
        $hydrator = new ObjectPropertyHydrator();
161
        $values = $hydrator->extract($behaviorType);
162
 
163
        $update = $this->sql->update(self::_TABLE);
164
        $update->set($values);
165
        $update->where->equalTo('id', $behaviorType->id);
166
 
167
        return $this->executeUpdate($update);
168
    }
169
 
170
    /**
171
     *
172
     * @param Behavior $behaviorType
173
     * @return boolean
174
     */
175
    public function delete($behaviorType) {
176
        $delete = $this->sql->delete(self::_TABLE);
177
        $delete->where->equalTo('id', $behaviorType->id);
178
 
179
        return $this->executeDelete($delete);
180
    }
181
 
182
    /**
183
     *
184
     * @return boolean
185
     */
186
    public function truncate() {
187
        $sql = 'DELETE FROM ' . self::_TABLE;
188
        if ($this->executeSentenceWithParameters($sql)) {
189
            $sql = 'ALTER TABLE ' . self::_TABLE . ' AUTO_INCREMENT = 1 ';
190
            return $this->executeSentenceWithParameters($sql);
191
        }
192
        return false;
193
    }
194
 
195
    /**
196
     *
197
     * @return Behavior[]
198
     */
199
    public function fetchAllActives() {
200
        $prototype = new Behavior();
201
        $select = $this->sql->select(self::_TABLE);
202
        $select->where->equalTo('status', Behavior::STATUS_ACTIVE);
203
        $select->order('name ASC');
204
 
205
        return $this->executeFetchAllObject($select, $prototype);
206
    }
207
 
208
    /**
209
     *
210
     * @return Behavior[]
211
     */
212
    public function fetchAllActivesByDefault() {
213
        $prototype = new Behavior();
214
        $select = $this->sql->select(self::_TABLE);
215
        $select->where->equalTo('status', Behavior::STATUS_ACTIVE);
216
        $select->where->isNull('company_id');
217
        $select->order('name ASC');
218
 
219
        return $this->executeFetchAllObject($select, $prototype);
220
    }
221
 
222
    /**
223
     *
224
     * @return Behavior[]
225
     */
226
    public function fetchAllActivesByCompanyId($company_id) {
227
        $prototype = new Behavior();
228
        $select = $this->sql->select(self::_TABLE);
229
        $select->where->equalTo('company_id', $company_id);
230
        $select->where->equalTo('status', Behavior::STATUS_ACTIVE);
231
        $select->order('name ASC');
232
 
233
        return $this->executeFetchAllObject($select, $prototype);
234
    }
235
 
236
    /**
237
     *
238
     * @return Behavior[]
239
     */
240
    public function fetchAllByCompanyId($company_id) {
241
        $prototype = new Behavior();
242
        $select = $this->sql->select(self::_TABLE);
243
        $select->where->equalTo('company_id', $company_id);
244
        $select->order('name ASC');
245
 
246
        return $this->executeFetchAllObject($select, $prototype);
247
    }
248
 
249
     /**
250
     *
251
     * @param int $company_id
252
     * @param $behavior_id_default
253
     * @return Behavior
254
     */
255
    public function fetchOneByCompanyIdAndCompetencyIdDefault($company_id, $behavior_id_default)
256
    {
257
        $select = $this->sql->select(self::_TABLE);
258
        $select->where->equalTo('company_id', $company_id);
259
        $select->where->equalTo('behavior_id_default', $behavior_id_default);
260
        $select->limit(1);
261
 
262
        $prototype = new Behavior();
263
        return $this->executeFetchOneObject($select, $prototype);
264
    }
265
 
266
}