PageRenderTime 96ms CodeModel.GetById 27ms RepoModel.GetById 1ms app.codeStats 0ms

/manager/controllers/default/system/dashboards/update.class.php

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