Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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