示例#1
0
文件: Simulator.php 项目: eureka2/g6k
 protected function loadEntities($simulator, $datasources)
 {
     foreach ($datasources->DataSource as $datasource) {
         $datasourceObj = new DataSource($this, (int) $datasource['id'], (string) $datasource['name'], (string) $datasource['type']);
         $datasourceObj->setUri((string) $datasource['uri']);
         $datasourceObj->setMethod((string) $datasource['method']);
         $datasourceObj->setDatabase((int) $datasource['database']);
         $datasourceObj->setDescription((string) $datasource->Description);
         foreach ($datasource->Namespace as $namespace) {
             $datasourceObj->addNamespace((string) $namespace['prefix'], (string) $namespace['uri']);
         }
         $this->datasources[] = $datasourceObj;
     }
     if ($datasources->Databases) {
         foreach ($datasources->Databases->Database as $database) {
             $databaseObj = new Database($this, (int) $database['id'], (string) $database['type'], (string) $database['name']);
             $databaseObj->setLabel((string) $database['label']);
             $databaseObj->setHost((string) $database['host']);
             $databaseObj->setPort((int) $database['port']);
             $databaseObj->setUser((string) $database['user']);
             if ((string) $database['password'] != '') {
                 $databaseObj->setPassword((string) $database['password']);
             } elseif ((string) $database['user'] != '') {
                 try {
                     $user = $this->controller->get('kernel')->getContainer()->getParameter('database_user');
                     if ((string) $database['user'] == $user) {
                         $databaseObj->setPassword($this->controller->get('kernel')->getContainer()->getParameter('database_password'));
                     }
                 } catch (\Exception $e) {
                 }
             }
             $this->databases[] = $databaseObj;
         }
     }
     $this->setName((string) $simulator["name"]);
     $this->setLabel((string) $simulator["label"]);
     $this->setDefaultView((string) $simulator["defaultView"]);
     $this->setReferer((string) $simulator["referer"]);
     $this->setDynamic((string) $simulator['dynamic'] == '1');
     $this->setMemo((string) $simulator['memo'] == '1');
     $this->setDescription((string) $simulator->Description);
     $this->setRelatedInformations($simulator->RelatedInformations);
     $this->setDateFormat((string) $simulator->DataSet['dateFormat']);
     $this->setDecimalPoint((string) $simulator->DataSet['decimalPoint']);
     $this->setMoneySymbol((string) $simulator->DataSet['moneySymbol']);
     $this->setSymbolPosition((string) $simulator->DataSet['symbolPosition']);
     if ($simulator->DataSet) {
         foreach ($simulator->DataSet->children() as $child) {
             if ($child->getName() == "DataGroup") {
                 $datagroup = $child;
                 $dataGroupObj = new DataGroup($this, (int) $datagroup['id'], (string) $datagroup['name']);
                 $dataGroupObj->setLabel((string) $datagroup['label']);
                 $dataGroupObj->setDescription((string) $datagroup->Description);
                 foreach ($datagroup->Data as $data) {
                     $dataGroupObj->addData($this->loadData($data));
                 }
                 $this->datas[] = $dataGroupObj;
             } elseif ($child->getName() == "Data") {
                 $this->datas[] = $this->loadData($child);
             }
         }
     }
     if ($simulator->Profiles) {
         $this->profiles = new Profiles($this);
         $this->profiles->setLabel((string) $simulator->Profiles['label']);
         foreach ($simulator->Profiles->Profile as $profile) {
             $profileObj = new Profile((int) $profile['id'], (string) $profile['name']);
             $profileObj->setLabel((string) $profile['label']);
             $profileObj->setDescription((string) $profile->Description);
             foreach ($profile->Data as $data) {
                 $profileObj->addData((int) $data['id'], (string) $data['default']);
             }
             $this->profiles->addProfile($profileObj);
         }
     }
     if ($simulator->Steps) {
         $step0 = false;
         foreach ($simulator->Steps->Step as $step) {
             $stepObj = new Step($this, (int) $step['id'], (string) $step['name'], (string) $step['label'], (string) $step['template']);
             if ($stepObj->getId() == 0) {
                 $step0 = true;
             }
             $stepObj->setOutput((string) $step['output']);
             $stepObj->setDescription((string) $step->Description);
             $stepObj->setDynamic((string) $step['dynamic'] == '1');
             foreach ($step->Panels->Panel as $panel) {
                 $panelObj = new Panel($stepObj, (int) $panel['id']);
                 $panelObj->setName((string) $panel['name']);
                 $panelObj->setLabel((string) $panel['label']);
                 foreach ($panel->children() as $block) {
                     if ($block->getName() == "FieldSet") {
                         $fieldset = $block;
                         $fieldsetObj = new FieldSet($panelObj, (int) $fieldset['id']);
                         $fieldsetObj->setLegend((string) $fieldset->Legend);
                         if ((string) $fieldset['disposition'] != "") {
                             $fieldsetObj->setDisposition((string) $fieldset['disposition']);
                         }
                         if ((string) $fieldset['display'] != "") {
                             $fieldsetObj->setDisplay((string) $fieldset['display']);
                         }
                         if ((string) $fieldset['popinLink'] != "") {
                             $fieldsetObj->setPopinLink((string) $fieldset['popinLink']);
                         }
                         foreach ($fieldset->children() as $child) {
                             if ($child->getName() == "Columns") {
                                 foreach ($child->Column as $column) {
                                     $columnObj = new Column(null, (int) $column['id'], (string) $column['name'], (string) $column['type']);
                                     $columnObj->setLabel((string) $column['label']);
                                     $fieldsetObj->addColumn($columnObj);
                                 }
                             } elseif ($child->getName() == "FieldRow") {
                                 $fieldrow = $child;
                                 $fieldRowObj = new FieldRow($fieldsetObj, (string) $fieldrow['label']);
                                 $fieldRowObj->setColon((string) $fieldrow['colon'] == '' || (string) $fieldrow['colon'] == '1');
                                 $fieldRowObj->setHelp((string) $fieldrow['help'] == '1');
                                 $fieldRowObj->setEmphasize((string) $fieldrow['emphasize'] == '1');
                                 $fieldRowObj->setDataGroup((string) $fieldrow['datagroup']);
                                 foreach ($fieldrow->Field as $field) {
                                     $fieldObj = new Field($fieldsetObj, (int) $field['position'], (int) $field['data'], (string) $field['label']);
                                     $fieldObj->setUsage((string) $field['usage']);
                                     $fieldObj->setPrompt((string) $field['prompt']);
                                     $fieldObj->setNewline((string) $field['newline'] == '' || (string) $field['newline'] == '1');
                                     $fieldObj->setRequired((string) $field['required'] == '1');
                                     $fieldObj->setVisibleRequired((string) $field['visibleRequired'] == '1');
                                     $fieldObj->setColon((string) $field['colon'] == '' || (string) $field['colon'] == '1');
                                     $fieldObj->setUnderlabel((string) $field['underlabel'] == '1');
                                     $fieldObj->setHelp((string) $field['help'] == '1');
                                     $fieldObj->setEmphasize((string) $field['emphasize'] == '1');
                                     $fieldObj->setExplanation((string) $field['explanation']);
                                     $fieldObj->setExpanded((string) $field['expanded'] == '1');
                                     if ($field->PreNote) {
                                         $noteObj = new FieldNote($this);
                                         $noteObj->setText((string) $field->PreNote);
                                         $fieldObj->setPreNote($noteObj);
                                     }
                                     if ($field->PostNote) {
                                         $noteObj = new FieldNote($this);
                                         $noteObj->setText((string) $field->PostNote);
                                         $fieldObj->setPostNote($noteObj);
                                     }
                                     $fieldRowObj->addField($fieldObj);
                                 }
                                 $fieldsetObj->addField($fieldRowObj);
                             } elseif ($child->getName() == "Field") {
                                 $field = $child;
                                 $fieldObj = new Field($fieldsetObj, (int) $field['position'], (int) $field['data'], (string) $field['label']);
                                 $fieldObj->setUsage((string) $field['usage']);
                                 $fieldObj->setPrompt((string) $field['prompt']);
                                 $fieldObj->setNewline((string) $field['newline'] == '' || (string) $field['newline'] == '1');
                                 $fieldObj->setRequired((string) $field['required'] == '1');
                                 $fieldObj->setVisibleRequired((string) $field['visibleRequired'] == '1');
                                 $fieldObj->setColon((string) $field['colon'] == '' || (string) $field['colon'] == '1');
                                 $fieldObj->setUnderlabel((string) $field['underlabel'] == '1');
                                 $fieldObj->setHelp((string) $field['help'] == '1');
                                 $fieldObj->setEmphasize((string) $field['emphasize'] == '1');
                                 $fieldObj->setExplanation((string) $field['explanation']);
                                 $fieldObj->setExpanded((string) $field['expanded'] == '1');
                                 if ($field->PreNote) {
                                     $noteObj = new FieldNote($this);
                                     $noteObj->setText((string) $field->PreNote);
                                     $fieldObj->setPreNote($noteObj);
                                 }
                                 if ($field->PostNote) {
                                     $noteObj = new FieldNote($this);
                                     $noteObj->setText((string) $field->PostNote);
                                     $fieldObj->setPostNote($noteObj);
                                 }
                                 $fieldsetObj->addField($fieldObj);
                             }
                         }
                         $panelObj->addFieldSet($fieldsetObj);
                     } elseif ($block->getName() == "BlockInfo") {
                         $blockinfo = $block;
                         $blockinfoObj = new BlockInfo($panelObj, (int) $blockinfo['id']);
                         $blockinfoObj->setName((string) $blockinfo['name']);
                         $blockinfoObj->setLabel((string) $blockinfo['label']);
                         foreach ($blockinfo->Chapter as $chapter) {
                             $chapterObj = new Chapter($blockinfoObj, (int) $chapter['id']);
                             $chapterObj->setName((string) $chapter['name']);
                             $chapterObj->setLabel((string) $chapter['label']);
                             $chapterObj->setIcon((string) $chapter['icon']);
                             $chapterObj->setCollapsible((string) $chapter['collapsible'] == '1');
                             foreach ($chapter->Section as $section) {
                                 $sectionObj = new Section($chapterObj, (int) $section['id']);
                                 $sectionObj->setName((string) $section['name']);
                                 $sectionObj->setLabel((string) $section['label']);
                                 $sectionObj->setContent((string) $section->Content);
                                 $sectionObj->setAnnotations((string) $section->Annotations);
                                 $chapterObj->addSection($sectionObj);
                             }
                             $blockinfoObj->addChapter($chapterObj);
                         }
                         $panelObj->addFieldSet($blockinfoObj);
                     }
                 }
                 $stepObj->addPanel($panelObj);
             }
             foreach ($step->ActionList as $actionList) {
                 foreach ($actionList as $action) {
                     $actionObj = new Action($stepObj, (string) $action['name'], (string) $action['label']);
                     $actionObj->setClass((string) $action['class']);
                     $actionObj->setWhat((string) $action['what']);
                     $actionObj->setFor((string) $action['for']);
                     $actionObj->setUri((string) $action['uri']);
                     $stepObj->addAction($actionObj);
                 }
             }
             foreach ($step->FootNotes as $footnotes) {
                 $footnotesObj = new FootNotes($stepObj);
                 if ((string) $footnotes['position'] != "") {
                     $footnotesObj->setPosition((string) $footnotes['position']);
                 }
                 foreach ($footnotes as $footnote) {
                     $footnoteObj = new FootNote($stepObj, (int) $footnote['id']);
                     $footnoteObj->setText((string) $footnote);
                     $footnotesObj->addFootNote($footnoteObj);
                 }
                 $stepObj->setFootNotes($footnotesObj);
             }
             $this->steps[] = $stepObj;
         }
         if (!$step0) {
             $this->setDynamic(false);
         }
     }
     if ($simulator->Sites) {
         foreach ($simulator->Sites->Site as $site) {
             $siteObj = new Site($this, (int) $site['id'], (string) $site['name'], (string) $site['home']);
             $this->sites[] = $siteObj;
         }
     }
     if ($simulator->Sources) {
         foreach ($simulator->Sources->Source as $source) {
             $sourceObj = new Source($this, (int) $source['id'], (string) $source['datasource'], (string) $source['returnType']);
             $sourceObj->setRequest((string) $source['request']);
             $sourceObj->setSeparator((string) $source['separator']);
             $sourceObj->setDelimiter((string) $source['delimiter']);
             $sourceObj->setReturnPath((string) $source['returnPath']);
             foreach ($source->Parameter as $parameter) {
                 $parameterObj = new Parameter($sourceObj, (string) $parameter['type']);
                 $parameterObj->setName((string) $parameter['name']);
                 $parameterObj->setFormat((string) $parameter['format']);
                 $parameterObj->setData((int) $parameter['data']);
                 $sourceObj->addParameter($parameterObj);
             }
             $this->sources[] = $sourceObj;
         }
     }
     if ($simulator->BusinessRules) {
         foreach ($simulator->BusinessRules->BusinessRule as $brule) {
             $businessRuleObj = new BusinessRule($this, 'rule-' . mt_rand(), (int) $brule['id'], (string) $brule['name']);
             $businessRuleObj->setLabel((string) $brule['label']);
             $businessRuleObj->setConditions((string) $brule->Conditions['value']);
             if (preg_match_all("/#(\\d+)/", (string) $brule->Conditions['value'], $matches)) {
                 foreach ($matches[1] as $id) {
                     $data = $this->getDataById($id);
                     $data->addRuleDependency((int) $brule['id']);
                 }
             }
             if ($brule->Conditions->Condition) {
                 $businessRuleObj->setConnector($this->loadConnector($brule->Conditions->Condition));
             } else {
                 if ($brule->Conditions->Connector) {
                     $businessRuleObj->setConnector($this->loadConnector($brule->Conditions->Connector));
                 }
             }
             foreach ($brule->IfActions->Action as $action) {
                 $ruleActionObj = new RuleAction((int) $action['id'], (string) $action['name']);
                 $ruleActionObj->setTarget((string) $action['target']);
                 $ruleActionObj->setData((string) $action['data']);
                 $ruleActionObj->setDatagroup((string) $action['datagroup']);
                 $ruleActionObj->setStep((string) $action['step']);
                 $ruleActionObj->setPanel((string) $action['panel']);
                 $ruleActionObj->setFieldset((string) $action['fieldset']);
                 $ruleActionObj->setField((string) $action['field']);
                 $ruleActionObj->setBlockinfo((string) $action['blockinfo']);
                 $ruleActionObj->setChapter((string) $action['chapter']);
                 $ruleActionObj->setSection((string) $action['section']);
                 $ruleActionObj->setPrenote((string) $action['prenote']);
                 $ruleActionObj->setPostnote((string) $action['postnote']);
                 $ruleActionObj->setFootnote((string) $action['footnote']);
                 $ruleActionObj->setAction((string) $action['action']);
                 $ruleActionObj->setChoice((string) $action['choice']);
                 $ruleActionObj->setValue((string) $action['value']);
                 $businessRuleObj->addIfAction($ruleActionObj);
                 if ((string) $action['name'] == "setAttribute" && preg_match_all("/#(\\d+)/", (string) $action['value'], $matches)) {
                     foreach ($matches[1] as $id) {
                         $data = $this->getDataById($id);
                         $data->addRuleDependency((int) $brule['id']);
                     }
                 }
             }
             foreach ($brule->ElseActions->Action as $action) {
                 $ruleActionObj = new RuleAction((int) $action['id'], (string) $action['name']);
                 $ruleActionObj->setTarget((string) $action['target']);
                 $ruleActionObj->setData((string) $action['data']);
                 $ruleActionObj->setDatagroup((string) $action['datagroup']);
                 $ruleActionObj->setStep((string) $action['step']);
                 $ruleActionObj->setPanel((string) $action['panel']);
                 $ruleActionObj->setFieldset((string) $action['fieldset']);
                 $ruleActionObj->setField((string) $action['field']);
                 $ruleActionObj->setBlockinfo((string) $action['blockinfo']);
                 $ruleActionObj->setChapter((string) $action['chapter']);
                 $ruleActionObj->setSection((string) $action['section']);
                 $ruleActionObj->setPrenote((string) $action['prenote']);
                 $ruleActionObj->setPostnote((string) $action['postnote']);
                 $ruleActionObj->setFootnote((string) $action['footnote']);
                 $ruleActionObj->setAction((string) $action['action']);
                 $ruleActionObj->setChoice((string) $action['choice']);
                 $ruleActionObj->setValue((string) $action['value']);
                 $businessRuleObj->addElseAction($ruleActionObj);
                 if ((string) $action['name'] == "setAttribute" && preg_match_all("/#(\\d+)/", (string) $action['value'], $matches)) {
                     foreach ($matches[1] as $id) {
                         $data = $this->getDataById($id);
                         $data->addRuleDependency((int) $brule['id']);
                     }
                 }
             }
             $this->businessrules[] = $businessRuleObj;
         }
     }
 }