1: <?php
2: /**
3: * This file contains the group member collection and item class.
4: *
5: * @package Core
6: * @subpackage GenericDB_Model
7: * @version SVN Revision $Rev:$
8: *
9: * @author Dominik Ziegler
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: * Group member collection
20: *
21: * @package Core
22: * @subpackage GenericDB_Model
23: */
24: class cApiGroupMemberCollection extends ItemCollection {
25:
26: /**
27: * Constructor
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: * @return cApiGroupMember
45: */
46: public function create($userId, $groupId) {
47: $oItem = parent::createNewItem();
48:
49: $oItem->set('user_id', $this->escape($userId));
50: $oItem->set('group_id', $this->escape($groupId));
51:
52: $oItem->store();
53:
54: return $oItem;
55: }
56:
57: /**
58: * Deletes group member entries by user id.
59: *
60: * @param string $userId
61: * @return bool
62: */
63: public function deleteByUserId($userId) {
64: $result = $this->deleteBy('user_id', $userId);
65: return ($result > 0) ? true : false;
66: }
67:
68: /**
69: * Fetches entry from table by user id and group id
70: *
71: * @param string $userId
72: * @param string $groupId
73: * @return cApiGroupMember NULL
74: */
75: public function fetchByUserIdAndGroupId($userId, $groupId) {
76: $where = "user_id = '" . $this->escape($userId) . "' AND group_id = '" . $this->escape($groupId) . "'";
77: if ($this->select($where)) {
78: return $this->next();
79: } else {
80: return NULL;
81: }
82: }
83:
84: }
85:
86: /**
87: * Group member item
88: *
89: * @package Core
90: * @subpackage GenericDB_Model
91: */
92: class cApiGroupMember extends Item {
93:
94: /**
95: * Constructor Function
96: *
97: * @param mixed $mId Specifies the ID of item to load
98: */
99: public function __construct($mId = false) {
100: global $cfg;
101: parent::__construct($cfg['tab']['groupmembers'], 'idgroupuser');
102: $this->setFilters(array(), array());
103: if ($mId !== false) {
104: $this->loadByPrimaryKey($mId);
105: }
106: }
107:
108: }
109: