Rev 4300 | Rev 4656 | Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |
<?phpdeclare(strict_types=1);namespace LeadersLinked\Controller;use Laminas\Db\Adapter\AdapterInterface;use Laminas\Cache\Storage\Adapter\AbstractAdapter;use Laminas\Mvc\Controller\AbstractActionController;use Laminas\Log\LoggerInterface;use Laminas\View\Model\ViewModel;use Laminas\View\Model\JsonModel;use LeadersLinked\Mapper\UserMapper;use LeadersLinked\Mapper\ChatUserMapper;use LeadersLinked\Mapper\ChatGroupMapper;use LeadersLinked\Mapper\ChatGroupUserMapper;use LeadersLinked\Mapper\CalendarEventMapper;use LeadersLinked\Mapper\ZoomMeetingMapper;use LeadersLinked\Model\CalendarEvent;use LeadersLinked\Library\Functions;use LeadersLinked\Mapper\PerformanceEvaluationEvaluationMapper;use LeadersLinked\Mapper\PerformanceEvaluationFormMapper;use LeadersLinked\Model\PerformanceEvaluationEvaluation;use LeadersLinked\Mapper\JobDescriptionMapper;use LeadersLinked\Mapper\CompanyUserMapper;use LeadersLinked\Model\CompanyUser;use LeadersLinked\Mapper\CompanyMapper;class CalendarController extends AbstractActionController{/**** @var AdapterInterface*/private $adapter;/**** @var AbstractAdapter*/private $cache;/**** @var LoggerInterface*/private $logger;/**** @var array*/private $config;/**** @param AdapterInterface $adapter* @param AbstractAdapter $cache* @param LoggerInterface $logger* @param array $config*/public function __construct($adapter, $cache, $logger, $config){$this->adapter = $adapter;$this->cache = $cache;$this->logger = $logger;$this->config = $config;}public function indexAction(){$currentUserPlugin = $this->plugin('currentUserPlugin');$currentUser = $currentUserPlugin->getUser();$this->layout()->setTemplate('layout/layout.phtml');$viewModel = new ViewModel();$viewModel->setTemplate('leaders-linked/calendar/index.phtml');return $viewModel;}public function eventsAction(){$request = $this->getRequest();if($request->isGet()) {$currentUserPlugin = $this->plugin('currentUserPlugin');$currentUser = $currentUserPlugin->getUser();$currentNetworkPlugin = $this->plugin('currentNetworkPlugin');$currentNetwork = $currentNetworkPlugin->getNetwork();$start = $this->params()->fromQuery('start');$end = $this->params()->fromQuery('end');if(!empty($start) && !empty($end)) {$dtStart = \DateTime::createFromFormat('Y-m-d', $start);$dtEnd = \DateTime::createFromFormat('Y-m-d', $end);} else {$dtStart = null;$dtEnd = null;}if(!$dtStart || !$dtEnd) {$t = time();$year = intval(date('Y', $t), 10);$month = intval(date('m', $t), 10);$last_day = intval(date('t', $t), 10);$start = mktime(0, 0, 0, $month, 1, $year);$start = date('Y-m-d H:i:s');$start = mktime(23, 56, 59, $month, $last_day, $year);$end = date('Y-m-d H:i:s');} else {$dtStart->setTime(0, 0, 0);$start = $dtStart->format('Y-m-d H:i:s');$dtEnd->setTime(23, 59, 59);$end = $dtEnd->format('Y-m-d H:i:s');}$events = [];//3 días$expirePeriod = 86400 * 3;$t1 = time();$companies = [];$companyMapper = CompanyMapper::getInstance($this->adapter);$companyUsers = [];$companyUserMapper = CompanyUserMapper::getInstance($this->adapter);$records = $companyUserMapper->fetchAllByUserId($currentUser->id);foreach($records as $record) {$companyUsers[$record->company_id] = $record->backend == CompanyUser::BACKEND_YES;}$zoomMeetingMapper = ZoomMeetingMapper::getInstance($this->adapter);$performanceEvaluationEvaluationMapper = PerformanceEvaluationEvaluationMapper::getInstance($this->adapter);$performanceEvaluationFormMapper = PerformanceEvaluationFormMapper::getInstance($this->adapter);$jobDescriptionMapper = JobDescriptionMapper::getInstance($this->adapter);$userMapper = UserMapper::getInstance($this->adapter);$calendarEventMapper = CalendarEventMapper::getInstance($this->adapter);$records = $calendarEventMapper->fetchAllByUserIdAndStartTimeAndEndTime($currentUser->id, $start, $end);foreach($records as $record){switch($record->type){case CalendarEvent::TYPE_PERFORMANCE_EVALUATION :$backgroundColor = $currentNetwork->css_calendar_performance_evaluation_bg_color ;$textColor = $currentNetwork->css_calendar_performance_evaluation_text_color;$performanceEvaluationEvaluation = $performanceEvaluationEvaluationMapper->fetchOne($record->relational_id);if($performanceEvaluationEvaluation) {$performanceEvaluationForm = $performanceEvaluationFormMapper->fetchOne($performanceEvaluationEvaluation->form_id);if($performanceEvaluationForm) {$jobDescription = $jobDescriptionMapper->fetchOne($performanceEvaluationForm->job_description_id);if($jobDescription) {if($performanceEvaluationEvaluation->supervisor_id) {$supervisor = $userMapper->fetchOne($performanceEvaluationEvaluation->supervisor_id);} else {$supervisor = '';}if($performanceEvaluationEvaluation->employee_id) {$employee = $userMapper->fetchOne($performanceEvaluationEvaluation->employee_id);} else {$employee = '';}$hasLink = false;if(isset($companyUsers[$currentUser->id])) {if($companyUsers[$currentUser->id]) {$hasLink = true;}}if($hasLink) {if(!isset($companies[$performanceEvaluationEvaluation->company_id])) {$company = $companyMapper->fetchOne($performanceEvaluationEvaluation->company_id);$companies[ $company->id ] = $company;} else {$company = $companies[ $performanceEvaluationEvaluation->company_id ];}$href = $this->url()->fromRoute('backend/signin-company', ['id' => $company->uuid,'relational' => $performanceEvaluationEvaluation->uuid,'type' => CalendarEvent::TYPE_PERFORMANCE_EVALUATION]);$agenda = '<a href="'.$href.'" class="goto-backend"><br>';}$agenda .= " LABEL_PERFORMANCE_EVALUATION_FORM_NAME : " . $performanceEvaluationForm->name . "<br>";$agenda .= " LABEL_PERFORMANCE_EVALUATION_JOB_DESCRIPTION : " . $jobDescription->name . "<br>";switch($performanceEvaluationEvaluation->type){case PerformanceEvaluationEvaluation::TYPE_BOTH :$agenda .= " LABEL_PERFORMANCE_EVALUATION_TYPE : LABEL_PERFORMANCE_EVALUATION_TYPE_BOTH <br>";break;case PerformanceEvaluationEvaluation::TYPE_SUPERVISOR :$agenda .= " LABEL_PERFORMANCE_EVALUATION_TYPE : LABEL_PERFORMANCE_EVALUATION_TYPE_SUPERVISOR <br>";break;case PerformanceEvaluationEvaluation::TYPE_EMPLOYEE :$agenda .= " LABEL_PERFORMANCE_EVALUATION_TYPE : LABEL_PERFORMANCE_EVALUATION_TYPE_EMPLOYEE <br>";break;}if($supervisor) {$agenda .= " LABEL_PERFORMANCE_EVALUATION_SUPERVISOR : " . trim($supervisor->first_name . ' ' . $supervisor->last_name) . " <br>";}if($employee) {$agenda .= " LABEL_PERFORMANCE_EVALUATION_EMPLOYEE : " . trim($employee->first_name . ' ' . $employee->last_name) . " <br>";}$dtStart = \DateTime::createFromFormat('Y-m-d', $performanceEvaluationEvaluation->last_date);$agenda .= " LABEL_PERFORMANCE_EVALUATION_LAST_DATE : " . $dtStart->format('Y-m-d') . "<br>" ;if($hasLink) {$agenda .= "</a><br>";}array_push($events, ['id' => $performanceEvaluationEvaluation->uuid,'title' => $performanceEvaluationForm->name,'agenda' => $agenda,'start' => $start,'url' => '','backgroundColor' => $backgroundColor,'textColor' => $textColor,]);}}}break;case CalendarEvent::TYPE_ZOOM :$zoomMeeting = $zoomMeetingMapper->fetchOne($record->relational_id);if($zoomMeeting) {$backgroundColor = $currentNetwork->css_calendar_zoom_bg_color ;$textColor = $currentNetwork->css_calendar_zoom_text_color;$dtStart = \DateTime::createFromFormat('Y-m-d H:i:s', $zoomMeeting->start_time);$t2 = $dtStart->getTimestamp();if($t2 > $t1) {$t3 = $t1 + $expirePeriod;if($t3 > $t2) {$backgroundColor = $currentNetwork->css_calendar_expire_bg_color;$textColor = $currentNetwork->css_calendar_expire_text_color;}}if($currentUser->timezone && $currentUser->timezone != $zoomMeeting->timezone) {$start = str_replace(' ', 'T', Functions::convertDateTimeBetweenTimeZones($zoomMeeting->start_time, $zoomMeeting->timezone, $currentUser->timezone));$end = str_replace(' ', 'T', Functions::convertDateTimeBetweenTimeZones($zoomMeeting->end_time, $zoomMeeting->timezone, $currentUser->timezone));} else {$start = str_replace(' ', 'T', $zoomMeeting->start_time);$end = str_replace(' ', 'T', $zoomMeeting->end_time);}$agenda = "<a href=\"{$zoomMeeting->join_url}\" target=\"_blank\">" . $zoomMeeting->agenda . "<br>" ." LABEL_ZOOM_MEETING_START_DATE : " . $dtStart->format('Y-m-d') . "<br>" ." LABEL_ZOOM_MEETING_START_TIME : " . $dtStart->format('H:i a') . "<br>" ." LABEL_ZOOM_MEETING_TIMEZONE : " . $zoomMeeting->timezone . "<br>" ." LABEL_ZOOM_MEETING_TITLE : " . $zoomMeeting->topic . "<br>" ." LABEL_ZOOM_MEETING_URL : " . $zoomMeeting->join_url . "<br>" ." LABEL_ZOOM_MEETING_PASSWORD : " . $zoomMeeting->password . "<br>" ."</a>";array_push($events, ['id' => $zoomMeeting->id,'title' => $zoomMeeting->topic,'agenda' => $agenda,'start' => $start,'end' => $end,'url' => $zoomMeeting->join_url,'backgroundColor' => $backgroundColor,'textColor' => $textColor,]);}break;}}return new JsonModel($events);} else {$response = ['success' => false,'data' => 'ERROR_METHOD_NOT_ALLOWED'];}return new JsonModel($response);}}