packageName] = $tallies[$task->packageName] ?? 0;
$tallies[$task->packageName]++;
}
$buf = '';
foreach ($tallies as $package => $tally) {
if ($tally === 1) {
$buf .= sprintf(
" - %s has %d task\n",
$package,
$tally
);
} else {
$buf .= sprintf(
" - %s has %d task(s)\n",
$package,
$tally
);
}
}
return $buf;
}
/**
* Make a table displaying a list of tasks.
*
* @param Task[] $tasks
* @param string[] $fields
* List of fields/columns to display.
* Some mix of: 'active', 'id', 'packageName', 'title', 'action'
* @return string
*/
public static function formatTaskTable($tasks, $fields)
{
$availableHeaders = ['active' => '', 'id' => 'ID', 'packageName' => 'Package', 'title' => 'Title', 'action' => 'Action'];
$header = [];
foreach ($fields as $field) {
$header[] = $availableHeaders[$field];
}
$fmtRun = function ($run) {
return sprintf('@%s %s', $run['type'], $run['code']);
};
$makeMainRow = function (Task $task, $runExpr) use ($fields) {
$row = [];
foreach ($fields as $field) {
switch ($field) {
case 'active':
$row[] = $task->active ? '+' : '-';
break;
case 'action':
$row[] = $runExpr;
break;
default:
$row[] = $task->{$field};
break;
}
}
return $row;
};
$makeExtraRow = function (Task $task, $runExpr) use ($fields) {
$row = [];
foreach ($fields as $field) {
switch ($field) {
case 'action':
$row[] = $runExpr;
break;
default:
$row[] = '';
break;
}
}
return $row;
};
$rows = [];
foreach ($tasks as $task) {
/** @var Task $task */
if (in_array('action', $fields)) {
foreach ($task->getParsedRun() as $n => $run) {
$maker = ($n === 0) ? $makeMainRow : $makeExtraRow;
$rows[] = $maker($task, $fmtRun($run));
}
} else {
$rows[] = $makeMainRow($task, null);
}
}
return TableHelper::formatTable($header, $rows);
}
}
__halt_compiler();----SIGNATURE:----OXm7b24OX0mmjgZfHO3IqZdkwZr8s2iRD8zw20ZcHy0LEmlX2BM9hGA6aroHxkTXBwwDYHxHV6y/wZd9tVyY5eR+dsCwfmW9OJPAbz9Oj9SG0VtNCOJpezt7/XWm7fTr/F+zoNhA8fRS1oF1NpHm1xZlOmb9i61dvliOZqQnxoM6e4ngWyLZssb/cx/M9lgmsadLXcKyW8MmuDeNhvYJ01V1l11I6NeRcvw6GjHii6JK3sgzVfeEKBA/kd0T/k15LNkj9K44xDGDk6dThhDPwNbmZw0yLhUxo1HBB322w+DTRpA2HhlTpZFXH5wXjxPqRCBUB8zBKCC7OSHxFRbFou9mZNzmJ7Vb3xdoiQ3kUS7kfUJ9aSdFGPViN8ClS9iLW34iMv/7QZtjq5A8/qjb5sb+TK8h5YTw3wINCjnO3fGDVgYPnZhxjCqfJjMOxUIXckTsERHhjZQPb1hyi/xjOKObtAu1X5w9slslqM8g0ql4jH1MHA5TDzmpXjQEbFQNGD+hrxKTc3Sk6/73sfyoVyX75/YErhX4JKsv68upYxOMTmAeZqgV7/8nFUq9yYkR4ZCcoUjZf/NaNRrv/3NMIowiFbdkN+L2VZM+C55JwJghnkvzXT8ymE2Y0vzpr7enrb5Z7wdnUBqqW39g7cFG22N0j+HGbTcdI9xs8foNsrU=----ATTACHMENT:----MzI3ODE4Mjg0NTczNjQ3MiA3OTMxNjA5MDA2NjQ4ODUxIDU3NDI2Mjc5NzA1ODcxNjg=