/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Product(); $users = User::getNames(); if (isset($_POST['Product'])) { $temp = $model->attributes; foreach ($_POST['Product'] as $name => &$value) { if ($value == $model->getAttributeLabel($name)) { $value = ''; } } foreach ($_POST as $key => $arr) { $pieces = explode("_", $key); if (isset($pieces[0]) && $pieces[0] == 'autoselect') { $newKey = $pieces[1]; if (isset($_POST[$newKey . "_id"]) && $_POST[$newKey . "_id"] != "") { $val = $_POST[$newKey . "_id"]; } else { $field = Fields::model()->findByAttributes(array('fieldName' => $newKey)); if (isset($field)) { $type = ucfirst($field->linkType); if ($type != "Contacts") { eval("\$lookupModel={$type}::model()->findByAttributes(array('name'=>'{$arr}'));"); } else { $names = explode(" ", $arr); $lookupModel = Contacts::model()->findByAttributes(array('firstName' => $names[0], 'lastName' => $names[1])); } if (isset($lookupModel)) { $val = $lookupModel->id; } else { $val = $arr; } } } $model->{$newKey} = $val; } } foreach (array_keys($model->attributes) as $field) { if (isset($_POST['Product'][$field])) { $model->{$field} = $_POST['Product'][$field]; $fieldData = Fields::model()->findByAttributes(array('modelName' => 'Products', 'fieldName' => $field)); if ($fieldData->type == 'assignment' && $fieldData->linkType == 'multiple') { $model->{$field} = Accounts::parseUsers($model->{$field}); } elseif ($fieldData->type == 'date') { $model->{$field} = strtotime($model->{$field}); } } } // $model->price = $this->parseCurrency($model->price,false); $model->createDate = time(); parent::create($model, $temp, 0); } $this->render('create', array('model' => $model, 'users' => $users)); }