Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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