Proyectos de Subversion LeadersLinked - Backend

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
9095 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;
9136 nelberth 16
use LeadersLinked\Model\Feed;
17
use LeadersLinked\Mapper\HighPerformanceTeamsGroupsViewTopicMapper;
18
use LeadersLinked\Model\HighPerformanceTeamsGroupsMembers;
19
use LeadersLinked\Model\HighPerformanceTeamsGroups;
20
use LeadersLinked\Mapper\HighPerformanceTeamsGroupsMembersMapper;
21
use LeadersLinked\Mapper\HighPerformanceTeamsGroupsMapper;
9149 nelberth 22
use LeadersLinked\Mapper\FeedMapper;
9290 nelberth 23
use LeadersLinked\Mapper\UserMapper;
9095 nelberth 24
 
9298 nelberth 25
use LeadersLinked\Library\Functions;
26
 
9136 nelberth 27
 
16701 efrain 28
 
9095 nelberth 29
class HighPerformanceTeamsGroupsViewCalendarController extends AbstractActionController
30
{
31
    /**
32
     *
33
     * @var AdapterInterface
34
     */
35
    private $adapter;
36
 
37
 
38
    /**
39
     *
40
     * @var AbstractAdapter
41
     */
42
    private $cache;
43
 
44
    /**
45
     *
46
     * @var  LoggerInterface
47
     */
48
    private $logger;
49
 
50
    /**
51
     *
52
     * @var array
53
     */
54
    private $config;
55
 
56
 
57
 
58
    /**
59
     *
60
     * @param AdapterInterface $adapter
61
     * @param AbstractAdapter $cache
62
     * @param LoggerInterface $logger
63
     * @param array $config
64
     */
65
    public function __construct($adapter, $cache , $logger, $config)
66
    {
67
        $this->adapter      = $adapter;
68
        $this->cache        = $cache;
69
        $this->logger       = $logger;
70
        $this->config       = $config;
71
 
72
 
73
    }
9135 nelberth 74
 
75
 
9095 nelberth 76
    public function indexAction()
77
    {
9135 nelberth 78
 
9095 nelberth 79
 
9135 nelberth 80
        $currentUserPlugin = $this->plugin('currentUserPlugin');
81
        $currentUser = $currentUserPlugin->getUser();
82
        $currentCompany = $currentUserPlugin->getCompany();
11084 nelberth 83
        $group_uuid =  $this->params()->fromRoute('group_id');
84
        $feed_uuid =  $this->params()->fromRoute('feed_id');
9135 nelberth 85
 
9095 nelberth 86
        $request = $this->getRequest();
87
        if($request->isGet()) {
88
 
89
 
9135 nelberth 90
            $headers  = $request->getHeaders();
9095 nelberth 91
 
9135 nelberth 92
            $isJson = false;
93
            if($headers->has('Accept')) {
94
                $accept = $headers->get('Accept');
95
 
96
                $prioritized = $accept->getPrioritized();
97
 
98
                foreach($prioritized as $key => $value) {
99
                    $raw = trim($value->getRaw());
100
 
101
                    if(!$isJson) {
102
                        $isJson = strpos($raw, 'json');
103
                    }
104
 
105
                }
106
            }
9141 nelberth 107
 
9318 nelberth 108
            $highPerformanceTeamsGroupsMapper = HighPerformanceTeamsGroupsMapper::getInstance($this->adapter);
109
            $highPerformanceTeamsGroups = $highPerformanceTeamsGroupsMapper->fetchOneByUuid($group_uuid);
11184 nelberth 110
            $this->layout()->setTemplate('layout/layout-backend');
111
            $viewModel = new ViewModel();
9318 nelberth 112
            if (!$highPerformanceTeamsGroups) {
11184 nelberth 113
                $viewModel->setTemplate('leaders-linked/no-access/index.phtml');
114
                return $viewModel ;
9318 nelberth 115
            }
116
 
117
            if($highPerformanceTeamsGroups->status != HighPerformanceTeamsGroups::STATUS_ACTIVE) {
118
 
11184 nelberth 119
                $viewModel->setTemplate('leaders-linked/no-access/index.phtml');
120
                return $viewModel ;
9318 nelberth 121
 
122
            }
11184 nelberth 123
 
11136 nelberth 124
            $highPerformanceTeamsGroupsMembersMapper = HighPerformanceTeamsGroupsMembersMapper::getInstance($this->adapter);
125
            $highPerformanceTeamsGroupsMember = $highPerformanceTeamsGroupsMembersMapper->fetchOneByGroupIdAndUserId($highPerformanceTeamsGroups->id, $currentUser->id);
126
            if(!$highPerformanceTeamsGroupsMember) {
11184 nelberth 127
                $viewModel->setTemplate('leaders-linked/no-access/index.phtml');
128
                return $viewModel ;
11136 nelberth 129
            }
130
            if(!($highPerformanceTeamsGroupsMember->status == HighPerformanceTeamsGroupsMembers::STATUS_ACCEPTED || $highPerformanceTeamsGroupsMember->status == HighPerformanceTeamsGroupsMembers::STATUS_ADDED_BY_ADMIN) ){
11184 nelberth 131
                $viewModel->setTemplate('leaders-linked/no-access/index.phtml');
132
                return $viewModel ;
11136 nelberth 133
            }
134
            $addTopicBoton=true;
135
            if($highPerformanceTeamsGroupsMember->type==HighPerformanceTeamsGroupsMembers::TYPE_MODERATOR||$highPerformanceTeamsGroupsMember->type==HighPerformanceTeamsGroupsMembers::TYPE_USER){
136
                $addTopicBoton=false;
137
            }
9922 nelberth 138
 
139
 
140
            $viewModel->setTemplate('leaders-linked/high-performance-teams-groups-view-calendar/index.phtml');
141
            $viewModel->setVariables([
142
                'group_uuid'  =>  $group_uuid,
143
                'group_title'=>$highPerformanceTeamsGroups->title,
144
            ]);
145
            return $viewModel ;
146
 
147
        } else {
148
            return new JsonModel([
149
                'success' => false,
150
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
151
            ]);
152
        }
153
    }
154
 
155
    public function viewAction()
156
    {
157
 
16701 efrain 158
 
14740 efrain 159
        $now  = $utilMapper->getDatebaseNow();
9922 nelberth 160
 
161
        $currentUserPlugin = $this->plugin('currentUserPlugin');
162
        $currentUser = $currentUserPlugin->getUser();
163
        $currentCompany = $currentUserPlugin->getCompany();
11084 nelberth 164
        $group_uuid =  $this->params()->fromRoute('group_id');
165
        $feed_uuid =  $this->params()->fromRoute('feed_id');
9922 nelberth 166
 
167
        $request = $this->getRequest();
168
        if($request->isGet()) {
9142 nelberth 169
 
9922 nelberth 170
 
171
            $headers  = $request->getHeaders();
172
 
173
            $isJson = false;
174
            if($headers->has('Accept')) {
175
                $accept = $headers->get('Accept');
176
 
177
                $prioritized = $accept->getPrioritized();
178
 
179
                foreach($prioritized as $key => $value) {
180
                    $raw = trim($value->getRaw());
181
 
182
                    if(!$isJson) {
183
                        $isJson = strpos($raw, 'json');
184
                    }
185
 
186
                }
187
            }
188
            $highPerformanceTeamsGroupsMapper = HighPerformanceTeamsGroupsMapper::getInstance($this->adapter);
16701 efrain 189
            $now = $highPerformanceTeamsGroupsMapper->getDatebaseNow();
190
 
9922 nelberth 191
            $highPerformanceTeamsGroups = $highPerformanceTeamsGroupsMapper->fetchOneByUuid($group_uuid);
192
 
193
            if (!$highPerformanceTeamsGroups) {
194
                $data = [
195
                    'success' => false,
196
                    'data' => 'ERROR_RECORD_NOT_FOUND'
197
                ];
198
 
199
                return new JsonModel($data);
200
            }
201
 
202
            if($highPerformanceTeamsGroups->status != HighPerformanceTeamsGroups::STATUS_ACTIVE) {
203
 
204
                return new JsonModel([
205
                    'success' => false,
206
                    'data' => 'ERROR_UNAUTHORIZED'
207
                ]);
208
 
209
            }
11136 nelberth 210
 
211
            $highPerformanceTeamsGroupsMembersMapper = HighPerformanceTeamsGroupsMembersMapper::getInstance($this->adapter);
212
            $highPerformanceTeamsGroupsMember = $highPerformanceTeamsGroupsMembersMapper->fetchOneByGroupIdAndUserId($highPerformanceTeamsGroups->id, $currentUser->id);
213
            if(!$highPerformanceTeamsGroupsMember) {
214
                return new JsonModel([
215
                    'success' => false,
216
                    'data' => 'ERROR_RECORD_NOT_FOUND'
217
                ]);
218
            }
219
            if(!($highPerformanceTeamsGroupsMember->status == HighPerformanceTeamsGroupsMembers::STATUS_ACCEPTED || $highPerformanceTeamsGroupsMember->status == HighPerformanceTeamsGroupsMembers::STATUS_ADDED_BY_ADMIN) ){
220
                return new JsonModel([
221
                    'success' => false,
222
                    'data' => 'ERROR_YOU_DO_NOT_HAVE_ACCESS'
223
                ]);
224
            }
225
            $addTopicBoton=true;
226
            if($highPerformanceTeamsGroupsMember->type==HighPerformanceTeamsGroupsMembers::TYPE_MODERATOR||$highPerformanceTeamsGroupsMember->type==HighPerformanceTeamsGroupsMembers::TYPE_USER){
227
                $addTopicBoton=false;
228
            }
9922 nelberth 229
 
9135 nelberth 230
            if($isJson) {
9255 nelberth 231
                $acl = $this->getEvent()->getViewModel()->getVariable('acl');
9256 nelberth 232
                $allowView = $acl->isAllowed($currentUser->usertype_id,'high-performance-teams/groups/view/calendar');
9135 nelberth 233
 
9144 nelberth 234
 
9281 nelberth 235
                $items = [];
9156 nelberth 236
                $feedMapper = FeedMapper::getInstance($this->adapter);
9264 nelberth 237
                if(isset($feed_uuid)){
14740 efrain 238
                    $record  = $feedMapper->fetchOneByUuid($feed_uuid);
9269 nelberth 239
 
14740 efrain 240
                    if($record->high_performance_group_id!=$highPerformanceTeamsGroups->id){
9264 nelberth 241
                        return new JsonModel([
242
                            'success' => false,
9276 nelberth 243
                            'data' => 'ERROR_METHOD_NOT_ALLOWED'
9264 nelberth 244
                        ]);
9281 nelberth 245
                    }
9290 nelberth 246
 
14740 efrain 247
                    $items = $this->renderFeed($record, $now);
9264 nelberth 248
                }else{
249
                    $records  = $feedMapper->fetchAllTypeCalendar($highPerformanceTeamsGroups->id);
9282 nelberth 250
                    $contador=1;
9271 nelberth 251
                    foreach($records as $record)
252
                    {
253
                        $item = [
254
                            'id' => $record->uuid,
255
                            'title' => 'Reunion #'.$contador,
256
                            'start' => $record->date.'T'.$record->time,
257
                            'color'=>'#00000'.$contador,
11084 nelberth 258
                            'link_feed'=> $allowView ? $this->url()->fromRoute('high-performance-teams/groups/view/calendar/view', ['group_id' => $highPerformanceTeamsGroups->uuid, 'feed_id'=>$record->uuid]) : '',
9271 nelberth 259
                        ];
260
                        $contador++;
261
                        array_push($items, $item);
262
                    }
9281 nelberth 263
                }
9273 nelberth 264
 
9179 nelberth 265
                return new JsonModel([
266
                    'success' => true,
267
                    'data' => [
268
                        'items' => $items,
269
                    ]
270
                ]);
9135 nelberth 271
 
272
            }
9095 nelberth 273
        } else {
9179 nelberth 274
            return new JsonModel([
275
                'success' => false,
276
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
277
            ]);
9095 nelberth 278
        }
279
    }
9135 nelberth 280
 
14740 efrain 281
    private function renderFeed($feed, $now)
9290 nelberth 282
    {
283
 
15351 efrain 284
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
285
        $network = $currentNetworkPlugin->getNetwork();
286
 
9290 nelberth 287
        $userMapper = UserMapper::getInstance($this->adapter);
288
        $user = $userMapper->fetchOne($feed->user_id);
14740 efrain 289
 
290
        $item['owner_time_elapse'] = Functions::timeAgo(  $feed->added_on, $now);
9290 nelberth 291
        $item['feed_priority'] = $feed->priority;
15351 efrain 292
        $item['owner_url'] = 'https://'. $network->main_hostname . '/profile/view/' . $user->uuid;
9290 nelberth 293
        $item['owner_image'] = $this->url()->fromRoute('storage', ['code' => $user->uuid, 'type' => 'user', 'filename' => $user->image]);
294
        $item['owner_name'] = $user->first_name . ' ' . $user->last_name;
295
        $item['owner_description'] = strip_tags($feed->description, 'p');
296
        $dt = \DateTime::createFromFormat('Y-m-d', $feed->date);
297
        $dt2 = \DateTime::createFromFormat('H:i:s', $feed->time);
298
        $item['owner_meeting_date'] =  $dt->format('d/m/Y');
299
        $item['owner_meeting_time'] =  $dt2->format('h:i a');
300
        $item['owner_meeting_link_type'] =  $feed->link_type;
301
        $item['owner_meeting_link_name'] =  $feed->link_name;
302
 
303
        return $item;
304
    }
305
 
9095 nelberth 306
}