1: <?php
2:
3: /**
4: * This file contains the frontend group collection and item class.
5: *
6: * @package Core
7: * @subpackage GenericDB_Model
8: * @author Murat Purc <murat@purc.de>
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: * Frontend group collection
19: *
20: * @package Core
21: * @subpackage GenericDB_Model
22: */
23: class cApiFrontendGroupCollection extends ItemCollection {
24:
25: /**
26: * Constructor Function
27: */
28: public function __construct() {
29: global $cfg;
30: parent::__construct($cfg['tab']['frontendgroups'], 'idfrontendgroup');
31: $this->_setItemClass('cApiFrontendGroup');
32:
33: // set the join partners so that joins can be used via link() method
34: $this->_setJoinPartner('cApiClientCollection');
35: }
36:
37: /**
38: * Creates a new group
39: *
40: * @param string $groupname
41: * Specifies the groupname
42: * @return cApiFrontendGroup
43: */
44: public function create($groupname) {
45: global $client;
46:
47: $group = new cApiFrontendGroup();
48:
49: // _arrInFilters = array('urlencode', 'htmlspecialchars', 'addslashes');
50:
51: $mangledGroupName = $group->_inFilter($groupname);
52: $this->select("idclient = " . cSecurity::toInteger($client) . " AND groupname = '" . $mangledGroupName . "'");
53:
54: if (($obj = $this->next()) !== false) {
55: $groupname = $groupname . md5(rand());
56: }
57:
58: $item = $this->createNewItem();
59: $item->set('idclient', $client);
60: $item->set('groupname', $groupname);
61: $item->store();
62:
63: return $item;
64: }
65:
66: /**
67: * Overridden delete method to remove groups from groupmember table
68: * before deleting group
69: *
70: * @todo should return return value of overloaded method
71: * @param int $itemID
72: * specifies the frontend user group
73: */
74: public function delete($itemID) {
75: $associations = new cApiFrontendGroupMemberCollection();
76: $associations->select('idfrontendgroup = ' . (int) $itemID);
77:
78: while (($item = $associations->next()) !== false) {
79: $associations->delete($item->get('idfrontendgroupmember'));
80: }
81: parent::delete($itemID);
82: }
83: }
84:
85: /**
86: * Frontend group item
87: *
88: * @package Core
89: * @subpackage GenericDB_Model
90: */
91: class cApiFrontendGroup extends Item {
92:
93: /**
94: * Constructor Function
95: *
96: * @param mixed $mId [optional]
97: * Specifies the ID of item to load
98: */
99: public function __construct($mId = false) {
100: global $cfg;
101: parent::__construct($cfg['tab']['frontendgroups'], 'idfrontendgroup');
102: if ($mId !== false) {
103: $this->loadByPrimaryKey($mId);
104: }
105: }
106: }
107: