wCMF  3.6
 All Classes Namespaces Files Functions Variables Groups Pages
ListboxFunctions.php
Go to the documentation of this file.
1 <?php
2 /**
3  * wCMF - wemove Content Management Framework
4  * Copyright (C) 2005-2014 wemove digital solutions GmbH
5  *
6  * Licensed under the terms of any of the following licenses
7  * at your choice:
8  *
9  * - GNU Lesser General Public License (LGPL)
10  * http://www.gnu.org/licenses/lgpl.html
11  * - Eclipse Public License (EPL)
12  * http://www.eclipse.org/org/documents/epl-v10.php
13  *
14  * See the license.txt file distributed with this work for
15  * additional information.
16  *
17  * $Id: ListboxFunctions.php 1462 2014-02-04 23:52:27Z iherwig $
18  */
19 require_once("base_dir.php");
20 
21 require_once(BASE."wcmf/lib/core/class.WCMFException.php");
22 require_once(BASE."wcmf/lib/util/class.FileUtil.php");
23 require_once(BASE."wcmf/lib/presentation/class.WCMFInifileParser.php");
24 require_once(BASE."wcmf/lib/persistence/class.PersistenceFacade.php");
25 require_once(BASE."wcmf/lib/i18n/class.Localization.php");
26 
27 /**
28  * Global function for id (oid) retrieval. For parameters see PersistenceFacade::getOIDs().
29  * If the type is a Node the display value for an oid is defined by the 'display_value' property of the corresponding type.
30  * If not given the oid is displayed.
31  * @param type The type to retrieve the ids (oids) for
32  * @param queryStr A query to be used with StringQuery [default: null]
33  * @param orderbyStr String with comma separated list of attributes to use for sorting e.g. 'Author.name ASC, Author.created DESC' [default: null]
34  * @param realOIDs True/False indicates wether to fetch ids (false) or oids (true) [default: false]
35  * @param language A language code if the returned data should be localized, optional [default: null]
36  * @return An assoziative array with the database ids (or object ids depending on the last parameter) as keys and the display values as values
37  * @note This function is especially useful as fkt parameter for list input type see FormUtil::getInputControl()
38  */
39 function g_getOIDs($type, $queryStr=null, $orderbyStr=null, $realOIDs=false, $language=null)
40 {
42  WCMFException::throwEx("Illegal type given: ".$type, __FILE__, __LINE__);
43 
44  $persistenceFacade = &PersistenceFacade::getInstance();
45  $localization = &Localization::getInstance();
46 
47  // see if the type has a display value defined (via the 'display_value' property)
48  $hasDisplayValue = false;
49  $template = &$persistenceFacade->create($type, BUILDDEPTH_SINGLE);
50  if (is_a($template, 'node') && $template->getProperty('display_value') != '')
51  $hasDisplayValue = true;
52 
53  // create the array
54  $result = array();
55 
56  // create the null entry
57  if ($realOIDs)
58  $result[PersistenceFacade::composeOID(array('type' => $type, 'id' => array('')))] = "";
59  else
60  $result[""] = "";
61 
62  // create the real entries
63  $orderby = null;
64  if ($orderbyStr != null)
65  $orderby = split(',', $orderbyStr);
66 
68  $pagingInfo = new PagingInfo();
69  $nodes = $query->execute($type, $queryStr, BUILDDEPTH_SINGLE, $orderby, $pagingInfo);
70  for($i=0; $i<sizeof($nodes); $i++)
71  {
72  $oid = $nodes[$i]->getOID();
73  if ($realOIDs)
74  $key = $oid;
75  else
76  $key = join(':', PersistenceFacade::getOIDParameter($oid, 'id'));
77 
78  // translate the node if requested
79  if ($language != null) {
80  $localization->loadTranslation($nodes[$i], $language, true, true);
81  }
82 
83  $displayValue = $oid;
84  if ($hasDisplayValue)
85  $displayValue = $nodes[$i]->getDisplayValue();
86  $result[$key] = $displayValue;
87  }
88  return $result;
89 }
90 
91 /**
92  * Global function that retrieves all oids of a given type that may be assoziated
93  * with a given parent (except for those that are already assoziated).
94  * This method is used to fill listboxes in the assoziated view.
95  * @return An associative array of object ids (key: oid, value: display value)
96  */
97 function g_getObjects($type, $parentOID)
98 {
99  $persistenceFacade = &PersistenceFacade::getInstance();
100  $result = array();
101  if (!PersistenceFacade::isValidOID($parentOID))
102  WCMFException::throwEx("Illegal parent oid given: ".$parentOID, __FILE__, __LINE__);
103  if (!PersistenceFacade::isKnownType($type))
104  WCMFException::throwEx("Illegal type given: ".$type, __FILE__, __LINE__);
105 
106  // collect children from parent
107  $parent = &$persistenceFacade->load($parentOID, 1);
108  $children = $parent->getChildrenEx(null, $type, null, null);
109  $childOIDs = array();
110  foreach($children as $child)
111  $childOIDs[sizeof($childOIDs)] = $child->getOID();
112 
113  // collect all possible objects
114  $query = &PersistenceFacade::createObjectQuery($type);
115  $nodes = $query->execute(BUILDDEPTH_SINGLE);
116  $oids = $persistenceFacade->getOIDs($type);
117  for($i=0; $i<sizeof($nodes); $i++)
118  {
119  $node = &$nodes[$i];
120  $oid = $node->getOID();
121  if (!in_array($oid, $childOIDs))
122  {
123  $result[$oid] = $node->getObjectDisplayName().": ".$node->getDisplayValue();
124  }
125  }
126  return $result;
127 }
128 
129 /**
130  * Global function that retrieves all entity types.
131  * This method is used to fill listboxes in the assoziated view.
132  * @return An associative array of type names (key: type, value: dispaly name)
133  */
134 function g_getTypes()
135 {
136  $persistenceFacade = &PersistenceFacade::getInstance();
138  foreach($types as $type)
139  {
140  $node = &$persistenceFacade->create($type, BUILDDEPTH_SINGLE);
141  $result[$type] = $node->getObjectDisplayName();
142  }
143  asort($result);
144  return $result;
145 }
146 
147 /**
148  * Global function that makes an associate array from oids given as '|' separated string.
149  * This method is used to fill listboxes in the assoziated view.
150  * @return An associative array of object ids (key: oid, value: display value)
151  */
152 $g_oidArray = array();
153 function g_getOIDArray($oidStringList)
154 {
155  global $g_oidArray;
156  if (!isset($g_oidArray[$oidStringList]))
157  {
158  $persistenceFacade = &PersistenceFacade::getInstance();
159  $result = array();
160  if (strpos($oidStringList, '|') === false)
161  $oids = array($oidStringList);
162  else
163  $oids = split('\|', $oidStringList);
164  foreach($oids as $oid)
165  {
167  {
168  $node = &$persistenceFacade->load($oid, BUILDDEPTH_SINGLE);
169  $result[$node->getOID()] = DisplayController::getDisplayText($node);
170  }
171  else
172  $result[$oid] = $oid;
173  }
174  $g_oidArray[$oidStringList] = $result;
175  }
176  return $g_oidArray[$oidStringList];
177 }
178 
179 /**
180  * Global function that retrieves all config files.
181  * This method is used to fill listboxes in the assoziated view.
182  * @return An associative array of config file names (key: filename, value: filename)
183  */
185 {
186  $result = array();
187  $configFiles = WCMFInifileParser::getIniFiles();
188  foreach ($configFiles as $file)
189  {
190  $file = basename($file);
191  $result[$file] = $file;
192  }
193  $result[''] = '';
194  return $result;
195 }
196 
197 /**
198  * Global function for backup name retrieval.
199  * @return An array of backup names
200  */
202 {
203  $result = array();
204 
205  $parser = &InifileParser::getInstance();
206  if (($backupDir = $parser->getValue('backupDir', 'cms')) === false)
207  WCMFException::throwEx($parser->getErrorMsg(), __FILE__, __LINE__);
208 
209  $fileUtil = new FileUtil();
210  $folders = $fileUtil->getFiles($backupDir, '/./');
211  foreach($folders as $folder)
212  $result[$folder] = $folder;
213  $result[""] = "";
214  return $result;
215 }
216 ?>
g_getObjects($type, $parentOID)
throwEx($message, $file='', $line='')
g_getConfigFiles()
g_getBackupNames()
getOIDParameter($oid, $param, $validate=true)
g_getOIDs($type, $queryStr=null, $orderbyStr=null, $realOIDs=false, $language=null)
PagingInfo contains information about a paged list.
g_getOIDArray($oidStringList)
FileUtil provides basic support for file functionality like HTTP file upload.
const BUILDDEPTH_SINGLE
g_getTypes()