Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Ir a la última revisión | | 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;
8
use LeadersLinked\Model\Topics;
9
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
10
use Laminas\Paginator\Paginator;
11
use Laminas\Db\ResultSet\HydratingResultSet;
12
use Laminas\Paginator\Adapter\DbSelect;
13
 
14
 
15
class TopicsMapper extends MapperCommon
16
{
17
    const _TABLE = 'tbl_topics';
18
 
19
    /**
20
     *
21
     * @var TopicsMapper
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
37
     * @return TopicsMapper
38
     */
39
    public static function getInstance($adapter)
40
    {
41
        if(self::$_instance == null) {
42
            self::$_instance = new TopicsMapper($adapter);
43
        }
44
        return self::$_instance;
45
    }
46
 
47
    /**
48
     *
49
     * @param int $id
50
     * @return Topics
51
     */
52
    public function fetchOne($id)
53
    {
54
        $prototype = new Topics();
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
66
     * @return Topics
67
     */
68
    public function fetchOneByUuid($uuid)
69
    {
70
        $prototype = new Topics();
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
    {
80
        $prototype = new Topics;
81
 
82
        $select = $this->sql->select(self::_TABLE);
83
        $select->where->equalTo('status', Topics::TYPE_MYT);
84
        $select->order('id');
85
 
86
        return $this->executeFetchAllObject($select, $prototype);
87
    }
88
 
89
    public function fetchAllHighPerfromanceGroup()
90
    {
91
        $prototype = new Topics;
92
 
93
        $select = $this->sql->select(self::_TABLE);
94
        $select->where->equalTo('status', Topics::TYPE_HPTG);
95
        $select->order('id');
96
 
97
        return $this->executeFetchAllObject($select, $prototype);
98
    }
99
 
100
    public function fetchAllHighPerfromanceForo()
101
    {
102
        $prototype = new Topics;
103
 
104
        $select = $this->sql->select(self::_TABLE);
105
        $select->where->equalTo('status', Topics::TYPE_HPTGF);
106
        $select->order('id');
107
 
108
        return $this->executeFetchAllObject($select, $prototype);
109
    }
110
 
111
 
112
    /**
113
     *
114
     * @param TopicsForm $form
115
     * @return boolean
116
     */
117
    public function insert($form)
118
    {
119
        $hydrator = new ObjectPropertyHydrator();
120
        $values = $hydrator->extract($form);
121
        $values = $this->removeEmpty($values);
122
 
123
        $insert = $this->sql->insert(self::_TABLE);
124
        $insert->values($values);
125
 
126
        //echo $insert->getSqlString($this->adapter->platform); exit;
127
 
128
        $result = $this->executeInsert($insert);
129
        if($result) {
130
            $form->id = $this->lastInsertId;
131
        }
132
        return $result;
133
    }
134
 
135
    /**
136
     *
137
     * @param TopicsForm $form
138
     * @return boolean
139
     */
140
    public function update($form)
141
    {
142
        $hydrator = new ObjectPropertyHydrator();
143
        $values = $hydrator->extract($form);
144
        $values = $this->removeEmpty($values);
145
 
146
        $update = $this->sql->update(self::_TABLE);
147
        $update->set($values);
148
        $update->where->equalTo('id', $form->id);
149
 
150
        return $this->executeUpdate($update);
151
    }
152
 
153
    /**
154
     *
155
     * @param int $form_id
156
     * @return boolean
157
     */
158
    public function delete($form_id)
159
    {
160
        $delete = $this->sql->delete(self::_TABLE);
161
        $delete->where->equalTo('id', $form_id);
162
 
163
        return $this->executeDelete($delete);
164
    }
165
 
166
 
167
}