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