Skip to content
Snippets Groups Projects
Commit efcaae5b authored by Peter Rotich's avatar Peter Rotich
Browse files

Advanced Search: Selection Fields

Make selection fields play well with Advanced Search
parent b089b7af
No related branches found
No related tags found
No related merge requests found
...@@ -107,7 +107,7 @@ implements TemplateVariable, Searchable { ...@@ -107,7 +107,7 @@ implements TemplateVariable, Searchable {
'name' => new TextboxField(array( 'name' => new TextboxField(array(
'label' => __('Name'), 'label' => __('Name'),
)), )),
'manager' => new AgentSelectionField(array( 'manager' => new DepartmentManagerSelectionField(array(
'label' => __('Manager'), 'label' => __('Manager'),
)), )),
); );
......
...@@ -723,7 +723,33 @@ class AdvancedSearchForm extends SimpleForm { ...@@ -723,7 +723,33 @@ class AdvancedSearchForm extends SimpleForm {
// Advanced search special fields // Advanced search special fields
class HelpTopicChoiceField extends ChoiceField { class AdvancedSearchSelectionField extends ChoiceField {
function getSearchQ($method, $value, $name=false) {
switch ($method) {
case 'includes':
case '!includes':
$Q = new Q();
if (count($value) > 1)
$Q->add(array("{$name}__in" => array_keys($value)));
else
$Q->add(array($name => key($value)));
if ($method == '!includes')
$Q->negate();
return $Q;
break;
default:
return parent::getSearchQ($method, $value, $name);
}
}
}
class HelpTopicChoiceField extends AdvancedSearchSelectionField {
function hasIdValue() { function hasIdValue() {
return true; return true;
} }
...@@ -734,7 +760,7 @@ class HelpTopicChoiceField extends ChoiceField { ...@@ -734,7 +760,7 @@ class HelpTopicChoiceField extends ChoiceField {
} }
require_once INCLUDE_DIR . 'class.dept.php'; require_once INCLUDE_DIR . 'class.dept.php';
class DepartmentChoiceField extends ChoiceField { class DepartmentChoiceField extends AdvancedSearchSelectionField {
var $_choices = null; var $_choices = null;
function getChoices($verbose=false) { function getChoices($verbose=false) {
...@@ -764,6 +790,7 @@ class DepartmentChoiceField extends ChoiceField { ...@@ -764,6 +790,7 @@ class DepartmentChoiceField extends ChoiceField {
} }
} }
class AssigneeChoiceField extends ChoiceField { class AssigneeChoiceField extends ChoiceField {
function getChoices($verbose=false) { function getChoices($verbose=false) {
global $thisstaff; global $thisstaff;
...@@ -902,7 +929,7 @@ trait ZeroMeansUnset { ...@@ -902,7 +929,7 @@ trait ZeroMeansUnset {
} }
} }
class AgentSelectionField extends ChoiceField { class AgentSelectionField extends AdvancedSearchSelectionField {
use ZeroMeansUnset; use ZeroMeansUnset;
function getChoices($verbose=false) { function getChoices($verbose=false) {
...@@ -940,6 +967,17 @@ class AgentSelectionField extends ChoiceField { ...@@ -940,6 +967,17 @@ class AgentSelectionField extends ChoiceField {
} }
} }
class DepartmentManagerSelectionField extends AgentSelectionField {
function getChoices($verbose=false) {
return Staff::getStaffMembers();
}
function getSearchQ($method, $value, $name=false) {
return parent::getSearchQ($method, $value, 'dept__manager_id');
}
}
class TeamSelectionField extends ChoiceField { class TeamSelectionField extends ChoiceField {
use ZeroMeansUnset; use ZeroMeansUnset;
...@@ -953,7 +991,7 @@ class TeamSelectionField extends ChoiceField { ...@@ -953,7 +991,7 @@ class TeamSelectionField extends ChoiceField {
} }
} }
class TicketStateChoiceField extends ChoiceField { class TicketStateChoiceField extends AdvancedSearchSelectionField {
function getChoices($verbose=false) { function getChoices($verbose=false) {
return array( return array(
'open' => __('Open'), 'open' => __('Open'),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment