You are here

function theme_flag_actions_page in Flag 7.2

Same name and namespace in other branches
  1. 5 flag_actions.module \theme_flag_actions_page()
  2. 6.2 flag_actions.module \theme_flag_actions_page()
  3. 6 flag_actions.module \theme_flag_actions_page()
  4. 7.3 flag_actions.module \theme_flag_actions_page()

Theme the list of actions currently in place for flags.

1 theme call to theme_flag_actions_page()
flag_actions_page in ./flag_actions.module
Menu callback for FLAG_ADMIN_PATH/actions.

File

./flag_actions.module, line 277
Actions support for the Flag module.

Code

function theme_flag_actions_page($variables) {
  $actions = $variables['actions'];
  $add_action_form = $variables['form'];
  $rows = array();
  foreach ($actions as $action) {
    $flag = flag_get_flag($action->flag);

    // Build a sample string representing repeating actions.
    if ($action->repeat_threshold) {
      $repeat_count = 3;
      $repeat_subtract = $action->event == 'flag' ? 1 : -1;
      $repeat_samples = array();
      for ($n = 1; $n < $repeat_count + 2; $n++) {
        $sample = $action->threshold + $n * $action->repeat_threshold * $repeat_subtract;
        if ($sample > 0) {
          $repeat_samples[] = $sample;
        }
      }
      if (count($repeat_samples) > $repeat_count) {
        $repeat_samples[$repeat_count] = '&hellip;';
      }
      $repeat_string = implode(', ', $repeat_samples);
    }
    else {
      $repeat_string = '-';
    }
    $row = array();
    $row[] = $flag
      ->get_title();
    $row[] = ($action->event == 'flag' ? '&ge; ' : '&lt; ') . $action->threshold;
    $row[] = $repeat_string;
    $row[] = empty($action->missing) ? $action->label : '<div class="error">' . $action->label . '</div>';
    $row[] = l(t('edit'), FLAG_ADMIN_PATH . '/actions/configure/' . $action->aid);
    $row[] = l(t('delete'), FLAG_ADMIN_PATH . '/actions/delete/' . $action->aid);
    $rows[] = $row;
  }
  if (empty($rows)) {
    $rows[] = array(
      array(
        'data' => t('Currently no flag actions. Use the <em>Add new flag action</em> form to add an action.'),
        'colspan' => 6,
      ),
    );
  }
  $header = array(
    t('Flag'),
    t('Threshold'),
    t('Repeats'),
    t('Action'),
    array(
      'data' => t('Operations'),
      'colspan' => 2,
    ),
  );
  $output = '';
  $output .= theme('table', array(
    'header' => $header,
    'rows' => $rows,
  ));
  $output .= drupal_render($add_action_form);
  return $output;
}