You are here

function drush_checklistapi_info in Checklist API 7

Drush callback for checklist info.

File

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

Code

function drush_checklistapi_info() {
  $checklist = drush_get_context('checklist');

  // Print the help.
  if (!empty($checklist->help)) {
    drush_print(strip_tags($checklist->help));
  }

  // Print last updated and progress details.
  if ($checklist
    ->hasSavedProgress()) {
    drush_print('');
    drush_print(dt('Last updated @date by !user', array(
      '@date' => $checklist
        ->getLastUpdatedDate(),
      '!user' => strip_tags($checklist
        ->getLastUpdatedUser()),
    )));
    drush_print(dt('@completed of @total (@percent%) complete', array(
      '@completed' => $checklist
        ->getNumberCompleted(),
      '@total' => $checklist
        ->getNumberOfItems(),
      '@percent' => round($checklist
        ->getPercentComplete()),
    )));
  }

  // Loop through groups.
  $groups = $checklist->items;
  foreach (element_children($groups) as $group_key) {
    $group =& $groups[$group_key];

    // Print group title.
    drush_print('');
    drush_print(strip_tags($group['#title']) . ':');

    // Loop through items.
    foreach (element_children($group) as $item_key) {
      $item =& $group[$item_key];
      $saved_item = !empty($checklist->savedProgress[$item_key]) ? $checklist->savedProgress[$item_key] : 0;

      // Build title.
      $title = strip_tags($item['#title']);
      if ($saved_item) {

        // Append completion details.
        $user = user_load($saved_item['#uid']);
        $title .= dt(' - Completed @time by !user', array(
          '@time' => format_date($saved_item['#completed'], 'short'),
          '!user' => strip_tags($user->name),
        ));
      }

      // Print the list item.
      drush_print(dt(' [!x] !title', array(
        '!x' => $saved_item ? 'x' : ' ',
        '!title' => $title,
      )));
    }
  }
}