Proyectos de Subversion LeadersLinked - Services

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 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\Topic;
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 TopicMapper extends MapperCommon
16
{
17
    const _TABLE = 'tbl_topics';
18
 
19
    /**
20
     *
21
     * @var TopicMapper
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 TopicMapper
38
     */
39
    public static function getInstance($adapter)
40
    {
41
        if(self::$_instance == null) {
42
            self::$_instance = new TopicMapper($adapter);
43
        }
44
        return self::$_instance;
45
    }
46
 
47
    /**
48
     *
49
     * @param int $id
50
     * @return Topic
51
     */
52
    public function fetchOne($id)
53
    {
54
        $prototype = new Topic();
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
66
     * @return Topic
67
     */
68
    public function fetchOneByUuid($uuid)
69
    {
70
        $prototype = new Topic();
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
     * @param int $uuid
80
     * @return Topic
81
     */
82
    public function fetchOneByUuidOrTitle($uuidOrTitle)
83
    {
84
        $prototype = new Topic();
85
        $select = $this->sql->select(self::_TABLE);
86
        $select->where->equalTo('uuid', $uuidOrTitle)->or->equalTo('title', $uuidOrTitle);
87
 
88
        return $this->executeFetchOneObject($select, $prototype);
89
    }
90
 
91
    public function fetchOneByUuidAndGroupId($uuid,$group_id)
92
    {
93
        $prototype = new Topic();
94
        $select = $this->sql->select(self::_TABLE);
95
        $select->where->equalTo('uuid', $uuid);
96
        $select->where->equalTo('high_performance_group_id', $group_id);
97
        return $this->executeFetchOneObject($select, $prototype);
98
    }
99
 
100
    public function fetchAllMyTrainer()
101
    {
102
        $prototype = new Topic;
103
 
104
        $select = $this->sql->select(self::_TABLE);
105
        $select->where->equalTo('type', Topic::TYPE_MYT);
106
        $select->order('id');
107
 
108
        return $this->executeFetchAllObject($select, $prototype);
109
    }
110
 
111
    public function fetchAllDevelopment()
112
    {
113
        $prototype = new Topic;
114
 
115
        $select = $this->sql->select(self::_TABLE);
116
        $select->where->equalTo('type', Topic::TYPE_DC);
117
        $select->where->notEqualTo('status', Topic::STATUS_DELETE);
118
        $select->order('id');
119
 
120
        return $this->executeFetchAllObject($select, $prototype);
121
    }
122
 
123
    public function fetchAllHighPerfromanceTeamsGroup($group_id)
124
    {
125
        $prototype = new Topic;
126
 
127
        $select = $this->sql->select(self::_TABLE);
128
        $select->where->equalTo('type', Topic::TYPE_HPTG);
129
        $select->where->equalTo('high_performance_group_id', $group_id);
130
        $select->where->notEqualTo('status', Topic::STATUS_DELETE);
131
        $select->order('id');
132
 
133
        return $this->executeFetchAllObject($select, $prototype);
134
    }
135
 
136
    public function fetchAllHighPerfromanceTeamsGroupForo($group_id)
137
    {
138
        $prototype = new Topic;
139
 
140
        $select = $this->sql->select(self::_TABLE);
141
        $select->where->equalTo('type', Topic::TYPE_HPTGF);
142
        $select->where->equalTo('high_performance_group_id', $group_id);
143
        $select->where->notEqualTo('status', Topic::STATUS_DELETE);
144
        $select->order('id');
145
 
146
        return $this->executeFetchAllObject($select, $prototype);
147
    }
148
 
149
 
150
    /**
151
     *
152
     * @param Topic $form
153
     * @return boolean
154
     */
155
 
156
    public function insert($datos)
157
    {
158
        $hydrator = new ObjectPropertyHydrator();
159
        $values = $hydrator->extract($datos);
160
        $values = $this->removeEmpty($values);
161
        $insert = $this->sql->insert(self::_TABLE);
162
        $insert->values($values);
163
 
164
        // echo $insert->getSqlString($this->adapter->platform); exit;
165
 
166
        $result = $this->executeInsert($insert);
167
        if($result) {
168
            $datos->id = $this->lastInsertId;
169
        }
170
 
171
        return $result;
172
 
173
    }
174
 
175
    /**
176
     *
177
     * @param Topic $form
178
     * @return boolean
179
     */
180
    public function update($form)
181
    {
182
        $hydrator = new ObjectPropertyHydrator();
183
        $values = $hydrator->extract($form);
184
        $values = $this->removeEmpty($values);
185
 
186
        $update = $this->sql->update(self::_TABLE);
187
        $update->set($values);
188
        $update->where->equalTo('id', $form->id);
189
 
190
        return $this->executeUpdate($update);
191
    }
192
 
193
    /**
194
     *
195
     * @param int $form_id
196
     * @return boolean
197
     */
198
    public function delete($form_id)
199
    {
200
        // $delete = $this->sql->delete(self::_TABLE);
201
        // $delete->where->equalTo('id', $form_id);
202
 
203
        // return $this->executeDelete($delete);
204
 
205
        $update = $this->sql->update(self::_TABLE);
206
        $update->set([
207
            'status' => Topic::STATUS_DELETE
208
        ]);
209
        $update->where->equalTo('id', $form_id);
210
        return $this->executeUpdate($update);
211
    }
212
 
213
 
214
}