Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 6481 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
4689 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\MyCoachAnswer;
6521 efrain 10
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
11
use Laminas\Db\Sql\Expression;
4689 efrain 12
 
13
 
14
class MyCoachAnswerMapper extends MapperCommon
15
{
16
    const _TABLE = 'tbl_my_coach_answers';
17
 
18
    /**
19
     *
20
     * @var MyCoachAnswerMapper
21
     */
22
    private static $_instance;
23
 
24
    /**
25
     *
26
     * @param AdapterInterface $adapter
27
     */
28
    private function __construct($adapter)
29
    {
30
        parent::__construct($adapter);
31
    }
32
 
33
    /**
34
     *
35
     * @param AdapterInterface $adapter
36
     * @return MyCoachAnswerMapper
37
     */
38
    public static function getInstance($adapter)
39
    {
40
        if(self::$_instance == null) {
41
            self::$_instance = new MyCoachAnswerMapper($adapter);
42
        }
43
        return self::$_instance;
44
    }
45
 
46
    /**
47
     *
48
     * @param int $id
49
     * @return MyCoachAnswer
50
     */
6521 efrain 51
    public function fetchOne($id)
4689 efrain 52
    {
53
 
54
        $select = $this->sql->select(self::_TABLE);
55
        $select->where->equalTo('id', $id);
56
 
57
        $prototype = new MyCoachAnswer();
58
        return $this->executeFetchOneObject($select, $prototype);
59
    }
60
 
61
 
62
 
6521 efrain 63
    /**
64
     *
65
     * @param string $uuid
66
     * @return MyCoachAnswer
67
     */
68
    public function fetchOneByUuid($uuid)
69
    {
70
 
71
        $select = $this->sql->select(self::_TABLE);
72
        $select->where->equalTo('uuid', $uuid);
73
 
74
        $prototype = new MyCoachAnswer();
75
        return $this->executeFetchOneObject($select, $prototype);
76
    }
4689 efrain 77
 
78
 
79
 
6521 efrain 80
 
81
 
82
 
83
 
4689 efrain 84
    /**
85
     *
86
     * @param int $question_id
87
     * @return MyCoachAnswer[]
88
     */
89
    public function fetchAllByQuestionId($question_id)
90
    {
91
 
92
        $select = $this->sql->select(self::_TABLE);
93
        $select->where->equalTo('question_id', $question_id);
94
 
95
 
96
        $prototype = new MyCoachAnswer();
97
        return $this->executeFetchAllObject($select, $prototype);
98
    }
99
 
6481 efrain 100
    /**
101
     *
102
     * @param int $question_id
103
     * @return MyCoachAnswer
104
     */
105
    public function fetchOneLastAnswerByQuestionId($question_id)
106
    {
107
 
108
        $select = $this->sql->select(self::_TABLE);
109
        $select->where->equalTo('question_id', $question_id);
110
        $select->order('added_on DESC');
111
 
112
 
113
        $prototype = new MyCoachAnswer();
114
        return $this->executeFetchOneObject($select, $prototype);
115
    }
116
 
6521 efrain 117
 
118
    /**
119
     *
120
     * @param int $my_coach_question_id
121
     * @return int
122
     */
123
    public function fetchCountByMyCoachQuestionId($my_coach_question_id)
124
    {
125
        $select = $this->sql->select(self::_TABLE);
126
        $select->columns(['total' => new Expression('COUNT(*)')]);
127
        $select->where->equalTo('question_id', $my_coach_question_id);
4689 efrain 128
 
6521 efrain 129
        $record = $this->executeFetchOneArray($select);
130
        return $record['total'];
131
    }
4689 efrain 132
 
6521 efrain 133
 
134
    /**
135
     *
136
     * @param int $question_id
137
     * @return boolean
138
     */
139
    public function deleteAllByQuestionId($question_id )
140
    {
141
        $delete = $this->sql->delete(self::_TABLE);
142
        $delete->where->equalTo('question_id', $question_id);
143
 
144
        return $this->executeDelete($delete);
145
    }
146
 
147
 
148
    /**
149
     *
150
     * @param  MyCoachAnswer $record
151
     * @return boolean
152
     */
153
    public function delete($record)
154
    {
155
        $delete = $this->sql->delete(self::_TABLE);
156
        $delete->where->equalTo('id', $record->id);
157
 
158
        return $this->executeDelete($delete);
159
    }
160
 
161
 
162
    /**
163
     *
164
     * @param MyCoachAnswer $record
165
     * @return boolean
166
     */
167
    public function insert($record)
168
    {
169
        $hydrator = new ObjectPropertyHydrator();
170
        $values = $hydrator->extract($record);
171
        $values = $this->removeEmpty($values);
172
 
173
        $insert = $this->sql->insert(self::_TABLE);
174
        $insert->values($values);
175
 
176
 
177
        $result = $this->executeInsert($insert);
178
        if ($result) {
179
            $record->id = $this->lastInsertId;
180
        }
181
 
182
        return $result;
183
    }
184
 
185
    /**
186
     *
187
     * @param MyCoachAnswer $record
188
     * @return boolean
189
     */
190
    public function update($record)
191
    {
192
        $hydrator = new ObjectPropertyHydrator();
193
        $values = $hydrator->extract($record);
194
        $values = $this->removeEmpty($values);
195
 
196
        $update = $this->sql->update(self::_TABLE);
197
        $update->set($values);
198
        $update->where->equalTo('id', $record->id);
199
 
200
        return $this->executeUpdate($update);
201
    }
202
 
203
 
204
 
4689 efrain 205
}