update.class.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <?php
  2. /**
  3. * @package modx
  4. */
  5. /**
  6. * Loads the Media Sources page
  7. *
  8. * @package modx
  9. * @subpackage manager.controllers
  10. */
  11. class SourceUpdateManagerController extends modManagerController {
  12. /** @var modMediaSource $source */
  13. public $source;
  14. /** @var array $sourceArray An array of fields for the source */
  15. public $sourceArray = array();
  16. /** @var array $sourceDefaultProperties The default properties on the source */
  17. public $sourceDefaultProperties = array();
  18. /**
  19. * Check for any permissions or requirements to load page
  20. * @return bool
  21. */
  22. public function checkPermissions() {
  23. return $this->modx->hasPermission('source_edit');
  24. }
  25. /**
  26. * Register custom CSS/JS for the page
  27. * @return void
  28. */
  29. public function loadCustomCssJs() {
  30. $mgrUrl = $this->modx->getOption('manager_url',null,MODX_MANAGER_URL);
  31. $this->addJavascript($mgrUrl.'assets/modext/widgets/core/modx.grid.local.property.js');
  32. $this->addJavascript($mgrUrl.'assets/modext/widgets/source/modx.grid.source.properties.js');
  33. $this->addJavascript($mgrUrl.'assets/modext/widgets/source/modx.grid.source.access.js');
  34. $this->addJavascript($mgrUrl.'assets/modext/widgets/source/modx.panel.source.js');
  35. $this->addJavascript($mgrUrl.'assets/modext/sections/source/update.js');
  36. $this->addHtml('<script type="text/javascript">Ext.onReady(function() {MODx.load({
  37. xtype: "modx-page-source-update"
  38. ,record: '.$this->modx->toJSON($this->sourceArray).'
  39. ,defaultProperties: '.$this->modx->toJSON($this->sourceDefaultProperties).'
  40. });});</script>');
  41. }
  42. /**
  43. * Custom logic code here for setting placeholders, etc
  44. * @param array $scriptProperties
  45. * @return mixed
  46. */
  47. public function process(array $scriptProperties = array()) {
  48. if (empty($this->scriptProperties['id']) || strlen($this->scriptProperties['id']) !== strlen((integer)$this->scriptProperties['id'])) {
  49. return $this->failure($this->modx->lexicon('source_err_ns'));
  50. }
  51. $this->source = $this->modx->getObject('sources.modMediaSource', array('id' => $this->scriptProperties['id']));
  52. if (empty($this->source)) return $this->failure($this->modx->lexicon('source_err_nf'));
  53. $this->sourceArray = $this->source->toArray();
  54. $this->getProperties();
  55. $this->getAccess();
  56. $this->getDefaultProperties();
  57. return array();
  58. }
  59. public function getProperties() {
  60. $properties = $this->source->getProperties();
  61. $data = array();
  62. foreach ($properties as $property) {
  63. $data[] = array(
  64. $property['name'],
  65. !empty($property['desc']) ? $property['desc'] : '',
  66. !empty($property['type']) ? $property['type'] : 'textfield',
  67. !empty($property['options']) ? $property['options'] : array(),
  68. $property['value'],
  69. !empty($property['lexicon']) ? $property['lexicon'] : '',
  70. !empty($property['overridden']) ? $property['overridden'] : 0,
  71. !empty($property['desc_trans']) ? $property['desc_trans'] : '',
  72. !empty($property['name_trans']) ? $property['name_trans'] : '',
  73. );
  74. }
  75. $this->sourceArray['properties'] = $data;
  76. }
  77. public function getDefaultProperties() {
  78. $default = $this->source->getDefaultProperties();
  79. $default = $this->source->prepareProperties($default);
  80. $data = array();
  81. foreach ($default as $property) {
  82. $data[] = array(
  83. $property['name'],
  84. !empty($property['desc']) ? $property['desc'] : '',
  85. !empty($property['type']) ? $property['type'] : 'textfield',
  86. !empty($property['options']) ? $property['options'] : array(),
  87. $property['value'],
  88. !empty($property['lexicon']) ? $property['lexicon'] : '',
  89. 0,
  90. !empty($property['desc_trans']) ? $property['desc_trans'] : '',
  91. !empty($property['name_trans']) ? $property['name_trans'] : '',
  92. );
  93. }
  94. $this->sourceDefaultProperties = $data;
  95. return $data;
  96. }
  97. public function getAccess() {
  98. $c = $this->modx->newQuery('sources.modAccessMediaSource');
  99. $c->innerJoin('sources.modMediaSource','Target');
  100. $c->innerJoin('modAccessPolicy','Policy');
  101. $c->innerJoin('modUserGroup','Principal');
  102. $c->innerJoin('modUserGroupRole','MinimumRole');
  103. $c->where(array(
  104. 'target' => $this->source->get('id'),
  105. ));
  106. $c->select($this->modx->getSelectColumns('sources.modAccessMediaSource','modAccessMediaSource'));
  107. $c->select(array(
  108. 'target_name' => 'Target.name',
  109. 'principal_name' => 'Principal.name',
  110. 'policy_name' => 'Policy.name',
  111. 'authority_name' => 'MinimumRole.name',
  112. ));
  113. $acls = $this->modx->getCollection('sources.modAccessMediaSource',$c);
  114. $access = array();
  115. /** @var modAccessMediaSource $acl */
  116. foreach ($acls as $acl) {
  117. $access[] = array(
  118. $acl->get('id'),
  119. $acl->get('target'),
  120. $acl->get('target_name'),
  121. $acl->get('principal_class'),
  122. $acl->get('principal'),
  123. $acl->get('principal_name'),
  124. $acl->get('authority'),
  125. $acl->get('authority_name'),
  126. $acl->get('policy'),
  127. $acl->get('policy_name'),
  128. $acl->get('context_key'),
  129. );
  130. }
  131. $this->sourceArray['access'] = $this->modx->toJSON($access);
  132. }
  133. /**
  134. * Return the pagetitle
  135. *
  136. * @return string
  137. */
  138. public function getPageTitle() {
  139. return $this->modx->lexicon('source_update');
  140. }
  141. /**
  142. * Return the location of the template file
  143. * @return string
  144. */
  145. public function getTemplateFile() {
  146. return '';
  147. }
  148. /**
  149. * Specify the language topics to load
  150. * @return array
  151. */
  152. public function getLanguageTopics() {
  153. return array('source','namespace','propertyset');
  154. }
  155. /**
  156. * Get the Help URL
  157. * @return string
  158. */
  159. public function getHelpUrl() {
  160. return 'Media+Sources';
  161. }
  162. }