Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Q
question2answer
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
outils
question2answer
Commits
e2e69a82
Commit
e2e69a82
authored
Apr 10, 2014
by
Scott
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor qa_db_recent_messages_selectspec, add inbox/outbox functions
parent
f4b51704
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
82 additions
and
12 deletions
+82
-12
qa-db-selects.php
qa-include/qa-db-selects.php
+82
-12
No files found.
qa-include/qa-db-selects.php
View file @
e2e69a82
...
@@ -1301,6 +1301,22 @@
...
@@ -1301,6 +1301,22 @@
}
}
function
qa_db_messages_columns
()
/*
Return columns for standard messages selectspec
*/
{
return
array
(
'messageid'
,
'fromuserid'
,
'touserid'
,
'content'
,
'format'
,
'created'
=>
'UNIX_TIMESTAMP(^messages.created)'
,
'fromflags'
=>
'^users.flags'
,
'fromlevel'
=>
'^users.level'
,
'fromemail'
=>
'^users.email'
,
'fromhandle'
=>
'^users.handle'
,
'fromavatarblobid'
=>
'BINARY ^users.avatarblobid'
,
// cast to BINARY due to MySQL bug which renders it signed in a union
'fromavatarwidth'
=>
'^users.avatarwidth'
,
'fromavatarheight'
=>
'^users.avatarheight'
,
);
}
function
qa_db_recent_messages_selectspec
(
$fromidentifier
,
$fromisuserid
,
$toidentifier
,
$toisuserid
,
$count
=
null
,
$start
=
0
)
function
qa_db_recent_messages_selectspec
(
$fromidentifier
,
$fromisuserid
,
$toidentifier
,
$toisuserid
,
$count
=
null
,
$start
=
0
)
/*
/*
If $fromidentifier is not null, return the selectspec to get recent private messages which have been sent from
If $fromidentifier is not null, return the selectspec to get recent private messages which have been sent from
...
@@ -1309,22 +1325,76 @@
...
@@ -1309,22 +1325,76 @@
for the user identified by $toidentifier+$toisuserid. Return $count (if null, a default is used) messages.
for the user identified by $toidentifier+$toisuserid. Return $count (if null, a default is used) messages.
*/
*/
{
{
$count
=
isset
(
$count
)
?
min
(
$count
,
QA_DB_RETRIEVE_MESSAGES
)
:
QA_DB_RETRIEVE_MESSAGES
;
$count
=
isset
(
$count
)
?
min
(
$count
,
QA_DB_RETRIEVE_MESSAGES
)
:
QA_DB_RETRIEVE_MESSAGES
;
if
(
isset
(
$fromidentifier
))
{
$fromsub
=
$fromisuserid
?
'$'
:
'(SELECT userid FROM ^users WHERE handle=$ LIMIT 1)'
;
$where
=
'fromuserid='
.
$fromsub
.
" AND type='PRIVATE'"
;
}
else
$where
=
"type='PUBLIC'"
;
$tosub
=
$toisuserid
?
'$'
:
'(SELECT userid FROM ^users WHERE handle=$ LIMIT 1)'
;
$source
=
'^messages LEFT JOIN ^users ON fromuserid=^users.userid WHERE '
.
$where
.
' AND touserid='
.
$tosub
.
' ORDER BY ^messages.created DESC LIMIT #,#'
;
$arguments
=
isset
(
$fromidentifier
)
?
array
(
$fromidentifier
,
$toidentifier
,
$start
,
$count
)
:
array
(
$toidentifier
,
$start
,
$count
);
return
array
(
return
array
(
'columns'
=>
array
(
'columns'
=>
qa_db_messages_columns
(),
'messageid'
,
'fromuserid'
,
'touserid'
,
'content'
,
'format'
,
'created'
=>
'UNIX_TIMESTAMP(^messages.created)'
,
'source'
=>
$source
,
'fromflags'
=>
'^users.flags'
,
'fromlevel'
=>
'^users.level'
,
'fromemail'
=>
'^users.email'
,
'fromhandle'
=>
'^users.handle'
,
'arguments'
=>
$arguments
,
'fromavatarblobid'
=>
'BINARY ^users.avatarblobid'
,
// cast to BINARY due to MySQL bug which renders it signed in a union
'arraykey'
=>
'messageid'
,
'fromavatarwidth'
=>
'^users.avatarwidth'
,
'fromavatarheight'
=>
'^users.avatarheight'
,
'sortdesc'
=>
'created'
,
),
);
}
'source'
=>
'^messages LEFT JOIN ^users ON fromuserid=^users.userid WHERE '
.
(
isset
(
$fromidentifier
)
?
(
'fromuserid='
.
(
$fromisuserid
?
"$"
:
"(SELECT userid FROM ^users WHERE handle=$ LIMIT 1)"
)
.
" AND type='PRIVATE'"
)
:
"type='PUBLIC'"
)
.
' AND touserid='
.
(
$toisuserid
?
"$"
:
"(SELECT userid FROM ^users WHERE handle=$ LIMIT 1)"
)
.
' ORDER BY ^messages.created DESC LIMIT #,#'
,
'arguments'
=>
isset
(
$fromidentifier
)
?
array
(
$fromidentifier
,
$toidentifier
,
$start
,
$count
)
:
array
(
$toidentifier
,
$start
,
$count
),
function
qa_db_messages_inbox_selectspec
(
$type
,
$toidentifier
,
$toisuserid
,
$count
=
null
,
$start
=
0
)
/*
Get selectspec for messages *to* specified user.
$type is either 'public' or 'private'.
$toidentifier is a handle or userid depending on the value of $toisuserid.
Return $count (or default) messages.
*/
{
$type
=
strtoupper
(
$type
);
$count
=
isset
(
$count
)
?
min
(
$count
,
QA_DB_RETRIEVE_MESSAGES
)
:
QA_DB_RETRIEVE_MESSAGES
;
$where
=
'touserid='
.
(
$toisuserid
?
'$'
:
'(SELECT userid FROM ^users WHERE handle=$ LIMIT 1)'
)
.
' AND type=$'
;
$source
=
'^messages LEFT JOIN ^users ON fromuserid=^users.userid WHERE '
.
$where
.
' ORDER BY ^messages.created DESC LIMIT #,#'
;
$arguments
=
array
(
$toidentifier
,
$type
,
$start
,
$count
);
return
array
(
'columns'
=>
qa_db_messages_columns
(),
'source'
=>
$source
,
'arguments'
=>
$arguments
,
'arraykey'
=>
'messageid'
,
'sortdesc'
=>
'created'
,
);
}
function
qa_db_messages_outbox_selectspec
(
$type
,
$fromidentifier
,
$fromisuserid
,
$count
=
null
,
$start
=
0
)
/*
Get selectspec for messages *from* specified user.
$type is either 'public' or 'private'.
$fromidentifier is a handle or userid depending on the value of $fromisuserid.
Return $count (or default) messages.
*/
{
$type
=
strtoupper
(
$type
);
$count
=
isset
(
$count
)
?
min
(
$count
,
QA_DB_RETRIEVE_MESSAGES
)
:
QA_DB_RETRIEVE_MESSAGES
;
$where
=
'fromuserid='
.
(
$fromisuserid
?
'$'
:
'(SELECT userid FROM ^users WHERE handle=$ LIMIT 1)'
)
.
' AND type=$'
;
$source
=
'^messages LEFT JOIN ^users ON fromuserid=^users.userid WHERE '
.
$where
.
' ORDER BY ^messages.created DESC LIMIT #,#'
;
$arguments
=
array
(
$fromidentifier
,
$type
,
$start
,
$count
);
return
array
(
'columns'
=>
qa_db_messages_columns
(),
'source'
=>
$source
,
'arguments'
=>
$arguments
,
'arraykey'
=>
'messageid'
,
'arraykey'
=>
'messageid'
,
'sortdesc'
=>
'created'
,
'sortdesc'
=>
'created'
,
);
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment