/**
  * Returns an ordered listing of events according to the provided events
  * date range and to the currently selected user calendar.
  *
  * @param string $calendarId Current calendar to be used
  * @param StdClass $currDateRange Formatted date range with month and year values
  *                                to use as the event date range
  * @return StdClass Event listing content (->listing) and a boolean (->hasEvents)
  *                  indicating whether or not there are calendar events
  */
 private function getEventListing($calendarId, $currDateRange)
 {
     // Setting properly the correct timezone based on login user timezone
     $timeZone = TineSessionRepository::getTineSession()->getAttribute('Tinebase.timeZone');
     $lrp = new LiteRequestProcessor();
     $preparedEventDateRange = EventUtils::prepareEventsDateRange($currDateRange);
     $message = $lrp->executeRequest('SearchEvents', (object) array('from' => $preparedEventDateRange->from, 'until' => $preparedEventDateRange->until, 'timeZone' => $timeZone, 'calendarId' => $calendarId));
     // Sorts the event list comparing each event start time (->from)
     usort($message->events, function ($e1, $e2) {
         return strcmp($e1->from, $e2->from);
     });
     return (object) array('hasEvents' => count($message->events) > 0, 'listing' => (object) $message->events);
 }
 /**
  * Format information, about the attendees of a calendar event, to be viewed. The current user
  * logged in, if he is one of the attendees, so he must be the first exhibited attendee. The
  * remaining attendees will be group by, in the following order, that have the confirmation
  * type: ACCEPTED, TENTATIVE, NEEDS-ACTION and DECLINED.
  *
  * @param array $attendees An array of attendees objects
  * @return array An array of formatted information about attendees in wich element contains
  *               the name (->name) of the attendee, it's current confirmation (->userConfirm),
  *               the icon css class of the current confirmation type (->userConfirmIcon) and
  *               the organization and region about attendee's role
  */
 private function formatAttendeesInformation($attendees)
 {
     // Email of current logged in user, because we'll search for it in attendees list
     $currUserEmail = TineSessionRepository::getTineSession()->getAttribute('Expressomail.email');
     // Array which indexes are confirmation types, each one containing an empty list of attendees
     $result = EventUtils::prepareListOfConfirmationTypesToGroupAttendees();
     $currUserAttendee = null;
     $userHasNotFounded = true;
     foreach ($attendees as $attendee) {
         // Formatting the description for the current attendee event confirmation type
         $attendee->confirmStatus = EventUtils::getConfirmationDescription($attendee->confirmation);
         // Verifying if the logged in user is also an attendee of the event.
         if ($userHasNotFounded && $attendee->email === $currUserEmail) {
             $currUserAttendee = $attendee;
             $userHasNotFounded = false;
         } else {
             $result[$attendee->confirmation][] = $attendee;
         }
     }
     // Checking whether the logged in user is a attendee of the current event
     if (!$userHasNotFounded && !is_null($currUserAttendee)) {
         array_unshift($result, array($currUserAttendee));
         // First one to be displayed
     }
     return EventUtils::sortAttendeesByName($result);
 }