コード例 #1
0
 /**
  * @param IRestServer $server
  * @param BookableResource $resource
  * @param ReservationItemView|null $conflictingReservation
  * @param ReservationItemView|null $nextReservation
  * @param Date|null $nextAvailableTime
  */
 public function __construct(IRestServer $server, $resource, $conflictingReservation, $nextReservation, $nextAvailableTime)
 {
     $this->resource = new ResourceReference($server, $resource);
     $this->available = $conflictingReservation == null;
     $this->AddService($server, WebServices::GetResource, array(WebServiceParams::ResourceId => $resource->GetId()));
     if (!$this->available) {
         $this->availableAt = $nextAvailableTime != null ? $nextAvailableTime->ToTimezone($server->GetSession()->Timezone)->ToIso() : null;
         $this->AddService($server, WebServices::GetUser, array(WebServiceParams::UserId => $conflictingReservation->UserId));
         $this->AddService($server, WebServices::GetReservation, array(WebServiceParams::ReferenceNumber => $conflictingReservation->ReferenceNumber));
     }
     if ($this->available && $nextReservation != null) {
         $this->availableUntil = $nextReservation->BufferedTimes()->GetBegin()->ToTimezone($server->GetSession()->Timezone)->ToIso();
     }
 }
コード例 #2
0
 public function testUpdatesResource()
 {
     $resourceId = 122;
     $request = ResourceRequest::Example();
     $expectedUpdateResource = new BookableResource($resourceId, $request->name, $request->location, $request->contact, $request->notes, $request->minLength, $request->maxLength, $request->autoAssignPermissions, $request->requiresApproval, $request->allowMultiday, $request->maxParticipants, $request->minNotice, $request->maxNotice, $request->description, $request->scheduleId);
     $expectedUpdateResource->SetSortOrder($request->sortOrder);
     $expectedUpdateResource->ChangeStatus($request->statusId, $request->statusReasonId);
     $attributes = array(new AttributeValue($request->customAttributes[0]->attributeId, $request->customAttributes[0]->attributeValue));
     $expectedUpdateResource->ChangeAttributes($attributes);
     $this->validator->expects($this->once())->method('ValidateUpdateRequest')->with($this->equalTo($resourceId), $this->equalTo($request))->will($this->returnValue(array()));
     $this->repository->expects($this->once())->method('Update')->with($this->equalTo($expectedUpdateResource));
     $response = $this->controller->Update($resourceId, $request, $this->session);
     $this->assertTrue($response->WasSuccessful());
     $this->assertEquals($resourceId, $response->ResourceId());
     $this->assertEmpty($response->Errors());
 }
コード例 #3
0
 public function testWhenNotFound()
 {
     $resourceId = 8282;
     $this->repository->expects($this->once())->method('LoadById')->with($this->equalTo($resourceId))->will($this->returnValue(BookableResource::Null()));
     $this->service->GetResource($resourceId);
     $this->assertEquals(RestResponse::NotFound(), $this->server->_LastResponse);
 }
コード例 #4
0
 private function FillRows()
 {
     $rows = $this->GetRows();
     foreach ($rows as $row) {
         $this->_Resources[] = BookableResource::Create($row);
     }
 }
コード例 #5
0
ファイル: ResourceReference.php プロジェクト: Trideon/gigolo
 /**
  * @param IRestServer $server
  * @param BookableResource $resource
  */
 public function __construct(IRestServer $server, $resource)
 {
     $this->resourceId = $resource->GetId();
     $this->name = $resource->GetName();
     $this->scheduleId = $resource->GetScheduleId();
     $this->statusId = $resource->GetStatusId();
     $this->statusReasonId = $resource->GetStatusReasonId();
     $this->AddService($server, WebServices::GetResource, array(WebServiceParams::ResourceId => $this->resourceId));
     $this->AddService($server, WebServices::GetSchedule, array(WebServiceParams::ScheduleId => $this->scheduleId));
 }
コード例 #6
0
ファイル: ResourceResponse.php プロジェクト: hugutux/booked
 /**
  * @param IRestServer $server
  * @param BookableResource $resource
  * @param IEntityAttributeList $attributes
  */
 public function __construct(IRestServer $server, $resource, $attributes)
 {
     $resourceId = $resource->GetId();
     $this->resourceId = $resourceId;
     $this->name = $resource->GetName();
     $this->location = $resource->GetLocation();
     $this->contact = $resource->GetContact();
     $this->notes = $resource->GetNotes();
     $this->maxLength = $resource->GetMaxLength()->__toString();
     $this->minLength = $resource->GetMinLength()->__toString();
     $this->maxNotice = $resource->GetMaxNotice()->__toString();
     $this->minNotice = $resource->GetMinNotice()->__toString();
     $this->requiresApproval = $resource->GetRequiresApproval();
     $this->allowMultiday = $resource->GetAllowMultiday();
     $this->maxParticipants = $resource->GetMaxParticipants();
     $this->description = $resource->GetDescription();
     $this->scheduleId = $resource->GetScheduleId();
     $this->statusId = $resource->GetStatusId();
     $this->statusReasonId = $resource->GetStatusReasonId();
     $this->bufferTime = $resource->GetBufferTime()->__toString();
     $attributeValues = $attributes->GetAttributes($resourceId);
     $i = 0;
     foreach ($attributeValues as $av) {
         $this->customAttributes[] = new CustomAttributeResponse($server, $av->Id(), $av->Label(), $av->Value());
         $i++;
     }
     if ($resource->GetIsCalendarSubscriptionAllowed()) {
         $url = new CalendarSubscriptionUrl(null, null, $resource->GetPublicId());
         $this->icsUrl = $url->__toString();
     }
     $this->AddService($server, WebServices::GetResource, array(WebServiceParams::ResourceId => $resourceId));
 }
コード例 #7
0
 /**
  * @param ResourceRequest $request
  * @param int $resourceId
  * @return BookableResource
  */
 private function BuildResource($request, $resourceId)
 {
     $resource = new BookableResource($resourceId, $request->name, $request->location, $request->contact, $request->notes, $request->minLength, $request->maxLength, $request->autoAssignPermissions, $request->requiresApproval, $request->allowMultiday, $request->maxParticipants, $request->minNotice, $request->maxNotice, $request->description, $request->scheduleId);
     $resource->SetSortOrder($request->sortOrder);
     $attributes = array();
     foreach ($request->GetCustomAttributes() as $attribute) {
         $attributes[] = new AttributeValue($attribute->attributeId, $attribute->attributeValue);
     }
     $resource->ChangeAttributes($attributes);
     if (isset($request->statusId)) {
         $resource->ChangeStatus($request->statusId, $request->statusReasonId);
     }
     return $resource;
 }
コード例 #8
0
 /**
  * @param int $userId
  * @param BookableResource $resource
  * @param string $title
  * @param string $description
  * @param UserSession $updatedBy
  */
 public function Update($userId, BookableResource $resource, $title, $description, UserSession $updatedBy)
 {
     $this->_bookedBy = $updatedBy;
     if ($this->seriesUpdateStrategy->RequiresNewSeries()) {
         $this->AddEvent(new SeriesBranchedEvent($this));
         $this->Repeats($this->seriesUpdateStrategy->GetRepeatOptions($this));
     }
     if ($this->_resource->GetId() != $resource->GetId()) {
         $this->AddEvent(new ResourceRemovedEvent($this->_resource, $this));
         $this->AddEvent(new ResourceAddedEvent($resource, ResourceLevel::Primary, $this));
     }
     if ($this->UserId() != $userId) {
         $this->AddEvent(new OwnerChangedEvent($this, $this->UserId(), $userId));
     }
     $this->_userId = $userId;
     $this->_resource = $resource;
     $this->_title = $title;
     $this->_description = $description;
 }
コード例 #9
0
 public static function FromBookable(BookableResource $resource)
 {
     return new AdminResourceJson($resource->GetId(), $resource->GetName());
 }
コード例 #10
0
 public function BindResource(BookableResource $resource)
 {
     $this->Set('resourceName', $resource->GetName());
     $this->Set('description', $resource->GetDescription());
     $this->Set('notes', $resource->GetNotes());
     $this->Set('contactInformation', $resource->GetContact());
     $this->Set('locationInformation', $resource->GetLocation());
     $this->Set('allowMultiday', $resource->GetAllowMultiday());
     $this->Set('minimumDuration', $resource->GetMinLength());
     $this->Set('maximumDuration', $resource->GetMaxLength());
     $this->Set('maxParticipants', $resource->GetMaxParticipants());
     $this->Set('maximumNotice', $resource->GetMaxNotice());
     $this->Set('minimumNotice', $resource->GetMinNotice());
     $this->Set('requiresApproval', $resource->GetRequiresApproval());
     $this->Set('autoAssign', $resource->GetAutoAssign());
     if ($resource->HasImage()) {
         $this->Set('imageUrl', Configuration::Instance()->GetKey(ConfigKeys::IMAGE_UPLOAD_URL) . '/' . $resource->GetImage());
     }
 }
コード例 #11
0
 /**
  * @param BookableResource $resource
  * @param ReservationItemView[][] $reservations
  * @return null|ReservationItemView
  */
 private function GetLastReservationBeforeAnOpening($resource, $reservations)
 {
     $resourceId = $resource->GetId();
     if (!array_key_exists($resourceId, $reservations)) {
         return null;
     }
     $resourceReservations = $reservations[$resourceId];
     for ($i = 0; $i < count($resourceReservations) - 1; $i++) {
         $current = $resourceReservations[$i];
         $next = $resourceReservations[$i + 1];
         if ($current->EndDate->Equals($next->StartDate)) {
             continue;
         }
         return $current;
     }
     return $resourceReservations[count($resourceReservations) - 1];
 }
コード例 #12
0
ファイル: ReservationEvents.php プロジェクト: Trideon/gigolo
 public function ResourceId()
 {
     return $this->resource->GetResourceId();
 }
コード例 #13
0
ファイル: BookableResource.php プロジェクト: hugutux/booked
 /**
  * @param array $row
  * @return BookableResource
  */
 public static function Create($row)
 {
     $resource = new BookableResource($row[ColumnNames::RESOURCE_ID], $row[ColumnNames::RESOURCE_NAME], $row[ColumnNames::RESOURCE_LOCATION], $row[ColumnNames::RESOURCE_CONTACT], $row[ColumnNames::RESOURCE_NOTES], $row[ColumnNames::RESOURCE_MINDURATION], $row[ColumnNames::RESOURCE_MAXDURATION], $row[ColumnNames::RESOURCE_AUTOASSIGN], $row[ColumnNames::RESOURCE_REQUIRES_APPROVAL], $row[ColumnNames::RESOURCE_ALLOW_MULTIDAY], $row[ColumnNames::RESOURCE_MAX_PARTICIPANTS], $row[ColumnNames::RESOURCE_MINNOTICE], $row[ColumnNames::RESOURCE_MAXNOTICE], $row[ColumnNames::RESOURCE_DESCRIPTION], $row[ColumnNames::SCHEDULE_ID]);
     $resource->SetImage($row[ColumnNames::RESOURCE_IMAGE_NAME]);
     $resource->SetAdminGroupId($row[ColumnNames::RESOURCE_ADMIN_GROUP_ID]);
     $resource->SetSortOrder($row[ColumnNames::RESOURCE_SORT_ORDER]);
     $resource->ChangeStatus($row[ColumnNames::RESOURCE_STATUS_ID], $row[ColumnNames::RESOURCE_STATUS_REASON_ID]);
     $resource->WithPublicId($row[ColumnNames::PUBLIC_ID]);
     $resource->WithSubscription($row[ColumnNames::ALLOW_CALENDAR_SUBSCRIPTION]);
     $resource->WithScheduleAdminGroupId($row[ColumnNames::SCHEDULE_ADMIN_GROUP_ID_ALIAS]);
     $resource->SetResourceTypeId($row[ColumnNames::RESOURCE_TYPE_ID]);
     $resource->SetBufferTime($row[ColumnNames::RESOURCE_BUFFER_TIME]);
     return $resource;
 }
コード例 #14
0
ファイル: load_test.php プロジェクト: utn-frm-si/booked
$resources = array();
$db = ServiceLocator::GetDatabase();
// USERS
$db->Execute(new AdHocCommand("delete from users where fname ='load' and lname = 'test'"));
$userRepo = new UserRepository();
for ($i = 0; $i < $numberOfUsers; $i++) {
    $user = User::Create("load{$i}", "test{$i}", "email {$i}", "username {$i}", "en_us", "America/Chicago", "7b6aec38ff9b7650d64d0374194307bdde711425", "3b3dbb9b");
    $userId = $userRepo->Add($user);
    $users[] = $user;
}
echo "Loaded {$numberOfUsers} users<br/>";
// RESOURCES
$db->Execute(new AdHocCommand("delete from resources where name like 'load%'"));
$resourceRepo = new ResourceRepository();
for ($i = 0; $i < $numberOfResources; $i++) {
    $resource = BookableResource::CreateNew("load{$i}", 1);
    $resourceId = $resourceRepo->Add($resource);
    $resources[] = $resource;
}
echo "Loaded {$numberOfResources} resources<br/>";
// ACCESSORIES
$db->Execute(new AdHocCommand("delete from accessories where accessory_name like 'load%'"));
$accessoryRepo = new AccessoryRepository();
for ($i = 0; $i < $numberOfAccessories; $i++) {
    $accessory = new Accessory(0, "Load {$i}", 10);
    $id = $accessoryRepo->Add($accessory);
}
echo "Loaded {$numberOfAccessories} accessories<br/>";
// RESERVATIONS
$db->Execute(new AdHocCommand("delete from reservation_series where title like 'load%'"));
$scheduleRepo = new ScheduleRepository();
コード例 #15
0
ファイル: ReservationSeries.php プロジェクト: JoseTfg/Booked
 /**
  * @return int
  */
 public function ScheduleId()
 {
     return $this->_resource->GetScheduleId();
 }
コード例 #16
0
 private function PopulateResources(ExistingReservationSeries $series)
 {
     // get all reservation resources
     $getResourcesCommand = new GetReservationResourcesCommand($series->SeriesId());
     $reader = ServiceLocator::GetDatabase()->Query($getResourcesCommand);
     while ($row = $reader->GetRow()) {
         $resource = BookableResource::Create($row);
         if ($row[ColumnNames::RESOURCE_LEVEL_ID] == ResourceLevel::Primary) {
             $series->WithPrimaryResource($resource);
         } else {
             $series->WithResource($resource);
         }
     }
     $reader->Free();
 }
コード例 #17
0
 public function Delete(BookableResource $resource)
 {
     Log::Debug("Deleting resource %s (%s)", $resource->GetResourceId(), $resource->GetName());
     $resourceId = $resource->GetResourceId();
     $db = ServiceLocator::GetDatabase();
     $db->Execute(new DeleteResourceReservationsCommand($resourceId));
     $db->Execute(new DeleteResourceCommand($resourceId));
 }
コード例 #18
0
 public function testDeletingAResourceRemovesAllAssociatedData()
 {
     $resourceId = 100;
     $resource = BookableResource::CreateNew('name', 1);
     $resource->SetResourceId($resourceId);
     $this->repository->Delete($resource);
     $deleteReservations = new DeleteResourceReservationsCommand($resourceId);
     $deleteResources = new DeleteResourceCommand($resourceId);
     $actualDeleteReservations = $this->db->_Commands[0];
     $actualDeleteResources = $this->db->_Commands[1];
     $this->assertEquals($deleteReservations, $actualDeleteReservations);
     $this->assertEquals($deleteResources, $actualDeleteResources);
 }