Changeset 25459


Ignore:
Timestamp:
Nov 11, 2013, 6:30:39 PM (10 years ago)
Author:
plg
Message:

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

Location:
trunk/include
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/functions.inc.php

    r25427 r25459  
    599599  if ($show_day_name)
    600600  {
    601     $print.= $lang['day'][ $date->format('w') ];
     601    $print.= $lang['day'][ $date->format('w') ].' ';
    602602  }
    603603 
    604   $print.= ' '.$date->format('d');
     604  $print.= $date->format('j');
    605605  $print.= ' '.$lang['month'][ $date->format('n') ];
    606606  $print.= ' '.$date->format('Y');
  • trunk/include/ws_functions/pwg.users.php

    r25281 r25459  
    8585        'username','email','status','level','groups','language','theme',
    8686        'nb_image_page','recent_period','expand','show_nb_comments','show_nb_hits',
    87         'enabled_high',
     87        'enabled_high','registration_date','registration_date_string',
     88        'registration_date_since', 'last_visit', 'last_visit_string',
     89        'last_visit_since'
    8890        ));
    8991    }
     
    106108    $ui_fields = array(
    107109      'status','level','language','theme','nb_image_page','recent_period','expand',
    108       'show_nb_comments','show_nb_hits','enabled_high',
     110      'show_nb_comments','show_nb_hits','enabled_high','registration_date'
    109111      );
    110112    foreach ($ui_fields as $field)
     
    164166    {
    165167      $users[ $row['user_id'] ]['groups'][] = $row['group_id'];
     168    }
     169  }
     170
     171  if (count($users) > 0 and in_array('registration_date_string', $params['display']))
     172  {
     173    foreach ($users as $cur_user)
     174    {
     175      $users[ $cur_user['id'] ]['registration_date_string'] = format_date($cur_user['registration_date'], false, false);
     176    }
     177  }
     178
     179  if (count($users) > 0 and in_array('registration_date_since', $params['display']))
     180  {
     181    foreach ($users as $cur_user)
     182    {
     183      $users[ $cur_user['id'] ]['registration_date_since'] = time_since($cur_user['registration_date'], 'month');
     184    }
     185  }
     186
     187  if (count($users) > 0 and in_array('last_visit', $params['display']))
     188  {
     189    $query = '
     190SELECT
     191    MAX(id) as history_id
     192  FROM '.HISTORY_TABLE.'
     193  WHERE user_id IN ('.implode(',', array_keys($users)).')
     194  GROUP BY user_id
     195;';
     196    $history_ids = array_from_query($query, 'history_id');
     197
     198    if (count($history_ids) == 0)
     199    {
     200      $history_ids[] = -1;
     201    }
     202   
     203    $query = '
     204SELECT
     205    user_id,
     206    date,
     207    time
     208  FROM '.HISTORY_TABLE.'
     209  WHERE id IN ('.implode(',', $history_ids).')
     210;';
     211    $result = pwg_query($query);
     212    while ($row = pwg_db_fetch_assoc($result))
     213    {
     214      $last_visit = $row['date'].' '.$row['time'];
     215      $users[ $row['user_id'] ]['last_visit'] = $last_visit;
     216
     217      if (in_array('last_visit_string', $params['display']))
     218      {
     219        $users[ $row['user_id'] ]['last_visit_string'] = format_date($last_visit, false, false);
     220      }
     221     
     222      if (in_array('last_visit_since', $params['display']))
     223      {
     224        $users[ $row['user_id'] ]['last_visit_since'] = time_since($last_visit, 'day');
     225      }
    166226    }
    167227  }
Note: See TracChangeset for help on using the changeset viewer.