Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

dashboardController.php 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. class dashboardController extends mainController {
  3. private $dashboardPageLimit;
  4. function __construct() {
  5. parent::__construct();
  6. $this->dashboardPageLimit = 5;
  7. //To change for every Controller
  8. $this->viewDir = 'Dashboard';
  9. //$this->allow = [];
  10. }
  11. public function index($args=null) {
  12. if (!$this->user->isLogged()) {
  13. return $this->redirect('login', 'permissionDenied');
  14. }
  15. $this->view->userData = $this->user->getUser();
  16. $this->view->showRoleLabel = count($this->view->userData['userRolesLocale']) > 1 ? true : false; //Statistics
  17. $this->showBreadcrumbs = false;
  18. return $this->setJsonView('index');
  19. }
  20. public function indexNoPrivacy() {
  21. return $this->setJsonView('indexNoPrivacy');
  22. }
  23. //Last sessions on Dashboard for administrator
  24. public function loadLastSessions() {
  25. if(!$this->checkPermissions([ADMIN_ROLE_ID])) {
  26. return $this->redirect('login', 'permissionDenied');
  27. }
  28. $userGroupId = $this->user->getUserField('userGroupId');
  29. $page = 1;
  30. $this->db->pageLimit = $this->dashboardPageLimit;
  31. $sessions = $this->db
  32. ->join('users u', 'u.id=s.user_id', 'INNER')
  33. ->where('s.user_id', 0, '>')
  34. ->where('u.group_id', $userGroupId)
  35. ->orderBy('s.session_updated_at', 'DESC')
  36. ->paginate('sessions s', $page, ['s.*', 'u.surname', 'u.name', 'u.updated_at']);
  37. $this->view->sessions = $sessions;
  38. return $this->setJsonView('loadLastSessions');
  39. }
  40. public function loadLastSubscriptions() {
  41. if(!$this->checkPermissions([ADMIN_ROLE_ID])) {
  42. return $this->redirect('login', 'permissionDenied');
  43. }
  44. $userGroupId = $this->user->getUserField('userGroupId');
  45. $page = 1;
  46. $this->db->pageLimit = $this->dashboardPageLimit;
  47. $this->view->usersList = $this->db->where('group_id', $userGroupId)->orderBy('created_at', 'DESC')->paginate('users', $page);
  48. return $this->setJsonView('loadLastSubscriptions');
  49. }
  50. public function loadLastAccesses() {
  51. if(!$this->checkPermissions([ADMIN_ROLE_ID])) {
  52. return $this->redirect('login', 'permissionDenied');
  53. }
  54. $userGroupId = $this->user->getUserField('userGroupId');
  55. $page = 1;
  56. $this->db->pageLimit = $this->dashboardPageLimit;
  57. $accesses = $this->db
  58. ->join('users u', 'u.id=a.user_id', 'INNER')
  59. ->where('a.user_id', 0, '>')
  60. ->where('u.group_id', $userGroupId)
  61. ->orderBy('a.created_at', 'DESC')
  62. ->paginate('log_access a', $page, ['a.*', 'a.created_at AS access_date', 'u.username', 'u.surname', 'u.name', 'u.updated_at AS user_updated_at']);
  63. $this->view->accesses = $accesses;
  64. return $this->setJsonView('loadLastAccesses');
  65. }
  66. public function loadStatistics() {
  67. $roleId = $this->getPost('roleId', 0);
  68. if(!$this->checkPermissions([ADMIN_ROLE_ID, MODERATOR_ROLE_ID, REFERRER_ROLE_ID, APPLICANT_ROLE_ID, GUEST_ROLE_ID])) {
  69. return $this->redirect('login', 'permissionDenied');
  70. }
  71. $handleRequest = new HandleRequest();
  72. $triageData = $handleRequest->getStatistics('triage_color', $roleId, $this);
  73. $statusData = $handleRequest->getStatistics('request_status', $roleId, $this);
  74. $this->view->statData = $statusData;
  75. $this->view->roleId = $roleId;
  76. $this->view->triageQty = array_sum($triageData['values']);
  77. $this->view->statusQty = array_sum($statusData['values']);
  78. //return $this->setJsonView('loadStatistics');
  79. $html = $this->partial('Dashboard/statistics-charts');
  80. return $this->setRawJsonResponse('ok', '', ['html'=>$html, 'chartTitle'=>'',
  81. 'barTriageLabels'=>$triageData['labelsValues'],
  82. 'pieTriageLabels'=>$triageData['labelsPerc'],
  83. 'TriageColors'=>$triageData['colors'],
  84. 'TriageBorders'=>$triageData['borders'],
  85. 'TriageValues'=>$triageData['values'],
  86. 'TriagePerc'=>$triageData['perc'],
  87. 'barStatusLabels'=>$statusData['labelsValues'],
  88. 'pieStatusLabels'=>$statusData['labelsPerc'],
  89. 'StatusColors'=>$statusData['colors'],
  90. 'StatusBorders'=>$statusData['borders'],
  91. 'StatusValues'=>$statusData['values'],
  92. 'StatusPerc'=>$statusData['perc'],
  93. ]);
  94. }
  95. public function allowAccess() {
  96. if (!$this->user->isLogged()) {
  97. return $this->redirect('login', 'index', ['jsRedirect'=>'/']);
  98. }
  99. return false;
  100. }
  101. }