You are here

function cmf_perform_query in Content Management Filter 7

Same name and namespace in other branches
  1. 5 cmf.module \cmf_perform_query()
  2. 6.2 cmf.module \cmf_perform_query()
  3. 6 cmf.module \cmf_perform_query()

Perform adjusted query.

Parameters

$user_page_user: if we are on a user page, the user that page belongs to, not the current user

array respecting tablesort_sql():

Return value

result of permormed query

3 calls to cmf_perform_query()
cmf_admin_both_form in ./both.inc
Defines the form for mixed content administration filter results.
cmf_admin_comments_form in ./comment.inc
Defines the form for comments administration filter results.
cmf_admin_nodes_form in ./node.inc
Defines the form for nodes administration filter results.

File

./cmf.module, line 817
@brief Content management filter module file

Code

function cmf_perform_query($header, $kind = NULL, $user_page_user = NULL) {
  $filter = cmf_build_filter_query();
  if (is_null($kind)) {
    $kind = $_SESSION['cmf_content_kind'];
  }
  $where = ' ' . $filter['where'];
  if (_cmf_valid_user($user_page_user)) {
    $where .= ' AND u.uid = ' . $user_page_user->uid;
  }
  $cwhere = str_replace(array(
    'n.title',
    'n.uid',
    'r.body',
  ), array(
    'c.subject',
    'c.uid',
    'c.comment',
  ), $where);
  switch ($kind) {
    case 'node':
      return pager_query('SELECT n.nid, n.title, n.type, n.status, n.created, ' . 'n.changed, n.promote, n.sticky, n.moderate, n.language, ' . 'u.name AS username, u.uid, r.body ' . 'FROM {node} n ' . 'JOIN {node_revisions} r ON r.vid = n.vid ' . 'INNER JOIN {users} u ON n.uid = u.uid ' . $filter['join'] . $where . tablesort_sql($header), isset($_SESSION['cmf_max_rows']) ? $_SESSION['cmf_max_rows'] : 50, 0, NULL, $filter['args']);
      break;
    case 'comment':
      return pager_query('SELECT c.cid, c.subject, c.nid, c.comment, c.timestamp AS created, ' . 'c.status, c.name, c.homepage, u.name AS username, u.uid, n.type, c.comment AS body ' . 'FROM {comments} c ' . 'INNER JOIN {node} n ON c.nid = n.nid ' . 'INNER JOIN {users} u ON u.uid = c.uid ' . $filter['join'] . $cwhere . tablesort_sql($header), isset($_SESSION['cmf_max_rows']) ? $_SESSION['cmf_max_rows'] : 50, 0, NULL, $filter['args']);
      break;
    case 'both':
      $args = array_merge($filter['args'], $filter['args']);
      $count_query = 'SELECT (' . 'SELECT COUNT(*) FROM {node} n ' . 'JOIN {node_revisions} r ON r.vid = n.vid ' . 'INNER JOIN {users} u ON n.uid = u.uid ' . $filter['join'] . $where . ') + (' . 'SELECT COUNT(*) FROM {comments} c INNER JOIN {node} n ON c.nid = n.nid ' . 'INNER JOIN {users} u ON u.uid = c.uid ' . $filter['join'] . $cwhere . ') AS count';
      return pager_query('SELECT 0 AS cid, n.nid, n.title, NULL AS comment, n.type, n.status, n.created, ' . 'n.changed, n.promote, n.sticky, n.moderate, n.language, ' . 'u.name AS username, u.uid, r.body ' . 'FROM {node} n ' . 'JOIN {node_revisions} r ON r.vid = n.vid ' . 'INNER JOIN {users} u ON n.uid = u.uid ' . $filter['join'] . $where . ' UNION SELECT c.cid, c.nid, c.subject AS title, c.comment, n.type, c.status, c.timestamp AS created, ' . '0 AS changed, 0 AS promote, 0 AS sticky, 0 AS moderate, "" AS language, ' . 'u.name AS username, u.uid, c.comment AS body ' . ' FROM {comments} c INNER JOIN {node} n ON c.nid = n.nid INNER JOIN {users} u ON u.uid = c.uid ' . $filter['join'] . $cwhere . tablesort_sql($header), isset($_SESSION['cmf_max_rows']) ? $_SESSION['cmf_max_rows'] : 50, 0, $count_query, $args);
      break;
  }
}