Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace app\modules\proposal\models\frontend;
- use app\modules\routes\models\Cities;
- use app\modules\routes\models\RoutesCities;
- use Yii;
- use app\modules\routes\models\Tariffs;
- use app\modules\proposal\models\Proposal;
- use yii\helpers\ArrayHelper;
- class CalculateForm extends Proposal
- {
- public $cargoData;
- public $mass;
- public $capacity;
- public $cargoGeometry;
- public $pattern;
- public $msg;
- public $prePayPrice;
- public $postPayPrice;
- const SCENARIO_CALC_FORM = 'CalculateForm';
- const SCENARIO_POPUP_FORM = 'CalculatePopupForm';
- public function init()
- {
- parent::init();
- $this->pattern = '^[ 0-9.,]+$';
- }
- public function rules()
- {
- return ArrayHelper::merge(parent::rules(),[
- [['from', 'to'], 'required', 'on' => self::SCENARIO_CALC_FORM],
- ['to', 'compare', 'compareAttribute' => 'from', 'operator' => '!=', 'on' => self::SCENARIO_CALC_FORM],
- ['from', 'compare', 'compareAttribute' => 'to', 'operator' => '!=', 'on' => self::SCENARIO_CALC_FORM],
- [
- 'message', 'match', 'pattern' => '#^[-а-яёa-z0-9 ,."]+$#iu',
- 'message' => '«{attribute}» может содержать А-ЯЁ, A-Z, тире и цифры', 'on' => self::SCENARIO_CALC_FORM],
- [
- 'name', 'match', 'pattern' => '#^[а-яё ]+$#iu',
- 'message' => '«{attribute}» может содержать А-ЯЁ', 'on' => self::SCENARIO_POPUP_FORM
- ],
- [
- 'phone', 'match', 'pattern' => '#\+7 \(\d{3}\) \d{3}-\d{2}-\d{2}#',
- 'message' => '«{attribute}» должен быть в формате +7(222) 333-44-55', 'on' => self::SCENARIO_POPUP_FORM
- ],
- [
- 'phone', 'required', 'when' => function($model){
- return $model->email == '';
- },
- 'on' => self::SCENARIO_POPUP_FORM
- ],
- [
- 'email', 'required', 'when' => function($model){
- return $model->phone == '';
- },
- 'on' => self::SCENARIO_POPUP_FORM
- ],
- [['message', 'name', 'cargoData'], 'string', 'on' => self::SCENARIO_CALC_FORM],
- ['email', 'email', 'on' => self::SCENARIO_CALC_FORM],
- [['mass', 'capacity'], 'number', 'on' => self::SCENARIO_CALC_FORM],
- ['capacity', 'default', 'value' => '0.005', 'on' => self::SCENARIO_CALC_FORM],
- ['weight', 'double'],
- ]);
- }
- public function scenarios()
- {
- $scenarios = parent::scenarios();
- $scenarios[self::SCENARIO_CALC_FORM] = ['from', 'to', 'message', 'name', 'email', 'phone', 'mass', 'capacity', 'cargoData'];
- return $scenarios;
- }
- public function attributeLabels()
- {
- return ArrayHelper::merge(parent::attributeLabels(), [
- 'mass' => 'Massa',
- 'capacity' => 'Capacity'
- ]);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement