public function storeDataset() { if (isset($_SESSION['dataset']) && isset($_SESSION['images'])) { $dataset = new Dataset(); $dataset->image = new Images(); $result = Dataset::model()->findAllBySql("select identifier from dataset order by identifier desc limit 1;"); $max_doi = $result[0]->identifier; $identifier = $max_doi + 1; $dataset_id = 0; $dataset->attributes = $_SESSION['dataset']; $dataset->image->attributes = $_SESSION['images']; $dataset->identifier = $identifier; $dataset->dataset_size = 0; $dataset->ftp_site = ""; if ($dataset->publication_date == "") { $dataset->publication_date = null; } if ($dataset->modification_date == "") { $dataset->modification_date = null; } if ($dataset->image->validate('update') && $dataset->validate('update') && $dataset->image->save()) { // save image $dataset->image_id = $dataset->image->id; if ($dataset->save()) { $dataset_id = $dataset->id; // link datatypes if (isset($_SESSION['datasettypes'])) { $datasettypes = $_SESSION['datasettypes']; foreach ($datasettypes as $id => $datasettype) { $newDatasetTypeRelationship = new DatasetType(); $newDatasetTypeRelationship->dataset_id = $dataset->id; $newDatasetTypeRelationship->type_id = $id; $newDatasetTypeRelationship->save(); } } } } return array($dataset_id, $identifier); } }
public function actionCreate() { $dataset = new Dataset(); $dataset->image = new Images(); if (isset($_POST['Dataset']) && isset($_POST['Images'])) { $dataset->attributes = $_POST['Dataset']; $dataset->image->attributes = $_POST['Images']; if ($dataset->publication_date == "") { $dataset->publication_date = null; } if ($dataset->modification_date == "") { $dataset->modification_date = null; } if ($dataset->image->validate('update') && $dataset->validate('update') && $dataset->image->save()) { // save image $dataset->image_id = $dataset->image->id; // save dataset if ($dataset->save()) { // link datatypes if (isset($_POST['datasettypes'])) { $datasettypes = $_POST['datasettypes']; foreach ($datasettypes as $id => $datasettype) { $newDatasetTypeRelationship = new DatasetType(); $newDatasetTypeRelationship->dataset_id = $dataset->id; $newDatasetTypeRelationship->type_id = $id; $newDatasetTypeRelationship->save(); } } Yii::app()->user->setFlash('saveSuccess', 'saveSuccess'); if ($dataset->upload_status == 'Pending') { $this->redirect('/dataset/private/identifier/' . $dataset->identifier); } else { $this->redirect(array('/dataset/' . $dataset->identifier)); } } } } $this->render('create', array('model' => $dataset)); }