1: <?php
2: /**
3: * This file contains the frontend group memeber 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 member collection
20: *
21: * @package Core
22: * @subpackage GenericDB_Model
23: */
24: class cApiFrontendGroupMemberCollection extends ItemCollection {
25:
26: /**
27: * Constructor Function
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: * @TODO Should return null in case of failure
42: * @param int $idfrontendgroup specifies the frontend group
43: * @param int $idfrontenduser specifies the frontend user
44: * @return cApiFrontendGroupMember|bool
45: */
46: public function create($idfrontendgroup, $idfrontenduser) {
47: $this->select('idfrontendgroup = ' . (int) $idfrontendgroup . ' AND idfrontenduser = ' . (int) $idfrontenduser);
48:
49: if ($this->next()) {
50: return false;
51: }
52:
53: $item = parent::createNewItem();
54:
55: $item->set('idfrontenduser', $idfrontenduser);
56: $item->set('idfrontendgroup', $idfrontendgroup);
57: $item->store();
58:
59: return $item;
60: }
61:
62: /**
63: * Removes an association
64: *
65: * @param int $idfrontendgroup Specifies the frontend group
66: * @param int $idfrontenduser Specifies the frontend user
67: */
68: public function remove($idfrontendgroup, $idfrontenduser) {
69: $this->select('idfrontendgroup = ' . (int) $idfrontendgroup . ' AND idfrontenduser = ' . (int) $idfrontenduser);
70:
71: if (($item = $this->next()) !== false) {
72: $this->delete($item->get('idfrontendgroupmember'));
73: }
74: }
75:
76: /**
77: * Returns all users in a single group
78: *
79: * @param int $idfrontendgroup specifies the frontend group
80: * @param bool $asObjects Specifies if the function should return objects
81: * @return array List of frontend user ids or cApiFrontendUser items
82: */
83: public function getUsersInGroup($idfrontendgroup, $asObjects = true) {
84: $this->select('idfrontendgroup = ' . (int) $idfrontendgroup);
85:
86: $objects = array();
87:
88: while (($item = $this->next()) !== false) {
89: if ($asObjects) {
90: $user = new cApiFrontendUser();
91: $user->loadByPrimaryKey($item->get('idfrontenduser'));
92: $objects[] = $user;
93: } else {
94: $objects[] = $item->get('idfrontenduser');
95: }
96: }
97:
98: return ($objects);
99: }
100: }
101:
102: /**
103: * Frontend group member item
104: *
105: * @package Core
106: * @subpackage GenericDB_Model
107: */
108: class cApiFrontendGroupMember extends Item {
109:
110: /**
111: * Constructor Function
112: *
113: * @param mixed $mId Specifies the ID of item to load
114: */
115: public function __construct($mId = false) {
116: global $cfg;
117: parent::__construct($cfg['tab']['frontendgroupmembers'], 'idfrontendgroupmember');
118: if ($mId !== false) {
119: $this->loadByPrimaryKey($mId);
120: }
121: }
122: }
123: