<commit_before><?php
// vim: set expandtab tabstop=4 shiftwidth=4 foldmethod=marker:
// +-------------------------------------------------------------------------+
// | Authors: <NAME> <<EMAIL>>                               |
// +-------------------------------------------------------------------------+
// $Id$
// ---------------------------------------------------------------------------

class Locations_Model extends Model
{
    const CONTAINMENT = 'containment';
    const COUNTRY     = 'country';
    const PROVINCE    = 'province';
    const STATE       = 'state';
    const CITY        = 'city';
    const VILLAGE     = 'village';
    const AIRPORT     = 'airport';
    const STREET      = 'street';
    const SIGHT       = 'sight';

    private $tableName = 'locations';
    public $names      = Array();
    // {{{ __construct
    public function __construct() {
        parent::__construct();

        $this->names = Array( self::CONTAINMENT => _("Containment"),
                              self::COUNTRY     => _("Country"),
                              self::PROVINCE    => _("Province"),
                              self::STATE       => _("State"),
                              self::CITY        => _("City"),
                              self::VILLAGE     => _("Village"),
                              self::AIRPORT     => _("Airport"),
                              self::STREET      => _("Street"),
                              self::SIGHT       => _("Sight")
                        );
                            
    }
    // }}}
    // {{{ get
    public function get($id) {
        $cache_id = 'location_'.$id;
        $cache    = New Cache;
        $cached   = $cache->get($cache_id);
        if ($cached) {
            return $cached;
        }

        $this->db->select('id', 'parent', 'name', 'english', 'code', 'type', 'latitude', 'longitude')->from($this->tableName)->where('id', $id);
        $loc = current($this->db->get()->result_array(False));

        $cache->set($cache_id, $loc);
        return $loc;
    }
    // }}}
    // {{{ getByParent
    public function getByParent($parent = 0)
    {
        $this->db->select('*')->from($this->tableName)->where('parent', $parent)->where('name <>', '')->orderby('name', 'english', 'code');
        $localized = $this->db->get()->result_array(False);

        $this->db->select('*')->from($this->tableName)->where('parent', $parent)->where('name', '')->orderby('name', 'english', 'code');
        $unlocalized = $this->db->get()->result_array(False);

        return array_merge($localized, $unlocalized);
    }
    // }}}
    // {{{ getSiblings
    public function getSiblings($id = 1)
    {
        return $this->getByParent(current(current($this->db->select('parent')->from($this->tableName)->where('id', $id)->get()->result_array(False))));
    }
    // }}}
    // {{{ search
    public function search($name = Null, $english = Null, $code = Null, $type = Null, $orderOfTypes = array(), $takeCareOfCode = true)
    {
        $where = '';

        if ($name) {
            $where = "name LIKE '%$name%' ";
        }

        if ($english) {
            $where .= $where ? " OR english LIKE '%$english%' " : " english LIKE '%$english%' ";
        }

        if ($code) {
            $where .= $where ? " OR code = '$code' " : " code = '$code' ";
        }

        if ($type) {
            $where = $where ? "($where) AND type = '$type' " : " type = '$type' ";
        }

        $order_by = '';

        $takeCareOfCode and $order_by = "oct(code REGEXP '$code') * 100 + ";

        $orderOfTypes = is_array($orderOfTypes) ? $orderOfTypes : array($orderOfTypes);
        $index = count($orderOfTypes);
        foreach($orderOfTypes as $order) {
            $order_by .= "oct(type = '$order') * $index + ";
            $index--;
        }
        $order_by .= '0 DESC, name, english, code, type';
<commit_msg>search in lowercase, return in uppercase words<commit_after><?php
// vim: set expandtab tabstop=4 shiftwidth=4 foldmethod=marker:
// +-------------------------------------------------------------------------+
// | Authors: <NAME> <<EMAIL>>                               |
// +-------------------------------------------------------------------------+
// $Id$
// ---------------------------------------------------------------------------

class Locations_Model extends Model
{
    const CONTAINMENT = 'containment';
    const COUNTRY     = 'country';
    const PROVINCE    = 'province';
    const STATE       = 'state';
    const CITY        = 'city';
    const VILLAGE     = 'village';
    const AIRPORT     = 'airport';
    const STREET      = 'street';
    const SIGHT       = 'sight';

    private $tableName = 'locations';
    public $names      = Array();
    // {{{ __construct
    public function __construct() {
        parent::__construct();

        $this->names = Array( self::CONTAINMENT => _("Containment"),
                              self::COUNTRY     => _("Country"),
                              self::PROVINCE    => _("Province"),
                              self::STATE       => _("State"),
                              self::CITY        => _("City"),
                              self::VILLAGE     => _("Village"),
                              self::AIRPORT     => _("Airport"),
                              self::STREET      => _("Street"),
                              self::SIGHT       => _("Sight")
                        );
                            
    }
    // }}}
    // {{{ get
    public function get($id) {
        $cache_id = 'location_'.$id;
        $cache    = New Cache;
        $cached   = $cache->get($cache_id);
        if ($cached) {
            return $cached;
        }

        $this->db->select('id', 'parent', 'name', 'english', 'code', 'type', 'latitude', 'longitude')->from($this->tableName)->where('id', $id);
        $loc            = current($this->db->get()->result_array(False));
        if ($loc['english']) {
            $loc['english'] = ucwords($loc['english']);
        }

        if ($loc['code']) {
            $loc['code'] = strtoupper($loc['code']);
        }

        $cache->set($cache_id, $loc);
        return $loc;
    }
    // }}}
    // {{{ getByParent
    public function getByParent($parent = 0)
    {
        $this->db->select('*')->from($this->tableName)->where('parent', $parent)->where('name <>', '')->orderby('name', 'english', 'code');
        $localized = $this->db->get()->result_array(False);

        $this->db->select('*')->from($this->tableName)->where('parent', $parent)->where('name', '')->orderby('name', 'english', 'code');
        $unlocalized = $this->db->get()->result_array(False);

        return array_merge($localized, $unlocalized);
    }
    // }}}
    // {{{ getSiblings
    public function getSiblings($id = 1)
    {
        return $this->getByParent(current(current($this->db->select('parent')->from($this->tableName)->where('id', $id)->get()->result_array(False))));
    }
    // }}}
    // {{{ search
    public function search($name = Null, $english = Null, $code = Null, $type = Null, $orderOfTypes = array(), $takeCareOfCode = true)
    {
        $where = '';

        $name    = strtolower($name);
        $english = strtolower($english);
        $code    = strtolower($code);

        if ($name) {
            $where = "name LIKE '%$name%' ";
        }

        if ($english) {
            $where .= $where ? " OR english LIKE '%$english%' " : " english LIKE '%$english%' ";
        }

        if ($code) {
            $where .= $where ? " OR code = '$code' " : " code = '$code' ";
        }

        if ($type) {
            $where = $where ? "($where) AND type = '$type' " : " type = '$type' ";
        }

        $order_by = '';

        $takeCareOfCode and $order_by = "oct(code REGEXP '$code') * 100 + ";

        $orderOfTypes = is_array($orderOfTypes) ? $orderOfTypes : array($orderOfTypes);
        $index = count($orderOfTypes);
        foreach($orderOfTypes as $order) {
            $order_by .= "oct(type = '$order') * $index + ";
            $index--;
        }
        $order_by .= '0 DESC, name, english, code, type';

{'fraction_non_alphanumeric': 0.23444976076555024, 'fraction_numerical': 0.001962949331370384, 'mean_word_length': 1.5340379235312402, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 107, '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': '1206758', 'n_tokens_mistral': 2388, 'n_tokens_neox': 2308, 'n_words': 448}