Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

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