File: //home/retile.ru/public_html/admin/model/extension/module/aqe/catalog/download.php
<?php
include_once __DIR__ . '/../general.php';
class ModelExtensionModuleAqeCatalogDownload extends ModelExtensionModuleAqeGeneral {
protected static $count = 0;
public function getDownloads($data = array()) {
if (isset($data['columns'])) {
$columns = $data['columns'];
} else {
$columns = array('name', 'date_added');
}
$sql = "SELECT SQL_CALC_FOUND_ROWS d.*, dd.* FROM " . DB_PREFIX . "download d LEFT JOIN " . DB_PREFIX . "download_description dd ON (d.download_id = dd.download_id AND dd.language_id = '" . (int)$this->config->get('config_language_id') . "')";
$where = array();
$int_filters = array(
'id' => 'd.download_id',
);
foreach ($int_filters as $key => $value) {
if (isset($data["filter_$key"]) && !is_null($data["filter_$key"])) {
$where[] = "$value = '" . (int)$data["filter_$key"] . "'";
}
}
$int_interval_filters = array(
);
foreach ($int_interval_filters as $key => $value) {
if (isset($data["filter_$key"]) && !is_null($data["filter_$key"])) {
if ($this->config->get('module_admin_quick_edit_interval_filter')) {
$where[] = $this->filterInterval($data["filter_$key"], $value);
} else {
$where[] = "$value = '" . (int)$data["filter_$key"] . "'";
}
}
}
$date_filters = array(
'date_added' => 'd.date_added',
);
foreach ($date_filters as $key => $value) {
if (isset($data["filter_$key"]) && !is_null($data["filter_$key"])) {
if ($this->config->get('module_admin_quick_edit_interval_filter')) {
$where[] = $this->filterInterval($this->db->escape($data["filter_$key"]), $value, true);
} else {
$where[] = "DATE($value) = DATE('" . $this->db->escape($data["filter_$key"]) . "')";
}
}
}
$anywhere_filters = array(
'name' => 'dd.name',
'mask' => 'd.mask',
'filename' => 'd.filename',
);
foreach ($anywhere_filters as $key => $value) {
if (!empty($data["filter_$key"])) {
if ($this->config->get('module_admin_quick_edit_match_anywhere')) {
$tokens = preg_split("/\s+/", trim($data["filter_$key"]));
foreach ($tokens as $token) {
$where[] = "$value LIKE '%" . $this->db->escape($token) . "%'";
}
} else {
$where[] = "$value LIKE '" . $this->db->escape($data["filter_$key"]) . "%'";
}
}
}
if ($where) {
$sql .= " WHERE " . implode(" AND ", $where);
}
$sql .= " GROUP BY d.download_id";
$sort_data = array(
'd.download_id',
'dd.name',
'd.mask',
'd.filename',
'd.date_added',
);
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
$sql .= " ORDER BY " . $data['sort'];
} else {
$sql .= " ORDER BY dd.name";
}
if (isset($data['order']) && ($data['order'] == 'DESC')) {
$sql .= " DESC";
} else {
$sql .= " ASC";
}
if (isset($data['start']) || isset($data['limit'])) {
if ($data['start'] < 0) {
$data['start'] = 0;
}
if ($data['limit'] < 1) {
$data['limit'] = 20;
}
$sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
}
$query = $this->db->query($sql);
$count = $this->db->query("SELECT FOUND_ROWS() AS count");
$this->count = ($count->num_rows) ? (int)$count->row['count'] : 0;
return $query->rows;
}
public function getTotalDownloads() {
return $this->count;
}
public function quickEditDownload($download_id, $column, $value, $lang_id=null, $data=null) {
$editable = array('mask');
$result = false;
if (in_array($column, $editable)) {
$result = $this->db->query("UPDATE " . DB_PREFIX . "download SET " . $column . " = '" . $this->db->escape($value) . "' WHERE download_id = '" . (int)$download_id . "'");
} else if (in_array($column, array('name'))) {
if (isset($data['value']) && is_array($data['value'])) {
foreach ((array)$data['value'] as $language_id => $value) {
$this->db->query("UPDATE " . DB_PREFIX . "download_description SET " . $column . " = '" . $this->db->escape($value) . "' WHERE download_id = '" . (int)$download_id . "' AND language_id = '" . (int)$language_id . "'");
}
$result = 1;
} else if ($value) {
$result = $this->db->query("UPDATE " . DB_PREFIX . "download_description SET " . $column . " = '" . $this->db->escape($value) . "' WHERE download_id = '" . (int)$download_id . "' AND language_id = '" . (int)$lang_id . "'");
$result = 1;
} else {
$result = 0;
}
}
return $result;
}
}