PageRenderTime 26ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/+modules/AdminQuickEditPro-5.6.0/upload/admin/model/sale/aqe/voucher_theme.php

https://bitbucket.org/DidenkoDima/opta
PHP | 152 lines | 127 code | 25 blank | 0 comment | 78 complexity | fe409873cdb9cf5ab375331496ddaa2c MD5 | raw file
  1. <?php
  2. class ModelSaleAqeVoucherTheme extends Model {
  3. protected static $count = 0;
  4. public function getVoucherThemes($data = array()) {
  5. if (isset($data['columns'])) {
  6. $columns = $data['columns'];
  7. } else {
  8. $columns = array('name');
  9. }
  10. $sql = "SELECT SQL_CALC_FOUND_ROWS vt.*";
  11. if (in_array("name", $columns)) {
  12. $sql .= ", vtd.name AS name";
  13. }
  14. $sql .= " FROM `" . DB_PREFIX . "voucher_theme` vt";
  15. if (in_array("name", $columns)) {
  16. $sql .= " LEFT JOIN " . DB_PREFIX . "voucher_theme_description vtd ON (vt.voucher_theme_id = vtd.voucher_theme_id AND vtd.language_id = '" . (int)$this->config->get('config_language_id') . "')";
  17. }
  18. $where = array();
  19. $int_filters = array(
  20. 'id' => 'vt.voucher_theme_id',
  21. );
  22. foreach ($int_filters as $key => $value) {
  23. if (isset($data["filter_$key"]) && !is_null($data["filter_$key"])) {
  24. $where[] = "$value = '" . (int)$data["filter_$key"] . "'";
  25. }
  26. }
  27. $anywhere_filters = array(
  28. 'name' => 'vtd.name',
  29. );
  30. foreach ($anywhere_filters as $key => $value) {
  31. if (!empty($data["filter_$key"])) {
  32. if ($this->config->get('aqe_match_anywhere')) {
  33. $where[] = "$value LIKE '%" . $this->db->escape($data["filter_$key"]) . "%'";
  34. } else {
  35. $where[] = "$value LIKE '" . $this->db->escape($data["filter_$key"]) . "%'";
  36. }
  37. }
  38. }
  39. if ($where) {
  40. $sql .= " WHERE " . implode($where, " AND ");
  41. }
  42. $sql .= " GROUP BY vt.voucher_theme_id";
  43. $sort_data = array(
  44. 'vt.voucher_theme_id',
  45. 'vtd.name',
  46. );
  47. if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
  48. $sql .= " ORDER BY " . $data['sort'];
  49. } else {
  50. $sql .= " ORDER BY vtd.name";
  51. }
  52. if (isset($data['order']) && ($data['order'] == 'DESC')) {
  53. $sql .= " DESC";
  54. } else {
  55. $sql .= " ASC";
  56. }
  57. if (isset($data['start']) || isset($data['limit'])) {
  58. if ($data['start'] < 0) {
  59. $data['start'] = 0;
  60. }
  61. if ($data['limit'] < 1) {
  62. $data['limit'] = 20;
  63. }
  64. $sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
  65. }
  66. $query = $this->db->query($sql);
  67. $count = $this->db->query("SELECT FOUND_ROWS() AS count");
  68. $this->count = ($count->num_rows) ? (int)$count->row['count'] : 0;
  69. return $query->rows;
  70. }
  71. public function getTotalVoucherThemes() {
  72. return $this->count;
  73. }
  74. public function quickEditVoucherTheme($voucher_theme_id, $column, $value, $lang_id=null, $data=null) {
  75. $editable = array('image');
  76. $result = false;
  77. if (in_array($column, $editable)) {
  78. if ($column == 'image') {
  79. $result = $this->db->query("UPDATE `" . DB_PREFIX . "voucher_theme` SET " . $column . " = '" . $this->db->escape($value) . "' WHERE voucher_theme_id = '" . (int)$voucher_theme_id . "'");
  80. }
  81. } else if ($column == 'name') {
  82. if (isset($data['value']) && is_array($data['value'])) {
  83. foreach ((array)$data['value'] as $language_id => $value) {
  84. $this->db->query("UPDATE " . DB_PREFIX . "voucher_theme_description SET " . $column . " = '" . $this->db->escape($value) . "' WHERE voucher_theme_id = '" . (int)$voucher_theme_id . "' AND language_id = '" . (int)$language_id . "'");
  85. }
  86. $result = 1;
  87. } else if ($value) {
  88. $result = $this->db->query("UPDATE " . DB_PREFIX . "voucher_theme_description SET " . $column . " = '" . $this->db->escape($value) . "' WHERE voucher_theme_id = '" . (int)$voucher_theme_id . "' AND language_id = '" . (int)$lang_id . "'");
  89. $result = 1;
  90. } else {
  91. $result = 0;
  92. }
  93. }
  94. return $result;
  95. }
  96. public function filterInterval($filter, $field, $date=false) {
  97. if ($date) {
  98. if (preg_match('/^(!=|<>)\s*(\d{2,4}-\d{1,2}-\d{1,2})$/', html_entity_decode(trim($filter)), $matches) && count($matches) == 3) {
  99. return "DATE($field) <> DATE('" . $matches[2] . "')";
  100. } else if (preg_match('/^(\d{2,4}-\d{1,2}-\d{1,2})\s*(<|<=)\s*(\d{2,4}-\d{1,2}-\d{1,2})$/', html_entity_decode(trim($filter)), $matches) && count($matches) == 4 && strtotime($matches[1]) <= strtotime($matches[3])) {
  101. return "DATE('" . $matches[1] . "') ${matches[2]} DATE($field) AND DATE($field) ${matches[2]} DATE('" . $matches[3] . "')";
  102. } else if (preg_match('/^(\d{2,4}-\d{1,2}-\d{1,2})\s*(>|>=)\s*(\d{2,4}-\d{1,2}-\d{1,2})$/', html_entity_decode(trim($filter)), $matches) && count($matches) == 4 && strtotime($matches[1]) >= strtotime($matches[3])) {
  103. return "DATE('" . $matches[1] . "') ${matches[2]} DATE($field) AND DATE($field) ${matches[2]} DATE('" . $matches[3] . "')";
  104. } else if (preg_match('/^(<|<=|>|>=)\s*(\d{2,4}-\d{1,2}-\d{1,2})$/', html_entity_decode(trim($filter)), $matches) && count($matches) == 3) {
  105. return "DATE($field) ${matches[1]} DATE('" . $matches[2] . "')";
  106. } else if (preg_match('/^(\d{2,4}-\d{1,2}-\d{1,2})\s*(>|>=|<|<=)$/', html_entity_decode(trim($filter)), $matches) && count($matches) == 3) {
  107. return "DATE('" . $matches[1] . "') ${matches[2]} DATE($field)";
  108. } else {
  109. return "DATE(${field}) = DATE('${filter}')";
  110. }
  111. } else {
  112. if (preg_match('/^(!=|<>)\s*(-?\d+\.?\d*)$/', html_entity_decode(trim(str_replace(",", ".", $filter))), $matches) && count($matches) == 3) {
  113. return "$field <> '" . (float)$matches[2] . "'";
  114. } else if (preg_match('/^(-?\d+\.?\d*)\s*(<|<=)\s*(-?\d+\.?\d*)$/', html_entity_decode(trim(str_replace(",", ".", $filter))), $matches) && count($matches) == 4 && (float)$matches[1] <= (float)$matches[3]) {
  115. return "'" . (float)$matches[1] . "' ${matches[2]} $field AND $field ${matches[2]} '" . (float)$matches[3] . "'";
  116. } else if (preg_match('/^(-?\d+\.?\d*)\s*(>|>=)\s*(-?\d+\.?\d*)$/', html_entity_decode(trim(str_replace(",", ".", $filter))), $matches) && count($matches) == 4 && (float)$matches[1] >= (float)$matches[3]) {
  117. return "'" . (float)$matches[1] . "' ${matches[2]} $field AND $field ${matches[2]} '" . (float)$matches[3] . "'";
  118. } else if (preg_match('/^(<|<=|>|>=)\s*(-?\d+\.?\d*)$/', html_entity_decode(trim(str_replace(",", ".", $filter))), $matches) && count($matches) == 3) {
  119. return "$field ${matches[1]} '" . (float)$matches[2] . "'";
  120. } else if (preg_match('/^(-?\d+\.?\d*)\s*(>|>=|<|<=)$/', html_entity_decode(trim(str_replace(",", ".", $filter))), $matches) && count($matches) == 3) {
  121. return "'" . (float)$matches[1] . "' ${matches[2]} $field";
  122. } else {
  123. return $field . " = '" . $this->db->escape($filter) . "'";
  124. }
  125. }
  126. }
  127. }