Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

Rev 6240 Rev 6388
Línea 35... Línea 35...
35
use LeadersLinked\Model\ContentReaction;
35
use LeadersLinked\Model\ContentReaction;
36
use LeadersLinked\Form\Feed\CommentForm;
36
use LeadersLinked\Form\Feed\CommentForm;
37
use LeadersLinked\Model\Comment;
37
use LeadersLinked\Model\Comment;
38
use LeadersLinked\Form\Feed\CreateGroupCompanyForm;
38
use LeadersLinked\Form\Feed\CreateGroupCompanyForm;
39
use LeadersLinked\Model\CompanyUser;
39
use LeadersLinked\Model\CompanyUser;
-
 
40
use LeadersLinked\Model\FastSurvey;
40
use LeadersLinked\Model\VideoConvert;
41
use LeadersLinked\Model\VideoConvert;
41
use LeadersLinked\Mapper\VideoConvertMapper;
42
use LeadersLinked\Mapper\VideoConvertMapper;
42
use LeadersLinked\Mapper\CompanyMapper;
43
use LeadersLinked\Mapper\CompanyMapper;
43
use LeadersLinked\Model\Company;
44
use LeadersLinked\Model\Company;
44
use LeadersLinked\Model\Group;
45
use LeadersLinked\Model\Group;
Línea 48... Línea 49...
48
use LeadersLinked\Mapper\NotificationMapper;
49
use LeadersLinked\Mapper\NotificationMapper;
49
use LeadersLinked\Mapper\UserNotificationSettingMapper;
50
use LeadersLinked\Mapper\UserNotificationSettingMapper;
50
use LeadersLinked\Mapper\EmailTemplateMapper;
51
use LeadersLinked\Mapper\EmailTemplateMapper;
51
use LeadersLinked\Model\EmailTemplate;
52
use LeadersLinked\Model\EmailTemplate;
52
use LeadersLinked\Library\QueueEmail;
53
use LeadersLinked\Library\QueueEmail;
53
use LeadersLinked\Mapper\UtilMapper;
54
use LeadersLinked\Mapper\FastSurveyMapper;
-
 
55
use LeadersLinked\Mapper\FastSurveyVoteMapper;
-
 
56
use LeadersLinked\Model\FastSurveyVote;
Línea 54... Línea 57...
54
 
57
 
55
 
58
 
56
class FeedController extends AbstractActionController
59
class FeedController extends AbstractActionController
Línea 115... Línea 118...
115
    {
118
    {
116
        $id = $this->params()->fromRoute('id');
119
        $id = $this->params()->fromRoute('id');
Línea 117... Línea 120...
117
 
120
 
118
        $request = $this->getRequest();
121
        $request = $this->getRequest();
119
        if ($request->isPost()) {
-
 
120
 
-
 
121
 
-
 
122
 
122
        if ($request->isPost()) {
-
 
123
            $feedMapper = FeedMapper::getInstance($this->adapter);
-
 
124
            $now = $feedMapper->getDatebaseNow();
123
            $feedMapper = FeedMapper::getInstance($this->adapter);
125
            
-
 
126
            $feed = $feedMapper->fetchOneByUuid($id);
124
            $feed = $feedMapper->fetchOneByUuid($id);
127
            
125
            if (!$feed) {
128
            if (!$feed) {
126
                $response = [
129
                $response = [
127
                    'success' => false,
130
                    'success' => false,
128
                    'data' => 'ERROR_POST_NOT_FOUND'
131
                    'data' => 'ERROR_POST_NOT_FOUND'
Línea 133... Línea 136...
133
            $dataPost = $request->getPost()->toArray();
136
            $dataPost = $request->getPost()->toArray();
134
            $form = new CommentForm();
137
            $form = new CommentForm();
135
            $form->setData($dataPost);
138
            $form->setData($dataPost);
Línea 136... Línea 139...
136
 
139
 
137
            if ($form->isValid()) {
-
 
138
                $utilMapper = UtilMapper::getInstance($this->adapter);
-
 
139
                $now = $utilMapper->getDatebaseNow();
-
 
140
 
140
            if ($form->isValid()) {
141
                $currentUserPlugin = $this->plugin('currentUserPlugin');
141
                $currentUserPlugin = $this->plugin('currentUserPlugin');
Línea 142... Línea 142...
142
                $currentUser = $currentUserPlugin->getUser();
142
                $currentUser = $currentUserPlugin->getUser();
Línea 439... Línea 439...
439
        return new JsonModel($response);
439
        return new JsonModel($response);
440
    }
440
    }
Línea 441... Línea 441...
441
 
441
 
442
    public function postOrShareFeed($dataPost)
442
    public function postOrShareFeed($dataPost)
443
    {
-
 
444
        $utilMapper = UtilMapper::getInstance($this->adapter);
-
 
-
 
443
    {
Línea 445... Línea 444...
445
        $now = $utilMapper->getDatebaseNow();
444
        
446
 
445
 
Línea 447... Línea 446...
447
        $currentUserPlugin = $this->plugin('currentUserPlugin');
446
        $currentUserPlugin = $this->plugin('currentUserPlugin');
Línea 469... Línea 468...
469
            $company = null;
468
            $company = null;
470
            $group = null;
469
            $group = null;
Línea 471... Línea 470...
471
 
470
 
472
            if ($companyId) {
471
            if ($companyId) {
-
 
472
                $companyMapper = CompanyMapper::getInstance($this->adapter);
-
 
473
                $now = $companyMapper->getDatebaseNow();
473
                $companyMapper = CompanyMapper::getInstance($this->adapter);
474
                
Línea 474... Línea 475...
474
                $company = $companyMapper->fetchOneByUuidAndNetworkId($companyId, $currentUser->network_id);
475
                $company = $companyMapper->fetchOneByUuidAndNetworkId($companyId, $currentUser->network_id);
475
 
476
 
Línea 502... Línea 503...
502
                }
503
                }
503
            }
504
            }
Línea 504... Línea 505...
504
 
505
 
505
            if ($groupId) {
506
            if ($groupId) {
-
 
507
                $groupMapper = GroupMapper::getInstance($this->adapter);
-
 
508
                $now = $groupMapper->getDatebaseNow();
506
                $groupMapper = GroupMapper::getInstance($this->adapter);
509
                
Línea 507... Línea 510...
507
                $group = $groupMapper->fetchOneByUuidAndNetworkId($groupId, $currentUser->network_id);
510
                $group = $groupMapper->fetchOneByUuidAndNetworkId($groupId, $currentUser->network_id);
508
 
511
 
509
                if (!$group) {
512
                if (!$group) {
Línea 550... Línea 553...
550
                    'data'      => 'ERROR_SUPPLY_VALID_SHARING_STATUS'
553
                    'data'      => 'ERROR_SUPPLY_VALID_SHARING_STATUS'
551
                ];
554
                ];
552
            }
555
            }
553
            $feed->posted_or_shared = $posted_or_shared;
556
            $feed->posted_or_shared = $posted_or_shared;
554
            $feedMapper = FeedMapper::getInstance($this->adapter);
557
            $feedMapper = FeedMapper::getInstance($this->adapter);
-
 
558
            $now = $feedMapper->getDatebaseNow();
Línea 555... Línea 559...
555
 
559
 
556
            $shared_with = isset($dataPost['shared_with']) ? $dataPost['shared_with'] : Feed::SHARE_WITH_PUBLIC;
560
            $shared_with = isset($dataPost['shared_with']) ? $dataPost['shared_with'] : Feed::SHARE_WITH_PUBLIC;
557
            if ($shared_with != Feed::SHARE_WITH_PUBLIC && $shared_with != Feed::SHARE_WITH_CONNECTIONS) {
561
            if ($shared_with != Feed::SHARE_WITH_PUBLIC && $shared_with != Feed::SHARE_WITH_CONNECTIONS) {
558
                return [
562
                return [
Línea 1144... Línea 1148...
1144
        return new JsonModel($response);
1148
        return new JsonModel($response);
1145
    }*/
1149
    }*/
Línea 1146... Línea 1150...
1146
 
1150
 
1147
    public function timelineAction()
1151
    public function timelineAction()
1148
    {
-
 
1149
        $utilMapper = UtilMapper::getInstance($this->adapter);
-
 
-
 
1152
    {
Línea 1150... Línea 1153...
1150
        $now = $utilMapper->getDatebaseNow();
1153
        
1151
 
1154
 
Línea 1165... Línea 1168...
1165
 
1168
 
1166
 
1169
 
-
 
1170
 
-
 
1171
        if ($feedUuid) {
1167
 
1172
            $feedMapper = FeedMapper::getInstance($this->adapter);
Línea 1168... Línea 1173...
1168
        if ($feedUuid) {
1173
            $now = $feedMapper->getDatebaseNow();
1169
            $feedMapper = FeedMapper::getInstance($this->adapter);
1174
            
1170
            $feed = $feedMapper->fetchOneByUuidAndNetworkIdAnyStatus($feedUuid, $currentUser->network_id);
1175
            $feed = $feedMapper->fetchOneByUuidAndNetworkIdAnyStatus($feedUuid, $currentUser->network_id);
Línea 1176... Línea 1181...
1176
 
1181
 
1177
 
1182
 
-
 
1183
 
-
 
1184
        $request = $this->getRequest();
-
 
1185
        if ($request->isGet()) {
-
 
1186
            
-
 
1187
            $exclude_feed_ids = [];
-
 
1188
            
-
 
1189
            $queryMapper = QueryMapper::getInstance($this->adapter);
-
 
1190
            
-
 
1191
            $selectNotUserCompany = $queryMapper->getSql()->select();
-
 
1192
            $selectNotUserCompany->columns(['company_id']);
-
 
1193
            $selectNotUserCompany->from(['cu' => CompanyUserMapper::_TABLE]);
-
 
1194
  
-
 
1195
            $selectNotUserCompany->where->equalTo('user_id', $currentUser->id);
-
 
1196
            $selectNotUserCompany->where->in('status', [CompanyUser::STATUS_ACCEPTED, CompanyUser::STATUS_ADMIN_WILL_ADD]);
-
 
1197
            
-
 
1198
            
-
 
1199
            
-
 
1200
            
-
 
1201
            
-
 
1202
            $select = $queryMapper->getSql()->select();
-
 
1203
            $select->columns(['id']);
-
 
1204
            $select->from(['f' => FeedMapper::_TABLE]);
-
 
1205
            $select->join(['fs' => FastSurveyMapper::_TABLE], 'fs.id = f.fast_survey_id', []);
-
 
1206
            $select->where->equalTo('f.file_type', Feed::FILE_TYPE_FAST_SURVEY);
-
 
1207
            $select->where->equalTo('f.network_id', $currentUser->network_id);
-
 
1208
            $select->where->equalTo('f.status', Feed::STATUS_PUBLISHED);
-
 
1209
            $select->where->equalTo('fs.privacy', FastSurvey::PRIVACY_COMPANY);
-
 
1210
            $select->where->notIn('fs.company_id', $selectNotUserCompany);
-
 
1211
            
-
 
1212
            $records = $queryMapper->fetchAll($select);
-
 
1213
            foreach($records as $record)
-
 
1214
            {
Línea 1178... Línea 1215...
1178
 
1215
                array_push($exclude_feed_ids, $record['id']);
1179
        $request = $this->getRequest();
1216
            }
1180
        if ($request->isGet()) {
1217
            
-
 
1218
 
-
 
1219
            $page = (int) $this->params()->fromQuery('page');
1181
 
1220
            if ($type == 'user') {
1182
            $page = (int) $this->params()->fromQuery('page');
1221
                $connectionMapper = ConnectionMapper::getInstance($this->adapter);
1183
            if ($type == 'user') {
1222
                $now = $connectionMapper->getDatebaseNow();
1184
                $connectionMapper = ConnectionMapper::getInstance($this->adapter);
1223
                
1185
                $records = $connectionMapper->fetchAllConnectionsByUser($id);
1224
                $records = $connectionMapper->fetchAllConnectionsByUser($id);
Línea 1238... Línea 1277...
1238
                    ->OR->NEST->and->equalTo('type', Feed::TYPE_UPDATE)->and->equalTo('shared_with', Feed::SHARE_WITH_PUBLIC)->UNNEST
1277
                    ->OR->NEST->and->equalTo('type', Feed::TYPE_UPDATE)->and->equalTo('shared_with', Feed::SHARE_WITH_PUBLIC)->UNNEST
1239
                    ->OR->NEST->in('user_id', $connectionIds)->and->equalTo('type', Feed::TYPE_UPDATE)->and->equalTo('shared_with', Feed::SHARE_WITH_CONNECTIONS)->UNNEST
1278
                    ->OR->NEST->in('user_id', $connectionIds)->and->equalTo('type', Feed::TYPE_UPDATE)->and->equalTo('shared_with', Feed::SHARE_WITH_CONNECTIONS)->UNNEST
1240
                    ->OR->NEST->or->in('company_id', $companyIds)->and->equalTo('type', Feed::TYPE_COMPANY)->UNNEST
1279
                    ->OR->NEST->or->in('company_id', $companyIds)->and->equalTo('type', Feed::TYPE_COMPANY)->UNNEST
1241
                    ->OR->NEST->or->in('group_id', $groupIds)->and->equalTo('type', Feed::TYPE_GROUP)->UNNEST
1280
                    ->OR->NEST->or->in('group_id', $groupIds)->and->equalTo('type', Feed::TYPE_GROUP)->UNNEST
1242
                    ->UNNEST;
1281
                    ->UNNEST;
-
 
1282
                
-
 
1283
                if($exclude_feed_ids) {
-
 
1284
                    $select->where->notIn('id', $exclude_feed_ids);        
-
 
1285
                }
-
 
1286
                    
-
 
1287
                    
1243
                $select->order('added_on desc');
1288
                $select->order('added_on desc');
1244
            }
1289
            }
1245
            if ($type == 'company') {
1290
            if ($type == 'company') {
1246
                $companyMapper = CompanyMapper::getInstance($this->adapter);
1291
                $companyMapper = CompanyMapper::getInstance($this->adapter);
-
 
1292
                $now = $companyMapper->getDatebaseNow();
-
 
1293
                
1247
                $company = $companyMapper->fetchOneByUuidAndNetworkId($id, $currentUser->network_id);
1294
                $company = $companyMapper->fetchOneByUuidAndNetworkId($id, $currentUser->network_id);
Línea 1248... Línea 1295...
1248
 
1295
 
1249
                if (!$company || $company->status != Company::STATUS_ACTIVE) {
1296
                if (!$company || $company->status != Company::STATUS_ACTIVE) {
1250
                    $id = 0;
1297
                    $id = 0;
Línea 1263... Línea 1310...
1263
                        } else {
1310
                        } else {
1264
                            $id = $company->id;
1311
                            $id = $company->id;
1265
                        }
1312
                        }
1266
                    }
1313
                    }
1267
                }
1314
                }
-
 
1315
                
Línea 1268... Línea 1316...
1268
 
1316
 
1269
 
-
 
1270
                $queryMapper = QueryMapper::getInstance($this->adapter);
1317
               
1271
                $select = $queryMapper->getSql()->select(FeedMapper::_TABLE);
1318
                $select = $queryMapper->getSql()->select(FeedMapper::_TABLE);
1272
                $select->columns(['id']);
1319
                $select->columns(['id']);
1273
                $select->where->equalTo('network_id', $currentUser->network_id);
1320
                $select->where->equalTo('network_id', $currentUser->network_id);
1274
                $select->where->equalTo('status', Feed::STATUS_PUBLISHED);
1321
                $select->where->equalTo('status', Feed::STATUS_PUBLISHED);
1275
                $select->where->equalTo('company_id', $id);
1322
                $select->where->equalTo('company_id', $id);
-
 
1323
                $select->where->and->equalTo('type', Feed::TYPE_COMPANY);
-
 
1324
                
-
 
1325
                if($exclude_feed_ids) {
-
 
1326
                    $select->where->notIn('id', $exclude_feed_ids);
-
 
1327
                }
1276
                $select->where->and->equalTo('type', Feed::TYPE_COMPANY);
1328
                
1277
                $select->order('added_on desc');
1329
                $select->order('added_on desc');
1278
            }
1330
            }
1279
            if ($type == 'group') {
1331
            if ($type == 'group') {
-
 
1332
                $groupMapper = GroupMapper::getInstance($this->adapter);
-
 
1333
                $now = $groupMapper->getDatebaseNow();
1280
                $groupMapper = GroupMapper::getInstance($this->adapter);
1334
                
Línea 1281... Línea 1335...
1281
                $group = $groupMapper->fetchOneByUuidAndNetworkId($id, $currentUser->network_id);
1335
                $group = $groupMapper->fetchOneByUuidAndNetworkId($id, $currentUser->network_id);
Línea 1282... Línea 1336...
1282
 
1336
 
Línea 1302... Línea 1356...
1302
                $select = $queryMapper->getSql()->select(FeedMapper::_TABLE);
1356
                $select = $queryMapper->getSql()->select(FeedMapper::_TABLE);
1303
                $select->columns(['id']);
1357
                $select->columns(['id']);
1304
                $select->where->equalTo('network_id', $currentUser->network_id);
1358
                $select->where->equalTo('network_id', $currentUser->network_id);
1305
                $select->where->equalTo('status', Feed::STATUS_PUBLISHED);
1359
                $select->where->equalTo('status', Feed::STATUS_PUBLISHED);
1306
                $select->where->equalTo('group_id', $id);
1360
                $select->where->equalTo('group_id', $id);
1307
                $select->where->and->equalTo('type', Feed::TYPE_GROUP);
1361
                $select->where->nest()->equalTo('type', Feed::TYPE_GROUP)
1308
                $select->where->or->equalTo('type', Feed::TYPE_UPDATE);
1362
                ->or->equalTo('type', Feed::TYPE_UPDATE)->unnest();
-
 
1363
                
-
 
1364
                if($exclude_feed_ids) {
-
 
1365
                    $select->where->notIn('id', $exclude_feed_ids);
-
 
1366
                }
-
 
1367
                
1309
                $select->order('added_on desc');
1368
                $select->order('added_on desc');
1310
            }
1369
            }
Línea 1311... Línea 1370...
1311
 
1370
 
1312
            $dbSelect = new DbSelect($select, $this->adapter);
1371
            $dbSelect = new DbSelect($select, $this->adapter);
Línea 1537... Línea 1596...
1537
 
1596
 
1538
        $item = [
1597
        $item = [
1539
            'feed_unique' => uniqid(),
1598
            'feed_unique' => uniqid(),
1540
            'feed_uuid' => $feed->uuid,
1599
            'feed_uuid' => $feed->uuid,
1541
            'feed_my_reaction' => $reaction ? $reaction->reaction : '',
-
 
1542
            'feed_save_reaction_recommended_url' => $feed_save_reaction_recommended,
-
 
1543
            'feed_save_reaction_support_url' => $feed_save_reaction_support,
-
 
1544
            'feed_save_reaction_love_url' => $feed_save_reaction_love,
-
 
1545
            'feed_save_reaction_interest_url' => $feed_save_reaction_interest,
-
 
1546
            'feed_save_reaction_fun_url' => $feed_save_reaction_fun,
-
 
1547
            'feed_delete_reaction_url' =>  $this->url()->fromRoute('feed/delete-reaction',  $params),
-
 
1548
            'feed_share_url' => $this->url()->fromRoute('feed/share',  $params),
-
 
1549
            'feed_share_external_url' => $share_external_url,
-
 
1550
            'feed_increment_external_counter_url' => $share_increment_external_counter_url,
1600
            'feed_my_reaction' => $reaction ? $reaction->reaction : '',
1551
            'feed_delete_url' =>  '',
1601
            'feed_delete_url' =>  '',
1552
            'feed_content_type' => $feed->file_type ? $feed->file_type : '',
1602
            'feed_content_type' => $feed->file_type ? $feed->file_type : '',
1553
            'feed_reactions' =>  $reactions,
1603
            'feed_reactions' =>  $reactions,
1554
            'feed_highlighted' => $feed->id == $feedHighlighted ? 1 : 0,
1604
            'feed_highlighted' => $feed->id == $feedHighlighted ? 1 : 0,
1555
            //'is_liked' => $contentReaction ? 1 : 0,
1605
            //'is_liked' => $contentReaction ? 1 : 0,
1556
            //'like_url' => $this->url()->fromRoute('post/like', ['id' => $post->uuid]),
1606
            //'like_url' => $this->url()->fromRoute('post/like', ['id' => $post->uuid]),
Línea 1557... Línea 1607...
1557
            //'unlike_url' => $this->url()->fromRoute('post/unlike', ['id' => $post->uuid]),
1607
            //'unlike_url' => $this->url()->fromRoute('post/unlike', ['id' => $post->uuid]),
-
 
1608
 
-
 
1609
        ];
-
 
1610
        
-
 
1611
        $fastSurveyVote =  '';
-
 
1612
        if($feed->file_type == Feed::FILE_TYPE_FAST_SURVEY) {
-
 
1613
            
-
 
1614
            $fastSurveyVoteMapper = FastSurveyVoteMapper::getInstance($this->adapter);
-
 
1615
            $fastSurveyVote =  $fastSurveyVoteMapper->fetchOneByFastSurveyIdAndUserId($feed->fast_survey_id, $currentUser->id);
-
 
1616
            
-
 
1617
            
-
 
1618
            
-
 
1619
            $item['feed_save_reaction_recommended_url'] = '';
-
 
1620
            $item['feed_save_reaction_support_url'] = '';
-
 
1621
            $item['feed_save_reaction_love_url'] = '';
-
 
1622
            $item['feed_save_reaction_interest_url'] = '';
-
 
1623
            $item['feed_save_reaction_fun_url'] = '';
-
 
1624
            $item['feed_delete_reaction_url'] =  '';
-
 
1625
            $item['feed_share_url'] = '';
-
 
1626
            $item['feed_share_external_url'] = '';
-
 
1627
            $item['feed_increment_external_counter_url'] = '';
-
 
1628
            
-
 
1629
            $item['feed_vote_url'] = $fastSurveyVote ? '' : $this->url()->fromRoute('feed/vote',  ['id' => $feed->uuid]);
-
 
1630
            
-
 
1631
        } else {
-
 
1632
            $item['feed_save_reaction_recommended_url'] = $feed_save_reaction_recommended;
-
 
1633
            $item['feed_save_reaction_support_url'] = $feed_save_reaction_support;
-
 
1634
            $item['feed_save_reaction_love_url'] = $feed_save_reaction_love;
-
 
1635
            $item['feed_save_reaction_interest_url'] = $feed_save_reaction_interest;
-
 
1636
            $item['feed_save_reaction_fun_url'] = $feed_save_reaction_fun;
-
 
1637
            $item['feed_delete_reaction_url'] =  $this->url()->fromRoute('feed/delete-reaction',  $params);
-
 
1638
            $item['feed_share_url'] = $this->url()->fromRoute('feed/share',  $params);
-
 
1639
            $item['feed_share_external_url'] = $share_external_url;
-
 
1640
            $item['feed_increment_external_counter_url'] = $share_increment_external_counter_url;
-
 
1641
            $item['feed_vote_url'] = '';
Línea 1558... Línea 1642...
1558
 
1642
        }
Línea 1559... Línea 1643...
1559
        ];
1643
        
Línea 1612... Línea 1696...
1612
            $item['owner_url'] = $this->url()->fromRoute('profile/view', ['id' => $user->uuid]);
1696
            $item['owner_url'] = $this->url()->fromRoute('profile/view', ['id' => $user->uuid]);
1613
            $item['owner_image'] = $this->url()->fromRoute('storage', ['code' => $user->uuid, 'type' => 'user', 'filename' => $user->image]);
1697
            $item['owner_image'] = $this->url()->fromRoute('storage', ['code' => $user->uuid, 'type' => 'user', 'filename' => $user->image]);
1614
            $item['owner_name'] = $user->first_name . ' ' . $user->last_name;
1698
            $item['owner_name'] = $user->first_name . ' ' . $user->last_name;
1615
        }
1699
        }
Línea -... Línea 1700...
-
 
1700
 
-
 
1701
        if($feed->file_type == Feed::FILE_TYPE_FAST_SURVEY) {
-
 
1702
            $fastSurveyMapper = FastSurveyMapper:: getInstance($this->adapter);
-
 
1703
            $fastSurvey = $fastSurveyMapper->fetchOne($feed->fast_survey_id);
-
 
1704
            
-
 
1705
            $owner_description = [
-
 
1706
                'question' => $fastSurvey->question,
-
 
1707
                'number_of_answers' => $fastSurvey->number_of_answers,
-
 
1708
                'answer1' => $fastSurvey->answer1,
-
 
1709
                'answer2' => $fastSurvey->answer2,
-
 
1710
                'answer3' => $fastSurvey->answer3,
-
 
1711
                'answer4' => $fastSurvey->answer4,
-
 
1712
                'answer5' => $fastSurvey->answer5,
-
 
1713
                'result_type' => $fastSurvey->result_type,
-
 
1714
                
-
 
1715
            ];
-
 
1716
            
-
 
1717
            if($fastSurvey->expire_on > $now) {
-
 
1718
                $owner_description['active'] = $fastSurveyVote ? 0 : 1;
-
 
1719
                $owner_description['time_remaining'] =  Functions::getDateDiff($now, $fastSurvey->expire_on);
-
 
1720
                
-
 
1721
            } else {
-
 
1722
                if($fastSurvey->result_type == FastSurvey::RESULT_TYPE_PUBLIC) {
-
 
1723
                    $owner_description['votes1'] = $fastSurvey->votes1;
-
 
1724
                    $owner_description['votes2'] = $fastSurvey->votes2;
-
 
1725
                    $owner_description['votes3'] = $fastSurvey->votes3;
-
 
1726
                    $owner_description['votes4'] = $fastSurvey->votes4;
-
 
1727
                    $owner_description['votes5'] = $fastSurvey->votes5;
-
 
1728
                }
-
 
1729
                
-
 
1730
                
-
 
1731
                $owner_description['active'] = 0;
-
 
1732
                $owner_description['time_remaining'] = 0;
-
 
1733
            }
-
 
1734
            
-
 
1735
            
-
 
1736
            $item['owner_description'] =  $owner_description;
1616
 
1737
        } else {
-
 
1738
            $item['owner_description'] = $feed->description;
1617
        $item['owner_description'] = $feed->description;
1739
        }
Línea 1618... Línea 1740...
1618
        $item['owner_feed_type'] = $feed->type;
1740
        $item['owner_feed_type'] = $feed->type;
1619
 
1741
 
1620
        $item['owner_shared'] = $feed->total_shared;
1742
        $item['owner_shared'] = $feed->total_shared;
Línea 1681... Línea 1803...
1681
            }
1803
            }
1682
        }
1804
        }
Línea 1683... Línea 1805...
1683
 
1805
 
Línea -... Línea 1806...
-
 
1806
        $companyMapper = CompanyMapper::getInstance($this->adapter);
-
 
1807
 
-
 
1808
        if($feed->file_type == Feed::FILE_TYPE_FAST_SURVEY) {
-
 
1809
            $item['comment_add_url'] = '';
-
 
1810
            $item['comments'] = [];
1684
        $companyMapper = CompanyMapper::getInstance($this->adapter);
1811
        } else {
1685
 
1812
        
1686
        $companies = [];
1813
            $companies = [];
1687
        $commentMapper = CommentMapper::getInstance($this->adapter);
1814
            $commentMapper = CommentMapper::getInstance($this->adapter);
1688
        $records = $commentMapper->fetchAllPublishedByFeedId($feed->id);
1815
            $records = $commentMapper->fetchAllPublishedByFeedId($feed->id);
1689
 
1816
    
1690
        $companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
1817
            $companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
1691
        $owner = $companyUserMapper->fetchOwnerByCompanyId($feed->company_id);
1818
            $owner = $companyUserMapper->fetchOwnerByCompanyId($feed->company_id);
1692
 
1819
    
1693
        $comments = [];
1820
            $comments = [];
1694
        foreach ($records as $record) {
1821
            foreach ($records as $record) {
1695
            $user = $userMapper->fetchOne($record->user_id);
1822
                $user = $userMapper->fetchOne($record->user_id);
1696
            $company = $companyMapper->fetchOne($feed->company_id);
1823
                $company = $companyMapper->fetchOne($feed->company_id);
1697
 
1824
    
1698
            if ($record->user_id == $currentUser->id) {
1825
                if ($record->user_id == $currentUser->id) {
1699
                $link_delete = $this->url()->fromRoute('feed/comment/delete', ['id' => $feed->uuid, 'comment' => $record->uuid]);
1826
                    $link_delete = $this->url()->fromRoute('feed/comment/delete', ['id' => $feed->uuid, 'comment' => $record->uuid]);
1700
                array_push($comments, [
1827
                    array_push($comments, [
1701
                    'unique' => uniqid(),
1828
                        'unique' => uniqid(),
1702
                    'user_url' => $this->url()->fromRoute('profile/view', ['id' => $user->uuid]),
1829
                        'user_url' => $this->url()->fromRoute('profile/view', ['id' => $user->uuid]),
1703
                    'user_name' => $user->first_name . ' ' . $user->last_name,
1830
                        'user_name' => $user->first_name . ' ' . $user->last_name,
1704
                    'company' => $owner,
1831
                        'company' => $owner,
1705
                    'user_image' => $this->url()->fromRoute('storage', ['type' => 'user',  'code' => $user->uuid, 'filename' =>  $user->image]),
1832
                        'user_image' => $this->url()->fromRoute('storage', ['type' => 'user',  'code' => $user->uuid, 'filename' =>  $user->image]),
1706
                    'time_elapsed' => Functions::timeAgo($record->added_on, $now),
1833
                        'time_elapsed' => Functions::timeAgo($record->added_on, $now),
1707
                    'comment' => $record->comment,
1834
                        'comment' => $record->comment,
1708
                    'link_delete' => $link_delete
1835
                        'link_delete' => $link_delete
1709
                ]);
1836
                    ]);
1710
            } else {
1837
                } else {
1711
                array_push($comments, [
1838
                    array_push($comments, [
1712
                    'unique' => uniqid(),
1839
                        'unique' => uniqid(),
1713
                    'user_url' => $this->url()->fromRoute('profile/view', ['id' => $user->uuid]),
1840
                        'user_url' => $this->url()->fromRoute('profile/view', ['id' => $user->uuid]),
1714
                    'user_name' => $user->first_name . ' ' . $user->last_name,
1841
                        'user_name' => $user->first_name . ' ' . $user->last_name,
1715
                    'user_image' => $this->url()->fromRoute('storage', ['type' => 'company',  'code' => $company->uuid, 'filename' =>  $company->image]),
1842
                        'user_image' => $this->url()->fromRoute('storage', ['type' => 'company',  'code' => $company->uuid, 'filename' =>  $company->image]),
1716
                    'time_elapsed' => Functions::timeAgo($record->added_on, $now),
1843
                        'time_elapsed' => Functions::timeAgo($record->added_on, $now),
1717
                    'comment' => $record->comment,
1844
                        'comment' => $record->comment,
1718
                    //'link_delete' => $link_delete
1845
                        //'link_delete' => $link_delete
-
 
1846
                    ]);
1719
                ]);
1847
                    $link_delete = '';
-
 
1848
                }
-
 
1849
            }
-
 
1850
        
1720
                $link_delete = '';
1851
 
-
 
1852
           
-
 
1853
        }
1721
            }
1854
        
1722
        }
1855
        echo '<pre>';
-
 
1856
        print_r($feed);
-
 
1857
        print_r($item);
Línea 1723... Línea 1858...
1723
        $item['comment_add_url'] = $this->url()->fromRoute('feed/comment', ['id' => $feed->uuid]);
1858
        echo '</pre>';
1724
        $item['comments'] = $comments;
1859
        exit;
Línea 1725... Línea 1860...
1725
 
1860
 
Línea 1835... Línea 1970...
1835
            
1970
            
Línea 1836... Línea 1971...
1836
        }*/
1971
        }*/
1837
 
1972
 
-
 
1973
        return $response;
-
 
1974
    }
-
 
1975
    
-
 
1976
    
-
 
1977
    public function voteAction()
-
 
1978
    {
-
 
1979
        $id = $this->params()->fromRoute('id');
-
 
1980
 
-
 
1981
        
-
 
1982
        $request = $this->getRequest();
-
 
1983
        if ($request->isPost()) {
-
 
1984
            
-
 
1985
           
-
 
1986
            
-
 
1987
            $currentUserPlugin = $this->plugin('currentUserPlugin');
-
 
1988
            $currentUser = $currentUserPlugin->getUser();
-
 
1989
            
-
 
1990
            
-
 
1991
            $feedMapper = FeedMapper::getInstance($this->adapter);
-
 
1992
            $feed = $feedMapper->fetchOneByUuidAndNetworkId($id, $currentUser->network_id);
-
 
1993
            if (!$feed) {
-
 
1994
                $response = [
-
 
1995
                    'success' => false,
-
 
1996
                    'data' => 'ERROR_POST_NOT_FOUND'
-
 
1997
                ];
-
 
1998
                return new JsonModel($response);
-
 
1999
            }
-
 
2000
            
-
 
2001
            
-
 
2002
            if($feed->file_type != Feed::FILE_TYPE_FAST_SURVEY) {
-
 
2003
                $response = [
-
 
2004
                    'success' => false,
-
 
2005
                    'data' => 'ERROR_FAST_SURVEY_FEED_IS_NOT_FAST_SURVEY' 
-
 
2006
                ];
-
 
2007
                return new JsonModel($response);
-
 
2008
            }
-
 
2009
       
-
 
2010
            $fastSurveyMapper = FastSurveyMapper::getInstance($this->adapter);
-
 
2011
            $fastSurvey = $fastSurveyMapper->fetchOne($feed->fast_survey_id);
-
 
2012
            if(!$fastSurvey) {
-
 
2013
                $response = [
-
 
2014
                    'success' => false,
-
 
2015
                    'data' => 'ERROR_FAST_SURVEY_NOT_FOUND'
-
 
2016
                ];
-
 
2017
                return new JsonModel($response);
-
 
2018
            }
-
 
2019
            
-
 
2020
            $now = $fastSurveyMapper->getDatebaseNow();
-
 
2021
            if($fastSurvey->expire_on <= $now) {
-
 
2022
                $response = [
-
 
2023
                    'success' => false,
-
 
2024
                    'data' => 'ERROR_FAST_SURVEY_IS_EXPIRED'
-
 
2025
                ];
-
 
2026
                return new JsonModel($response);
-
 
2027
            }
-
 
2028
            
-
 
2029
            
-
 
2030
            if($fastSurvey->privacy == FastSurvey::PRIVACY_COMPANY) {
-
 
2031
                
-
 
2032
                $companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
-
 
2033
                $companyUser = $companyUserMapper->fetchOneByCompanyIdAndUserId($fastSurvey->company_id, $currentUser->id);
-
 
2034
                if(!$companyUser || !in_array($companyUser->status, [CompanyUser::STATUS_ACCEPTED, CompanyUser::STATUS_ADMIN_WILL_ADD])) {
-
 
2035
                    $response = [
-
 
2036
                        'success' => false,
-
 
2037
                        'data' => 'ERROR_FAST_SURVEY_UNAUTHORIZED'
-
 
2038
                    ];
-
 
2039
                    return new JsonModel($response);
-
 
2040
                }
-
 
2041
                
-
 
2042
            }
-
 
2043
            
-
 
2044
            
-
 
2045
            
-
 
2046
            $vote = intval($this->params()->fromPost('vote', 0), 10);
-
 
2047
            if($vote < 1 || $vote > 5 || $vote > $fastSurvey->number_of_answers) {
-
 
2048
                $response = [
-
 
2049
                    'success' => false,
-
 
2050
                    'data' => 'ERROR_FAST_SURVEY_VOTE_IS_INVALID' 
-
 
2051
                ];
-
 
2052
                return new JsonModel($response);
-
 
2053
            }
-
 
2054
            
-
 
2055
            $fastSurveyVoteMapper = FastSurveyVoteMapper::getInstance($this->adapter);
-
 
2056
            $fastSurveyVote = $fastSurveyVoteMapper->fetchOneByFastSurveyIdAndUserId($fastSurvey->id, $currentUser->id);
-
 
2057
            if($fastSurveyVote) {
-
 
2058
                $response = [
-
 
2059
                    'success' => false,
-
 
2060
                    'data' => 'ERROR_FAST_SURVEY_VOTE_IS_ALREADY_FOUND'
-
 
2061
                ];
-
 
2062
                return new JsonModel($response);
-
 
2063
            }
-
 
2064
            
-
 
2065
            $fastSurveyVote = new FastSurveyVote();
-
 
2066
            $fastSurveyVote->fast_survey_id = $fastSurvey->id;
-
 
2067
            $fastSurveyVote->user_id = $currentUser->id;
-
 
2068
            $fastSurveyVote->vote = $vote;
-
 
2069
            
-
 
2070
            
-
 
2071
            if ($fastSurveyVoteMapper->insert($fastSurveyVote)) {
-
 
2072
                
-
 
2073
                return [
-
 
2074
                    'success'   => true,
-
 
2075
                    'data'   => $this->renderFeed($feed->id, $now)
-
 
2076
                ];
-
 
2077
            } else {
-
 
2078
                $response = [
-
 
2079
                    'success' => false,
-
 
2080
                    'data' => $fastSurveyVoteMapper->getError()
-
 
2081
                ];
-
 
2082
            }
-
 
2083
            return new JsonModel($response);
-
 
2084
        }
-
 
2085
        
-
 
2086
        $response = [
-
 
2087
            'success' => false,
-
 
2088
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
-
 
2089
        ];
1838
        return $response;
2090
        return new JsonModel($response);