PageRenderTime 43ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/dmAdminPlugin/lib/view/html/log/dmLogView.php

http://github.com/diem-project/diem
PHP | 119 lines | 95 code | 24 blank | 0 comment | 1 complexity | 1f4f50cb04cff0fdd2ec8d72fa02ebe6 MD5 | raw file
Possible License(s): BSD-3-Clause, MIT, ISC
  1. <?php
  2. abstract class dmLogView extends dmConfigurable
  3. {
  4. protected
  5. $log,
  6. $i18n,
  7. $user,
  8. $helper,
  9. $dateFormat,
  10. $maxEntries = 10,
  11. $entries;
  12. public function __construct(dmLog $log, dmI18n $i18n, dmCoreUser $user, dmHelper $helper, array $options = array())
  13. {
  14. $this->log = $log;
  15. $this->i18n = $i18n;
  16. $this->user = $user;
  17. $this->helper = $helper;
  18. $this->initialize($options);
  19. }
  20. public function getDefaultOptions()
  21. {
  22. return array(
  23. 'show_ip' => true
  24. );
  25. }
  26. protected function initialize(array $options)
  27. {
  28. $this->configure($options);
  29. $this->dateFormat = new sfDateFormat($this->user->getCulture());
  30. }
  31. public function setMax($max)
  32. {
  33. $this->maxEntries = $max;
  34. $this->entries = null;
  35. return $this;
  36. }
  37. public function render()
  38. {
  39. return
  40. $this->renderHead().
  41. '<tbody>'.$this->renderBody().'</tbody>'.
  42. $this->renderFoot();
  43. }
  44. public function renderEmpty()
  45. {
  46. return
  47. $this->renderHead().
  48. '<tbody></tbody>'.
  49. $this->renderFoot();
  50. }
  51. public function renderHead()
  52. {
  53. $html = '<table>';
  54. return $html;
  55. }
  56. public function renderBody()
  57. {
  58. $html = '';
  59. foreach($this->getEntries() as $index => $entry)
  60. {
  61. $html .= '<tr class="'.($index%2 ? 'odd' : 'even').'">';
  62. foreach($this->rows as $name => $method)
  63. {
  64. $html .= '<td>'.$this->$method($entry).'</td>';
  65. }
  66. $html .= '</tr>';
  67. }
  68. return $html;
  69. }
  70. protected function renderIp($ip)
  71. {
  72. if ($this->getOption('show_ip'))
  73. {
  74. return $ip;
  75. }
  76. $ipParts = explode('.', $ip);
  77. return 4 === count($ipParts) ? $ipParts[0].'.'.$ipParts[1].'.xx.xx' : $ip;
  78. }
  79. protected function getEntries(array $options = array())
  80. {
  81. return $this->doGetEntries($options);
  82. }
  83. public function getHash()
  84. {
  85. return substr(md5(serialize($this->getEntries(array('hydrate' => false)))), -6);
  86. }
  87. protected function doGetEntries(array $options)
  88. {
  89. return $this->log->getEntries($this->maxEntries, $options);
  90. }
  91. public function renderFoot()
  92. {
  93. return '</table>';
  94. }
  95. }