Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 3213 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1841 eleazar 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;
1842 eleazar 8
use LeadersLinked\Model\Topic;
1841 eleazar 9
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
10
use Laminas\Paginator\Paginator;
11
use Laminas\Db\ResultSet\HydratingResultSet;
12
use Laminas\Paginator\Adapter\DbSelect;
13
 
14
 
1842 eleazar 15
class TopicMapper extends MapperCommon
1841 eleazar 16
{
17
    const _TABLE = 'tbl_topics';
18
 
19
    /**
20
     *
1842 eleazar 21
     * @var TopicMapper
1841 eleazar 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
1842 eleazar 37
     * @return TopicMapper
1841 eleazar 38
     */
39
    public static function getInstance($adapter)
40
    {
41
        if(self::$_instance == null) {
1842 eleazar 42
            self::$_instance = new TopicMapper($adapter);
1841 eleazar 43
        }
44
        return self::$_instance;
45
    }
46
 
47
    /**
48
     *
49
     * @param int $id
1842 eleazar 50
     * @return Topic
1841 eleazar 51
     */
52
    public function fetchOne($id)
53
    {
1842 eleazar 54
        $prototype = new Topic();
1841 eleazar 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
1842 eleazar 66
     * @return Topic
1841 eleazar 67
     */
68
    public function fetchOneByUuid($uuid)
69
    {
1842 eleazar 70
        $prototype = new Topic();
1841 eleazar 71
        $select = $this->sql->select(self::_TABLE);
72
        $select->where->equalTo('uuid', $uuid);
1849 nelberth 73
 
1841 eleazar 74
        return $this->executeFetchOneObject($select, $prototype);
75
    }
2105 eleazar 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
 
2018 nelberth 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
    }
1841 eleazar 99
 
100
    public function fetchAllMyTrainer()
101
    {
1842 eleazar 102
        $prototype = new Topic;
1841 eleazar 103
 
104
        $select = $this->sql->select(self::_TABLE);
1843 nelberth 105
        $select->where->equalTo('type', Topic::TYPE_MYT);
1841 eleazar 106
        $select->order('id');
107
 
108
        return $this->executeFetchAllObject($select, $prototype);
109
    }
110
 
2209 eleazar 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);
3213 kerby 117
        $select->where->notEqualTo('status', Topic::STATUS_DELETE);
2209 eleazar 118
        $select->order('id');
119
 
120
        return $this->executeFetchAllObject($select, $prototype);
121
    }
122
 
1845 nelberth 123
    public function fetchAllHighPerfromanceTeamsGroup($group_id)
1841 eleazar 124
    {
1842 eleazar 125
        $prototype = new Topic;
1841 eleazar 126
 
127
        $select = $this->sql->select(self::_TABLE);
1843 nelberth 128
        $select->where->equalTo('type', Topic::TYPE_HPTG);
1848 nelberth 129
        $select->where->equalTo('high_performance_group_id', $group_id);
1843 nelberth 130
        $select->where->notEqualTo('status', Topic::STATUS_DELETE);
1841 eleazar 131
        $select->order('id');
132
 
133
        return $this->executeFetchAllObject($select, $prototype);
134
    }
135
 
1845 nelberth 136
    public function fetchAllHighPerfromanceTeamsGroupForo($group_id)
1841 eleazar 137
    {
1842 eleazar 138
        $prototype = new Topic;
1841 eleazar 139
 
140
        $select = $this->sql->select(self::_TABLE);
1843 nelberth 141
        $select->where->equalTo('type', Topic::TYPE_HPTGF);
1848 nelberth 142
        $select->where->equalTo('high_performance_group_id', $group_id);
1843 nelberth 143
        $select->where->notEqualTo('status', Topic::STATUS_DELETE);
1841 eleazar 144
        $select->order('id');
145
 
146
        return $this->executeFetchAllObject($select, $prototype);
147
    }
148
 
149
 
150
    /**
151
     *
3671 efrain 152
     * @param Topic $form
1841 eleazar 153
     * @return boolean
154
     */
1846 nelberth 155
 
156
    public function insert($datos)
1841 eleazar 157
    {
158
        $hydrator = new ObjectPropertyHydrator();
1846 nelberth 159
        $values = $hydrator->extract($datos);
1841 eleazar 160
        $values = $this->removeEmpty($values);
161
        $insert = $this->sql->insert(self::_TABLE);
162
        $insert->values($values);
163
 
2104 eleazar 164
        // echo $insert->getSqlString($this->adapter->platform); exit;
1846 nelberth 165
 
1841 eleazar 166
        $result = $this->executeInsert($insert);
167
        if($result) {
1846 nelberth 168
            $datos->id = $this->lastInsertId;
1841 eleazar 169
        }
1846 nelberth 170
 
1841 eleazar 171
        return $result;
1846 nelberth 172
 
173
    }
1841 eleazar 174
 
175
    /**
176
     *
3671 efrain 177
     * @param Topic $form
1841 eleazar 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
    {
3208 kerby 200
        // $delete = $this->sql->delete(self::_TABLE);
201
        // $delete->where->equalTo('id', $form_id);
1841 eleazar 202
 
3208 kerby 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);
1841 eleazar 211
    }
212
 
213
 
214
}