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: * Constructor to create an instance of this class.
26: *
27: * @param bool $select [optional]
28: * where clause to use for selection (see ItemCollection::select())
29: *
30: * @throws cDbException
31: * @throws cInvalidArgumentException
32: */
33: public function __construct($select = false) {
34: global $cfg;
35: parent::__construct($cfg['tab']['container_conf'], 'idcontainerc');
36: $this->_setItemClass('cApiContainerConfiguration');
37:
38: // set the join partners so that joins can be used via link() method
39: $this->_setJoinPartner('cApiTemplateConfigurationCollection');
40:
41: if ($select !== false) {
42: $this->select($select);
43: }
44: }
45:
46: /**
47: * Creates a container configuration item
48: *
49: * @param int $idtplcfg
50: * @param int $number
51: * @param string $container
52: *
53: * @return cApiContainerConfiguration
54: * @throws cDbException
55: * @throws cException
56: * @throws cInvalidArgumentException
57: */
58: public function create($idtplcfg, $number, $container) {
59: $item = $this->createNewItem();
60:
61: $item->set('idtplcfg', $idtplcfg);
62: $item->set('number', $number);
63: $item->set('container', $container);
64: $item->store();
65:
66: return $item;
67: }
68:
69: /**
70: * Returns list of all configured container by template configuration id
71: *
72: * @param int $idtplcfg
73: * Template configuration id
74: * @return array
75: * Assoziative array where the key is the number and value the
76: * container configuration.
77: * @throws cDbException
78: * @throws cException
79: */
80: public function getByTemplateConfiguration($idtplcfg) {
81: $configuration = array();
82:
83: $this->select('idtplcfg = ' . (int) $idtplcfg, '', 'number ASC');
84: while (($item = $this->next()) !== false) {
85: $configuration[(int) $item->get('number')] = $item->get('container');
86: }
87:
88: return $configuration;
89: }
90: }
91:
92: /**
93: * Container configuration item
94: *
95: * @package Core
96: * @subpackage GenericDB_Model
97: */
98: class cApiContainerConfiguration extends Item
99: {
100: /**
101: * Constructor to create an instance of this class.
102: *
103: * @param mixed $mId [optional]
104: * Specifies the ID of item to load
105: *
106: * @throws cDbException
107: * @throws cException
108: */
109: public function __construct($mId = false) {
110: global $cfg;
111: parent::__construct($cfg['tab']['container_conf'], 'idcontainerc');
112: $this->setFilters(array(), array());
113: if ($mId !== false) {
114: $this->loadByPrimaryKey($mId);
115: }
116: }
117:
118: /**
119: * Userdefined setter for container config fields.
120: *
121: * @param string $name
122: * @param mixed $value
123: * @param bool $bSafe [optional]
124: * Flag to run defined inFilter on passed value
125: *
126: * @return bool
127: */
128: public function setField($name, $value, $bSafe = true) {
129: switch ($name) {
130: case 'idtplcfg':
131: case 'number':
132: $value = cSecurity::toInteger($value);
133: break;
134: }
135:
136: return parent::setField($name, $value, $bSafe);
137: }
138:
139: /**
140: * Adds a key value pair to passed container string and returns the modified
141: * container string
142: *
143: * @param string $container
144: * @param string $key
145: * @param string $value
146: * @return string
147: */
148: public static function addContainerValue($container, $key, $value) {
149: $container .= $key . '=' . urlencode(stripslashes($value)) . '&';
150: return $container;
151: }
152:
153: /**
154: * Parses the container value to its variables
155: *
156: * @param string $value
157: * @return array
158: */
159: public static function parseContainerValue($value) {
160: $vars = array();
161:
162: $value = preg_replace('/&$/', '', $value);
163: $parts = preg_split('/&/', $value);
164: foreach ($parts as $key1 => $value1) {
165: $param = explode('=', $value1);
166: foreach ($param as $key2 => $value2) {
167: $vars[$param[0]] = urldecode($param[1]);
168: }
169: }
170:
171: return $vars;
172: }
173:
174: }
175: