Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 6388 | | 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\MyCoachQuestion;
6388 efrain 10
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
11
use Laminas\Db\ResultSet\HydratingResultSet;
12
use Laminas\Paginator\Adapter\DbSelect;
13
use Laminas\Paginator\Paginator;
6521 efrain 14
use Laminas\Db\Sql\Expression;
4689 efrain 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
     *
6388 efrain 51
     * @param int $id
4689 efrain 52
     * @return MyCoachQuestion
53
     */
6388 efrain 54
    public function fetchOne($id)
4689 efrain 55
    {
56
 
57
        $select = $this->sql->select(self::_TABLE);
6388 efrain 58
        $select->where->equalTo('id', $id);
59
 
4689 efrain 60
 
61
        $prototype = new MyCoachQuestion();
62
        return $this->executeFetchOneObject($select, $prototype);
63
    }
64
 
6521 efrain 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
    }
4689 efrain 83
 
6521 efrain 84
 
4689 efrain 85
    /**
86
     *
6521 efrain 87
     * @param string $uuid
6388 efrain 88
     * @return MyCoachQuestion
4689 efrain 89
     */
6388 efrain 90
    public function fetchOneByUuid($uuid)
4689 efrain 91
    {
92
 
93
        $select = $this->sql->select(self::_TABLE);
6388 efrain 94
        $select->where->equalTo('uuid', $uuid);
4689 efrain 95
 
6388 efrain 96
 
4689 efrain 97
        $prototype = new MyCoachQuestion();
6388 efrain 98
        return $this->executeFetchOneObject($select, $prototype);
4689 efrain 99
    }
6521 efrain 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
    }
4689 efrain 118
 
6521 efrain 119
 
4689 efrain 120
    /**
121
     *
6388 efrain 122
     * @param  MyCoachQuestion $record
4689 efrain 123
     * @return boolean
124
     */
6388 efrain 125
    public function delete($record)
4689 efrain 126
    {
127
        $delete = $this->sql->delete(self::_TABLE);
6388 efrain 128
        $delete->where->equalTo('id', $record->id);
4689 efrain 129
 
130
        return $this->executeDelete($delete);
131
    }
132
 
6388 efrain 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
 
4689 efrain 175
}