diff options
author | plegall <plg@piwigo.org> | 2013-11-11 17:30:39 +0000 |
---|---|---|
committer | plegall <plg@piwigo.org> | 2013-11-11 17:30:39 +0000 |
commit | c10683b35bb065e0d4db5f4bdd706998fd15b982 (patch) | |
tree | 48ad795001de0c46db368069da42d42bc8033593 /include/ws_functions | |
parent | 2945b71c10ea05f94b97b63904a2021afd515771 (diff) |
feature 2976: add output fields for pwg.users.getList. registration_date,
registration_date_string, registration_date_since, last_visit,
last_visit_string, last_visit_since.
bug fixed: format_date(), removing leading zero on day number
git-svn-id: http://piwigo.org/svn/trunk@25459 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to 'include/ws_functions')
-rw-r--r-- | include/ws_functions/pwg.users.php | 64 |
1 files changed, 62 insertions, 2 deletions
diff --git a/include/ws_functions/pwg.users.php b/include/ws_functions/pwg.users.php index aacc92ed0..b77bf45fa 100644 --- a/include/ws_functions/pwg.users.php +++ b/include/ws_functions/pwg.users.php @@ -84,7 +84,9 @@ function ws_users_getList($params, &$service) $params['display'] = array_merge($params['display'], array( 'username','email','status','level','groups','language','theme', 'nb_image_page','recent_period','expand','show_nb_comments','show_nb_hits', - 'enabled_high', + 'enabled_high','registration_date','registration_date_string', + 'registration_date_since', 'last_visit', 'last_visit_string', + 'last_visit_since' )); } else if (in_array('basics', $params['display'])) @@ -105,7 +107,7 @@ function ws_users_getList($params, &$service) $ui_fields = array( 'status','level','language','theme','nb_image_page','recent_period','expand', - 'show_nb_comments','show_nb_hits','enabled_high', + 'show_nb_comments','show_nb_hits','enabled_high','registration_date' ); foreach ($ui_fields as $field) { @@ -166,6 +168,64 @@ SELECT user_id, group_id } } + if (count($users) > 0 and in_array('registration_date_string', $params['display'])) + { + 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) + { + $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 = ' +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 = ' +SELECT + user_id, + date, + time + 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'])) + { + $users[ $row['user_id'] ]['last_visit_since'] = time_since($last_visit, 'day'); + } + } + } + return array( 'paging' => new PwgNamedStruct( array( |