From 4d1193e4ced7f9fd66eeea83698daca29c47cd62 Mon Sep 17 00:00:00 2001 From: Jared Hancock <jared@osticket.com> Date: Thu, 8 May 2014 11:55:51 -0500 Subject: [PATCH] filter: Allow specification of sorting for criteria Allow developers to specify a sorting position for groups of fields selectable in the criteria select drop-down --- include/class.dynamic_forms.php | 4 ++-- include/class.filter.php | 26 +++++++++++++++----------- include/class.organization.php | 2 +- include/class.topic.php | 2 +- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/include/class.dynamic_forms.php b/include/class.dynamic_forms.php index 437b9c124..2da492069 100644 --- a/include/class.dynamic_forms.php +++ b/include/class.dynamic_forms.php @@ -246,7 +246,7 @@ Filter::addSupportedMatches('User Data', function() { $matches['field.'.$f->get('id')] = 'User / '.$f->getLabel(); } return $matches; -}); +}, 20); class TicketForm extends DynamicForm { static $instance; @@ -330,7 +330,7 @@ Filter::addSupportedMatches('Ticket Data', function() { $matches['field.'.$f->get('id')] = 'Ticket / '.$f->getLabel(); } return $matches; -}); +}, 30); // Manage materialized view on custom data updates Signal::connect('model.created', array('TicketForm', 'updateDynamicDataView'), diff --git a/include/class.filter.php b/include/class.filter.php index 951832926..50d32f6e3 100644 --- a/include/class.filter.php +++ b/include/class.filter.php @@ -20,13 +20,17 @@ class Filter { static $match_types = array( 'User Information' => array( - 'name' => 'Name', - 'email' => 'Email', + array('name' => 'Name', + 'email' => 'Email', + ), + 900 ), 'Email Meta-Data' => array( - 'reply-to' => 'Reply-To Email', - 'reply-to-name' => 'Reply-To Name', - 'addressee' => 'Addressee (To and Cc)', + array('reply-to' => 'Reply-To Email', + 'reply-to-name' => 'Reply-To Name', + 'addressee' => 'Addressee (To and Cc)', + ), + 200 ), ); @@ -320,16 +324,16 @@ class Filter { } static function getSupportedMatches() { foreach (static::$match_types as $k=>&$v) { - if (is_callable($v)) - $v = $v(); + if (is_callable($v[0])) + $v[0] = $v[0](); } unset($v); - ksort(static::$match_types); - return static::$match_types; + uasort(static::$match_types, function($a, $b) { return $a[1] - $b[1]; }); + return array_map(function($a) { return $a[0]; }, static::$match_types); } - static function addSupportedMatches($group, $callable) { - static::$match_types[$group] = $callable; + static function addSupportedMatches($group, $callable, $order=10) { + static::$match_types[$group] = array($callable, $order); } static function getSupportedMatchFields() { diff --git a/include/class.organization.php b/include/class.organization.php index 69924a6c3..a21c916bf 100644 --- a/include/class.organization.php +++ b/include/class.organization.php @@ -396,6 +396,6 @@ Filter::addSupportedMatches('Organization Data', function() { $matches['field.'.$f->get('id')] = 'Organization / '.$f->getLabel(); } return $matches; -}); +},40); Organization::_inspect(); ?> diff --git a/include/class.topic.php b/include/class.topic.php index 18bda5a53..8d4d460ab 100644 --- a/include/class.topic.php +++ b/include/class.topic.php @@ -273,4 +273,4 @@ class Topic { } // Add fields from the standard ticket form to the ticket filterable fields -Filter::addSupportedMatches('Help Topic', array('topicId' => 'Topic ID')); +Filter::addSupportedMatches('Help Topic', array('topicId' => 'Topic ID'), 100); -- GitLab