Proyectos de Subversion LeadersLinked - Services

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
declare(strict_types=1);
3
 
4
namespace LeadersLinked\Mapper;
5
 
6
 
7
use LeadersLinked\Mapper\Common\MapperCommon;
8
use Laminas\Db\Adapter\AdapterInterface;
9
use LeadersLinked\Model\MyCoachQuestion;
10
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
11
use Laminas\Db\ResultSet\HydratingResultSet;
12
use Laminas\Paginator\Adapter\DbSelect;
13
use Laminas\Paginator\Paginator;
14
use Laminas\Db\Sql\Expression;
15
 
16
 
17
class MyCoachQuestionMapper extends MapperCommon
18
{
19
    const _TABLE = 'tbl_my_coach_questions';
20
 
21
    /**
22
     *
23
     * @var MyCoachQuestionMapper
24
     */
25
    private static $_instance;
26
 
27
    /**
28
     *
29
     * @param AdapterInterface $adapter
30
     */
31
    private function __construct($adapter)
32
    {
33
        parent::__construct($adapter);
34
    }
35
 
36
    /**
37
     *
38
     * @param AdapterInterface $adapter
39
     * @return MyCoachQuestionMapper
40
     */
41
    public static function getInstance($adapter)
42
    {
43
        if(self::$_instance == null) {
44
            self::$_instance = new MyCoachQuestionMapper($adapter);
45
        }
46
        return self::$_instance;
47
    }
48
 
49
    /**
50
     *
51
     * @param int $id
52
     * @return MyCoachQuestion
53
     */
54
    public function fetchOne($id)
55
    {
56
 
57
        $select = $this->sql->select(self::_TABLE);
58
        $select->where->equalTo('id', $id);
59
 
60
 
61
        $prototype = new MyCoachQuestion();
62
        return $this->executeFetchOneObject($select, $prototype);
63
    }
64
 
65
    /**
66
     *
67
     * @param int $id
68
     * @param int $network_id
69
     * @return MyCoachQuestion
70
     */
71
    public function fetchOneByIdAndNetworkId($id, $network_id)
72
    {
73
 
74
        $select = $this->sql->select(self::_TABLE);
75
        $select->where->equalTo('id', $id);
76
        $select->where->equalTo('network_id', $network_id);
77
 
78
 
79
        $prototype = new MyCoachQuestion();
80
        return $this->executeFetchOneObject($select, $prototype);
81
 
82
    }
83
 
84
 
85
    /**
86
     *
87
     * @param string $uuid
88
     * @return MyCoachQuestion
89
     */
90
    public function fetchOneByUuid($uuid)
91
    {
92
 
93
        $select = $this->sql->select(self::_TABLE);
94
        $select->where->equalTo('uuid', $uuid);
95
 
96
 
97
        $prototype = new MyCoachQuestion();
98
        return $this->executeFetchOneObject($select, $prototype);
99
    }
100
 
101
    /**
102
     *
103
     * @param string $uuid
104
     * @param int $network_id
105
     * @return MyCoachQuestion
106
     */
107
    public function fetchOneByUuidAndNetworkId($uuid, $network_id)
108
    {
109
 
110
        $select = $this->sql->select(self::_TABLE);
111
        $select->where->equalTo('uuid', $uuid);
112
        $select->where->equalTo('network_id', $network_id);
113
 
114
 
115
        $prototype = new MyCoachQuestion();
116
        return $this->executeFetchOneObject($select, $prototype);
117
    }
118
 
119
 
120
    /**
121
     *
122
     * @param  MyCoachQuestion $record
123
     * @return boolean
124
     */
125
    public function delete($record)
126
    {
127
        $delete = $this->sql->delete(self::_TABLE);
128
        $delete->where->equalTo('id', $record->id);
129
 
130
        return $this->executeDelete($delete);
131
    }
132
 
133
 
134
    /**
135
     *
136
     * @param MyCoachQuestion $record
137
     * @return boolean
138
     */
139
    public function insert($record)
140
    {
141
        $hydrator = new ObjectPropertyHydrator();
142
        $values = $hydrator->extract($record);
143
        $values = $this->removeEmpty($values);
144
 
145
        $insert = $this->sql->insert(self::_TABLE);
146
        $insert->values($values);
147
 
148
 
149
        $result = $this->executeInsert($insert);
150
        if ($result) {
151
            $record->id = $this->lastInsertId;
152
        }
153
 
154
        return $result;
155
    }
156
 
157
    /**
158
     *
159
     * @param MyCoachQuestion $record
160
     * @return boolean
161
     */
162
    public function update($record)
163
    {
164
        $hydrator = new ObjectPropertyHydrator();
165
        $values = $hydrator->extract($record);
166
        $values = $this->removeEmpty($values);
167
 
168
        $update = $this->sql->update(self::_TABLE);
169
        $update->set($values);
170
        $update->where->equalTo('id', $record->id);
171
 
172
        return $this->executeUpdate($update);
173
    }
174
 
175
}