XOOPS  2.6.0
groupperm.php
Go to the documentation of this file.
1 <?php
26 
38 {
42  public function __construct()
43  {
44  $this->initVar('gperm_id', XOBJ_DTYPE_INT, null, false);
45  $this->initVar('gperm_groupid', XOBJ_DTYPE_INT, null, false);
46  $this->initVar('gperm_itemid', XOBJ_DTYPE_INT, null, false);
47  $this->initVar('gperm_modid', XOBJ_DTYPE_INT, 0, false);
48  $this->initVar('gperm_name', XOBJ_DTYPE_OTHER, null, false);
49  }
50 
55  public function id($format = 'n')
56  {
57  return $this->getVar('gperm_id', $format);
58  }
59 
64  public function gperm_id($format = '')
65  {
66  return $this->getVar('gperm_id', $format);
67  }
68 
73  public function gperm_groupid($format = '')
74  {
75  return $this->getVar('gperm_groupid', $format);
76  }
77 
82  public function gperm_itemid($format = '')
83  {
84  return $this->getVar('gperm_itemid', $format);
85  }
86 
91  public function gperm_modid($format = '')
92  {
93  return $this->getVar('gperm_modid', $format);
94  }
95 
100  public function gperm_name($format = '')
101  {
102  return $this->getVar('gperm_name', $format);
103  }
104 
105 }
106 
119 {
125  public function __construct(Connection $db = null)
126  {
127  parent::__construct($db, 'group_permission', 'XoopsGroupPerm', 'gperm_id', 'gperm_name');
128  }
129 
138  public function deleteByGroup($gperm_groupid, $gperm_modid = null)
139  {
140  $criteria = new CriteriaCompo(new Criteria('gperm_groupid', intval($gperm_groupid)));
141  if (isset($gperm_modid)) {
142  $criteria->add(new Criteria('gperm_modid', intval($gperm_modid)));
143  }
144  return $this->deleteAll($criteria);
145  }
146 
156  public function deleteByModule($gperm_modid, $gperm_name = null, $gperm_itemid = null)
157  {
158  $criteria = new CriteriaCompo(new Criteria('gperm_modid', intval($gperm_modid)));
159  if (isset($gperm_name)) {
160  $criteria->add(new Criteria('gperm_name', $gperm_name));
161  if (isset($gperm_itemid)) {
162  $criteria->add(new Criteria('gperm_itemid', intval($gperm_itemid)));
163  }
164  }
165  return $this->deleteAll($criteria);
166  }
167 
179  public function checkRight($gperm_name, $gperm_itemid, $gperm_groupid, $gperm_modid = 1, $trueifadmin = true)
180  {
181  if (empty($gperm_groupid)) {
182  return false;
183  } else {
184  if (is_array($gperm_groupid)) {
185  if (in_array(FixedGroups::ADMIN, $gperm_groupid) && $trueifadmin) {
186  return true;
187  }
188  $criteria_group = new CriteriaCompo();
189  foreach ($gperm_groupid as $gid) {
190  $criteria_group->add(new Criteria('gperm_groupid', $gid), 'OR');
191  }
192  } else {
193  if (FixedGroups::ADMIN == $gperm_groupid && $trueifadmin) {
194  return true;
195  }
196  $criteria_group = new CriteriaCompo(new Criteria('gperm_groupid', $gperm_groupid));
197  }
198  }
199  $criteria = new CriteriaCompo(new Criteria('gperm_modid', $gperm_modid));
200  $criteria->add($criteria_group);
201  $criteria->add(new Criteria('gperm_name', $gperm_name));
202  $gperm_itemid = intval($gperm_itemid);
203  if ($gperm_itemid > 0) {
204  $criteria->add(new Criteria('gperm_itemid', $gperm_itemid));
205  }
206  if ($this->getCount($criteria) > 0) {
207  return true;
208  }
209  return false;
210  }
211 
222  function addRight($gperm_name, $gperm_itemid, $gperm_groupid, $gperm_modid = 1)
223  {
224  $perm = $this->create();
225  $perm->setVar('gperm_name', $gperm_name);
226  $perm->setVar('gperm_groupid', $gperm_groupid);
227  $perm->setVar('gperm_itemid', $gperm_itemid);
228  $perm->setVar('gperm_modid', $gperm_modid);
229  return $this->insert($perm);
230  }
231 
241  public function getItemIds($gperm_name, $gperm_groupid, $gperm_modid = 1)
242  {
243  $ret = array();
244  $criteria = new CriteriaCompo(new Criteria('gperm_name', $gperm_name));
245  $criteria->add(new Criteria('gperm_modid', intval($gperm_modid)));
246  if (is_array($gperm_groupid)) {
247  $criteria2 = new CriteriaCompo();
248  foreach ($gperm_groupid as $gid) {
249  $criteria2->add(new Criteria('gperm_groupid', $gid), 'OR');
250  }
251  $criteria->add($criteria2);
252  } else {
253  $criteria->add(new Criteria('gperm_groupid', intval($gperm_groupid)));
254  }
255  $perms = $this->getObjects($criteria, true);
256  foreach (array_keys($perms) as $i) {
257  $ret[] = $perms[$i]->getVar('gperm_itemid');
258  }
259  return array_unique($ret);
260  }
261 
271  public function getGroupIds($gperm_name, $gperm_itemid, $gperm_modid = 1)
272  {
273  $ret = array();
274  $criteria = new CriteriaCompo(new Criteria('gperm_name', $gperm_name));
275  $criteria->add(new Criteria('gperm_itemid', intval($gperm_itemid)));
276  $criteria->add(new Criteria('gperm_modid', intval($gperm_modid)));
277  $perms = $this->getObjects($criteria, true);
278  foreach (array_keys($perms) as $i) {
279  $ret[] = $perms[$i]->getVar('gperm_groupid');
280  }
281  return $ret;
282  }
283 }
gperm_groupid($format= '')
Definition: groupperm.php:73
gperm_name($format= '')
Definition: groupperm.php:100
$i
Definition: dialog.php:68
gperm_itemid($format= '')
Definition: groupperm.php:82
id($format= 'n')
Definition: groupperm.php:55
getVar($key, $format= 's')
addRight($gperm_name, $gperm_itemid, $gperm_groupid, $gperm_modid=1)
Definition: groupperm.php:222
gperm_modid($format= '')
Definition: groupperm.php:91
deleteByGroup($gperm_groupid, $gperm_modid=null)
Definition: groupperm.php:138
getObjects(CriteriaElement $criteria=null, $id_as_key=false, $as_object=true)
$criteria2
getGroupIds($gperm_name, $gperm_itemid, $gperm_modid=1)
Definition: groupperm.php:271
deleteAll(CriteriaElement $criteria, $force=true, $asObject=false)
$criteria
gperm_id($format= '')
Definition: groupperm.php:64
checkRight($gperm_name, $gperm_itemid, $gperm_groupid, $gperm_modid=1, $trueifadmin=true)
Definition: groupperm.php:179
initVar($key, $data_type, $value=null, $required=false, $maxlength=null, $options= '')
__construct(Connection $db=null)
Definition: groupperm.php:125
getItemIds($gperm_name, $gperm_groupid, $gperm_modid=1)
Definition: groupperm.php:241
deleteByModule($gperm_modid, $gperm_name=null, $gperm_itemid=null)
Definition: groupperm.php:156