1: <?php
2:
3: /**
4: * This file contains the container configuration collection and item class.
5: *
6: * @package Core
7: * @subpackage GenericDB_Model
8: * @author Timo Hummel
9: * @copyright four for business AG <www.4fb.de>
10: * @license http://www.contenido.org/license/LIZENZ.txt
11: * @link http://www.4fb.de
12: * @link http://www.contenido.org
13: */
14:
15: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
16:
17: /**
18: * Container configuration collection
19: *
20: * @package Core
21: * @subpackage GenericDB_Model
22: */
23: class cApiContainerConfigurationCollection extends ItemCollection {
24:
25: /**
26: * Create a new collection of items.
27: *
28: * @param string $select [optional]
29: * where clause to use for selection (see ItemCollection::select())
30: */
31: public function __construct($select = false) {
32: global $cfg;
33: parent::__construct($cfg['tab']['container_conf'], 'idcontainerc');
34: $this->_setItemClass('cApiContainerConfiguration');
35:
36: // set the join partners so that joins can be used via link() method
37: $this->_setJoinPartner('cApiTemplateConfigurationCollection');
38:
39: if ($select !== false) {
40: $this->select($select);
41: }
42: }
43:
44: /**
45: * Creates a container configuration item
46: * @param int $idtplcfg
47: * @param int $number
48: * @param string $container
49: * @return cApiContainerConfiguration
50: */
51: public function create($idtplcfg, $number, $container) {
52: $item = $this->createNewItem();
53:
54: $item->set('idtplcfg', $idtplcfg);
55: $item->set('number', $number);
56: $item->set('container', $container);
57: $item->store();
58:
59: return $item;
60: }
61:
62: /**
63: * Returns list of all configured container by template configuration id
64: *
65: * @param int $idtplcfg
66: * Template configuration id
67: * @return array
68: * Assoziative array where the key is the number and value the
69: * container configuration.
70: */
71: public function getByTemplateConfiguration($idtplcfg) {
72: $configuration = array();
73:
74: $this->select('idtplcfg = ' . (int) $idtplcfg, '', 'number ASC');
75: while (($item = $this->next()) !== false) {
76: $configuration[(int) $item->get('number')] = $item->get('container');
77: }
78:
79: return $configuration;
80: }
81: }
82:
83: /**
84: * Container configuration item
85: *
86: * @package Core
87: * @subpackage GenericDB_Model
88: */
89: class cApiContainerConfiguration extends Item {
90:
91: /**
92: * Constructor Function
93: *
94: * @param mixed $mId [optional]
95: * Specifies the ID of item to load
96: */
97: public function __construct($mId = false) {
98: global $cfg;
99: parent::__construct($cfg['tab']['container_conf'], 'idcontainerc');
100: $this->setFilters(array(), array());
101: if ($mId !== false) {
102: $this->loadByPrimaryKey($mId);
103: }
104: }
105:
106: /**
107: * Userdefined setter for container config fields.
108: *
109: * @todo should return return value of overloaded method
110: * @param string $name
111: * @param mixed $value
112: * @param bool $bSafe [optional]
113: * Flag to run defined inFilter on passed value
114: */
115: public function setField($name, $value, $bSafe = true) {
116: switch ($name) {
117: case 'idtplcfg':
118: case 'number':
119: $value = cSecurity::toInteger($value);
120: break;
121: }
122:
123: parent::setField($name, $value, $bSafe);
124: }
125:
126: /**
127: * Adds a key value pair to passed container string and returns the modified
128: * container string
129: *
130: * @param string $container
131: * @param string $key
132: * @param string $value
133: * @return string
134: */
135: public static function addContainerValue($container, $key, $value) {
136: $container .= $key . '=' . urlencode(stripslashes($value)) . '&';
137: return $container;
138: }
139:
140: /**
141: * Parses the container value to its variables
142: *
143: * @param string $value
144: * @return array
145: */
146: public static function parseContainerValue($value) {
147: $vars = array();
148:
149: $value = preg_replace('/&$/', '', $value);
150: $parts = preg_split('/&/', $value);
151: foreach ($parts as $key1 => $value1) {
152: $param = explode('=', $value1);
153: foreach ($param as $key2 => $value2) {
154: $vars[$param[0]] = urldecode($param[1]);
155: }
156: }
157:
158: return $vars;
159: }
160:
161: }
162: