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