Ejemplo n.º 1
0
 /**
  * Upate sample attribute
  * 
  * @param Sample $model
  */
 private function updateSampleAttributes($model)
 {
     // delete first all the sample Attribute
     SampleAttribute::model()->deleteAllByAttributes(array('sample_id' => $model->id));
     if (trim($model->attributesList)) {
         // From a model we will clone
         $sampleAttr = new SampleAttribute();
         $sampleAttr->sample_id = $model->id;
         foreach (explode(',', $model->attributesList) as $sAttr) {
             $sAttr = str_replace('"', '', $sAttr);
             $data = explode('=', $sAttr);
             if (count($data) == 2) {
                 // Get attribute, if not exist we create
                 $attribute = Attribute::model()->findByAttributes(array('structured_comment_name' => trim($data[0])));
                 if (!$attribute) {
                     $attribute = new Attribute();
                     $attribute->structured_comment_name = trim($data[0]);
                     $attribute->attribute_name = str_replace('_', ' ', trim($data[0]));
                     $attribute->definition = str_replace('_', ' ', trim($data[0]));
                     $attribute->save();
                 }
                 // Let's save the new sample attribute
                 $sampleAttribute = clone $sampleAttr;
                 $sampleAttribute->value = trim($data[1]);
                 $sampleAttribute->attribute_id = $attribute->id;
                 $sampleAttribute->save();
             }
         }
     }
 }
 public function actionUpdateSampleAttribute()
 {
     if (isset($_POST['sa_id']) && isset($_POST['sa_value'])) {
         $sa = SampleAttribute::model()->findByPk($_POST['sa_id']);
         if (!$sa) {
             Util::returnJSON(array("success" => false, "message" => Yii::t("app", "Cannot find the sample attribute.")));
         }
         $sa->value = $_POST['sa_value'];
         if ($sa->save()) {
             Util::returnJSON(array("success" => true));
         }
         Util::returnJSON(array("success" => false, "message" => Yii::t("app", "Update Error.")));
     }
 }
Ejemplo n.º 3
0
 private function storeSpps($samples, $value, $sppAttr)
 {
     $lastSA = SampleAttribute::model()->findByAttributes(array(), array('order' => 'id desc'));
     $lastId = $lastSA->id;
     foreach ($samples as $sample) {
         $spp = SampleAttribute::model()->findByAttributes(array('attribute_id' => $sppAttr->id, 'sample_id' => $sample->id));
         if (!$spp) {
             $lastId = $lastId + 1;
             $spp = new SampleAttribute();
             $spp->id = $lastId;
             $spp->attribute_id = $sppAttr->id;
             $spp->sample_id = $sample->id;
         }
         #store spp value
         $spp->value = $value;
         if (!$spp->save()) {
             return false;
         }
     }
     return true;
 }