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