Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 12985 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 12985 Rev 14740
Línea 42... Línea 42...
42
use LeadersLinked\Form\MyTrainerQuestionForm;
42
use LeadersLinked\Form\MyTrainerQuestionForm;
43
use LeadersLinked\Model\MyTrainerQuestions;
43
use LeadersLinked\Model\MyTrainerQuestions;
Línea 44... Línea 44...
44
 
44
 
45
use LeadersLinked\Model\FeedTopic;
45
use LeadersLinked\Model\FeedTopic;
-
 
46
use LeadersLinked\Form\TopicForm;
Línea 46... Línea 47...
46
use LeadersLinked\Form\TopicForm;
47
use LeadersLinked\Mapper\UtilMapper;
47
 
48
 
48
class MyTrainerAnswerController extends AbstractActionController
49
class MyTrainerAnswerController extends AbstractActionController
49
{
50
{
Línea 196... Línea 197...
196
                ];
197
                ];
197
                      return new JsonModel($data);
198
                      return new JsonModel($data);
198
            }      
199
            }      
Línea 199... Línea 200...
199
                             
200
                             
-
 
201
            $items = [];
-
 
202
            
-
 
203
            $utilMapper = UtilMapper::getInstance($this->adapter);
Línea 200... Línea 204...
200
            $items = [];
204
            $now = $utilMapper->getDatebaseNow();
201
           
205
           
202
            
206
            
203
            foreach($feeds as $solution)
207
            foreach($feeds as $solution)
Línea 204... Línea 208...
204
            {
208
            {
205
                $items = $this->renderFeed($solution->id);
209
                $items = $this->renderFeed($solution->id, $now);
206
            }
210
            }
Línea 253... Línea 257...
253
            $paginator->setItemCountPerPage(10);
257
            $paginator->setItemCountPerPage(10);
Línea 254... Línea 258...
254
            
258
            
255
            $items = [];
259
            $items = [];
Línea -... Línea 260...
-
 
260
            $feeds = $paginator->getCurrentItems();
-
 
261
            
-
 
262
            
-
 
263
            $utilMapper = UtilMapper::getInstance($this->adapter);
256
            $feeds = $paginator->getCurrentItems();
264
            $now = $utilMapper->getDatebaseNow();
257
            
265
            
258
            foreach($feeds as $feed)
266
            foreach($feeds as $feed)
259
            {
267
            {
Línea 260... Línea 268...
260
                $items[] = $this->renderFeed($feed->id);
268
                $items[] = $this->renderFeed($feed->id, $now);
261
            }
269
            }
262
            
270
            
Línea 490... Línea 498...
490
        $str = rawurlencode($str);
498
        $str = rawurlencode($str);
491
        $str = str_replace('%', '-', $str);
499
        $str = str_replace('%', '-', $str);
492
        return trim(strtolower($str));
500
        return trim(strtolower($str));
493
    }
501
    }
Línea 494... Línea 502...
494
 
502
 
Línea 495... Línea 503...
495
    private function renderFeed($id){
503
    private function renderFeed($id , $now){
496
        
504
        
497
        $sandbox = $this->config['leaderslinked.runmode.sandbox'];
505
        $sandbox = $this->config['leaderslinked.runmode.sandbox'];
498
        if($sandbox) {
506
        if($sandbox) {
Línea 541... Línea 549...
541
        $item['feed_delete_url'] = $this->url()->fromRoute('my-trainer/question/answer/delete',  $params);
549
        $item['feed_delete_url'] = $this->url()->fromRoute('my-trainer/question/answer/delete',  $params);
542
        $item['owner_url'] =  str_replace('[uuid]', $company->uuid, $company_profile_url);
550
        $item['owner_url'] =  str_replace('[uuid]', $company->uuid, $company_profile_url);
543
        $item['owner_image'] = $this->url()->fromRoute('storage', ['code' => $company->uuid, 'type' => 'user', 'filename' => $company->image]);
551
        $item['owner_image'] = $this->url()->fromRoute('storage', ['code' => $company->uuid, 'type' => 'user', 'filename' => $company->image]);
544
        $item['owner_name'] = $company->name;
552
        $item['owner_name'] = $company->name;
Línea 545... Línea -...
545
 
-
 
546
        $dt = \DateTime::createFromFormat('Y-m-d H:i:s', $feed->added_on);
553
 
Línea 547... Línea 554...
547
        $item['owner_time_elapse'] = Functions::timeElapsedString( $dt->getTimestamp());
554
        $item['owner_time_elapse'] = Functions::timeAgo( $feed->added_on, $now);
548
        
555
        
Línea 549... Línea 556...
549
        if($feed->file_type == Feed::FILE_TYPE_IMAGE) {
556
        if($feed->file_type == Feed::FILE_TYPE_IMAGE) {
Línea 575... Línea 582...
575
        $comments = [];
582
        $comments = [];
576
        $comment_count=0;
583
        $comment_count=0;
577
        foreach($records as $record)
584
        foreach($records as $record)
578
        {
585
        {
579
            $user = $userMapper->fetchOne($record->user_id);
586
            $user = $userMapper->fetchOne($record->user_id);
580
            $dt = \DateTime::createFromFormat('Y-m-d H:i:s', $record->added_on);
-
 
-
 
587
 
Línea 581... Línea 588...
581
 
588
 
582
            $comment = [];
589
            $comment = [];
583
            $comment['unique'] = uniqid();
590
            $comment['unique'] = uniqid();
584
            $comment_count++;
591
            $comment_count++;
Línea 595... Línea 602...
595
            }
602
            }
596
            $comment['link_delete'] = $this->url()->fromRoute('my-trainer/question/answer/comments/delete',['id' => $feed->uuid, 'comment' => $record->uuid ]);
603
            $comment['link_delete'] = $this->url()->fromRoute('my-trainer/question/answer/comments/delete',['id' => $feed->uuid, 'comment' => $record->uuid ]);
Línea 597... Línea 604...
597
            
604
            
598
            
605
            
599
            $comment['link_answer_add'] = $this->url()->fromRoute('my-trainer/question/answer/comments/answer',['id' => $feed->uuid, 'comment' => $record->uuid ]);
606
            $comment['link_answer_add'] = $this->url()->fromRoute('my-trainer/question/answer/comments/answer',['id' => $feed->uuid, 'comment' => $record->uuid ]);
Línea 600... Línea 607...
600
            $comment['time_elapsed'] = Functions::timeElapsedString($dt->getTimestamp());
607
            $comment['time_elapsed'] = Functions::timeAgo($record->added_on, $now);
601
            $comment['comment'] = $record->comment;
608
            $comment['comment'] = $record->comment;
602
            
609
            
603
            $records2 = $commentMapper->fetchAllPublishedByCommentId($record->id);
610
            $records2 = $commentMapper->fetchAllPublishedByCommentId($record->id);
604
            $answers = [];
611
            $answers = [];
605
            $contador=0;
612
            $contador=0;
606
            foreach($records2 as $record2)
-
 
-
 
613
            foreach($records2 as $record2)
Línea 607... Línea 614...
607
            {
614
            {
608
                $user = $userMapper->fetchOne($record2->user_id);
615
                $user = $userMapper->fetchOne($record2->user_id);
Línea 624... Línea 631...
624
                }
631
                }
Línea 625... Línea 632...
625
                
632
                
Línea 626... Línea 633...
626
                    $answer['link_delete'] = $this->url()->fromRoute('my-trainer/question/answer/comments/delete',['id' => $feed->uuid, 'comment' => $record2->uuid ]);
633
                    $answer['link_delete'] = $this->url()->fromRoute('my-trainer/question/answer/comments/delete',['id' => $feed->uuid, 'comment' => $record2->uuid ]);
627
                
634
                
Línea 628... Línea 635...
628
                
635
                
Línea 629... Línea 636...
629
                $answer['time_elapsed'] = Functions::timeElapsedString($dt->getTimestamp());
636
                $answer['time_elapsed'] = Functions::timeAgo($record2->added_on, $now);
Línea 692... Línea 699...
692
                $comment->feed_id = $feed->id;
699
                $comment->feed_id = $feed->id;
693
                $comment->user_id = $currentCompany->id;
700
                $comment->user_id = $currentCompany->id;
Línea 694... Línea 701...
694
                
701
                
695
                $commentMapper = CommentMapper::getInstance($this->adapter);
702
                $commentMapper = CommentMapper::getInstance($this->adapter);
-
 
703
                if($commentMapper->insert($comment)) {
-
 
704
                    $utilMapper = UtilMapper::getInstance($this->adapter);
Línea 696... Línea 705...
696
                if($commentMapper->insert($comment)) {
705
                    $now = $utilMapper->getDatebaseNow();
Línea 697... Línea 706...
697
                    
706
                    
698
                    $total_comments = $commentMapper->fetchCountCommentByFeedId($comment->feed_id);
707
                    $total_comments = $commentMapper->fetchCountCommentByFeedId($comment->feed_id);
Línea 699... Línea 708...
699
                    
708
                    
700
                    $feed->total_comments = $total_comments;
709
                    $feed->total_comments = $total_comments;
701
                    $feedMapper->update($feed);
710
                    $feedMapper->update($feed);
702
                    
711
                    
703
                    $response = [
712
                    $response = [
Línea 704... Línea 713...
704
                        'success'   => true,
713
                        'success'   => true,
Línea 801... Línea 810...
801
                $commentMapper = CommentMapper::getInstance($this->adapter);
810
                $commentMapper = CommentMapper::getInstance($this->adapter);
802
                $comment=$commentMapper->fetchOneByUuid($comment_uuid);
811
                $comment=$commentMapper->fetchOneByUuid($comment_uuid);
803
                $answer->parent_id = $comment->id;
812
                $answer->parent_id = $comment->id;
Línea 804... Línea 813...
804
                
813
                
-
 
814
                if($commentMapper->insert($answer)) {
-
 
815
                    $utilMapper = UtilMapper::getInstance($this->adapter);
Línea 805... Línea 816...
805
                if($commentMapper->insert($answer)) {
816
                    $now = $utilMapper->getDatebaseNow();
Línea 806... Línea 817...
806
                    
817
                    
807
                    $total_comments = $commentMapper->fetchCountCommentByFeedId($comment->feed_id);
818
                    $total_comments = $commentMapper->fetchCountCommentByFeedId($comment->feed_id);
Línea 808... Línea 819...
808
                    
819
                    
809
                    $feed->total_comments = $total_comments;
820
                    $feed->total_comments = $total_comments;
810
                    $feedMapper->update($feed);
821
                    $feedMapper->update($feed);
811
                    
822
                    
812
                    $response = [
823
                    $response = [
Línea 813... Línea 824...
813
                        'success'   => true,
824
                        'success'   => true,
Línea 936... Línea 947...
936
        }
947
        }
Línea 937... Línea 948...
937
        
948
        
938
        return new JsonModel($response);
949
        return new JsonModel($response);
Línea 939... Línea 950...
939
    }
950
    }
940
 
951
 
941
    private function renderComment($comment_id)
952
    private function renderComment($comment_id, $now)
942
    {
953
    {
943
        $currentUserPlugin = $this->plugin('currentUserPlugin');
954
        $currentUserPlugin = $this->plugin('currentUserPlugin');
Línea 971... Línea 982...
971
        $feed = $feedMapper->fetchOne($record->feed_id);
982
        $feed = $feedMapper->fetchOne($record->feed_id);
Línea 972... Línea 983...
972
        
983
        
973
        if($record) {
984
        if($record) {
Línea 974... Línea -...
974
            $userMapper = UserMapper::getInstance($this->adapter);
-
 
-
 
985
            $userMapper = UserMapper::getInstance($this->adapter);
Línea 975... Línea 986...
975
            
986
            
976
            $dt = \DateTime::createFromFormat('Y-m-d H:i:s', $record->added_on);
987
   
Línea 993... Línea 1004...
993
            
1004
            
994
            
1005
            
995
          
1006
          
996
            $item['link_answer_add'] = $this->url()->fromRoute('my-trainer/question/answer/comments/answer',['id' => $feed->uuid, 'comment' => $record->uuid ]);
1007
            $item['link_answer_add'] = $this->url()->fromRoute('my-trainer/question/answer/comments/answer',['id' => $feed->uuid, 'comment' => $record->uuid ]);
Línea 997... Línea 1008...
997
            $item['link_delete'] = $this->url()->fromRoute('my-trainer/question/answer/comments/delete',['id' => $feed->uuid, 'comment' => $record->uuid ]);
1008
            $item['link_delete'] = $this->url()->fromRoute('my-trainer/question/answer/comments/delete',['id' => $feed->uuid, 'comment' => $record->uuid ]);
998
            $item['time_elapsed'] = Functions::timeElapsedString($dt->getTimestamp());
1009
            $item['time_elapsed'] = Functions::timeAgo($record->added_on, $now);
999
            $item['comment'] = $record->comment;
1010
            $item['comment'] = $record->comment;