You are here

function drush_checklistapi_list in Checklist API 7

Drush callback for checklist listing.

File

./checklistapi.drush.inc, line 46
Drush commands for the Checklist API module.

Code

function drush_checklistapi_list() {
  $definitions = checklistapi_get_checklist_info();
  if (empty($definitions)) {
    return drush_print(dt('No checklists available.'));
  }

  // Build table rows.
  $rows = array();

  // The first row is the table header.
  $rows[] = array(
    dt('Checklist'),
    dt('Progress'),
    dt('Last updated'),
    dt('Last updated by'),
  );
  foreach ($definitions as $id => $definition) {
    $checklist = checklistapi_checklist_load($id);
    $row = array();
    $row[] = dt('!title (!id)', array(
      '!title' => strip_tags($checklist->title),
      '!id' => $id,
    ));
    $row[] = dt('@completed of @total (@percent%)', array(
      '@completed' => $checklist
        ->getNumberCompleted(),
      '@total' => $checklist
        ->getNumberOfItems(),
      '@percent' => round($checklist
        ->getPercentComplete()),
    ));
    $row[] = $checklist
      ->getLastUpdatedDate();
    $row[] = strip_tags($checklist
      ->getLastUpdatedUser());
    $rows[] = $row;
  }
  return drush_format_table($rows, TRUE);
}