<commit_before><?php

    namespace app\models;

    use Yii;
    use yii\db\ActiveRecord;
    use yii\helpers\ArrayHelper;
    use yii\helpers\Json;
    use yii\sergsova\fileManager\FileManager;
    use yii\web\UploadedFile;

    /**
     * This is the model class for table "tur_event".
     *
     * @property integer       $id
     * @property integer       $event_type_id
     * @property integer       $creator_id
     * @property string        $title
     * @property string        $photo
     * @property string        $desc
     * @property string        $organizators
     * @property string        $particip
     * @property string        $condition
     * @property string        $date_start
     * @property string        $date_end
     * @property string        $date_creation
     * @property string        $status
     * @property integer       $rate
     * @property string        $track_path
     * @property Comments[]    $comments
     * @property User          $creator
     * @property EventType     $eventType
     * @property ParticEvent[] $particEvents
     */
    class Event extends ActiveRecord{
        const STATUS_ACTIVE   = 'ACTIVE';
        const STATUS_INACTIVE = 'INACTIVE';
        const STATUS_BLOCKED  = 'BLOCKED';
        const STATUS_FINISH   = 'FINISH';

        public $time_start;
        public $time_end;

        public $track;

        /**
         * @inheritdoc
         */
        public static function tableName(){
            return 'tur_event';
        }

        /**
         * @inheritdoc
         */
        public function rules(){
            return [
                [
                    [
                        'event_type_id',
                        'title',
                        'desc',
                        'date_start',
                        'date_end',
                        'time_start',
                        'time_end'
                    ],
                    'required'
                ],
                [
                    [
                        'event_type_id',
                        'creator_id',
                        'rate'
                    ],
                    'integer'
                ],
                [
                    [
                        'desc',
                        'particip',
                        'condition',
                        'status',
                        'track_path'
                    ],
                    'string'
                ],
                [
                    [
                        'organizators',
                        'date_creation'
                    ],
                    'safe'
                ],
                [
                    ['title'],
                    'string',
                    'max' => 255
                ],
                [
                    ['event_type_id'],
                    'exist',
                    'skipOnError' => true,
                    'targetClass' => EventType::className(),
                    'targetAttribute' => ['event_type_id' => 'id']
                ],
                [
                    ['creator_id'],
                    'exist',
                    'skipOnError' => true,
                    'targetClass' => User::className(),
                    'targetAttribute' => ['creator_id' => 'id']
                ],
                [
                    ['creator_id'],
                    'default',
                    'value' => Yii::$app->user->id
                ],
                [
                    'date_creation',
                    'default',
                    'value' => date('Y-m-d H:i:s')
                ],
                [
                    'rate',
                    'default',
                    'value' => 0
                ],
                [
                    'status',
                    'default',
                    'value' => self::STATUS_INACTIVE
                ],
                [
                    'track',
                    'file',
                    'extensions' => 'kml'
                ]

            ];
        }

        /**
         * @inheritdoc
         */
        public function attributeLabels(){
            return [
                'id' => 'ID',
                'event_type_id' => 'Тип события',
                'creator_id' => 'Автор',
                'title' => 'Название',
                'photo' => 'Фотографии',
                'desc' => 'Описание',
                'organizators' => 'Организаторы',
                'particip' => 'Должности помошников',
                'condition' => 'Условия',
                'date_start' => 'Дата начала',
                'date_end' => 'Дата оклнчания',
                'date_creation' => 'Дата создания',
                'status' => 'Статус',
                'rate' => 'Регйтинг',
            ];
        }

        public function afterFind(){
            $this->organizators = json_decode($this->organizators);
            $this->_countRate();

            if(strtotime($this->date_end) < strtotime(date('Y-m-d H:i:s'))){
                $this->status = self::STATUS_FINISH;
                $this->save(false);
            }

            $this->time_start = date('H:i', strtotime($this->date_start));
            $this->time_end = date('H:i', strtotime($this->date_end));
            parent::afterFind();
        }

        public function beforeSave($insert){
            if($this->time_start){
                $this->date_start = date('Y-m-d H:i:s', strtotime($this->date_start) + strtotime($this->time_start) - strtotime(date('Y-m-d')));
            }
            if($this->time_end){
                $this->date_end = date('Y-m-d H:i:s', strtotime($this->date_end) + strtotime($this->time_end) - strtotime(date('Y-m-d')));
            }

            $this->track = UploadedFile::getInstance($this, 'track');
            FileManager::getInstance()
                       ->createDirectory('event_track');
            $this->track->saveAs(FileManager::getInstance()
                                            ->getStoragePath().'event_track/'.$this->track->baseName.'.'.$this->track->extension);
            $this->track_path = Json::encode(['event_track/'.$this->track->baseName.'.'.$this->track->extension]);

            return parent::beforeSave($insert);
        }

        public function afterSave($insert, $changedAttributes){
            if($insert){
                $participant = new ParticEvent();
                $participant->user_id = Yii::$app->user->id;
                $participant->event_id = $this->id;
                $participant->confirmed = true;
                $participant->insert();
            }
<commit_msg>oshibko photo<commit_after><?php

    namespace app\models;

    use Yii;
    use yii\db\ActiveRecord;
    use yii\helpers\ArrayHelper;
    use yii\helpers\Json;
    use yii\sergsova\fileManager\FileManager;
    use yii\web\UploadedFile;

    /**
     * This is the model class for table "tur_event".
     *
     * @property integer       $id
     * @property integer       $event_type_id
     * @property integer       $creator_id
     * @property string        $title
     * @property string        $photo
     * @property string        $desc
     * @property string        $organizators
     * @property string        $particip
     * @property string        $condition
     * @property string        $date_start
     * @property string        $date_end
     * @property string        $date_creation
     * @property string        $status
     * @property integer       $rate
     * @property string        $track_path
     * @property Comments[]    $comments
     * @property User          $creator
     * @property EventType     $eventType
     * @property ParticEvent[] $particEvents
     */
    class Event extends ActiveRecord{
        const STATUS_ACTIVE   = 'ACTIVE';
        const STATUS_INACTIVE = 'INACTIVE';
        const STATUS_BLOCKED  = 'BLOCKED';
        const STATUS_FINISH   = 'FINISH';

        public $time_start;
        public $time_end;

        public $track;

        /**
         * @inheritdoc
         */
        public static function tableName(){
            return 'tur_event';
        }

        /**
         * @inheritdoc
         */
        public function rules(){
            return [
                [
                    [
                        'event_type_id',
                        'title',
                        'desc',
                        'date_start',
                        'date_end',
                        'time_start',
                        'time_end'
                    ],
                    'required'
                ],
                [
                    [
                        'event_type_id',
                        'creator_id',
                        'rate'
                    ],
                    'integer'
                ],
                [
                    [
                        'desc',
                        'particip',
                        'condition',
                        'status',
                        'track_path',
                        'photo'
                    ],
                    'string'
                ],
                [
                    [
                        'organizators',
                        'date_creation'
                    ],
                    'safe'
                ],
                [
                    ['title'],
                    'string',
                    'max' => 255
                ],
                [
                    ['event_type_id'],
                    'exist',
                    'skipOnError' => true,
                    'targetClass' => EventType::className(),
                    'targetAttribute' => ['event_type_id' => 'id']
                ],
                [
                    ['creator_id'],
                    'exist',
                    'skipOnError' => true,
                    'targetClass' => User::className(),
                    'targetAttribute' => ['creator_id' => 'id']
                ],
                [
                    ['creator_id'],
                    'default',
                    'value' => Yii::$app->user->id
                ],
                [
                    'date_creation',
                    'default',
                    'value' => date('Y-m-d H:i:s')
                ],
                [
                    'rate',
                    'default',
                    'value' => 0
                ],
                [
                    'status',
                    'default',
                    'value' => self::STATUS_INACTIVE
                ],
                [
                    'track',
                    'file',
                    'extensions' => 'kml'
                ]

            ];
        }

        /**
         * @inheritdoc
         */
        public function attributeLabels(){
            return [
                'id' => 'ID',
                'event_type_id' => 'Тип события',
                'creator_id' => 'Автор',
                'title' => 'Название',
                'photo' => 'Фотографии',
                'desc' => 'Описание',
                'organizators' => 'Организаторы',
                'particip' => 'Должности помошников',
                'condition' => 'Условия',
                'date_start' => 'Дата начала',
                'date_end' => 'Дата оклнчания',
                'date_creation' => 'Дата создания',
                'status' => 'Статус',
                'rate' => 'Регйтинг',
            ];
        }

        public function afterFind(){
            $this->organizators = json_decode($this->organizators);
            $this->_countRate();

            if(strtotime($this->date_end) < strtotime(date('Y-m-d H:i:s'))){
                $this->status = self::STATUS_FINISH;
                $this->save(false);
            }

            $this->time_start = date('H:i', strtotime($this->date_start));
            $this->time_end = date('H:i', strtotime($this->date_end));
            parent::afterFind();
        }

        public function beforeSave($insert){
            if($this->time_start){
                $this->date_start = date('Y-m-d H:i:s', strtotime($this->date_start) + strtotime($this->time_start) - strtotime(date('Y-m-d')));
            }
            if($this->time_end){
                $this->date_end = date('Y-m-d H:i:s', strtotime($this->date_end) + strtotime($this->time_end) - strtotime(date('Y-m-d')));
            }

            $this->track = UploadedFile::getInstance($this, 'track');
            if($this->track){
                FileManager::getInstance()
                           ->createDirectory('event_track');
                $this->track->saveAs(FileManager::getInstance()
                                                ->getStoragePath().'event_track/'.$this->track->baseName.'.'.$this->track->extension);
                $this->track_path = Json::encode(['event_track/'.$this->track->baseName.'.'.$this->track->extension]);
            }
            return parent::beforeSave($insert);
        }

        public function afterSave($insert, $changedAttributes){
            if($insert){
                $participant = new ParticEvent();
                $participant->user_id = Yii::$app->user->id;
                $participant->event_id = $this->id;
                $participant->confirmed = true;
                $participant->insert();
            }

{'fraction_non_alphanumeric': 0.12429378531073447, 'fraction_numerical': 0.0005947071067499256, 'mean_word_length': 1.0160347669713772, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 142, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '181952', 'n_tokens_mistral': 3591, 'n_tokens_neox': 3384, 'n_words': 559}