mirror of
https://github.com/FOSSBilling/FOSSBilling.git
synced 2026-11-25 22:33:18 +09:00
Finish ticket-wait-time
This commit is contained in:
commit
0fd9aebd21
4 files changed
+122
-5
No files matched your search
@@ -843,6 +843,24 @@ class Service implements \Box\InjectionAwareInterface
|
||||
return $ticket->hash;
|
||||
}
|
||||
|
||||
public function canClientSubmitNewTicket(\Model_Client $client, array $config)
|
||||
{
|
||||
$hours = $config['wait_hours'];
|
||||
|
||||
$lastTicket = $this->di['db']->findOne('SupportTicket', 'client_id = :client_id ORDER BY created_at DESC', array(':client_id' => $client->id));
|
||||
if (!$lastTicket instanceof \Model_SupportTicket) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$timeSinceLast = round(abs(strtotime($lastTicket->created_at) - strtotime(date('c'))) / 3600, 0);
|
||||
|
||||
if ($timeSinceLast < $hours) {
|
||||
throw new \Box_Exception(sprintf('You can submit one ticket per %s hours. %s hours left', $hours, $hours - $timeSinceLast));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function ticketCreateForClient(\Model_Client $client, \Model_SupportHelpdesk $helpdesk, array $data)
|
||||
{
|
||||
//@todo validate task params
|
||||
@@ -857,6 +875,13 @@ class Service implements \Box\InjectionAwareInterface
|
||||
throw new \Box_Exception('We have already received this request.');
|
||||
}
|
||||
|
||||
$mod = $this->di['mod']('support');
|
||||
$config = $mod->getConfig();
|
||||
|
||||
if (isset($config['wait_hours']) && is_numeric($config['wait_hours'])) {
|
||||
$this->canClientSubmitNewTicket($client, $config);
|
||||
}
|
||||
|
||||
$event_params = $data;
|
||||
$event_params['client_id'] = $client->id;
|
||||
$this->di['events_manager']->fire(array('event' => 'onBeforeClientOpenTicket', 'params' => $event_params));
|
||||
@@ -882,19 +907,17 @@ class Service implements \Box\InjectionAwareInterface
|
||||
|
||||
$this->di['events_manager']->fire(array('event' => 'onAfterClientOpenTicket', 'params' => array('id' => $ticket->id)));
|
||||
|
||||
$mod = $this->di['mod']('support');
|
||||
$config = $mod->getConfig();
|
||||
if (isset($config['autorespond_enable'])
|
||||
&& $config['autorespond_enable']
|
||||
&& isset($config['autorespond_message_id'])
|
||||
&& !empty($config['autorespond_message_id'])
|
||||
) {
|
||||
try {
|
||||
$cannedObj = $this->di['db']->getExistingModelById('SupportPr', $config['autorespond_message_id'], 'Canned reply not found');
|
||||
$canned = $this->cannedToApiArray($cannedObj);
|
||||
$cannedObj = $this->di['db']->getExistingModelById('SupportPr', $config['autorespond_message_id'], 'Canned reply not found');
|
||||
$canned = $this->cannedToApiArray($cannedObj);
|
||||
$staffService = $this->di['mod_service']('staff');
|
||||
$admin = $staffService->getCronAdmin();
|
||||
if (isset($canned['content']) && $admin instanceof \Model_Admin){
|
||||
if (isset($canned['content']) && $admin instanceof \Model_Admin) {
|
||||
$this->ticketReply($ticket, $admin, $canned['content']);
|
||||
}
|
||||
|
||||
|
||||
@@ -88,6 +88,15 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<legend>{% trans 'Wait time - how many hours user needs to wait until consequent ticket submission' %}</legend>
|
||||
<div class="rowElem noborder">
|
||||
<label>{% trans 'Wait time in hours' %}</label>
|
||||
<div class="formRight">
|
||||
<input type="text" name="wait_hours" value="{{ params.wait_hours }}" />
|
||||
</div>
|
||||
<div class="fix"></div>
|
||||
</div>
|
||||
|
||||
<input type="submit" value="{% trans 'Update' %}" class="greyishBtn submitForm" />
|
||||
<input type="hidden" name="ext" value="mod_support" />
|
||||
</fieldset>
|
||||
|
||||
@@ -2545,5 +2545,53 @@ class ServiceTest extends \PHPUnit_Framework_TestCase
|
||||
$result = $this->service->ticketTaskComplete($model);
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
public function testCanClientSubmitNewTicketProvider()
|
||||
{
|
||||
|
||||
$ticket = new \Model_SupportTicket();
|
||||
$ticket->loadBean(new \RedBeanPHP\OODBBean());
|
||||
$ticket->client_id = 5;
|
||||
$ticket->created_at = date('c');
|
||||
|
||||
$ticket2 = new \Model_SupportTicket();
|
||||
$ticket2->loadBean(new \RedBeanPHP\OODBBean());
|
||||
$ticket2->client_id = 5;
|
||||
$ticket2->created_at = date('c', strtotime("-2 days"));;
|
||||
|
||||
return array(
|
||||
array($ticket, 24, false), //Ticket is created today, exception should be thrown
|
||||
array(null, 24, true), //No previously created tickets found, can submit a ticket
|
||||
array($ticket2, 24, true) //Last ticket submitted 2 days ago, can submit a ticket
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider testCanClientSubmitNewTicketProvider
|
||||
*/
|
||||
public function testCanClientSubmitNewTicket($ticket, $hours, $expected)
|
||||
{
|
||||
if (!$expected) {
|
||||
$this->setExpectedException('\Box_Exception');
|
||||
}
|
||||
$dbMock = $this->getMockBuilder('\Box_Database')->disableOriginalConstructor()->getMock();
|
||||
$dbMock->expects($this->atLeastOnce())
|
||||
->method('findOne')
|
||||
->will($this->returnValue($ticket));
|
||||
|
||||
$di = new \Box_Di();
|
||||
$di['db'] = $dbMock;
|
||||
$this->service->setDi($di);
|
||||
|
||||
$client = new \Model_Client();
|
||||
$client->loadBean(new \RedBeanPHP\OODBBean());
|
||||
$client->id = 5;
|
||||
|
||||
$config = array('wait_hours' => $hours);
|
||||
|
||||
$result = $this->service->canClientSubmitNewTicket($client, $config);
|
||||
$this->assertTrue($result);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,4 +82,41 @@ class Api_Client_SupportTest extends BBDbApiTestCase
|
||||
$id = $this->api_client->support_ticket_create($data);
|
||||
$this->assertInternalType('int', $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Box_Exception
|
||||
*/
|
||||
public function testCanSubmitTicketException()
|
||||
{
|
||||
$this->api_admin->extension_config_save(
|
||||
array(
|
||||
'ext' => 'mod_support',
|
||||
'wait_hours' => 24,
|
||||
));
|
||||
$data = array(
|
||||
'client_id' => 1,
|
||||
'support_helpdesk_id' => 1,
|
||||
'subject' => 'this is subject',
|
||||
'content' => 'this is content',
|
||||
);
|
||||
$this->api_client->support_ticket_create($data);
|
||||
$this->api_client->support_ticket_create($data); //should throw an exception because 1 ticket per 24 hours is allowed
|
||||
}
|
||||
|
||||
public function testCanSubmitTicket()
|
||||
{
|
||||
$this->api_admin->extension_config_save(
|
||||
array(
|
||||
'ext' => 'mod_support',
|
||||
'wait_hours' => '',
|
||||
));
|
||||
$data = array(
|
||||
'client_id' => 1,
|
||||
'support_helpdesk_id' => 1,
|
||||
'subject' => 'this is subject',
|
||||
'content' => 'this is content',
|
||||
);
|
||||
$this->api_client->support_ticket_create($data);
|
||||
$this->api_client->support_ticket_create($data); //should not throw an exception as delay time is not set
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user