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

class Groups_Model extends Model 
{
    // {{{ Properties
    
    public $tableNameApps;
    public $tableNameGroups;
    public $tableNameUsers;
    public $tableNameFilters;

    // }}}
    // {{{ Constructor
    function __construct()
    {
        parent::__construct('default');

        // set tables' names
        $this->tableNameApps   = "user_applications";
        $this->tableNameGroups = "user_groups";
        $this->tableNameUsers  = "user_users";

    }
    // }}}
    // {{{ & getAnonymousGroup
    public function & getAnonymousGroup($appname)
    {
        $this->db->select('name, appname, privileges, redirect');
        $this->db->from($this->tableNameGroups);
        $this->db->where('appname', $appname);
        $this->db->where('name', 'anonymous');

        $group = (Array) $this->db->getwhere()->current();

        if (!empty($group)) {
            $group['privileges'] = unserialize($group['privileges']);
        } else {

            // XXX: Okay, there is no anonymous group for this appname so just construct a Null
            //      anonymous group
            $group['name']       = 'anonymous';
            $group['appname']    = $appname;
            $group['privileges'] = Null;
            $group['redirect']   = False;
        }

        return $group;
    }
    // }}}
    // {{{ getGroups
    public function getGroups($appName = NULL)
    {
        $this->db->select('id, name, modified_by, created_by, modify_date, create_date, appname');
        $this->db->from($this->tableNameGroups);

        if ($appName != NULL) {
            $this->db->where('appname', $appName);
        }
        
        $this->db->orderby('id', 'ASC');

        $query = $this->db->get();
        
        $retval = $query->result(False);
        return $retval;
    }
    // }}}
    // {{{ & getGroup
    public function & getGroup($id = NULL, $appname = NULL, $groupname = NULL)
    {
        $this->db->select('id, name, modified_by, created_by, modify_date, create_date, appname, privileges');
        $this->db->from($this->tableNameGroups);

        if ($id != NULL) {
            $this->db->where('id', $id);
        } else {
            $this->db->where(array('appname' => $appname,
                                   'name'    => $groupname));
        }


        $group = (Array) $this->db->getwhere()->current();

        return $group;
    }
    // }}}
    // {{{ getDate
    public function getDate($row)
    {
        return date('Y-m-d H:i:s', $row['create_date']);
    }
    // }}}
    // {{{ getModifyDate
    public function getModifyDate($row)
    {
        return date('Y-m-d H:i:s', $row['modify_date']);
    }
    // }}}
    // {{{ setGroup
    public function setGroup($appName, $group)
    {
       $row = Array('default_group' => $group); 
       
       $this->db->where('name', $appName);
       $this->db->update($this->tableNameApps, $row);         
    }
    // }}}
    // {{{ getDefaultGroup
    public function getDefaultGroup($appName)
    {
        $this->db->select('default_group');
        $this->db->from($this->tableNameApps);
        $this->db->where('name', $appName);

        $query = $this->db->get();
        $row   = $query->result(False);

        return $row;        
    }
    // }}}
    // {{{ getAllAppGroups
    public function getAllAppGroups($appName)
    {<commit_msg>SQL query simplified<commit_after><?php
// vim: set expandtab tabstop=4 shiftwidth=4 foldmethod=marker:             
// +-------------------------------------------------------------------------+
// | Authors: <NAME> <<EMAIL>>                              |
// |          <NAME> <<EMAIL>>                     |
// +-------------------------------------------------------------------------+
// $Id$
// ---------------------------------------------------------------------------

class Groups_Model extends Model 
{
    // {{{ Properties
    
    public $tableNameApps;
    public $tableNameGroups;
    public $tableNameUsers;
    public $tableNameFilters;

    // }}}
    // {{{ Constructor
    function __construct()
    {
        parent::__construct('default');

        // set tables' names
        $this->tableNameApps   = "user_applications";
        $this->tableNameGroups = "user_groups";
        $this->tableNameUsers  = "user_users";

    }
    // }}}
    // {{{ & getAnonymousGroup
    public function & getAnonymousGroup($appname)
    {
        $this->db->select('name, appname, privileges, redirect');
        $this->db->from($this->tableNameGroups);
        $this->db->where('appname', $appname);
        $this->db->where('name', 'anonymous');

        $group = (Array) $this->db->getwhere()->current();

        if (!empty($group)) {
            $group['privileges'] = unserialize($group['privileges']);
        } else {

            // XXX: Okay, there is no anonymous group for this appname so just construct a Null
            //      anonymous group
            $group['name']       = 'anonymous';
            $group['appname']    = $appname;
            $group['privileges'] = Null;
            $group['redirect']   = False;
        }

        return $group;
    }
    // }}}
    // {{{ getGroups
    public function getGroups($appName = NULL)
    {
        $this->db->select('id, name, modified_by, created_by, modify_date, create_date, appname');
        $this->db->from($this->tableNameGroups);

        if ($appName != NULL) {
            $this->db->where('appname', $appName);
        }
        
        $this->db->orderby('id', 'ASC');

        $query = $this->db->get();
        
        $retval = $query->result(False);
        return $retval;
    }
    // }}}
    // {{{ & getGroup
    public function & getGroup($id = NULL, $appname = NULL, $groupname = NULL)
    {
        $this->db->select('id, name, modified_by, created_by, modify_date, create_date, appname, privileges');
        $this->db->from($this->tableNameGroups);

        if ($id != NULL) {
            $this->db->where('id', $id);
        } else {
            $this->db->where(array('appname' => $appname,
                                   'name'    => $groupname));
        }


        $group = (Array) $this->db->getwhere()->current();

        return $group;
    }
    // }}}
    // {{{ getDate
    public function getDate($row)
    {
        return date('Y-m-d H:i:s', $row['create_date']);
    }
    // }}}
    // {{{ getModifyDate
    public function getModifyDate($row)
    {
        return date('Y-m-d H:i:s', $row['modify_date']);
    }
    // }}}
    // {{{ setGroup
    public function setGroup($appName, $group)
    {
       $row = Array('default_group' => $group); 
       
       $this->db->where('name', $appName);
       $this->db->update($this->tableNameApps, $row);         
    }
    // }}}
    // {{{ getDefaultGroup
    public function getDefaultGroup($appName)
    {
        $this->db->select('default_group');
        $this->db->from($this->tableNameApps);
        $this->db->where('name', $appName);

        return $this->db->get()->current()->default_group;
    }
    // }}}
    // {{{ getAllAppGroups
    public function getAllAppGroups($appName)
    {
{'fraction_non_alphanumeric': 0.22946063563233549, 'fraction_numerical': 0.0005274957140973229, 'mean_word_length': 1.608875128998968, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 130, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5985760', 'n_tokens_mistral': 2241, 'n_tokens_neox': 2200, 'n_words': 382}