<commit_before><?php
namespace SmsBus\Db;

use PDO;
use SmsBus\Db\AbstractTable;
use Zend\Config\Config;

class RoutesTable extends AbstractTable {
	protected $table = 'routes';
	
	public function fetchAll($where = array(), $sort = '') {
		
	}
	public function fetch($id) {
		
	}
	public function update($data = array()) {
		
	}
	public function save($data = array()) {
		
	}
	public function delete($id) {
		
	}
	
	public function needsAgency() {
		return true;
	}
	
	public function setAgencyId($agency_id = 0) {
		$this->agency = intval($agency_id);
	}

    /**
     * Searches the route_long_name field for matching terms to return the desired route(s).
     * @param $phrase
     * @return array|bool
     */
    public function searchByName($phrase)
    {
        $terms = explode(" ", $phrase);
        $search_terms = array();
        foreach($terms as $i => $term) {
            $search_terms[':route_' . $i] = '%' . $term . '%';
        }

        $sql = "SELECT * FROM `routes` WHERE ";
        $sql .= "(`route_long_name` LIKE " . implode(" AND `route_long_name` LIKE ", array_keys($search_terms)) . ") OR ";
        $sql .= "`route_short_name` LIKE " . implode(" OR `route_short_name LIKE ", array_keys($search_terms));

        $stmt = $this->dbConn->prepare($sql);

        $result = $stmt->execute($search_terms);
        if(!$result) {
            return false;
        }
        return $stmt->fetchAll(\PDO::FETCH_ASSOC);
    }
}<commit_msg>added a search by name function to the table entity<commit_after><?php
namespace SmsBus\Db;

use PDO;
use SmsBus\Db\AbstractTable;
use Zend\Config\Config;

class RoutesTable extends AbstractTable {
	protected $table = 'routes';
	
	public function fetchAll($where = array(), $sort = '') {
		
	}
	public function fetch($id) {
		
	}
	public function update($data = array()) {
		
	}
	public function save($data = array()) {
		
	}
	public function delete($id) {
		
	}
	
	public function needsAgency() {
		return true;
	}
	
	public function setAgencyId($agency_id = 0) {
		$this->agency = intval($agency_id);
	}

    /**
     * Searches the route_long_name field for matching terms to return the desired route(s).
     * @param $phrase
     * @return array|bool
     */
    public function searchByName($phrase)
    {
        $terms = explode(" ", $phrase);
        $search_terms = array();
        foreach($terms as $i => $term) {
            $search_terms[':route_' . $i] = '%' . $term . '%';
        }

        $sql = "SELECT * FROM `routes` WHERE ";
        $sql .= "`route_long_name` LIKE " . implode(" AND `route_long_name` LIKE ", array_keys($search_terms)) . "";

        $stmt = $this->dbConn->prepare($sql);

        $result = $stmt->execute($search_terms);
        if(!$result) {
            return false;
        }
        return $stmt->fetchAll(\PDO::FETCH_ASSOC);
    }
}
{'fraction_non_alphanumeric': 0.1529245947850599, 'fraction_numerical': 0.0007047216349541931, 'mean_word_length': 2.687012987012987, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '5912006', 'n_tokens_mistral': 973, 'n_tokens_neox': 900, 'n_words': 216}