Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

Rev 6521 Rev 6547
Línea 685... Línea 685...
685
            if ($allowAnswerAdd) {
685
            if ($allowAnswerAdd) {
686
                $link_answers_add = $this->url()->fromRoute('my-coach/questions/answers/add', ['id' => $myCoachQuestion->uuid]);
686
                $link_answers_add = $this->url()->fromRoute('my-coach/questions/answers/add', ['id' => $myCoachQuestion->uuid]);
687
            } else {
687
            } else {
688
                $link_answers_add = '';
688
                $link_answers_add = '';
689
            }
689
            }
690
            
690
       
Línea 691... Línea 691...
691
            
691
            
Línea 692... Línea 692...
692
 
692
 
Línea 711... Línea 711...
711
                    'user_image' => $this->url()->fromRoute('storage', ['type' => 'user', 'code' => $user->uuid, 'filename' => $user->image]),
711
                    'user_image' => $this->url()->fromRoute('storage', ['type' => 'user', 'code' => $user->uuid, 'filename' => $user->image]),
712
                    'title' => $myCoachQuestion->title,
712
                    'title' => $myCoachQuestion->title,
713
                    'description' => $myCoachQuestion->description,
713
                    'description' => $myCoachQuestion->description,
714
                    'categories' => $bags_categories,
714
                    'categories' => $bags_categories,
715
                    'views' => intval($myCoachQuestionViewMapper->fetchCountByQuestionId($myCoachQuestion->id) , 10),
715
                    'views' => intval($myCoachQuestionViewMapper->fetchCountByQuestionId($myCoachQuestion->id) , 10),
716
                    'answers' => intval($myCoachAnswerMapper->fetchAllByQuestionId($myCoachQuestion->id) , 10),
716
                    'answers' => intval($myCoachAnswerMapper->fetchCountByMyCoachQuestionId($myCoachQuestion->id) , 10),
717
                    'reactions' => intval($contentReactionMapper->fetchCountByMyCoachQuestionId($myCoachQuestion->id), 10),
717
                    'reactions' => intval($contentReactionMapper->fetchCountByMyCoachQuestionId($myCoachQuestion->id), 10),
718
                    'comments' => intval($commentMapper->fetchCountByMyCoachQuestionId($myCoachQuestion->id), 10),
718
                    'comments' => intval($commentMapper->fetchCountByMyCoachQuestionId($myCoachQuestion->id), 10),
719
                    'added_on' => $added_on,
719
                    'added_on' => $added_on,
720
                    'updated_on' => $updated_on,
720
                    'updated_on' => $updated_on,
721
                    'last_answer_on' => $last_answer_on,
721
                    'last_answer_on' => $last_answer_on,
Línea 803... Línea 803...
803
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
803
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
804
            ]);
804
            ]);
805
        }
805
        }
806
    }
806
    }
Línea -... Línea 807...
-
 
807
    
-
 
808
    public function deleteAnswerAction()
-
 
809
    {
-
 
810
        $currentNetworkPlugin  = $this->plugin('currentNetworkPlugin');
-
 
811
        $currentNetwork        = $currentNetworkPlugin->getNetwork();
-
 
812
        
-
 
813
        $currentUserPlugin  = $this->plugin('currentUserPlugin');
-
 
814
        $currentUser        = $currentUserPlugin->getUser();
-
 
815
        
-
 
816
        $request    = $this->getRequest();
-
 
817
        $answer     = $this->params()->fromRoute('answer');
-
 
818
        
-
 
819
        $message_error = '';
-
 
820
        $myCoachAccessControl = MyCoachAccessControl::getInstance($this->adapter);
-
 
821
        if(!$myCoachAccessControl->hasAccessEditOrDeleteAnswer($currentUser->id, $answer, $currentNetwork->id, $message_error)) {
-
 
822
            return new JsonModel([
-
 
823
                'success'   => false,
-
 
824
                'data'   => $message_error
-
 
825
            ]);
-
 
826
        }
-
 
827
        
-
 
828
        
-
 
829
        $myCoachAnswerMapper = MyCoachAnswerMapper::getInstance($this->adapter);
-
 
830
        $myCoachAnswer = $myCoachAnswerMapper->fetchOneByUuid($answer);
-
 
831
        
-
 
832
        if ($request->isPost()) {
-
 
833
            
-
 
834
            if($myCoachAnswerMapper->delete($myCoachAnswer)) {
-
 
835
                    
-
 
836
                $contentReactionMapper = ContentReactionMapper::getInstance($this->adapter);
-
 
837
                $commentMapper = CommentMapper::getInstance($this->adapter);
-
 
838
                
-
 
839
                
-
 
840
                $this->logger->info('Se borro la respuesta ' . $myCoachAnswer->text, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
-
 
841
                    
-
 
842
                $data = [
-
 
843
                    'success'   => true,
-
 
844
                    'data'   => [
-
 
845
                        'total_comments' => intval($commentMapper->fetchCountByMyCoachQuestionId($myCoachAnswer->question_id), 10),
-
 
846
                        'total_answers' => intval($myCoachAnswerMapper->fetchCountByMyCoachQuestionId($myCoachAnswer->question_id), 10),
-
 
847
                        'total_reactions' => intval($contentReactionMapper->fetchCountByMyCoachQuestionId($myCoachAnswer->question_id), 10)
-
 
848
              
-
 
849
                    ]
-
 
850
                ];
-
 
851
            } else {
-
 
852
                $data = [
-
 
853
                    'success'   => false,
-
 
854
                    'data'      => $myCoachAnswerMapper->getError()
-
 
855
                ];
-
 
856
            }
-
 
857
        } else {
-
 
858
            $data = [
-
 
859
                'success' => false,
-
 
860
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
-
 
861
            ];
-
 
862
            
-
 
863
            
-
 
864
        }
-
 
865
        return new JsonModel($data);
-
 
866
        
-
 
867
        
-
 
868
    }
-
 
869
    
-
 
870
    
-
 
871
    public function editAnswerAction()
-
 
872
    {
-
 
873
        $currentNetworkPlugin  = $this->plugin('currentNetworkPlugin');
-
 
874
        $currentNetwork        = $currentNetworkPlugin->getNetwork();
-
 
875
        
-
 
876
        $currentUserPlugin  = $this->plugin('currentUserPlugin');
-
 
877
        $currentUser        = $currentUserPlugin->getUser();
-
 
878
        
-
 
879
        $request    = $this->getRequest();
-
 
880
        $answer     = $this->params()->fromRoute('answer');
-
 
881
        
-
 
882
        $message_error = '';
-
 
883
        $myCoachAccessControl = MyCoachAccessControl::getInstance($this->adapter);
-
 
884
        if(!$myCoachAccessControl->hasAccessEditOrDeleteAnswer($currentUser->id, $answer, $currentNetwork->id, $message_error)) {
-
 
885
            return new JsonModel([
-
 
886
                'success'   => false,
-
 
887
                'data'   => $message_error
-
 
888
            ]);
-
 
889
        }
-
 
890
        
-
 
891
        
-
 
892
        $myCoachAnswerMapper = MyCoachAnswerMapper::getInstance($this->adapter);
-
 
893
        $myCoachAnswer = $myCoachAnswerMapper->fetchOneByUuid($answer);
-
 
894
        
-
 
895
        if ($request->isPost()) {
-
 
896
            
-
 
897
            $dataPost = array_merge($request->getPost()->toArray(), $request->getFiles()->toArray());
-
 
898
            $form = new MyCoachAnswerForm();
-
 
899
            $form->setData($dataPost);
-
 
900
            
-
 
901
            if ($form->isValid()) {
-
 
902
                $myCoachAnswer->text        = $dataPost['description'];
-
 
903
 
-
 
904
                if($myCoachAnswerMapper->update($myCoachAnswer)) {
-
 
905
                    
-
 
906
                    $this->logger->info('Se edito la respuesta ' . $myCoachAnswer->text, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
-
 
907
                    
-
 
908
                    $data = [
-
 
909
                        'success'   => true,
-
 
910
                        'data'   => [
-
 
911
                            'description' => $myCoachAnswer->text
-
 
912
                        ]
-
 
913
                    ];
-
 
914
                } else {
-
 
915
                    $data = [
-
 
916
                        'success'   => false,
-
 
917
                        'data'      => $myCoachAnswerMapper->getError()
-
 
918
                    ];
-
 
919
                }
-
 
920
                
-
 
921
                return new JsonModel($data);
-
 
922
            } else {
-
 
923
                $messages = [];
-
 
924
                $form_messages = (array) $form->getMessages();
-
 
925
                foreach ($form_messages  as $fieldname => $field_messages)
-
 
926
                {
-
 
927
                    $messages[$fieldname] = array_values($field_messages);
-
 
928
                }
-
 
929
                
-
 
930
                return new JsonModel([
-
 
931
                    'success'   => false,
-
 
932
                    'data'   => $messages
-
 
933
                ]);
-
 
934
            }
-
 
935
        } else  if ($request->isGet()) {
-
 
936
            return new JsonModel([
-
 
937
                'success'   => true,
-
 
938
                'data'   => [
-
 
939
                    'description' => $myCoachAnswer->text
-
 
940
                ]
-
 
941
            ]);
-
 
942
        } else {
-
 
943
            $data = [
-
 
944
                'success' => false,
-
 
945
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
-
 
946
            ];
-
 
947
            
-
 
948
            return new JsonModel($data);
-
 
949
        }
-
 
950
        
-
 
951
        
Línea -... Línea 952...
-
 
952
    }
-
 
953
 
807
    
954
    
808
 
955
    
809
    
956
    
810
    
957
    
Línea 1806... Línea 1953...
1806
    }
1953
    }
Línea 1807... Línea 1954...
1807
    
1954
    
1808
    
1955
    
-
 
1956
    private function renderAnswer($answer_id, $current_user_id, $now)
-
 
1957
    {
-
 
1958
        $currentNetworkPlugin  = $this->plugin('currentNetworkPlugin');
Línea 1809... Línea 1959...
1809
    private function renderAnswer($answer_id, $current_user_id, $now)
1959
        $currentNetwork        = $currentNetworkPlugin->getNetwork();
1810
    {
1960
        $message_error = '';
-
 
1961
        
-
 
1962
        $myCoachAnswerMapper = MyCoachAnswerMapper::getInstance($this->adapter);
-
 
1963
        $myCoachAnswer =  $myCoachAnswerMapper->fetchOne($answer_id);
-
 
1964
 
Línea -... Línea 1965...
-
 
1965
        $myCoachQuestionMapper = MyCoachQuestionMapper::getInstance($this->adapter);
-
 
1966
        $myCoachQuestion = $myCoachQuestionMapper->fetchOne($myCoachAnswer->question_id);
-
 
1967
        
-
 
1968
        
-
 
1969
        $myCoachAccessControl = MyCoachAccessControl::getInstance($this->adapter);
-
 
1970
        $hasAccessEditOrDeleteAnswer = $myCoachAccessControl->hasAccessEditOrDeleteAnswer($current_user_id, $answer_id, $currentNetwork->id, $message_error);
-
 
1971
        if($hasAccessEditOrDeleteAnswer) {
-
 
1972
            
-
 
1973
 
-
 
1974
            $link_edit = $this->url()->fromRoute('my-coach/questions/answers/edit',['id' => $myCoachQuestion->uuid, 'answer' => $myCoachAnswer->uuid]);
-
 
1975
            $link_delete = $this->url()->fromRoute('my-coach/questions/answers/delete',['id' => $myCoachQuestion->uuid, 'answer' => $myCoachAnswer->uuid]);
-
 
1976
            
Línea 1811... Línea 1977...
1811
        
1977
        } else {
1812
        $myCoachAnswerMapper = MyCoachAnswerMapper::getInstance($this->adapter);
1978
            $link_edit = '';
Línea 1813... Línea 1979...
1813
        $myCoachAnswer =  $myCoachAnswerMapper->fetchOne($answer_id);
1979
            $link_delete = '';
1814
        
1980
        }
1815
        
1981
        
Línea 1816... Línea 1982...
1816
        $userMapper = UserMapper::getInstance($this->adapter);
1982
        $userMapper = UserMapper::getInstance($this->adapter);
Línea 1834... Línea 2000...
1834
        
2000
        
1835
        
2001
        
1836
        $item = [
2002
        $item = [
-
 
2003
            'unique' => uniqid(),
1837
            'unique' => uniqid(),
2004
            'uuid' => $myCoachAnswer->uuid,
1838
            'uuid' => $myCoachAnswer->uuid,
2005
            'question_uuid' => $myCoachQuestion->uuid,
1839
            'user_image' => $this->url()->fromRoute('storage', ['type' => 'user',  'code' => $user->uuid, 'filename' =>  $user->image]),
2006
            'user_image' => $this->url()->fromRoute('storage', ['type' => 'user',  'code' => $user->uuid, 'filename' =>  $user->image]),
1840
            'user_url' => $this->url()->fromRoute('profile/view', ['id' => $user->uuid]),
2007
            'user_url' => $this->url()->fromRoute('profile/view', ['id' => $user->uuid]),
1841
            'user_name' => $user->first_name . ' ' . $user->last_name,
2008
            'user_name' => $user->first_name . ' ' . $user->last_name,
1842
            'time_elapsed' => Functions::timeAgo($myCoachAnswer->added_on, $now),
2009
            'time_elapsed' => Functions::timeAgo($myCoachAnswer->added_on, $now),
1843
            'text' => $myCoachAnswer->text, 
2010
            'text' => $myCoachAnswer->text, 
1844
            'reaction' => $contentReaction ? $contentReaction->reaction : '',  
2011
            'reaction' => $contentReaction ? $contentReaction->reaction : '',  
1845
            'total_comments' => $total_comments,
2012
            'total_comments' => $total_comments,
-
 
2013
            'total_reactions' => $total_reactions,
-
 
2014
            'comments' => $comments,
1846
            'total_reactions' => $total_reactions,
2015
            'link_edit' => $link_edit,
1847
            'comments' => $comments,
2016
            'link_delete' => $link_delete,
1848
            'link_reaction_delete' => $this->url()->fromRoute('my-coach/questions/reaction/delete', ['id' => $myCoachAnswer->uuid]),
2017
            'link_reaction_delete' => $this->url()->fromRoute('my-coach/questions/reaction/delete', ['id' => $myCoachAnswer->uuid]),
1849
            'link_save_reaction' => $this->url()->fromRoute('my-coach/questions/reaction/save', ['id' => $myCoachAnswer->uuid]),
2018
            'link_save_reaction' => $this->url()->fromRoute('my-coach/questions/reaction/save', ['id' => $myCoachAnswer->uuid]),