dbXapp
2.0
RAD, CMS, Module und Runtime-IDE fuer dbXapp
Toggle main menu visibility
Loading...
Searching...
No Matches
dbxContactTicket.class.php
Go to the documentation of this file.
1
<?php
2
namespace
dbx\dbxContact;
3
4
class
dbxContactTicket
{
5
6
public
const
DD_TICKET
=
'dbxContact|contactRequest'
;
7
public
const
DD_MESSAGE
=
'dbxContact|contactMessage'
;
8
9
public
static
function
statuses
(): array {
10
return array(
11
'open'
=>
'Offen'
,
12
'in_progress'
=>
'In Bearbeitung'
,
13
'waiting_customer'
=>
'Rueckfrage'
,
14
'answered'
=>
'Beantwortet'
,
15
'closed'
=>
'Geschlossen'
,
16
);
17
}
18
19
public
static
function
priorities
(): array {
20
return array(
21
'low'
=>
'Niedrig'
,
22
'normal'
=>
'Normal'
,
23
'high'
=>
'Hoch'
,
24
'urgent'
=>
'Dringend'
,
25
);
26
}
27
28
public
function
openCount
(): int {
29
$db
=
dbx
()->get_system_obj(
'dbxDB'
);
30
if
(!is_object(
$db
)) {
31
return
0;
32
}
33
34
$count
=
$db
->count(self::DD_TICKET, array(
'status'
=>
'open'
));
35
return
max(0, (
int
)
$count
);
36
}
37
38
public
static
function
normalizeStatus
(
string
$status,
string
$fallback =
'open'
): string {
39
return array_key_exists($status, self::
statuses
()) ? $status : $fallback;
40
}
41
42
public
static
function
normalizePriority
(
string
$priority,
string
$fallback =
'normal'
): string {
43
return array_key_exists($priority, self::
priorities
()) ? $priority : $fallback;
44
}
45
46
public
static
function
ticket
(
$db
,
int
$ticketId): array {
47
if
(!is_object(
$db
) || $ticketId <= 0) {
48
return
array();
49
}
50
$row =
$db
->select1(self::DD_TICKET, $ticketId,
'*'
, 0);
51
return
is_array($row) ? $row : array();
52
}
53
54
public
static
function
userOwns
(array $ticket,
int
$uid): bool {
55
return $uid > 0 && (int) ($ticket[
'uid'
] ?? 0) === $uid;
56
}
57
58
public
static
function
messages
(
$db
,
int
$ticketId,
bool
$includeInternal =
false
): array {
59
if
(!is_object(
$db
) || $ticketId <= 0) {
60
return
array();
61
}
62
63
$where =
'ticket_id = '
. $ticketId;
64
if
(!$includeInternal) {
65
$where .=
" AND visibility = 'public'"
;
66
}
67
68
$rows =
$db
->select(
69
self::DD_MESSAGE,
70
$where,
71
array(
'id'
,
'create_date'
,
'author_uid'
,
'author_type'
,
'message_type'
,
'visibility'
,
'body'
,
'status_from'
,
'status_to'
,
'mail_sent'
,
'mail_sent_date'
),
72
'create_date,id'
,
73
'ASC'
,
74
''
,
75
1000,
76
0,
77
0
78
);
79
80
return
is_array($rows) ? $rows : array();
81
}
82
83
public
static
function
ensureInitialMessage
(
$db
, array $ticket): void {
84
$ticketId = (int) ($ticket[
'id'
] ?? 0);
85
if
(!is_object(
$db
) || $ticketId <= 0) {
86
return
;
87
}
88
$message = trim((
string
) ($ticket[
'message'
] ??
''
));
89
$hasRequest =
$db
->count(
90
self::DD_MESSAGE,
91
"ticket_id = "
. $ticketId .
" AND message_type = 'request'"
92
) > 0;
93
if
($message !==
''
&& !$hasRequest) {
94
self::addMessage(
$db
, $ticketId, array(
95
'author_uid'
=> (
int
) ($ticket[
'uid'
] ?? 0),
96
'author_type'
=>
'requester'
,
97
'message_type'
=>
'request'
,
98
'visibility'
=>
'public'
,
99
'body'
=> $message,
100
'status_to'
=> self::normalizeStatus((
string
) ($ticket[
'status'
] ??
'open'
)),
101
'create_date'
=> (
string
) ($ticket[
'create_date'
] ??
''
),
102
));
103
}
104
105
}
106
107
public
static
function
addMessage
(
$db
,
int
$ticketId, array $data): int {
108
if
(!is_object(
$db
) || $ticketId <= 0) {
109
return
0;
110
}
111
112
$values = array(
113
'ticket_id'
=> $ticketId,
114
'author_uid'
=> (
int
) ($data[
'author_uid'
] ??
dbx
()->user()),
115
'author_type'
=> (
string
) ($data[
'author_type'
] ??
'system'
),
116
'message_type'
=> (
string
) ($data[
'message_type'
] ??
'message'
),
117
'visibility'
=> (
string
) ($data[
'visibility'
] ??
'public'
),
118
'body'
=> trim((
string
) ($data[
'body'
] ??
''
)),
119
'status_from'
=> (
string
) ($data[
'status_from'
] ??
''
),
120
'status_to'
=> (
string
) ($data[
'status_to'
] ??
''
),
121
'mail_sent'
=> (
int
) ($data[
'mail_sent'
] ?? 0),
122
'mail_sent_date'
=> (
string
) ($data[
'mail_sent_date'
] ??
''
),
123
);
124
125
if
(!empty($data[
'create_date'
])) {
126
$values[
'create_date'
] = (string) $data[
'create_date'
];
127
}
128
129
$ok =
$db
->insert(self::DD_MESSAGE, $values, 0, 1, 1, 1);
130
return
$ok > 0 ? (int)
$db
->get_insert_id() : 0;
131
}
132
133
public
static
function
touch
(
$db
,
int
$ticketId, array $values = array()): bool {
134
if
(!is_object(
$db
) || $ticketId <= 0) {
135
return
false
;
136
}
137
$values[
'last_activity_date'
] = date(
'Y-m-d H:i:s'
);
138
return
$db
->update(self::DD_TICKET, $values, $ticketId, 0, 1, 1, 1) === 1;
139
}
140
141
public
static
function
statusLabel
(
string
$status): string {
142
$statuses = self::
statuses
();
143
return
$statuses[$status] ?? $status;
144
}
145
146
public
static
function
priorityLabel
(
string
$priority): string {
147
$priorities = self::
priorities
();
148
return
$priorities[$priority] ?? $priority;
149
}
150
}
dbx\dbxContact\dbxContactTicket
Definition
dbxContactTicket.class.php:4
dbx\dbxContact\dbxContactTicket\DD_MESSAGE
const DD_MESSAGE
Definition
dbxContactTicket.class.php:7
dbx\dbxContact\dbxContactTicket\DD_TICKET
const DD_TICKET
Definition
dbxContactTicket.class.php:6
dbx\dbxContact\dbxContactTicket\userOwns
static userOwns(array $ticket, int $uid)
Definition
dbxContactTicket.class.php:54
dbx\dbxContact\dbxContactTicket\statusLabel
static statusLabel(string $status)
Definition
dbxContactTicket.class.php:141
dbx\dbxContact\dbxContactTicket\priorities
static priorities()
Definition
dbxContactTicket.class.php:19
dbx\dbxContact\dbxContactTicket\ticket
static ticket($db, int $ticketId)
Definition
dbxContactTicket.class.php:46
dbx\dbxContact\dbxContactTicket\touch
static touch($db, int $ticketId, array $values=array())
Definition
dbxContactTicket.class.php:133
dbx\dbxContact\dbxContactTicket\normalizeStatus
static normalizeStatus(string $status, string $fallback='open')
Definition
dbxContactTicket.class.php:38
dbx\dbxContact\dbxContactTicket\messages
static messages($db, int $ticketId, bool $includeInternal=false)
Definition
dbxContactTicket.class.php:58
dbx\dbxContact\dbxContactTicket\addMessage
static addMessage($db, int $ticketId, array $data)
Definition
dbxContactTicket.class.php:107
dbx\dbxContact\dbxContactTicket\normalizePriority
static normalizePriority(string $priority, string $fallback='normal')
Definition
dbxContactTicket.class.php:42
dbx\dbxContact\dbxContactTicket\priorityLabel
static priorityLabel(string $priority)
Definition
dbxContactTicket.class.php:146
dbx\dbxContact\dbxContactTicket\openCount
openCount()
Definition
dbxContactTicket.class.php:28
dbx\dbxContact\dbxContactTicket\ensureInitialMessage
static ensureInitialMessage($db, array $ticket)
Definition
dbxContactTicket.class.php:83
dbx\dbxContact\dbxContactTicket\statuses
static statuses()
Definition
dbxContactTicket.class.php:9
$count
$count
Definition
generate_dbxapp_merch_mockups.php:270
if
if( $syncRequest)
Definition
index.php:520
dbx
DBX schema administration.
$db
$db
Definition
run_context_help_provision.php:38
dbx
modules
dbxContact
include
dbxContactTicket.class.php
Generated by
1.17.0