Пример #1
0
 /**
  * Add or update stepconditions
  *
  * @param Step $stepDB
  * @param \stdClass $stepJS
  * @return array
  */
 protected function publishStepConditions(Step $stepDB, \stdClass $stepJS = null)
 {
     //retrieve condition from DB
     $existingCondition = $stepDB->getCondition();
     $processedCondition = array();
     if (isset($stepJS->condition)) {
         //retrieve the condition
         $conditionJS = $stepJS->condition;
         // Current condition has never been published or condition entity has been deleted => create it
         if (empty($conditionJS->scid) || $existingCondition->getId() != $conditionJS->scid) {
             //echo "create condition <br>\n";
             $publishedCondition = $this->stepConditionsManager->createStepCondition($stepDB);
             $uniqId = "_COND" . uniqid();
             $this->uniqId2sc[$uniqId] = $publishedCondition;
             // Update json structure with new resource ID
             $conditionJS->scid = $uniqId;
         } else {
             //echo "update condition <br>\n";
             $publishedCondition = $this->getStepCondition($conditionJS->scid);
             $publishedCondition = $this->stepConditionsManager->editStepCondition($stepDB, $publishedCondition);
         }
         $processedCondition[] = $publishedCondition;
         //echo "manage criteriagroups <br>\n";
         //manage criteriagroups
         $existingCriteriagroups = $publishedCondition->getCriteriagroups()->toArray();
         $publishedCriteriagroup = $this->publishCriteriagroups($publishedCondition, 0, null, $conditionJS->criteriagroups);
         //echo "Clean criteriagroup to remove <br>\n";
         // Clean criteriagroup to remove
         $this->cleanCriteriagroup($publishedCriteriagroup, $existingCriteriagroups, $publishedCondition);
         //echo "Clean Condition to remove <br>\n";
         // Clean Condition to remove
         if (is_object($existingCondition)) {
             $this->cleanCondition($publishedCondition, $existingCondition, $stepDB);
         }
     }
     return $processedCondition;
 }