Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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