id */ function getId() { return $this->data['entity']->getId(); } /** * return modified time of Google Record * @return modified time */ public function getModifiedTime() { return $this->vtigerFormat($this->data['entity']->getUpdated()); } /** * converts the Google Format date to * @param $date Google Date * @return Vtiger date Format */ public static function vtigerFormat($date) { $origDate = $date; list($date, $timestring) = explode('T', $date); list($time, $tz) = explode('.', $timestring); // EDIT - if this is UTC lets change it to correct system time if (substr($tz, -1) == 'Z') { $date = new DateTime($origDate); $timeZone = new DateTimeZone(date_default_timezone_get()); $date->setTimezone($timeZone); $date = $date->format('Y-m-d H:i:s'); return $date; } return $date . " " . $time; } /** * return Subject of Google Record * @return Subject */ function getSubject() { return $this->data['entity']->getSummary(); } /** * @return bool */ public function isAllDay() { $start = $this->getEntity()->getStart(); $end = $this->getEntity()->getEnd(); return ($start->getDate() && $end->getDate()); } /** * @return object */ public function getEntity() { return $this->data['entity']; } /** * return Start time time in UTC of Google Record * @return string start time */ function getStartTimeUTC($user = false) { if (isset($this->startUTC)) { return $this->startUTC; } if (!$user) { $user = Users_Record_Model::getCurrentUserModel(); } $when = $this->data['entity']->getStart(); if (empty($when)) { $gStart = "00:00"; } else { if ($when->getDateTime()) { $gStart = $when->getDateTime(); } else { $gStart = "00:00"; } } $start = new DateTime($gStart); $timeZone = new DateTimeZone(date_default_timezone_get()); $start->setTimezone($timeZone); $startUTC = $start->format('H:i:s'); $gDateTime = $when->getDateTime(); if ($startUTC == '00:00:00' && empty($gDateTime)) { $userTimezone = $user->get('time_zone'); $startUTCObj = DateTimeField::convertTimeZone($startUTC, $userTimezone, DateTimeField::getDBTimeZone()); $startUTC = $startUTCObj->format('H:i:s'); } $this->startUTC = $startUTC; return $startUTC; } /** * return End time in UTC of Google Record * @return string end time * @throws Exception */ function getEndTimeUTC($user = false) { if (isset($this->endUTC)) { return $this->endUTC; } if (!$user) { $user = Users_Record_Model::getCurrentUserModel(); } $when = $this->data['entity']->getEnd(); if (empty($when)) { $gEnd = "00:00"; } else { if ($when->getDateTime()) { $gEnd = $when->getDateTime(); } else { $gEnd = "00:00"; } } $end = new DateTime($gEnd); $timeZone = new DateTimeZone(date_default_timezone_get()); $end->setTimezone($timeZone); $endUTC = $end->format('H:i:s'); $gDateTime = $when->getDateTime(); if ($endUTC == '00:00:00' && empty($gDateTime)) { $userTimezone = $user->get('time_zone'); $startUTCObj = DateTimeField::convertTimeZone($endUTC, $userTimezone, DateTimeField::getDBTimeZone()); $endUTC = $startUTCObj->format('H:i:s'); } $this->endUTC = $endUTC; return $endUTC; } /** * @return string * @throws Exception */ public function getTaskStartDate() { $startDate = $this->data['entity']->getStart(); $date = $this->getDateFromObject($startDate); return $this->getUTCDate($date); } /** * @param object $value * @param string $date * @return string */ public function getDateFromObject($value, $date = '') { if (!empty($value)) { if ($value->getDateTime()) { $date = $value->getDateTime(); } else { if ($value->getDate()) { $date = $value->getDate(); } } } return $date; } /** * @param string $date * @param string $format * @return string * @throws Exception */ public function getUTCDate($date, $format = 'Y-m-d') { $timeZone = new DateTimeZone('UTC'); $start = new DateTime($date, $timeZone); return $start->format($format); } /** * @return string * @throws Exception */ public function getTaskEndDate() { $startDate = $this->data['entity']->getEnd(); $date = $this->getDateFromObject($startDate); return $this->getUTCDate($date); } /** * @retrun Google_Service_Calendar_Event */ public function getDataEntity() { return $this->data['entity']; } /** * @param Google_Service_Calendar_EventDateTime $when * @return string */ public function getWhenDate($when) { if (!$when) { return date('Y-m-d'); } if ($when->getDateTime()) { return $when->getDateTime(); } if ($when->getDate()) { return $when->getDate(); } return date('Y-m-d'); } /** * return start date in UTC of Google Record * @return string start date * @throws Exception */ function getStartDate($user = false) { if (isset($this->googleStartDate)) { return $this->googleStartDate; } if (!$user) { $user = Users_Record_Model::getCurrentUserModel(); } $when = $this->getDataEntity()->getStart(); $gStart = $this->getWhenDate($when); $timeZone = new DateTimeZone('UTC'); $start = new DateTime($gStart); $start->setTimezone($timeZone); $startDate = $start->format('Y-m-d'); if ($start->format('H:i:s') == '00:00:00' && empty($when->getDateTime())) { $userTimezone = $user->get('time_zone'); $startUTCObj = DateTimeField::convertTimeZone($startDate, $userTimezone, DateTimeField::getDBTimeZone()); $startDate = $startUTCObj->format('Y-m-d'); } $this->googleStartDate = $startDate; return $startDate; } /** * @param Google_Service_Calendar_EventDateTime $when * @param Users_Record_Model $user * @return string * @throws Exception */ public function getUserDatetime($when, $user = null) { $whenDate = $this->getWhenDate($when); if (!$user) { $user = Users_Record_Model::getCurrentUserModel(); } $timeZone = new DateTimeZone($user->get('time_zone')); $date = new DateTime($whenDate); $date->setTimezone($timeZone); return $date->format('Y-m-d H:i:s'); } /** * @param Google_Service_Calendar_EventDateTime $when * @param Users_Record_Model $user * @return string * @throws Exception */ public function getUserDate($when, $user = null) { $whenDate = $this->getWhenDate($when); if (!$user) { $user = Users_Record_Model::getCurrentUserModel(); } $timeZone = new DateTimeZone($user->get('time_zone')); $date = new DateTime($whenDate); $date->setTimezone($timeZone); return $date->format('Y-m-d'); } public function getUserDateStart($user = null) { $when = $this->getDataEntity()->getStart(); return $this->getUserDate($when, $user); } public function getUserDateEnd($user = null) { $when = $this->getDataEntity()->getEnd(); $date = $this->getUserDate($when, $user); return date('Y-m-d', strtotime('-1 day', strtotime($date))); } public function getUserDatetimeStart($user = null) { $when = $this->getDataEntity()->getStart(); return $this->getUserDatetime($when, $user); } public function getUserDatetimeEnd($user = null) { $when = $this->getDataEntity()->getEnd(); return $this->getUserDatetime($when, $user); } /** * return End date in UTC of Google Record * @return string end date * @throws Exception */ function getEndDate($user = false) { if (isset($this->googleEndDate)) { return $this->googleEndDate; } if (!$user) { $user = Users_Record_Model::getCurrentUserModel(); } $when = $this->getDataEntity()->getEnd(); $gEnd = $this->getWhenDate($when); $timeZone = new DateTimeZone('UTC'); $end = new DateTime($gEnd); $end->setTimezone($timeZone); $endDate = $end->format('Y-m-d'); if ($end->format('H:i:s') == '00:00:00' && empty($when->getDateTime())) { $userTimezone = $user->get('time_zone'); $endUTCObj = DateTimeField::convertTimeZone($endDate, $userTimezone, DateTimeField::getDBTimeZone()); $endDate = $endUTCObj->format('Y-m-d'); } $this->googleEndDate = $endDate; return $endDate; } /** * return tilte of Google Record * @return title */ function getTitle() { $title = $this->data['entity']->getSummary(); return empty($title) ? null : $title; } /** * function to get Visibility of google calendar event * @return visibility of google event (Private or Public) * @return if google event visibility is default */ public function getVisibility($user) { $visibility = $this->data['entity']->getVisibility(); if (strpos($visibility, 'private') !== false) { return 'Private'; } elseif (strpos($visibility, 'public') !== false) { return 'Public'; } else { $sharedType = $user->get('calendarsharedtype'); if ($sharedType == 'selectedusers' || $sharedType == 'public') { return 'Public'; } return 'Private'; } } /** * return discription of Google Record * @return Discription */ function getDescription() { return $this->data['entity']->getDescription(); } /** * return location of Google Record * @return location */ function getWhere() { $where = $this->data['entity']->getLocation(); return $where; } /** * @return mixed */ public function getAssignedUserId() { return $this->assigned_user_id; } /** * @param mixed $assigned_user_id */ public function setAssignedUserId($assigned_user_id) { $this->assigned_user_id = $assigned_user_id; } /** * @return mixed */ public function getActivityType() { return $this->activityType; } /** * @param mixed $activityType */ public function setActivityType($activityType) { $this->activityType = $activityType; } /** * return array Attendees of Google Record */ public function getAttendees() { $attendeeDetails = array(); $attendees = $this->data['entity']->getAttendees(); if (is_array($attendees)) { foreach ($attendees as $attendee) { $attendeeDetails[] = $attendee->getEmail(); } } return $attendeeDetails; } }