<commit_before><?php
/**
 * teleport
 * Created: 21.12.15 11:06
 * @copyright Copyright (c) 2015 OSKR NIAEP
 */

namespace frontend\models\vks;

use common\components\events\RequestStatusChangedEvent;
use common\components\events\RoomStatusChangedEvent;
use common\components\MinuteFormatter;
use common\rbac\SystemPermission;
use yii\mongodb\validators\MongoDateValidator;
use common\components\validators\MinuteValidator;
use yii\helpers\ArrayHelper;
use common\models\vks\Participant;

/**
 * @author <NAME> <<EMAIL>>
 *
 * RequestForm
 */
class RequestForm extends Request
{
    const SCENARIO_REFRESH_PARTICIPANTS = 'refresh_participants';
    /**
     * @var string Begin time representation in form
     */
    public $beginTimeInput;
    /**
     * @var string End time representation in form
     */
    public $endTimeInput;

    /**
     * @inheritDoc
     */
    public function init()
    {
        parent::init();

        $this->date = new \MongoDate(mktime(0, 0, 0, date("n"), date("j") + 1));
        $this->beginTime = \Yii::$app->params['vks.minTime'];
        $this->endTime = \Yii::$app->params['vks.maxTime'];
        $this->dateInput = \Yii::$app->formatter->asDate($this->date->sec, 'dd.MM.yyyy');
        $this->beginTimeInput = MinuteFormatter::asString($this->beginTime);
        $this->endTimeInput = MinuteFormatter::asString($this->endTime);
    }

    /**
     * @return array
     */
    public function behaviors()
    {
        return array_merge(parent::behaviors(),[
            RequestLogBehavior::class
        ]);
    }

    /**
     * @inheritDoc
     */
    public function scenarios()
    {
        return [
            'default' => ['status', 'topic', 'dateInput', 'beginTimeInput', 'endTimeInput', 'mode', 'equipment', 'audioRecord', 'participantsId', 'note'],
            self::SCENARIO_REFRESH_PARTICIPANTS => ['dateInput', 'beginTimeInput', 'endTimeInput', 'participantsId'],
        ];
    }

    /**
     * @inheritDoc
     */
    public function afterFind()
    {
        parent::afterFind();

        $this->dateInput = \Yii::$app->formatter->asDate($this->date->sec, 'dd.MM.yyyy');
        $this->beginTimeInput = $this->beginTimeString;
        $this->endTimeInput = $this->endTimeString;
    }


    public function rules()
    {
        return array_merge(parent::rules(), [
            [['topic', 'dateInput', 'beginTimeInput', 'endTimeInput', 'mode'], 'required'],

            ['dateInput', MongoDateValidator::className(), 'format' => 'dd.MM.yyyy',
                'min' => \Yii::$app->formatter->asDate(mktime(0, 0, 0), 'dd.MM.yyyy'),
                'max' => \Yii::$app->formatter->asDate(strtotime("+1 week"), 'dd.MM.yyyy'),
            ],

            ['beginTimeInput', MinuteValidator::className(),
                'min' => MinuteFormatter::asString(\Yii::$app->params['vks.minTime']),
                'max' => $this->endTimeInput,
                'minuteAttribute' => 'beginTime'
            ],
            ['beginTimeInput', 'compare', 'compareAttribute' => 'endTimeInput', 'operator' => '!=='],
            ['beginTimeInput', function($attribute) {
                $allowTimeStamp = $this->date->sec + ($this->beginTime - \Yii::$app->params['vks.allowRequestUpdateMinute']) * 60;
                $now = time() + 3 * 60 * 60;

                if($now > $allowTimeStamp) {
                    $this->addError($attribute, "Должно быть не меньше 20 минут от текущего времени");<commit_msg>Allow set begin time for OSKR users without limit<commit_after><?php
/**
 * teleport
 * Created: 21.12.15 11:06
 * @copyright Copyright (c) 2015 OSKR NIAEP
 */

namespace frontend\models\vks;

use common\components\events\RequestStatusChangedEvent;
use common\components\events\RoomStatusChangedEvent;
use common\components\MinuteFormatter;
use common\rbac\SystemPermission;
use yii\mongodb\validators\MongoDateValidator;
use common\components\validators\MinuteValidator;
use yii\helpers\ArrayHelper;
use common\models\vks\Participant;

/**
 * @author <NAME> <<EMAIL>>
 *
 * RequestForm
 */
class RequestForm extends Request
{
    const SCENARIO_REFRESH_PARTICIPANTS = 'refresh_participants';
    /**
     * @var string Begin time representation in form
     */
    public $beginTimeInput;
    /**
     * @var string End time representation in form
     */
    public $endTimeInput;

    /**
     * @inheritDoc
     */
    public function init()
    {
        parent::init();

        $this->date = new \MongoDate(mktime(0, 0, 0, date("n"), date("j") + 1));
        $this->beginTime = \Yii::$app->params['vks.minTime'];
        $this->endTime = \Yii::$app->params['vks.maxTime'];
        $this->dateInput = \Yii::$app->formatter->asDate($this->date->sec, 'dd.MM.yyyy');
        $this->beginTimeInput = MinuteFormatter::asString($this->beginTime);
        $this->endTimeInput = MinuteFormatter::asString($this->endTime);
    }

    /**
     * @return array
     */
    public function behaviors()
    {
        return array_merge(parent::behaviors(),[
            RequestLogBehavior::class
        ]);
    }

    /**
     * @inheritDoc
     */
    public function scenarios()
    {
        return [
            'default' => ['status', 'topic', 'dateInput', 'beginTimeInput', 'endTimeInput', 'mode', 'equipment', 'audioRecord', 'participantsId', 'note'],
            self::SCENARIO_REFRESH_PARTICIPANTS => ['dateInput', 'beginTimeInput', 'endTimeInput', 'participantsId'],
        ];
    }

    /**
     * @inheritDoc
     */
    public function afterFind()
    {
        parent::afterFind();

        $this->dateInput = \Yii::$app->formatter->asDate($this->date->sec, 'dd.MM.yyyy');
        $this->beginTimeInput = $this->beginTimeString;
        $this->endTimeInput = $this->endTimeString;
    }


    public function rules()
    {
        return array_merge(parent::rules(), [
            [['topic', 'dateInput', 'beginTimeInput', 'endTimeInput', 'mode'], 'required'],

            ['dateInput', MongoDateValidator::className(), 'format' => 'dd.MM.yyyy',
                'min' => \Yii::$app->formatter->asDate(mktime(0, 0, 0), 'dd.MM.yyyy'),
                'max' => \Yii::$app->formatter->asDate(strtotime("+1 week"), 'dd.MM.yyyy'),
            ],

            ['beginTimeInput', MinuteValidator::className(),
                'min' => MinuteFormatter::asString(\Yii::$app->params['vks.minTime']),
                'max' => $this->endTimeInput,
                'minuteAttribute' => 'beginTime'
            ],
            ['beginTimeInput', 'compare', 'compareAttribute' => 'endTimeInput', 'operator' => '!=='],
            ['beginTimeInput', function($attribute) {
                if (\Yii::$app->user->can(SystemPermission::APPROVE_REQUEST)) {
                    return;
                }
                $allowTimeStamp = $this->date->sec + ($this->beginTime - \Yii::$app->params['vks.allowRequestUpdateMinute']) * 60;
                $now = time() + 3 * 60 * 60;

                if($now > $allowTimeStamp) {
                    $this->addError($attribute, "Должно быть не меньше 20 минут от текущего времени");
{'fraction_non_alphanumeric': 0.1687889077532541, 'fraction_numerical': 0.008771929824561403, 'mean_word_length': 2.6683964711987547, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 101, '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': '6066370', 'n_tokens_mistral': 2248, 'n_tokens_neox': 2150, 'n_words': 378}