Proyectos de Subversion LeadersLinked - Services

Rev

Rev 302 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 302 Rev 650
Línea 1... Línea 1...
1
<?php
1
<?php
-
 
2
 
2
declare(strict_types=1);
3
declare(strict_types=1);
Línea 3... Línea 4...
3
 
4
 
Línea 4... Línea 5...
4
namespace LeadersLinked\Mapper;
5
namespace LeadersLinked\Mapper;
Línea 14... Línea 15...
14
 
15
 
15
 
16
 
16
class MediaCategoryMapper extends MapperCommon
17
class MediaCategoryMapper extends MapperCommon
17
{
18
{
18
    const _TABLE = 'tbl_media_categories';
19
    const _TABLE = 'tbl_media_categories';
19
    
20
 
20
    /**
21
    /**
21
     *
22
     *
22
     * @var MediaCategoryMapper
23
     * @var MediaCategoryMapper
23
     */
24
     */
24
    private static $_instance;
25
    private static $_instance;
25
    
26
 
26
    /**
27
    /**
27
     *
28
     *
28
     * @param AdapterInterface $adapter
29
     * @param AdapterInterface $adapter
29
     */
30
     */
30
    private function __construct($adapter)
31
    private function __construct($adapter)
31
    {
32
    {
32
        parent::__construct($adapter);
33
        parent::__construct($adapter);
33
    }
34
    }
34
    
35
 
35
    /**
36
    /**
36
     *
37
     *
37
     * @param AdapterInterface $adapter
38
     * @param AdapterInterface $adapter
38
     * @return MediaCategoryMapper
39
     * @return MediaCategoryMapper
39
     */
40
     */
40
    public static function getInstance($adapter)
41
    public static function getInstance($adapter)
41
    {
42
    {
42
        if(self::$_instance == null) {
43
        if (self::$_instance == null) {
43
            self::$_instance = new MediaCategoryMapper($adapter);
44
            self::$_instance = new MediaCategoryMapper($adapter);
44
        }
45
        }
45
        return self::$_instance;
46
        return self::$_instance;
46
    }
47
    }
47
    
48
 
48
    /**
49
    /**
49
     *
50
     *
50
     * @param int $company_id
51
     * @param int $company_id
Línea 54... Línea 55...
54
    {
55
    {
55
        $select = $this->sql->select();
56
        $select = $this->sql->select();
56
        $select->columns(['total' => new Expression('COUNT(*)')]);
57
        $select->columns(['total' => new Expression('COUNT(*)')]);
57
        $select->from(self::_TABLE);
58
        $select->from(self::_TABLE);
58
        $select->where->equalTo('company_id', $company_id);
59
        $select->where->equalTo('company_id', $company_id);
59
        
60
 
60
        $record = $this->executeFetchOneArray($select);
61
        $record = $this->executeFetchOneArray($select);
61
        return $record['total'];
62
        return $record['total'];
62
    }
63
    }
63
    
-
 
Línea -... Línea 64...
-
 
64
 
64
 
65
 
65
    
66
 
66
    /**
67
    /**
67
     *
68
     *
68
     * @param int $id
69
     * @param int $id
69
     * @return MediaCategory
70
     * @return MediaCategory
70
     */
71
     */
71
    public function fetchOne($id)
72
    public function fetchOne($id)
72
    {
73
    {
73
        $prototype = new MediaCategory();
74
        $prototype = new MediaCategory();
74
        
75
 
75
        $select = $this->sql->select(self::_TABLE);
76
        $select = $this->sql->select(self::_TABLE);
76
        $select->where->equalTo('id', $id);
77
        $select->where->equalTo('id', $id);
77
        
78
 
78
        return $this->executeFetchOneObject($select, $prototype);
79
        return $this->executeFetchOneObject($select, $prototype);
79
    }
80
    }
80
    
81
 
81
    /**
82
    /**
82
     *
83
     *
83
     * @param int $uuid
84
     * @param int $uuid
84
     * @return MediaCategory
85
     * @return MediaCategory
85
     */
86
     */
86
    public function fetchOneByUuid($uuid)
87
    public function fetchOneByUuid($uuid)
87
    {
88
    {
88
        $prototype = new MediaCategory;
89
        $prototype = new MediaCategory;
89
        $select = $this->sql->select(self::_TABLE);
90
        $select = $this->sql->select(self::_TABLE);
90
        $select->where->equalTo('uuid', $uuid);
91
        $select->where->equalTo('uuid', $uuid);
91
        
92
 
92
        return $this->executeFetchOneObject($select, $prototype);
93
        return $this->executeFetchOneObject($select, $prototype);
93
    }
94
    }
94
    
95
 
95
    /**
96
    /**
96
     *
97
     *
97
     * @param int $company_id
98
     * @param int $company_id
98
     * @return MediaCategory[]
99
     * @return MediaCategory[]
99
     */
100
     */
100
    public function fetchAllByCompanyId($company_id)
101
    public function fetchAllByCompanyId($company_id)
101
    {
102
    {
102
        $prototype = new MediaCategory();
103
        $prototype = new MediaCategory();
103
        
104
 
104
        $select = $this->sql->select(self::_TABLE);
105
        $select = $this->sql->select(self::_TABLE);
105
        $select->where->equalTo('company_id', $company_id);
106
        $select->where->equalTo('company_id', $company_id);
106
        $select->order(['name']);
107
        $select->order(['name']);
107
        
108
 
108
        return $this->executeFetchAllObject($select, $prototype);
109
        return $this->executeFetchAllObject($select, $prototype);
109
    }
-
 
Línea -... Línea 110...
-
 
110
    }
110
    
111
 
111
 
112
 
112
    
113
 
113
    /**
114
    /**
114
     *
115
     *
115
     * @param int $companyId
116
     * @param int $companyId
Línea 119... Línea 120...
119
     * @param string $order_field
120
     * @param string $order_field
120
     * @param string $order_direction
121
     * @param string $order_direction
121
     * @return Paginator
122
     * @return Paginator
122
     * 
123
     * 
123
     */
124
     */
124
    public function fetchAllDataTableByCompanyId($companyId, $search, $page = 1, $records_per_page = 10, $order_field= 'file', $order_direction = 'ASC')
125
    public function fetchAllDataTableByCompanyId($companyId, $search, $page = 1, $records_per_page = 10, $order_field = 'file', $order_direction = 'ASC')
125
    {
126
    {
126
        $prototype = new MediaCategory();
127
        $prototype = new MediaCategory();
127
        $select = $this->sql->select(self::_TABLE);
128
        $select = $this->sql->select(self::_TABLE);
128
        $select->where->equalTo('company_id', $companyId);
129
        $select->where->equalTo('company_id', $companyId);
129
        
130
 
130
        if($search) {
131
        if ($search) {
131
            $select->where->like('name', '%' . $search . '%');
132
            $select->where->like('name', '%' . $search . '%');
132
        }
133
        }
133
        $select->order($order_field . ' ' . $order_direction);
134
        $select->order($order_field . ' ' . $order_direction);
134
        
135
 
135
        //echo $select->getSqlString($this->adapter->platform); exit;
136
        //echo $select->getSqlString($this->adapter->platform); exit;
136
        
137
 
137
        $hydrator   = new ObjectPropertyHydrator();
138
        $hydrator   = new ObjectPropertyHydrator();
138
        $resultset  = new HydratingResultSet($hydrator, $prototype);
139
        $resultset  = new HydratingResultSet($hydrator, $prototype);
139
        
140
 
140
        $adapter = new DbSelect($select, $this->sql, $resultset);
141
        $adapter = new DbSelect($select, $this->sql, $resultset);
141
        $paginator = new Paginator($adapter);
142
        $paginator = new Paginator($adapter);
142
        $paginator->setItemCountPerPage($records_per_page);
143
        $paginator->setItemCountPerPage($records_per_page);
143
        $paginator->setCurrentPageNumber($page);
144
        $paginator->setCurrentPageNumber($page);
144
        
145
 
145
        
146
 
146
        return $paginator;
147
        return $paginator;
147
    }
148
    }
148
    
149
 
149
    
150
 
150
    /**
151
    /**
151
     *
152
     *
152
     * @param MediaCategory $mediaLibrary
153
     * @param MediaCategory $mediaLibrary
153
     * @return boolean
154
     * @return boolean
154
     */
155
     */
155
    public function insert($mediaLibrary)
156
    public function insert($mediaLibrary)
156
    {
157
    {
157
        $hydrator = new ObjectPropertyHydrator();
158
        $hydrator = new ObjectPropertyHydrator();
158
        $values = $hydrator->extract($mediaLibrary);
159
        $values = $hydrator->extract($mediaLibrary);
159
        $values = $this->removeEmpty($values);
160
        $values = $this->removeEmpty($values);
160
                
161
 
161
        $insert = $this->sql->insert(self::_TABLE);
162
        $insert = $this->sql->insert(self::_TABLE);
162
        $insert->values($values);
163
        $insert->values($values);
Línea 163... Línea 164...
163
 
164
 
164
        $result = $this->executeInsert($insert);
165
        $result = $this->executeInsert($insert);
165
        if($result) {
166
        if ($result) {
166
            $mediaLibrary->id = $this->lastInsertId;
167
            $mediaLibrary->id = $this->lastInsertId;
167
        }
168
        }
168
        return $result;
169
        return $result;
169
    }
170
    }
170
    
171
 
171
    /**
172
    /**
172
     *
173
     *
173
     * @param MediaCategory $mediaLibrary
174
     * @param MediaCategory $mediaLibrary
174
     * @return boolean
175
     * @return boolean
Línea 177... Línea 178...
177
    {
178
    {
Línea 178... Línea 179...
178
 
179
 
179
        $hydrator = new ObjectPropertyHydrator();
180
        $hydrator = new ObjectPropertyHydrator();
180
        $values = $hydrator->extract($mediaLibrary);
181
        $values = $hydrator->extract($mediaLibrary);
181
        $values = $this->removeEmpty($values);
182
        $values = $this->removeEmpty($values);
182
        
183
 
183
        $update = $this->sql->update(self::_TABLE);
184
        $update = $this->sql->update(self::_TABLE);
184
        $update->set($values);
185
        $update->set($values);
185
        $update->where->equalTo('id', $mediaLibrary->id);
186
        $update->where->equalTo('id', $mediaLibrary->id);
Línea 186... Línea 187...
186
        
187
 
187
 
188
 
Línea 188... Línea 189...
188
        return $this->executeUpdate($update);
189
        return $this->executeUpdate($update);
Línea 195... Línea 196...
195
     */
196
     */
196
    public function delete($mediaLibrary)
197
    public function delete($mediaLibrary)
197
    {
198
    {
198
        $delete = $this->sql->delete(self::_TABLE);
199
        $delete = $this->sql->delete(self::_TABLE);
199
        $delete->where->equalTo('id', $mediaLibrary->id);
200
        $delete->where->equalTo('id', $mediaLibrary->id);
200
        
201
 
201
        return $this->executeDelete($delete);
202
        return $this->executeDelete($delete);
202
    }
203
    }
203
    
-
 
204
 
-
 
205
    
-
 
206
}
-
 
207
204
}
-
 
205