public function testDeletesAttributeById()
 {
     $attributeId = 1091;
     $this->page->_attributeId = $attributeId;
     $this->attributeRepository->expects($this->once())->method('DeleteById')->with($this->equalTo($attributeId));
     $this->presenter->DeleteAttribute();
 }
 private function PopulateTemplate()
 {
     $this->Set('UserName', $this->reservationOwner->FullName());
     $currentInstance = $this->reservationSeries->CurrentInstance();
     $this->Set('StartDate', $currentInstance->StartDate()->ToTimezone($this->timezone));
     $this->Set('EndDate', $currentInstance->EndDate()->ToTimezone($this->timezone));
     $this->Set('ResourceName', $this->resource->GetName());
     $this->Set('Title', $this->reservationSeries->Title());
     $this->Set('Description', $this->reservationSeries->Description());
     $repeatDates = array();
     foreach ($this->reservationSeries->Instances() as $repeated) {
         $repeatDates[] = $repeated->StartDate()->ToTimezone($this->timezone);
     }
     $this->Set('RequiresApproval', $this->reservationSeries->RequiresApproval());
     $this->Set('RepeatDates', $repeatDates);
     $this->Set('ReservationUrl', Pages::RESERVATION . "?" . QueryStringKeys::REFERENCE_NUMBER . '=' . $currentInstance->ReferenceNumber());
     $resourceNames = array();
     foreach ($this->reservationSeries->AllResources() as $resource) {
         $resourceNames[] = $resource->GetName();
     }
     $this->Set('ResourceNames', $resourceNames);
     $this->Set('Accessories', $this->reservationSeries->Accessories());
     $attributes = $this->attributeRepository->GetByCategory(CustomAttributeCategory::RESERVATION);
     $attributeValues = array();
     foreach ($attributes as $attribute) {
         $attributeValues[] = new Attribute($attribute, $this->reservationSeries->GetAttributeValue($attribute->Id()));
     }
     $this->Set('Attributes', $attributeValues);
     $bookedBy = $this->reservationSeries->BookedBy();
     if ($bookedBy != null && $bookedBy->UserId != $this->reservationOwner->Id()) {
         $this->Set('CreatedBy', new FullName($bookedBy->FirstName, $bookedBy->LastName));
     }
 }
 protected function PopulateTemplate()
 {
     $currentInstance = $this->reservationSeries->CurrentInstance();
     $this->Set('UserName', $this->reservationOwner->FullName());
     $this->Set('StartDate', $currentInstance->StartDate()->ToTimezone($this->timezone));
     $this->Set('EndDate', $currentInstance->EndDate()->ToTimezone($this->timezone));
     $this->Set('ResourceName', $this->reservationSeries->Resource()->GetName());
     $this->Set('Title', $this->reservationSeries->Title());
     $this->Set('Description', $this->reservationSeries->Description());
     $repeatDates = array();
     if ($this->reservationSeries->IsRecurring()) {
         foreach ($this->reservationSeries->Instances() as $repeated) {
             $repeatDates[] = $repeated->StartDate()->ToTimezone($this->timezone);
         }
     }
     $this->Set('RepeatDates', $repeatDates);
     $this->Set('RequiresApproval', $this->reservationSeries->RequiresApproval());
     $this->Set('ReservationUrl', sprintf("%s?%s=%s", Pages::RESERVATION, QueryStringKeys::REFERENCE_NUMBER, $currentInstance->ReferenceNumber()));
     $this->Set('ICalUrl', sprintf("export/%s?%s=%s", Pages::CALENDAR_EXPORT, QueryStringKeys::REFERENCE_NUMBER, $currentInstance->ReferenceNumber()));
     $resourceNames = array();
     foreach ($this->reservationSeries->AllResources() as $resource) {
         $resourceNames[] = $resource->GetName();
     }
     $this->Set('ResourceNames', $resourceNames);
     $this->Set('Accessories', $this->reservationSeries->Accessories());
     $attributes = $this->attributeRepository->GetByCategory(CustomAttributeCategory::RESERVATION);
     $attributeValues = array();
     foreach ($attributes as $attribute) {
         $attributeValues[] = new Attribute($attribute, $this->reservationSeries->GetAttributeValue($attribute->Id()));
     }
     $this->Set('Attributes', $attributeValues);
 }
 public function HandleDataRequest($dataRequest)
 {
     $categoryId = $this->page->GetRequestedCategory();
     if (empty($categoryId)) {
         $categoryId = CustomAttributeCategory::RESERVATION;
     }
     $this->page->BindAttributes($this->attributeRepository->GetByCategory($categoryId));
 }
 /**
  * @param int $attributeId
  * @param WebServiceUserSession $session
  * @return AttributeControllerResult
  */
 public function Delete($attributeId, $session)
 {
     $errors = empty($attributeId) ? array('attributeId is required') : array();
     if (!empty($errors)) {
         return new AttributeControllerResult(null, $errors);
     }
     $this->repository->DeleteById($attributeId);
     return new AttributeControllerResult($attributeId);
 }
Example #6
0
 /**
  * @param array $rows
  * @param IAttributeRepository $attributeRepository
  */
 public function __construct($rows, IAttributeRepository $attributeRepository)
 {
     $this->resultCount = count($rows);
     $this->cols = new ReportColumns();
     if (count($rows) > 0) {
         foreach ($rows[0] as $columnName => $value) {
             if ($columnName == ColumnNames::ATTRIBUTE_LIST) {
                 $attributes = $attributeRepository->GetByCategory(CustomAttributeCategory::RESERVATION);
                 foreach ($attributes as $attribute) {
                     $this->cols->AddAttribute($attribute->Id(), $attribute->Label());
                 }
             } else {
                 $this->cols->Add($columnName);
             }
         }
     }
     $this->data = new CustomReportData($rows);
 }
Example #7
0
 /**
  * @param ReservationItemView $reservation
  * @param string $format
  * @return string
  */
 public function Format(ReservationItemView $reservation, $format = null)
 {
     $shouldHideUser = Configuration::Instance()->GetSectionKey(ConfigSection::PRIVACY, ConfigKeys::PRIVACY_HIDE_USER_DETAILS, new BooleanConverter());
     $shouldHideDetails = ReservationDetailsFilter::HideReservationDetails($reservation->StartDate, $reservation->EndDate);
     if (($shouldHideUser || $shouldHideDetails) && (is_null($this->user) || $this->user->UserId != $reservation->UserId && !$this->user->IsAdminForGroup($reservation->OwnerGroupIds()))) {
         return '';
     }
     if (empty($format)) {
         $format = Configuration::Instance()->GetSectionKey(ConfigSection::SCHEDULE, ConfigKeys::SCHEDULE_RESERVATION_LABEL);
     }
     if ($format == 'none' || empty($format)) {
         return '';
     }
     $name = $this->GetFullName($reservation);
     $timezone = 'UTC';
     $dateFormat = Resources::GetInstance()->GetDateFormat('res_popup');
     if (!is_null($this->user)) {
         $timezone = $this->user->Timezone;
     }
     $label = $format;
     $label = str_replace('{name}', $name, $label);
     $label = str_replace('{title}', $reservation->Title, $label);
     $label = str_replace('{description}', $reservation->Description, $label);
     $label = str_replace('{email}', $reservation->OwnerEmailAddress, $label);
     $label = str_replace('{organization}', $reservation->OwnerOrganization, $label);
     $label = str_replace('{phone}', $reservation->OwnerPhone, $label);
     $label = str_replace('{position}', $reservation->OwnerPosition, $label);
     $label = str_replace('{startdate}', $reservation->StartDate->ToTimezone($timezone)->Format($dateFormat), $label);
     $label = str_replace('{enddate}', $reservation->EndDate->ToTimezone($timezone)->Format($dateFormat), $label);
     $label = str_replace('{resourcename}', $reservation->ResourceName, $label);
     $label = str_replace('{participants}', trim(implode(', ', $reservation->ParticipantNames)), $label);
     $label = str_replace('{invitees}', trim(implode(', ', $reservation->InviteeNames)), $label);
     $matches = array();
     preg_match_all('/\\{(att\\d+?)\\}/', $format, $matches);
     $matches = $matches[0];
     if (count($matches) > 0) {
         for ($m = 0; $m < count($matches); $m++) {
             $id = filter_var($matches[$m], FILTER_SANITIZE_NUMBER_INT);
             $value = $reservation->GetAttributeValue($id);
             $label = str_replace($matches[$m], $value, $label);
         }
     }
     if (BookedStringHelper::Contains($label, '{reservationAttributes}')) {
         $attributesLabel = new StringBuilder();
         $attributes = $this->attributeRepository->GetByCategory(CustomAttributeCategory::RESERVATION);
         foreach ($attributes as $attribute) {
             $attributesLabel->Append($attribute->Label() . ': ' . $reservation->GetAttributeValue($attribute->Id()) . ', ');
         }
         $label = str_replace('{reservationAttributes}', rtrim($attributesLabel->ToString(), ', '), $label);
     }
     return $label;
 }
 public function testBindsCustomAttributesWithValues()
 {
     $val1 = 'v1';
     $val2 = 'v2';
     $reservationView = new ReservationView();
     $reservationView->AddAttribute(new AttributeValue(10, $val1));
     $reservationView->AddAttribute(new AttributeValue(20, $val2));
     $binder = new ReservationCustomAttributeValueBinder($this->attributeRepository, $reservationView);
     $attributes = array(new CustomAttribute(10, '1', CustomAttributeTypes::SINGLE_LINE_TEXTBOX, CustomAttributeCategory::RESERVATION, '', false, '', 1), new CustomAttribute(20, '2', CustomAttributeTypes::SINGLE_LINE_TEXTBOX, CustomAttributeCategory::RESERVATION, '', false, '', 2));
     $this->attributeRepository->expects($this->once())->method('GetByCategory')->with($this->equalTo(CustomAttributeCategory::RESERVATION))->will($this->returnValue($attributes));
     $this->initializer->expects($this->at(0))->method('AddAttribute')->with($this->equalTo($attributes[0]), $this->equalTo($val1));
     $this->initializer->expects($this->at(1))->method('AddAttribute')->with($this->equalTo($attributes[1]), $this->equalTo($val2));
     $binder->Bind($this->initializer);
 }
Example #9
0
 public function GetById($attributeId)
 {
     return $this->attributeRepository->LoadById($attributeId);
 }
 public function Bind(IReservationComponentInitializer $initializer)
 {
     $attributes = $this->repository->GetByCategory(CustomAttributeCategory::RESERVATION);
     foreach ($attributes as $attribute) {
         $initializer->AddAttribute($attribute, $this->reservationView->GetAttributeValue($attribute->Id()));
     }
 }
Example #11
0
 public function PageLoad()
 {
     $hideUserInfo = Configuration::Instance()->GetSectionKey(ConfigSection::PRIVACY, ConfigKeys::PRIVACY_HIDE_USER_DETAILS, new BooleanConverter());
     $hideReservationDetails = Configuration::Instance()->GetSectionKey(ConfigSection::PRIVACY, ConfigKeys::PRIVACY_HIDE_RESERVATION_DETAILS, new BooleanConverter());
     $tz = ServiceLocator::GetServer()->GetUserSession()->Timezone;
     $reservation = $this->_reservationRepository->GetReservationForEditing($this->_page->GetReservationId());
     if (!$reservation->IsDisplayable()) {
         return;
     }
     if ($hideReservationDetails || $hideUserInfo) {
         $canViewDetails = $this->_reservationAuthorization->CanViewDetails($reservation, ServiceLocator::GetServer()->GetUserSession());
         $hideReservationDetails = !$canViewDetails && $hideReservationDetails;
         $hideUserInfo = !$canViewDetails && $hideUserInfo;
     }
     $this->_page->SetHideDetails($hideReservationDetails);
     $this->_page->SetHideUser($hideUserInfo);
     $startDate = $reservation->StartDate->ToTimezone($tz);
     $endDate = $reservation->EndDate->ToTimezone($tz);
     $this->_page->SetName($reservation->OwnerFirstName, $reservation->OwnerLastName);
     $this->_page->SetResources($reservation->Resources);
     $this->_page->SetParticipants($reservation->Participants);
     $this->_page->SetSummary($reservation->Description);
     $this->_page->SetTitle($reservation->Title);
     $this->_page->SetAccessories($reservation->Accessories);
     $this->_page->SetDates($startDate, $endDate);
     $attributes = $this->_attributeRepository->GetByCategory(CustomAttributeCategory::RESERVATION);
     $attributeValues = array();
     foreach ($attributes as $attribute) {
         $attributeValues[] = new Attribute($attribute, $reservation->GetAttributeValue($attribute->Id()));
     }
     $this->_page->BindAttributes($attributeValues);
 }
 public function testPassThroughForAttribute()
 {
     $attributeId = 123;
     $this->attributeRepository->expects($this->once())->method('LoadById')->with($this->equalTo($attributeId))->will($this->returnValue(new TestCustomAttribute(1, 'l')));
     $this->attributeService->GetById($attributeId);
 }