1: <?php
2:
3: /**
4: * This file contains the frontend group memeber 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 member collection
19: *
20: * @package Core
21: * @subpackage GenericDB_Model
22: */
23: class cApiFrontendGroupMemberCollection 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']['frontendgroupmembers'], 'idfrontendgroupmember');
32: $this->_setItemClass('cApiFrontendGroupMember');
33:
34: // set the join partners so that joins can be used via link() method
35: $this->_setJoinPartner('cApiFrontendGroupCollection');
36: $this->_setJoinPartner('cApiFrontendUserCollection');
37: }
38:
39: /**
40: * Creates a new association
41: *
42: * @todo Should return null in case of failure
43: *
44: * @param int $idfrontendgroup
45: * specifies the frontend group
46: * @param int $idfrontenduser
47: * specifies the frontend user
48: *
49: * @return cApiFrontendGroupMember|false
50: * @throws cDbException
51: * @throws cException
52: * @throws cInvalidArgumentException
53: */
54: public function create($idfrontendgroup, $idfrontenduser) {
55: $this->select('idfrontendgroup = ' . (int) $idfrontendgroup . ' AND idfrontenduser = ' . (int) $idfrontenduser);
56:
57: if ($this->next()) {
58: return false;
59: }
60:
61: $item = $this->createNewItem();
62:
63: $item->set('idfrontenduser', $idfrontenduser);
64: $item->set('idfrontendgroup', $idfrontendgroup);
65: $item->store();
66:
67: return $item;
68: }
69:
70: /**
71: * Removes an association
72: *
73: * @param int $idfrontendgroup
74: * Specifies the frontend group
75: * @param int $idfrontenduser
76: * Specifies the frontend user
77: *
78: * @throws cDbException
79: * @throws cException
80: * @throws cInvalidArgumentException
81: */
82: public function remove($idfrontendgroup, $idfrontenduser) {
83: $this->select('idfrontendgroup = ' . (int) $idfrontendgroup . ' AND idfrontenduser = ' . (int) $idfrontenduser);
84:
85: if (($item = $this->next()) !== false) {
86: $this->delete($item->get('idfrontendgroupmember'));
87: }
88: }
89:
90: /**
91: * Returns all users in a single group
92: *
93: * @param int $idfrontendgroup
94: * specifies the frontend group
95: * @param bool $asObjects [optional]
96: * Specifies if the function should return objects
97: * @return array
98: * List of frontend user ids or cApiFrontendUser items
99: *
100: * @throws cDbException
101: * @throws cException
102: */
103: public function getUsersInGroup($idfrontendgroup, $asObjects = true) {
104: $this->select('idfrontendgroup = ' . (int) $idfrontendgroup);
105:
106: $objects = array();
107:
108: while (($item = $this->next()) !== false) {
109: if ($asObjects) {
110: $user = new cApiFrontendUser();
111: $user->loadByPrimaryKey($item->get('idfrontenduser'));
112: $objects[] = $user;
113: } else {
114: $objects[] = $item->get('idfrontenduser');
115: }
116: }
117:
118: return $objects;
119: }
120: }
121:
122: /**
123: * Frontend group member item
124: *
125: * @package Core
126: * @subpackage GenericDB_Model
127: */
128: class cApiFrontendGroupMember extends Item
129: {
130: /**
131: * Constructor to create an instance of this class.
132: *
133: * @param mixed $mId [optional]
134: * Specifies the ID of item to load
135: *
136: * @throws cDbException
137: * @throws cException
138: */
139: public function __construct($mId = false) {
140: global $cfg;
141: parent::__construct($cfg['tab']['frontendgroupmembers'], 'idfrontendgroupmember');
142: if ($mId !== false) {
143: $this->loadByPrimaryKey($mId);
144: }
145: }
146: }
147: