BxDolStudioPermissionsQuery.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup DolphinStudio Dolphin Studio
  7. * @{
  8. */
  9. bx_import('BxDolAclQuery');
  10. class BxDolStudioPermissionsQuery extends BxDolAclQuery {
  11. function __construct() {
  12. parent::__construct();
  13. }
  14. function isLevelUsed($iId) {
  15. $sSql = $this->prepare("SELECT UNIX_TIMESTAMP(MAX(`DateExpires`)) as `MaxDateExpires` FROM `sys_acl_levels_members` WHERE `IDLevel`=?", $iId);
  16. return (int)$this->getOne($sSql) > time();
  17. }
  18. function getLevelOrderMax() {
  19. return (int)$this->getOne("SELECT MAX(`Order`) FROM `sys_acl_levels` WHERE 1");
  20. }
  21. function updateLevels($iId, $aFields) {
  22. $sSql = "UPDATE `sys_acl_levels` SET `" . implode("`=?, `", array_keys($aFields)) . "`=? WHERE `ID`=?";
  23. $sSql = call_user_func_array(array($this, 'prepare'), array_merge(array($sSql), array_values($aFields), array($iId)));
  24. return (int)$this->query($sSql) > 0;
  25. }
  26. function deleteLevel($aParams) {
  27. $sWhereClause = $sLimitClause = "";
  28. switch($aParams['type']) {
  29. case 'by_id':
  30. $sWhereClause .= $this->prepare("AND `tal`.`ID`=?", $aParams['value']);
  31. break;
  32. }
  33. $sSql = "DELETE FROM `tal`, `tam`
  34. USING `sys_acl_levels` AS `tal`
  35. LEFT JOIN `sys_acl_matrix` AS `tam` ON `tal`.`ID`=`tam`.`IDLevel`
  36. WHERE 1 " . $sWhereClause . " " . $sLimitClause;
  37. return (int)$this->query($sSql) > 0;
  38. }
  39. function switchAction($iLevelId, $iActionId, $bEnable) {
  40. if($bEnable)
  41. $sSql = $this->prepare("INSERT INTO `sys_acl_matrix`(`IDLevel`, `IDAction`) VALUES(?, ?)", $iLevelId, $iActionId);
  42. else
  43. $sSql = $this->prepare("DELETE FROM `sys_acl_matrix` WHERE `IDLevel`=? AND `IDAction`=?", $iLevelId, $iActionId);
  44. return (int)$this->query($sSql) > 0;
  45. }
  46. function getOptions($aParams, &$aItems, $bReturnCount = true) {
  47. $aMethod = array('name' => 'getAll', 'params' => array(0 => 'query'));
  48. $sSelectClause = $sJoinClause = $sWhereClause = $sOrderClause = $sLimitClause = "";
  49. if(!isset($aParams['order']) || empty($aParams['order']))
  50. $sOrderClause = "ORDER BY `tam`.`IDAction` ASC";
  51. switch($aParams['type']) {
  52. case 'by_level_action_ids':
  53. $aMethod['name'] = 'getRow';
  54. $sSelectClause = ", `taa`.`Title` AS `action_title`, `taa`.`Countable` AS `action_countable`";
  55. $sJoinClause = "LEFT JOIN `sys_acl_actions` AS `taa` ON `tam`.`IDAction`=`taa`.`ID` ";
  56. $sWhereClause = $this->prepare(" AND `tam`.`IDLevel`=? AND `tam`.`IDAction`=? ", $aParams['level_id'], $aParams['action_id']);
  57. break;
  58. }
  59. $aMethod['params'][0] = "SELECT " . ($bReturnCount ? "SQL_CALC_FOUND_ROWS" : "") . "
  60. `tam`.`IDLevel` AS `level_id`,
  61. `tam`.`IDAction` AS `action_id`,
  62. `tam`.`AllowedCount` AS `allowed_count`,
  63. `tam`.`AllowedPeriodLen` AS `allowed_period_len`,
  64. `tam`.`AllowedPeriodStart` AS `allowed_period_start`,
  65. `tam`.`AllowedPeriodEnd` AS `allowed_period_end`,
  66. `tam`.`AdditionalParamValue` AS `additional_param_value`" . $sSelectClause . "
  67. FROM `sys_acl_matrix` AS `tam` " . $sJoinClause . "
  68. WHERE 1 " . $sWhereClause . " " . $sOrderClause . " " . $sLimitClause;
  69. $aItems = call_user_func_array(array($this, $aMethod['name']), $aMethod['params']);
  70. if(!$bReturnCount)
  71. return !empty($aItems);
  72. return (int)$this->getOne("SELECT FOUND_ROWS()");
  73. }
  74. function updateOptions($iLevelId, $iActionId, $aFields) {
  75. $sSql = "UPDATE `sys_acl_matrix` SET `" . implode("`=?, `", array_keys($aFields)) . "`=? WHERE `IDLevel`=? AND `IDAction`=?";
  76. $sSql = call_user_func_array(array($this, 'prepare'), array_merge(array($sSql), array_values($aFields), array($iLevelId, $iActionId)));
  77. return (int)$this->query($sSql) > 0;
  78. }
  79. function deleteActions($aParams) {
  80. $sWhereClause = "";
  81. switch($aParams['type']) {
  82. case 'by_level_id':
  83. $sWhereClause .= $this->prepare("AND `IDLevel`=?", $aParams['value']);
  84. break;
  85. }
  86. return (int)$this->query("DELETE FROM `sys_acl_matrix` WHERE 1 " . $sWhereClause) > 0;
  87. }
  88. }
  89. /** @} */