Proyectos de Subversion LeadersLinked - Backend

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
9921 nelberth 1
<?php
2
declare(strict_types=1);
3
 
4
namespace LeadersLinked\Controller;
5
 
6
use Laminas\Authentication\AuthenticationService;
7
use Laminas\Authentication\Result as AuthResult;
8
use Laminas\Db\Adapter\AdapterInterface;
16768 efrain 9
 
9921 nelberth 10
use Laminas\Mvc\Controller\AbstractActionController;
11
use Laminas\Mvc\I18n\Translator;
12
use Laminas\Log\LoggerInterface;
13
use Laminas\View\Model\ViewModel;
14
use Laminas\View\Model\JsonModel;
15
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
9931 nelberth 16
use LeadersLinked\Form\CreateFeedForm;
17
use LeadersLinked\Library\Functions;
18
use LeadersLinked\Mapper\UserMapper;
9921 nelberth 19
 
9931 nelberth 20
use LeadersLinked\Mapper\CompanyMapper;
21
use LeadersLinked\Mapper\TopicMapper;
22
use LeadersLinked\Model\Feed;
11194 nelberth 23
use LeadersLinked\Model\HighPerformanceTeamsGroups;
9931 nelberth 24
use LeadersLinked\Mapper\FeedMapper;
25
use LeadersLinked\Mapper\HighPerformanceTeamsGroupsMapper;
26
use LeadersLinked\Model\HighPerformanceTeamsGroupsMembers;
27
use LeadersLinked\Form\HighPerformanceTeamsGroupsMembersForm;
28
use LeadersLinked\Mapper\HighPerformanceTeamsGroupsMembersMapper;
29
 
9921 nelberth 30
class HighPerformanceTeamsGroupsViewForoArticlesViewController extends AbstractActionController
31
{
32
    /**
33
     *
16769 efrain 34
     * @var \Laminas\Db\Adapter\AdapterInterface
9921 nelberth 35
     */
36
    private $adapter;
37
 
38
    /**
39
     *
16769 efrain 40
     * @var \LeadersLinked\Cache\CacheInterface
9921 nelberth 41
     */
16769 efrain 42
    private $cache;
43
 
44
 
45
    /**
46
     *
47
     * @var \Laminas\Log\LoggerInterface
48
     */
9921 nelberth 49
    private $logger;
50
 
51
    /**
52
     *
53
     * @var array
54
     */
55
    private $config;
56
 
16769 efrain 57
 
9921 nelberth 58
    /**
59
     *
16769 efrain 60
     * @var \Laminas\Mvc\I18n\Translator
61
     */
62
    private $translator;
63
 
64
 
65
    /**
66
     *
67
     * @param \Laminas\Db\Adapter\AdapterInterface $adapter
68
     * @param \LeadersLinked\Cache\CacheInterface $cache
69
     * @param \Laminas\Log\LoggerInterface LoggerInterface $logger
9921 nelberth 70
     * @param array $config
16769 efrain 71
     * @param \Laminas\Mvc\I18n\Translator $translator
9921 nelberth 72
     */
16769 efrain 73
    public function __construct($adapter, $cache, $logger, $config, $translator)
9921 nelberth 74
    {
16769 efrain 75
        $this->adapter      = $adapter;
76
        $this->cache        = $cache;
77
        $this->logger       = $logger;
78
        $this->config       = $config;
79
        $this->translator   = $translator;
9921 nelberth 80
    }
81
 
82
    public function indexAction()
83
    {
9932 nelberth 84
 
85
        $currentUserPlugin = $this->plugin('currentUserPlugin');
86
        $currentUser = $currentUserPlugin->getUser();
87
        $currentCompany = $currentUserPlugin->getCompany();
11085 nelberth 88
        $group_uuid =  $this->params()->fromRoute('group_id');
89
        $category_uuid =  $this->params()->fromRoute('category_id');
90
        $article_uuid =  $this->params()->fromRoute('article_id');
9932 nelberth 91
        $request = $this->getRequest();
10121 nelberth 92
 
9931 nelberth 93
        if(!$group_uuid) {
94
            $data = [
95
                'success'   => false,
96
                'data'   => 'ERROR_INVALID_PARAMETER'
97
            ];
98
 
99
            return new JsonModel($data);
100
        }
11193 nelberth 101
        if(!$article_uuid) {
102
            $data = [
103
                'success'   => false,
104
                'data'   => 'ERROR_INVALID_PARAMETER'
105
            ];
106
 
107
            return new JsonModel($data);
108
        }
9931 nelberth 109
        if(!$category_uuid) {
110
            $data = [
111
                'success'   => false,
112
                'data'   => 'ERROR_INVALID_PARAMETER'
113
            ];
114
 
115
            return new JsonModel($data);
116
        }
117
 
11193 nelberth 118
 
9931 nelberth 119
        $highPerformanceTeamsGroupsMapper = HighPerformanceTeamsGroupsMapper::getInstance($this->adapter);
120
        $highPerformanceTeamsGroups = $highPerformanceTeamsGroupsMapper->fetchOneByUuid($group_uuid);
11193 nelberth 121
        $this->layout()->setTemplate('layout/layout-backend');
122
        $viewModel = new ViewModel();
9931 nelberth 123
        if (!$highPerformanceTeamsGroups) {
11193 nelberth 124
            $viewModel->setTemplate('leaders-linked/no-access/index.phtml');
125
            return $viewModel;
126
        }
127
        if($highPerformanceTeamsGroups->status != HighPerformanceTeamsGroups::STATUS_ACTIVE) {
128
            $viewModel->setTemplate('leaders-linked/no-access/index.phtml');
129
            return $viewModel;
9931 nelberth 130
 
11193 nelberth 131
        }
132
        $highPerformanceTeamsGroupsMembersMapper = HighPerformanceTeamsGroupsMembersMapper::getInstance($this->adapter);
133
        $highPerformanceTeamsGroupsMember = $highPerformanceTeamsGroupsMembersMapper->fetchOneByGroupIdAndUserId($highPerformanceTeamsGroups->id, $currentUser->id);
9931 nelberth 134
        if(!$highPerformanceTeamsGroupsMember) {
11193 nelberth 135
            $viewModel->setTemplate('leaders-linked/no-access/index.phtml');
136
            return $viewModel;
9931 nelberth 137
        }
138
        if(!($highPerformanceTeamsGroupsMember->status == HighPerformanceTeamsGroupsMembers::STATUS_ACCEPTED || $highPerformanceTeamsGroupsMember->status == HighPerformanceTeamsGroupsMembers::STATUS_ADDED_BY_ADMIN) ){
11193 nelberth 139
            $viewModel->setTemplate('leaders-linked/no-access/index.phtml');
140
            return $viewModel;
9931 nelberth 141
        }
142
 
11193 nelberth 143
        $topicMapper = TopicMapper::getInstance($this->adapter);
144
        $topic = $topicMapper->fetchOneByUuidAndGroupId($category_uuid,$highPerformanceTeamsGroups->id);
145
 
146
        if(!$topic){
147
            $viewModel->setTemplate('leaders-linked/no-access/index.phtml');
148
            return $viewModel;
149
        }
150
 
9921 nelberth 151
        if($request->isGet()) {
9931 nelberth 152
            $formAdd = new CreateFeedForm($this->adapter);
9921 nelberth 153
            $this->layout()->setTemplate('layout/layout-backend');
154
            $viewModel = new ViewModel();
9930 nelberth 155
            $viewModel->setTemplate('leaders-linked/high-performance-teams-groups-view-foro-articles-view/index.phtml');
9931 nelberth 156
            $viewModel->setVariables([
157
                'formAdd' => $formAdd,
158
                'group_uuid'=>$group_uuid,
159
                'group_title'=>$highPerformanceTeamsGroups->title,
10121 nelberth 160
                'category_uuid'=>$category_uuid,
161
                'article_uuid'=>$article_uuid
9931 nelberth 162
            ]);
9921 nelberth 163
            return $viewModel ;
164
 
165
 
166
        } else {
167
            return new JsonModel([
168
                'success' => false,
169
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
170
            ]);;
171
        }
172
    }
173
}