Skip to content

Instantly share code, notes, and snippets.

@jnankin
Created May 22, 2012 15:17
Show Gist options
  • Save jnankin/2769704 to your computer and use it in GitHub Desktop.
Save jnankin/2769704 to your computer and use it in GitHub Desktop.
Transforming Track Tickets to PDF
<?
class TracTicketsToPdfTask extends sfBaseTask {
/**
* @see sfTask
*/
protected function configure() {
$this->addOptions(array(
new sfCommandOption('application', null, sfCommandOption::PARAMETER_REQUIRED, 'The application name', 'public'),
new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environment', 'prod'),
new sfCommandOption('filename', null, sfCommandOption::PARAMETER_REQUIRED, 'Filename containing the trac csv report', 'query.csv'),
new sfCommandOption('outfile', null, sfCommandOption::PARAMETER_REQUIRED, 'Filename where report will be written to', 'tickets.html'),
new sfCommandOption('min_id', null, sfCommandOption::PARAMETER_REQUIRED, 'Only include ticket ids greater than or equal to x', 0),
new sfCommandOption('include_tickets', null, sfCommandOption::PARAMETER_REQUIRED, 'Only include ticket ids in this list (separated by commas)', '')
));
$this->namespace = 'yourapp';
$this->name = 'tracTicketsToPdf';
$this->briefDescription = 'Makes a trac report into a printable pdf for sprint tickets';
$this->detailedDescription = "";
}
/**
* @see sfTask
*/
protected function execute($arguments = array(), $options = array()) {
sfContext::createInstance($this->configuration);
$minTicketId = $options['min_id'];
$ticketsToInclude = !$options['include_tickets']) ? null : explode(',', $options['include_tickets']);
ob_start();?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=PT+Sans:regular,bold&amp;amp;subset=latin" />
<style>
body {
margin: 0px;
padding: 20px;
font-family: 'PT Sans', Arial, Helvetica, sans-serif;
font-size: 14px;
}
td {
width: 200px;
font-weight: bold;
border: 1px solid black;
padding: 10px;
}
tr.blank td {
height: 100px;
vertical-align: top;
font-weight: normal;
}
</style>
</head>
<body>
<?php
//skip the field title line
if (($handle = fopen($options['filename'], "r")) !== FALSE) {
fgetcsv($handle);
$row = 1;
while (($data = fgetcsv($handle)) !== FALSE) {
list($id,$summary,$milestone,$owner,$type,$status,$priority,$qacomplete,$estimatedhours) = $data;
if ($minTicketId &amp;amp;&amp;amp; $id < $minTicketId) continue;
else if ($ticketsToInclude &amp;amp;&amp;amp; array_search($id, $ticketsToInclude) === false) continue;
?>
<div>
<div style="float: left; padding: 10px; border: 1px solid black; font-size: 36px; font-weight: bold;">
<?=$id;?>
</div>
<div style="float: left; padding-left: 20px;">
<div style="font-size: 30px; padding-bottom: 10px;"><?=$summary;?></div>
<strong>Milestone:</strong> <?=$milestone;?> <span style="white-space: pre;"> </span><strong>Owner:</strong> <?=$owner;?>
</div>
</div>
<img src="yourlogo.png" align="right"/>
<div style="clear: both; margin-bottom: 20px;">&amp;amp;nbsp</div>
<table align="center" style="border-collapse: collapse; border: 1px solid black;">
<tr>
<td>Type</td><td>Priority</td><td>Est. Hours</td><td>QA</td>
</tr>
<tr class="blank">
<td><?=$type;?></td><td><?=$priority;?></td><td><?=$estimatedhours;?></td><td></td>
</tr>
</table>
<? if ($row % 2 == 0) : ?>
<DIV style="page-break-after:always"></DIV>
<? else: ?>
<DIV style="margin-bottom: 200px;"></DIV>
<? endif; ?>
<? $row++;
}
fclose($handle);
}
?>
</body>
</html>
<?
$html = ob_get_clean();
file_put_contents($options['outfile'], $html);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment