Rev 5050 | Rev 6849 | 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\CalendarEventMapper;use LeadersLinked\Mapper\ZoomMeetingMapper;use LeadersLinked\Model\CalendarEvent;use LeadersLinked\Library\Functions;use LeadersLinked\Mapper\PerformanceEvaluationTestMapper;use LeadersLinked\Mapper\PerformanceEvaluationFormMapper;use LeadersLinked\Model\PerformanceEvaluationTest;use LeadersLinked\Mapper\JobDescriptionMapper;use LeadersLinked\Mapper\CompanyUserMapper;use LeadersLinked\Model\CompanyUser;use LeadersLinked\Mapper\CompanyMapper;use LeadersLinked\Mapper\RecruitmentSelectionInterviewMapper;use LeadersLinked\Mapper\RecruitmentSelectionCandidateMapper;use LeadersLinked\Mapper\RecruitmentSelectionVacancyMapper;use LeadersLinked\Model\RecruitmentSelectionInterview;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);$recruitmentSelectionCandidateMapper = RecruitmentSelectionCandidateMapper::getInstance($this->adapter);$recruitmentSelectionVacancyMapper = RecruitmentSelectionVacancyMapper::getInstance($this->adapter);$recruitmentSelectionInterviewMapper = RecruitmentSelectionInterviewMapper::getInstance($this->adapter);$performanceEvaluationTestMapper = PerformanceEvaluationTestMapper::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_RECRUITMENT_SELECTION_INTERVIEW :$backgroundColor = $currentNetwork->css_calendar_recruitment_and_selection_bg_color ;$textColor = $currentNetwork->css_calendar_recruitment_and_selection_text_color;$recruitmentSelectionInterview = $recruitmentSelectionInterviewMapper->fetchOne($record->relational_id);if($recruitmentSelectionInterview) {$recruitmentSelectionVacancy = $recruitmentSelectionVacancyMapper->fetchOne($recruitmentSelectionInterview->vacancy_id);$recruitmentSelectionCandidate = $recruitmentSelectionCandidateMapper->fetchOne($recruitmentSelectionInterview->candidate_id);if($recruitmentSelectionVacancy && $recruitmentSelectionCandidate) {$jobDescription = $jobDescriptionMapper->fetchOne($recruitmentSelectionVacancy->job_description_id);if($jobDescription) {$hasLink = false;if(isset($companyUsers[$currentUser->id])) {if($companyUsers[$currentUser->id]) {$hasLink = true;}}if($hasLink) {if(!isset($companies[$recruitmentSelectionInterview->company_id])) {$company = $companyMapper->fetchOne($recruitmentSelectionInterview->company_id);$companies[ $company->id ] = $company;} else {$company = $companies[ $recruitmentSelectionInterview->company_id ];}$href = $this->url()->fromRoute('backend/signin-company', ['id' => $company->uuid,'relational' => $recruitmentSelectionInterview->uuid,'type' => CalendarEvent::TYPE_RECRUITMENT_SELECTION_INTERVIEW]);$agenda = '<a href="'.$href.'" class="goto-backend"><br>';}$agenda .= " LABEL_RECRUITMENT_SELECTION_JOB_DESCRIPTION : " . $jobDescription->name . "<br>";switch($recruitmentSelectionInterview->type){case RecruitmentSelectionInterview::TYPE_BOSS :$agenda .= " LABEL_RECRUITMENT_SELECTION_TYPE : LABEL_RECRUITMENT_SELECTION_TYPE_BOSS_INTERVIEW <br>";break;case RecruitmentSelectionInterview::TYPE_HUMAN_RESOURCE :$agenda .= " LABEL_RECRUITMENT_SELECTION_TYPE : LABEL_RECRUITMENT_SELECTION_TYPE_HUMAN_RESOURCE <br>";break;}$agenda .= " LABEL_RECRUITMENT_SELECTION_CANDIDATE : " . trim($recruitmentSelectionCandidate->first_name . ' ' . $recruitmentSelectionCandidate->last_name) . " <br>";$dtStart = \DateTime::createFromFormat('Y-m-d', $recruitmentSelectionInterview->last_date);$agenda .= " LABEL_PERFORMANCE_EVALUATION_LAST_DATE : " . $dtStart->format('Y-m-d') . "<br>" ;if($hasLink) {$agenda .= "</a><br>";}array_push($events, ['id' => $recruitmentSelectionInterview->uuid,'title' => $recruitmentSelectionVacancy->name,'agenda' => $agenda,'start' => $dtStart->format('Y-m-d'),'url' => '','backgroundColor' => $backgroundColor,'textColor' => $textColor,'allDay' => true,'type' => 'task',]);}}}break;case CalendarEvent::TYPE_PERFORMANCE_EVALUATION :$backgroundColor = $currentNetwork->css_calendar_performance_evaluation_bg_color ;$textColor = $currentNetwork->css_calendar_performance_evaluation_text_color;$performanceEvaluationTest = $performanceEvaluationTestMapper->fetchOne($record->relational_id);if($performanceEvaluationTest) {$performanceEvaluationForm = $performanceEvaluationFormMapper->fetchOne($performanceEvaluationTest->form_id);if($performanceEvaluationForm) {$jobDescription = $jobDescriptionMapper->fetchOne($performanceEvaluationForm->job_description_id);if($jobDescription) {if($performanceEvaluationTest->supervisor_id) {$supervisor = $userMapper->fetchOne($performanceEvaluationTest->supervisor_id);} else {$supervisor = '';}if($performanceEvaluationTest->employee_id) {$employee = $userMapper->fetchOne($performanceEvaluationTest->employee_id);} else {$employee = '';}$hasLink = false;if(isset($companyUsers[$currentUser->id])) {if($companyUsers[$currentUser->id]) {$hasLink = true;}}if($hasLink) {if(!isset($companies[$performanceEvaluationTest->company_id])) {$company = $companyMapper->fetchOne($performanceEvaluationTest->company_id);$companies[ $company->id ] = $company;} else {$company = $companies[ $performanceEvaluationTest->company_id ];}$href = $this->url()->fromRoute('backend/signin-company', ['id' => $company->uuid,'relational' => $performanceEvaluationTest->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($performanceEvaluationTest->type){case PerformanceEvaluationTest::TYPE_BOTH :$agenda .= " LABEL_PERFORMANCE_EVALUATION_TYPE : LABEL_PERFORMANCE_EVALUATION_TYPE_BOTH <br>";break;case PerformanceEvaluationTest::TYPE_SUPERVISOR :$agenda .= " LABEL_PERFORMANCE_EVALUATION_TYPE : LABEL_PERFORMANCE_EVALUATION_TYPE_SUPERVISOR <br>";break;case PerformanceEvaluationTest::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', $performanceEvaluationTest->last_date);$agenda .= " LABEL_PERFORMANCE_EVALUATION_LAST_DATE : " . $dtStart->format('Y-m-d') . "<br>" ;if($hasLink) {$agenda .= "</a><br>";}array_push($events, ['id' => $performanceEvaluationTest->uuid,'title' => $performanceEvaluationForm->name,'agenda' => $agenda,'start' => $dtStart->format('Y-m-d'),'url' => '','backgroundColor' => $backgroundColor,'textColor' => $textColor,'allDay' => true,'type' => 'task',]);}}}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,'type' => 'event',]);}break;}}return new JsonModel($events);} else {$response = ['success' => false,'data' => 'ERROR_METHOD_NOT_ALLOWED'];}return new JsonModel($response);}}