public function GetScheduleResources($scheduleId, $includeInaccessibleResources, UserSession $user, $filter = null) { if ($filter == null) { $filter = new ScheduleResourceFilter(); } $resources = $this->_resourceRepository->GetScheduleResources($scheduleId); $resourceIds = $filter->FilterResources($resources, $this->_resourceRepository, $this->_attributeService); return $this->Filter($resources, $user, $includeInaccessibleResources, $resourceIds); }
/** * @param int $scheduleId * @param ISchedulePage $page * @return ScheduleResourceFilter */ public function GetResourceFilter($scheduleId, ISchedulePage $page) { $filter = new ScheduleResourceFilter(); if ($page->FilterSubmitted()) { $filter = new ScheduleResourceFilter($scheduleId, $page->GetResourceTypeId(), $page->GetMaxParticipants(), $this->AsAttributeValues($page->GetResourceAttributes()), $this->AsAttributeValues($page->GetResourceTypeAttributes())); } else { $cookie = ServiceLocator::GetServer()->GetCookie('resource_filter' . $scheduleId); if (!empty($cookie)) { $val = json_decode($cookie); $filter = ScheduleResourceFilter::FromCookie($val); } } $filter->ScheduleId = $scheduleId; $filter->ResourceId = $this->GetResourceId($scheduleId, $page); $filter->GroupId = $this->GetGroupId($scheduleId, $page); return $filter; }
public function testFiltersResourceTypeCustomAttributes() { $attributeId1 = 1; $attributeValue1 = 1; $attributeId2 = 2; $attributeValue2 = 'something'; $resourceId = 3; $resourceTypeId = 4; $attributeList = new FakeAttributeList(); $attributeList->Add($resourceTypeId, new Attribute(new CustomAttribute($attributeId1, '', CustomAttributeTypes::CHECKBOX, CustomAttributeCategory::RESOURCE, '', false, '', 0, $resourceTypeId), $attributeValue1)); $attributeList->Add($resourceTypeId, new Attribute(new CustomAttribute($attributeId2, '', CustomAttributeTypes::MULTI_LINE_TEXTBOX, CustomAttributeCategory::RESOURCE, '', false, '', 0, $resourceTypeId), $attributeValue2)); $attributeList->Add(1, new Attribute(new CustomAttribute($attributeId2, '', CustomAttributeTypes::MULTI_LINE_TEXTBOX, CustomAttributeCategory::RESOURCE, '', false, '', 0, 1), $attributeValue2)); $attributeList->Add(3, new Attribute(new CustomAttribute($attributeId2, '', CustomAttributeTypes::MULTI_LINE_TEXTBOX, CustomAttributeCategory::RESOURCE, '', false, '', 0, 3), $attributeValue2)); $this->attributeService->expects($this->once())->method('GetAttributes')->with($this->equalTo(CustomAttributeCategory::RESOURCE_TYPE), $this->isNull())->will($this->returnValue($attributeList)); $filter = new ScheduleResourceFilter(); $filter->ResourceTypeAttributes = array(new AttributeValue($attributeId1, $attributeValue1), new AttributeValue($attributeId2, $attributeValue2)); $resource1 = new FakeBookableResource(1, 'resource1'); $resource1->SetResourceTypeId(100); $resource2 = new FakeBookableResource(2, 'resource2'); $resource2->SetResourceTypeId(200); $resource3 = new FakeBookableResource($resourceId, 'resource3'); $resource3->SetResourceTypeId($resourceTypeId); $resource4 = new FakeBookableResource(4, 'resource4'); $resources = array($resource1, $resource2, $resource3, $resource4); $resourceIds = $filter->FilterResources($resources, $this->resourceRepository, $this->attributeService); $this->assertEquals(1, count($resourceIds)); $this->assertEquals($resourceId, $resourceIds[0]); }