update.class.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <?php
  2. /**
  3. * @package modx
  4. * @subpackage manager.controllers
  5. */
  6. /**
  7. * Loads the dashboard update page
  8. *
  9. * @package modx
  10. * @subpackage manager.controllers
  11. */
  12. class SystemDashboardsUpdateManagerController extends modManagerController {
  13. /** @var modDashboard $dashboard */
  14. public $dashboard;
  15. /** @var array $dashboardArray */
  16. public $dashboardArray;
  17. /**
  18. * Check for any permissions or requirements to load page
  19. * @return bool
  20. */
  21. public function checkPermissions() {
  22. return $this->modx->hasPermission('dashboards');
  23. }
  24. /**
  25. * Custom logic code here for setting placeholders, etc
  26. *
  27. * @param array $scriptProperties
  28. * @return array
  29. */
  30. public function process(array $scriptProperties = array()) {
  31. if (empty($this->scriptProperties['id']) || strlen($this->scriptProperties['id']) !== strlen((integer)$this->scriptProperties['id'])) {
  32. return $this->failure($this->modx->lexicon('dashboard_err_ns'));
  33. }
  34. $this->dashboard = $this->modx->getObject('modDashboard', array('id' => $this->scriptProperties['id']));
  35. if (empty($this->dashboard)) return $this->failure($this->modx->lexicon('dashboard_err_nf'));
  36. $this->dashboardArray = $this->dashboard->toArray();
  37. $this->dashboardArray['widgets'] = $this->getWidgets();
  38. return $this->dashboardArray;
  39. }
  40. /**
  41. * Get all the Widgets placed on this Dashboard
  42. * @return array
  43. */
  44. public function getWidgets() {
  45. $c = $this->modx->newQuery('modDashboardWidgetPlacement');
  46. $c->where(array(
  47. 'dashboard' => $this->dashboard->get('id'),
  48. ));
  49. $c->sortby('modDashboardWidgetPlacement.rank','ASC');
  50. $placements = $this->modx->getCollection('modDashboardWidgetPlacement',$c);
  51. $list = array();
  52. /** @var modDashboardWidgetPlacement $placement */
  53. foreach ($placements as $placement) {
  54. $placement->getOne('Widget');
  55. if (!($placement->Widget instanceof modDashboardWidget)) {
  56. continue;
  57. }
  58. if ($placement->Widget->get('lexicon') != 'core:dashboards') {
  59. $this->modx->lexicon->load($placement->Widget->get('lexicon'));
  60. }
  61. $widgetArray = $placement->Widget->toArray();
  62. $list[] = array(
  63. $placement->get('dashboard'),
  64. $placement->get('widget'),
  65. $placement->get('rank'),
  66. $widgetArray['name'],
  67. $widgetArray['name_trans'],
  68. $widgetArray['description'],
  69. $widgetArray['description_trans'],
  70. );
  71. }
  72. return $list;
  73. }
  74. /**
  75. * Get all the User Groups assigned to this Dashboard
  76. * @return array
  77. */
  78. public function getUserGroups() {
  79. $c = $this->modx->newQuery('modUserGroup');
  80. $c->where(array(
  81. 'dashboard' => $this->dashboard->get('id'),
  82. ));
  83. $c->sortby('name','ASC');
  84. $usergroups = $this->modx->getCollection('modUserGroup',$c);
  85. $list = array();
  86. /** @var modUserGroup $usergroup */
  87. foreach ($usergroups as $usergroup) {
  88. $list[] = array($usergroup->get('id'),$usergroup->get('name'));
  89. }
  90. return $list;
  91. }
  92. /**
  93. * Register custom CSS/JS for the page
  94. * @return void
  95. */
  96. public function loadCustomCssJs() {
  97. $this->addJavascript($this->modx->getOption('manager_url')."assets/modext/widgets/system/modx.panel.dashboard.js");
  98. $this->addJavascript($this->modx->getOption('manager_url').'assets/modext/sections/system/dashboards/update.js');
  99. $this->addHtml('<script type="text/javascript">Ext.onReady(function() {
  100. MODx.load({
  101. xtype: "modx-page-dashboard-update"
  102. ,record: '.$this->modx->toJSON($this->dashboardArray).'
  103. });
  104. });</script>');
  105. }
  106. /**
  107. * Return the pagetitle
  108. *
  109. * @return string
  110. */
  111. public function getPageTitle() {
  112. return $this->modx->lexicon('dashboards');
  113. }
  114. /**
  115. * Return the location of the template file
  116. * @return string
  117. */
  118. public function getTemplateFile() {
  119. return '';
  120. }
  121. /**
  122. * Specify the language topics to load
  123. * @return array
  124. */
  125. public function getLanguageTopics() {
  126. return array('dashboards','user');
  127. }
  128. /**
  129. * Get the Help URL
  130. * @return string
  131. */
  132. public function getHelpUrl() {
  133. return 'Dashboards';
  134. }
  135. }