diff --git a/include/class.dynamic_forms.php b/include/class.dynamic_forms.php index 97348ff2c2e66dff5e50a4fce246925064eaf94d..2da492069c3bd8aae2b02ca61afef2c9e2dee0e1 100644 --- a/include/class.dynamic_forms.php +++ b/include/class.dynamic_forms.php @@ -74,10 +74,13 @@ class DynamicForm extends VerySimpleModel { return call_user_func_array($delegate, $args); } - function getField($name) { - foreach ($this->getFields() as $f) + function getField($name, $cache=true) { + foreach ($this->getFields($cache) as $f) { if (!strcasecmp($f->get('name'), $name)) return $f; + } + if ($cache) + return $this->getField($name, false); } function hasField($name) { @@ -235,6 +238,15 @@ class UserForm extends DynamicForm { return static::$instance; } } +Filter::addSupportedMatches('User Data', function() { + $matches = array(); + foreach (UserForm::getInstance()->getFields() as $f) { + if (!$f->hasData()) + continue; + $matches['field.'.$f->get('id')] = 'User / '.$f->getLabel(); + } + return $matches; +}, 20); class TicketForm extends DynamicForm { static $instance; @@ -315,10 +327,10 @@ Filter::addSupportedMatches('Ticket Data', function() { foreach (TicketForm::getInstance()->getFields() as $f) { if (!$f->hasData()) continue; - $matches['field.'.$f->get('id')] = $f->getLabel(); + $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 4c36541e6e262f097d6e7989d0ee9148d6760496..50d32f6e3e530b6912956cb1b79aae2fddad0c7f 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 ), ); @@ -318,17 +322,18 @@ class Filter { if ($this->getHelpTopic()) $ticket['topicId'] = $this->getHelpTopic(); } - /* static */ function getSupportedMatches() { + 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); - 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 e80e435c75283e00308c0fa9894aca8e18b42199..78332b1e60067de88efac03bd3306e7da0a69dcf 100644 --- a/include/class.organization.php +++ b/include/class.organization.php @@ -193,6 +193,20 @@ class Organization extends OrganizationModel { $form->save(); } + function getFilterData() { + $vars = array(); + foreach ($this->getDynamicData() as $entry) { + if ($entry->getForm()->get('type') != 'O') + continue; + foreach ($entry->getFields() as $f) + $vars['field.'.$f->get('id')] = $f->toString($f->getClean()); + // Add special `name` field + $f = $entry->getForm()->getField('name'); + $vars['field.'.$f->get('id')] = $this->getName(); + } + return $vars; + } + function to_json() { $info = array( @@ -393,5 +407,14 @@ class OrganizationForm extends DynamicForm { } } +Filter::addSupportedMatches('Organization Data', function() { + $matches = array(); + foreach (OrganizationForm::getInstance()->getFields() as $f) { + if (!$f->hasData()) + continue; + $matches['field.'.$f->get('id')] = 'Organization / '.$f->getLabel(); + } + return $matches; +},40); Organization::_inspect(); ?> diff --git a/include/class.ticket.php b/include/class.ticket.php index 6b0d597e10821cf53396f1ac925521520fdfcc20..8102d8de070943206c59328e391806b968074370 100644 --- a/include/class.ticket.php +++ b/include/class.ticket.php @@ -2208,13 +2208,26 @@ class Ticket { if ($vars['uid'] && ($user = User::lookup($vars['uid']))) { $vars['email'] = $user->getEmail(); $vars['name'] = $user->getName(); + // Add in user and organization data for filtering + $vars += $user->getFilterData(); + if ($org = $user->getOrganization()) { + $vars += $org->getFilterData(); + } } else { $interesting = array('name', 'email'); $user_form = UserForm::getUserForm()->getForm($vars); - foreach ($user_form->getFields() as $f) + // Add all the user-entered info for filtering + foreach ($user_form->getFields() as $f) { + $vars['field.'.$f->get('id')] = $f->toString($f->getClean()); if (in_array($f->get('name'), $interesting)) - $vars[$f->get('name')] = $f->toString($f->getClean()); + $vars[$f->get('name')] = $vars['field.'.$f->get('id')]; + } + // Add in organization data if one exists for this email domain + list($mailbox, $domain) = explode('@', $vars['email'], 2); + if ($org = Organization::forDomain($domain)) { + $vars += $org->getFilterData(); + } } diff --git a/include/class.topic.php b/include/class.topic.php index 18bda5a536b232f5b1f3ae71176df8f76046d466..8d4d460ab1dd915b3b53a047cc425e15541fb348 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); diff --git a/include/class.user.php b/include/class.user.php index b5247d66731718bfa8d56b3669d3b84c8700f093..4736a1707633611a18e7935e0422c0865b845faa 100644 --- a/include/class.user.php +++ b/include/class.user.php @@ -288,6 +288,22 @@ class User extends UserModel { return $this->_entries; } + function getFilterData() { + $vars = array(); + foreach ($this->getDynamicData() as $entry) { + if ($entry->getForm()->get('type') != 'U') + continue; + foreach ($entry->getFields() as $f) + $vars['field.'.$f->get('id')] = $f->toString($f->getClean()); + // Add in special `name` and `email` fields + foreach (array('name', 'email') as $name) { + if ($f = $entry->getForm()->getField($name)) + $vars['field.'.$f->get('id')] = $this->getName(); + } + } + return $vars; + } + function getForms($data=null) { if (!isset($this->_forms)) { diff --git a/include/staff/filter.inc.php b/include/staff/filter.inc.php index 29fcaf17cc3c66327754344fde8cfd70539a930c..a1b92945c6cc52279d8cd1219f59560b6b745b6f 100644 --- a/include/staff/filter.inc.php +++ b/include/staff/filter.inc.php @@ -122,7 +122,7 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info); <tr id="r<?php echo $i; ?>"> <td colspan="2"> <div> - <select name="rule_w<?php echo $i; ?>"> + <select style="max-width: 200px;" name="rule_w<?php echo $i; ?>"> <option value="">— Select One ‐</option> <?php foreach ($matches as $group=>$ms) { ?>