Proyectos de Subversion LeadersLinked - Backend

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
7308 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;
9
use Laminas\Cache\Storage\Adapter\AbstractAdapter;
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;
16
 
10327 nelberth 17
use LeadersLinked\Model\HighPerformanceTeamsGroupsMembers;
11185 nelberth 18
use LeadersLinked\Model\HighPerformanceTeamsGroups;
9019 nelberth 19
use LeadersLinked\Model\Feed;
11081 nelberth 20
use LeadersLinked\Form\HighPerformanceTeamsGroupsFeedForm;
9627 nelberth 21
use LeadersLinked\Form\TopicForm;
10275 nelberth 22
use LeadersLinked\Form\HighPerformanceTeamsGroupsMembersTypeForm;
7321 nelberth 23
use LeadersLinked\Mapper\HighPerformanceTeamsGroupsMapper;
24
use LeadersLinked\Mapper\HighPerformanceTeamsGroupsMembersMapper;
25
 
7322 nelberth 26
use LeadersLinked\Mapper\UserMapper;
27
 
7310 nelberth 28
class HighPerformanceTeamsGroupsViewController extends AbstractActionController
7308 nelberth 29
{
30
    /**
31
     *
32
     * @var AdapterInterface
33
     */
34
    private $adapter;
35
 
36
 
37
    /**
38
     *
39
     * @var AbstractAdapter
40
     */
41
    private $cache;
42
 
43
    /**
44
     *
45
     * @var  LoggerInterface
46
     */
47
    private $logger;
48
 
49
    /**
50
     *
51
     * @var array
52
     */
53
    private $config;
54
 
55
 
56
 
57
    /**
58
     *
59
     * @param AdapterInterface $adapter
60
     * @param AbstractAdapter $cache
61
     * @param LoggerInterface $logger
62
     * @param array $config
63
     */
64
    public function __construct($adapter, $cache , $logger, $config)
65
    {
66
        $this->adapter      = $adapter;
67
        $this->cache        = $cache;
68
        $this->logger       = $logger;
69
        $this->config       = $config;
70
 
71
 
72
    }
7320 nelberth 73
 
8685 nelberth 74
    public function IndexAction()
7308 nelberth 75
    {
7320 nelberth 76
        $currentUserPlugin = $this->plugin('currentUserPlugin');
77
        $currentUser = $currentUserPlugin->getUser();
7339 nelberth 78
        $currentCompany = $currentUserPlugin->getCompany();
11084 nelberth 79
        $group_uuid   = $this->params()->fromRoute('group_id');
80
        $topic_uuid   = $this->params()->fromRoute('topic_id');
8634 nelberth 81
 
82
 
7835 nelberth 83
        if(!isset($topic_uuid)){
84
            $topic_uuid='';
7616 nelberth 85
        }
8678 nelberth 86
 
8685 nelberth 87
        $urgent   = $this->params()->fromRoute('urgent');
88
        if(!isset($urgent)){
89
            $urgent='';
90
        }
8734 nelberth 91
 
9513 nelberth 92
 
7339 nelberth 93
        $request = $this->getRequest();
94
        if($request->isGet()) {
95
            $headers  = $request->getHeaders();
7320 nelberth 96
 
7339 nelberth 97
            $isJson = false;
98
            if($headers->has('Accept')) {
99
                $accept = $headers->get('Accept');
7320 nelberth 100
 
7339 nelberth 101
                $prioritized = $accept->getPrioritized();
7320 nelberth 102
 
7339 nelberth 103
                foreach($prioritized as $key => $value) {
104
                    $raw = trim($value->getRaw());
7321 nelberth 105
 
7339 nelberth 106
                    if(!$isJson) {
107
                        $isJson = strpos($raw, 'json');
7321 nelberth 108
                    }
7320 nelberth 109
 
110
                }
7321 nelberth 111
            }
11179 nelberth 112
            $highPerformanceTeamsGroupsMapper = HighPerformanceTeamsGroupsMapper::getInstance($this->adapter);
113
            $highPerformanceTeamsGroups = $highPerformanceTeamsGroupsMapper->fetchOneByUuid($group_uuid);
11184 nelberth 114
            $this->layout()->setTemplate('layout/layout-backend');
115
            $viewModel = new ViewModel();
11182 nelberth 116
            if (!$highPerformanceTeamsGroups) {
11179 nelberth 117
                $viewModel->setTemplate('leaders-linked/no-access/index.phtml');
11182 nelberth 118
                return $viewModel;
119
            }
11185 nelberth 120
 
11184 nelberth 121
            if($highPerformanceTeamsGroups->status != HighPerformanceTeamsGroups::STATUS_ACTIVE) {
122
                $viewModel->setTemplate('leaders-linked/no-access/index.phtml');
123
                return $viewModel ;
124
            }
11179 nelberth 125
 
10326 nelberth 126
            $highPerformanceTeamsGroupsMembersMapper = HighPerformanceTeamsGroupsMembersMapper::getInstance($this->adapter);
127
            $member = $highPerformanceTeamsGroupsMembersMapper->fetchOneByGroupIdAndUserId($highPerformanceTeamsGroups->id,$currentUser->id);
10342 nelberth 128
            if(!$member){
11171 nelberth 129
                $viewModel->setTemplate('leaders-linked/no-access/index.phtml');
130
                return $viewModel ;
11169 nelberth 131
            }
132
            $rolAdmin=true;
10326 nelberth 133
            if($member->type==HighPerformanceTeamsGroupsMembers::TYPE_MODERATOR||$member->type==HighPerformanceTeamsGroupsMembers::TYPE_USER){
134
                $rolAdmin=false;
11169 nelberth 135
            }
10326 nelberth 136
 
11081 nelberth 137
            $formFeed = new HighPerformanceTeamsGroupsFeedForm($this->adapter);
9627 nelberth 138
            $formTopicNomal = new TopicForm();
10275 nelberth 139
            $formMemberEdit = new HighPerformanceTeamsGroupsMembersTypeForm();
7339 nelberth 140
            $this->layout()->setTemplate('layout/layout-backend');
141
            $viewModel = new ViewModel();
7344 nelberth 142
            $viewModel->setTemplate('leaders-linked/high-performance-teams-groups-view/index.phtml');
7339 nelberth 143
            $viewModel->setVariables([
7347 nelberth 144
                'formFeed'    =>  $formFeed,
7462 nelberth 145
                'group_uuid'  =>  $group_uuid,
7835 nelberth 146
                'topic_uuid'=>$topic_uuid,
8634 nelberth 147
                'formTopicNormal' => $formTopicNomal,
9019 nelberth 148
                'urgent'=>$urgent,
149
                'type_meeting'=>Feed::FILE_TYPE_MEETING,
9233 nelberth 150
                'group_title'=>$highPerformanceTeamsGroups->title,
9235 nelberth 151
                'group_description'=>$highPerformanceTeamsGroups->description,
10275 nelberth 152
                'formMemberEdit'=>$formMemberEdit,
10326 nelberth 153
                'rolAdmin'=>$rolAdmin,
7321 nelberth 154
            ]);
7339 nelberth 155
            return $viewModel ;
7321 nelberth 156
 
157
 
158
        } else {
7339 nelberth 159
            return new JsonModel([
160
                'success' => false,
161
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
7320 nelberth 162
            ]);
163
        }
7339 nelberth 164
 
7321 nelberth 165
 
7320 nelberth 166
    }
167
 
8683 nelberth 168
 
7504 nelberth 169
 
7308 nelberth 170
}