AttributeDescription.php
1 <?php
2 /**
3  * wCMF - wemove Content Management Framework
4  * Copyright (C) 2005-2015 wemove digital solutions GmbH
5  *
6  * Licensed under the terms of the MIT License.
7  *
8  * See the LICENSE file distributed with this work for
9  * additional information.
10  */
11 namespace wcmf\lib\persistence;
12 
13 /**
14  * Instances of AttributeDescription describe attributes of PersistentObjects
15  *
16  * @author ingo herwig <ingo@wemove.com>
17  */
19 
20  protected $name = '';
21  protected $type = 'String';
22  protected $tags = array();
23  protected $defaultValue = null;
24  protected $validateType = '';
25  protected $validateDescription = '';
26  protected $isEditable = true;
27  protected $inputType = 'text';
28  protected $displayType = 'text';
29 
30  /**
31  * Constructor.
32  * @param $name The attribute name
33  * @param $type The attribute type
34  * @param $tags An array of application specific tags that this attribute is tagged with
35  * @param $defaultValue The default value (will be set when creating a blank object, see PersistenceMapper::create())
36  * @param $validateType A validation type for the value
37  * @param $validateDescription A description for the validation type
38  * @param $isEditable Boolean whether the attribute should be editable, see Control::render()
39  * @param $inputType The input type for the value, see Control::render()
40  * @param $displayType The display type for the value
41  */
44 
45  $this->name = $name;
46  $this->type = $type;
47  $this->tags = $tags;
48  $this->defaultValue = $defaultValue;
49  $this->validateType = $validateType;
50  $this->validateDescription = $validateDescription;
51  $this->isEditable = $isEditable;
52  $this->inputType = $inputType;
53  $this->displayType = $displayType;
54  }
55 
56  /**
57  * Check if this attribute has the given application specific tag
58  * @param $tag Tag that the attribute should have
59  * @return Boolean
60  */
61  public function hasTag($tag) {
62  return in_array($tag, $this->tags);
63  }
64 
65  /**
66  * Check if this attribute is tagged with the given application specific tags
67  * @param $tags An array of tags that the attribute should match. Empty array results in true the given matchMode (default: empty array)
68  * @param $matchMode One of 'all', 'none', 'any', defines how the attribute's tags should match the given tags (default: 'all')
69  * @return True if the attribute tags satisfy the match mode, false else
70  */
71  public function matchTags(array $tags=array(), $matchMode='all') {
72  $numGivenTags = sizeof($tags);
73  if (sizeof($numGivenTags) == 0) {
74  return true;
75  }
76  $result = true;
77  $diff = sizeof(array_diff($tags, $this->tags));
78  switch ($matchMode) {
79  case 'all':
80  $result = ($diff == 0);
81  break;
82  case 'none':
83  $result = ($diff == $numGivenTags);
84  break;
85  case 'any':
86  $result = ($diff < $numGivenTags);
87  break;
88  }
89  return $result;
90  }
91 
92  /**
93  * Return an array of property names defined in this attribute description
94  * @return An array of names
95  */
96  public function getPropertyNames() {
97  return array('name', 'type', 'tags', 'defaultValue', 'validateType',
98  'validateDescription', 'isEditable', 'inputType', 'displayType');
99  }
100 
101  /**
102  * Get the attribute name
103  * @return String
104  */
105  public function getName() {
106  return $this->name;
107  }
108 
109  /**
110  * Get the attribute type
111  * @return String
112  */
113  public function getType() {
114  return $this->type;
115  }
116 
117  /**
118  * Get the application specific tags that this attribute is tagged with
119  * @return Array of String
120  */
121  public function getTags() {
122  return $this->tags;
123  }
124 
125  /**
126  * Get the default value
127  * @return Mixed
128  */
129  public function getDefaultValue() {
130  return $this->defaultValue;
131  }
132 
133  /**
134  * Get the validation type for the value
135  * @return String
136  */
137  public function getValidateType() {
138  return $this->validateType;
139  }
140 
141  /**
142  * Get the description for the validation type
143  * @return String
144  */
145  public function getValidateDescription() {
147  }
148 
149  /**
150  * Check whether the attribute should be editable
151  * @return Boolean
152  */
153  public function getIsEditable() {
154  return $this->isEditable;
155  }
156 
157  /**
158  * Get the input type for the value
159  * @return String
160  */
161  public function getInputType() {
162  return $this->inputType;
163  }
164 
165  /**
166  * Get the display type for the value
167  * @return String
168  */
169  public function getDisplayType() {
170  return $this->displayType;
171  }
172 }
173 ?>
getPropertyNames()
Return an array of property names defined in this attribute description.
getTags()
Get the application specific tags that this attribute is tagged with.
getValidateType()
Get the validation type for the value.
getIsEditable()
Check whether the attribute should be editable.
Persistence layer related interfaces and classes.
Definition: namespaces.php:42
getValidateDescription()
Get the description for the validation type.
hasTag($tag)
Check if this attribute has the given application specific tag.
getDisplayType()
Get the display type for the value.
matchTags(array $tags=array(), $matchMode='all')
Check if this attribute is tagged with the given application specific tags.
Instances of AttributeDescription describe attributes of PersistentObjects.
getInputType()
Get the input type for the value.
__construct($name, $type, array $tags, $defaultValue, $validateType, $validateDescription, $isEditable, $inputType, $displayType)
Constructor.