update.class.php 4.1 KB

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