PageRenderTime 52ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/src/administrator/components/com_kunena/views/statistics/view.html.php

https://github.com/xillibit/Kunena-forum
PHP | 189 lines | 107 code | 26 blank | 56 comment | 1 complexity | 01a20e232cb43c6698eac728f76f726a MD5 | raw file
  1. <?php
  2. /**
  3. * Kunena Component
  4. *
  5. * @package Kunena.Administrator
  6. * @subpackage Views
  7. *
  8. * @copyright Copyright (C) 2008 - 2020 Kunena Team. All rights reserved.
  9. * @license https://www.gnu.org/copyleft/gpl.html GNU/GPL
  10. * @link https://www.kunena.org
  11. **/
  12. defined('_JEXEC') or die();
  13. use Joomla\CMS\HTML\HTMLHelper;
  14. use Joomla\CMS\Factory;
  15. use Joomla\CMS\Language\Text;
  16. use Joomla\CMS\Toolbar\ToolbarHelper;
  17. /**
  18. * Statistics view for Kunena backend
  19. *
  20. * @since Kunena
  21. */
  22. class KunenaAdminViewStatistics extends KunenaView
  23. {
  24. /**
  25. * @param null $tpl tpl
  26. *
  27. * @since Kunena
  28. * @throws ReflectionException
  29. */
  30. public function displayDefault($tpl = null)
  31. {
  32. $this->state = $this->get('state');
  33. $this->group = $this->state->get('group');
  34. $this->items = $this->get('items');
  35. $this->pagination = $this->get('Pagination');
  36. $this->filterUserFields = $this->getFilterUserFields();
  37. $this->sortFields = $this->getSortFields();
  38. $this->sortDirectionFields = $this->getSortDirectionFields();
  39. $this->filterTypeFields = $this->getFilterTypeFields();
  40. $this->filterOperationFields = $this->getFilterOperationFields();
  41. $this->filterSearch = $this->escape($this->state->get('filter.search'));
  42. $this->filterType = $this->escape($this->state->get('filter.type'));
  43. $this->filterUser = $this->escape($this->state->get('filter.user'));
  44. $this->filterCategory = $this->escape($this->state->get('filter.category'));
  45. $this->filterTopic = $this->escape($this->state->get('filter.topic'));
  46. $this->filterTargetUser = $this->escape($this->state->get('filter.target_user'));
  47. $this->filterIp = $this->escape($this->state->get('filter.ip'));
  48. $this->filterTimeStart = $this->escape($this->state->get('filter.time_start'));
  49. $this->filterTimeStop = $this->escape($this->state->get('filter.time_stop'));
  50. $this->filterOperation = $this->escape($this->state->get('filter.operation'));
  51. $this->filterActive = $this->escape($this->state->get('filter.active'));
  52. $this->filterUsertypes = $this->escape($this->state->get('filter.usertypes'));
  53. $this->listOrdering = $this->escape($this->state->get('list.ordering'));
  54. $this->listDirection = $this->escape($this->state->get('list.direction'));
  55. $document = Factory::getApplication()->getDocument();
  56. $document->setTitle(Text::_('Forum Logs'));
  57. $this->setToolbar();
  58. $this->display();
  59. }
  60. /**
  61. * @return array
  62. * @since Kunena
  63. */
  64. protected function getFilterUserFields()
  65. {
  66. $filterFields = array();
  67. $filterFields[] = HTMLHelper::_('select.option', 0, 'Guests');
  68. $filterFields[] = HTMLHelper::_('select.option', 1, 'Registered users');
  69. $filterFields[] = HTMLHelper::_('select.option', 2, 'Regular members');
  70. $filterFields[] = HTMLHelper::_('select.option', 3, 'Moderators');
  71. $filterFields[] = HTMLHelper::_('select.option', 4, 'Administrators');
  72. $filterFields[] = HTMLHelper::_('select.option', 5, 'Mods and Admins');
  73. return $filterFields;
  74. }
  75. /**
  76. * @return array
  77. * @since Kunena
  78. */
  79. protected function getSortFields()
  80. {
  81. $sortFields = array();
  82. // TODO: translate
  83. $sortFields[] = HTMLHelper::_('select.option', 'id', $this->group ? 'Count' : 'Id');
  84. $sortFields[] = HTMLHelper::_('select.option', 'type', 'Type (by id)');
  85. $sortFields[] = HTMLHelper::_('select.option', 'user', 'User (by id)');
  86. $sortFields[] = HTMLHelper::_('select.option', 'category', 'Category (by id)');
  87. $sortFields[] = HTMLHelper::_('select.option', 'topic', 'Topic (by id)');
  88. $sortFields[] = HTMLHelper::_('select.option', 'target_user', 'Target User (by id)');
  89. $sortFields[] = HTMLHelper::_('select.option', 'time', 'Time (by id)');
  90. return $sortFields;
  91. }
  92. /**
  93. * @return array
  94. * @since Kunena
  95. */
  96. protected function getSortDirectionFields()
  97. {
  98. $sortDirection = array();
  99. $sortDirection[] = HTMLHelper::_('select.option', 'asc', Text::_('COM_KUNENA_FIELD_LABEL_ASCENDING'));
  100. $sortDirection[] = HTMLHelper::_('select.option', 'desc', Text::_('COM_KUNENA_FIELD_LABEL_DESCENDING'));
  101. return $sortDirection;
  102. }
  103. /**
  104. * @return array
  105. * @since Kunena
  106. */
  107. protected function getFilterTypeFields()
  108. {
  109. $filterFields = array();
  110. $filterFields[] = HTMLHelper::_('select.option', 1, 'MOD');
  111. $filterFields[] = HTMLHelper::_('select.option', 2, 'ACT');
  112. $filterFields[] = HTMLHelper::_('select.option', 3, 'ERR');
  113. $filterFields[] = HTMLHelper::_('select.option', 4, 'REP');
  114. return $filterFields;
  115. }
  116. /**
  117. * @return array
  118. * @since Kunena
  119. * @throws ReflectionException
  120. */
  121. protected function getFilterOperationFields()
  122. {
  123. $filterFields = array();
  124. $reflection = new ReflectionClass('KunenaLog');
  125. $constants = $reflection->getConstants();
  126. ksort($constants);
  127. foreach ($constants as $key => $value)
  128. {
  129. if (strpos($key, 'LOG_') === 0)
  130. {
  131. $filterFields[] = HTMLHelper::_('select.option', $key, Text::_("COM_KUNENA_{$value}"));
  132. }
  133. }
  134. return $filterFields;
  135. }
  136. protected function setToolbar()
  137. {
  138. // Set the titlebar text
  139. ToolbarHelper::title(Text::_('COM_KUNENA') . ': ' . Text::_('COM_KUNENA_MENU_STATISTICS'), 'chart');
  140. }
  141. /**
  142. * @param $id
  143. *
  144. * @return mixed|string
  145. * @since Kunena
  146. */
  147. public function getType($id)
  148. {
  149. static $types = array(1 => 'MOD', 2 => 'ACT', 3 => 'ERR', 4 => 'REP');
  150. return isset($types[$id]) ? $types[$id] : '???';
  151. }
  152. /**
  153. * @param $name
  154. *
  155. * @return string
  156. * @since Kunena
  157. */
  158. public function getGroupCheckbox($name)
  159. {
  160. $checked = isset($this->group[$name]) ? ' checked="checked"' : '';
  161. return '<input type="checkbox" name="group_' . $name . '" value="1" title="Group By" ' . $checked . ' class="filter form-control" />';
  162. }
  163. }