PageRenderTime 45ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/library/bdPaygate/Model/Log.php

https://github.com/xfoso/bdPaygates
PHP | 182 lines | 135 code | 37 blank | 10 comment | 25 complexity | b0064ad837b22468b77906f78372b073 MD5 | raw file
  1. <?php
  2. class bdPaygate_Model_Log extends XenForo_Model {
  3. /* Start auto-generated lines of code. Change made will be overwriten... */
  4. public function getList(array $conditions = array(), array $fetchOptions = array()) {
  5. $data = $this->getLogs($conditions, $fetchOptions);
  6. $list = array();
  7. foreach ($data as $id => $row) {
  8. $list[$id] = $row['processor'];
  9. }
  10. return $list;
  11. }
  12. public function getLogById($id, array $fetchOptions = array()) {
  13. $data = $this->getLogs(array ('log_id' => $id), $fetchOptions);
  14. return reset($data);
  15. }
  16. public function getLogs(array $conditions = array(), array $fetchOptions = array()) {
  17. $whereConditions = $this->prepareLogConditions($conditions, $fetchOptions);
  18. $orderClause = $this->prepareLogOrderOptions($fetchOptions);
  19. $joinOptions = $this->prepareLogFetchOptions($fetchOptions);
  20. $limitOptions = $this->prepareLimitFetchOptions($fetchOptions);
  21. $all = $this->fetchAllKeyed($this->limitQueryResults("
  22. SELECT log.*
  23. $joinOptions[selectFields]
  24. FROM `xf_bdpaygate_log` AS log
  25. $joinOptions[joinTables]
  26. WHERE $whereConditions
  27. $orderClause
  28. ", $limitOptions['limit'], $limitOptions['offset']
  29. ), 'log_id');
  30. $this->_getLogsCustomized($all, $fetchOptions);
  31. return $all;
  32. }
  33. public function countLogs(array $conditions = array(), array $fetchOptions = array()) {
  34. $whereConditions = $this->prepareLogConditions($conditions, $fetchOptions);
  35. $orderClause = $this->prepareLogOrderOptions($fetchOptions);
  36. $joinOptions = $this->prepareLogFetchOptions($fetchOptions);
  37. $limitOptions = $this->prepareLimitFetchOptions($fetchOptions);
  38. return $this->_getDb()->fetchOne("
  39. SELECT COUNT(*)
  40. FROM `xf_bdpaygate_log` AS log
  41. $joinOptions[joinTables]
  42. WHERE $whereConditions
  43. ");
  44. }
  45. public function prepareLogConditions(array $conditions = array(), array $fetchOptions = array()) {
  46. $sqlConditions = array();
  47. $db = $this->_getDb();
  48. if (isset($conditions['log_id'])) {
  49. if (is_array($conditions['log_id'])) {
  50. if (!empty($conditions['log_id'])) {
  51. // only use IN condition if the array is not empty (nasty!)
  52. $sqlConditions[] = "log.log_id IN (" . $db->quote($conditions['log_id']) . ")";
  53. }
  54. } else {
  55. $sqlConditions[] = "log.log_id = " . $db->quote($conditions['log_id']);
  56. }
  57. }
  58. if (isset($conditions['processor'])) {
  59. if (is_array($conditions['processor'])) {
  60. if (!empty($conditions['processor'])) {
  61. // only use IN condition if the array is not empty (nasty!)
  62. $sqlConditions[] = "log.processor IN (" . $db->quote($conditions['processor']) . ")";
  63. }
  64. } else {
  65. $sqlConditions[] = "log.processor = " . $db->quote($conditions['processor']);
  66. }
  67. }
  68. if (isset($conditions['transaction_id'])) {
  69. if (is_array($conditions['transaction_id'])) {
  70. if (!empty($conditions['transaction_id'])) {
  71. // only use IN condition if the array is not empty (nasty!)
  72. $sqlConditions[] = "log.transaction_id IN (" . $db->quote($conditions['transaction_id']) . ")";
  73. }
  74. } else {
  75. $sqlConditions[] = "log.transaction_id = " . $db->quote($conditions['transaction_id']);
  76. }
  77. }
  78. if (isset($conditions['log_type'])) {
  79. if (is_array($conditions['log_type'])) {
  80. if (!empty($conditions['log_type'])) {
  81. // only use IN condition if the array is not empty (nasty!)
  82. $sqlConditions[] = "log.log_type IN (" . $db->quote($conditions['log_type']) . ")";
  83. }
  84. } else {
  85. $sqlConditions[] = "log.log_type = " . $db->quote($conditions['log_type']);
  86. }
  87. }
  88. if (isset($conditions['log_message'])) {
  89. if (is_array($conditions['log_message'])) {
  90. if (!empty($conditions['log_message'])) {
  91. // only use IN condition if the array is not empty (nasty!)
  92. $sqlConditions[] = "log.log_message IN (" . $db->quote($conditions['log_message']) . ")";
  93. }
  94. } else {
  95. $sqlConditions[] = "log.log_message = " . $db->quote($conditions['log_message']);
  96. }
  97. }
  98. if (isset($conditions['log_date'])) {
  99. if (is_array($conditions['log_date'])) {
  100. if (!empty($conditions['log_date'])) {
  101. // only use IN condition if the array is not empty (nasty!)
  102. $sqlConditions[] = "log.log_date IN (" . $db->quote($conditions['log_date']) . ")";
  103. }
  104. } else {
  105. $sqlConditions[] = "log.log_date = " . $db->quote($conditions['log_date']);
  106. }
  107. }
  108. $this->_prepareLogConditionsCustomized($sqlConditions, $conditions, $fetchOptions);
  109. return $this->getConditionsForClause($sqlConditions);
  110. }
  111. public function prepareLogFetchOptions(array $fetchOptions = array()) {
  112. $selectFields = '';
  113. $joinTables = '';
  114. $this->_prepareLogFetchOptionsCustomized($selectFields, $joinTables, $fetchOptions);
  115. return array(
  116. 'selectFields' => $selectFields,
  117. 'joinTables' => $joinTables
  118. );
  119. }
  120. public function prepareLogOrderOptions(array $fetchOptions = array(), $defaultOrderSql = '') {
  121. $choices = array(
  122. );
  123. $this->_prepareLogOrderOptionsCustomized($choices, $fetchOptions);
  124. return $this->getOrderByClause($choices, $fetchOptions, $defaultOrderSql);
  125. }
  126. /* End auto-generated lines of code. Feel free to make changes below */
  127. protected function _getLogsCustomized(array &$data, array $fetchOptions) {
  128. foreach ($data as &$entry) {
  129. $entry['logDetails'] = @unserialize($entry['log_details']);
  130. if (empty($entry['logDetails'])) $entry['logDetails'] = array();
  131. }
  132. }
  133. protected function _prepareLogConditionsCustomized(array &$sqlConditions, array $conditions, array $fetchOptions) {
  134. // customized code goes here
  135. }
  136. protected function _prepareLogFetchOptionsCustomized(&$selectFields, &$joinTables, array $fetchOptions) {
  137. // customized code goes here
  138. }
  139. protected function _prepareLogOrderOptionsCustomized(array &$choices, array &$fetchOptions) {
  140. $choices['log_id'] = 'log.log_id';
  141. }
  142. public function clearLog() {
  143. $this->_getDb()->query('TRUNCATE TABLE xf_bdpaygate_log');
  144. }
  145. }