/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Customer(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Customer'])) { $model->attributes = $_POST['Customer']; if ($model->save()) { // Comprobamos si existe la lista de envio de todos los clientes if (count(Mailist::model()->findByAttributes(array('Name' => 'Todos los clientes', 'UserID' => Yii::app()->user->ID)))) { // Si existe la lista añadimos el nuevo cliente $ListID = Mailist::model()->findByAttributes(array('Name' => 'Todos los clientes'))->ID; $modelCustomerList = new CustomerList(); $modelCustomerList->UserID = Yii::app()->user->ID; $modelCustomerList->ListID = $ListID; $modelCustomerList->CustomerID = $model->ID; $modelCustomerList->save(); } else { // Si no existe la lista la creamos y añadimos el cliente nuevo $modelMailist = new Mailist(); $modelMailist->Name = "Todos los clientes"; $modelMailist->UserID = Yii::app()->user->ID; if ($modelMailist->save()) { $modelCustomerList = new CustomerList(); $modelCustomerList->UserID = Yii::app()->user->ID; $modelCustomerList->ListID = $modelMailist->ID; $modelCustomerList->CustomerID = $model->ID; $modelCustomerList->save(); } } $this->redirect(array('admin')); } } $this->render('create', array('model' => $model)); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Mailist(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Mailist'])) { $model->attributes = $_POST['Mailist']; $model->UserID = Yii::app()->user->ID; if ($model->save()) { $this->redirect(array('update', 'id' => $model->ID)); } } $this->render('create', array('model' => $model)); }