/** * Gets the value of inputName * * @return string */ public function getInputName() { if (!isset($this->_inputName)) { $nameModel = $this->model->formName(); $this->_inputName = "{$nameModel}[{$this->field}]"; } return $this->_inputName; }
/** * Adds a Service to an Order Cart. * @return mixed */ public function actionAdd($title = null) { if (isset($title) and $service = $this->findServiceByTitle($title)) { $object_models = Yii::$app->request->get('CsObjects') ? Yii::$app->request->get('CsObjects')['id'] : null; $products = Yii::$app->request->get('CsProducts') ? Yii::$app->request->get('CsProducts')['id'] : null; $presentation = Yii::$app->request->get('Presentations') ? $this->findPresentation(Yii::$app->request->get('Presentations')['id']) : null; //service = $this->findService($ser_tr->service_id); $key = isset(Yii::$app->session['cart']['industry'][$service->industry_id]['data']) && Yii::$app->session['cart']['industry'][$service->industry_id]['data'] != null ? count(Yii::$app->session['cart']['industry'][$service->industry_id]['data']) + 1 : 1; $model = $this->loadCartFormModel($service, $object_models, $key, $products, $presentation); // method model $model_action_properties = $this->loadServiceActionProperties($service, $key); // specification model $model_object_properties = $this->loadServiceObjectProperties($service, $object_models, $products, $key); if ($model->load(Yii::$app->request->post()) and $model->storeToCart()) { if ($model_action_properties != null) { // methods if (yii\base\Model::loadMultiple($model_action_properties, Yii::$app->request->post()) and yii\base\Model::validateMultiple($model_action_properties)) { foreach ($model_action_properties as $model_action_property) { $model_action_property->store(); } } } if ($model_object_properties != null and ($model->user_object == '' or $model->user_object == null)) { // specifications if (yii\base\Model::loadMultiple($model_object_properties, Yii::$app->request->post()) and yii\base\Model::validateMultiple($model_object_properties)) { foreach ($model_object_properties as $model_object_property) { $model_object_property->store(); } } } if ($model->imageFiles) { $model->upload(); } if (isset($_POST['searchPresentationIndex']) and $_POST['searchPresentationIndex'] == '') { return $this->redirect($this->addParamsForPresentationIndex($model_object_properties, $model_action_properties, $model, $service)); } if (isset($_POST['addMoreServices']) and $_POST['addMoreServices'] == '') { return $this->redirect(['/services', 'i' => $service->industry_id]); } return $this->redirect(['/new-order', 'industry' => $service->industry_id]); } else { return $this->render('add', ['model' => $model, 'model_object_properties' => $model_object_properties, 'model_action_properties' => $model_action_properties, 'service' => $service, 'object_models' => $object_models, 'objects' => $this->getObjectModels($object_models), 'serviceObjectProperties' => $service->serviceObjectProperties, 'objectProperties' => $this->objectProperties($service, $object_models, $products), 'userObjects' => $this->checkUserObjectsExist($service, $object_models), 'serviceActionProperties' => $service->serviceActionProperties]); } } else { return $this->redirect('/services'); } }
/** * Find the maxlength parameter for an attribute's model. * * This method searches for a yii\validators\StringValidator among all the active validators (based on the current * model scenario). If it founds one, it returns the max length parameter value. If no such value can be found because it is not * defined or because no StringValidator is active, $defaultValue is returned. * * @param yii\base\Model $model * @param string $attribute the attribute name * @return integer | null the maxlength setting * @see yii\validators\StringValidator */ public static function getMaxLength($model, $attribute, $defaultValue = null) { $maxLength = null; foreach ($model->getActiveValidators($attribute) as $validator) { if ($validator instanceof yii\validators\StringValidator) { $maxLength = $validator->max; break; } } return $maxLength !== null ? $maxLength : $defaultValue; }
/** * Take all fields from object based on scenario * @return array Array of fields that must be in the form */ protected function getFieldsBasedOnScenario() { $scenarios = $this->model->scenarios(); return $scenarios[$this->model->scenario]; }