checklistapi.admin.inc 1.57 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
<?php

/**
 * @file
 * Admin page callback file for the Checklist API module.
 */

/**
 * Page callback: Form constructor for the report form.
 *
 * @see checklistapi_menu()
 *
 * @ingroup forms
 */
function checklistapi_report_form() {
16
  // Define table header.
17 18 19 20 21 22 23
  $header = array(
    t('Checklist'),
    t('Progress'),
    t('Last updated'),
    t('Last updated by'),
    t('Operations'),
  );
24 25 26

  // Build table rows.
  $rows = array();
27
  $definitions = checklistapi_get_checklist_info();
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
  foreach ($definitions as $id => $definition) {
    $checklist = checklistapi_checklist_load($id);
    $row = array();
    $row[] = array(
      'data' => ($checklist->userHasAccess()) ? l($checklist->title, $checklist->path) : drupal_placeholder($checklist->title),
      'title' => (!empty($checklist->description)) ? $checklist->description : '',
    );
    $row[] = t('@completed of @total (@percent%)', array(
      '@completed' => $checklist->getNumberCompleted(),
      '@total' => $checklist->getNumberOfItems(),
      '@percent' => round($checklist->getPercentComplete()),
    ));
    $row[] = $checklist->getLastUpdatedDate();
    $row[] = $checklist->getLastUpdatedUser();
    $row[] = ($checklist->userHasAccess('edit') && $checklist->hasSavedProgress()) ? l(t('clear saved progress'), $checklist->path . '/clear', array(
      'query' => array('destination' => 'admin/reports/checklistapi'),
    )) : '';
    $rows[] = $row;
46
  }
47 48 49 50 51 52 53 54 55

  // Compile table.
  $table = array(
    'header' => $header,
    'rows' => $rows,
    'empty' => t('No checklists available.'),
  );

  return theme('table', $table);
56
}