Proyectos de Subversion LeadersLinked - Backend

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
10144 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
 
10144 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;
16
use LeadersLinked\Model\Feed;
10146 nelberth 17
use LeadersLinked\Model\Topic;
10144 nelberth 18
use LeadersLinked\Mapper\HighPerformanceTeamsGroupsViewTopicMapper;
19
use LeadersLinked\Model\HighPerformanceTeamsGroupsMembers;
20
use LeadersLinked\Model\HighPerformanceTeamsGroups;
21
use LeadersLinked\Mapper\HighPerformanceTeamsGroupsMembersMapper;
22
use LeadersLinked\Mapper\HighPerformanceTeamsGroupsMapper;
23
use LeadersLinked\Mapper\FeedMapper;
10170 nelberth 24
use LeadersLinked\Mapper\TopicMapper;
10144 nelberth 25
use LeadersLinked\Mapper\UserMapper;
10170 nelberth 26
 
10144 nelberth 27
use Laminas\Db\Sql\Expression;
28
 
29
use LeadersLinked\Library\Functions;
30
 
31
use LeadersLinked\Mapper\QueryMapper;
32
 
10145 nelberth 33
class HighPerformanceTeamsGroupsViewForoController extends AbstractActionController
10144 nelberth 34
{
35
    /**
36
     *
37
     * @var AdapterInterface
38
     */
39
    private $adapter;
40
 
41
    /**
42
     *
43
     * @var  LoggerInterface
44
     */
45
    private $logger;
46
 
47
    /**
48
     *
49
     * @var array
50
     */
51
    private $config;
52
 
53
    /**
54
     *
55
     * @param AdapterInterface $adapter
56
     * @param LoggerInterface $logger
57
     * @param array $config
58
     */
16768 efrain 59
    public function __construct($adapter, $logger, $config)
10144 nelberth 60
    {
16768 efrain 61
        $this->adapter = $adapter;
62
        $this->logger = $logger;
63
        $this->config = $config;
10144 nelberth 64
    }
65
 
66
 
67
    public function indexAction()
68
    {
69
 
70
 
71
            $request = $this->getRequest();
72
            $this->layout()->setTemplate('layout/layout-backend');
73
            $viewModel = new ViewModel();
74
            $viewModel->setTemplate('leaders-linked/unknown/index.phtml');
75
            return $viewModel ;
76
    }
77
 
78
 
79
    public function viewAction()
80
    {
81
 
82
 
83
        $currentUserPlugin = $this->plugin('currentUserPlugin');
84
        $currentUser = $currentUserPlugin->getUser();
85
        $currentCompany = $currentUserPlugin->getCompany();
11086 nelberth 86
        $group_uuid =  $this->params()->fromRoute('group_id');
10144 nelberth 87
 
88
        $request = $this->getRequest();
89
        if($request->isGet()) {
90
 
91
 
92
            $headers  = $request->getHeaders();
93
 
94
            $isJson = false;
95
            if($headers->has('Accept')) {
96
                $accept = $headers->get('Accept');
97
 
98
                $prioritized = $accept->getPrioritized();
99
 
100
                foreach($prioritized as $key => $value) {
101
                    $raw = trim($value->getRaw());
102
 
103
                    if(!$isJson) {
104
                        $isJson = strpos($raw, 'json');
105
                    }
106
 
107
                }
108
            }
109
 
11138 nelberth 110
            if(!$group_uuid) {
111
                $data = [
112
                    'success'   => false,
113
                    'data'   => 'ERROR_INVALID_PARAMETER'
114
                ];
115
 
116
                return new JsonModel($data);
117
            }
118
 
10144 nelberth 119
            $highPerformanceTeamsGroupsMapper = HighPerformanceTeamsGroupsMapper::getInstance($this->adapter);
120
            $highPerformanceTeamsGroups = $highPerformanceTeamsGroupsMapper->fetchOneByUuid($group_uuid);
121
 
122
            if (!$highPerformanceTeamsGroups) {
123
                $data = [
124
                    'success' => false,
125
                    'data' => 'ERROR_RECORD_NOT_FOUND'
126
                ];
11138 nelberth 127
 
10144 nelberth 128
                return new JsonModel($data);
129
            }
130
            if($highPerformanceTeamsGroups->status != HighPerformanceTeamsGroups::STATUS_ACTIVE) {
131
 
132
                return new JsonModel([
133
                    'success' => false,
134
                    'data' => 'ERROR_UNAUTHORIZED'
135
                ]);
136
 
137
            }
11138 nelberth 138
            $highPerformanceTeamsGroupsMembersMapper = HighPerformanceTeamsGroupsMembersMapper::getInstance($this->adapter);
139
            $highPerformanceTeamsGroupsMember = $highPerformanceTeamsGroupsMembersMapper->fetchOneByGroupIdAndUserId($highPerformanceTeamsGroups->id, $currentUser->id);
140
            if(!$highPerformanceTeamsGroupsMember) {
141
                return new JsonModel([
142
                    'success' => false,
143
                    'data' => 'ERROR_YOU_DO_NOT_HAVE_ACCESS'
144
                ]);
145
            }
146
            if(!($highPerformanceTeamsGroupsMember->status == HighPerformanceTeamsGroupsMembers::STATUS_ACCEPTED || $highPerformanceTeamsGroupsMember->status == HighPerformanceTeamsGroupsMembers::STATUS_ADDED_BY_ADMIN) ){
147
                return new JsonModel([
148
                    'success' => false,
149
                    'data' => 'ERROR_YOU_DO_NOT_HAVE_ACCESS'
150
                ]);
151
            }
152
 
10144 nelberth 153
            if($isJson) {
154
                $acl = $this->getEvent()->getViewModel()->getVariable('acl');
10166 nelberth 155
                $allowView = $acl->isAllowed($currentUser->usertype_id,'high-performance-teams/groups/view/foro/categories/articles/view');
10144 nelberth 156
                $items = [];
157
                $feedMapper = FeedMapper::getInstance($this->adapter);
10146 nelberth 158
                $paginator  = $feedMapper->fetchFiveForoJoinTopic($highPerformanceTeamsGroups->id, Topic::TYPE_HPTGF);
10163 nelberth 159
 
160
                $records = $paginator->getCurrentItems();
10166 nelberth 161
                $topicMapper = TopicMapper::getInstance($this->adapter);
10165 nelberth 162
 
10144 nelberth 163
                    foreach($records as $record)
164
                    {
10166 nelberth 165
 
10188 nelberth 166
                        $topic  = $topicMapper->fetchOne($record->topic_id);
10192 nelberth 167
 
10144 nelberth 168
                        $item = [
10146 nelberth 169
                            'title' => $record->title,
10193 nelberth 170
                            'category' => $topic->title,
11086 nelberth 171
                            'link_foro'=> $allowView ? $this->url()->fromRoute('high-performance-teams/groups/view/foro/categories/articles/view',['group_id' => $highPerformanceTeamsGroups->uuid,'category_id' => $topic->uuid, 'article_id' => $record->uuid]) : '',
10144 nelberth 172
                        ];
173
                        array_push($items, $item);
174
                    }
175
 
10146 nelberth 176
 
10144 nelberth 177
                return new JsonModel([
178
                    'success' => true,
179
                    'data' => [
180
                        'items' => $items,
181
                    ]
182
                ]);
183
 
184
            }
185
        } else {
186
            return new JsonModel([
187
                'success' => false,
188
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
189
            ]);
190
        }
191
    }
192
 
14740 efrain 193
    private function renderFeed($feed, $now)
10144 nelberth 194
    {
15351 efrain 195
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
196
        $network = $currentNetworkPlugin->getNetwork();
10144 nelberth 197
 
198
        $userMapper = UserMapper::getInstance($this->adapter);
199
        $user = $userMapper->fetchOne($feed->user_id);
14740 efrain 200
 
201
        $item['owner_time_elapse'] = Functions::timeAgo( $feed->added_on, $now);
10144 nelberth 202
        $item['feed_priority'] = $feed->priority;
15351 efrain 203
        $item['owner_url'] = 'https://'. $network->main_hostname . '/profile/view/' . $user->uuid,
10144 nelberth 204
        $item['owner_image'] = $this->url()->fromRoute('storage', ['code' => $user->uuid, 'type' => 'user', 'filename' => $user->image]);
205
        $item['owner_name'] = $user->first_name . ' ' . $user->last_name;
206
        $item['owner_description'] = strip_tags($feed->description, 'p');
207
        $dt = \DateTime::createFromFormat('Y-m-d', $feed->date);
208
        $dt2 = \DateTime::createFromFormat('H:i:s', $feed->time);
209
        $item['owner_meeting_date'] =  $dt->format('d/m/Y');
210
        $item['owner_meeting_time'] =  $dt2->format('h:i a');
211
        $item['owner_meeting_link_type'] =  $feed->link_type;
212
        $item['owner_meeting_link_name'] =  $feed->link_name;
213
 
214
        return $item;
215
    }
216
 
217
}