コード例 #1
0
ファイル: Project.php プロジェクト: jessesiu/GigaDBV3
 public static function getListProjects()
 {
     $models = Species::model()->findAll();
     $list = array();
     foreach ($models as $key => $model) {
         $list[$model->id] = $model->common_name;
     }
     return $list;
 }
コード例 #2
0
ファイル: Species.php プロジェクト: jessesiu/GigaDBV3
 public static function getListCommonNames()
 {
     $models = Species::model()->findAll(array('limit' => 10));
     $list = array();
     foreach ($models as $key => $model) {
         $list[$model->id] = $model->common_name;
     }
     return $list;
 }
コード例 #3
0
 /**
  * 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 = Species::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
コード例 #4
0
 public function actionAddSample()
 {
     if (isset($_POST['dataset_id']) && isset($_POST['sample_name']) && isset($_POST['species'])) {
         $transaction = Yii::app()->db->beginTransaction();
         try {
             if ($_POST['sample_name'] == "") {
                 Util::returnJSON(array("success" => false, "message" => Yii::t("app", 'Cannot add sample, please input "Sample ID" value.')));
             }
             if ($_POST['species'] == "") {
                 Util::returnJSON(array("success" => false, "message" => Yii::t("app", 'Cannot add sample, please input "valid  species" value.')));
             }
             $array = explode(":", $_POST['species']);
             $tax_id = $array[0];
             $species = Species::model()->findByAttributes(array('tax_id' => $tax_id));
             if (!$species) {
                 Util::returnJSON(array("success" => false, "message" => Yii::t("app", 'Cannot add sample, please input "valid  species" value.')));
             }
             #create new sample
             $sample = new Sample();
             $sample->species_id = $species->id;
             $sample->name = $_POST['sample_name'];
             $sample->submitted_id = Yii::app()->user->id;
             $sample->submission_date = date('Y-m-d H:i:s');
             $user = User::model()->findByPk(Yii::app()->user->id);
             if ($user) {
                 $sample->contact_author_name = $user->first_name . " " . $user->last_name;
                 $sample->contact_author_email = $user->email;
             }
             if ($sample->save()) {
                 #create dataset sample
                 $ds = new DatasetSample();
                 $ds->dataset_id = $_POST['dataset_id'];
                 $ds->sample_id = $sample->id;
                 if ($ds->save()) {
                     $transaction->commit();
                     Util::returnJSON(array("success" => true));
                 }
             }
             Util::returnJSON(array("success" => false, "message" => Yii::t("app", "Save Error.")));
         } catch (Exception $e) {
             $message = $e->getMessage();
             Yii::log(print_r($message, true), 'error');
             $transaction->rollback();
             Util::returnJSON(array("success" => false, "message" => Yii::t("app", 'Cannot add sample, please input "valid  species" value.')));
         }
     }
 }
コード例 #5
0
 /**
  * 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);
     //$old_code= $model->code;
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Sample'])) {
         $model->attributes = $_POST['Sample'];
         if (strpos($_POST['Sample']['species_id'], ":") !== false) {
             $array = explode(":", $_POST['Sample']['species_id']);
             //                var_dump($array);
             $tax_id = $array[0];
             if (is_numeric($tax_id)) {
                 $species = Species::model()->findByAttributes(array('tax_id' => $tax_id));
                 $model->species_id = $species->id;
                 // save sample attributes
                 $model->attributesList = $_POST['Sample']['attributesList'];
                 $this->updateSampleAttributes($model);
                 if ($model->save()) {
                     // $dataset_id= DatasetSample::model()->findByAttributes(array('sample_id'=>$model->id))->dataset_id;
                     //     $files= File::model()->findAllByAttributes(array('code'=>$old_code,'dataset_id'=>$dataset_id));
                     //     foreach($files as $file)
                     //     {
                     //         $file->code=$model->code;
                     //         $file->save();
                     //         //echo $model->code;
                     //     }
                     $this->redirect(array('view', 'id' => $model->id));
                 }
             } else {
                 $model->addError("error", 'The species id should be numeric');
             }
         } else {
             $model->addError("error", 'The input format is wrong, should be id:common_name');
         }
     }
     $specie = Species::model()->findByPk($model->species_id);
     $this->render('update', array('model' => $model, 'specie' => $specie));
 }
コード例 #6
0
ファイル: Sample.php プロジェクト: jessesiu/GigaDBV3
 public static function getCommonList($ids)
 {
     $crit = new CDbCriteria();
     $crit->join = "join sample on sample.species_id = t.id";
     $crit->addInCondition("sample.id", $ids);
     return Species::model()->findAll($crit);
 }
コード例 #7
0
ファイル: _form1.php プロジェクト: jessesiu/GigaDBV3
	<p class="note">Fields with <span class="required">*</span> are required.</p>

	<?php 
echo $form->errorSummary($model);
?>

	<div class="control-group">
		<?php 
echo $form->labelEx($model, 'species_id', array('class' => 'control-label'));
?>

				<div class="controls">
                                    
        <?php 
echo CHtml::activeDropDownList($model, 'species_id', CHtml::listData(Species::model()->findAll(), 'id', 'common_name'));
?>
		<?php 
echo $form->error($model, 'species_id');
?>
                </div>
	</div>

	<div class="control-group">
		<?php 
echo $form->labelEx($model, 's_attrs', array('class' => 'control-label'));
?>
				<div class="controls">
		<?php 
echo $form->textArea($model, 's_attrs', array('rows' => 6, 'cols' => 50));
?>