Exemple #1
0
 /**
  * Creates the string for the user's events and todos between the given start
  * and end times
  *
  * @param UserBean $user_bean the current UserBean
  * @param DateTime $start_date_time the start date to search from
  * @param DateTime $end_date_time the end date to search to
  * @param string $dtstamp the current timestamp
  * @return string the entries for events and todos
  */
 protected function createSugarIcal(&$user_bean, &$start_date_time, &$end_date_time, $dtstamp)
 {
     $ical_array = array();
     global $DO_USER_TIME_OFFSET, $sugar_config, $current_user, $timedate;
     $hide_calls = false;
     if (!empty($_REQUEST['hide_calls']) && $_REQUEST['hide_calls'] == "true") {
         $hide_calls = true;
     }
     $taskAsVTODO = true;
     if (!empty($_REQUEST['show_tasks_as_events']) && ($_REQUEST['show_tasks_as_events'] == "1" || $_REQUEST['show_tasks_as_events'] == "true")) {
         $taskAsVTODO = false;
     }
     $acts_arr = CalendarActivity::get_activities($user_bean->id, !$taskAsVTODO, $start_date_time, $end_date_time, 'month', !$hide_calls);
     // loop thru each activity, get start/end time in UTC, and return iCal strings
     foreach ($acts_arr as $act) {
         $event = $act->sugar_bean;
         if (!$hide_calls || $hide_calls && $event->object_name != "Call") {
             $ical_array[] = array("BEGIN", "VEVENT");
             $ical_array[] = array("SUMMARY", $event->name);
             $ical_array[] = array("DTSTART;TZID=" . $user_bean->getPreference('timezone'), str_replace("Z", "", $timedate->tzUser($act->start_time, $current_user)->format(self::UTC_FORMAT)));
             $ical_array[] = array("DTEND;TZID=" . $user_bean->getPreference('timezone'), str_replace("Z", "", $timedate->tzUser($act->end_time, $current_user)->format(self::UTC_FORMAT)));
             $ical_array[] = array("DTSTAMP", $dtstamp);
             $ical_array[] = array("DESCRIPTION", $event->description);
             $ical_array[] = array("URL;VALUE=URI", $sugar_config['site_url'] . "/index.php?module=" . $event->module_dir . "&action=DetailView&record=" . $event->id);
             $ical_array[] = array("UID", $event->id);
             if ($event->object_name == "Meeting") {
                 $ical_array[] = array("LOCATION", $event->location);
                 $eventUsers = $event->get_meeting_users();
                 $query = "SELECT contact_id as id from meetings_contacts where meeting_id='{$event->id}' AND deleted=0";
                 $eventContacts = $event->build_related_list($query, new Contact());
                 $eventAttendees = array_merge($eventUsers, $eventContacts);
                 if (is_array($eventAttendees)) {
                     foreach ($eventAttendees as $attendee) {
                         if ($attendee->id != $user_bean->id) {
                             // Define the participant status
                             $participant_status = '';
                             if (!empty($attendee->accept_status)) {
                                 switch ($attendee->accept_status) {
                                     case 'accept':
                                         $participant_status = ';PARTSTAT=ACCEPTED';
                                         break;
                                     case 'decline':
                                         $participant_status = ';PARTSTAT=DECLINED';
                                         break;
                                     case 'tentative':
                                         $participant_status = ';PARTSTAT=TENTATIVE';
                                         break;
                                 }
                             }
                             $ical_array[] = array('ATTENDEE' . $participant_status . ';CN="' . $attendee->get_summary_text() . '"', 'mailto:' . (!empty($attendee->email1) ? $attendee->email1 : '*****@*****.**'));
                         }
                     }
                 }
             }
             if ($event->object_name == "Call") {
                 $eventUsers = $event->get_call_users();
                 $eventContacts = $event->get_contacts();
                 $eventAttendees = array_merge($eventUsers, $eventContacts);
                 if (is_array($eventAttendees)) {
                     foreach ($eventAttendees as $attendee) {
                         if ($attendee->id != $user_bean->id) {
                             // Define the participant status
                             $participant_status = '';
                             if (!empty($attendee->accept_status)) {
                                 switch ($attendee->accept_status) {
                                     case 'accept':
                                         $participant_status = ';PARTSTAT=ACCEPTED';
                                         break;
                                     case 'decline':
                                         $participant_status = ';PARTSTAT=DECLINED';
                                         break;
                                     case 'tentative':
                                         $participant_status = ';PARTSTAT=TENTATIVE';
                                         break;
                                 }
                             }
                             $ical_array[] = array('ATTENDEE' . $participant_status . ';CN="' . $attendee->get_summary_text() . '"', 'mailto:' . (!empty($attendee->email1) ? $attendee->email1 : '*****@*****.**'));
                         }
                     }
                 }
             }
             if (isset($event->reminder_time) && $event->reminder_time > 0 && $event->status != "Held") {
                 $ical_array[] = array("BEGIN", "VALARM");
                 $ical_array[] = array("TRIGGER", "-PT");
                 $ical_array[] = array("ACTION", "DISPLAY");
                 $ical_array[] = array("DESCRIPTION", $event->name);
                 $ical_array[] = array("END", "VALARM");
             }
             $ical_array[] = array("END", "VEVENT");
         }
     }
     $str = vCal::create_ical_string_from_array($ical_array, true);
     require_once 'include/TimeDate.php';
     $timedate = new TimeDate();
     $today = gmdate("Y-m-d");
     $today = $timedate->handle_offset($today, $timedate->dbDayFormat, false);
     require_once 'modules/ProjectTask/ProjectTask.php';
     $where = "project_task.assigned_user_id='{$user_bean->id}' " . "AND (project_task.status IS NULL OR (project_task.status!='Deferred')) " . "AND (project_task.date_start IS NULL OR " . CalendarActivity::get_occurs_within_where_clause('project_task', '', $start_date_time, $end_date_time, 'date_start', 'month') . ")";
     $seedProjectTask = new ProjectTask();
     $projectTaskList = $seedProjectTask->get_full_list("", $where);
     if (is_array($projectTaskList)) {
         foreach ($projectTaskList as $projectTask) {
             $str .= $this->createSugarIcalTodo($user_bean, $projectTask, "ProjectTask", $dtstamp);
         }
     }
     if ($taskAsVTODO) {
         require_once 'modules/Tasks/Task.php';
         $where = "tasks.assigned_user_id='{$user_bean->id}' " . "AND (tasks.status IS NULL OR (tasks.status!='Deferred')) " . "AND (tasks.date_start IS NULL OR " . CalendarActivity::get_occurs_within_where_clause('tasks', '', $start_date_time, $end_date_time, 'date_start', 'month') . ")";
         $seedTask = new Task();
         $taskList = $seedTask->get_full_list("", $where);
         if (is_array($taskList)) {
             foreach ($taskList as $task) {
                 $str .= $this->createSugarIcalTodo($user_bean, $task, "Tasks", $dtstamp);
             }
         }
     }
     return $str;
 }
Exemple #2
0
 /**
  * Creates the string for the user's events and todos between the given start
  * and end times
  *
  * @param UserBean $user_bean the current UserBean
  * @param DateTime $start_date_time the start date to search from
  * @param DateTime $end_date_time the end date to search to
  * @param string $dtstamp the current timestamp
  * @return string the entries for events and todos
  */
 protected function createSugarIcal(&$user_bean, &$start_date_time, &$end_date_time, $dtstamp)
 {
     $str = '';
     global $DO_USER_TIME_OFFSET, $sugar_config, $current_user, $timedate;
     $acts_arr = CalendarActivity::get_activities($user_bean->id, false, $start_date_time, $end_date_time, 'month');
     $hide_calls = false;
     if (!empty($_REQUEST['hide_calls']) && $_REQUEST['hide_calls'] == "true") {
         $hide_calls = true;
     }
     // loop thru each activity, get start/end time in UTC, and return iCal strings
     foreach ($acts_arr as $act) {
         $event = $act->sugar_bean;
         if (!$hide_calls || $hide_calls && $event->object_name != "Call") {
             $str .= "BEGIN:VEVENT\n";
             $str .= "SUMMARY:" . $event->name . "\n";
             $str .= "DTSTART;TZID=" . $user_bean->getPreference('timezone') . ":" . str_replace("Z", "", $timedate->tzUser($act->start_time, $current_user)->format(self::UTC_FORMAT)) . "\n";
             $str .= "DTEND;TZID=" . $user_bean->getPreference('timezone') . ":" . str_replace("Z", "", $timedate->tzUser($act->end_time, $current_user)->format(self::UTC_FORMAT)) . "\n";
             $str .= "DTSTAMP:" . $dtstamp . "\n";
             $str .= "DESCRIPTION:" . $this->escapeNls($event->description) . "\n";
             $str .= "URL;VALUE=URI:" . $sugar_config['site_url'] . "/index.php?module=" . $event->module_dir . "&action=DetailView&record=" . $event->id . "\n";
             $str .= "UID:" . $event->id . "\n";
             if ($event->object_name == "Meeting") {
                 $str .= "LOCATION:" . $event->location . "\n";
                 $eventUsers = $event->get_meeting_users();
                 $query = "SELECT contact_id as id from meetings_contacts where meeting_id='{$event->id}' AND deleted=0";
                 $eventContacts = $event->build_related_list($query, new Contact());
                 $eventAttendees = array_merge($eventUsers, $eventContacts);
                 if (is_array($eventAttendees)) {
                     foreach ($eventAttendees as $attendee) {
                         if ($attendee->id != $user_bean->id) {
                             $str .= 'ATTENDEE;CN="' . $attendee->get_summary_text() . '":mailto:' . $attendee->email1 . "\n";
                         }
                     }
                 }
             }
             if ($event->object_name == "Call") {
                 $eventUsers = $event->get_call_users();
                 $eventContacts = $event->get_contacts();
                 $eventAttendees = array_merge($eventUsers, $eventContacts);
                 if (is_array($eventAttendees)) {
                     foreach ($eventAttendees as $attendee) {
                         if ($attendee->id != $user_bean->id) {
                             $str .= 'ATTENDEE;CN="' . $attendee->get_summary_text() . '":mailto:' . $attendee->email1 . "\n";
                         }
                     }
                 }
             }
             if ($event->reminder_time > 0 && $event->status != "Held") {
                 $str .= "BEGIN:VALARM\n";
                 $str .= "TRIGGER:-PT" . $event->reminder_time / 60 . "M\n";
                 $str .= "ACTION:DISPLAY\n";
                 $str .= "DESCRIPTION:" . $event->name . "\n";
                 $str .= "END:VALARM\n";
             }
             $str .= "END:VEVENT\n";
         }
     }
     require_once 'include/TimeDate.php';
     $timedate = new TimeDate();
     $today = gmdate("Y-m-d");
     $today = $timedate->handle_offset($today, $timedate->dbDayFormat, false);
     require_once 'modules/ProjectTask/ProjectTask.php';
     $where = "project_task.assigned_user_id='{$user_bean->id}' " . "AND (project_task.status IS NULL OR (project_task.status!='Deferred')) " . "AND (project_task.date_start IS NULL OR project_task.date_start <= '{$today}')";
     $seedProjectTask = new ProjectTask();
     $projectTaskList = $seedProjectTask->get_full_list("", $where);
     if (is_array($projectTaskList)) {
         foreach ($projectTaskList as $projectTask) {
             $str .= $this->createSugarIcalTodo($user_bean, $projectTask, "ProjectTask", $dtstamp);
         }
     }
     require_once 'modules/Tasks/Task.php';
     $where = "tasks.assigned_user_id='{$user_bean->id}' " . "AND (tasks.status IS NULL OR (tasks.status!='Deferred')) " . "AND (tasks.date_start IS NULL OR tasks.date_start <= '{$today}')";
     $seedTask = new Task();
     $taskList = $seedTask->get_full_list("", $where);
     if (is_array($taskList)) {
         foreach ($taskList as $task) {
             $str .= $this->createSugarIcalTodo($user_bean, $task, "Tasks", $dtstamp);
         }
     }
     return $str;
 }