Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 2105 | Rev 2146 | 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);
2145 eleazar 73
        $select->where->notEqualTo('status', Topic::STATUS_DELETE);
1849 nelberth 74
 
1841 eleazar 75
        return $this->executeFetchOneObject($select, $prototype);
76
    }
2105 eleazar 77
 
78
    /**
79
     *
80
     * @param int $uuid
81
     * @return Topic
82
     */
83
    public function fetchOneByUuidOrTitle($uuidOrTitle)
84
    {
85
        $prototype = new Topic();
86
        $select = $this->sql->select(self::_TABLE);
87
        $select->where->equalTo('uuid', $uuidOrTitle)->or->equalTo('title', $uuidOrTitle);
88
 
89
        return $this->executeFetchOneObject($select, $prototype);
90
    }
91
 
2018 nelberth 92
    public function fetchOneByUuidAndGroupId($uuid,$group_id)
93
    {
94
        $prototype = new Topic();
95
        $select = $this->sql->select(self::_TABLE);
96
        $select->where->equalTo('uuid', $uuid);
97
        $select->where->equalTo('high_performance_group_id', $group_id);
98
        return $this->executeFetchOneObject($select, $prototype);
99
    }
1841 eleazar 100
 
101
    public function fetchAllMyTrainer()
102
    {
1842 eleazar 103
        $prototype = new Topic;
1841 eleazar 104
 
105
        $select = $this->sql->select(self::_TABLE);
1843 nelberth 106
        $select->where->equalTo('type', Topic::TYPE_MYT);
1841 eleazar 107
        $select->order('id');
108
 
109
        return $this->executeFetchAllObject($select, $prototype);
110
    }
111
 
1845 nelberth 112
    public function fetchAllHighPerfromanceTeamsGroup($group_id)
1841 eleazar 113
    {
1842 eleazar 114
        $prototype = new Topic;
1841 eleazar 115
 
116
        $select = $this->sql->select(self::_TABLE);
1843 nelberth 117
        $select->where->equalTo('type', Topic::TYPE_HPTG);
1848 nelberth 118
        $select->where->equalTo('high_performance_group_id', $group_id);
1843 nelberth 119
        $select->where->notEqualTo('status', Topic::STATUS_DELETE);
1841 eleazar 120
        $select->order('id');
121
 
122
        return $this->executeFetchAllObject($select, $prototype);
123
    }
124
 
1845 nelberth 125
    public function fetchAllHighPerfromanceTeamsGroupForo($group_id)
1841 eleazar 126
    {
1842 eleazar 127
        $prototype = new Topic;
1841 eleazar 128
 
129
        $select = $this->sql->select(self::_TABLE);
1843 nelberth 130
        $select->where->equalTo('type', Topic::TYPE_HPTGF);
1848 nelberth 131
        $select->where->equalTo('high_performance_group_id', $group_id);
1843 nelberth 132
        $select->where->notEqualTo('status', Topic::STATUS_DELETE);
1841 eleazar 133
        $select->order('id');
134
 
135
        return $this->executeFetchAllObject($select, $prototype);
136
    }
137
 
138
 
139
    /**
140
     *
1842 eleazar 141
     * @param TopicForm $form
1841 eleazar 142
     * @return boolean
143
     */
1846 nelberth 144
 
145
    public function insert($datos)
1841 eleazar 146
    {
147
        $hydrator = new ObjectPropertyHydrator();
1846 nelberth 148
        $values = $hydrator->extract($datos);
1841 eleazar 149
        $values = $this->removeEmpty($values);
150
        $insert = $this->sql->insert(self::_TABLE);
151
        $insert->values($values);
152
 
2104 eleazar 153
        // echo $insert->getSqlString($this->adapter->platform); exit;
1846 nelberth 154
 
1841 eleazar 155
        $result = $this->executeInsert($insert);
156
        if($result) {
1846 nelberth 157
            $datos->id = $this->lastInsertId;
1841 eleazar 158
        }
1846 nelberth 159
 
1841 eleazar 160
        return $result;
1846 nelberth 161
 
162
    }
1841 eleazar 163
 
164
    /**
165
     *
1842 eleazar 166
     * @param TopicForm $form
1841 eleazar 167
     * @return boolean
168
     */
169
    public function update($form)
170
    {
171
        $hydrator = new ObjectPropertyHydrator();
172
        $values = $hydrator->extract($form);
173
        $values = $this->removeEmpty($values);
174
 
175
        $update = $this->sql->update(self::_TABLE);
176
        $update->set($values);
177
        $update->where->equalTo('id', $form->id);
178
 
179
        return $this->executeUpdate($update);
180
    }
181
 
182
    /**
183
     *
184
     * @param int $form_id
185
     * @return boolean
186
     */
187
    public function delete($form_id)
188
    {
189
        $delete = $this->sql->delete(self::_TABLE);
190
        $delete->where->equalTo('id', $form_id);
191
 
192
        return $this->executeDelete($delete);
193
    }
194
 
195
 
196
}