Ignore:
Timestamp:
Dec 7, 2006, 4:49:20 AM (17 years ago)
Author:
rvelices
Message:

put some functionnality from feed.php into a function (to be used
later in the notification by email)

File:
1 edited

Legend:

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

    r1637 r1639  
    414414}
    415415
     416/**
     417 * returns information about recently published elements grouped by post date
     418 * @param int max_dates maximum returned number of recent dates
     419 * @param int max_elements maximum returned number of elements per date
     420 * @param int max_cats maximum returned number of categories per date
     421 */
     422function get_recent_post_dates($max_dates, $max_elements, $max_cats)
     423{
     424  global $conf, $user;
     425
     426  $where_sql = 'WHERE category_id NOT IN ('.$user['forbidden_categories'].')';
     427
     428  $query = '
     429SELECT date_available,
     430      COUNT(DISTINCT id) nb_elements,
     431      COUNT(DISTINCT category_id) nb_cats
     432  FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id=image_id
     433  '.$where_sql.'
     434  GROUP BY date_available
     435  ORDER BY date_available DESC
     436  LIMIT 0,'.$max_dates.'
     437;';
     438  $result = pwg_query($query);
     439  $dates = array();
     440  while ($row = mysql_fetch_assoc($result))
     441  {
     442    array_push($dates, $row);
     443  }
     444
     445  for ($i=0; $i<count($dates); $i++)
     446  {
     447    if ($max_elements>0)
     448    { // get some thumbnails ...
     449      $query = '
     450SELECT DISTINCT id, path, name, tn_ext
     451  FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id=image_id
     452  '.$where_sql.'
     453    AND date_available="'.$dates[$i]['date_available'].'"
     454    AND tn_ext IS NOT NULL
     455  LIMIT 0,'.$max_elements.'
     456;';
     457      $dates[$i]['elements'] = array();
     458      $result = pwg_query($query);
     459      while ($row = mysql_fetch_assoc($result))
     460      {
     461        array_push($dates[$i]['elements'], $row);
     462      }
     463    }
     464
     465    if ($max_cats>0)
     466    {// get some categories ...
     467      $query = '
     468SELECT DISTINCT c.uppercats, COUNT(DISTINCT i.id) img_count
     469  FROM '.IMAGES_TABLE.' i INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON i.id=image_id
     470    INNER JOIN '.CATEGORIES_TABLE.' c ON c.id=category_id
     471  '.$where_sql.'
     472    AND date_available="'.$dates[$i]['date_available'].'"
     473  GROUP BY category_id
     474  ORDER BY img_count DESC
     475  LIMIT 0,'.$max_cats.'
     476;';
     477      $dates[$i]['categories'] = array();
     478      $result = pwg_query($query);
     479      while ($row = mysql_fetch_assoc($result))
     480      {
     481        array_push($dates[$i]['categories'], $row);
     482      }
     483    }
     484  }
     485  return $dates;
     486}
    416487?>
Note: See TracChangeset for help on using the changeset viewer.