Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1441 ariadna 1
<?php
2
// This file is part of Moodle - http://moodle.org/
3
//
4
// Moodle is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// Moodle is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
 
17
namespace core_sms;
18
 
19
use core\attribute_helper;
20
 
21
/**
22
 * The general status of a message. Gateways are able to provide more specific statuses to supplement these.
23
 *
24
 * @package    core
25
 * @copyright  2024 Andrew Lyons <andrew@nicols.co.uk>
26
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27
 */
28
enum message_status: string {
29
    #[description('status:unknown', 'core_sms')]
30
    #[status()]
31
    case UNKNOWN = 'unknown';
32
 
33
    #[description('status:message_over_size', 'core_sms')]
34
    #[status(failed: true)]
35
    case MESSAGE_OVER_SIZE = 'message_over_size';
36
 
37
    #[description('status:gateway_not_available', 'core_sms')]
38
    #[status(failed: true)]
39
    case GATEWAY_NOT_AVAILABLE = 'gateway_not_available';
40
 
41
    #[description('status:gateway_queued', 'core_sms')]
42
    #[status(inprogress: true)]
43
    case GATEWAY_QUEUED = 'gateway_queued';
44
 
45
    #[description('status:gateway_sent', 'core_sms')]
46
    #[status(sent: true)]
47
    case GATEWAY_SENT = 'gateway_sent';
48
 
49
    #[description('status:gateway_rejected', 'core_sms')]
50
    #[status(failed: true)]
51
    case GATEWAY_REJECTED = 'gateway_rejected';
52
 
53
    #[description('status:gateway_failed', 'core_sms')]
54
    #[status(failed: true)]
55
    case GATEWAY_FAILED = 'gateway_failed';
56
 
57
    /**
58
     * Whether the message is in a state marked as sent.
59
     *
60
     * @return bool
61
     */
62
    public function is_sent(): bool {
63
        $status = attribute_helper::instance($this, status::class);
64
        return $status?->sent ?? false;
65
    }
66
 
67
    /**
68
     * Whether the message is in a state marked as failed.
69
     *
70
     * @return bool
71
     */
72
    public function is_failed(): bool {
73
        $status = attribute_helper::instance($this, status::class);
74
        return $status?->failed ?? false;
75
    }
76
 
77
    /**
78
     * Whether the message is in an in-progress state.
79
     *
80
     * @return bool
81
     */
82
    public function is_in_progress(): bool {
83
        $status = attribute_helper::instance($this, status::class);
84
        return $status?->inprogress ?? false;
85
    }
86
 
87
    /**
88
     * Get the human-readable status of the message.
89
     *
90
     * @return null|\lang_string
91
     */
92
    public function description(): ?\lang_string {
93
        return attribute_helper::instance($this, description::class);
94
    }
95
}