SDbAuthManager.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /*
  3. * To change this template, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. /**
  7. * Description of SDbAuthManager
  8. *
  9. * @author ssoldatos
  10. */
  11. class SDbAuthManager extends CDbAuthManager {
  12. /**
  13. * Performs access check for the specified user.
  14. * @param string the name of the operation that need access check
  15. * @param mixed the user ID. This should can be either an integer and a string representing
  16. * the unique identifier of a user. See {@link IWebUser::getId}.
  17. * @param array name-value pairs that would be passed to biz rules associated
  18. * with the tasks and roles assigned to the user.
  19. * @return boolean whether the operations can be performed by the user.
  20. */
  21. public function checkAccess($itemName, $userId, $params=array()) {
  22. if (!empty($this->defaultRoles) && in_array($itemName,$this->defaultRoles)) {
  23. return true;
  24. }
  25. $sql = "SELECT name, type, description, t1.bizrule, t1.data, t2.bizrule AS bizrule2, t2.data AS data2 FROM {$this->itemTable} t1, {$this->assignmentTable} t2 WHERE name=itemname AND userid=:userid";
  26. $command = $this->db->createCommand($sql);
  27. $command->bindValue(':userid', $userId);
  28. // check directly assigned items
  29. $names = array();
  30. foreach ($command->queryAll() as $row) {
  31. Yii::trace('Checking permission "' . $row['name'] . '"', 'system.web.auth.CDbAuthManager');
  32. if ($this->executeBizRule($row['bizrule2'], $params, unserialize($row['data2']))
  33. && $this->executeBizRule($row['bizrule'], $params, unserialize($row['data']))) {
  34. if (strtolower($row['name']) === strtolower($itemName)) {
  35. return true;
  36. }
  37. $names[] = $row['name'];
  38. }
  39. }
  40. // check all descendant items
  41. while ($names !== array()) {
  42. $items = $this->getItemChildren($names);
  43. $names = array();
  44. foreach ($items as $item) {
  45. Yii::trace('Checking permission "' . $item->getName() . '"', 'system.web.auth.CDbAuthManager');
  46. if ($this->executeBizRule($item->getBizRule(), $params, $item->getData())) {
  47. if (strtolower($item->getName()) === strtolower($itemName)) {
  48. return true;
  49. }
  50. $names[] = $item->getName();
  51. }
  52. }
  53. }
  54. return false;
  55. }
  56. }
  57. ?>