checklistapi.admin.inc 1.88 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
<?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() {
  $header = array(
    t('Checklist'),
    t('Progress'),
    t('Last updated'),
    t('Last updated by'),
    t('Operations'),
  );
23 24
  $definitions = checklistapi_get_checklist_info();
  if (count($definitions)) {
25
    $rows = array();
26 27
    foreach ($definitions as $id => $definition) {
      $checklist = checklistapi_checklist_load($id);
28
      $row = array();
29 30 31 32
      $row[] = array(
        'data' => ($checklist->userHasAccess()) ? l($checklist->title, $checklist->path) : drupal_placeholder($checklist->title),
        'title' => (!empty($checklist->description)) ? $checklist->description : '',
      );
33 34 35 36 37 38
      $row[] = t('@completed of @total (@percent%) complete', array(
        '@completed' => $completed = (!empty($checklist->savedProgress['#completed_items'])) ? $checklist->savedProgress['#completed_items'] : 0,
        '@total' => $checklist->totalItems,
        '@percent' => round($completed / $checklist->totalItems * 100),
      ));
      $row[] = (!empty($checklist->savedProgress['#changed'])) ? format_date($checklist->savedProgress['#changed']) : t('n/a');
39
      $row[] = (isset($checklist->savedProgress['#changed_by'])) ? theme('username', array('account' => user_load($checklist->savedProgress['#changed_by']))) : t('n/a');
40
      $row[] = ($checklist->userHasAccess('edit') && $checklist->hasSavedProgress()) ? l(t('clear saved progress'), $checklist->path . '/clear', array(
41 42 43 44 45 46 47
        'query' => array('destination' => 'admin/reports/checklistapi'),
      )) : '';
      $rows[] = $row;
    }
  }
  else {
    $rows[][] = array('data' => t('No checklists available.'), 'colspan' => 5);
48 49 50
  }
  return theme('table', array('header' => $header, 'rows' => $rows));
}