Proyectos de Subversion LeadersLinked - Services

Rev

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

Rev 618 Rev 626
Línea 8... Línea 8...
8
use LeadersLinked\Library\Functions;
8
use LeadersLinked\Library\Functions;
9
use LeadersLinked\Mapper\MicrolearningCapsuleMapper;
9
use LeadersLinked\Mapper\MicrolearningCapsuleMapper;
10
use LeadersLinked\Mapper\QueryMapper;
10
use LeadersLinked\Mapper\QueryMapper;
11
use LeadersLinked\Mapper\UserMapper;
11
use LeadersLinked\Mapper\UserMapper;
12
use Laminas\Db\Sql\Select;
12
use Laminas\Db\Sql\Select;
13
use LeadersLinked\Mapper\MicrolearningCapsuleUserMapper;
-
 
14
use LeadersLinked\Mapper\MicrolearningCapsuleCommentMapper;
13
use LeadersLinked\Mapper\MicrolearningCapsuleCommentMapper;
15
use LeadersLinked\Form\Service\CapsuleCommentForm;
14
use LeadersLinked\Form\Service\CapsuleCommentForm;
16
use LeadersLinked\Model\MicrolearningCapsuleComment;
15
use LeadersLinked\Model\MicrolearningCapsuleComment;
17
use LeadersLinked\Model\MicrolearningCapsuleUser;
-
 
18
use LeadersLinked\Model\MicrolearningAnswer;
16
use LeadersLinked\Model\MicrolearningAnswer;
19
use LeadersLinked\Mapper\MicrolearningUserProgressMapper;
17
use LeadersLinked\Mapper\MicrolearningUserProgressMapper;
20
use LeadersLinked\Mapper\MicrolearningSlideMapper;
18
use LeadersLinked\Mapper\MicrolearningSlideMapper;
21
use LeadersLinked\Mapper\MicrolearningUserLogMapper;
19
use LeadersLinked\Mapper\MicrolearningUserLogMapper;
22
use LeadersLinked\Model\MicrolearningUserLog;
20
use LeadersLinked\Model\MicrolearningUserLog;
Línea 122... Línea 120...
122
                    'link_profile' => $this->url()->fromRoute('microlearning/profile',[], ['force_canonical' => true]),
120
                    'link_profile' => $this->url()->fromRoute('microlearning/profile',[], ['force_canonical' => true]),
123
                    'link_topics' => $this->url()->fromRoute('microlearning/topics',[], ['force_canonical' => true]),
121
                    'link_topics' => $this->url()->fromRoute('microlearning/topics',[], ['force_canonical' => true]),
124
                    'link_capsules_pending' => $this->url()->fromRoute('microlearning/capsules-pending',[], ['force_canonical' => true]),
122
                    'link_capsules_pending' => $this->url()->fromRoute('microlearning/capsules-pending',[], ['force_canonical' => true]),
125
                    'link_capsules_completed' => $this->url()->fromRoute('microlearning/capsules-completed',[], ['force_canonical' => true]),
123
                    'link_capsules_completed' => $this->url()->fromRoute('microlearning/capsules-completed',[], ['force_canonical' => true]),
126
                    'link_capsules_in_progress' => $this->url()->fromRoute('microlearning/capsules-in-progress',[], ['force_canonical' => true]),
124
                    'link_capsules_in_progress' => $this->url()->fromRoute('microlearning/capsules-in-progress',[], ['force_canonical' => true]),
127
                  
-
 
128
 
-
 
129
                ]
125
                ]
130
            ]);
126
            ]);
131
        }
127
        }
Línea 132... Línea 128...
132
        
128
        
Línea 196... Línea 192...
196
                return new JsonModel([
192
                return new JsonModel([
197
                    'success' => false,
193
                    'success' => false,
198
                    'data' => 'ERROR_CAPSULE_NOT_FOUND'
194
                    'data' => 'ERROR_CAPSULE_NOT_FOUND'
Línea 199... Línea 195...
199
                    
195
                    
200
                ]);
-
 
201
                
-
 
202
            }
-
 
203
            
-
 
204
            $capsuleUserMapper = MicrolearningCapsuleUserMapper::getInstance($this->adapter);
-
 
205
            $capsuleUser = $capsuleUserMapper->fetchOneByUserIdAndCapsuleId($currentUser->id, $capsule->id);
-
 
206
            if(! $capsuleUser) {
-
 
207
                return new JsonModel([
-
 
208
                    'success' => false,
-
 
209
                    'data' => 'ERROR_YOU_DO_NOT_HAVE_ACCESS_TO_THIS_CAPSULE',
-
 
210
                ]);
196
                ]);
Línea 211... Línea 197...
211
            }
197
            }
212
            
198
            
Línea 213... Línea -...
213
            $userMapper = UserMapper::getInstance($this->adapter);
-
 
214
            $users = [];
199
            $userMapper = UserMapper::getInstance($this->adapter);
Línea 215... Línea 200...
215
            
200
            $users = [];
216
            
201
            
Línea 295... Línea 280...
295
            if(!$capsule) {
280
            if(!$capsule) {
296
                return new JsonModel([
281
                return new JsonModel([
297
                    'success' => false,
282
                    'success' => false,
298
                    'data' => 'ERROR_CAPSULE_NOT_FOUND'
283
                    'data' => 'ERROR_CAPSULE_NOT_FOUND'
Línea 299... Línea 284...
299
                    
284
                    
300
                ]);
-
 
301
                
-
 
302
            }
-
 
303
            
-
 
304
            $capsuleUserMapper = MicrolearningCapsuleUserMapper::getInstance($this->adapter);
-
 
305
            $capsuleUser = $capsuleUserMapper->fetchOneByUserIdAndCapsuleId($currentUser->id, $capsule->id);
-
 
306
            if(! $capsuleUser) {
-
 
307
                return new JsonModel([
-
 
308
                    'success' => false,
-
 
309
                    'data' => 'ERROR_YOU_DO_NOT_HAVE_ACCESS_TO_THIS_CAPSULE',
-
 
310
                ]);
285
                ]);   
Línea 311... Línea 286...
311
            }
286
            }
312
            
287
            
Línea 329... Línea 304...
329
            
304
            
330
            
305
            
331
            $result = $capsuleCommentMapper->delete($capsuleComment->id);
306
            $result = $capsuleCommentMapper->delete($capsuleComment->id);
332
            if($result) {
-
 
333
                $dataCountAndRatingAverage = $capsuleCommentMapper->fetchCountAndRatingAverage($capsule->company_id, $capsule->id);
307
            if($result) {
334
                
-
 
335
                
-
 
336
                
308
                $dataCountAndRatingAverage = $capsuleCommentMapper->fetchCountAndRatingAverage($capsule->company_id, $capsule->id);
337
                
309
 
338
                return new JsonModel([
310
                return new JsonModel([
339
                    'success' => true,
311
                    'success' => true,
340
                    'data' => [
312
                    'data' => [
Línea 351... Línea 323...
351
                    'success' => false,
323
                    'success' => false,
352
                    'data' => $capsuleCommentMapper->getError()
324
                    'data' => $capsuleCommentMapper->getError()
Línea 353... Línea 325...
353
                    
325
                    
354
                ]);
326
                ]);
355
            }
-
 
356
            
-
 
357
            
-
 
358
            
327
            }
Línea 359... Línea 328...
359
        }
328
        }
360
        
329
        
361
        return new JsonModel([
330
        return new JsonModel([
Línea 387... Línea 356...
387
                    
356
                    
Línea 388... Línea 357...
388
                ]);
357
                ]);
Línea 389... Línea -...
389
                
-
 
390
            }
-
 
391
            
-
 
392
            $capsuleUserMapper = MicrolearningCapsuleUserMapper::getInstance($this->adapter);
-
 
393
            $capsuleUser = $capsuleUserMapper->fetchOneByUserIdAndCapsuleId($currentUser->id, $capsule->id);
-
 
394
            if(! $capsuleUser) {
-
 
395
                return new JsonModel([
-
 
396
                    'success' => false,
-
 
397
                    'data' => 'ERROR_YOU_DO_NOT_HAVE_ACCESS_TO_THIS_CAPSULE',
-
 
398
                ]);
-
 
399
            }
-
 
400
            
-
 
401
            //$rawdata = file_get_contents("php://input");
-
 
402
            //  error_log('$rawdata = ' . $rawdata );
358
                
403
            
359
            }
404
            
360
            
Línea 405... Línea -...
405
            $form = new  CapsuleCommentForm();
-
 
406
            $dataPost = $request->getPost()->toArray();
361
            $form = new  CapsuleCommentForm();
Línea 407... Línea 362...
407
            $dataPost['added_on'] = $capsuleMapper->getDatebaseNow();
362
            $dataPost = $request->getPost()->toArray();
408
 
363
            $dataPost['added_on'] = $capsuleMapper->getDatebaseNow();
Línea 1117... Línea 1072...
1117
            $percentIncompleted        = 100;
1072
            $percentIncompleted        = 100;
Línea 1118... Línea 1073...
1118
            
1073
            
1119
            $topicMapper = MicrolearningTopicMapper::getInstance($this->adapter);
1074
            $topicMapper = MicrolearningTopicMapper::getInstance($this->adapter);
Línea 1120... Línea -...
1120
            $topics = $topicMapper->fetchAllActiveByCompanyIdAndIds($company->id, $accessGrantedIds->topics);
-
 
1121
            
1075
            $topics = $topicMapper->fetchAllActiveByCompanyIdAndIds($company->id, $accessGrantedIds->topics);
Línea 1122... Línea 1076...
1122
            //$capsuleMapper = MicrolearningCapsuleMapper::getInstance($this->adapter);
1076
            
Línea 1123... Línea -...
1123
            $progressMapper = MicrolearningUserProgressMapper::getInstance($this->adapter);
-
 
1124
            
-
 
1125
            $topicCapsuleMapper = MicrolearningTopicCapsuleMapper::getInstance($this->adapter);
-
 
1126
            
1077
            $progressMapper = MicrolearningUserProgressMapper::getInstance($this->adapter);
1127
            //$capsuleUserMapper = MicrolearningCapsuleUserMapper::getInstance($this->adapter);
1078
            
1128
            
1079
            $topicCapsuleMapper = MicrolearningTopicCapsuleMapper::getInstance($this->adapter);
1129
            
1080
            
Línea 1145... Línea 1096...
1145
                $capsuleStarted = $capsuleStarted + $resultCount;
1096
                $capsuleStarted = $capsuleStarted + $resultCount;
1146
            }
1097
            }
Línea 1147... Línea 1098...
1147
   
1098
   
Línea 1148... Línea -...
1148
            $capsuleToStart = $capsuleTotal -  $capsuleStarted;
-
 
1149
            
1099
            $capsuleToStart = $capsuleTotal -  $capsuleStarted;
1150
            
1100
            
1151
            if($capsuleTotal > 0) {
1101
            if($capsuleTotal > 0) {
1152
                $percentCompleted = ($capsuleCompleted * 100) /  $capsuleTotal;
1102
                $percentCompleted = ($capsuleCompleted * 100) /  $capsuleTotal;
Línea 1153... Línea -...
1153
                $percentIncompleted = 100 - $percentCompleted;
-
 
1154
            }
-
 
1155
            
1103
                $percentIncompleted = 100 - $percentCompleted;
1156
            
1104
            }
1157
            
1105
            
1158
            return new JsonModel([
1106
            return new JsonModel([
1159
                'success' => true,
1107
                'success' => true,
Línea 1180... Línea 1128...
1180
    
1128
    
1181
    
1129
    
1182
    public function topicsAction()
1130
    public function topicsAction()
-
 
1131
    {
1183
    {
1132
        $request = $this->getRequest();
1184
        $request = $this->getRequest();
1133
 
1185
        if($request->isGet()) {
1134
        if($request->isGet()) {
Línea 1186... Línea -...
1186
            $currentUserPlugin = $this->plugin('currentUserPlugin');
-
 
1187
            $currentUser = $currentUserPlugin->getUser();
1135
            $currentUserPlugin = $this->plugin('currentUserPlugin');
1188
            
1136
            $currentUser = $currentUserPlugin->getUser();
Línea 1189... Línea 1137...
1189
            
1137
            
1190
            $data = [];
1138
            $data = [];
Línea 1391... Línea 1339...
1391
                'image'             => $image,
1339
                'image'             => $image,
1392
                'total_comments'    => $total_comments,
1340
                'total_comments'    => $total_comments,
1393
                'total_rating'      => $total_rating,
1341
                'total_rating'      => $total_rating,
1394
                'progress'          => $progress,
1342
                'progress'          => $progress,
1395
                'completed'         => $completed,
1343
                'completed'         => $completed,
1396
                'order'             => $capsule->order,
-
 
1397
                'added_on'          => $capsule->added_on,
1344
                'added_on'          => $capsule->added_on,
1398
                'updated_on'        => $capsule->updated_on,
1345
                'updated_on'        => $capsule->updated_on,
1399
            ]);
1346
            ]);
1400
        }
1347
        }
Línea 2284... Línea 2231...
2284
    private function getAccessGranted()
2231
    private function getAccessGranted()
2285
    {
2232
    {
2286
        $currentUserPlugin = $this->plugin('currentUserPlugin');
2233
        $currentUserPlugin = $this->plugin('currentUserPlugin');
2287
        $currentUser = $currentUserPlugin->getUser();
2234
        $currentUser = $currentUserPlugin->getUser();
Línea 2288... Línea 2235...
2288
        
2235
        
2289
        $capsuleUserMapper = MicrolearningCapsuleUserMapper::getInstance($this->adapter);
2236
        $topicUserMapper = MicrolearningTopicUserMapper::getInstance($this->adapter);
Línea 2290... Línea 2237...
2290
        $now = $capsuleUserMapper->getDatebaseNow();
2237
        $now = $topicUserMapper->getDatebaseNow();
Línea 2291... Línea 2238...
2291
        
2238
        
Línea 2292... Línea -...
2292
        $records = $capsuleUserMapper->fetchAllActiveByUserId($currentUser->id);
-
 
2293
        
2239
        $records = $topicUserMapper->fetchAllActiveByUserId($currentUser->id);
2294
        $accessGrantedIds = new MicrolearningUserAccessGrantedIds();
2240
        
2295
        
2241
        $accessGrantedIds = new MicrolearningUserAccessGrantedIds();
2296
        
2242
        
2297
        foreach($records as $record)
2243
        foreach($records as $record)
2298
        {
2244
        {
2299
            if($record->access != MicrolearningCapsuleUser::ACCESS_UNLIMITED && $record->access != MicrolearningCapsuleUser::ACCESS_PAY_PERIOD) {
2245
            if($record->access != MicrolearningTopicUser::ACCESS_UNLIMITED && $record->access != MicrolearningTopicUser::ACCESS_PAY_PERIOD) {
2300
                continue;
2246
                continue;
2301
            }
2247
            }
2302
            if($record->access == MicrolearningCapsuleUser::ACCESS_PAY_PERIOD) {
2248
            if($record->access == MicrolearningTopicUser::ACCESS_PAY_PERIOD) {
2303
                if($now < $record->paid_from || $now > $record->paid_to) {
-
 
2304
                    continue;
2249
                if($now < $record->paid_from || $now > $record->paid_to) {
-
 
2250
                    continue;
2305
                }
2251
                }
2306
            }
2252
            }
2307
            
2253
                
Línea -... Línea 2254...
-
 
2254
            // Verificar si la empresa está en la lista de empresas permitidas
2308
            
2255
            if(!in_array($record->company_id, $accessGrantedIds->companies )) {
2309
            if(!in_array($record->company_id, $accessGrantedIds->companies )) {
2256
                array_push($accessGrantedIds->companies, $record->company_id);
2310
                array_push($accessGrantedIds->companies, $record->company_id);
2257
            }
2311
            }
-
 
2312
            
-
 
2313
            if(!in_array($record->topic_id, $accessGrantedIds->topics )) {
-
 
2314
                array_push( $accessGrantedIds->topics, $record->topic_id);
-
 
2315
            }
2258
            
Línea 2316... Línea 2259...
2316
            
2259
            // Verificar si el tópico está en la lista de tópicos permitidos
2317
            if(!in_array($record->capsule_id, $accessGrantedIds->capsules)) {
2260
            if(!in_array($record->topic_id, $accessGrantedIds->topics )) {