Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 4689 | | 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\MyCoachQuestionCategory;
6388 efrain 10
use LeadersLinked\Model\MyCoachQuestion;
11
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
4689 efrain 12
 
13
 
14
class MyCoachQuestionCategoryMapper extends MapperCommon
15
{
16
    const _TABLE = 'tbl_my_coach_question_categories';
17
 
18
    /**
19
     *
20
     * @var MyCoachQuestionCategoryMapper
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 MyCoachQuestionCategoryMapper
37
     */
38
    public static function getInstance($adapter)
39
    {
40
        if(self::$_instance == null) {
41
            self::$_instance = new MyCoachQuestionCategoryMapper($adapter);
42
        }
43
        return self::$_instance;
44
    }
45
 
46
    /**
47
     *
48
     * @param int $question_id
49
     * @param int $category_id
50
     * @return MyCoachQuestionCategory
51
     */
52
    public function fetchOneByQuestionIdAndCategoryId($question_id, $category_id )
53
    {
54
 
55
        $select = $this->sql->select(self::_TABLE);
56
        $select->where->equalTo('category_id', $category_id);
57
        $select->where->equalTo('question_id', $question_id);
58
 
59
        $prototype = new MyCoachQuestionCategory();
60
        return $this->executeFetchOneObject($select, $prototype);
61
    }
62
 
63
 
64
 
65
 
66
 
67
 
68
    /**
69
     *
70
     * @param
71
     * @return MyCoachQuestionCategory[]
72
     */
73
    public function fetchAllByQuestionId($question_id)
74
    {
75
 
76
        $select = $this->sql->select(self::_TABLE);
77
        $select->where->equalTo('question_id', $question_id);
78
 
79
 
80
        $prototype = new MyCoachQuestionCategory();
81
        return $this->executeFetchAllObject($select, $prototype);
82
    }
83
 
84
    /**
85
     *
86
     * @param int $question_id
87
     * @param int $category_id
88
     * @return boolean
89
     */
90
    public function deleteByQuestionIdAndCategoryId($question_id, $category_id )
91
    {
92
        $delete = $this->sql->delete(self::_TABLE);
93
        $delete->where->equalTo('category_id', $category_id);
94
        $delete->where->equalTo('question_id', $question_id);
95
 
96
        return $this->executeDelete($delete);
97
    }
98
 
6388 efrain 99
 
100
    /**
101
     *
102
     * @param int $question_id
103
     * @return boolean
104
     */
105
    public function deleteAllByQuestionId($question_id )
106
    {
107
        $delete = $this->sql->delete(self::_TABLE);
108
        $delete->where->equalTo('question_id', $question_id);
109
 
110
        return $this->executeDelete($delete);
111
    }
112
 
113
 
114
    /**
115
     *
116
     * @param int $id
117
     * @return boolean
118
     */
119
    public function delete($id)
120
    {
121
        $delete = $this->sql->delete(self::_TABLE);
122
        $delete->where->equalTo('id', $id);
123
 
124
        return $this->executeDelete($delete);
125
    }
126
 
127
 
128
    /**
129
     *
130
     * @param MyCoachQuestion $record
131
     * @return boolean
132
     */
133
    public function insert($record) {
134
        $hydrator = new ObjectPropertyHydrator();
135
        $values = $hydrator->extract($record);
136
        $values = $this->removeEmpty($values);
137
 
138
        $insert = $this->sql->insert(self::_TABLE);
139
        $insert->values($values);
140
 
141
 
142
        $result = $this->executeInsert($insert);
143
        if ($result) {
144
            $record->id = $this->lastInsertId;
145
        }
146
 
147
        return $result;
148
    }
149
 
150
    /**
151
     *
152
     * @param MyCoachQuestion $record
153
     * @return boolean
154
     */
155
    public function update($record) {
156
        $hydrator = new ObjectPropertyHydrator();
157
        $values = $hydrator->extract($record);
158
        $values = $this->removeEmpty($values);
159
 
160
        $update = $this->sql->update(self::_TABLE);
161
        $update->set($values);
162
        $update->where->equalTo('id', $record->id);
163
 
164
        return $this->executeUpdate($update);
165
    }
166
 
167
 
4689 efrain 168
}