echo $form->error($pxForm, 'instrumentOther'); ?> </div> </div> </div> <div class="px-column-right"> <div class="control-group"> <div> <?php echo $form->labelEx($pxForm, 'modification', array('class' => 'px-label')); ?> </div> <div class="px-checkbox-list"> <? $mList = PxInfoForm::getModificationList(); foreach ( $mList as $modification) { $checkedHtml = array_key_exists($modification, $pxForm->modification) ? 'checked="checked"' : ''; echo '<input type="checkbox" name="modification[' . $modification . ']" value="1"' . $checkedHtml . '/> '. $modification . '<br/>'; } ?> <?php echo $form->textField($pxForm, 'modificationOther'); ?> <?php echo $form->error($pxForm, 'modificationOther'); ?> </div> </div> </div>
public function actionPxInfoManagement() { if (!isset($_GET['id'])) { $this->redirect("/user/view_profile"); } else { $dataset = Dataset::model()->findByPk($_GET['id']); if (!$dataset) { Yii::log('dataset id not found', 'debug'); $this->redirect("/user/view_profile"); } if ($dataset->submitter_id != Yii::app()->user->id) { Yii::log('not the owner', 'debug'); Yii::app()->user->setFlash('keyword', "You are not the owner of dataset"); $this->redirect("/user/view_profile"); } # load attributes $keywordsAttr = Attribute::model()->findByAttributes(array('attribute_name' => 'PX_keywords')); $sppAttr = Attribute::model()->findByAttributes(array('attribute_name' => 'PX_sample_processing_protocol')); $dppAttr = Attribute::model()->findByAttributes(array('attribute_name' => 'PX_data_processing_protocol')); $expTypeAttr = Attribute::model()->findByAttributes(array('attribute_name' => 'PX_experiment_type')); $instrumentAttr = Attribute::model()->findByAttributes(array('attribute_name' => 'PX_instrument')); $quantificationAttr = Attribute::model()->findByAttributes(array('attribute_name' => 'PX_quantification')); $modificationAttr = Attribute::model()->findByAttributes(array('attribute_name' => 'PX_modification')); if (!$keywordsAttr or !$sppAttr or !$dppAttr or !$expTypeAttr or !$instrumentAttr or !$quantificationAttr or !$modificationAttr) { Yii::app()->user->setFlash('keyword', "Attr cannot be found."); Yii::log("Attr cannot be found.", 'debug'); $this->redirect("/user/view_profile"); } # create new pxForm for validation and store px info into pxForm $pxForm = new PxInfoForm(); # load keywords $keywords = DatasetAttributes::model()->findByAttributes(array('dataset_id' => $dataset->id, 'attribute_id' => $keywordsAttr->id)); if (!$keywords) { $keywords = new DatasetAttributes(); $keywords->dataset_id = $dataset->id; $keywords->attribute_id = $keywordsAttr->id; } $pxForm->keywords = $keywords->value; # load sample processing protocol $criteria = new CDbCriteria(); $criteria->join = 'LEFT JOIN sample s on (t.sample_id = s.id) LEFT JOIN dataset_sample ds on (ds.sample_id = s.id)'; $criteria->addCondition('ds.dataset_id = ' . $dataset->id); $criteria->addCondition('t.attribute_id = ' . $sppAttr->id); $spp = SampleAttribute::model()->find($criteria); if ($spp) { # get one spp $pxForm->spp = $spp->value; } # load experiment first, if not create one $experiment = Experiment::model()->findByAttributes(array('dataset_id' => $dataset->id)); if (!$experiment) { #create new experiment $experiment = new Experiment(); $experiment->experiment_type = 'proteomic'; $experiment->experiment_name = 'PX "' . $dataset->title . '"'; $experiment->dataset_id = $dataset->id; $experiment->save(false); } # load data processing protocol $dpp = ExpAttributes::model()->findByAttributes(array('exp_id' => $experiment->id, 'attribute_id' => $dppAttr->id)); if (!$dpp) { $dpp = new ExpAttributes(); $dpp->exp_id = $experiment->id; $dpp->attribute_id = $dppAttr->id; } $pxForm->dpp = $dpp->value; # load experiment type $expType = ExpAttributes::model()->findByAttributes(array('exp_id' => $experiment->id, 'attribute_id' => $expTypeAttr->id)); if (!$expType) { # set default experiment type $expType = new ExpAttributes(); $expType->exp_id = $experiment->id; $expType->attribute_id = $expTypeAttr->id; $expType->value = CJSON::encode(array()); } $expTypeVal = CJSON::decode($expType->value); $pxForm->experimentType = $expTypeVal; if (isset($expTypeVal['Other'])) { $pxForm->exTypeOther = $expTypeVal['Other']; } # load instrument $instrument = ExpAttributes::model()->findByAttributes(array('exp_id' => $experiment->id, 'attribute_id' => $instrumentAttr->id)); if (!$instrument) { # set default instrument $instrument = new ExpAttributes(); $instrument->exp_id = $experiment->id; $instrument->attribute_id = $instrumentAttr->id; $instrument->value = CJSON::encode(array()); } $insVal = CJSON::decode($instrument->value); $pxForm->instrument = $insVal; if (isset($insVal['Other'])) { $pxForm->instrumentOther = $insVal['Other']; } # load quantification $quantification = ExpAttributes::model()->findByAttributes(array('exp_id' => $experiment->id, 'attribute_id' => $quantificationAttr->id)); if (!$quantification) { # set default quantification $quantification = new ExpAttributes(); $quantification->exp_id = $experiment->id; $quantification->attribute_id = $quantificationAttr->id; $quantification->value = CJSON::encode(array()); } $quanVal = CJSON::decode($quantification->value); $pxForm->quantification = $quanVal; if (isset($quanVal['Other'])) { $pxForm->quantificationOther = $quanVal['Other']; } # load modification $modification = ExpAttributes::model()->findByAttributes(array('exp_id' => $experiment->id, 'attribute_id' => $modificationAttr->id)); if (!$modification) { # set default modificaiton $modification = new ExpAttributes(); $modification->exp_id = $experiment->id; $modification->attribute_id = $modificationAttr->id; $modification->value = CJSON::encode(array()); } $modiVal = CJSON::decode($modification->value); $pxForm->modification = $modiVal; if (isset($modiVal['Other'])) { $pxForm->modificationOther = $modiVal['Other']; } if (isset($_POST['PxInfoForm'])) { # default is save and quit, redirect to user view_profile page $isSubmit = false; if (isset($_POST['submit-btn'])) { # if user click submit, then submit the dataset $isSubmit = true; } # store px Info $transaction = Yii::app()->db->beginTransaction(); try { $attrs = $_POST['PxInfoForm']; $pxForm->attributes = $attrs; if ($pxForm->validate()) { #store keywords $keywords->value = $attrs['keywords']; #store dpp $dpp->value = $attrs['dpp']; if (isset($_POST['exType'])) { #store exp type $expTypeVal = $_POST['exType']; if (isset($expTypeVal['Other'])) { $expTypeVal['Other'] = $attrs['exTypeOther'] ? $attrs['exTypeOther'] : ""; } $expType->value = CJSON::encode($expTypeVal); } if (isset($_POST['quantification'])) { #store quantification $quanVal = $_POST['quantification']; if (isset($quanVal['Other'])) { $quanVal['Other'] = $attrs['quantificationOther'] ? $attrs['quantificationOther'] : ""; } $quantification->value = CJSON::encode($quanVal); } if (isset($_POST['instrument'])) { #store instrument $insVal = $_POST['instrument']; if (isset($insVal['Other'])) { $insVal['Other'] = $attrs['instrumentOther'] ? $attrs['instrumentOther'] : ""; } $instrument->value = CJSON::encode($insVal); } if (isset($_POST['modification'])) { #store modification $modiVal = $_POST['modification']; if (isset($modiVal['Other'])) { $modiVal['Other'] = $attrs['modificationOther'] ? $attrs['modificationOther'] : ""; } $modification->value = CJSON::encode($modiVal); } #store spp into each samples in the dataset $samples = $dataset->allSamples; $isSppsStored = $this->storeSpps($samples, $attrs['spp'], $sppAttr); if ($isSppsStored and $keywords->save() and $dpp->save() and $expType->save() and $quantification->save() and $instrument->save() and $modification->save()) { $transaction->commit(); if ($isSubmit) { $this->redirect(array('/dataset/submit', 'id' => $dataset->id)); } $this->redirect('/user/view_profile'); } } } catch (Exception $e) { $message = $e->getMessage(); Yii::log(print_r($message, true), 'error'); $transaction->rollback(); $this->redirect('/'); } } $this->render('pxInfoManagement', array('model' => $dataset, 'pxForm' => $pxForm)); } }