예제 #1
0
 /**
  * Update criteria from a criteriagroup
  *
  * @param array $criteriagroupJS
  * @param Criteriagroup $criteriagroupDB
  * @return array
  */
 protected function publishCriteria($criteriagroupJS = array(), Criteriagroup $criteriagroupDB)
 {
     $processedCriteria = array();
     // Retrieve existing criteriagroups for this condition
     $existingCriteria = $criteriagroupDB->getCriteria();
     foreach ($criteriagroupJS->criterion as $criterionJS) {
         //criterion attributes
         $data = isset($criterionJS->data) ? $criterionJS->data : null;
         $ctype = isset($criterionJS->type) ? $criterionJS->type : null;
         //echo "criterionid ".$criterionJS->id."<br>\n";
         // Current criterion has never been published or criterion entity has been deleted => create it
         if (empty($criterionJS->critid) || !$existingCriteria->containsKey($criterionJS->critid)) {
             //echo "criterion add <br>\n";
             $criterionDB = $this->stepConditionsManager->createCriterion($data, $ctype, $criteriagroupDB);
             $uniqId = "_CRIT" . uniqid();
             $this->uniqId2crit[$uniqId] = $criterionDB;
             // Update json structure with new resource ID
             $criterionJS->critid = $uniqId;
         } else {
             //echo "criterion edit <br>\n";
             //retrieve criterion
             $criterionDB = $existingCriteria->get($criterionJS->critid);
             //edit criterion in DB
             $criterionDB = $this->stepConditionsManager->editCriterion($data, $ctype, $criteriagroupDB, $criterionDB);
         }
         // Store criteria to know it doesn't have to be deleted when we will clean the condition
         $processedCriteria[] = $criterionDB;
     }
     return $processedCriteria;
 }