1: | <?php
2: | namespace Opencart\Catalog\Model\Setting;
3: | /**
4: | * Class Api
5: | *
6: | * @package Opencart\Catalog\Model\Setting
7: | */
8: | class Api extends \Opencart\System\Engine\Model {
9: | /**
10: | * Login
11: | *
12: | * @param string $username
13: | * @param string $key
14: | *
15: | * @return array<string, mixed>
16: | */
17: | public function login(string $username, string $key): array {
18: | $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "api` `a` LEFT JOIN `" . DB_PREFIX . "api_ip` `ai` ON (`a`.`api_id` = `ai`.`api_id`) WHERE `a`.`username` = '" . $this->db->escape($username) . "' AND `a`.`key` = '" . $this->db->escape($key) . "'");
19: |
20: | return $query->row;
21: | }
22: |
23: | /**
24: | * Get Api By Token
25: | *
26: | * @param string $token
27: | *
28: | * @return array<string, mixed>
29: | */
30: | public function getApiByToken(string $token): array {
31: | $query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "api` `a` LEFT JOIN `" . DB_PREFIX . "api_session` `as` ON (`a`.`api_id` = `as`.`api_id`) LEFT JOIN `" . DB_PREFIX . "api_ip` `ai` ON (`a`.`api_id` = `ai`.`api_id`) WHERE `a`.`status` = '1' AND `as`.`session_id` = '" . $this->db->escape($token) . "' AND `ai`.`ip` = '" . $this->db->escape($this->request->server['REMOTE_ADDR']) . "'");
32: |
33: | return $query->row;
34: | }
35: |
36: | /**
37: | * Get Sessions
38: | *
39: | * @param int $api_id
40: | *
41: | * @return array<int, array<string, mixed>>
42: | */
43: | public function getSessions(int $api_id): array {
44: | $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "api_session` WHERE TIMESTAMPADD(HOUR, 1, `date_modified`) < NOW() AND `api_id` = '" . (int)$api_id . "'");
45: |
46: | return $query->rows;
47: | }
48: |
49: | /**
50: | * Delete API Sessions
51: | *
52: | * @param int $api_id
53: | *
54: | * @return array<int, array<string, mixed>>
55: | */
56: | public function deleteSessions(int $api_id): array {
57: | $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "api_session` WHERE TIMESTAMPADD(HOUR, 1, `date_modified`) < NOW() AND `api_id` = '" . (int)$api_id . "'");
58: |
59: | return $query->rows;
60: | }
61: |
62: | /**
63: | * Update Session
64: | *
65: | * @param string $api_session_id
66: | *
67: | * @return void
68: | */
69: | public function updateSession(string $api_session_id): void {
70: | // keep the session alive
71: | $this->db->query("UPDATE `" . DB_PREFIX . "api_session` SET `date_modified` = NOW() WHERE `api_session_id` = '" . (int)$api_session_id . "'");
72: | }
73: |
74: | /**
75: | * Clean API Sessions
76: | *
77: | * @return void
78: | */
79: | public function cleanSessions(): void {
80: | $this->db->query("DELETE FROM `" . DB_PREFIX . "api_session` WHERE TIMESTAMPADD(HOUR, 1, `date_modified`) < NOW()");
81: | }
82: | }
83: |

OpenCart API API documentation generated by ApiGen dev-master