1: | <?php
2: | namespace Opencart\Catalog\Model\Account;
3: | /**
4: | * Class Download
5: | *
6: | * @package Opencart\Catalog\Model\Account
7: | */
8: | class Download extends \Opencart\System\Engine\Model {
9: | /**
10: | * Get Download
11: | *
12: | * @param int $download_id
13: | *
14: | * @return array<string, mixed>
15: | */
16: | public function getDownload(int $download_id): array {
17: | $implode = [];
18: |
19: | $order_statuses = (array)$this->config->get('config_complete_status');
20: |
21: | foreach ($order_statuses as $order_status_id) {
22: | $implode[] = "`o`.`order_status_id` = '" . (int)$order_status_id . "'";
23: | }
24: |
25: | if ($implode) {
26: | $query = $this->db->query("SELECT `d`.`filename`, `d`.`mask` FROM `" . DB_PREFIX . "order` `o` LEFT JOIN `" . DB_PREFIX . "order_product` `op` ON (`o`.`order_id` = `op`.`order_id`) LEFT JOIN `" . DB_PREFIX . "product_to_download` `p2d` ON (`op`.`product_id` = `p2d`.`product_id`) LEFT JOIN `" . DB_PREFIX . "download` `d` ON (`p2d`.`download_id` = `d`.`download_id`) WHERE `o`.`customer_id` = '" . (int)$this->customer->getId() . "' AND (" . implode(" OR ", $implode) . ") AND `d`.`download_id` = '" . (int)$download_id . "'");
27: |
28: | return $query->row;
29: | }
30: |
31: | return [];
32: | }
33: |
34: | /**
35: | * Get Downloads
36: | *
37: | * @param int $start
38: | * @param int $limit
39: | *
40: | * @return array<int, array<string, mixed>>
41: | */
42: | public function getDownloads(int $start = 0, int $limit = 20): array {
43: | if ($start < 0) {
44: | $start = 0;
45: | }
46: |
47: | if ($limit < 1) {
48: | $limit = 20;
49: | }
50: |
51: | $implode = [];
52: |
53: | $order_statuses = (array)$this->config->get('config_complete_status');
54: |
55: | foreach ($order_statuses as $order_status_id) {
56: | $implode[] = "`o`.`order_status_id` = '" . (int)$order_status_id . "'";
57: | }
58: |
59: | if ($implode) {
60: | $query = $this->db->query("SELECT DISTINCT `d`.`download_id`, `o`.`order_id`, `o`.`date_added`, `dd`.`name`, `d`.`filename` FROM `" . DB_PREFIX . "order` `o` LEFT JOIN `" . DB_PREFIX . "order_product` `op` ON (`o`.`order_id` = `op`.`order_id`) LEFT JOIN `" . DB_PREFIX . "product_to_download` `p2d` ON (`op`.`product_id` = `p2d`.`product_id`) LEFT JOIN `" . DB_PREFIX . "download` `d` ON (`p2d`.`download_id` = `d`.`download_id`) LEFT JOIN `" . DB_PREFIX . "download_description` `dd` ON (`d`.`download_id` = `dd`.`download_id`) WHERE `o`.`customer_id` = '" . (int)$this->customer->getId() . "' AND `o`.`store_id` = '" . (int)$this->config->get('config_store_id') . "' AND (" . implode(" OR ", $implode) . ") AND `dd`.`language_id` = '" . (int)$this->config->get('config_language_id') . "' ORDER BY `dd`.`name` ASC LIMIT " . (int)$start . "," . (int)$limit);
61: |
62: | return $query->rows;
63: | }
64: |
65: | return [];
66: | }
67: |
68: | /**
69: | * Get Total Downloads
70: | *
71: | * @return int
72: | */
73: | public function getTotalDownloads(): int {
74: | $implode = [];
75: |
76: | $order_statuses = (array)$this->config->get('config_complete_status');
77: |
78: | foreach ($order_statuses as $order_status_id) {
79: | $implode[] = "`o`.`order_status_id` = '" . (int)$order_status_id . "'";
80: | }
81: |
82: | if ($implode) {
83: | $query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "order` `o` LEFT JOIN `" . DB_PREFIX . "order_product` `op` ON (`o`.`order_id` = `op`.`order_id`) LEFT JOIN `" . DB_PREFIX . "product_to_download` `p2d` ON (`op`.`product_id` = `p2d`.`product_id`) WHERE `o`.`customer_id` = '" . (int)$this->customer->getId() . "' AND `o`.`store_id` = '" . (int)$this->config->get('config_store_id') . "' AND (" . implode(" OR ", $implode) . ") AND `p2d`.`download_id` > 0");
84: |
85: | return $query->row['total'];
86: | }
87: |
88: | return 0;
89: | }
90: |
91: | /**
92: | * Add Report
93: | *
94: | * @param int $download_id
95: | * @param string $ip
96: | * @param string $country
97: | *
98: | * @return void
99: | */
100: | public function addReport(int $download_id, string $ip, string $country = ''): void {
101: | $this->db->query("INSERT INTO `" . DB_PREFIX . "download_report` SET `download_id` = '" . (int)$download_id . "', `store_id` = '" . (int)$this->config->get('config_store_id') . "', `ip` = '" . $this->db->escape($ip) . "', `country` = '" . $this->db->escape($country) . "', `date_added` = NOW()");
102: | }
103: | }
104: |

OpenCart API API documentation generated by ApiGen dev-master