1: <?php
2: /**
3: * PHP version 5
4: * @package generalDriver
5: * @author Christian Schiffler <c.schiffler@cyberspectrum.de>
6: * @author Stefan Heimes <stefan_heimes@hotmail.com>
7: * @author Tristan Lins <tristan.lins@bit3.de>
8: * @copyright The MetaModels team.
9: * @license LGPL.
10: * @filesource
11: */
12:
13: namespace DcGeneral\Data;
14:
15: /**
16: * Class DefaultConfig.
17: *
18: * This class is the default implementation of the ConfigInterface.
19: *
20: * @package DcGeneral\Data
21: */
22: class DefaultConfig implements ConfigInterface
23: {
24: /**
25: * The id of the element to be retrieved.
26: *
27: * @var mixed
28: */
29: protected $mixId = null;
30:
31: /**
32: * The ids to be retrieved.
33: *
34: * @var array
35: */
36: protected $arrIds = array();
37:
38: /**
39: * Flag determining if only the ids shall get fetched or models.
40: *
41: * @var bool
42: *
43: * @see fetch
44: */
45: protected $blnIdOnly = false;
46:
47: /**
48: * Offset for retrieving entries.
49: *
50: * @var int
51: */
52: protected $intStart = 0;
53:
54: /**
55: * Amount of entries to be retrieved.
56: *
57: * @var int
58: */
59: protected $intAmount = 0;
60:
61: /**
62: * The filters to use.
63: *
64: * @var array|null
65: */
66: protected $arrFilter = null;
67:
68: /**
69: * The properties to use for sorting.
70: *
71: * @var array(string => string)
72: */
73: protected $arrSorting = array();
74:
75: /**
76: * The properties to retrieve.
77: *
78: * @var array|null
79: */
80: protected $arrFields = null;
81:
82: /**
83: * Miscellaneous arbitrary data stored in the config.
84: *
85: * @var array
86: *
87: * @see set
88: * @see get
89: */
90: protected $arrData = array();
91:
92: /**
93: * Create object.
94: *
95: * Private as only the data provider shall know how to instantiate.
96: */
97: private function __construct()
98: {
99: return $this;
100: }
101:
102: /**
103: * Static constructor.
104: *
105: * @todo: do we want to keep this behaviour? Third party will not know the correct class anyway.
106: *
107: * @return ConfigInterface
108: */
109: public static function init()
110: {
111: return new static();
112: }
113:
114: /**
115: * Get specific id.
116: *
117: * @return mixed
118: */
119: public function getId()
120: {
121: return $this->mixId;
122: }
123:
124: /**
125: * Set a specific id for an element to be retrieved.
126: *
127: * @param mixed $mixId The id of the element to be retrieved.
128: *
129: * @return ConfigInterface
130: */
131: public function setId($mixId)
132: {
133: $this->mixId = $mixId;
134:
135: return $this;
136: }
137:
138: /**
139: * Get list of specific ids to be retrieved.
140: *
141: * @return array
142: */
143: public function getIds()
144: {
145: return $this->arrIds;
146: }
147:
148: /**
149: * Set list of specific ids to be retrieved.
150: *
151: * @param array $arrIds The list of ids to be retrieved.
152: *
153: * @return ConfigInterface
154: */
155: public function setIds($arrIds)
156: {
157: $this->arrIds = $arrIds;
158:
159: return $this;
160: }
161:
162: /**
163: * Return flag if only ids should be returned.
164: *
165: * @return boolean
166: */
167: public function getIdOnly()
168: {
169: return $this->blnIdOnly;
170: }
171:
172: /**
173: * Set flag for return id only.
174: *
175: * @param boolean $blnIdOnly Boolean flag to determine that only Ids shall be returned when calling fetchAll().
176: *
177: * @return bool
178: */
179: public function setIdOnly($blnIdOnly)
180: {
181: $this->blnIdOnly = $blnIdOnly;
182:
183: return $this;
184: }
185:
186: /**
187: * Get the offset to start with.
188: *
189: * This is the offset to use for pagination.
190: *
191: * @return integer
192: */
193: public function getStart()
194: {
195: return $this->intStart;
196: }
197:
198: /**
199: * Set the offset to start with.
200: *
201: * This is the offset to use for pagination.
202: *
203: * @param integer $intStart Number of first element to return.
204: *
205: * @return ConfigInterface
206: */
207: public function setStart($intStart)
208: {
209: $this->intStart = $intStart;
210:
211: return $this;
212: }
213:
214: /**
215: * Get the limit for results.
216: *
217: * This is the amount of items to return for pagination.
218: *
219: * @return integer
220: */
221: public function getAmount()
222: {
223: return $this->intAmount;
224: }
225:
226: /**
227: * Set the limit for results.
228: *
229: * This is the amount of items to return for pagination.
230: *
231: * @param int $intAmount The amount to use.
232: *
233: * @return ConfigInterface
234: */
235: public function setAmount($intAmount)
236: {
237: $this->intAmount = $intAmount;
238:
239: return $this;
240: }
241:
242: /**
243: * Get the list with filter options.
244: *
245: * @return array
246: */
247: public function getFilter()
248: {
249: return $this->arrFilter;
250: }
251:
252: /**
253: * Set the list with filter options.
254: *
255: * @param array $arrFilter The array containing the filter values.
256: *
257: * @return ConfigInterface
258: */
259: public function setFilter($arrFilter)
260: {
261: $this->arrFilter = $arrFilter;
262:
263: return $this;
264: }
265:
266: /**
267: * Get the list of all defined sortings.
268: *
269: * The returning array will be of 'property name' => 'ASC|DESC' nature.
270: *
271: * @return array
272: */
273: public function getSorting()
274: {
275: return $this->arrSorting;
276: }
277:
278: /**
279: * Set the list of all defined sortings.
280: *
281: * The array must be of 'property name' => 'ASC|DESC' nature.
282: *
283: * @param array $arrSorting The sorting array to use.
284: *
285: * @return array
286: */
287: public function setSorting($arrSorting)
288: {
289: $this->arrSorting = $arrSorting;
290:
291: return $this;
292: }
293:
294: /**
295: * Get the list of fields to be retrieved.
296: *
297: * @return array
298: */
299: public function getFields()
300: {
301: return $this->arrFields;
302: }
303:
304: /**
305: * Set the list of fields to be retrieved.
306: *
307: * @param array $arrFields Array of property names.
308: *
309: * @return ConfigInterface
310: */
311: public function setFields($arrFields)
312: {
313: $this->arrFields = $arrFields;
314:
315: return $this;
316: }
317:
318: // TODO: make a property bag out of this.
319: /**
320: * Get the additional information.
321: *
322: * @param string $strKey The name of the information to retrieve.
323: *
324: * @return mixed || null
325: */
326: public function get($strKey)
327: {
328: if (isset($this->arrData[$strKey]))
329: {
330: return $this->arrData[$strKey];
331: }
332:
333: return null;
334: }
335:
336: /**
337: * Set the additional information.
338: *
339: * @param string $strKey The name of the information to retrieve.
340: *
341: * @param mixed $varValue The value to store.
342: *
343: * @return ConfigInterface
344: */
345: public function set($strKey, $varValue)
346: {
347: $this->arrData[$strKey] = $varValue;
348:
349: return $this;
350: }
351: }
352: