public static function storeDatasetTypes($dataset_id, $types) { $currentTypes = DatasetType::model()->findAllByAttributes(array('dataset_id' => $dataset_id)); $currentIds = array(); foreach ($currentTypes as $currentType) { $currentIds[] = $currentType->type_id; } foreach ($currentTypes as $currentType) { if (!in_array($currentType->type_id, $types)) { if (!$currentType->delete(false)) { return false; } } } foreach ($types as $id) { if (!in_array($id, $currentIds)) { if (!self::createDatasetType($dataset_id, $id)) { return false; } } } return true; }
public function getIsProteomic() { $dt = DatasetType::model()->findByAttributes(array('dataset_id' => $this->id, 'type_id' => 10)); if ($dt) { return true; } return false; }
/** * Updates a particular model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id the ID of the model to be updated */ public function actionUpdate($id) { $model = $this->loadModel($id); if (isset($_POST['Dataset'])) { $datasetAttr = $_POST['Dataset']; $model->setAttributes($datasetAttr, true); if ($model->upload_status == 'Published') { $files = $model->files; if (strpos($model->ftp_site, "10.5524") == FALSE) { $model->ftp_site = "ftp://climb.genomics.cn/pub/10.5524/100001_101000/" . $model->identifier; if (count($files) > 0) { foreach ($files as $file) { $origin_location = $file->location; $new_location = ""; $location_array = explode("/", $origin_location); $count = count($location_array); if ($count == 1) { $new_location = "ftp://climb.genomics.cn/pub/10.5524/100001_101000/" . $model->identifier . "/" . $location_array[0]; } else { if ($count >= 2) { $new_location = "ftp://climb.genomics.cn/pub/10.5524/100001_101000/" . $model->identifier . "/" . $location_array[$count - 2] . "/" . $location_array[$count - 1]; } } $file->location = $new_location; $file->date_stamp = date("Y-m-d H:i:s"); if (!$file->save()) { return false; } } } } } // Image information $image = $model->image; $image->attributes = $_POST['Images']; $image->scenario = 'update'; if ($model->publication_date == "") { $model->publication_date = null; } if ($model->modification_date == "") { $model->modification_date = null; } if ($model->fairnuse == "") { $model->fairnuse = null; } if ($model->save() && $image->save()) { if (isset($_POST['datasettypes'])) { $datasettypes = $_POST['datasettypes']; } $datasetTypeMaps = DatasetType::model()->findAllByAttributes(array('dataset_id' => $id)); for ($i = 0; $i < count($datasetTypeMaps); ++$i) { $datasetTypeMap = $datasetTypeMaps[$i]; if (isset($datasettypes) && !in_array($datasetTypeMap->type_id, array_keys($datasettypes), true) || !isset($datasettypes)) { $datasetTypeMap->delete(); } } if (isset($datasettypes)) { foreach ($datasettypes as $datasetTypeId => $datasettype) { $currDatasetTypeMap = DatasetType::model()->findByAttributes(array('dataset_id' => $model->id, 'type_id' => $datasetTypeId)); if (!$currDatasetTypeMap) { $newDatasetTypeRelationship = new DatasetType(); $newDatasetTypeRelationship->dataset_id = $model->id; $newDatasetTypeRelationship->type_id = $datasetTypeId; $newDatasetTypeRelationship->save(); } } } if ($model->upload_status == 'Published') { $this->redirect('/dataset/' . $model->identifier); } else { $this->redirect(array('/dataset/view/id/' . $model->identifier . '/token/' . $model->token)); } } else { Yii::log(print_r($model->getErrors(), true), 'debug'); } } $this->render('update', array('model' => $model)); }