1: <?php
2:
3: /**
4: * This file contains the frontend permission collection and item class.
5: *
6: * @package Core
7: * @subpackage GenericDB_Model
8: * @author Murat Purc <murat@purc.de>
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: * Frontend permission collection
19: *
20: * @package Core
21: * @subpackage GenericDB_Model
22: */
23: class cApiFrontendPermissionCollection extends ItemCollection {
24:
25: /**
26: * instance of cApiFrontendPermission to access defined filters
27: *
28: * @var cApiFrontendPermission
29: */
30: protected $_frontendPermission;
31:
32: /**
33: * Constructor to create an instance of this class.
34: */
35: public function __construct() {
36: global $cfg;
37: $this->_frontendPermission = new cApiFrontendPermission();
38:
39: parent::__construct($cfg['tab']['frontendpermissions'], 'idfrontendpermission');
40: $this->_setItemClass('cApiFrontendPermission');
41:
42: // set the join partners so that joins can be used via link() method
43: $this->_setJoinPartner('cApiFrontendGroupCollection');
44: $this->_setJoinPartner('cApiLanguageCollection');
45: }
46:
47: /**
48: * Creates a new permission entry.
49: *
50: * @param int $group
51: * Specifies the frontend group
52: * @param string $plugin
53: * Specifies the plugin
54: * @param string $action
55: * Specifies the action
56: * @param string $item
57: * Specifies the item
58: * @return cApiFrontendPermission|false
59: */
60: public function create($group, $plugin, $action, $item) {
61: global $lang;
62:
63: $perm = false;
64: if (!$this->checkPerm($group, $plugin, $action, $item)) {
65: $perm = $this->createNewItem();
66: $perm->set('idlang', $lang);
67: $perm->set('idfrontendgroup', $group);
68: $perm->set('plugin', $plugin);
69: $perm->set('action', $action);
70: $perm->set('item', $item);
71:
72: $perm->store();
73: }
74:
75: return $perm;
76: }
77:
78: /**
79: * Sets a permission entry, is a wrapper for create() function
80: *
81: * @param int $group
82: * Specifies the frontend group
83: * @param string $plugin
84: * Specifies the plugin
85: * @param string $action
86: * Specifies the action
87: * @param string $item
88: * Specifies the item
89: */
90: public function setPerm($group, $plugin, $action, $item) {
91: $this->create($group, $plugin, $action, $item);
92: }
93:
94: /**
95: * Cheks, if an entry exists.
96: *
97: * 1.) Checks for global permission
98: * 2.) Checks for specific item permission
99: *
100: * @param int $group
101: * Specifies the frontend group
102: * @param string $plugin
103: * Specifies the plugin
104: * @param string $action
105: * Specifies the action
106: * @param string $item
107: * Specifies the item
108: * @param bool $useLang [optional]
109: * Flag to use language (Not used!)
110: * @return bool
111: */
112: public function checkPerm($group, $plugin, $action, $item, $useLang = false) {
113: global $lang;
114:
115: // checklang = ($useLang !== false) ? $useLang : $lang;
116:
117: $group = (int) $group;
118: $plugin = $this->_frontendPermission->_inFilter($plugin);
119: $action = $this->_frontendPermission->_inFilter($action);
120: $item = $this->_frontendPermission->_inFilter($item);
121:
122: // Check for global permisson
123: $this->select("idlang = " . $lang . " AND idfrontendgroup = " . $group . " AND plugin = '" . $plugin . "' AND action = '" . $action . "' AND item = '__GLOBAL__'");
124: if ($this->next()) {
125: return true;
126: }
127:
128: // Check for item permisson
129: $this->select("idlang = " . $lang . " AND idfrontendgroup = " . $group . " AND plugin = '" . $plugin . "' AND action = '" . $action . "' AND item = '" . $item . "'");
130: return ($this->next()) ? true : false;
131: }
132:
133: /**
134: * Removes the permission.
135: *
136: * @param int $group
137: * Specifies the frontend group
138: * @param string $plugin
139: * Specifies the plugin
140: * @param string $action
141: * Specifies the action
142: * @param string $item
143: * Specifies the item
144: * @param bool $useLang [optional]
145: * Flag to use language (Not used!)
146: * @return bool
147: */
148: public function removePerm($group, $plugin, $action, $item, $useLang = false) {
149: global $lang;
150:
151: // checklang = ($useLang !== false) ? $useLang : $lang;
152:
153: $group = (int) $group;
154: $plugin = $this->_frontendPermission->_inFilter($plugin);
155: $action = $this->_frontendPermission->_inFilter($action);
156: $item = $this->_frontendPermission->_inFilter($item);
157:
158: $this->select("idlang = " . $lang . " AND idfrontendgroup = " . $group . " AND plugin = '" . $plugin . "' AND action = '" . $action . "' AND item = '" . $item . "'");
159: if (($myitem = $this->next()) !== false) {
160: return $this->delete($myitem->get('idfrontendpermission'));
161: }
162: return false;
163: }
164: }
165:
166: /**
167: * Frontend permission item
168: *
169: * @package Core
170: * @subpackage GenericDB_Model
171: */
172: class cApiFrontendPermission extends Item {
173:
174: /**
175: * Constructor to create an instance of this class.
176: *
177: * @param mixed $mId [optional]
178: * Specifies the ID of item to load
179: */
180: public function __construct($mId = false) {
181: global $cfg;
182: parent::__construct($cfg['tab']['frontendpermissions'], 'idfrontendpermission');
183: if ($mId !== false) {
184: $this->loadByPrimaryKey($mId);
185: }
186: }
187: }
188: