ValueListController.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 
15 
16 /**
17  * ValueListController is used to resolve lists for _input_type_ definitions.
18  *
19  * The controller supports the following actions:
20  *
21  * <div class="controller-action">
22  * <div> __Action__ _default_ </div>
23  * <div>
24  * List key/values.
25  * | Parameter | Description
26  * |------------------------|-------------------------
27  * | _in_ `listDef` | The list definition (expected to be base64 encoded)
28  * | _in_ `displayFilter` | A regular expression that the returned 'value' values should match (optional)
29  * | _out_ `list` | Array of associative arrays with keys 'oid', 'displayText'
30  * | _out_ `static` | Boolean indicating whether returned data are static or not
31  * | __Response Actions__ | |
32  * | `ok` | In all cases
33  * </div>
34  * </div>
35  *
36  * @author ingo herwig <ingo@wemove.com>
37  */
39 
40  /**
41  * @see Controller::validate()
42  */
43  protected function validate() {
44  $request = $this->getRequest();
45  $response = $this->getResponse();
46  if(!$request->hasValue('listDef')) {
47  $response->addError(ApplicationError::get('PARAMETER_INVALID',
48  array('invalidParameters' => array('listDef'))));
49  return false;
50  }
51  if (!$this->checkLanguageParameter()) {
52  return false;
53  }
54  // do default validation
55  return parent::validate();
56  }
57 
58  /**
59  * @see Controller::doExecute()
60  */
61  protected function doExecute() {
62  $request = $this->getRequest();
63  $response = $this->getResponse();
64 
65  $listDef = base64_decode($request->getValue('listDef'));
66  $language = $request->getValue('language');
67 
68  $list = ValueListProvider::getList($listDef, $language);
69  $items = array();
70  foreach($list['items'] as $id => $name) {
71  $items[] = array('oid' => $id, 'displayText' => $name);
72  }
73 
74  $response->setValue('list', $items);
75  $response->setValue('static', $list['isStatic']);
76 
77  // success
78  $response->setAction('ok');
79  }
80 }
81 ?>
getRequest()
Get the Request instance.
Definition: Controller.php:190
Controller is the base class of all controllers.
Definition: Controller.php:48
ValueListController is used to resolve lists for input_type definitions.
checkLanguageParameter()
Checks the language request parameter and adds an response error, if it is not contained in the Local...
Definition: Controller.php:315
Application controllers.
Definition: namespaces.php:3
static get($code, $data=null)
Factory method for retrieving a predefind error instance.
getResponse()
Get the Response instance.
Definition: Controller.php:198
static getList($definition, $language=null)
Get a list of key/value pairs defined by the given configuration.