PageRenderTime 49ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/web/concrete/core/models/permission/keys/custom/add_block_to_area.php

https://github.com/glockops/concrete5
PHP | 106 lines | 93 code | 13 blank | 0 comment | 21 complexity | 50e184abbebc9131e583187dfad68e3b MD5 | raw file
Possible License(s): MIT, LGPL-2.1, BSD-3-Clause
  1. <?
  2. defined('C5_EXECUTE') or die("Access Denied.");
  3. class Concrete5_Model_AddBlockToAreaAreaPermissionKey extends AreaPermissionKey {
  4. public function copyFromPageToArea() {
  5. $db = Loader::db();
  6. $inheritedPKID = $db->GetOne('select pkID from PermissionKeys where pkHandle = ?', array('add_block'));
  7. $r = $db->Execute('select peID, pa.paID from PermissionAssignments pa inner join PermissionAccessList pal on pa.paID = pal.paID where pkID = ?', array(
  8. $inheritedPKID
  9. ));
  10. if ($r) {
  11. while ($row = $r->FetchRow()) {
  12. $db->Replace('AreaPermissionAssignments', array(
  13. 'cID' => $this->permissionObject->getCollectionID(),
  14. 'arHandle' => $this->permissionObject->getAreaHandle(),
  15. 'pkID' => $this->getPermissionKeyID(),
  16. 'paID' => $row['paID']
  17. ), array('cID', 'arHandle', 'pkID'), true);
  18. $rx = $db->Execute('select permission from BlockTypePermissionBlockTypeAccessList where paID = ? and peID = ?', array(
  19. $row['paID'], $row['peID']
  20. ));
  21. while ($rowx = $rx->FetchRow()) {
  22. $db->Replace('AreaPermissionBlockTypeAccessList', array(
  23. 'peID' => $row['peID'],
  24. 'permission' => $rowx['permission'],
  25. 'paID' => $row['paID']
  26. ), array('paID', 'peID'), true);
  27. }
  28. $db->Execute('delete from AreaPermissionBlockTypeAccessListCustom where paID = ?', array(
  29. $row['paID']
  30. ));
  31. $rx = $db->Execute('select btID from BlockTypePermissionBlockTypeAccessListCustom where paID = ? and peID = ?', array(
  32. $row['paID'], $row['peID']
  33. ));
  34. while ($rowx = $rx->FetchRow()) {
  35. $db->Replace('AreaPermissionBlockTypeAccessListCustom', array(
  36. 'paID' => $row['paID'],
  37. 'btID' => $rowx['btID'],
  38. 'peID' => $row['peID']
  39. ), array('paID', 'peID', 'btID'), true);
  40. }
  41. }
  42. }
  43. }
  44. protected function getAllowedBlockTypeIDs() {
  45. $u = new User();
  46. $pae = $this->getPermissionAccessObject();
  47. if (!is_object($pae)) {
  48. return array();
  49. }
  50. $accessEntities = $u->getUserAccessEntityObjects();
  51. $accessEntities = $pae->validateAndFilterAccessEntities($accessEntities);
  52. $list = $this->getAccessListItems(AreaPermissionKey::ACCESS_TYPE_ALL, $accessEntities);
  53. $list = PermissionDuration::filterByActive($list);
  54. $db = Loader::db();
  55. $btIDs = array();
  56. if (count($list) > 0) {
  57. $dsh = Loader::helper('concrete/dashboard');
  58. if ($dsh->inDashboard()) {
  59. $allBTIDs = $db->GetCol('select btID from BlockTypes');
  60. } else {
  61. $allBTIDs = $db->GetCol('select btID from BlockTypes where btIsInternal = 0');
  62. }
  63. foreach($list as $l) {
  64. if ($l->getBlockTypesAllowedPermission() == 'N') {
  65. $btIDs = array();
  66. }
  67. if ($l->getBlockTypesAllowedPermission() == 'C') {
  68. if ($l->getAccessType() == AreaPermissionKey::ACCESS_TYPE_EXCLUDE) {
  69. $btIDs = array_values(array_diff($btIDs, $l->getBlockTypesAllowedArray()));
  70. } else {
  71. $btIDs = array_unique(array_merge($btIDs, $l->getBlockTypesAllowedArray()));
  72. }
  73. }
  74. if ($l->getBlockTypesAllowedPermission() == 'A') {
  75. $btIDs = $allBTIDs;
  76. }
  77. }
  78. }
  79. return $btIDs;
  80. }
  81. public function validate($bt = false) {
  82. $u = new User();
  83. if ($u->isSuperUser()) {
  84. return true;
  85. }
  86. $types = $this->getAllowedBlockTypeIDs();
  87. if ($bt != false) {
  88. return in_array($bt->getBlockTypeID(), $types);
  89. } else {
  90. return count($types) > 0;
  91. }
  92. }
  93. }