NodeListStrategy.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  */
12 
17 
18 /**
19  * NodeListStrategy implements a list of entities that is retrieved
20  * from the store, where the keys are the object ids and the
21  * values are the display values.
22  *
23  * Configuration examples:
24  * @code
25  * // list all authors
26  * {"type":"node","types":["Author"]}
27  *
28  * // list all authors and books
29  * {"type":"node","types":["Author","Book"]}
30  *
31  * // list all authors with name starting with A (see StringQuery)
32  * {"type":"node","types":["Author"],"query":"Author.name LIKE 'A%'"}
33  * @endcode
34  *
35  * @author ingo herwig <ingo@wemove.com>
36  */
37 class NodeListStrategy implements ListStrategy {
38 
39  /**
40  * @see ListStrategy::getList
41  * $options is an associative array with keys 'types' and 'query' (optional)
42  */
43  public function getList($options, $language=null) {
44  if (!isset($options['types'])) {
45  throw new ConfigurationException("No 'types' given in list options: "+$options);
46  }
47  $types = $options['types'];
48 
49  $isSingleType = sizeof($types) == 1;
50 
51  $list = array();
52  foreach ($types as $type) {
53  $query = new StringQuery($type);
54  if (isset($options['query'])) {
55  $query->setConditionString($options['query']);
56  }
57  $objects = $query->execute(BuildDepth::SINGLE);
58  foreach ($objects as $object) {
59  $id = $isSingleType ? $object->getOID()->getFirstId() : $object->getOID()->__toString();
60  $list[$id] = $object->getDisplayValue();
61  }
62  }
63 
64  return $list;
65  }
66 
67  /**
68  * @see ListStrategy::isStatic
69  */
70  public function isStatic($options) {
71  return false;
72  }
73 }
74 ?>
StringQuery executes queries from a string representation.
Definition: StringQuery.php:40
NodeListStrategy implements a list of entities that is retrieved from the store, where the keys are t...
ListStrategy defines the interface for classes that retrieve value lists.
ConfigurationException signals an exception in the configuration.