public function save($runValidation = true, $attributes = null) { $transaction = Yii::app()->db->beginTransaction(); try { if (!parent::save($runValidation, $attributes)) { throw new CHttpException(500, 'Registration could not be saved.'); } // remove items that has child $serviceIds = array_combine($this->services, $this->services); foreach ($serviceIds as $sid) { $item = OurService::model()->findByPk($sid); if (!$item) { throw new CHttpException(400, 'Request invalid.'); } if ($item->parent_id) { unset($serviceIds[$item->parent_id]); } } // save registered services foreach ($serviceIds as $sid) { $m = new ServiceRegistrationItem(); $m->service_id = $sid; $m->registration_id = $this->id; if (!$m->save()) { throw new CHttpException(500, 'Registration item could not be saved.'); } } $transaction->commit(); } catch (Exception $ex) { $transaction->rollBack(); throw $ex; } return true; }
public function actionStep1() { $model = new ServiceRegistrationForm('step1'); $lastId = Yii::app()->session['last-service-id']; if ($lastId && !in_array($lastId, $model->services)) { $s = OurService::model()->findByPk($lastId); if ($s) { if ($s->childs) { foreach ($s->childs as $c) { $model->services[] = $c->id; } } else { $model->services[] = $s->id; } } unset(Yii::app()->session['last-service-id']); } $this->_setFormData($model); $this->_saveFormData($model); if (Yii::app()->request->isPostRequest && $model->validate()) { $this->redirect(array('step2')); } Yii::app()->theme = 'onehome'; $this->layout = '/layouts/onehome/1-col'; $this->pageTitle = 'Get Started - ' . Yii::app()->params['title']; $this->render('step1', array('model' => $model)); }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer the ID of the model to be loaded */ public function loadModel($id) { $model = OurService::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
/** * @inheritdoc */ public static function model($className = __CLASS__) { return parent::model($className); }