docs/api/source-admin.model.setting.cron.html
| 1: | <?php |
| 2: | namespace Opencart\Admin\Model\Setting; |
| 3: | /** |
| 4: | * Class Cron |
| 5: | * |
| 6: | * @package Opencart\Admin\Model\Setting |
| 7: | */ |
| 8: | class Cron extends \Opencart\System\Engine\Model { |
| 9: | /** |
| 10: | * Add Cron |
| 11: | * |
| 12: | * @param string $code |
| 13: | * @param string $description |
| 14: | * @param string $cycle |
| 15: | * @param string $action |
| 16: | * @param bool $status |
| 17: | * |
| 18: | * @return int |
| 19: | */ |
| 20: | public function addCron(string $code, string $description, string $cycle, string $action, bool $status): int { |
| 21: | $this->db->query("INSERT INTO " . DB\_PREFIX . "cron SET code = '" . $this->db->escape($code) . "', description = '" . $this->db->escape($description) . "', cycle = '" . $this->db->escape($cycle) . "', action = '" . $this->db->escape($action) . "', status = '" . (int)$status . "', date_added = NOW(), date_modified = NOW()"); |
| 22: | |
| 23: | return $this->db->getLastId(); |
| 24: | } |
| 25: | |
| 26: | /** |
| 27: | * Delete Cron |
| 28: | * |
| 29: | * @param int $cron_id |
| 30: | * |
| 31: | * @return void |
| 32: | */ |
| 33: | public function deleteCron(int $cron_id): void { |
| 34: | $this->db->query("DELETE FROM " . DB\_PREFIX . "cron WHERE cron\_id = '" . (int)$cron_id . "'"); |
| 35: | } |
| 36: | |
| 37: | /** |
| 38: | * Delete Cron By Code |
| 39: | * |
| 40: | * @param string $code |
| 41: | * |
| 42: | * @return void |
| 43: | */ |
| 44: | public function deleteCronByCode(string $code): void { |
| 45: | $this->db->query("DELETE FROM " . DB\_PREFIX . "cron WHERE code = '" . $this->db->escape($code) . "'"); |
| 46: | } |
| 47: | |
| 48: | /** |
| 49: | * Edit Cron |
| 50: | * |
| 51: | * @param int $cron_id |
| 52: | * |
| 53: | * @return void |
| 54: | */ |
| 55: | public function editCron(int $cron_id): void { |
| 56: | $this->db->query("UPDATE " . DB\_PREFIX . "cron SET date\_modified = NOW() WHERE cron\_id = '" . (int)$cron_id . "'"); |
| 57: | } |
| 58: | |
| 59: | /** |
| 60: | * Edit Status |
| 61: | * |
| 62: | * @param int $cron_id |
| 63: | * @param bool $status |
| 64: | * |
| 65: | * @return void |
| 66: | */ |
| 67: | public function editStatus(int $cron_id, bool $status): void { |
| 68: | $this->db->query("UPDATE " . DB\_PREFIX . "cron SET status = '" . (bool)$status . "' WHERE cron_id = '" . (int)$cron_id . "'"); |
| 69: | } |
| 70: | |
| 71: | /** |
| 72: | * Get Cron |
| 73: | * |
| 74: | * @param int $cron_id |
| 75: | * |
| 76: | * @return array<string, mixed> |
| 77: | */ |
| 78: | public function getCron(int $cron_id): array { |
| 79: | $query = $this->db->query("SELECT DISTINCT * FROM " . DB\_PREFIX . "cron WHERE cron\_id = '" . (int)$cron_id . "'"); |
| 80: | |
| 81: | return $query->row; |
| 82: | } |
| 83: | |
| 84: | /** |
| 85: | * Get Cron By Code |
| 86: | * |
| 87: | * @param string $code |
| 88: | * |
| 89: | * @return array<string, mixed> |
| 90: | */ |
| 91: | public function getCronByCode(string $code): array { |
| 92: | $query = $this->db->query("SELECT DISTINCT * FROM " . DB\_PREFIX . "cron WHERE code = '" . $this->db->escape($code) . "' LIMIT 1"); |
| 93: | |
| 94: | return $query->row; |
| 95: | } |
| 96: | |
| 97: | /** |
| 98: | * Get Cron(s) |
| 99: | * |
| 100: | * @param array<string, mixed> $data |
| 101: | * |
| 102: | * @return array<int, array<string, mixed>> |
| 103: | */ |
| 104: | public function getCrons(array $data = []): array { |
| 105: | $sql = "SELECT * FROM " . DB\_PREFIX . "cron"; |
| 106: | |
| 107: | $sort_data = [ |
| 108: | 'code', |
| 109: | 'cycle', |
| 110: | 'action', |
| 111: | 'status', |
| 112: | 'date_added', |
| 113: | 'date_modified' |
| 114: | ]; |
| 115: | |
| 116: | if (isset($data['sort']) && in_array($data['sort'], $sort_data)) { |
| 117: | $sql .= " ORDER BY " . $data['sort']; |
| 118: | } else { |
| 119: | $sql .= " ORDER BY date_added"; |
| 120: | } |
| 121: | |
| 122: | if (isset($data['order']) && ($data['order'] == 'DESC')) { |
| 123: | $sql .= " DESC"; |
| 124: | } else { |
| 125: | $sql .= " ASC"; |
| 126: | } |
| 127: | |
| 128: | if (isset($data['start']) || isset($data['limit'])) { |
| 129: | if ($data['start'] < 0) { |
| 130: | $data['start'] = 0; |
| 131: | } |
| 132: | |
| 133: | if ($data['limit'] < 1) { |
| 134: | $data['limit'] = 20; |
| 135: | } |
| 136: | |
| 137: | $sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit']; |
| 138: | } |
| 139: | |
| 140: | $query = $this->db->query($sql); |
| 141: | |
| 142: | return $query->rows; |
| 143: | } |
| 144: | |
| 145: | /** |
| 146: | * Get Total Cron(s) |
| 147: | * |
| 148: | * @return int |
| 149: | */ |
| 150: | public function getTotalCrons(): int { |
| 151: | $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB\_PREFIX . "cron"); |
| 152: | |
| 153: | return (int)$query->row['total']; |
| 154: | } |
| 155: | } |
| 156: | |
OpenCart API API documentation generated by ApiGen dev-master