Add each ThreadEntry, where you want it displayed. * -> Add ThreadSummary where you want summary displayed. Each calculates and displays required data using original output format and formula. * @author Grizly, using Masino Sinaga's original code. * * Last update Fri Nov 8 2013 * * TODO: Need to test for re-opened tickets * TODO: Figure out what the feck is wrong with old PHP versions and that is_date code.. */ /** * The format of the timestamp, must not change! * @var string */ define('MOD_DURATION_DATEFORMAT', "Y-m-d H:i:s"); class MOD_Duration { /** * Current number of thread entries. * @var int */ private $entrycount; /** * Timestamp of creation of ticket * @var DateTime */ private $created; /** * Timestamp of ticket closure * @var DateTime */ private $closed; /** * Timestamp of ticket last update * @var DateTime */ private $updated; /** * Timestamp of ticket due date * @var DateTime */ private $duedate; /** * Timestamp of the last entry to be added. (used to calculate the entries duration) * @var DateTime */ private $last; /** * @var bool */ private $isopen; /** * osTicket MOD. * * Used to calculate time spent waiting between updates to a tickets thread, and to produce a summary at the end indicating * the amount of time in total spent on the ticket. * * @param object the ticket object! */ public function MOD_Duration($ticket){ $this->isopen = $ticket->isOpen(); if(!$this->isopen){ $this->closed = $ticket->getCloseDate(); } $this->duedate = $ticket->getDueDate(); } /** * Calculate the time difference between two times. * Mostly Masino Sinaga's original code! * @param Date $a * @param Date $b * @return string Formatted string useful for printing on a ticket thread. Or an empty string if called incorrectly. */ function getDiff($a, $b) { $diff = intval(strtotime($b)) - intval(strtotime($a)); $diffday = round(intval(floor($diff/86400))); $modday = ($diff%86400); $diffhour = round(intval(floor($modday/3600)),0); $diffminute = round(intval(floor(($modday%3600)/60)),0); $diffsecond = round(($modday%60),0); //>0 will add to output by not being 0.. ;-) $o = ''; $o.= ($diffday>0) ? $diffday .'d, ' : ''; $o.= ($diffhour>0) ? $diffhour .'h, ' : ''; $o.= ($diffminute>0) ? $diffminute.'m, ' : ''; $o.= ($diffsecond>0) ? $diffsecond.'s.' : '.'; return $o; //make it nice and small, with no zero's //uncomment to get the original output. // return round($diffday)." Day(s), ".round($diffhour)." Hour(s), ".round($diffminute,0)." Minute(s), ".round($diffsecond,0)." Second(s)."; } /** * Grab the values from the thead-entry, this should be called once for each entry. * Currently only tested using showNotesInline mode.. so you might want to check for the other. * * // I like it in the heading, between title and poster:
Error fetching ticket thread - get technical help.
'; */ public function printThreadSummary(){ //sanity check if(!$this->is_date($this->created)){ print 'Unable to compute time.'; return; } //Original had different formatting based on whether the ticket was open or not. if($this->isopen){ print "Ticket open for ".$this->getDiff($this->created, date(MOD_DURATION_DATEFORMAT)); if($this->is_date($this->duedate)){ //TODO: Make this some form of passive-aggressive RED or something should it be overdue? print "\n