update.class.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. /*
  3. * This file is part of MODX Revolution.
  4. *
  5. * Copyright (c) MODX, LLC. All Rights Reserved.
  6. *
  7. * For complete copyright and license information, see the COPYRIGHT and LICENSE
  8. * files found in the top-level directory of this distribution.
  9. */
  10. /**
  11. * Loads the policy template page
  12. *
  13. * @package modx
  14. * @subpackage manager.controllers
  15. */
  16. class SecurityAccessPolicyTemplateUpdateManagerController extends modManagerController {
  17. /** @var modAccessPolicyTemplate $template */
  18. public $template;
  19. /** @var array $templateArray */
  20. public $templateArray = array();
  21. /**
  22. * Check for any permissions or requirements to load page
  23. * @return bool
  24. */
  25. public function checkPermissions() {
  26. return $this->modx->hasPermission('policy_template_edit');
  27. }
  28. /**
  29. * Get the current policy template
  30. * @return void
  31. */
  32. public function initialize() {
  33. if (!empty($this->scriptProperties['id']) && strlen($this->scriptProperties['id']) === strlen((integer)$this->scriptProperties['id'])) {
  34. $this->template = $this->modx->getObject('modAccessPolicyTemplate', array('id' => $this->scriptProperties['id']));
  35. }
  36. }
  37. /**
  38. * Register custom CSS/JS for the page
  39. * @return void
  40. */
  41. public function loadCustomCssJs() {
  42. $mgrUrl = $this->modx->getOption('manager_url',null,MODX_MANAGER_URL);
  43. $this->addJavascript($mgrUrl.'assets/modext/widgets/security/modx.panel.access.policy.template.js');
  44. $this->addJavascript($mgrUrl.'assets/modext/sections/security/access/policy/template/update.js');
  45. $this->addHtml('
  46. <script type="text/javascript">
  47. // <![CDATA[
  48. Ext.onReady(function() {
  49. MODx.load({
  50. xtype: "modx-page-access-policy-template"
  51. ,template: "'.$this->templateArray['id'].'"
  52. ,record: '.$this->modx->toJSON($this->templateArray).'
  53. });
  54. });
  55. // ]]>
  56. </script>');
  57. }
  58. /**
  59. * Custom logic code here for setting placeholders, etc
  60. * @param array $scriptProperties
  61. * @return mixed
  62. */
  63. public function process(array $scriptProperties = array()) {
  64. if (empty($this->template)) return $this->failure($this->modx->lexicon('policy_template_err_nf'));
  65. $placeholders = array();
  66. /* get permissions */
  67. $this->templateArray = $this->template->toArray();
  68. $c = $this->modx->newQuery('modAccessPermission');
  69. $c->sortby('name','ASC');
  70. $permissions = $this->template->getMany('Permissions',$c);
  71. /** @var modAccessPermission $permission */
  72. foreach ($permissions as $permission) {
  73. $desc = $permission->get('description');
  74. if (!empty($this->templateArray['lexicon'])) {
  75. if (strpos($this->templateArray['lexicon'],':') !== false) {
  76. $this->modx->lexicon->load($this->templateArray['lexicon']);
  77. } else {
  78. $this->modx->lexicon->load('core:'.$this->templateArray['lexicon']);
  79. }
  80. $desc = $this->modx->lexicon($desc);
  81. }
  82. $this->templateArray['permissions'][] = array(
  83. $permission->get('name'),
  84. $permission->get('description'),
  85. $desc,
  86. $permission->get('value'),
  87. );
  88. }
  89. $placeholders['template'] = $this->templateArray;
  90. return $placeholders;
  91. }
  92. /**
  93. * Return the pagetitle
  94. *
  95. * @return string
  96. */
  97. public function getPageTitle() {
  98. return $this->modx->lexicon('policy_template').': '.$this->templateArray['name'];
  99. }
  100. /**
  101. * Return the location of the template file
  102. * @return string
  103. */
  104. public function getTemplateFile() {
  105. return '';
  106. }
  107. /**
  108. * Specify the language topics to load
  109. * @return array
  110. */
  111. public function getLanguageTopics() {
  112. return array('user','access','policy','context');
  113. }
  114. /**
  115. * Get the Help URL
  116. * @return string
  117. */
  118. public function getHelpUrl() {
  119. return 'PolicyTemplates';
  120. }
  121. }