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