update.class.php 3.9 KB

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