Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

Rev 6056 Rev 6319
Línea 16... Línea 16...
16
 
16
 
17
class CommentMapper extends MapperCommon
17
class CommentMapper extends MapperCommon
18
{
18
{
Línea 19... Línea 19...
19
    const _TABLE = 'tbl_comments';
19
    const _TABLE = 'tbl_comments';
20
 
20
 
21
    
21
 
22
    /**
22
    /**
23
     *
23
     *
24
     * @var CommentMapper
24
     * @var CommentMapper
25
     */
25
     */
26
    private static $_instance;
26
    private static $_instance;
27
    
27
 
28
    /**
28
    /**
29
     *
29
     *
30
     * @param AdapterInterface $adapter
30
     * @param AdapterInterface $adapter
31
     */
31
     */
32
    private function __construct($adapter)
32
    private function __construct($adapter)
33
    {
33
    {
34
        parent::__construct($adapter);
34
        parent::__construct($adapter);
35
    }
35
    }
36
    
36
 
37
    /**
37
    /**
38
     *
38
     *
39
     * @param AdapterInterface $adapter
39
     * @param AdapterInterface $adapter
40
     * @param LoggerInterface $logger
40
     * @param LoggerInterface $logger
41
     * @param int $user_id
41
     * @param int $user_id
42
     * @return \LeadersLinked\Mapper\CommentMapper
42
     * @return \LeadersLinked\Mapper\CommentMapper
43
     */
43
     */
44
    public static function getInstance($adapter)
44
    public static function getInstance($adapter)
45
    {
45
    {
46
        if(self::$_instance == null) {
46
        if (self::$_instance == null) {
47
            self::$_instance = new CommentMapper($adapter);
47
            self::$_instance = new CommentMapper($adapter);
48
        }
48
        }
49
        return self::$_instance;
49
        return self::$_instance;
50
    }
50
    }
51
    
51
 
52
    /**
52
    /**
53
     *
53
     *
54
     * @param int $uuid
54
     * @param int $uuid
55
     * @return Comment
55
     * @return Comment
56
     */
56
     */
57
    public function fetchOneByUuid($uuid)
57
    public function fetchOneByUuid($uuid)
58
    {
58
    {
59
        $prototype = new Comment;
59
        $prototype = new Comment;
60
        $select = $this->sql->select(self::_TABLE);
60
        $select = $this->sql->select(self::_TABLE);
61
        $select->where->equalTo('uuid', $uuid);
61
        $select->where->equalTo('uuid', $uuid);
62
        
62
 
63
        return $this->executeFetchOneObject($select, $prototype);
63
        return $this->executeFetchOneObject($select, $prototype);
64
    }
64
    }
65
    
65
 
66
    
66
 
67
    /**
67
    /**
68
     * 
68
     * 
69
     * @param int $feed_id
69
     * @param int $feed_id
70
     * @return int
70
     * @return int
71
     */
71
     */
72
    public function fetchCountCommentByFeedId($feed_id)
72
    public function fetchCountCommentByFeedId($feed_id)
73
    {
73
    {
74
        $select = $this->sql->select(self::_TABLE);
74
        $select = $this->sql->select(self::_TABLE);
75
        $select->columns(['total' => new Expression('COUNT(*)') ]);
75
        $select->columns(['total' => new Expression('COUNT(*)')]);
76
        $select->where->equalTo('feed_id', $feed_id);
76
        $select->where->equalTo('feed_id', $feed_id);
77
        $select->where->equalTo('relational', Comment::RELATIONAL_FEED);
77
        $select->where->equalTo('relational', Comment::RELATIONAL_FEED);
78
        $select->where->equalTo('status', Feed::STATUS_PUBLISHED);
78
        $select->where->equalTo('status', Feed::STATUS_PUBLISHED);
79
        
79
 
80
        $record = $this->executeFetchOneArray($select);
80
        $record = $this->executeFetchOneArray($select);
81
        return $record['total'];
81
        return $record['total'];
82
    }
82
    }
83
    
83
 
84
    /**
84
    /**
85
     *
85
     *
86
     * @param int $knowledge_area_id
86
     * @param int $knowledge_area_id
87
     * @return int
87
     * @return int
88
     */
88
     */
89
    public function fetchCountCommentByKnowledgeAreaId($knowledge_area_id)
89
    public function fetchCountCommentByKnowledgeAreaId($knowledge_area_id)
90
    {
90
    {
91
        $select = $this->sql->select(self::_TABLE);
91
        $select = $this->sql->select(self::_TABLE);
92
        $select->columns(['total' => new Expression('COUNT(*)') ]);
92
        $select->columns(['total' => new Expression('COUNT(*)')]);
93
        $select->where->equalTo('knowledge_area_id', $knowledge_area_id);
93
        $select->where->equalTo('knowledge_area_id', $knowledge_area_id);
94
        $select->where->equalTo('relational', Comment::RELATIONAL_KNOWLEDGE_AREA);
94
        $select->where->equalTo('relational', Comment::RELATIONAL_KNOWLEDGE_AREA);
95
        
95
 
96
        $select->where->equalTo('status', Feed::STATUS_PUBLISHED);
96
        $select->where->equalTo('status', Feed::STATUS_PUBLISHED);
97
        
97
 
98
        $record = $this->executeFetchOneArray($select);
98
        $record = $this->executeFetchOneArray($select);
99
        return $record['total'];
99
        return $record['total'];
100
    }
100
    }
101
    
101
 
102
    
102
 
103
    /**
103
    /**
104
     *
104
     *
105
     * @param int $post_id
105
     * @param int $post_id
106
     * @return int
106
     * @return int
107
     */
107
     */
108
    public function fetchCountCommentByPostId($post_id)
108
    public function fetchCountCommentByPostId($post_id)
109
    {
109
    {
110
        $select = $this->sql->select(self::_TABLE);
110
        $select = $this->sql->select(self::_TABLE);
111
        $select->columns(['total' => new Expression('COUNT(*)') ]);
111
        $select->columns(['total' => new Expression('COUNT(*)')]);
112
        $select->where->equalTo('post_id', $post_id);
112
        $select->where->equalTo('post_id', $post_id);
113
        $select->where->equalTo('relational', Comment::RELATIONAL_POST);
113
        $select->where->equalTo('relational', Comment::RELATIONAL_POST);
114
        
114
 
115
        $select->where->equalTo('status', Feed::STATUS_PUBLISHED);
115
        $select->where->equalTo('status', Feed::STATUS_PUBLISHED);
116
        
116
 
117
        $record = $this->executeFetchOneArray($select);
117
        $record = $this->executeFetchOneArray($select);
118
        return $record['total'];
118
        return $record['total'];
119
    }
119
    }
120
    
120
 
121
    
121
 
122
    /**
122
    /**
123
     *
123
     *
124
     * @param int $feed_id
124
     * @param int $feed_id
125
     * @return Comment[]
125
     * @return Comment[]
126
     */
126
     */
127
    public function fetchAllByFeedId($feed_id)
127
    public function fetchAllByFeedId($feed_id)
128
    {
128
    {
129
        $prototype = new Comment();
129
        $prototype = new Comment();
130
        
130
 
131
        $select = $this->sql->select(self::_TABLE);
131
        $select = $this->sql->select(self::_TABLE);
132
        $select->where->equalTo('feed_id', $feed_id);
132
        $select->where->equalTo('feed_id', $feed_id);
133
        $select->where->equalTo('relational', Comment::RELATIONAL_FEED);
133
        $select->where->equalTo('relational', Comment::RELATIONAL_FEED);
134
        
134
 
135
        return $this->executeFetchAllObject($select, $prototype);
135
        return $this->executeFetchAllObject($select, $prototype);
136
    }
136
    }
137
    
137
 
138
    /**
138
    /**
139
     *
139
     *
140
     * @param int $post_id
140
     * @param int $post_id
141
     * @return Comment[]
141
     * @return Comment[]
142
     */
142
     */
143
    public function fetchAllByPostId($post_id)
143
    public function fetchAllByPostId($post_id)
144
    {
144
    {
145
        $prototype = new Comment();
145
        $prototype = new Comment();
146
        
146
 
147
        $select = $this->sql->select(self::_TABLE);
147
        $select = $this->sql->select(self::_TABLE);
148
        $select->where->equalTo('post_id', $post_id);
148
        $select->where->equalTo('post_id', $post_id);
149
        $select->where->equalTo('relational', Comment::RELATIONAL_POST);
149
        $select->where->equalTo('relational', Comment::RELATIONAL_POST);
150
        
150
 
151
        return $this->executeFetchAllObject($select, $prototype);
151
        return $this->executeFetchAllObject($select, $prototype);
152
    }
152
    }
153
    
153
 
154
    /**
154
    /**
155
     *
155
     *
156
     * @param int $feed_id
156
     * @param int $feed_id
157
     * @return Comment[]
157
     * @return Comment[]
158
     */
158
     */
159
    public function fetchAllPublishedByFeedId($feed_id)
159
    public function fetchAllPublishedByFeedId($feed_id)
160
    {
160
    {
161
        $prototype = new Comment();
161
        $prototype = new Comment();
162
        
162
 
163
        $select = $this->sql->select(self::_TABLE);
163
        $select = $this->sql->select(self::_TABLE);
164
        $select->where->equalTo('feed_id', $feed_id);
164
        $select->where->equalTo('feed_id', $feed_id);
165
        $select->where->equalTo('status', Feed::STATUS_PUBLISHED);
165
        $select->where->equalTo('status', Feed::STATUS_PUBLISHED);
166
        $select->where->equalTo('relational', Comment::RELATIONAL_FEED);
166
        $select->where->equalTo('relational', Comment::RELATIONAL_FEED);
167
        $select->where->IsNull('parent_id');
167
        $select->where->IsNull('parent_id');
168
        return $this->executeFetchAllObject($select, $prototype);
168
        return $this->executeFetchAllObject($select, $prototype);
169
    }
169
    }
170
    
170
 
171
    
171
 
172
    /**
172
    /**
173
     *
173
     *
174
     * @param int $post_id
174
     * @param int $post_id
175
     * @return Comment[]
175
     * @return Comment[]
176
     */
176
     */
177
    public function fetchAllPublishedByKnowledgeAreaId($knowledge_area_id)
177
    public function fetchAllPublishedByKnowledgeAreaId($knowledge_area_id)
178
    {
178
    {
179
        $prototype = new Comment();
179
        $prototype = new Comment();
180
        
180
 
181
        $select = $this->sql->select(self::_TABLE);
181
        $select = $this->sql->select(self::_TABLE);
182
        $select->where->equalTo('knowledge_area_id', $knowledge_area_id);
182
        $select->where->equalTo('knowledge_area_id', $knowledge_area_id);
183
        $select->where->equalTo('status', Feed::STATUS_PUBLISHED);
183
        $select->where->equalTo('status', Feed::STATUS_PUBLISHED);
184
        $select->where->equalTo('relational', Comment::RELATIONAL_KNOWLEDGE_AREA);
184
        $select->where->equalTo('relational', Comment::RELATIONAL_KNOWLEDGE_AREA);
185
        $select->where->IsNull('parent_id');
185
        $select->where->IsNull('parent_id');
186
        return $this->executeFetchAllObject($select, $prototype);
186
        return $this->executeFetchAllObject($select, $prototype);
187
    }
187
    }
188
    
188
 
189
    
189
 
190
    /**
190
    /**
191
     *
191
     *
192
     * @param int $post_id
192
     * @param int $post_id
193
     * @return Comment[]
193
     * @return Comment[]
194
     */
194
     */
195
    public function fetchAllPublishedByPostId($post_id)
195
    public function fetchAllPublishedByPostId($post_id)
196
    {
196
    {
197
        $prototype = new Comment();
197
        $prototype = new Comment();
198
        
198
 
199
        $select = $this->sql->select(self::_TABLE);
199
        $select = $this->sql->select(self::_TABLE);
200
        $select->where->equalTo('post_id', $post_id);
200
        $select->where->equalTo('post_id', $post_id);
201
        $select->where->equalTo('status', Feed::STATUS_PUBLISHED);
201
        $select->where->equalTo('status', Feed::STATUS_PUBLISHED);
202
        $select->where->equalTo('relational', Comment::RELATIONAL_POST);
202
        $select->where->equalTo('relational', Comment::RELATIONAL_POST);
203
        $select->where->IsNull('parent_id');
203
        $select->where->IsNull('parent_id');
204
        return $this->executeFetchAllObject($select, $prototype);
204
        return $this->executeFetchAllObject($select, $prototype);
205
    }
205
    }
206
    
206
 
207
    public function fetchAllPublishedByCommentId($comment_id)
207
    public function fetchAllPublishedByCommentId($comment_id)
208
    {
208
    {
209
        $prototype = new Comment();
209
        $prototype = new Comment();
210
        
210
 
211
        $select = $this->sql->select(self::_TABLE);
211
        $select = $this->sql->select(self::_TABLE);
212
        $select->where->equalTo('parent_id', $comment_id);
212
        $select->where->equalTo('parent_id', $comment_id);
213
        $select->where->equalTo('status', Feed::STATUS_PUBLISHED);
213
        $select->where->equalTo('status', Feed::STATUS_PUBLISHED);
214
        return $this->executeFetchAllObject($select, $prototype);
214
        return $this->executeFetchAllObject($select, $prototype);
215
    }
215
    }
216
    
216
 
217
    /**
217
    /**
218
     *
218
     *
219
     * @param int $id
219
     * @param int $id
220
     * @return Comment
220
     * @return Comment
221
     */
221
     */
222
    public function fetchOne($id)
222
    public function fetchOne($id)
223
    {
223
    {
224
        $prototype = new Comment();
224
        $prototype = new Comment();
225
        
225
 
226
        $select = $this->sql->select(self::_TABLE);
226
        $select = $this->sql->select(self::_TABLE);
227
        $select->where->equalTo('id', $id);
227
        $select->where->equalTo('id', $id);
228
        
228
 
229
        return $this->executeFetchOneObject($select, $prototype);
229
        return $this->executeFetchOneObject($select, $prototype);
230
    }
230
    }
231
    
231
 
232
    /**
232
    /**
233
     * 
233
     * 
234
     * @param Comment $comment
234
     * @param Comment $comment
235
     * @return boolean
235
     * @return boolean
236
     */
236
     */
237
    public function insert($comment)
237
    public function insert($comment)
238
    {
238
    {
239
        $hydrator = new ObjectPropertyHydrator();
239
        $hydrator = new ObjectPropertyHydrator();
240
        $values = $hydrator->extract($comment);
240
        $values = $hydrator->extract($comment);
241
        $values = $this->removeEmpty($values);
241
        $values = $this->removeEmpty($values);
242
        
242
 
243
        
243
 
244
        $insert = $this->sql->insert(self::_TABLE);
244
        $insert = $this->sql->insert(self::_TABLE);
245
        $insert->values($values);
245
        $insert->values($values);
246
        
246
 
247
        $result = $this->executeInsert($insert);
247
        $result = $this->executeInsert($insert);
248
        if($result) {
248
        if ($result) {
249
           $comment->id = $this->getLastInsertId();
249
            $comment->id = $this->getLastInsertId();
250
        }
250
        }
251
        
-
 
252
        return $result;
251
 
253
        
252
        return $result;
254
    }
253
    }
255
    
254
 
256
    
255
 
257
    /**
256
    /**
258
     *
257
     *
259
     * @param Comment $comment
258
     * @param Comment $comment
260
     * @return boolean
259
     * @return boolean
261
     */
260
     */
262
    public function update($comment)
261
    public function update($comment)
263
    {
262
    {
264
        $hydrator = new ObjectPropertyHydrator();
263
        $hydrator = new ObjectPropertyHydrator();
265
        $values = $hydrator->extract($comment);
264
        $values = $hydrator->extract($comment);
266
        $values = $this->removeEmpty($values);
265
        $values = $this->removeEmpty($values);
267
        
266
 
268
        
267
 
269
        $update = $this->sql->update(self::_TABLE);
268
        $update = $this->sql->update(self::_TABLE);
270
        $update->set($values);
-
 
271
        $update->where->equalTo('id', $comment->id);
-
 
Línea -... Línea 269...
-
 
269
        $update->set($values);
272
        
270
        $update->where->equalTo('id', $comment->id);
-
 
271
 
273
        
272
 
274
 
273
 
275
        
274
 
276
        return $this->executeUpdate($update);
275
        return $this->executeUpdate($update);
277
    }
276
    }
278
    
277
 
279
    
278
 
280
    /**
279
    /**
281
     *
280
     *
282
     * @param int $id
281
     * @param int $id
283
     * @return boolean
282
     * @return boolean
284
     */
283
     */
285
    public function delete($id)
284
    public function delete($id)
286
    {
285
    {
287
       
286
 
288
        
287
 
289
        $update = $this->sql->update(self::_TABLE);
288
        $update = $this->sql->update(self::_TABLE);
290
        $update->set([
289
        $update->set([
291
            'status' => Comment::STATUS_DELETED
290
            'status' => Comment::STATUS_DELETED
292
        ]);
291
        ]);
293
        $update->where->equalTo('id', $id);
292
        $update->where->equalTo('id', $id);
294
        
293
 
295
        return $this->executeUpdate($update);
294
        return $this->executeUpdate($update);
296
    }
295
    }
297
    
296
 
298
    /**
297
    /**
299
     * 
298
     * 
300
     * @param int $feed_id
299
     * @param int $feed_id
301
     * @return boolean
300
     * @return boolean
302
     */
301
     */
303
    public function deleteAllByFeedId($feed_id)
302
    public function deleteAllByFeedId($feed_id)
304
    {
303
    {
305
        
304
 
306
        $update = $this->sql->update(self::_TABLE);
305
        $update = $this->sql->update(self::_TABLE);
307
        $update->set([
306
        $update->set([
308
            'status' => Comment::STATUS_DELETED
307
            'status' => Comment::STATUS_DELETED
309
        ]);
308
        ]);
310
        $update->where->equalTo('feed_id', $feed_id);
309
        $update->where->equalTo('feed_id', $feed_id);
311
        
-
 
312
        return $this->executeUpdate($update);
310
 
-
 
311
        return $this->executeUpdate($update);