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:----Yc+t6ZIJKl4Yo/mi+hRVo66VxJcUcSE1037Tu8VVMBz/ZRuePbGaF4s4BF+03iA+vjlAJ1TdQOkufsgN76vPiui+G+qpan9YzdK7QgqfcQ2HO5mbthSFQXhypOmB2/W+1YvkFQ9uMdHye25GyP+CrzTj8ZsCdS8YKiGIW6GE7eN2MXYZCpZoKyQMEghMwdCwhh3EFbEaLj8fYYnwdM/zX/Ev4zZGK0ocnPauqKFll/c1wV8oP0VM/KTpAwDto6MKImWs0BxKO7y6KP5GgUGXcAPoQsLgSghi8FI2H6b88dy+roX/+qATs++z0aoDQPdkPVuTGoKQKw3m7NUmL9fr420B47obVDsrZghrBAHmJLtq/NeCLog4sSoCX4APWgMNydQNZkdeg+xl8jL3mkyT3P571xfm4N62GpNahcZW8OlfcgFFgY5KTV2km3dhHL1qBh0E1fqz0GABEfJ3QsKL1VdnjYY5hcmqEdyL8DKq0aeCXorrRJb6iKhxNoY7Km/kqLayvpuhFhT+E1hNDmKwIbOTcXiorfvXIbLXbC4MpOAWpZQ55Z9LA/hH2aMKsaQtSCkZCCijnfWcmNU4w7gGci0oWUivWDJGjNp41FJvPL9S4acY54wt1oH1hKIYod3eJgKwH9d4cv7K9qMNacvHx8Cb8Z5+U1rTq7AQhVB/AKg=----ATTACHMENT:----NjM2NTIzNTcyNTMxNjYzNiA5ODY2NDIxMTk4MzE5MDEzIDgyNTAyMDg3NTIzODMxMTM=