AttributeDescription.php
1 <?php
2 /**
3  * wCMF - wemove Content Management Framework
4  * Copyright (C) 2005-2020 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 = [];
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  $this->name = $name;
45  $this->type = $type;
46  $this->tags = $tags;
47  $this->defaultValue = $defaultValue;
48  $this->validateType = $validateType;
49  $this->validateDescription = $validateDescription;
50  $this->isEditable = $isEditable;
51  $this->inputType = $inputType;
52  $this->displayType = $displayType;
53  }
54 
55  /**
56  * Check if this attribute has the given application specific tag
57  * @param $tag Tag that the attribute should have
58  * @return Boolean
59  */
60  public function hasTag($tag) {
61  return in_array($tag, $this->tags);
62  }
63 
64  /**
65  * Check if this attribute is tagged with the given application specific tags
66  * @param $tags An array of tags that the attribute should match. Empty array results in true the given matchMode (default: empty array)
67  * @param $matchMode One of 'all', 'none', 'any', defines how the attribute's tags should match the given tags (default: 'all')
68  * @return True if the attribute tags satisfy the match mode, false else
69  */
70  public function matchTags(array $tags=[], $matchMode='all') {
71  $numGivenTags = sizeof($tags);
72  if (sizeof($numGivenTags) == 0) {
73  return true;
74  }
75  $result = true;
76  $diff = sizeof(array_diff($tags, $this->tags));
77  switch ($matchMode) {
78  case 'all':
79  $result = ($diff == 0);
80  break;
81  case 'none':
82  $result = ($diff == $numGivenTags);
83  break;
84  case 'any':
85  $result = ($diff < $numGivenTags);
86  break;
87  }
88  return $result;
89  }
90 
91  /**
92  * Return an array of property names defined in this attribute description
93  * @return An array of names
94  */
95  public function getPropertyNames() {
96  return ['name', 'type', 'tags', 'defaultValue', 'validateType',
97  'validateDescription', 'isEditable', 'inputType', 'displayType'];
98  }
99 
100  /**
101  * Get the attribute name
102  * @return String
103  */
104  public function getName() {
105  return $this->name;
106  }
107 
108  /**
109  * Get the attribute type
110  * @return String
111  */
112  public function getType() {
113  return $this->type;
114  }
115 
116  /**
117  * Get the application specific tags that this attribute is tagged with
118  * @return Array of String
119  */
120  public function getTags() {
121  return $this->tags;
122  }
123 
124  /**
125  * Get the default value
126  * @return Mixed
127  */
128  public function getDefaultValue() {
129  return $this->defaultValue;
130  }
131 
132  /**
133  * Get the validation type for the value
134  * @return String
135  */
136  public function getValidateType() {
137  return $this->validateType;
138  }
139 
140  /**
141  * Get the description for the validation type
142  * @return String
143  */
144  public function getValidateDescription() {
146  }
147 
148  /**
149  * Check whether the attribute should be editable
150  * @return Boolean
151  */
152  public function getIsEditable() {
153  return $this->isEditable;
154  }
155 
156  /**
157  * Get the input type for the value
158  * @return String
159  */
160  public function getInputType() {
161  return $this->inputType;
162  }
163 
164  /**
165  * Get the display type for the value
166  * @return String
167  */
168  public function getDisplayType() {
169  return $this->displayType;
170  }
171 }
172 ?>
matchTags(array $tags=[], $matchMode='all')
Check if this attribute is tagged with the given application specific tags.
getInputType()
Get the input type for the value.
Persistence layer related interfaces and classes.
Definition: namespaces.php:42
getTags()
Get the application specific tags that this attribute is tagged with.
__construct($name, $type, array $tags, $defaultValue, $validateType, $validateDescription, $isEditable, $inputType, $displayType)
Constructor.
getValidateType()
Get the validation type for the value.
Instances of AttributeDescription describe attributes of PersistentObjects.
getIsEditable()
Check whether the attribute should be editable.
getValidateDescription()
Get the description for the validation type.
getDisplayType()
Get the display type for the value.
getPropertyNames()
Return an array of property names defined in this attribute description.
hasTag($tag)
Check if this attribute has the given application specific tag.