Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 3639 | Rev 3775 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 3639 Rev 3671
Línea 1... Línea 1...
1
<?php
1
<?php
2
 
-
 
3
declare(strict_types=1);
2
declare(strict_types=1);
Línea 4... Línea 3...
4
 
3
 
Línea 5... Línea -...
5
namespace LeadersLinked\Mapper;
-
 
6
 
-
 
7
use LeadersLinked\Model\Post;
4
namespace LeadersLinked\Mapper;
8
use LeadersLinked\Mapper\Common\MapperCommon;
5
 
-
 
6
use Laminas\Db\Adapter\AdapterInterface;
-
 
7
use Laminas\Paginator\Paginator;
9
use Laminas\Db\Adapter\AdapterInterface;
8
use LeadersLinked\Mapper\Common\MapperCommon;
10
use Laminas\Paginator\PaginatorIterator;
9
use LeadersLinked\Model\Post;
11
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
10
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
12
use Laminas\Db\ResultSet\HydratingResultSet;
-
 
13
use Laminas\Paginator\Adapter\DbSelect;
-
 
Línea 14... Línea 11...
14
use Laminas\Paginator\Paginator;
11
use Laminas\Db\ResultSet\HydratingResultSet;
15
 
12
use Laminas\Paginator\Adapter\DbSelect;
16
 
13
 
17
class PostMapper extends MapperCommon
14
class PostMapper extends MapperCommon {
Línea 18... Línea 15...
18
{
15
    
19
    const _TABLE = 'tbl_posts';
16
    const _TABLE = 'tbl_posts';
20
 
17
    
21
    
18
    
Línea 46... Línea 43...
46
        }
43
        }
47
        return self::$_instance;
44
        return self::$_instance;
48
    }
45
    }
Línea 49... Línea 46...
49
    
46
    
50
    /**
47
    /**
51
     * 
48
     *
52
     * @return Post[]
49
     * @return Post[]
53
     */
50
     */
54
    public function fetchAll()
51
    public function fetchAll()
55
    {
52
    {
56
        $prototype = new Post();
53
        $prototype = new Post();
Línea 57... Línea 54...
57
        $select = $this->sql->select(self::_TABLE);
54
        $select = $this->sql->select(self::_TABLE);
58
        
55
        
Línea 59... Línea -...
59
        return $this->executeFetchAllObject($select, $prototype);
-
 
60
    }
56
        return $this->executeFetchAllObject($select, $prototype);
61
    
57
    }
62
    
58
    
63
    /**
59
    /**
64
     *
60
     *
Línea 86... Línea 82...
86
     */
82
     */
87
    public function fetchAllActiveByNetworkId($network_id)
83
    public function fetchAllActiveByNetworkId($network_id)
88
    {
84
    {
89
        $prototype = new Post();
85
        $prototype = new Post();
90
        $select = $this->sql->select(self::_TABLE);
86
        $select = $this->sql->select(self::_TABLE);
91
        $selec->where->equalTo('network_id', $network_id);
87
        $select->where->equalTo('network_id', $network_id);
92
        $select->where->equalTo('status', Post::STATUS_ACTIVE);
88
        $select->where->equalTo('status', Post::STATUS_ACTIVE);
93
        $select->order('date DESC');
89
        $select->order('date DESC');
Línea 94... Línea 90...
94
        
90
        
Línea 95... Línea 91...
95
        
91
        
Línea 96... Línea -...
96
        //echo $select->getSqlString($this->adapter->platform);
-
 
97
        
-
 
98
        return $this->executeFetchAllObject($select, $prototype);
-
 
99
        
-
 
100
    
-
 
101
    /**
-
 
102
     *
-
 
103
     * @param int $id
-
 
104
     * @return Post
-
 
105
     */
-
 
106
    public function fetchOne($id)
-
 
107
    {
-
 
108
        $prototype = new Post();
-
 
109
        $select = $this->sql->select(self::_TABLE);
-
 
110
        $select->where->equalTo('id', $id);
-
 
111
        
-
 
112
        return $this->executeFetchOneObject($select, $prototype);
-
 
113
    }
-
 
114
    
-
 
115
    
-
 
116
    /**
-
 
117
     *
-
 
118
     * @param string $uuid
-
 
119
     * @return Post
-
 
120
     */
-
 
121
    public function fetchOneByUuid($uuid)
-
 
122
    {
-
 
123
        $prototype = new Post();
-
 
124
        $select = $this->sql->select(self::_TABLE);
-
 
125
        $select->where->equalTo('uuid', $uuid);
-
 
126
        
-
 
127
        return $this->executeFetchOneObject($select, $prototype);
-
 
128
    }
-
 
129
    
-
 
130
    /**
-
 
131
     *
-
 
132
     * @param string $uuid
-
 
133
     * @param int $network_id
-
 
134
     * @return Post
-
 
135
     */
-
 
136
    public function fetchOneByUuidAndNetworkId($uuid, $network_id)
-
 
137
    {
-
 
138
        $prototype = new Post();
-
 
139
        $select = $this->sql->select(self::_TABLE);
-
 
140
        $select->where->equalTo('uuid', $uuid);
92
        //echo $select->getSqlString($this->adapter->platform);
141
        $select->where->equalTo('network_id', $network_id);
-
 
142
        
-
 
143
        return $this->executeFetchOneObject($select, $prototype);
93
        
144
    }
94
        return $this->executeFetchAllObject($select, $prototype);
145
    
95
        
146
    
96
    }
147
    /**
97
        /**
148
     *
98
         *
149
     * @param Post $post
99
         * @param int $id
150
     * @return boolean
-
 
151
     */
100
         * @return Post
152
    public function insert($post)
-
 
153
    {
-
 
154
        $hydrator = new ObjectPropertyHydrator();
101
         */
155
        $values = $hydrator->extract($post);
102
        public function fetchOne($id)
156
        $values = $this->removeEmpty($values);
103
        {
157
        
104
            $prototype = new Post();
158
        $insert = $this->sql->insert(self::_TABLE);
-
 
159
        $insert->values($values);
-
 
160
        
105
            $select = $this->sql->select(self::_TABLE);
Línea 161... Línea -...
161
        $result = $this->executeInsert($insert);
-
 
162
        if($result) {
-
 
163
            $post->id = $this->lastInsertId;
-
 
164
        }
-
 
165
        
-
 
166
        return $result;
-
 
167
        
-
 
168
    }
-
 
169
    
-
 
170
    /**
-
 
171
     *
-
 
172
     * @param Post $post
-
 
173
     * @return boolean
-
 
174
     */
-
 
175
    public function update($post)
-
 
176
    {
-
 
177
        $hydrator = new ObjectPropertyHydrator();
-
 
178
        $values = $hydrator->extract($post);
-
 
179
        $values = $this->removeEmpty($values);
-
 
180
        
-
 
181
        $update = $this->sql->update(self::_TABLE);
-
 
182
        $update->set($values);
-
 
183
        $update->where->equalTo('id', $post->id);
-
 
184
        
-
 
185
        return $this->executeUpdate($update);
-
 
186
    }
-
 
187
    
-
 
188
    /**
-
 
189
     *
-
 
190
     * @param Post $post
-
 
191
     * @return boolean
-
 
Línea -... Línea 106...
-
 
106
            $select->where->equalTo('id', $id);
-
 
107
            
-
 
108
            return $this->executeFetchOneObject($select, $prototype);
-
 
109
        }
-
 
110
        
-
 
111
        
-
 
112
        /**
-
 
113
         *
-
 
114
         * @param string $uuid
-
 
115
         * @return Post
-
 
116
         */
192
     */
117
        public function fetchOneByUuid($uuid)
-
 
118
        {
Línea 193... Línea -...
193
    public function delete($post)
-
 
194
    {
119
            $prototype = new Post();
195
        $delete = $this->sql->delete(self::_TABLE);
-
 
196
        $delete->where->equalTo('id', $post->id);
-
 
197
        
-
 
198
        return $this->executeDelete($delete);
-
 
199
        
-
 
200
    }
-
 
201
    
-
 
202
    /**
-
 
203
     *
-
 
204
     * @param string $search
-
 
205
     * @param int $page
-
 
206
     * @param int $records_per_page
-
 
207
     * @param string $order_field
-
 
208
     * @param string $order_direction
-
 
Línea -... Línea 120...
-
 
120
            $select = $this->sql->select(self::_TABLE);
-
 
121
            $select->where->equalTo('uuid', $uuid);
-
 
122
            
-
 
123
            return $this->executeFetchOneObject($select, $prototype);
209
     * @return Paginator
124
        }
-
 
125
        
-
 
126
 
-
 
127
        
-
 
128
        /**
-
 
129
         *
210
     */
130
         * @param string $uuid
-
 
131
         * @param int $network_id
-
 
132
         * @return Post
-
 
133
         */
211
    public function fetchAllDataTable($search, $page = 1, $records_per_page = 10, $order_field= 'title', $order_direction = 'ASC')
134
        public function fetchOneByUuidAndNetworkId($uuid, $network_id)
212
    {
-
 
Línea -... Línea 135...
-
 
135
        {
-
 
136
            $prototype = new Post();
-
 
137
            $select = $this->sql->select(self::_TABLE);
-
 
138
            $select->where->equalTo('uuid', $uuid);
-
 
139
            $select->where->equalTo('network_id', $network_id);
-
 
140
            
-
 
141
            return $this->executeFetchOneObject($select, $prototype);
-
 
142
        }
-
 
143
        
-
 
144
        
-
 
145
        /**
-
 
146
         *
-
 
147
         * @param Post $post
-
 
148
         * @return boolean
-
 
149
         */
-
 
150
        public function insert($post)
-
 
151
        {
-
 
152
            $hydrator = new ObjectPropertyHydrator();
-
 
153
            $values = $hydrator->extract($post);
-
 
154
            $values = $this->removeEmpty($values);
-
 
155
            
-
 
156
            $insert = $this->sql->insert(self::_TABLE);
Línea -... Línea 157...
-
 
157
            $insert->values($values);
-
 
158
            
-
 
159
            $result = $this->executeInsert($insert);
-
 
160
            if($result) {
-
 
161
                $post->id = $this->lastInsertId;
-
 
162
            }
-
 
163
            
213
        $prototype = new Post();
164
            return $result;
214
        $select = $this->sql->select(self::_TABLE);
165
            
-
 
166
        }
-
 
167
        
-
 
168
        /**
-
 
169
         *
-
 
170
         * @param Post $post
-
 
171
         * @return boolean
-
 
172
         */
-
 
173
        public function update($post)
Línea -... Línea 174...
-
 
174
        {
-
 
175
            $hydrator = new ObjectPropertyHydrator();
-
 
176
            $values = $hydrator->extract($post);
-
 
177
            $values = $this->removeEmpty($values);
-
 
178
            
215
        $select->where->notEqualTo('status', Post::STATUS_DELETE);
179
            $update = $this->sql->update(self::_TABLE);
-
 
180
            $update->set($values);
216
        
181
            $update->where->equalTo('id', $post->id);
217
        if($search) {
182
            
-
 
183
            return $this->executeUpdate($update);
218
            $select->like('title', '%' . $search . '%');
184
        }
-
 
185
        
-
 
186
        /**
Línea -... Línea 187...
-
 
187
         *
-
 
188
         * @param Post $post
-
 
189
         * @return boolean
-
 
190
         */
-
 
191
        public function delete($post)
-
 
192
        {
-
 
193
            $delete = $this->sql->delete(self::_TABLE);
-
 
194
            $delete->where->equalTo('id', $post->id);
-
 
195
            
-
 
196
            return $this->executeDelete($delete);
-
 
197
            
-
 
198
        }
-
 
199
        
-
 
200
        /**
-
 
201
         *
-
 
202
         * @param string $search
-
 
203
         * @param int $network_id
-
 
204
         * @param int $page
-
 
205
         * @param int $records_per_page
-
 
206
         * @param string $order_field
-
 
207
         * @param string $order_direction
-
 
208
         * @return Paginator
-
 
209
         */
-
 
210
        public function fetchAllDataTable($search, $network_id, $page = 1, $records_per_page = 10, $order_field= 'title', $order_direction = 'ASC')
-
 
211
        {
-
 
212
            $prototype = new Post();
-
 
213
            $select = $this->sql->select(self::_TABLE);
-
 
214
            $select->where->notEqualTo('status', Post::STATUS_DELETE);
-
 
215
            $select->where->equalTo('network_id', $network_id);
-
 
216
            
-
 
217
            if($search) {
-
 
218
                $select->like('title', '%' . $search . '%');
-
 
219
            }
-
 
220
            $select->order($order_field . ' ' . $order_direction);
-
 
221
            
Línea 219... Línea -...
219
        }
-
 
220
        $select->order($order_field . ' ' . $order_direction);
-
 
Línea 221... Línea 222...
221
        
222
            
222
        
223