lib/Ajde/Filter/Match.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php

class Ajde_Filter_Match extends Ajde_Filter
{
    protected $_fields;
    protected $_against;
    protected $_operator;
    protected $_table;

    public function __construct($fields, $against, $operator = Ajde_Query::OP_AND, $table = null)
    {
        $this->_fields = $fields;
        $this->_against = $against;
        $this->_operator = $operator;
        $this->_table = $table;
    }

    public function prepare(Ajde_Db_Table $table = null)
    {
        if (isset($this->_table)) {
            $useTable = (string) $this->_table;
        } else {
            $useTable = (string) $table;
        }
        $sql = 'MATCH ('.implode(', ', $this->_fields).') AGAINST (:'.spl_object_hash($this).')';

        return [
            'where'  => [
                'arguments' => [$sql, $this->_operator],
                'values'    => [spl_object_hash($this) => $this->_against],
            ],
            'select' => [
                'arguments' => [$sql.' AS relevancy_'.$useTable],
            ],
        ];
    }
}