You are here

function cmf_filters in Content Management Filter 6

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

List node administration filters that can be applied.

Parameters

$user_page (bool) is this building the user profile page (defaults to false).:

Return value

array with filter properties. Any property starting with '#' goes directly into the filter form. '#options' is also used in function cmf_filter_form_submit. 'title' is the text that will show on the filter form. 'single_use' (bool) determines if the filter will be disabled if it is already in use. 'where' sets a simple WHERE clause for the query (with substitution). 'join' sets a simple JOIN clause for the query (with substitution). 'query_build' provides a funtion for more complex query clauses. If validation and/or submission handling is needed, use the #validate and #submit elements. Submit handlers must set the return value in $form_state['values'] array.

NOTE: for the 'where' clause some node fields are translated to comment-equivalent field names if appropriate. See function cmf_perform_query for 'comment' and 'both.'

3 calls to cmf_filters()
cmf_build_filter_query in ./cmf.module
Build the variable parts of the query to be performed regarding the filter status.
cmf_filter_form in ./cmf.module
Defines the form for content administration filters.
cmf_filter_form_refine in ./cmf.module
Handle post-validation form submission.

File

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

Code

function cmf_filters($user_page = FALSE) {

  // Make the array static so it is built only once per page load.
  static $filters;
  if (isset($filters)) {
    return $filters;
  }
  $filters = array();

  // Regular filters.
  $filters['status'] = array(
    'title' => t('node status'),
    'single_use' => FALSE,
    'query_build' => '_cmf_status_query_build',
    '#type' => 'select',
    '#options' => array(
      'status-1' => t('published'),
      'status-0' => t('not published'),
      'promote-1' => t('promoted'),
      'promote-0' => t('not promoted'),
      'sticky-1' => t('sticky'),
      'sticky-0' => t('not sticky'),
    ),
  );
  $filters['type'] = array(
    'title' => t('node type'),
    'single_use' => TRUE,
    'where' => "n.type = '%s'",
    '#type' => 'select',
    '#options' => node_get_types('names'),
  );

  // The taxonomy filter.
  if ($taxonomy = taxonomy_form_all(TRUE)) {
    $filters['category'] = array(
      'title' => t('category'),
      'single_use' => FALSE,
      'query_build' => '_cmf_category_query_build',
      '#type' => 'select',
      '#options' => $taxonomy,
    );
  }

  // Cmf filters.
  $filters['title'] = array(
    'title' => t('title/subject'),
    'single_use' => FALSE,
    'where' => "LOWER(n.title) LIKE LOWER('%%%s%%')",
    '#type' => 'textfield',
  );
  $filters['body_contains'] = array(
    'title' => t('Body contains'),
    'single_use' => FALSE,
    'where' => "LOWER(r.body) LIKE LOWER('%%%s%%')",
    '#type' => 'textfield',
  );
  $filters['created_after'] = array(
    'title' => t('created after'),
    'single_use' => TRUE,
    'where' => "n.created >= %d",
    '#type' => 'date',
    '#validate' => 'date_validate',
    '#submit' => array(
      'cmf_date_submit',
    ),
    '#default_value' => array(
      'year' => date('Y'),
      'month' => 1,
      'day' => 1,
    ),
    '#prefix' => '<div class="date-inline">',
    '#suffix' => '</div>',
  );
  $filters['created_before'] = array(
    'title' => t('created before'),
    'single_use' => TRUE,
    'where' => "n.created <= %d",
    '#type' => 'date',
    '#validate' => 'date_validate',
    '#submit' => array(
      'cmf_date_submit',
    ),
    '#default_value' => array(
      'year' => date('Y'),
      'month' => 12,
      'day' => 31,
    ),
    '#prefix' => '<div class="date-inline">',
    '#suffix' => '</div>',
  );
  if (module_exists('locale')) {
    $lang_codes = array(
      '' => t('Neutral'),
    ) + locale_language_list('name');
    $filters['language'] = array(
      'title' => t('language'),
      'single_use' => TRUE,
      'where' => "n.language ='%s'",
      '#type' => 'select',
      '#options' => $lang_codes,
    );
  }

  // Don't show these on the user page.
  if (!$user_page) {
    $filters['user'] = array(
      'title' => t('user list'),
      'single_use' => TRUE,
      'where' => "u.uid = %d",
      '#type' => 'select',
      '#options' => cmf_get_users('names'),
    );
    $filters['users'] = array(
      'title' => t('user name'),
      'single_use' => TRUE,
      'where' => "u.name = '%s'",
      '#type' => 'textfield',
      '#submit' => array(
        'cmf_users_submit',
      ),
      '#autocomplete_path' => 'cmf/userauto',
    );
    $filters['role'] = array(
      'title' => t('user role'),
      'single_use' => TRUE,
      'where' => "u.uid = ur.uid AND ur.rid = %d",
      'join' => "INNER JOIN {users_roles} ur ON u.uid = ur.uid",
      '#type' => 'select',
      '#options' => cmf_get_roles('names'),
    );
    $filters['blocked'] = array(
      'title' => t('user status'),
      'single_use' => TRUE,
      'where' => "u.status = %d AND u.uid != 0",
      '#type' => 'select',
      '#options' => array(
        1 => t('active'),
        0 => t('blocked'),
      ),
    );
  }
  return $filters;
}