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: /**
26: * Constructor
27: */
28: public function __construct() {
29: global $cfg;
30: parent::__construct($cfg['tab']['groupmembers'], 'idgroupuser');
31: $this->_setItemClass('cApiGroupMember');
32:
33: // set the join partners so that joins can be used via link() method
34: $this->_setJoinPartner('cApiGroupCollection');
35: $this->_setJoinPartner('cApiUserCollection');
36: }
37:
38: /**
39: * Creates a group member entry.
40: *
41: * @param string $userId
42: * @param string $groupId
43: * @return cApiGroupMember
44: */
45: public function create($userId, $groupId) {
46: $oItem = $this->createNewItem();
47:
48: $oItem->set('user_id', $userId);
49: $oItem->set('group_id', $groupId);
50:
51: $oItem->store();
52:
53: return $oItem;
54: }
55:
56: /**
57: * Deletes group member entries by user id.
58: *
59: * @param string $userId
60: * @return bool
61: */
62: public function deleteByUserId($userId) {
63: $result = $this->deleteBy('user_id', $userId);
64: return ($result > 0) ? true : false;
65: }
66:
67: /**
68: * Fetches entry from table by user id and group id
69: *
70: * @param string $userId
71: * @param string $groupId
72: * @return cApiGroupMember|NULL
73: */
74: public function fetchByUserIdAndGroupId($userId, $groupId) {
75: $where = "user_id = '" . $this->escape($userId) . "' AND group_id = '" . $this->escape($groupId) . "'";
76: if ($this->select($where)) {
77: return $this->next();
78: } else {
79: return NULL;
80: }
81: }
82:
83: }
84:
85: /**
86: * Group member item
87: *
88: * @package Core
89: * @subpackage GenericDB_Model
90: */
91: class cApiGroupMember extends Item {
92:
93: /**
94: * Constructor Function
95: *
96: * @param mixed $mId [optional]
97: * 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: