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