public function __construct(IRestServer $server, CustomAttribute $attribute)
 {
     $this->id = $attribute->Id();
     $this->categoryId = $attribute->Category();
     $this->label = $attribute->Label();
     $this->possibleValues = $attribute->PossibleValueList();
     $this->regex = $attribute->Regex();
     $this->required = $attribute->Required();
     $this->type = $attribute->Type();
     $this->sortOrder = $attribute->SortOrder();
     $this->appliesToId = $attribute->EntityId();
     $this->AddService($server, WebServices::AllCustomAttributes, array(WebServiceParams::AttributeCategoryId => $this->categoryId));
     $this->AddService($server, WebServices::GetCustomAttribute, array(WebServiceParams::AttributeId => $this->id));
     $this->AddService($server, WebServices::UpdateCustomAttribute, array(WebServiceParams::AttributeId => $this->id));
     $this->AddService($server, WebServices::DeleteCustomAttribute, array(WebServiceParams::AttributeId => $this->id));
 }
Пример #2
0
 public function testTrimsOffPossibleValueWhiteSpace()
 {
     $attribute = CustomAttribute::Create(null, 1, 1, null, false, '  1, abc    ,1abc3   ', '    1   ');
     $list = $attribute->PossibleValueList();
     $this->assertTrue(in_array('1', $list));
     $this->assertTrue(in_array('abc', $list));
     $this->assertTrue(in_array('1abc3', $list));
     $this->assertEquals(1, $attribute->SortOrder());
 }
Пример #3
0
 public function AddDefinition(CustomAttribute $attribute)
 {
     $this->labels[] = $attribute->Label();
     $this->attribute_order[$attribute->Id()] = 1;
     if ($attribute->UniquePerEntity()) {
         $this->entityDefinitions[$attribute->EntityId()][$attribute->Id()] = $attribute;
         $this->entityAttributes[$attribute->Id()] = 1;
         //			Log::Debug('Adding custom attribute definition for entityId=%s, label=%s', $attribute->EntityId(), $attribute->Label());
     } else {
         $this->definitions[$attribute->Id()] = $attribute;
         //			Log::Debug('Adding custom attribute definition label=%s', $attribute->Label());
     }
 }
 public function __construct(IRestServer $server, CustomAttribute $attribute)
 {
     $this->id = $attribute->Id();
     $this->categoryId = $attribute->Category();
     $this->label = $attribute->Label();
     $this->possibleValues = $attribute->PossibleValueList();
     $this->regex = $attribute->Regex();
     $this->required = $attribute->Required();
     $this->AddService($server, WebServices::AllCustomAttributes, array(WebServiceParams::AttributeCategoryId => $this->categoryId));
     $this->AddService($server, WebServices::GetCustomAttribute, array(WebServiceParams::AttributeId => $this->id));
 }
Пример #5
0
 public function AddAttribute()
 {
     $attributeName = $this->page->GetLabel();
     $type = $this->page->GetType();
     $scope = $this->page->GetCategory();
     $regex = $this->page->GetValidationExpression();
     $required = $this->page->GetIsRequired();
     $possibleValues = $this->page->GetPossibleValues();
     $sortOrder = $this->page->GetSortOrder();
     $entityId = $this->page->GetEntityId();
     Log::Debug('Adding new attribute named: %s', $attributeName);
     $attribute = CustomAttribute::Create($attributeName, $type, $scope, $regex, $required, $possibleValues, $sortOrder, $entityId);
     $this->attributeRepository->Add($attribute);
 }
 public function testAddsAttribute()
 {
     $request = new CustomAttributeRequest();
     $request->label = 'attributename';
     $request->type = CustomAttributeTypes::SELECT_LIST;
     $request->categoryId = CustomAttributeCategory::USER;
     $request->regex = 'regex';
     $request->required = true;
     $request->possibleValues = '1,2,3';
     $request->sortOrder = 9;
     $request->appliesToId = 100;
     $result = $this->controller->Create($request, $this->session);
     $this->assertEquals(true, $result->WasSuccessful());
     $this->assertEquals($this->attributeRepository->_LastCreateId, $result->AttributeId());
     $expected = CustomAttribute::Create($request->label, $request->type, $request->categoryId, $request->regex, $request->required, $request->possibleValues, $request->sortOrder, $request->appliesToId);
     $this->assertEquals($expected, $this->attributeRepository->_Added);
 }
Пример #7
0
 /**
  * @return bool
  */
 public function UniquePerEntity()
 {
     return $this->attributeDefinition->UniquePerEntity();
 }
Пример #8
0
 /**
  * @static
  * @param $row array
  * @return Attribute
  */
 public static function FromRow($row)
 {
     $attribute = new CustomAttribute($row[ColumnNames::ATTRIBUTE_ID], $row[ColumnNames::ATTRIBUTE_LABEL], $row[ColumnNames::ATTRIBUTE_TYPE], $row[ColumnNames::ATTRIBUTE_CATEGORY], $row[ColumnNames::ATTRIBUTE_CONSTRAINT], $row[ColumnNames::ATTRIBUTE_REQUIRED], $row[ColumnNames::ATTRIBUTE_POSSIBLE_VALUES], $row[ColumnNames::ATTRIBUTE_SORT_ORDER], $row[ColumnNames::ATTRIBUTE_ENTITY_ID], $row[ColumnNames::ATTRIBUTE_ENTITY_ID]);
     $attribute->WithEntityDescription($row[ColumnNames::ATTRIBUTE_ENTITY_DESCRIPTION]);
     return $attribute;
 }
 public function testUpdatesAttribute()
 {
     $attributeId = 1091;
     $label = 'new label';
     $required = true;
     $regex = '/$\\d^/';
     $possibleValues = '1,2,3';
     $sortOrder = "5";
     $entityId = true;
     $this->page->_label = $label;
     $this->page->_required = $required;
     $this->page->_regex = $regex;
     $this->page->_possibleValues = $possibleValues;
     $this->page->_attributeId = $attributeId;
     $this->page->_sortOrder = $sortOrder;
     $this->page->_entityId = $entityId;
     $expectedAttribute = CustomAttribute::Create('', CustomAttributeTypes::CHECKBOX, CustomAttributeCategory::USER, null, false, null, $sortOrder, $entityId);
     $this->attributeRepository->expects($this->once())->method('LoadById')->with($this->equalTo($attributeId))->will($this->returnValue($expectedAttribute));
     $this->attributeRepository->expects($this->once())->method('Update')->with($this->equalTo($expectedAttribute));
     $this->presenter->UpdateAttribute();
     $this->assertEquals($label, $expectedAttribute->Label());
     $this->assertEquals($regex, $expectedAttribute->Regex());
     $this->assertEquals($required, $expectedAttribute->Required());
     $this->assertEquals($possibleValues, $expectedAttribute->PossibleValues());
     $this->assertEquals($sortOrder, $expectedAttribute->SortOrder());
     $this->assertEquals($entityId, $expectedAttribute->EntityId());
 }
Пример #10
0
 /**
  * @param CustomAttributeRequest $request
  * @param WebServiceUserSession $session
  * @return AttributeControllerResult
  */
 public function Create($request, $session)
 {
     $errors = $this->ValidateRequest($request);
     if (!empty($errors)) {
         return new AttributeControllerResult(null, $errors);
     }
     $attribute = CustomAttribute::Create($request->label, $request->type, $request->categoryId, $request->regex . '', (int) $request->required, $this->GetPossibleValues($request), $request->sortOrder, $request->appliesToId);
     $attributeId = $this->repository->Add($attribute);
     return new AttributeControllerResult($attributeId, null);
 }
 public function testBindsCustomAttributes()
 {
     $binder = new ReservationCustomAttributeBinder($this->attributeRepository);
     $attributes = array(CustomAttribute::Create('1', CustomAttributeTypes::SINGLE_LINE_TEXTBOX, CustomAttributeCategory::RESERVATION, '', false, '', 1), CustomAttribute::Create('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(null));
     $this->initializer->expects($this->at(1))->method('AddAttribute')->with($this->equalTo($attributes[1]), $this->equalTo(null));
     $binder->Bind($this->initializer);
 }
Пример #12
0
 /**
  * @param CustomAttribute $attribute
  */
 public function Update(CustomAttribute $attribute)
 {
     ServiceLocator::GetDatabase()->Execute(new UpdateAttributeCommand($attribute->Id(), $attribute->Label(), $attribute->Type(), $attribute->Category(), $attribute->Regex(), $attribute->Required(), $attribute->PossibleValues(), $attribute->SortOrder(), $attribute->EntityId()));
 }
Пример #13
0
 public function testLoadsAttributesByCategory()
 {
     $id = 12098;
     $label = 'label';
     $type = CustomAttributeTypes::SINGLE_LINE_TEXTBOX;
     $category = CustomAttributeCategory::RESERVATION;
     $regex = 'regex';
     $required = false;
     $possibleValues = 'val1,val2,val3';
     $sortOrder = '4';
     $entityId = 12;
     $entityDescription = 'entity desc';
     $row1 = $this->GetAttributeRow($id, $label, $type, $category, $regex, $required, $possibleValues, $sortOrder, $entityId, $entityDescription);
     $row2 = $this->GetAttributeRow(2);
     $this->db->SetRows(array($row1, $row2));
     $attributes = $this->repository->GetByCategory(CustomAttributeCategory::RESERVATION);
     $expectedFirstAttribute = new CustomAttribute($id, $label, $type, $category, $regex, $required, $possibleValues, $sortOrder, $entityId);
     $expectedFirstAttribute->WithEntityDescription($entityDescription);
     $this->assertEquals(2, count($attributes));
     $this->assertEquals($expectedFirstAttribute, $attributes[0]);
     $this->assertEquals(new GetAttributesByCategoryCommand(CustomAttributeCategory::RESERVATION), $this->db->_LastCommand);
 }