1: <?php
2:
3: /**
4: * This file contains the group member collection and item class.
5: *
6: * @package Core
7: * @subpackage GenericDB_Model
8: * @author Dominik Ziegler
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: * Group member collection
19: *
20: * @package Core
21: * @subpackage GenericDB_Model
22: */
23: class cApiGroupMemberCollection 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']['groupmembers'], 'idgroupuser');
32: $this->_setItemClass('cApiGroupMember');
33:
34: // set the join partners so that joins can be used via link() method
35: $this->_setJoinPartner('cApiGroupCollection');
36: $this->_setJoinPartner('cApiUserCollection');
37: }
38:
39: /**
40: * Creates a group member entry.
41: *
42: * @param string $userId
43: * @param string $groupId
44: *
45: * @return cApiGroupMember
46: * @throws cDbException
47: * @throws cException
48: * @throws cInvalidArgumentException
49: */
50: public function create($userId, $groupId) {
51: $oItem = $this->createNewItem();
52:
53: $oItem->set('user_id', $userId);
54: $oItem->set('group_id', $groupId);
55:
56: $oItem->store();
57:
58: return $oItem;
59: }
60:
61: /**
62: * Deletes group member entries by user id.
63: *
64: * @param string $userId
65: *
66: * @return bool
67: *
68: * @throws cDbException
69: * @throws cInvalidArgumentException
70: */
71: public function deleteByUserId($userId) {
72: $result = $this->deleteBy('user_id', $userId);
73: return ($result > 0) ? true : false;
74: }
75:
76: /**
77: * Fetches entry from table by user id and group id
78: *
79: * @param string $userId
80: * @param string $groupId
81: *
82: * @return cApiGroupMember|NULL
83: *
84: * @throws cDbException
85: * @throws cException
86: */
87: public function fetchByUserIdAndGroupId($userId, $groupId) {
88: $where = "user_id = '" . $this->escape($userId) . "' AND group_id = '" . $this->escape($groupId) . "'";
89: if ($this->select($where)) {
90: return $this->next();
91: } else {
92: return NULL;
93: }
94: }
95:
96: }
97:
98: /**
99: * Group member item
100: *
101: * @package Core
102: * @subpackage GenericDB_Model
103: */
104: class cApiGroupMember extends Item
105: {
106: /**
107: * Constructor to create an instance of this class.
108: *
109: * @param mixed $mId [optional]
110: * Specifies the ID of item to load
111: *
112: * @throws cDbException
113: * @throws cException
114: */
115: public function __construct($mId = false) {
116: global $cfg;
117: parent::__construct($cfg['tab']['groupmembers'], 'idgroupuser');
118: $this->setFilters(array(), array());
119: if ($mId !== false) {
120: $this->loadByPrimaryKey($mId);
121: }
122: }
123:
124: }
125: