You are here

function subscriptions_get_summary in Subscriptions 5

1 call to subscriptions_get_summary()
subscriptions_page in ./subscriptions.module
displays subscribed content data on user and subuscription pages @ TODO clean up all of these parts

File

./subscriptions.module, line 445

Code

function subscriptions_get_summary() {

  // query string for node subscriptions
  $queryn = 'SELECT n.nid, n.title, s.sid, COUNT(*) as ncount FROM ';
  $queryn .= '{subscriptions} s INNER JOIN {node} n ON n.nid = s.sid ';
  $queryn .= 'WHERE s.stype = \'node\' ';
  $queryn .= 'GROUP BY n.nid, n.title, s.sid ';
  $queryn .= 'ORDER BY s.sid ';

  // query string for blog subscriptions (by blog owner)
  $queryb = 'SELECT u.uid, u.name, s.sid, COUNT(*) as ncount FROM ';
  $queryb .= '{subscriptions} s INNER JOIN {users} u ON u.uid = s.sid ';
  $queryb .= 'WHERE s.stype = \'blog\' ';
  $queryb .= 'GROUP BY u.uid, u.name, s.sid ';
  $queryb .= 'ORDER BY s.sid ';

  // query string for category subscriptions
  $queryt .= 'SELECT s.sid, td.name, COUNT(*) as ncount FROM ';
  $queryt .= '{subscriptions} s RIGHT JOIN {term_data} td ON td.tid = s.sid ';
  $queryt .= 'WHERE s.stype = \'taxa\' ';
  $queryt .= 'GROUP BY s.sid, td.name ';
  $queryt .= 'ORDER BY s.sid ';

  // query string for content type subscriptions
  $querytp .= 'SELECT s.stype, COUNT(*) as ncount FROM ';
  $querytp .= '{subscriptions} s ';
  $querytp .= 'WHERE s.stype LIKE \'type%\' ';
  $querytp .= 'GROUP BY s.sid ';
  $querytp .= 'ORDER BY s.sid ';
  $resultn = db_query($queryn);
  $resultb = db_query($queryb);
  $resultt = db_query($queryt);
  $resulttp = db_query($querytp);
  $subssumm['node'] = $subssumm['taxa'] = $subssumm['blog'] = $subssumm['type'] = array();
  while ($nsub = db_fetch_object($resultn)) {
    $subssumm['node'][$nsub->nid] = $nsub;
  }
  while ($bsub = db_fetch_object($resultb)) {
    $subssumm['blog'][$bsub->uid] = $bsub;
  }
  while ($tsub = db_fetch_object($resultt)) {
    $subssumm['taxa'][$tsub->tid] = $tsub;
  }
  while ($tpsub = db_fetch_object($resulttp)) {
    $subssumm['type'][$tsub->stype] = $tpsub;
  }
  return $subssumm;
}