<commit_before><?php
/**
 * Belgian Police Web Platform - Districts Component
 *
 * @copyright	Copyright (C) 2012 - 2013 Timble CVBA. (http://www.timble.net)
 * @license		GNU GPLv3 <http://www.gnu.org/licenses/gpl.html>
 * @link		https://github.com/belgianpolice/internet-platform
 */

namespace Nooku\Component\Districts;
use Nooku\Library;

class ModelOfficers extends Library\ModelTable
{	
    public function __construct(Library\ObjectConfig $config)
	{
		parent::__construct($config);

		$this->getState()
		    ->insert('location' , 'int');
	}
	
	protected function _buildQueryColumns(Library\DatabaseQuerySelect $query)
    {
        parent::_buildQueryColumns($query);

        $query->columns(array(
            'district_count' => 'COUNT(districts_officers.districts_district_id)',
        ));
    }
	
	protected function _buildQueryJoins(Library\DatabaseQuerySelect $query)
	{
		$query->join(array('districts_officers' => 'districts_districts_officers'), 'districts_officers.districts_officer_id = tbl.districts_officer_id')
              ->join(array('district' => 'districts'), 'district.districts_district_id = districts_officers.districts_district_id');
	}
    
    protected function _buildQueryWhere(Library\DatabaseQuerySelect $query)
	{
		parent::_buildQueryWhere($query);
		$state = $this->getState();

		if ($state->search) {
			$query->where('tbl.firstname LIKE :search')->bind(array('search' => '%'.$state->search.'%'));
		}
	}
	
	protected function _buildQueryOrder(Library\DatabaseQuerySelect $query)
    {
        $state = $this->getState();

        $direction = strtoupper($state->direction);

        if ($state->sort == 'firstname')
        {
            $query->order($state->sort, $direction)<commit_msg>re #743 - Added lastname search for officers<commit_after><?php
/**
 * Belgian Police Web Platform - Districts Component
 *
 * @copyright	Copyright (C) 2012 - 2013 Timble CVBA. (http://www.timble.net)
 * @license		GNU GPLv3 <http://www.gnu.org/licenses/gpl.html>
 * @link		https://github.com/belgianpolice/internet-platform
 */

namespace Nooku\Component\Districts;
use Nooku\Library;

class ModelOfficers extends Library\ModelTable
{	
	protected function _buildQueryColumns(Library\DatabaseQuerySelect $query)
    {
        parent::_buildQueryColumns($query);

        $query->columns(array(
            'district_count' => 'COUNT(districts_officers.districts_district_id)',
        ));
    }
	
	protected function _buildQueryJoins(Library\DatabaseQuerySelect $query)
	{
		$query->join(array('districts_officers' => 'districts_districts_officers'), 'districts_officers.districts_officer_id = tbl.districts_officer_id')
              ->join(array('district' => 'districts'), 'district.districts_district_id = districts_officers.districts_district_id');
	}
    
    protected function _buildQueryWhere(Library\DatabaseQuerySelect $query)
	{
		parent::_buildQueryWhere($query);
		$state = $this->getState();

		if ($state->search) {
			$query->where('tbl.firstname LIKE :search OR tbl.lastname LIKE :search')->bind(array('search' => '%'.$state->search.'%'));
		}
	}
	
	protected function _buildQueryOrder(Library\DatabaseQuerySelect $query)
    {
        $state = $this->getState();

        $direction = strtoupper($state->direction);

        if ($state->sort == 'firstname')
        {
            $query->order($state->sort, $direction)
{'fraction_non_alphanumeric': 0.14378891194782092, 'fraction_numerical': 0.006225911651348948, 'mean_word_length': 4.058470764617691, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 41, 'https://': 2, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1870228', 'n_tokens_mistral': 1134, 'n_tokens_neox': 1023, 'n_words': 167}