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: * Constructor to create an instance of this class.
26: *
27: * @throws cInvalidArgumentException
28: */
29: public function __construct() {
30: global $cfg;
31: parent::__construct($cfg['tab']['frontendgroups'], 'idfrontendgroup');
32: $this->_setItemClass('cApiFrontendGroup');
33:
34: // set the join partners so that joins can be used via link() method
35: $this->_setJoinPartner('cApiClientCollection');
36: }
37:
38: /**
39: * Creates a new group
40: *
41: * @param string $groupname
42: * Specifies the groupname
43: *
44: * @return cApiFrontendGroup
45: * @throws cDbException
46: * @throws cException
47: * @throws cInvalidArgumentException
48: */
49: public function create($groupname) {
50: global $client;
51:
52: $group = new cApiFrontendGroup();
53:
54: // _arrInFilters = array('urlencode', 'htmlspecialchars', 'addslashes');
55:
56: $mangledGroupName = $group->_inFilter($groupname);
57: $this->select("idclient = " . cSecurity::toInteger($client) . " AND groupname = '" . $mangledGroupName . "'");
58:
59: if (($obj = $this->next()) !== false) {
60: $groupname = $groupname . md5(rand());
61: }
62:
63: $item = $this->createNewItem();
64: $item->set('idclient', $client);
65: $item->set('groupname', $groupname);
66: $item->store();
67:
68: return $item;
69: }
70:
71: /**
72: * Overridden delete method to remove groups from groupmember table
73: * before deleting group
74: *
75: * @param int $itemID
76: * specifies the frontend user group
77: *
78: * @return bool
79: *
80: * @throws cDbException
81: * @throws cException
82: * @throws cInvalidArgumentException
83: */
84: public function delete($itemID) {
85: $associations = new cApiFrontendGroupMemberCollection();
86: $associations->select('idfrontendgroup = ' . (int) $itemID);
87:
88: while (($item = $associations->next()) !== false) {
89: $associations->delete($item->get('idfrontendgroupmember'));
90: }
91:
92: return parent::delete($itemID);
93: }
94: }
95:
96: /**
97: * Frontend group item
98: *
99: * @package Core
100: * @subpackage GenericDB_Model
101: */
102: class cApiFrontendGroup extends Item
103: {
104: /**
105: * Constructor to create an instance of this class.
106: *
107: * @param mixed $mId [optional]
108: * Specifies the ID of item to load
109: *
110: * @throws cDbException
111: * @throws cException
112: */
113: public function __construct($mId = false) {
114: global $cfg;
115: parent::__construct($cfg['tab']['frontendgroups'], 'idfrontendgroup');
116: if ($mId !== false) {
117: $this->loadByPrimaryKey($mId);
118: }
119: }
120: }
121: