aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorplegall <plg@piwigo.org>2013-11-11 22:11:11 +0000
committerplegall <plg@piwigo.org>2013-11-11 22:11:11 +0000
commit0cb2c621deebc31aa1af0e2e656807aaf85590a3 (patch)
treeef6b732e007a432d97b6cdcf80d475bdc3e27af0 /include
parentc10683b35bb065e0d4db5f4bdd706998fd15b982 (diff)
feature 2976: makes sure we output registration_date if registration_date_* is requested (same for last_visit_*)
git-svn-id: http://piwigo.org/svn/trunk@25461 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to 'include')
-rw-r--r--include/ws_functions/pwg.users.php113
1 files changed, 70 insertions, 43 deletions
diff --git a/include/ws_functions/pwg.users.php b/include/ws_functions/pwg.users.php
index b77bf45fa..0a8b2d6a2 100644
--- a/include/ws_functions/pwg.users.php
+++ b/include/ws_functions/pwg.users.php
@@ -96,6 +96,30 @@ function ws_users_getList($params, &$service)
));
}
+ // if registration_date_string or registration_date_since is requested,
+ // then registration_date is automatically added
+ if (in_array('registration_date_string', $params['display']) and !in_array('registration_date', $params['display']))
+ {
+ $params['display'][] = 'registration_date';
+ }
+
+ if (in_array('registration_date_since', $params['display']) and !in_array('registration_date', $params['display']))
+ {
+ $params['display'][] = 'registration_date';
+ }
+
+ // if last_visit_string or last_visit_since is requested, then
+ // last_visit is automatically added
+ if (in_array('last_visit_string', $params['display']) and !in_array('last_visit', $params['display']))
+ {
+ $params['display'][] = 'last_visit';
+ }
+
+ if (in_array('last_visit_since', $params['display']) and !in_array('last_visit', $params['display']))
+ {
+ $params['display'][] = 'last_visit';
+ }
+
if (in_array('username', $params['display']))
{
$display['u.'.$conf['user_fields']['username']] = 'username';
@@ -153,54 +177,56 @@ SELECT DISTINCT ';
$users = hash_from_query($query, 'id');
- if (count($users) > 0 and in_array('groups', $params['display']))
+ if (count($users) > 0)
{
- $query = '
+ if (in_array('groups', $params['display']))
+ {
+ $query = '
SELECT user_id, group_id
FROM '. USER_GROUP_TABLE .'
WHERE user_id IN ('. implode(',', array_keys($users)) .')
;';
- $result = pwg_query($query);
-
- while ($row = pwg_db_fetch_assoc($result))
- {
- $users[ $row['user_id'] ]['groups'][] = $row['group_id'];
+ $result = pwg_query($query);
+
+ while ($row = pwg_db_fetch_assoc($result))
+ {
+ $users[ $row['user_id'] ]['groups'][] = $row['group_id'];
+ }
}
- }
-
- if (count($users) > 0 and in_array('registration_date_string', $params['display']))
- {
- foreach ($users as $cur_user)
+
+ if (in_array('registration_date_string', $params['display']))
{
- $users[ $cur_user['id'] ]['registration_date_string'] = format_date($cur_user['registration_date'], false, false);
+ foreach ($users as $cur_user)
+ {
+ $users[$cur_user['id']]['registration_date_string'] = format_date($cur_user['registration_date'], false, false);
+ }
}
- }
- if (count($users) > 0 and in_array('registration_date_since', $params['display']))
- {
- foreach ($users as $cur_user)
+ if (in_array('registration_date_since', $params['display']))
{
- $users[ $cur_user['id'] ]['registration_date_since'] = time_since($cur_user['registration_date'], 'month');
+ foreach ($users as $cur_user)
+ {
+ $users[ $cur_user['id'] ]['registration_date_since'] = time_since($cur_user['registration_date'], 'month');
+ }
}
- }
- if (count($users) > 0 and in_array('last_visit', $params['display']))
- {
- $query = '
+ if (in_array('last_visit', $params['display']))
+ {
+ $query = '
SELECT
MAX(id) as history_id
FROM '.HISTORY_TABLE.'
WHERE user_id IN ('.implode(',', array_keys($users)).')
GROUP BY user_id
;';
- $history_ids = array_from_query($query, 'history_id');
-
- if (count($history_ids) == 0)
- {
- $history_ids[] = -1;
- }
-
- $query = '
+ $history_ids = array_from_query($query, 'history_id');
+
+ if (count($history_ids) == 0)
+ {
+ $history_ids[] = -1;
+ }
+
+ $query = '
SELECT
user_id,
date,
@@ -208,20 +234,21 @@ SELECT
FROM '.HISTORY_TABLE.'
WHERE id IN ('.implode(',', $history_ids).')
;';
- $result = pwg_query($query);
- while ($row = pwg_db_fetch_assoc($result))
- {
- $last_visit = $row['date'].' '.$row['time'];
- $users[ $row['user_id'] ]['last_visit'] = $last_visit;
-
- if (in_array('last_visit_string', $params['display']))
- {
- $users[ $row['user_id'] ]['last_visit_string'] = format_date($last_visit, false, false);
- }
-
- if (in_array('last_visit_since', $params['display']))
+ $result = pwg_query($query);
+ while ($row = pwg_db_fetch_assoc($result))
{
- $users[ $row['user_id'] ]['last_visit_since'] = time_since($last_visit, 'day');
+ $last_visit = $row['date'].' '.$row['time'];
+ $users[ $row['user_id'] ]['last_visit'] = $last_visit;
+
+ if (in_array('last_visit_string', $params['display']))
+ {
+ $users[ $row['user_id'] ]['last_visit_string'] = format_date($last_visit, false, false);
+ }
+
+ if (in_array('last_visit_since', $params['display']))
+ {
+ $users[ $row['user_id'] ]['last_visit_since'] = time_since($last_visit, 'day');
+ }
}
}
}