<commit_before><?php


class sfPhastBehavior extends SfPropelBehaviorBase
{

    protected $phastTables = [];


    public function parentClass($builder){
        $classname = preg_replace('/^Base/', '', $builder->getClassname());
        if(in_array($classname, $this->phastTables)){
            return 'Phast' . $classname;
        };
    }

    public function modifyDatabase()
    {

        foreach((new sfFinder)->name('*.php')->in(__DIR__ . '/../model') as $path){
            $this->phastTables[] = preg_replace('/^Phast|\.php$/', '', basename($path));
        }

        foreach ($this->getDatabase()->getTables() as $table) {
/*
            if(in_array($table->getPhpName(), $phastTables)){
                $table->setBaseClass('Phast' . $table->getPhpName());
            };

            if(in_array($table->getPhpName() . 'Peer', $phastTables)){
                $table->setBasePeer('Phast' . $table->getPhpName() . 'Peer');
            };
*/

            switch ($table->getName()) {
                case 'holder':
                    foreach ($table->getForeignTableNames() as $rel) {
                        $this
                            ->getDatabase()
                            ->getTable($rel)
                            ->setDescription('~holder');
                    }
                    break;

            }
        }

        parent::modifyDatabase();
    }

    public function preSave()
    {
        if ($this->isDisabled()) {
            return;
        }

        return '';
    }

    public function preInsert()
    {
        if ($this->isDisabled()) {
            return;
        }

        return '';
    }


    public function objectMethods()
    {
        if ($this->isDisabled()) {
            return;
        }

        $script = '';
        $script .= 'protected $cached = [];';
        $script .= 'protected function cache($key, Closure $closure){

                        if(array_key_exists($key, $this->cached)){
                            return $this->cached[$key];
                        }

                        return $this->cached[$key] = $closure();
                    }
        ';


        foreach($this->getTable()->getReferrers() as $rel){
            $relTable = $rel->getTable();
            $primaryKeys = $relTable->getPrimaryKey();

            if(count($primaryKeys) == 2){
                $sourceColumn = $relTable->getColumn($rel->getLocalColumns()[0]);
                $targetColumn = $primaryKeys[$primaryKeys[0]->getPhpName() == $sourceColumn->getPhpName() ? 1 : 0];

                $script .= "
                    public function assign{$relTable->getPhpName()}s(\$values){

                        if(\$values === null){
                            \$values = [];
                        }

                        \$values_ex = [];
                        foreach(\$this->get{$relTable->getPhpName()}s() as \$rel){
                            if(in_array(\$rel->get{$targetColumn->getPhpName()}(), \$values)){
                                \$values_ex[] = \$rel->get{$targetColumn->getPhpName()}();
                            }else{
                                \$rel->delete();
                            }
                        }

                        foreach(array_diff(\$values, \$values_ex) as \$value){
                            \$rel = new {$targetColumn->getTable()->getPhpName()}();
                            \$rel->set{$sourceColumn->getPhpName()}(\$this->getId());
                            \$rel->set{$targetColumn->getPhpName()}(\$value);
                            \$rel->save();
                        }

                        return \$this;

                    }
                ";

            }
        }


        $galleryColumns = [];
        $imageColumns = [];
        $dateColumns = [];
        $i18nColumns = [];

        foreach ($this->getTable()->getColumns() as $column) {

            if (preg_match('/^(\w+)?Ru$/', $column->getPhpName(), $match)) {
                $i18nColumns[$match[1]] = $column;
            }

            if (preg_match('/^(\w+)?GalleryId$/', $column->getPhpName(), $match)) {
                if($this->getTable()->getPhpName() == 'Image') continue;
                $prefix = isset($match[1]) ? $match[1] : '';
                $galleryColumns[$prefix] = $column;
            }

            /** @var $column Column */
            if (preg_match('/^(\w+)?ImageId$/', $column->getPhpName(), $match)) {
                $prefix = isset($match[1]) ? $match[1] : '';
                $imageColumns[] = [
                    'column' => $column,
                    'prefix' => $prefix
                ];
            }else if (preg_match('/^(\w+)?At$/', $column->getPhpName(), $match)) {
                $dateColumns[$match[1]] = $column;
            }
        }

        foreach($i18nColumns as $prefix => $column){
            $script .= "public function get{$prefix}(\$culture = null){return (null !== \$culture && 'ru' == \$culture or null === \$culture && 'ru' == sfContext::getInstance()->getUser()->getCulture()) ? \$this->get{$prefix}Ru() : \$this->get{$prefix}En();}\n";
        }

        foreach($dateColumns as $prefix => $column){
            $script .= "public function get{$prefix}Date(\$mode = 'simple'){return sfPhastUtils::date(\$mode, strtotime(\$this->get{$prefix}At()));}\n";
        }

        foreach ($galleryColumns as $prefix => $column){<commit_msg>date behavior for integer column<commit_after><?php


class sfPhastBehavior extends SfPropelBehaviorBase
{

    protected $phastTables = [];


    public function parentClass($builder){
        $classname = preg_replace('/^Base/', '', $builder->getClassname());
        if(in_array($classname, $this->phastTables)){
            return 'Phast' . $classname;
        };
    }

    public function modifyDatabase()
    {

        foreach((new sfFinder)->name('*.php')->in(__DIR__ . '/../model') as $path){
            $this->phastTables[] = preg_replace('/^Phast|\.php$/', '', basename($path));
        }

        foreach ($this->getDatabase()->getTables() as $table) {
/*
            if(in_array($table->getPhpName(), $phastTables)){
                $table->setBaseClass('Phast' . $table->getPhpName());
            };

            if(in_array($table->getPhpName() . 'Peer', $phastTables)){
                $table->setBasePeer('Phast' . $table->getPhpName() . 'Peer');
            };
*/

            switch ($table->getName()) {
                case 'holder':
                    foreach ($table->getForeignTableNames() as $rel) {
                        $this
                            ->getDatabase()
                            ->getTable($rel)
                            ->setDescription('~holder');
                    }
                    break;

            }
        }

        parent::modifyDatabase();
    }

    public function preSave()
    {
        if ($this->isDisabled()) {
            return;
        }

        return '';
    }

    public function preInsert()
    {
        if ($this->isDisabled()) {
            return;
        }

        return '';
    }


    public function objectMethods()
    {
        if ($this->isDisabled()) {
            return;
        }

        $script = '';
        $script .= 'protected $cached = [];';
        $script .= 'protected function cache($key, Closure $closure){

                        if(array_key_exists($key, $this->cached)){
                            return $this->cached[$key];
                        }

                        return $this->cached[$key] = $closure();
                    }
        ';


        foreach($this->getTable()->getReferrers() as $rel){
            $relTable = $rel->getTable();
            $primaryKeys = $relTable->getPrimaryKey();

            if(count($primaryKeys) == 2){
                $sourceColumn = $relTable->getColumn($rel->getLocalColumns()[0]);
                $targetColumn = $primaryKeys[$primaryKeys[0]->getPhpName() == $sourceColumn->getPhpName() ? 1 : 0];

                $script .= "
                    public function assign{$relTable->getPhpName()}s(\$values){

                        if(\$values === null){
                            \$values = [];
                        }

                        \$values_ex = [];
                        foreach(\$this->get{$relTable->getPhpName()}s() as \$rel){
                            if(in_array(\$rel->get{$targetColumn->getPhpName()}(), \$values)){
                                \$values_ex[] = \$rel->get{$targetColumn->getPhpName()}();
                            }else{
                                \$rel->delete();
                            }
                        }

                        foreach(array_diff(\$values, \$values_ex) as \$value){
                            \$rel = new {$targetColumn->getTable()->getPhpName()}();
                            \$rel->set{$sourceColumn->getPhpName()}(\$this->getId());
                            \$rel->set{$targetColumn->getPhpName()}(\$value);
                            \$rel->save();
                        }

                        return \$this;

                    }
                ";

            }
        }


        $galleryColumns = [];
        $imageColumns = [];
        $dateColumns = [];
        $i18nColumns = [];

        foreach ($this->getTable()->getColumns() as $column) {

            if (preg_match('/^(\w+)?Ru$/', $column->getPhpName(), $match)) {
                $i18nColumns[$match[1]] = $column;
            }

            if (preg_match('/^(\w+)?GalleryId$/', $column->getPhpName(), $match)) {
                if($this->getTable()->getPhpName() == 'Image') continue;
                $prefix = isset($match[1]) ? $match[1] : '';
                $galleryColumns[$prefix] = $column;
            }

            /** @var $column Column */
            if (preg_match('/^(\w+)?ImageId$/', $column->getPhpName(), $match)) {
                $prefix = isset($match[1]) ? $match[1] : '';
                $imageColumns[] = [
                    'column' => $column,
                    'prefix' => $prefix
                ];
            }else if (preg_match('/^(\w+)?At$/', $column->getPhpName(), $match)) {
                $dateColumns[$match[1]] = $column;
            }
        }

        foreach($i18nColumns as $prefix => $column){
            $script .= "public function get{$prefix}(\$culture = null){return (null !== \$culture && 'ru' == \$culture or null === \$culture && 'ru' == sfContext::getInstance()->getUser()->getCulture()) ? \$this->get{$prefix}Ru() : \$this->get{$prefix}En();}\n";
        }

        foreach($dateColumns as $prefix => $column){
            $script .= "public function get{$prefix}Date(\$mode = 'simple'){return sfPhastUtils::date(\$mode, is_int(\$this->get{$prefix}At()) ? \$this->get{$prefix}At() : strtotime(\$this->get{$prefix}At()));}\n";
        }

        foreach ($galleryColumns as $prefix => $column){
{'fraction_non_alphanumeric': 0.1793393723121969, 'fraction_numerical': 0.0031109891115381097, 'mean_word_length': 1.4435501900290633, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 137, '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': '6525247', 'n_tokens_mistral': 3074, 'n_tokens_neox': 2858, 'n_words': 451}