* @license PHP License
* @package WB
* @subpackage db
*/
WBClass::load('WBDatasource_Decorator',
'WBDatasource_Decorator_ITS');
/**
* Simple datasource decorator: ITS_CommentStat
*
* Create table to hold statistic
DROP TABLE IF EXISTS wbticketstatusstatistic;
CREATE TABLE `wbticketstatusstatistic` (
`ticstatid` int(11) unsigned NOT NULL AUTO_INCREMENT,
`ticid` int(11) unsigned NOT NULL DEFAULT '0',
`uid` int(11) unsigned NOT NULL DEFAULT '0',
`oldstatus` enum('new','trash','assigned','waitforstaff','waitforcustomer','solved','closed') NOT NULL DEFAULT 'new',
`newstatus` enum('new','trash','assigned','waitforstaff','waitforcustomer','solved','closed') NOT NULL DEFAULT 'new',
`changed` datetime NOT NULL DEFAULT '1970-01-01 00:00:00',
`duration` int(11) unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (`ticstatid`),
KEY `ticid` (`ticid`)
) ENGINE=MyISAM AUTO_INCREMENT=190 DEFAULT CHARSET=utf8 COMMENT='ITS ticket status statistic';
*
* Configure statitic table like this:
*
* Create a datasource like
-
ITS_CommentStat
* Walk the datasource every day to keep statistic table up to date
*
* @version 0.1.1
* @package WB
* @subpackage db
*/
class WBDatasource_Decorator_ITS_CommentStat extends WBDatasource_Decorator_ITS
{
/**
* Decorator's parameter list
*
* Parameters:
*
* @var array
*/
protected $parameter = array(
);
/**
* Ticket comment event data buffer
* @var buffer data
*/
private $ticketCommentBuffer = array();
/**
* Ticket statistic data buffer
* @var buffer data
*/
private $ticketStatBuffer = array();
/**
* Table access
* @var WBDatasource_Table
*/
private $table;
/**
* Named primary key of ticket
* @var string
*/
private $pTicket;
/**
* Constructor
*
*/
public function __construct($parmeter = array())
{
$this->table = WBClass::create('WBDatasource_Table');
$this->pTicket = $this->table->getIdentifier('ticket');
}
/**
* Start walk
*/
public function onStart(&$item)
{
$this->ticketCommentBuffer = array(
$this->pTicket => $item['xid'],
'changed' => $item['created'],
'oldsatus' => 'new',
'newstatus' => 'new',
);
$this->ticketStatBuffer = array();
}
/**
* actually decorate list item
*
* @param array $item
* @return void
*/
public function decorate(&$item)
{
$data = $this->extractData($item['commentbody']);
if (empty($data)) {
return;
}
$old = $this->ticketCommentBuffer;
if ($old[$this->pTicket] != $item['xid']) {
$this->saveStatistic($old[$this->pTicket]);
$this->ticketStatBuffer = array();
$old = array(
$this->pTicket => $item['xid'],
'changed' => $item['created'],
'oldsatus' => $data['status'],
'newstatus' => $data['status']
);
}
$duration = strtotime($item['created']) - strtotime($old['changed']);
$stat = array(
$this->pTicket => $item['xid'],
'uid' => $item['uid'],
'oldstatus' => $old['newstatus'],
'newstatus' => $data['status'],
'changed' => $item['created'],
'duration' => $duration,
);
$this->ticketStatBuffer[] = $stat;
$this->ticketCommentBuffer = $stat;
}
/**
* End handler
*
* @return void
*/
public function onEnd()
{
$this->saveStatistic($this->ticketCommentBuffer[$this->pTicket]);
}
/**
* Extract event data from comment body
*
* @param string XML body
* @return array
*/
private function extractData($body)
{
$start = strpos($body, '>ticketStatBuffer)) {
return;
}
$this->table->delete('ticketstatusstatistic', null, $id);
$this->table->save('ticketstatusstatistic', '__new', $this->ticketStatBuffer);
}
}