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 to create an instance of this class.
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: * @param int $itemID
71: * specifies the frontend user group
72: *
73: * @return bool
74: */
75: public function delete($itemID) {
76: $associations = new cApiFrontendGroupMemberCollection();
77: $associations->select('idfrontendgroup = ' . (int) $itemID);
78:
79: while (($item = $associations->next()) !== false) {
80: $associations->delete($item->get('idfrontendgroupmember'));
81: }
82:
83: return parent::delete($itemID);
84: }
85: }
86:
87: /**
88: * Frontend group item
89: *
90: * @package Core
91: * @subpackage GenericDB_Model
92: */
93: class cApiFrontendGroup extends Item {
94:
95: /**
96: * Constructor to create an instance of this class.
97: *
98: * @param mixed $mId [optional]
99: * Specifies the ID of item to load
100: */
101: public function __construct($mId = false) {
102: global $cfg;
103: parent::__construct($cfg['tab']['frontendgroups'], 'idfrontendgroup');
104: if ($mId !== false) {
105: $this->loadByPrimaryKey($mId);
106: }
107: }
108: }
109: