Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 4689 | Ir a la última revisión | | 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;
4689 efrain 14
 
15
 
16
class MyCoachQuestionMapper extends MapperCommon
17
{
18
    const _TABLE = 'tbl_my_coach_questions';
19
 
20
    /**
21
     *
22
     * @var MyCoachQuestionMapper
23
     */
24
    private static $_instance;
25
 
26
    /**
27
     *
28
     * @param AdapterInterface $adapter
29
     */
30
    private function __construct($adapter)
31
    {
32
        parent::__construct($adapter);
33
    }
34
 
35
    /**
36
     *
37
     * @param AdapterInterface $adapter
38
     * @return MyCoachQuestionMapper
39
     */
40
    public static function getInstance($adapter)
41
    {
42
        if(self::$_instance == null) {
43
            self::$_instance = new MyCoachQuestionMapper($adapter);
44
        }
45
        return self::$_instance;
46
    }
47
 
48
    /**
49
     *
6388 efrain 50
     * @param int $id
4689 efrain 51
     * @return MyCoachQuestion
52
     */
6388 efrain 53
    public function fetchOne($id)
4689 efrain 54
    {
55
 
56
        $select = $this->sql->select(self::_TABLE);
6388 efrain 57
        $select->where->equalTo('id', $id);
58
 
4689 efrain 59
 
60
        $prototype = new MyCoachQuestion();
61
        return $this->executeFetchOneObject($select, $prototype);
62
    }
63
 
64
 
65
    /**
66
     *
6388 efrain 67
     * @param int $uuid
68
     * @return MyCoachQuestion
4689 efrain 69
     */
6388 efrain 70
    public function fetchOneByUuid($uuid)
4689 efrain 71
    {
72
 
73
        $select = $this->sql->select(self::_TABLE);
6388 efrain 74
        $select->where->equalTo('uuid', $uuid);
4689 efrain 75
 
6388 efrain 76
 
4689 efrain 77
        $prototype = new MyCoachQuestion();
6388 efrain 78
        return $this->executeFetchOneObject($select, $prototype);
4689 efrain 79
    }
80
 
81
    /**
82
     *
6388 efrain 83
     * @param  MyCoachQuestion $record
4689 efrain 84
     * @return boolean
85
     */
6388 efrain 86
    public function delete($record)
4689 efrain 87
    {
88
        $delete = $this->sql->delete(self::_TABLE);
6388 efrain 89
        $delete->where->equalTo('id', $record->id);
4689 efrain 90
 
91
        return $this->executeDelete($delete);
92
    }
93
 
6388 efrain 94
 
95
    /**
96
     *
97
     * @param MyCoachQuestion $record
98
     * @return boolean
99
     */
100
    public function insert($record)
101
    {
102
        $hydrator = new ObjectPropertyHydrator();
103
        $values = $hydrator->extract($record);
104
        $values = $this->removeEmpty($values);
105
 
106
        $insert = $this->sql->insert(self::_TABLE);
107
        $insert->values($values);
108
 
109
 
110
        $result = $this->executeInsert($insert);
111
        if ($result) {
112
            $record->id = $this->lastInsertId;
113
        }
114
 
115
        return $result;
116
    }
117
 
118
    /**
119
     *
120
     * @param MyCoachQuestion $record
121
     * @return boolean
122
     */
123
    public function update($record)
124
    {
125
        $hydrator = new ObjectPropertyHydrator();
126
        $values = $hydrator->extract($record);
127
        $values = $this->removeEmpty($values);
128
 
129
        $update = $this->sql->update(self::_TABLE);
130
        $update->set($values);
131
        $update->where->equalTo('id', $record->id);
132
 
133
        return $this->executeUpdate($update);
134
    }
135
 
4689 efrain 136
}