Proyectos de Subversion LeadersLinked - Services

Rev

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

Rev 143 Rev 242
Línea 32... Línea 32...
32
use LeadersLinked\Model\Comment;
32
use LeadersLinked\Model\Comment;
33
use LeadersLinked\Mapper\ContentReactionMapper;
33
use LeadersLinked\Mapper\ContentReactionMapper;
34
use LeadersLinked\Model\ContentReaction;
34
use LeadersLinked\Model\ContentReaction;
35
use LeadersLinked\Mapper\MyCoachQuestionViewMapper;
35
use LeadersLinked\Mapper\MyCoachQuestionViewMapper;
36
use LeadersLinked\Model\MyCoachQuestionView;
36
use LeadersLinked\Model\MyCoachQuestionView;
-
 
37
use LeadersLinked\Model\User;
Línea 37... Línea 38...
37
 
38
 
38
 
39
 
39
class MyCoachController extends AbstractActionController
40
class MyCoachController extends AbstractActionController
Línea 273... Línea 274...
273
                    'answers' =>  intval($myCoachAnswerMapper->fetchCountByMyCoachQuestionId($record->id), 10),
274
                    'answers' =>  intval($myCoachAnswerMapper->fetchCountByMyCoachQuestionId($record->id), 10),
274
                    'reactions' => intval($contentReactionMapper->fetchCountByMyCoachQuestionId($record->id), 10),
275
                    'reactions' => intval($contentReactionMapper->fetchCountByMyCoachQuestionId($record->id), 10),
275
                    'comments' =>  intval($commentMapper->fetchCountByMyCoachQuestionId($record->id), 10),
276
                    'comments' =>  intval($commentMapper->fetchCountByMyCoachQuestionId($record->id), 10),
276
                    'added_on' => $added_on,
277
                    'added_on' => $added_on,
277
                    'updated_on' => $updated_on,
278
                    'updated_on' => $updated_on,
278
                    'link_add_comment' => $this->url()->fromRoute('my-coach/questions/comments/add', ['id' => $record->uuid]),
279
                    'link_add_comment' => $this->url()->fromRoute('my-coach/questions/comments/add', ['id' => $record->uuid],['force_canonical' => true]),
279
                    'link_view' => $this->url()->fromRoute('my-coach/questions/view', ['id' => $record->uuid]),
280
                    'link_view' => $this->url()->fromRoute('my-coach/questions/view', ['id' => $record->uuid]),
280
                    'link_edit' => $allowEdit ?  $this->url()->fromRoute('my-coach/questions/edit', ['id' => $record->uuid]) : '',
281
                    'link_edit' => $allowEdit ?  $this->url()->fromRoute('my-coach/questions/edit', ['id' => $record->uuid],['force_canonical' => true]) : '',
281
                    'link_delete' => $allowDelete ? $this->url()->fromRoute('my-coach/questions/delete', ['id' =>  $record->uuid]) : '',
282
                    'link_delete' => $allowDelete ? $this->url()->fromRoute('my-coach/questions/delete', ['id' =>  $record->uuid],['force_canonical' => true]) : '',
-
 
283
                    'link_reactions' => $this->url()->fromRoute('my-coach/questions/reactions', ['id' =>  $record->uuid],['force_canonical' => true])
282
                ];
284
                ];
Línea 283... Línea 285...
283
                
285
                
284
                array_push($items, $item);
286
                array_push($items, $item);
Línea 1240... Línea 1242...
1240
        }
1242
        }
Línea 1241... Línea 1243...
1241
        
1243
        
1242
        return new JsonModel($response);
1244
        return new JsonModel($response);
Línea 1243... Línea 1245...
1243
    }
1245
    }
1244
    
1246
    
1245
    public function reactionsAction()
1247
    public function reactionAction()
1246
    {
1248
    {
1247
        return new JsonModel([
1249
        return new JsonModel([
1248
            'success' => false,
1250
            'success' => false,
Línea 1249... Línea 1251...
1249
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
1251
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
Línea -... Línea 1252...
-
 
1252
        ]);
-
 
1253
 
-
 
1254
    }
-
 
1255
    
-
 
1256
    public function reactionsAction()
-
 
1257
    {
-
 
1258
        $id = $this->params()->fromRoute('id');
-
 
1259
 
-
 
1260
        $request = $this->getRequest();
-
 
1261
        if ($request->isGet()) {
-
 
1262
            
-
 
1263
            $currentNetworkPlugin  = $this->plugin('currentNetworkPlugin');
-
 
1264
            $currentNetwork        = $currentNetworkPlugin->getNetwork();
-
 
1265
            
-
 
1266
            $currentUserPlugin  = $this->plugin('currentUserPlugin');
-
 
1267
            $currentUser        = $currentUserPlugin->getUser();
-
 
1268
            
-
 
1269
            $message_error = '';
-
 
1270
            $myCoachAccessControl = MyCoachAccessControl::getInstance($this->adapter);
-
 
1271
            if(!$myCoachAccessControl->hasAccessViewQuestion($currentUser->id, $id, $currentNetwork->id, $message_error)) {
-
 
1272
                return new JsonModel([
-
 
1273
                    'success'   => false,
-
 
1274
                    'data'   => $message_error
-
 
1275
                ]);
-
 
1276
            }
-
 
1277
            
-
 
1278
            $myCoachQuestionMapper = MyCoachQuestionMapper::getInstance($this->adapter);
-
 
1279
            $myCoachQuestion = $myCoachQuestionMapper->fetchOneByUuid($id);
-
 
1280
            
-
 
1281
            
-
 
1282
            $userMapper = UserMapper::getInstance($this->adapter);
-
 
1283
            
-
 
1284
            $items = [];
-
 
1285
            
-
 
1286
            $contentReactionMapper = ContentReactionMapper::getInstance($this->adapter);
-
 
1287
            $records = $contentReactionMapper->fetchAllByMyCoachQuestionId($myCoachQuestion->id);
-
 
1288
            
-
 
1289
            foreach($records as $record)
-
 
1290
            {
-
 
1291
                $user = $userMapper->fetchOne($record->user_id);
-
 
1292
                if($user && $user->status == User::STATUS_ACTIVE) {
-
 
1293
                    
-
 
1294
                    array_push($items, [
-
 
1295
                        'first_name' => $user->first_name,
-
 
1296
                        'last_name' => $user->last_name,
-
 
1297
                        'email' => $user->email,
-
 
1298
                        'image' => $this->url()->fromRoute('storage', ['type' => 'user', 'code' => $user->uuid, 'filename' => $user->image], ['force_canonical' => true]),
-
 
1299
                        'reaction' => $record->reaction,
-
 
1300
                    ]);
-
 
1301
                }
-
 
1302
            }
-
 
1303
            
-
 
1304
            $response = [
-
 
1305
                'success' => true,
-
 
1306
                'data' => $items
-
 
1307
            ];
-
 
1308
            
-
 
1309
            return new JsonModel($response);
-
 
1310
            
-
 
1311
            
-
 
1312
            
-
 
1313
            
-
 
1314
        } else {
-
 
1315
            $response = [
-
 
1316
                'success' => false,
-
 
1317
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
-
 
1318
            ];
-
 
1319
            
Línea 1250... Línea 1320...
1250
        ]);
1320
            return new JsonModel($response);
1251
 
1321
        }
1252
    }
1322
    }