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