Skip to content
Snippets Groups Projects
class.search.php 37.6 KiB
Newer Older
  • Learn to ignore specific revisions
  • 
        function getSearchMethodWidgets() {
            return array(
                'assigned' => null,
    
                '!assigned' => null,
                'includes' => array('ChoiceField', array(
    
                    'choices' => $this->getChoices(),
                    'configuration' => array('multiselect' => true),
                )),
    
                '!includes' => array('ChoiceField', array(
    
                    'choices' => $this->getChoices(),
                    'configuration' => array('multiselect' => true),
                )),
            );
        }
    
    
        function getSearchQ($method, $value, $name=false) {
            global $thisstaff;
    
            $Q = new Q();
            switch ($method) {
            case 'assigned':
    
                $Q->negate();
            case '!assigned':
                $Q->add(array('team_id' => 0,
                    'staff_id' => 0));
    
                break;
            case '!includes':
                $Q->negate();
            case 'includes':
                $teams = $agents = array();
                foreach ($value as $id => $ST) {
                    switch ($id[0]) {
                    case 'M':
                        $agents[] = $thisstaff->getId();
                        break;
                    case 's':
                        $agents[] = (int) substr($id, 1);
                        break;
                    case 'T':
                        $teams = array_merge($thisstaff->getTeams());
                        break;
                    case 't':
                        $teams[] = (int) substr($id, 1);
                        break;
                    }
                }
                $constraints = array();
                if ($teams)
                    $constraints['team_id__in'] = $teams;
                if ($agents)
                    $constraints['staff_id__in'] = $agents;
                $Q->add(Q::any($constraints));
            }
            return $Q;
        }
    }
    
    class TicketStateChoiceField extends ChoiceField {
        function getChoices() {
            return array(
                'open' => __('Open'),
                'closed' => __('Closed'),
                'archived' => __('Archived'),
                'deleted' => __('Deleted'),
            );
        }
    
        function getSearchMethods() {
            return array(
                'includes' =>   __('is'),
                '!includes' =>  __('is not'),
            );
        }
    
        function getSearchQ($method, $value, $name=false) {
            return parent::getSearchQ($method, $value, 'status__state');
        }
    }
    
    class TicketFlagChoiceField extends ChoiceField {
        function getChoices() {
            return array(
                'isanswered' =>   __('Answered'),
                'isoverdue' =>    __('Overdue'),
            );
        }
    
        function getSearchMethods() {
            return array(
                'includes' =>   __('is'),
                '!includes' =>  __('is not'),
            );
        }
    
        function getSearchQ($method, $value, $name=false) {
            $Q = new Q();
            if (isset($value['isanswered']))
                $Q->add(array('isanswered' => 1));
            if (isset($value['isoverdue']))
                $Q->add(array('isoverdue' => 1));
            if ($method == '!includes')
                $Q->negate();
            if ($Q->constraints)
                return $Q;
        }
    
    class TicketSourceChoiceField extends ChoiceField {
        function getChoices() {
            return array(
                'w' => __('Web'),
                'e' => __('Email'),
                'p' => __('Phone'),
                'a' => __('API'),
                'o' => __('Other'),
            );
        }
    
        function getSearchMethods() {
            return array(
                'includes' =>   __('is'),
                '!includes' =>  __('is not'),
            );
        }
    
        function getSearchQ($method, $value, $name=false) {
            return parent::getSearchQ($method, $value, 'source');
        }
    }
    
    
    class TicketStatusChoiceField extends SelectionField {
        static $widget = 'ChoicesWidget';
    
        function getList() {
            return new TicketStatusList(
                DynamicList::lookup(
                    array('type' => 'ticket-status'))
            );
        }
    
        function getSearchMethods() {
            return array(
    
                'includes' =>   __('is'),
                '!includes' =>  __('is not'),