Rev 7300 | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |
<?php
declare(strict_types=1);
namespace LeadersLinked\Controller;
use Laminas\Db\Adapter\AdapterInterface;
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;
use Laminas\Mvc\I18n\Translator;
use LeadersLinked\Cache\CacheInterface;
use LeadersLinked\Mapper\SurveyTestMapper;
use LeadersLinked\Mapper\SurveyCampaignMapper;
class CalendarController extends AbstractActionController
{
/**
*
* @var \Laminas\Db\Adapter\AdapterInterface
*/
private $adapter;
/**
*
* @var \LeadersLinked\Cache\CacheInterface
*/
private $cache;
/**
*
* @var \Laminas\Log\LoggerInterface
*/
private $logger;
/**
*
* @var array
*/
private $config;
/**
*
* @var \Laminas\Mvc\I18n\Translator
*/
private $translator;
/**
*
* @param \Laminas\Db\Adapter\AdapterInterface $adapter
* @param \LeadersLinked\Cache\CacheInterface $cache
* @param \Laminas\Log\LoggerInterface LoggerInterface $logger
* @param array $config
* @param \Laminas\Mvc\I18n\Translator $translator
*/
public function __construct($adapter, $cache, $logger, $config, $translator)
{
$this->adapter = $adapter;
$this->cache = $cache;
$this->logger = $logger;
$this->config = $config;
$this->translator = $translator;
}
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');
$end = 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_SURVEY_NORMAL:
$backgroundColor = $currentNetwork->css_calendar_survey_bg_color;
$textColor = $currentNetwork->css_calendar_survey_text_color;
$surveyTestMapper = SurveyTestMapper::getInstance($this->adapter);
$surveyTest = $surveyTestMapper->fetchOne($record->relational_id);
if($surveyTest && $surveyTest->user_id == $currentUser->id) {
$surveyCampaingMapper = SurveyCampaignMapper::getInstance($this->adapter);
$surveyCampaing = $surveyCampaingMapper->fetchOne($surveyTest->campaign_id);
$url = '';
$hasLink = !empty($companyUsers[$surveyTest->company_id]);
if ($hasLink) {
if (!isset($companies[$surveyTest->company_id])) {
$company = $companyMapper->fetchOne($surveyTest->company_id);
$companies[$company->id] = $company;
} else {
$company = $companies[$surveyTest->company_id];
}
$url = $this->url()->fromRoute('backend/signin-company', [
'id' => $company->uuid,
'relational' => $surveyTest->uuid,
'type' => CalendarEvent::TYPE_SURVEY_ORGANIZATIONAL_CLIMATE,
]);
}
$dtStart = \DateTime::createFromFormat('Y-m-d', $surveyCampaing->end_date);
array_push($events, [
'id' => $surveyTest->uuid,
'title' => $surveyCampaing->name,
'start' => $dtStart->format('d/m/Y'),
'url' => $url,
'backgroundColor' => $backgroundColor,
'textColor' => $textColor,
'allDay' => true,
'type' => 'task',
]);
}
break;
case CalendarEvent::TYPE_SURVEY_ORGANIZATIONAL_CLIMATE:
$backgroundColor = $currentNetwork->css_calendar_organizational_climate_bg_color;
$textColor = $currentNetwork->css_calendar_organizational_climate_text_color;
$surveyTestMapper = SurveyTestMapper::getInstance($this->adapter);
$surveyTest = $surveyTestMapper->fetchOne($record->relational_id);
if($surveyTest && $surveyTest->user_id == $currentUser->id) {
$surveyCampaingMapper = SurveyCampaignMapper::getInstance($this->adapter);
$surveyCampaing = $surveyCampaingMapper->fetchOne($surveyTest->campaign_id);
$url = '';
$hasLink = !empty($companyUsers[$surveyTest->company_id]);
if ($hasLink) {
if (!isset($companies[$surveyTest->company_id])) {
$company = $companyMapper->fetchOne($surveyTest->company_id);
$companies[$company->id] = $company;
} else {
$company = $companies[$surveyTest->company_id];
}
$url = $this->url()->fromRoute('backend/signin-company', [
'id' => $company->uuid,
'relational' => $surveyTest->uuid,
'type' => CalendarEvent::TYPE_SURVEY_ORGANIZATIONAL_CLIMATE,
]);
}
$dtStart = \DateTime::createFromFormat('Y-m-d', $surveyCampaing->end_date);
array_push($events, [
'id' => $surveyTest->uuid,
'title' => $surveyCampaing->name,
'start' => $dtStart->format('d/m/Y'),
'url' => $url,
'backgroundColor' => $backgroundColor,
'textColor' => $textColor,
'allDay' => true,
'type' => 'task',
]);
}
break;
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) {
$url = '';
$hasLink = !empty($companyUsers[$recruitmentSelectionInterview->company_id]);
if($hasLink) {
if(!isset($companies[$recruitmentSelectionInterview->company_id])) {
$company = $companyMapper->fetchOne($recruitmentSelectionInterview->company_id);
$companies[ $company->id ] = $company;
} else {
$company = $companies[ $recruitmentSelectionInterview->company_id ];
}
$url = $this->url()->fromRoute('backend/signin-company', [
'id' => $company->uuid,
'relational' => $recruitmentSelectionInterview->uuid,
'type' => CalendarEvent::TYPE_RECRUITMENT_SELECTION_INTERVIEW
]);
}
$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>" ;
array_push($events, [
'id' => $recruitmentSelectionInterview->uuid,
'title' => $recruitmentSelectionVacancy->name,
'agenda' => $agenda,
'url' => $url,
'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) {
$url = '';
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 = !empty($companyUsers[$performanceEvaluationTest->company_id]);
switch ($performanceEvaluationTest->type)
{
case PerformanceEvaluationTest::TYPE_SUPERVISOR :
case PerformanceEvaluationTest::TYPE_BOTH :
if($performanceEvaluationTest->supervisor_id != $currentUser->id) {
$hasLink = false;
}
break;
case PerformanceEvaluationTest::TYPE_EMPLOYEE :
if($performanceEvaluationTest->employee_id != $currentUser->id) {
$hasLink = false;
}
break;
default :
$hasLink = false;
break;
}
if($hasLink) {
if(!isset($companies[$performanceEvaluationTest->company_id])) {
$company = $companyMapper->fetchOne($performanceEvaluationTest->company_id);
$companies[ $company->id ] = $company;
} else {
$company = $companies[ $performanceEvaluationTest->company_id ];
}
$url = $this->url()->fromRoute('backend/signin-company', [
'id' => $company->uuid,
'relational' => $performanceEvaluationTest->uuid,
'type' => CalendarEvent::TYPE_PERFORMANCE_EVALUATION
]);
}
$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>" ;
array_push($events, [
'id' => $performanceEvaluationTest->uuid,
'title' => $performanceEvaluationForm->name,
'agenda' => $agenda,
'start' => $dtStart->format('Y-m-d'),
'url' => $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);
}
}