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