update.class.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 SystemDashboardsWidgetUpdateManagerController extends modManagerController {
  13. /** @var modDashboard $dashboard */
  14. public $dashboard;
  15. /** @var modDashboardWidget $widget */
  16. public $widget;
  17. /** @var array $widgetArray */
  18. public $widgetArray = array();
  19. /**
  20. * Check for any permissions or requirements to load page
  21. * @return bool
  22. */
  23. public function checkPermissions() {
  24. return $this->modx->hasPermission('dashboards');
  25. }
  26. /**
  27. * Get the active widget
  28. * @return void
  29. */
  30. public function initialize() {
  31. if (!empty($this->scriptProperties['id']) && strlen($this->scriptProperties['id']) === strlen((integer)$this->scriptProperties['id'])) {
  32. $this->widget = $this->modx->getObject('modDashboardWidget', array('id' => $this->scriptProperties['id']));
  33. }
  34. }
  35. /**
  36. * Custom logic code here for setting placeholders, etc
  37. *
  38. * @param array $scriptProperties
  39. * @return array
  40. */
  41. public function process(array $scriptProperties = array()) {
  42. if (empty($this->widget)) return $this->failure($this->modx->lexicon('widget_err_nf'));
  43. $this->widgetArray = $this->widget->toArray();
  44. $this->widgetArray['dashboards'] = $this->getDashboards();
  45. return $this->widgetArray;
  46. }
  47. /**
  48. * Get the Dashboards this Widget has been placed on
  49. * @return array
  50. */
  51. public function getDashboards() {
  52. $list = array();
  53. $c = $this->modx->newQuery('modDashboardWidgetPlacement');
  54. $c->innerJoin('modDashboard','Dashboard');
  55. $c->where(array(
  56. 'widget' => $this->widget->get('id'),
  57. ));
  58. $c->sortby('Dashboard.name','ASC');
  59. $c->select($this->modx->getSelectColumns('modDashboardWidgetPlacement','modDashboardWidgetPlacement'));
  60. $c->select(array(
  61. 'Dashboard.name',
  62. 'Dashboard.description',
  63. ));
  64. $placements = $this->widget->getMany('Placements',$c);
  65. /** @var modDashboardWidgetPlacement $placement */
  66. foreach ($placements as $placement) {
  67. $list[] = array(
  68. $placement->get('dashboard'),
  69. $placement->get('name'),
  70. $placement->get('description'),
  71. );
  72. }
  73. return $list;
  74. }
  75. /**
  76. * Register custom CSS/JS for the page
  77. * @return void
  78. */
  79. public function loadCustomCssJs() {
  80. $mgrUrl = $this->modx->getOption('manager_url',null,MODX_MANAGER_URL);
  81. $this->addJavascript($mgrUrl."assets/modext/widgets/system/modx.panel.dashboard.widget.js");
  82. $this->addJavascript($mgrUrl.'assets/modext/sections/system/dashboards/widget/update.js');
  83. $this->addHtml('<script type="text/javascript">Ext.onReady(function() {
  84. MODx.load({
  85. xtype: "modx-page-dashboard-widget-update"
  86. ,record: '.$this->modx->toJSON($this->widgetArray).'
  87. });
  88. });</script>');
  89. }
  90. /**
  91. * Return the pagetitle
  92. *
  93. * @return string
  94. */
  95. public function getPageTitle() {
  96. return $this->modx->lexicon('dashboards');
  97. }
  98. /**
  99. * Return the location of the template file
  100. * @return string
  101. */
  102. public function getTemplateFile() {
  103. return '';
  104. }
  105. /**
  106. * Specify the language topics to load
  107. * @return array
  108. */
  109. public function getLanguageTopics() {
  110. $topics = array('dashboards','user');
  111. if ($this->widget) {
  112. $lexicon = $this->widget->get('lexicon');
  113. if (!empty($lexicon) && $lexicon != 'core:dashboards') {
  114. $topics[] = $lexicon;
  115. }
  116. }
  117. return $topics;
  118. }
  119. /**
  120. * Get the Help URL
  121. * @return string
  122. */
  123. public function getHelpUrl() {
  124. return 'Dashboard+Widgets';
  125. }
  126. }