Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
osticket
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
docker
osticket
Commits
124ee863
Commit
124ee863
authored
10 years ago
by
Peter Rotich
Browse files
Options
Downloads
Patches
Plain Diff
Use criteria lookup to get thread entries
parent
380a7e04
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
include/class.thread.php
+56
-49
56 additions, 49 deletions
include/class.thread.php
with
56 additions
and
49 deletions
include/class.thread.php
+
56
−
49
View file @
124ee863
...
...
@@ -84,8 +84,8 @@ class Thread {
function
getEntries
(
$criteria
)
{
if
(
!
$order
||
!
in_array
(
$order
,
array
(
'DESC'
,
'ASC'
)))
$
order
=
'ASC'
;
if
(
!
$
criteria
[
'
order
'
]
||
!
in_array
(
$
criteria
[
'
order
'
]
,
array
(
'DESC'
,
'ASC'
)))
$
criteria
[
'order'
]
=
'ASC'
;
$sql
=
'SELECT entry.*
, COALESCE(user.name,
...
...
@@ -102,13 +102,17 @@ class Thread {
ON (attach.object_id = entry.id AND attach.`type`="H") '
.
' WHERE entry.thread_id='
.
db_input
(
$this
->
getId
());
if
(
$type
&&
is_array
(
$type
))
$sql
.
=
' AND entry.`type` IN ('
.
implode
(
','
,
db_input
(
$type
))
.
')'
;
elseif
(
$type
)
$sql
.
=
' AND entry.`type` = '
.
db_input
(
$type
);
if
(
$criteria
[
'type'
]
&&
is_array
(
$criteria
[
'type'
]))
$sql
.
=
' AND entry.`type` IN ('
.
implode
(
','
,
db_input
(
$criteria
[
'type'
]))
.
')'
;
elseif
(
$criteria
[
'type'
])
$sql
.
=
' AND entry.`type` = '
.
db_input
(
$criteria
[
'type'
]);
$sql
.
=
' GROUP BY entry.id '
.
' ORDER BY entry.created '
.
$order
;
.
' ORDER BY entry.created '
.
$criteria
[
'order'
];
if
(
$criteria
[
'limit'
])
$sql
.
=
' LIMIT '
.
$criteria
[
'limit'
];
$entries
=
array
();
if
((
$res
=
db_query
(
$sql
))
&&
db_num_rows
(
$res
))
{
...
...
@@ -167,19 +171,6 @@ class Thread {
return
true
;
}
function
getVar
(
$name
)
{
switch
(
$name
)
{
case
'original'
:
return
Message
::
firstByTicketId
(
$this
->
ticket
->
getId
())
->
getBody
();
break
;
case
'last_message'
:
case
'lastmessage'
:
return
$this
->
ticket
->
getLastMessage
()
->
getBody
();
break
;
}
}
static
function
create
(
$vars
)
{
if
(
!
$vars
||
!
$vars
[
'object_id'
]
||
!
$vars
[
'object_type'
])
...
...
@@ -1285,30 +1276,8 @@ class MessageThreadEntry extends ThreadEntry {
)
?
$m
:
null
;
}
//TODO: redo shit below.
function
lastByTicketId
(
$ticketId
)
{
return
self
::
byTicketId
(
$ticketId
);
}
function
firstByTicketId
(
$ticketId
)
{
return
self
::
byTicketId
(
$ticketId
,
false
);
}
function
byTicketId
(
$ticketId
,
$last
=
true
)
{
$sql
=
' SELECT thread.id FROM '
.
TICKET_THREAD_TABLE
.
' thread '
.
' WHERE thread_type=\'M\' AND thread.ticket_id = '
.
db_input
(
$ticketId
)
.
sprintf
(
' ORDER BY thread.id %s LIMIT 1'
,
$last
?
'DESC'
:
'ASC'
);
if
((
$res
=
db_query
(
$sql
))
&&
(
$id
=
db_result
(
$res
)))
return
Message
::
lookup
(
$id
);
return
null
;
}
}
/* thread entry of type response */
class
ResponseThreadEntry
extends
ThreadEntry
{
...
...
@@ -1440,15 +1409,42 @@ class TicketThread extends Thread {
}
function
getMessages
()
{
return
$this
->
getEntries
(
MessageThreadEntry
::
ENTRY_TYPE
);
return
$this
->
getEntries
(
array
(
'type'
=>
MessageThreadEntry
::
ENTRY_TYPE
));
}
function
getLastMessage
()
{
$criteria
=
array
(
'type'
=>
MessageThreadEntry
::
ENTRY_TYPE
,
'order'
=>
'DESC'
,
'limit'
=>
1
);
return
$this
->
getEntry
(
$criteria
);
}
function
getEntry
(
$var
)
{
if
(
is_numeric
(
$var
))
$id
=
$var
;
else
{
$criteria
=
array_merge
(
$var
,
array
(
'limit'
=>
1
));
$entries
=
$this
->
getEntries
(
$criteria
);
if
(
$entries
&&
$entries
[
0
])
$id
=
$entries
[
0
][
'id'
];
}
return
$id
?
parent
::
getEntry
(
$id
)
:
null
;
}
function
getResponses
()
{
return
$this
->
getEntries
(
ResponseThreadEntry
::
ENTRY_TYPE
);
return
$this
->
getEntries
(
array
(
'type'
=>
ResponseThreadEntry
::
ENTRY_TYPE
));
}
function
getNotes
()
{
return
$this
->
getEntries
(
NoteThreadEntry
::
ENTRY_TYPE
);
return
$this
->
getEntries
(
array
(
'type'
=>
NoteThreadEntry
::
ENTRY_TYPE
));
}
function
addNote
(
$vars
,
&
$errors
)
{
...
...
@@ -1474,15 +1470,26 @@ class TicketThread extends Thread {
return
ResponseThreadEntry
::
create
(
$vars
,
$errors
);
}
//TODO: revisit
function
getVar
(
$name
)
{
switch
(
$name
)
{
case
'original'
:
return
MessageThreadEntry
::
first
(
$this
->
getId
())
->
getBody
();
case
'original'
:
$entries
=
$this
->
getEntries
(
array
(
'type'
=>
MessageThreadEntry
::
ENTRY_TYPE
,
'order'
=>
'ASC'
,
'limit'
=>
1
));
if
(
$entries
&&
$entries
[
0
])
return
(
string
)
$entries
[
0
][
'body'
];
break
;
case
'last_message'
:
case
'lastmessage'
:
return
$this
->
ticket
->
getLastMessage
()
->
getBody
();
$entries
=
$this
->
getEntries
(
array
(
'type'
=>
MessageThreadEntry
::
ENTRY_TYPE
,
'order'
=>
'DESC'
,
'limit'
=>
1
));
if
(
$entries
&&
$entries
[
0
])
return
(
string
)
$entries
[
0
][
'body'
];
break
;
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment