STATS.class.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /**
  3. * STATS
  4. *
  5. *
  6. * @author vesta, http://vestacp.com/
  7. * @author Dmitry Malishev <dima.malishev@gmail.com>
  8. * @author Dmitry Naumov-Socolov <naumov.socolov@gmail.com>
  9. * @copyright vesta 2010-2011
  10. */
  11. class STATS extends AjaxHandler
  12. {
  13. const DAILY = 'daily';
  14. const WEEKLY = 'weekly';
  15. const MONTHLY = 'monthly';
  16. const YEARLY = 'yearly';
  17. const RRD_BASE_DIR = '/rrd/';
  18. /**
  19. * Get STATS entries
  20. *
  21. * @param Request $request
  22. * @return string - Ajax Reply
  23. */
  24. public function getListExecute(Request $request)
  25. {
  26. $_period = $request->getParameter('period');
  27. // if stats graph is requested not for today it should be regenerated manually
  28. if($_period && (in_array($_period, array(self::WEEKLY, self::MONTHLY, self::YEARLY)))){
  29. $result = Vesta::execute(Vesta:: V_UPDATE_SYS_RRD, array('PERIOD' => $_period));
  30. if (!$result['status']) {
  31. $this->errors[] = array($result['error_code'] => $result['error_message']);
  32. return $this->reply($result['status'], '');
  33. }
  34. }
  35. else{
  36. $_period = self::DAILY;
  37. }
  38. $result = Vesta::execute(Vesta::V_LIST_SYS_RRD, array('PERIOD' => $_period));
  39. $reply = array();
  40. foreach ($result['data'] as $order => $details) {
  41. $reply[$order] = array(
  42. // 'TYPE' => $details['TYPE'],
  43. // 'RRD' => $details['RRD'],
  44. 'PERIOD' => $_period,
  45. 'SRC' => self::RRD_BASE_DIR.$details['TYPE'].'/'.$_period.'-'.$details['RRD'].'.png',
  46. 'TITLE' => $details['TITLE'].' &nbsp; ('.$_period.')'
  47. );
  48. }
  49. if (!$result['status']) {
  50. $this->errors[] = array($result['error_code'] => $result['error_message']);
  51. }
  52. return $this->reply($result['status'], $reply);
  53. }
  54. }