You are here

function rules_admin_overview_table in Rules 6

Returns a table of rules filtered by the given parameters

Supported parameters: fixed, category, set, active. Category and set may be set to NULL to hide their columns.

2 calls to rules_admin_overview_table()
rules_admin_form_edit_rule_set in rules_admin/rules_admin.sets.inc
Shows the rule set edit page form
rules_admin_form_overview in rules_admin/rules_admin.rule_forms.inc
Lists the available rules.

File

rules_admin/rules_admin.inc, line 277

Code

function rules_admin_overview_table($params) {
  $rules = rules_get_configured_items('rules');
  _rules_element_defaults($rules);
  rules_sort_children($rules);

  //set parameter defaults
  $params += array(
    'category' => NULL,
    'set' => NULL,
    'active' => TRUE,
    'fixed' => FALSE,
  );
  extract($params);
  $is_set = $set && strpos($set, 'event_') !== 0;
  $header = array(
    t('Label'),
    $is_set ? t('Set') : t('Event'),
    t('Category'),
    t('Status'),
    t('Operations'),
  );
  $rows = array();
  foreach (element_children($rules) as $name) {
    $rule = $rules[$name];
    _rules_element_defaults($rule);
    if ((!$category || in_array($category, $rule['#categories'])) && (!$set && strpos($rule['#set'], 'event_') === 0 || $rule['#set'] == $set) && $rule['#active'] == $active && ($rule['#status'] == 'fixed') == $fixed) {
      $path = RULES_ADMIN_RULE_PATH . '/' . $name;
      $ops = array();
      if ($rule['#status'] == 'custom') {
        $ops[] = l(t('delete'), $path . '/delete', array(
          'query' => drupal_get_destination(),
        ));
      }
      else {
        if ($rule['#status'] == 'altered') {
          $ops[] = l(t('revert'), $path . '/revert', array(
            'query' => drupal_get_destination(),
          ));
        }
      }
      $ops[] = l(t('clone'), $path . '/clone', array(), drupal_get_destination());
      $categories = array_map('check_plain', $rule['#categories']);
      $set_info = rules_get_rule_sets($rule['#set']);

      // If the set info is missing, the module providing the event is gone and the
      // rule can't be edited.
      $rows[] = array(
        $set_info ? l($rule['#label'], $path . '/edit') : check_plain($rule['#label']),
        $set_info ? check_plain(rules_get_element_label($set_info)) : array(
          'class' => 'error',
          'data' => check_plain($rule['#set']),
        ),
        implode(', ', $categories),
        theme('rules_admin_configuration_status', $rule['#status']),
        implode(' ', $ops),
      );
      if (!$set_info) {
        rules_handle_error_msg("%set can't be found. Probably the providing module has been deactivated.", array(
          '%set' => $rule['#set'],
        ));
      }
    }
  }
  if (count($rows)) {
    return array(
      '#value' => theme('table', $header, $rows, array(
        'class' => 'rules-rule-configurations',
      )),
    );
  }
  return array(
    '#value' => '<p>' . t('None') . '</p>',
  );
}