/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { if (Yii::app()->user->isGuest && !Yii::app()->user->checkAccess($_POST['Actions']['associationType'] . 'View')) { $this->denied(); } $formTypes = Actions::getFormTypes(); foreach ($formTypes as $type) { // determine which kind of action we're creating if (isset($_POST[$type])) { $post = $_POST[$type]; $modelType = $type; break; } } if (!isset($modelType) && isset($_POST['actionType']) && in_array($_POST['actionType'], $formTypes)) { $modelType = $_POST['actionType']; } elseif (!isset($modelType)) { $modelType = 'Actions'; } $model = new $modelType(); if (isset($post)) { if ($model instanceof ActionFormModelBase) { $model->setAttributes($post); if ($model->validate()) { $model = $model->getAction(); // convert to active record } } else { // ($model instanceof Actions) $model->setX2Fields($post); } if (!$model->hasErrors() && isset($_POST['x2ajax'])) { $this->quickCreate($model); $model->syncGoogleCalendar('create'); } elseif (!$model->hasErrors() && $model->save()) { $model->syncGoogleCalendar('create'); $this->redirect(array('index')); } } if (empty($model->assignedTo)) { $model->assignedTo = Yii::app()->user->getName(); } if (isset($_POST['x2ajax'])) { // allows form to be refreshed if (!$model->hasErrors()) { $model = new $modelType(); } $this->renderInlineForm($model); } else { $this->render('create', array('model' => $model)); } }