You are here

function workbench_scheduler_admin_page in Workbench Scheduler 7

Same name and namespace in other branches
  1. 7.2 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 15
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('Start State'),
    ),
    array(
      'data' => t('End State'),
    ),
    array(
      'data' => t('Content Types'),
    ),
    array(
      'data' => t('Operations'),
      'colspan' => 2,
    ),
  );
  $rows = array();

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

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

    // 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 $name => $schedule) {

      // 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,
        $name,
        !empty($states[$schedule->start_state]) ? $states[$schedule->start_state] : '',
        !empty($states[$schedule->end_state]) ? $states[$schedule->end_state] : '',
        $types,
        // Link to edit the schedule.
        l(t('Edit'), 'admin/config/workbench/scheduler/schedules/' . $name . '/edit'),
        // Link to delete the scheduler.
        l(t('Delete'), 'admin/config/workbench/scheduler/schedules/' . $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,
      ),
    );
  }

  // Add a row for a link to add a new schedule.
  $rows[] = array(
    array(
      'data' => l(t('Add Schedule'), 'admin/config/workbench/scheduler/schedules/add'),
      'colspan' => 7,
    ),
  );

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