Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 2146 | Rev 3208 | Ir a la última revisión | | 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);
117
        $select->order('id');
118
 
119
        return $this->executeFetchAllObject($select, $prototype);
120
    }
121
 
1845 nelberth 122
    public function fetchAllHighPerfromanceTeamsGroup($group_id)
1841 eleazar 123
    {
1842 eleazar 124
        $prototype = new Topic;
1841 eleazar 125
 
126
        $select = $this->sql->select(self::_TABLE);
1843 nelberth 127
        $select->where->equalTo('type', Topic::TYPE_HPTG);
1848 nelberth 128
        $select->where->equalTo('high_performance_group_id', $group_id);
1843 nelberth 129
        $select->where->notEqualTo('status', Topic::STATUS_DELETE);
1841 eleazar 130
        $select->order('id');
131
 
132
        return $this->executeFetchAllObject($select, $prototype);
133
    }
134
 
1845 nelberth 135
    public function fetchAllHighPerfromanceTeamsGroupForo($group_id)
1841 eleazar 136
    {
1842 eleazar 137
        $prototype = new Topic;
1841 eleazar 138
 
139
        $select = $this->sql->select(self::_TABLE);
1843 nelberth 140
        $select->where->equalTo('type', Topic::TYPE_HPTGF);
1848 nelberth 141
        $select->where->equalTo('high_performance_group_id', $group_id);
1843 nelberth 142
        $select->where->notEqualTo('status', Topic::STATUS_DELETE);
1841 eleazar 143
        $select->order('id');
144
 
145
        return $this->executeFetchAllObject($select, $prototype);
146
    }
147
 
148
 
149
    /**
150
     *
1842 eleazar 151
     * @param TopicForm $form
1841 eleazar 152
     * @return boolean
153
     */
1846 nelberth 154
 
155
    public function insert($datos)
1841 eleazar 156
    {
157
        $hydrator = new ObjectPropertyHydrator();
1846 nelberth 158
        $values = $hydrator->extract($datos);
1841 eleazar 159
        $values = $this->removeEmpty($values);
160
        $insert = $this->sql->insert(self::_TABLE);
161
        $insert->values($values);
162
 
2104 eleazar 163
        // echo $insert->getSqlString($this->adapter->platform); exit;
1846 nelberth 164
 
1841 eleazar 165
        $result = $this->executeInsert($insert);
166
        if($result) {
1846 nelberth 167
            $datos->id = $this->lastInsertId;
1841 eleazar 168
        }
1846 nelberth 169
 
1841 eleazar 170
        return $result;
1846 nelberth 171
 
172
    }
1841 eleazar 173
 
174
    /**
175
     *
1842 eleazar 176
     * @param TopicForm $form
1841 eleazar 177
     * @return boolean
178
     */
179
    public function update($form)
180
    {
181
        $hydrator = new ObjectPropertyHydrator();
182
        $values = $hydrator->extract($form);
183
        $values = $this->removeEmpty($values);
184
 
185
        $update = $this->sql->update(self::_TABLE);
186
        $update->set($values);
187
        $update->where->equalTo('id', $form->id);
188
 
189
        return $this->executeUpdate($update);
190
    }
191
 
192
    /**
193
     *
194
     * @param int $form_id
195
     * @return boolean
196
     */
197
    public function delete($form_id)
198
    {
199
        $delete = $this->sql->delete(self::_TABLE);
200
        $delete->where->equalTo('id', $form_id);
201
 
202
        return $this->executeDelete($delete);
203
    }
204
 
205
 
206
}