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: * Constructor to create an instance of this class.
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 to create an instance of this class.
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: * @param string $name
110: * @param mixed $value
111: * @param bool $bSafe [optional]
112: * Flag to run defined inFilter on passed value
113: *
114: * @return bool
115: */
116: public function setField($name, $value, $bSafe = true) {
117: switch ($name) {
118: case 'idtplcfg':
119: case 'number':
120: $value = cSecurity::toInteger($value);
121: break;
122: }
123:
124: return parent::setField($name, $value, $bSafe);
125: }
126:
127: /**
128: * Adds a key value pair to passed container string and returns the modified
129: * container string
130: *
131: * @param string $container
132: * @param string $key
133: * @param string $value
134: * @return string
135: */
136: public static function addContainerValue($container, $key, $value) {
137: $container .= $key . '=' . urlencode(stripslashes($value)) . '&';
138: return $container;
139: }
140:
141: /**
142: * Parses the container value to its variables
143: *
144: * @param string $value
145: * @return array
146: */
147: public static function parseContainerValue($value) {
148: $vars = array();
149:
150: $value = preg_replace('/&$/', '', $value);
151: $parts = preg_split('/&/', $value);
152: foreach ($parts as $key1 => $value1) {
153: $param = explode('=', $value1);
154: foreach ($param as $key2 => $value2) {
155: $vars[$param[0]] = urldecode($param[1]);
156: }
157: }
158:
159: return $vars;
160: }
161:
162: }
163: