Skip to content

Commit

Permalink
SLA is now included in search
Browse files Browse the repository at this point in the history
Fixes #184
Fixes #182
  • Loading branch information
inghamn committed Jan 21, 2015
1 parent 78a37d9 commit 177346f
Show file tree
Hide file tree
Showing 10 changed files with 343 additions and 63 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ crm/data/media/*
crm/data/sessions/*
crm/data/templates/*
crm/data/blocks/*
crm/data/workers/*
site_config.inc
crm/scripts/backup.cnf
crm/scripts/migration/0.0-1.0/calltrack/3_tickets.php
Expand Down
44 changes: 30 additions & 14 deletions crm/Models/Category.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* @copyright 2011-2014 City of Bloomington, Indiana
* @copyright 2011-2015 City of Bloomington, Indiana
* @license http://www.gnu.org/licenses/agpl.txt GNU/AGPL, see LICENSE.txt
* @author Cliff Ingham <inghamn@bloomington.in.gov>
*/
Expand All @@ -16,6 +16,7 @@ class Category extends ActiveRecord
protected $categoryGroup;

private $displayPermissionLevelHasChanged = false;
private $slaDaysHasChanged = false;

/**
* Populates the object with data
Expand Down Expand Up @@ -87,9 +88,11 @@ public function save() {
$this->setLastModified(date(DATE_FORMAT));
parent::save();

if ($this->displayPermissionLevelHasChanged) {
if ($this->displayPermissionLevelHasChanged || $this->slaDaysHasChanged) {
// Spawn a background process to reindex the search engine
$cmd = PHP.' '.APPLICATION_HOME.'/scripts/workers/indexCategory.php '.$this->getId().' '.$_SERVER['SITE_HOME'];
$cmd = PHP.' '.APPLICATION_HOME.'/scripts/workers/indexCategory.php '.SITE_HOME.' '.$this->getId();
if ($this->slaDaysHasChanged) { $cmd .= ' open'; }

shell_exec("nohup $cmd > /dev/null 2>&1 &");
}
}
Expand All @@ -113,23 +116,36 @@ public function getLastModified($format=null, \DateTimeZone $timezone=null) { re
public function setName ($s) { parent::set('name', $s); }
public function setDescription ($s) { parent::set('description', $s); }
public function setPostingPermissionLevel($s) { parent::set('postingPermissionLevel',$s); }
public function setDisplayPermissionLevel($s) {
if ($this->getId()) {
$s = trim($s);
if ( $this->getDisplayPermissionLevel()
&& $this->getDisplayPermissionLevel() != $s) {
$this->displayPermissionLevelHasChanged = true;
}
}
parent::set('displayPermissionLevel',$s);
}
public function setSlaDays ($i) { parent::set('slaDays', (int)$i); }
public function setDepartment_id ($id) { parent::setForeignKeyField( __namespace__.'\Department', 'department_id', $id); }
public function setCategoryGroup_id($id) { parent::setForeignKeyField( __namespace__.'\CategoryGroup', 'categoryGroup_id', $id); }
public function setDepartment (Department $o) { parent::setForeignKeyObject(__namespace__.'\Department', 'department_id', $o); }
public function setCategoryGroup(CategoryGroup $o) { parent::setForeignKeyObject(__namespace__.'\CategoryGroup', 'categoryGroup_id', $o); }
public function setLastModified($d) { parent::setDateData('lastModified', $d); }

public function setDisplayPermissionLevel($s)
{
if ($this->getId()) {
$s = trim($s);
if ( $this->getDisplayPermissionLevel()
&& $this->getDisplayPermissionLevel() != $s) {
$this->displayPermissionLevelHasChanged = true;
}
}
parent::set('displayPermissionLevel',$s);
}

public function setSlaDays($i)
{
$i = (int)$i;

if ($this->getId()) {
if ($this->getSlaDays() != $i) {
$this->slaDaysHasChanged = true;
}
}
parent::set('slaDays', $i);
}

/**
* @param array $post
*/
Expand Down
26 changes: 20 additions & 6 deletions crm/Models/Search.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* @copyright 2012-2014 City of Bloomington, Indiana
* @copyright 2012-2015 City of Bloomington, Indiana
* @license http://www.gnu.org/licenses/agpl.txt GNU/AGPL, see LICENSE.txt
* @author Cliff Ingham <inghamn@bloomington.in.gov>
*/
Expand All @@ -16,6 +16,8 @@ class Search
const MAX_RAW_RESULTS = 10000;
const DATE_FORMAT = 'Y-m-d\TH:i:s\Z';

const SLA_OVERDUE_FUNCTION = '{!frange l=0}if(exists(slaDays),sub(if(exists(closedDate),ms(closedDate,enteredDate),ms(NOW,enteredDate)),product(slaDays,86400000)),-1)';

/**
* The full list of fields that can be searched on
*
Expand All @@ -41,7 +43,8 @@ class Search
'label_id' => 'Label',
'contactMethod_id'=> 'Received Via',
'enteredDate' => 'Case Date',
'bbox' => 'Bounding Box'
'bbox' => 'Bounding Box',
'sla' => 'SLA'
);

/**
Expand Down Expand Up @@ -179,6 +182,7 @@ public function query(&$get, $raw=false)

// Facets
$additionalParameters['facet'] = 'true';
$additionalParameters['facet.query'] = self::SLA_OVERDUE_FUNCTION;
$additionalParameters['facet.field'] = self::$facetFields['ticket'];

// Search Parameters
Expand All @@ -198,14 +202,16 @@ public function query(&$get, $raw=false)
$fq[] = "$field:[$startDate TO $endDate]";
}
}
// Added else if statement by Quan on Aug 5, 2013
// coordinates is a not a numeric value but does not need to be quoted.
else if (false !== strpos($field, 'bbox')) {
elseif (false !== strpos($field, 'bbox')) {
$key = 'coordinates';
list($minLat, $minLng, $maxLat, $maxLng) = explode(',', $get[$field]);
$value = "[$minLat,$minLng TO $maxLat,$maxLng]";
$fq[] = "$key:$value";
}
elseif ($field == 'sla' && $get[$field] == 'overdue') {
$fq[] = self::SLA_OVERDUE_FUNCTION;
}
else {
$value = is_numeric($get[$field])
? $get[$field]
Expand Down Expand Up @@ -313,12 +319,20 @@ private function createDocument($record)
$document->addField('recordKey', "t_{$record->getId()}");
$document->addField('recordType', 'ticket');

$document->addField('enteredDate', $record->getEnteredDate(Search::DATE_FORMAT), \DateTimeZone::UTC);
$document->addField('enteredDate', $record->getEnteredDate(Search::DATE_FORMAT), \DateTimeZone::UTC);
if ($record->getClosedDate()) {
$document->addField('closedDate', $record->getClosedDate (Search::DATE_FORMAT), \DateTimeZone::UTC);
}

if ($record->getLatLong()) {
$document->addField('coordinates', $record->getLatLong());
}
if ($record->getCategory()) {
$document->addField('displayPermissionLevel', $record->getCategory()->getDisplayPermissionLevel());
$c = $record->getCategory();
$document->addField('displayPermissionLevel', $c->getDisplayPermissionLevel());
if ($c->getSlaDays()) {
$document->addField('slaDays', $c->getSlaDays());
}
}

// Ticket information indexing
Expand Down
11 changes: 11 additions & 0 deletions crm/blocks/html/tickets/searchForm.inc
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,17 @@ if (Person::isAllowed('tickets','add')) {
";
}
}
$value = $this->solrObject->facet_counts->facet_queries->{Search::SLA_OVERDUE_FUNCTION};
$url = clone $currentURL;
$url->sla = 'overdue';
echo "
<div class=\"collapsible\">
<h3 class=\"hd\">{$this->_('labels.sla')}</h3>
<ul class=\"bd\">
<li><a href=\"$url\">{$this->_('labels.overdue')}</a> ($value)</li>
</ul>
</div>
";
}
?>
<div class="collapsible">
Expand Down
59 changes: 32 additions & 27 deletions crm/blocks/html/tickets/searchParameters.inc
Original file line number Diff line number Diff line change
Expand Up @@ -42,34 +42,39 @@ if (!empty($_GET['query'])
// There may only be one filterQuery
if (!is_array($fq)) { $fq = [$fq]; }

foreach ($fq as $facet) {
preg_match('/([^:]+):(.+)/', $facet, $matches);
$key = $matches[1];
$value = $matches[2];
// Users should not change the permission level they're searching as
if ($key != 'displayPermissionLevel') {
$deleteURL = clone $currentURL;
foreach ($fq as $filter) {
if (preg_match('/([^:]+):(.+)/', $filter, $matches)) {
$key = $matches[1];
$value = $matches[2];

if($key === 'coordinates') {
if (isset($deleteURL->zoom)) { unset($deleteURL->zoom); }
$key = 'bbox';
if (isset($deleteURL->$key)) {
unset($deleteURL->$key);
}
$displayName = Search::$searchableFields[$key];
echo $helper->buttonLink($deleteURL, $displayName, 'delete');
}
else {
if (isset($deleteURL->$key)) {
unset($deleteURL->$key);
}
$displayName = Search::$searchableFields[$key];
$displayValue = Search::getDisplayName('ticket', $key, $value);
if ($displayValue) {
echo $helper->buttonLink($deleteURL, "$displayName: $displayValue", 'delete');
}
}
}
if (array_key_exists($key, Search::$searchableFields)) {
$deleteURL = clone $currentURL;

if ($key === 'coordinates') {
if (isset($deleteURL->zoom)) { unset($deleteURL->zoom); }
if (isset($deleteURL->bbox)) { unset($deleteURL->bbox); }

$displayName = Search::$searchableFields['bbox'];
echo $helper->buttonLink($deleteURL, $displayName, 'delete');
}
else {
if (isset($deleteURL->$key)) { unset($deleteURL->$key); }

$displayName = Search::$searchableFields[$key];
$displayValue = Search::getDisplayName('ticket', $key, $value);
if ($displayValue) {
echo $helper->buttonLink($deleteURL, "$displayName: $displayValue", 'delete');
}
}
}
}
else {
if ($filter == Search::SLA_OVERDUE_FUNCTION) {
$deleteURL = clone $currentURL;
if (isset($deleteURL->sla)) { unset($deleteURL->sla); }
echo $helper->buttonLink($deleteURL, "{$this->_('labels.sla')}: {$this->_('labels.overdue')}", 'delete');
}
}
}
echo "</span>";
}
Expand Down
Binary file modified crm/language/en_US.mo
Binary file not shown.
7 changes: 5 additions & 2 deletions crm/language/en_US.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgstr ""
"Project-Id-Version: uReport 1.9\n"
"Report-Msgid-Bugs-To: ureport@googlegroups.com\n"
"POT-Creation-Date: 2013-09-20 16:33-0400\n"
"PO-Revision-Date: 2014-07-11 13:56-0500\n"
"PO-Revision-Date: 2015-01-21 10:13-0500\n"
"Last-Translator: Cliff Ingham <inghamn@bloomington.in.gov>\n"
"Language-Team: City of Bloomington <ureport@googlegroups.com>\n"
"MIME-Version: 1.0\n"
Expand Down Expand Up @@ -295,7 +295,10 @@ msgstr "Service Level Agreement"
#. The abbreviation for "Service Level Agreement"
#. http://en.wikipedia.org/wiki/Service-level_agreement
msgid "labels.sla"
msgstr "SLA"
msgstr "SLA (Service Level)"

msgid "labels.overdue"
msgstr "Over SLA"

#. Reports that users send in are organized into Tickets
#. A ticket can contain multiple issue reports that are related, usually by location
Expand Down
Loading

0 comments on commit 177346f

Please sign in to comment.