1: <?php
2: /**
3: * This file contains the frontend group collection and item class.
4: *
5: * @package Core
6: * @subpackage GenericDB_Model
7: * @version SVN Revision $Rev:$
8: *
9: * @author Murat Purc <murat@purc.de>
10: * @copyright four for business AG <www.4fb.de>
11: * @license http://www.contenido.org/license/LIZENZ.txt
12: * @link http://www.4fb.de
13: * @link http://www.contenido.org
14: */
15:
16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
17:
18: /**
19: * Frontend group collection
20: *
21: * @package Core
22: * @subpackage GenericDB_Model
23: */
24: class cApiFrontendGroupCollection extends ItemCollection {
25:
26: /**
27: * Constructor Function
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 $groupname string Specifies the groupname
42: * @param $password string Specifies the password (optional)
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 = " . (int) $client . " AND groupname = '" . $mangledGroupName . "'");
53:
54: if (($obj = $this->next()) !== false) {
55: $groupname = $groupname . md5(rand());
56: }
57:
58: $item = parent::createNewItem();
59:
60: $item->set('idclient', $client);
61: $item->set('groupname', $groupname);
62: $item->store();
63:
64: return $item;
65: }
66:
67: /**
68: * Overridden delete method to remove groups from groupmember table
69: * before deleting group
70: *
71: * @param $itemID int specifies the frontend user group
72: */
73: public function delete($itemID) {
74: $associations = new cApiFrontendGroupMemberCollection();
75: $associations->select('idfrontendgroup = ' . (int) $itemID);
76:
77: while (($item = $associations->next()) !== false) {
78: $associations->delete($item->get('idfrontendgroupmember'));
79: }
80: parent::delete($itemID);
81: }
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 Specifies the ID of item to load
97: */
98: public function __construct($mId = false) {
99: global $cfg;
100: parent::__construct($cfg['tab']['frontendgroups'], 'idfrontendgroup');
101: if ($mId !== false) {
102: $this->loadByPrimaryKey($mId);
103: }
104: }
105:
106: }
107: