/**
  * @param ReservationItemView $res
  * @param UserSession $currentUser
  * @param IPrivacyFilter $privacyFilter
  * @param string|null $summaryFormat
  */
 public function __construct($res, UserSession $currentUser, IPrivacyFilter $privacyFilter, $summaryFormat = null)
 {
     if ($summaryFormat == null) {
         $summaryFormat = Configuration::Instance()->GetSectionKey(ConfigSection::RESERVATION_LABELS, ConfigKeys::RESERVATION_LABELS_ICS_SUMMARY);
     }
     $factory = new SlotLabelFactory($currentUser);
     $this->ReservationItemView = $res;
     $canViewUser = $privacyFilter->CanViewUser($currentUser, $res, $res->UserId);
     $canViewDetails = $privacyFilter->CanViewDetails($currentUser, $res, $res->UserId);
     $privateNotice = 'Private';
     $this->DateCreated = $res->CreatedDate;
     $this->DateEnd = $res->EndDate;
     $this->DateStart = $res->StartDate;
     $this->Description = $canViewDetails ? $res->Description : $privateNotice;
     $fullName = new FullName($res->OwnerFirstName, $res->OwnerLastName);
     $this->Organizer = $canViewUser ? $fullName->__toString() : $privateNotice;
     $this->OrganizerEmail = $canViewUser ? $res->OwnerEmailAddress : $privateNotice;
     $this->RecurRule = $this->CreateRecurRule($res);
     $this->ReferenceNumber = $res->ReferenceNumber;
     $this->Summary = $canViewDetails ? $factory->Format($res, $summaryFormat) : $privateNotice;
     $this->ReservationUrl = sprintf("%s/%s?%s=%s", Configuration::Instance()->GetScriptUrl(), Pages::RESERVATION, QueryStringKeys::REFERENCE_NUMBER, $res->ReferenceNumber);
     $this->Location = $res->ResourceName;
     $this->StartReminder = $res->StartReminder;
     $this->EndReminder = $res->EndReminder;
     if ($res->UserId == $currentUser->UserId) {
         $this->OrganizerEmail = str_replace('@', '-noreply@', $res->OwnerEmailAddress);
     }
 }
 public function testUsesFormatIfAvailable()
 {
     $this->reservation->Title = 'mytitle';
     $this->reservation->Description = 'mydescription';
     $this->reservation->OwnerEmailAddress = 'myemail';
     $this->reservation->OwnerOrganization = 'myorg';
     $this->reservation->OwnerPhone = 'myphone';
     $this->reservation->OwnerPosition = 'myposition';
     $this->reservation->ParticipantNames = array('p1', 'p2');
     $this->reservation->InviteeNames = array('i1', 'i2');
     $this->reservation->StartDate = Date::Now();
     $this->reservation->EndDate = Date::Now();
     $this->SetConfig('{name} + {title} - {description} {email} {phone} {organization} {position} {participants} {invitees}');
     $value = SlotLabelFactory::Create($this->reservation);
     $this->assertEquals('first last + mytitle - mydescription myemail myphone myorg myposition p1, p2 i1, i2', $value);
 }
Example #3
0
 /**
  * @static
  * @param ReservationItemView $reservation
  * @return string
  */
 public static function Create(ReservationItemView $reservation)
 {
     $f = new SlotLabelFactory();
     return $f->Format($reservation);
 }
Example #4
0
 /**
  * @static
  * @param array|ReservationItemView[] $reservations
  * @param array|ResourceDto[] $resources
  * @param UserSession $userSession
  * @param bool $groupSeriesByResource
  * @return array|CalendarReservation[]
  */
 public static function FromScheduleReservationList($reservations, $resources, UserSession $userSession, $groupSeriesByResource = false)
 {
     $knownSeries = array();
     $factory = new SlotLabelFactory($userSession);
     $resourceMap = array();
     /** @var $resource ResourceDto */
     foreach ($resources as $resource) {
         $resourceMap[$resource->GetResourceId()] = $resource->GetName();
     }
     $res = array();
     foreach ($reservations as $reservation) {
         if (!array_key_exists($reservation->ResourceId, $resourceMap)) {
             continue;
         }
         if ($groupSeriesByResource) {
             if (array_key_exists($reservation->SeriesId, $knownSeries)) {
                 continue;
             }
             $knownSeries[$reservation->SeriesId] = true;
         }
         $timezone = $userSession->Timezone;
         $start = $reservation->StartDate->ToTimezone($timezone);
         $end = $reservation->EndDate->ToTimezone($timezone);
         $referenceNumber = $reservation->ReferenceNumber;
         $cr = new CalendarReservation($start, $end, $resourceMap[$reservation->ResourceId], $referenceNumber);
         $cr->Title = $reservation->Title;
         $cr->OwnerName = new FullName($reservation->FirstName, $reservation->LastName);
         $cr->OwnerFirst = $reservation->FirstName;
         $cr->OwnerLast = $reservation->LastName;
         $cr->DisplayTitle = $factory->Format($reservation, Configuration::Instance()->GetSectionKey(ConfigSection::RESERVATION_LABELS, ConfigKeys::RESERVATION_LABELS_RESOURCE_CALENDAR));
         $color = $reservation->UserPreferences->Get(UserPreferences::RESERVATION_COLOR);
         if (!empty($color)) {
             $cr->Color = "#{$color}";
             $cr->TextColor = new ContrastingColor($color);
         }
         $cr->Class = self::GetClass($reservation);
         $res[] = $cr;
     }
     return $res;
 }
Example #5
0
 /**
  * @param SlotLabelFactory|null $factory
  * @return string
  */
 public function Label($factory = null)
 {
     if (empty($factory)) {
         return SlotLabelFactory::Create($this->_reservation);
     }
     return $factory->Format($this->_reservation);
 }
Example #6
0
 public function FormatReservationDescription(iCalendarReservationView $reservation, UserSession $user)
 {
     $factory = new SlotLabelFactory($user);
     return $factory->Format($reservation->ReservationItemView, Configuration::Instance()->GetSectionKey(ConfigSection::RESERVATION_LABELS, ConfigKeys::RESERVATION_LABELS_RSS_DESCRIPTION));
 }