Exemple #1
0
 public function __construct(IRestServer $server, User $user, IEntityAttributeList $attributes)
 {
     $userId = $user->Id();
     $this->id = $userId;
     $this->emailAddress = $user->EmailAddress();
     $this->firstName = $user->FirstName();
     $this->lastName = $user->LastName();
     $this->language = $user->Language();
     $this->lastLogin = Date::FromDatabase($user->LastLogin())->ToIso();
     $this->organization = $user->GetAttribute(UserAttribute::Organization);
     $this->phoneNumber = $user->GetAttribute(UserAttribute::Phone);
     $this->position = $user->GetAttribute(UserAttribute::Position);
     $this->statusId = $user->StatusId();
     $this->timezone = $user->Timezone();
     $this->username = $user->Username();
     $attributeValues = $attributes->GetAttributes($userId);
     if (!empty($attributeValues)) {
         foreach ($attributeValues as $av) {
             $this->customAttributes[] = new CustomAttributeResponse($server, $av->Id(), $av->Label(), $av->Value());
         }
     }
     foreach ($user->AllowedResourceIds() as $allowedResourceId) {
         $this->permissions[] = new ResourceItemResponse($server, $allowedResourceId, '');
     }
     foreach ($user->Groups() as $group) {
         $this->groups[] = new GroupItemResponse($server, $group->GroupId, $group->GroupName);
     }
     if ($user->GetIsCalendarSubscriptionAllowed()) {
         $url = new CalendarSubscriptionUrl($user->GetPublicId(), null, null);
         $this->icsUrl = $url->__toString();
     }
 }
 /**
  * @param int $blackoutId
  * @return BlackoutSeries
  */
 public function LoadByBlackoutId($blackoutId)
 {
     $db = ServiceLocator::GetDatabase();
     $result = $db->Query(new GetBlackoutSeriesByBlackoutIdCommand($blackoutId));
     if ($row = $result->GetRow()) {
         $series = BlackoutSeries::FromRow($row);
         $result = $db->Query(new GetBlackoutInstancesCommand($series->Id()));
         while ($row = $result->GetRow()) {
             $instance = new Blackout(new DateRange(Date::FromDatabase($row[ColumnNames::BLACKOUT_START]), Date::FromDatabase($row[ColumnNames::BLACKOUT_END])));
             $instance->WithId($row[ColumnNames::BLACKOUT_INSTANCE_ID]);
             $series->AddBlackout($instance);
         }
         $result = $db->Query(new GetBlackoutResourcesCommand($series->Id()));
         while ($row = $result->GetRow()) {
             $series->AddResource(new BlackoutResource($row[ColumnNames::RESOURCE_ID], $row[ColumnNames::RESOURCE_NAME], $row[ColumnNames::SCHEDULE_ID], $row[ColumnNames::RESOURCE_ADMIN_GROUP_ID], $row[ColumnNames::SCHEDULE_ADMIN_GROUP_ID_ALIAS], $row[ColumnNames::RESOURCE_STATUS_ID]));
         }
         return $series;
     } else {
         return null;
     }
 }
 private function PopulateInstances(ExistingReservationSeries $series)
 {
     // get all series instances
     $getInstancesCommand = new GetReservationSeriesInstances($series->SeriesId());
     $reader = ServiceLocator::GetDatabase()->Query($getInstancesCommand);
     while ($row = $reader->GetRow()) {
         $start = Date::FromDatabase($row[ColumnNames::RESERVATION_START]);
         $end = Date::FromDatabase($row[ColumnNames::RESERVATION_END]);
         $reservation = new Reservation($series, new DateRange($start, $end), $row[ColumnNames::RESERVATION_INSTANCE_ID], $row[ColumnNames::REFERENCE_NUMBER]);
         $series->WithInstance($reservation);
     }
     $reader->Free();
 }
 /**
  * @static
  * @param $row
  * @return BlackoutItemView
  */
 public static function Populate($row)
 {
     return new BlackoutItemView($row[ColumnNames::BLACKOUT_INSTANCE_ID], Date::FromDatabase($row[ColumnNames::BLACKOUT_START]), Date::FromDatabase($row[ColumnNames::BLACKOUT_END]), $row[ColumnNames::RESOURCE_ID], $row[ColumnNames::USER_ID], $row[ColumnNames::SCHEDULE_ID], $row[ColumnNames::BLACKOUT_TITLE], $row[ColumnNames::BLACKOUT_DESCRIPTION], $row[ColumnNames::FIRST_NAME], $row[ColumnNames::LAST_NAME], $row[ColumnNames::RESOURCE_NAME], $row[ColumnNames::BLACKOUT_SERIES_ID], $row[ColumnNames::REPEAT_OPTIONS], $row[ColumnNames::REPEAT_TYPE]);
 }
Exemple #5
0
 /**
  * @param string[] $row
  * @return BlackoutSeries
  */
 public static function FromRow($row)
 {
     $series = new BlackoutSeries($row[ColumnNames::OWNER_USER_ID], $row[ColumnNames::BLACKOUT_TITLE]);
     $series->WithId($row[ColumnNames::BLACKOUT_SERIES_ID]);
     $series->SetCurrentBlackout(new DateRange(Date::FromDatabase($row[ColumnNames::BLACKOUT_START]), Date::FromDatabase($row[ColumnNames::BLACKOUT_END])));
     $series->WithCurrentBlackoutId($row[ColumnNames::BLACKOUT_INSTANCE_ID]);
     $configuration = RepeatConfiguration::Create($row[ColumnNames::REPEAT_TYPE], $row[ColumnNames::REPEAT_OPTIONS]);
     $factory = new RepeatOptionsFactory();
     $options = $factory->Create($row[ColumnNames::REPEAT_TYPE], $configuration->Interval, $configuration->TerminationDate, $configuration->Weekdays, $configuration->MonthlyType);
     $series->WithRepeatOptions($options);
     return $series;
 }
Exemple #6
0
 public static function Create($row)
 {
     $user = new UserItemView();
     $user->Id = $row[ColumnNames::USER_ID];
     $user->Username = $row[ColumnNames::USERNAME];
     $user->First = $row[ColumnNames::FIRST_NAME];
     $user->Last = $row[ColumnNames::LAST_NAME];
     $user->Email = $row[ColumnNames::EMAIL];
     $user->Phone = $row[ColumnNames::PHONE_NUMBER];
     $user->DateCreated = Date::FromDatabase($row[ColumnNames::USER_CREATED]);
     $user->LastLogin = Date::FromDatabase($row[ColumnNames::LAST_LOGIN]);
     $user->StatusId = $row[ColumnNames::USER_STATUS_ID];
     $user->Timezone = $row[ColumnNames::TIMEZONE_NAME];
     $user->Organization = $row[ColumnNames::ORGANIZATION];
     $user->Position = $row[ColumnNames::POSITION];
     $user->Language = $row[ColumnNames::LANGUAGE_CODE];
     if (isset($row[ColumnNames::ATTRIBUTE_LIST])) {
         $user->Attributes = CustomAttributes::Parse($row[ColumnNames::ATTRIBUTE_LIST]);
     } else {
         $user->Attributes = new CustomAttributes();
     }
     if (isset($row[ColumnNames::USER_PREFERENCES])) {
         $preferences = UserPreferences::Parse($row[ColumnNames::USER_PREFERENCES]);
         if (!empty($preferences)) {
             $user->ReservationColor = $preferences->Get(UserPreferences::RESERVATION_COLOR);
         }
         $user->Preferences = $preferences;
     } else {
         $user->Preferences = new UserPreferences();
     }
     return $user;
 }
Exemple #7
0
 /**
  * @param array $row
  * @return ReminderNotice
  */
 public static function FromRow($row)
 {
     $seriesId = $row[ColumnNames::SERIES_ID];
     $reservationId = $row[ColumnNames::RESERVATION_INSTANCE_ID];
     $referenceNumber = $row[ColumnNames::REFERENCE_NUMBER];
     $startDate = Date::FromDatabase($row[ColumnNames::RESERVATION_START]);
     $endDate = Date::FromDatabase($row[ColumnNames::RESERVATION_END]);
     $title = $row[ColumnNames::RESERVATION_TITLE];
     $description = $row[ColumnNames::RESERVATION_DESCRIPTION];
     $resourceName = $row[ColumnNames::RESOURCE_NAME_ALIAS];
     $emailAddress = $row[ColumnNames::EMAIL];
     $firstName = $row[ColumnNames::FIRST_NAME];
     $lastName = $row[ColumnNames::LAST_NAME];
     $timezone = $row[ColumnNames::TIMEZONE_NAME];
     $reminder_minutes = $row[ColumnNames::REMINDER_MINUTES_PRIOR];
     $language = $row[ColumnNames::LANGUAGE_CODE];
     return new ReminderNotice($seriesId, $reservationId, $referenceNumber, $startDate, $endDate, $title, $description, $resourceName, $emailAddress, $firstName, $lastName, $timezone, $reminder_minutes, $language);
 }
 /**
  * @param array $row
  * @return NextReservationView
  */
 public static function Populate($row)
 {
     $item = new NextReservationView($row[ColumnNames::REFERENCE_NUMBER], $row[ColumnNames::SERIES_ID], $row[ColumnNames::RESOURCE_ID], Date::FromDatabase($row[ColumnNames::RESERVATION_START]), Date::FromDatabase($row[ColumnNames::RESERVATION_END]), $row[ColumnNames::USER_ID]);
     $item->OwnerFirstName = $row[ColumnNames::FIRST_NAME];
     $item->OwnerLastName = $row[ColumnNames::LAST_NAME];
     $item->Title = $row[ColumnNames::RESERVATION_TITLE];
     $item->Description = $row[ColumnNames::RESERVATION_DESCRIPTION];
     return $item;
 }
 /**
  * @param int $reportId
  * @param int $userId
  * @return SavedReport
  */
 public function LoadSavedReportForUser($reportId, $userId)
 {
     $reader = ServiceLocator::GetDatabase()->Query(new GetSavedReportForUserCommand($reportId, $userId));
     if ($row = $reader->GetRow()) {
         return SavedReport::FromDatabase($row[ColumnNames::REPORT_NAME], $row[ColumnNames::USER_ID], Date::FromDatabase($row[ColumnNames::DATE_CREATED]), $row[ColumnNames::REPORT_DETAILS], $row[ColumnNames::REPORT_ID]);
     } else {
         return null;
     }
 }
Exemple #10
0
 public function GetChartData($row, $key)
 {
     $format = Resources::GetInstance()->GetDateFormat(ResourceKeys::DATE_GENERAL);
     return Date::FromDatabase($row[$key])->ToTimezone($this->timezone)->GetDate()->Format($format);
 }
Exemple #11
0
 private function SetTerminationDate($terminationDateString)
 {
     if (!empty($terminationDateString)) {
         $this->TerminationDate = Date::FromDatabase($terminationDateString);
     }
 }
 public function testLoadByIdFullyHydratesReservationSeriesObject()
 {
     $seriesId = 10;
     $reservationId = 1;
     $referenceNumber = 'currentInstanceRefNum';
     $ownerId = 10;
     $resourceId = 100;
     $scheduleId = 1000;
     $title = 'title';
     $description = 'description';
     $resourceId1 = 99;
     $resourceId2 = 999;
     $begin = '2010-01-05 12:30:00';
     $end = '2010-01-05 18:30:00';
     $duration = DateRange::Create($begin, $end, 'UTC');
     $interval = 3;
     $repeatType = RepeatType::Daily;
     $terminationDateString = '2010-01-20 12:30:00';
     $terminationDate = Date::FromDatabase($terminationDateString);
     $repeatOptions = new RepeatDaily($interval, $terminationDate);
     $instance1Invitees = array(1, 2, 3);
     $instance1Participants = array(4, 5);
     $instance2Invitees = array(6);
     $instance2Participants = array(7, 8, 9);
     $resourceName = 'primary resource';
     $location = 'l';
     $contact = 'c';
     $notes = 'notes';
     $minLength = '3:00';
     $maxLength = null;
     $autoAssign = true;
     $requiresApproval = false;
     $allowMultiDay = true;
     $maxParticipants = 100;
     $minNotice = '2:10';
     $maxNotice = null;
     $statusId = ReservationStatus::Pending;
     $accessoryId1 = 8111;
     $accessoryId2 = 8222;
     $quantity1 = 11;
     $quantity2 = 22;
     $attributeId1 = 908;
     $attributeValue1 = 'custom1';
     $attributeId2 = 999;
     $attributeValue2 = 'custom2';
     $fileId = 100;
     $startReminderMinutes = 25;
     $endReminderMinutes = 120;
     $allowParticipation = true;
     $expected = new ExistingReservationSeries();
     $expected->WithId($seriesId);
     $expected->WithOwner($ownerId);
     $expected->WithPrimaryResource(new BookableResource($resourceId, $resourceName, $location, $contact, $notes, $minLength, $maxLength, $autoAssign, $requiresApproval, $allowMultiDay, $maxParticipants, $minNotice, $maxNotice, null, $scheduleId));
     $expected->WithTitle($title);
     $expected->WithDescription($description);
     $expected->WithResource(new BookableResource($resourceId1, $resourceName, $location, $contact, $notes, $minLength, $maxLength, $autoAssign, $requiresApproval, $allowMultiDay, $maxParticipants, $minNotice, $maxNotice, null, $scheduleId));
     $expected->WithResource(new BookableResource($resourceId2, $resourceName, $location, $contact, $notes, $minLength, $maxLength, $autoAssign, $requiresApproval, $allowMultiDay, $maxParticipants, $minNotice, $maxNotice, null, $scheduleId));
     $expected->WithRepeatOptions($repeatOptions);
     $expected->WithStatus($statusId);
     $expected->WithAccessory(new ReservationAccessory($accessoryId1, $quantity1));
     $expected->WithAccessory(new ReservationAccessory($accessoryId2, $quantity2));
     $expected->WithAttribute(new AttributeValue($attributeId1, $attributeValue1));
     $expected->WithAttribute(new AttributeValue($attributeId2, $attributeValue2));
     $expected->WithAttachment($fileId, 'doc');
     $expected->AllowParticipation($allowParticipation);
     $instance1 = new Reservation($expected, $duration->AddDays(10));
     $instance1->SetReferenceNumber('instance1');
     $instance1->SetReservationId(909);
     $instance1->WithInvitees($instance1Invitees);
     $instance1->WithParticipants($instance1Participants);
     $instance2 = new Reservation($expected, $duration->AddDays(20));
     $instance2->SetReferenceNumber('instance2');
     $instance2->SetReservationId(1909);
     $instance2->WithInvitees($instance2Invitees);
     $instance2->WithParticipants($instance2Participants);
     $expected->WithInstance($instance1);
     $expected->WithInstance($instance2);
     $expectedInstance = new Reservation($expected, $duration);
     $expectedInstance->SetReferenceNumber($referenceNumber);
     $expectedInstance->SetReservationId($reservationId);
     $expected->WithCurrentInstance($expectedInstance);
     $expected->WithStartReminder(new ReservationReminder($startReminderMinutes, ReservationReminderInterval::Minutes));
     $expected->WithEndReminder(new ReservationReminder($endReminderMinutes / 60, ReservationReminderInterval::Hours));
     $reservationRow = new ReservationRow($reservationId, $begin, $end, $title, $description, $repeatType, $repeatOptions->ConfigurationString(), $referenceNumber, $seriesId, $ownerId, $statusId, $allowParticipation);
     $reservationInstanceRow = new ReservationInstanceRow($seriesId);
     $reservationInstanceRow->WithInstance($instance1->ReservationId(), $instance1->ReferenceNumber(), $instance1->Duration())->WithInstance($instance2->ReservationId(), $instance2->ReferenceNumber(), $instance2->Duration())->WithInstance($reservationId, $expectedInstance->ReferenceNumber(), $expectedInstance->Duration());
     $reservationResourceRow = new ReservationResourceRow($reservationId, $resourceName, $location, $contact, $notes, $minLength, $maxLength, $autoAssign, $requiresApproval, $allowMultiDay, $maxParticipants, $minNotice, $maxNotice, $scheduleId);
     $reservationResourceRow->WithPrimary($resourceId)->WithAdditional($resourceId1)->WithAdditional($resourceId2);
     $reservationUserRow = new ReservationUserRow();
     $reservationUserRow->WithParticipants($instance1, $instance1Participants)->WithParticipants($instance2, $instance2Participants)->WithInvitees($instance1, $instance1Invitees)->WithInvitees($instance2, $instance2Invitees);
     $reservationAccessoryRow = new ReservationAccessoryRow();
     $reservationAccessoryRow->WithAccessory($accessoryId1, $quantity1)->WithAccessory($accessoryId2, $quantity2);
     $attributeValueRow = new CustomAttributeValueRow();
     $attributeValueRow->With($attributeId1, $attributeValue1)->With($attributeId2, $attributeValue2);
     $attachmentRow = new ReservationAttachmentItemRow();
     $attachmentRow->With($fileId, $seriesId, null, 'doc');
     $reminderRow = new ReservationReminderRow();
     $reminderRow->With(1, $seriesId, $startReminderMinutes, ReservationReminderType::Start)->With(2, $seriesId, $endReminderMinutes, ReservationReminderType::End);
     $this->db->SetRow(0, $reservationRow->Rows());
     $this->db->SetRow(1, $reservationInstanceRow->Rows());
     $this->db->SetRow(2, $reservationResourceRow->Rows());
     $this->db->SetRow(3, $reservationUserRow->Rows());
     $this->db->SetRow(4, $reservationAccessoryRow->Rows());
     $this->db->SetRow(5, $attributeValueRow->Rows());
     $this->db->SetRow(6, $attachmentRow->Rows());
     $this->db->SetRow(7, $reminderRow->Rows());
     $actualReservation = $this->repository->LoadById($reservationId);
     $this->assertEquals($expected, $actualReservation);
     $getReservation = new GetReservationByIdCommand($reservationId);
     $getInstances = new GetReservationSeriesInstances($seriesId);
     $getResources = new GetReservationResourcesCommand($seriesId);
     $getParticipants = new GetReservationSeriesParticipantsCommand($seriesId);
     $getAccessories = new GetReservationAccessoriesCommand($seriesId);
     $getAttributeValues = new GetAttributeValuesCommand($seriesId, CustomAttributeCategory::RESERVATION);
     $getAttachments = new GetReservationAttachmentsCommand($seriesId);
     $getReminders = new GetReservationReminders($seriesId);
     $this->assertTrue($this->db->ContainsCommand($getReservation));
     $this->assertTrue($this->db->ContainsCommand($getInstances));
     $this->assertTrue($this->db->ContainsCommand($getResources));
     $this->assertTrue($this->db->ContainsCommand($getParticipants));
     $this->assertTrue($this->db->ContainsCommand($getAccessories));
     $this->assertTrue($this->db->ContainsCommand($getAttributeValues));
     $this->assertTrue($this->db->ContainsCommand($getAttachments));
     $this->assertTrue($this->db->ContainsCommand($getReminders));
 }
 public function testOrdersAndFormatsData()
 {
     $timezone = 'America/Chicago';
     $date = '2012-02-14 08:12:31';
     $oneHourThirtyMinutes = TimeInterval::Parse("1h30m");
     $userId = 100;
     $rows = array(array(ColumnNames::RESERVATION_START => $date, ColumnNames::OWNER_FULL_NAME_ALIAS => 'un', ColumnNames::OWNER_USER_ID => $userId, ColumnNames::ACCESSORY_NAME => 'an', 'unknown' => 'unknown', ColumnNames::TOTAL_TIME => $oneHourThirtyMinutes->TotalSeconds(), ColumnNames::ACCESSORY_ID => 1));
     $report = new CustomReport($rows, $this->attributeRepository);
     $definition = new ReportDefinition($report, $timezone);
     /** @var $row ReportCell[] */
     $row = $definition->GetRow($rows[0]);
     $this->assertEquals(4, count($row));
     $this->assertEquals('an', $row[0]->Value());
     $format = Resources::GetInstance()->GeneralDateTimeFormat();
     $systemFormat = Resources::GetInstance()->GeneralDateFormat();
     $this->assertEquals(Date::FromDatabase($date)->ToTimezone($timezone)->Format($format), $row[1]->Value());
     $this->assertEquals(Date::FromDatabase($date)->ToTimezone($timezone)->Format($systemFormat), $row[1]->ChartValue());
     $this->assertEquals(ChartColumnType::Date, $row[1]->GetChartColumnType());
     $this->assertNull($row[1]->GetChartGroup());
     $this->assertEquals('un', $row[2]->Value());
     $this->assertEquals($userId, $row[2]->ChartValue());
     $this->assertEquals(ChartColumnType::Label, $row[2]->GetChartColumnType());
     $this->assertEmpty($row[2]->GetChartGroup());
     $this->assertEquals($oneHourThirtyMinutes, $row[3]->Value());
     $this->assertEquals($oneHourThirtyMinutes->TotalSeconds(), $row[3]->ChartValue());
     $this->assertEquals(ChartColumnType::Total, $row[3]->GetChartColumnType());
 }
Exemple #14
0
 public static function FromRow($row)
 {
     return new Announcement($row[ColumnNames::ANNOUNCEMENT_ID], $row[ColumnNames::ANNOUNCEMENT_TEXT], Date::FromDatabase($row[ColumnNames::ANNOUNCEMENT_START]), Date::FromDatabase($row[ColumnNames::ANNOUNCEMENT_END]), $row[ColumnNames::ANNOUNCEMENT_PRIORITY]);
 }
 public function testLoadsAnnouncement()
 {
     $text1 = 'text1';
     $start1 = null;
     $end1 = null;
     $priority1 = 3;
     $rows = array($this->GetAnnouncementRow(1, $text1, $start1, $end1, $priority1));
     $this->db->SetRows($rows);
     $id = 1232;
     $actual = $this->repository->LoadById($id);
     $expected = new Announcement(1, $text1, Date::FromDatabase($start1), Date::FromDatabase($end1), $priority1);
     $this->assertEquals(new GetAnnouncementByIdCommand($id), $this->db->_LastCommand);
     $this->assertEquals($actual, $expected);
 }