Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
osticket
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
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
7b261b6e
Commit
7b261b6e
authored
10 years ago
by
Jared Hancock
Browse files
Options
Downloads
Patches
Plain Diff
orm: Convert ajax.tickets, consider user name and org name
parent
fb5d1743
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
include/ajax.tickets.php
+45
-43
45 additions, 43 deletions
include/ajax.tickets.php
include/class.orm.php
+3
-2
3 additions, 2 deletions
include/class.orm.php
with
48 additions
and
45 deletions
include/ajax.tickets.php
+
45
−
43
View file @
7b261b6e
...
...
@@ -33,29 +33,29 @@ class TicketsAjaxAPI extends AjaxController {
$limit
=
isset
(
$_REQUEST
[
'limit'
])
?
(
int
)
$_REQUEST
[
'limit'
]
:
25
;
$tickets
=
array
();
$sql
=
'SELECT DISTINCT `number`, email.address AS email'
.
' FROM '
.
TICKET_TABLE
.
' ticket'
.
' LEFT JOIN '
.
USER_TABLE
.
' user ON user.id = ticket.user_id'
.
' LEFT JOIN '
.
USER_EMAIL_TABLE
.
' email ON user.id = email.user_id'
.
' WHERE `number` LIKE \''
.
db_input
(
$_REQUEST
[
'q'
],
false
)
.
'%\''
;
$sql
.
=
' AND ( staff_id='
.
db_input
(
$thisstaff
->
getId
());
if
((
$teams
=
$thisstaff
->
getTeams
())
&&
count
(
array_filter
(
$teams
)))
$sql
.
=
' OR team_id IN('
.
implode
(
','
,
db_input
(
array_filter
(
$teams
)))
.
')'
;
if
(
!
$thisstaff
->
showAssignedOnly
()
&&
(
$depts
=
$thisstaff
->
getDepts
()))
$sql
.
=
' OR dept_id IN ('
.
implode
(
','
,
db_input
(
$depts
))
.
')'
;
$visibility
=
Q
::
any
(
array
(
'staff_id'
=>
$thisstaff
->
getId
(),
'team_id__in'
=>
$thisstaff
->
teams
->
values_flat
(
'team_id'
),
));
if
(
!
$thisstaff
->
showAssignedOnly
()
&&
(
$depts
=
$thisstaff
->
getDepts
()))
{
$visibility
->
add
(
array
(
'dept_id__in'
=>
$depts
));
}
$sql
.
=
' ) '
.
' ORDER BY ticket.created LIMIT '
.
$limit
;
if
((
$res
=
db_query
(
$sql
))
&&
db_num_rows
(
$res
))
{
while
(
list
(
$id
,
$email
)
=
db_fetch_row
(
$res
))
{
$info
=
"
$id
-
$email
"
;
$tickets
[]
=
array
(
'id'
=>
$id
,
'email'
=>
$email
,
'value'
=>
$id
,
'info'
=>
$info
,
'matches'
=>
$_REQUEST
[
'q'
]);
}
$hits
=
TicketModel
::
objects
()
->
filter
(
Q
::
any
(
array
(
'number__startswith'
=>
$_REQUEST
[
'q'
],
)))
->
filter
(
$visibility
)
->
values
(
'number'
,
'user__emails__address'
)
->
annotate
(
array
(
'tickets'
=>
SqlAggregate
::
COUNT
(
'ticket_id'
)))
->
order_by
(
'-created'
)
->
limit
(
$limit
);
foreach
(
$hits
as
$T
)
{
$tickets
[]
=
array
(
'id'
=>
$T
[
'number'
],
'value'
=>
$T
[
'number'
],
'info'
=>
"
{
$T
[
'number'
]
}
—
{
$T
[
'user__emails__address'
]
}
"
,
'matches'
=>
$_REQUEST
[
'q'
]);
}
if
(
!
$tickets
)
return
self
::
lookupByEmail
();
...
...
@@ -70,29 +70,31 @@ class TicketsAjaxAPI extends AjaxController {
$limit
=
isset
(
$_REQUEST
[
'limit'
])
?
(
int
)
$_REQUEST
[
'limit'
]
:
25
;
$tickets
=
array
();
$sql
=
'SELECT email.address AS email, count(ticket.ticket_id) as tickets '
.
' FROM '
.
TICKET_TABLE
.
' ticket'
.
' JOIN '
.
USER_TABLE
.
' user ON user.id = ticket.user_id'
.
' JOIN '
.
USER_EMAIL_TABLE
.
' email ON user.id = email.user_id'
.
' WHERE (email.address LIKE \'%'
.
db_input
(
strtolower
(
$_REQUEST
[
'q'
]),
false
)
.
'%\'
OR user.name LIKE \'%'
.
db_input
(
$_REQUEST
[
'q'
],
false
)
.
'%\')'
;
$sql
.
=
' AND ( staff_id='
.
db_input
(
$thisstaff
->
getId
());
if
((
$teams
=
$thisstaff
->
getTeams
())
&&
count
(
array_filter
(
$teams
)))
$sql
.
=
' OR team_id IN('
.
implode
(
','
,
db_input
(
array_filter
(
$teams
)))
.
')'
;
if
(
!
$thisstaff
->
showAssignedOnly
()
&&
(
$depts
=
$thisstaff
->
getDepts
()))
$sql
.
=
' OR dept_id IN ('
.
implode
(
','
,
db_input
(
$depts
))
.
')'
;
$sql
.
=
' ) '
.
' GROUP BY email.address '
.
' ORDER BY ticket.created LIMIT '
.
$limit
;
$visibility
=
Q
::
any
(
array
(
'staff_id'
=>
$thisstaff
->
getId
(),
'team_id__in'
=>
$thisstaff
->
teams
->
values_flat
(
'team_id'
),
));
if
(
!
$thisstaff
->
showAssignedOnly
()
&&
(
$depts
=
$thisstaff
->
getDepts
()))
{
$visibility
->
add
(
array
(
'dept_id__in'
=>
$depts
));
}
if
((
$res
=
db_query
(
$sql
))
&&
db_num_rows
(
$res
))
{
while
(
list
(
$email
,
$count
)
=
db_fetch_row
(
$res
))
$tickets
[]
=
array
(
'email'
=>
$email
,
'value'
=>
$email
,
'info'
=>
"
$email
(
$count
)"
,
'matches'
=>
$_REQUEST
[
'q'
]);
$hits
=
TicketModel
::
objects
()
->
filter
(
Q
::
any
(
array
(
'user__emails__address__contains'
=>
$_REQUEST
[
'q'
],
'user__name__contains'
=>
$_REQUEST
[
'q'
],
'user__account__username'
=>
$_REQUEST
[
'q'
],
'user__org__name__contains'
=>
$_REQUEST
[
'q'
],
)))
->
filter
(
$visibility
)
->
values
(
'user__emails__address'
)
->
annotate
(
array
(
'tickets'
=>
SqlAggregate
::
COUNT
(
'ticket_id'
)))
->
limit
(
$limit
);
foreach
(
$hits
as
$T
)
{
$email
=
$T
[
'user__emails__address'
];
$count
=
$T
[
'tickets'
];
$tickets
[]
=
array
(
'email'
=>
$email
,
'value'
=>
$email
,
'info'
=>
"
$email
(
$count
)"
,
'matches'
=>
$_REQUEST
[
'q'
]);
}
return
$this
->
json_encode
(
$tickets
);
...
...
This diff is collapsed.
Click to expand it.
include/class.orm.php
+
3
−
2
View file @
7b261b6e
...
...
@@ -1786,9 +1786,10 @@ class MySqlCompiler extends SqlCompiler {
$rmodel
=
$model
;
// Support inline views
$table
=
(
$rmodel
::
$meta
[
'view'
])
// XXX: Support parameters from the nested query
?
$rmodel
::
getQuery
(
$this
)
:
$this
->
quote
(
$rmodel
::
$meta
[
'table'
]);
$base
=
$join
.
$table
.
$alias
;
$base
=
"
$join$table
$alias
"
;
if
(
$constraints
)
$base
.
=
' ON ('
.
implode
(
' AND '
,
$constraints
)
.
')'
;
return
$base
;
...
...
@@ -1862,7 +1863,7 @@ class MySqlCompiler extends SqlCompiler {
}
if
(
isset
(
$queryset
->
extra
[
'where'
]))
{
foreach
(
$queryset
->
extra
[
'where'
]
as
$S
)
{
$where
[]
=
'('
.
$S
.
')'
;
$where
[]
=
"(
$S
)"
;
}
}
if
(
$where
)
...
...
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