You are here

function workbench_scheduler_admin_page in Workbench Scheduler 7.2

Same name and namespace in other branches
  1. 7 workbench_scheduler.admin.inc \workbench_scheduler_admin_page()

Display a table of workbench schedule for administration.

Return value

string themed output.

1 string reference to 'workbench_scheduler_admin_page'
workbench_scheduler_menu in ./workbench_scheduler.module
Implements hook_menu().

File

./workbench_scheduler.admin.inc, line 13
Provides admin functions for Workbench Scheduler.

Code

function workbench_scheduler_admin_page() {

  // Build a table to show the different schedules.
  $headers = array(
    array(
      'data' => t('Name'),
    ),
    array(
      'data' => t('Machine Name'),
    ),
    array(
      'data' => t('Transition'),
    ),
    array(
      'data' => t('Content Types'),
    ),
    array(
      'data' => t('Operations'),
      'colspan' => 2,
    ),
  );
  $rows = array();

  // Retrieve any schedules that exist.
  if ($schedules = workbench_scheduler_schedules_load()) {

    // Get list of the different moderation states.
    $states = workbench_scheduler_state_labels();
    $transitions = workbench_moderation_transitions();

    // Get list of the different content types.
    $node_types = node_type_get_types();

    // Loop through the schedules to add them to the table.
    foreach ($schedules as $sid => $schedule) {

      // Load transition info.
      unset($transition);
      foreach ($transitions as $transition) {
        if ($transition->id == $schedule->transition) {
          break;
        }
      }

      // Format the content types the schedule is available for,
      // Based on number.
      $type_count = count($schedule->types);

      // More then one type?
      if ($type_count > 1) {
        $items = array();

        // Loop through each type.
        foreach ($schedule->types as $type) {

          // Display the human readable name.
          $items[] = $node_types[$type]->name;
        }

        // Format into an item list.
        $types = theme('item_list', array(
          'items' => $items,
          'type' => 'ul',
        ));
      }
      elseif (count($schedule->types) == 1) {

        // Display the human readable name.
        $types = $node_types[array_pop($schedule->types)]->name;
      }
      else {

        // Display null.
        $types = 'NULL';
      }

      // Format the row.
      $row = array(
        $schedule->label,
        $schedule->name,
        $transition->name,
        $types,
        // Link to edit the schedule.
        l(t('edit'), 'admin/config/workbench/scheduler/schedules/' . $schedule->name . '/edit'),
        // Link to delete the scheduler.
        l(t('delete'), 'admin/config/workbench/scheduler/schedules/' . $schedule->name . '/delete'),
      );

      // Add to the rows array.
      $rows[] = $row;
    }
  }
  else {

    // Display message in first row.
    $rows[] = array(
      array(
        'data' => t('No Schedules Found'),
        'colspan' => 7,
      ),
    );
  }

  // Returned the themed table.
  return theme('table', array(
    'header' => $headers,
    'rows' => $rows,
  ));
}