Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

| Ultima modificación | Ver Log |

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