<commit_before><?php // vim:ts=4:sw=4:et:fdm=marker
/**
 * This is a Basic Grid implementation, which produces fully
 * functional HTML grid capable of filtering, sorting, paginating
 * and using multiple column formatters. Basic Grid no longer
 * implements the column formatters, instead they have been
 * moved into Grid_Advanced
 * 
 * @link http://agiletoolkit.org/doc/grid
 *
 * Use:
 *  $grid=$this->add('Grid');
 *  $grid->setModel('User');
 *
 * @license See http://agiletoolkit.org/about/license
 *
**/
class Grid_Basic extends CompleteLister {
    public $columns=array();

    public $default_controller='Controller_MVCGrid';

    public $sort_icons=array(
        'ui-icon ui-icon-arrowthick-2-n-s',
        'ui-icon ui-icon-arrowthick-1-n',
        'ui-icon ui-icon-arrowthick-1-s',
    );
    public $show_header = true;
    function init(){
        parent::init();
        $this->initWidget();
    }

    /** You might want Grid to be enganced with a widget. Initialize it here or define this as empty function to avoid */
    function initWidget(){
    }

    function defaultTemplate(){
        return array('grid');
    }

    function importFields($model,$fields=undefined){
        $this->add('Controller_MVCGrid')->importFields($model,$fields);
    }

    function addColumn($formatters,$name=null,$descr=null){
        if($name===null){
            $name=$formatters;
            $formatters='text';
        }

        if($descr===null)$descr=ucwords(str_replace('_',' ',$name));

        $descr=$this->api->_($descr);

        $this->columns[$name]=array('type'=>$formatters);

        if(is_array($descr)){
            $this->columns[$name]=array_merge($this->columns[$name],$descr);
        } else {
            $this->columns[$name]['descr']=$descr;
        }

        $this->last_column=$name;

        if(!is_string($formatters) && is_callable($formatters)){
            $this->columns[$name]['fx']=$formatters;
            return $this;
        }

        $subtypes=explode(',',$formatters);
        foreach($subtypes as $subtype){
            if(strpos($subtype,'/')){

                if(!$this->elements[$subtype.'_'.$name]){
                // add-on functionality
                    $addon=preg_replace('|^(.*/)?(.*)$|','\1Controller_Grid_Format_\2',$subtype);
                    $this->elements[$subtype.'_'.$name]=$this->add($addon);
                }

                $addon = $this->getElement($subtype.'_'.$name);
                $addon->initField($name,$descr);
                return $addon;

            }elseif(!$this->hasMethod($m='init_'.$subtype)){
                if(!$this->hasMethod($m='format_'.$subtype)){
                    throw $this->exception('No such formatter')->addMoreInfo('formater',$subtype);
                }
            }else $this->$m($name,$descr);
        }

        return $this;
    }
    function addFormatter($field,$formatter){
        /*
         * add extra formatter to existing field
         */
        if(!isset($this->columns[$field])){
            throw new BaseException('Cannot format nonexistant field '.$field);
        }
        $this->columns[$field]['type'].=','.$formatter;
        if(strpos($formatter,'/')){

            if(!$this->elements[$formatter.'_'.$field]){
                // add-on functionality
                $addon=preg_replace('|^(.*/)?(.*)$|','\1Controller_Grid_Format_\2',$formatter);
                $this->elements[$formatter.'_'.$field]=$this->add($addon,$formatter);
            }

            $addon = $this->getElement($formatter.'_'.$field);
            $addon->initField($field,$this->columns[$field]['descr']);
            return $addon;

        }elseif($this->hasMethod($m='init_'.$formatter))$this->$m($field);
        return $this;
    }
    function setFormatter($field,$formatter){
        /*
         * replace current formatter for field
         */
        if(!isset($this->columns[$field])){
            throw new BaseException('Cannot format nonexistant field '.$field);
        }
        $this->columns[$field]['type']=$formatter;
        if($this->hasMethod($m='init_'.$formatter))$this->$m($field);
        $this->last_column=$field;<commit_msg>fix addon support when using setFormatter<commit_after><?php // vim:ts=4:sw=4:et:fdm=marker
/**
 * This is a Basic Grid implementation, which produces fully
 * functional HTML grid capable of filtering, sorting, paginating
 * and using multiple column formatters. Basic Grid no longer
 * implements the column formatters, instead they have been
 * moved into Grid_Advanced
 * 
 * @link http://agiletoolkit.org/doc/grid
 *
 * Use:
 *  $grid=$this->add('Grid');
 *  $grid->setModel('User');
 *
 * @license See http://agiletoolkit.org/about/license
 *
**/
class Grid_Basic extends CompleteLister {
    public $columns=array();

    public $default_controller='Controller_MVCGrid';

    public $sort_icons=array(
        'ui-icon ui-icon-arrowthick-2-n-s',
        'ui-icon ui-icon-arrowthick-1-n',
        'ui-icon ui-icon-arrowthick-1-s',
    );
    public $show_header = true;
    function init(){
        parent::init();
        $this->initWidget();
    }

    /** You might want Grid to be enganced with a widget. Initialize it here or define this as empty function to avoid */
    function initWidget(){
    }

    function defaultTemplate(){
        return array('grid');
    }

    function importFields($model,$fields=undefined){
        $this->add('Controller_MVCGrid')->importFields($model,$fields);
    }

    function addColumn($formatters,$name=null,$descr=null){
        if($name===null){
            $name=$formatters;
            $formatters='text';
        }

        if($descr===null)$descr=ucwords(str_replace('_',' ',$name));

        $descr=$this->api->_($descr);

        $this->columns[$name]=array('type'=>$formatters);

        if(is_array($descr)){
            $this->columns[$name]=array_merge($this->columns[$name],$descr);
        } else {
            $this->columns[$name]['descr']=$descr;
        }

        $this->last_column=$name;

        if(!is_string($formatters) && is_callable($formatters)){
            $this->columns[$name]['fx']=$formatters;
            return $this;
        }

        $subtypes=explode(',',$formatters);
        // TODO call addFormatter instead!
        foreach($subtypes as $subtype){
            if(strpos($subtype,'/')){

                if(!$this->elements[$subtype.'_'.$name]){
                // add-on functionality
                    $addon=preg_replace('|^(.*/)?(.*)$|','\1Controller_Grid_Format_\2',$subtype);
                    $this->elements[$subtype.'_'.$name]=$this->add($addon);
                }

                $addon = $this->getElement($subtype.'_'.$name);
                $addon->initField($name,$descr);
                return $addon;

            }elseif(!$this->hasMethod($m='init_'.$subtype)){
                if(!$this->hasMethod($m='format_'.$subtype)){
                    throw $this->exception('No such formatter')->addMoreInfo('formater',$subtype);
                }
            }else $this->$m($name,$descr);
        }

        return $this;
    }
    function addFormatter($field,$formatter){
        /*
         * add extra formatter to existing field
         */
        if(!isset($this->columns[$field])){
            throw new BaseException('Cannot format nonexistant field '.$field);
        }
        if($this->columns[$field]['type']){
            $this->columns[$field]['type'].=','.$formatter;
        }else{
            $this->columns[$field]['type']=$formatter;
        }

        if(strpos($formatter,'/')){

            if(!$this->elements[$formatter.'_'.$field]){
                // add-on functionality
                $addon=preg_replace('|^(.*/)?(.*)$|','\1Controller_Grid_Format_\2',$formatter);
                $this->elements[$formatter.'_'.$field]=$this->add($addon,$formatter);
            }

            $addon = $this->getElement($formatter.'_'.$field);
            $addon->initField($field,$this->columns[$field]['descr']);
            return $addon;

        }elseif($this->hasMethod($m='init_'.$formatter))$this->$m($field);
        return $this;
    }
    function setFormatter($field,$formatter){
        /*
         * replace current formatter for field
         */
        if(!isset($this->columns[$field])){
            throw new BaseException('Cannot format nonexistant field '.$field);
        }
        $this->columns[$field]['type']='';
        $this->addFormatter($field,$formatter);
        $this->last_column=$field;
{'fraction_non_alphanumeric': 0.17971864009378663, 'fraction_numerical': 0.0021101992966002345, 'mean_word_length': 2.423354735152488, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 82, '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': '4581374', 'n_tokens_mistral': 2536, 'n_tokens_neox': 2451, 'n_words': 397}