Пример #1
0
 public function import_XML($xml)
 {
     $xpath = new DOMXPath($xml);
     $elements = $xpath->query("/export");
     foreach ($elements as $element) {
         if (Ini::$version != $element->getAttribute("version")) {
             return json_encode(array("result" => -5));
         }
     }
     $last_result = 0;
     $elements = $xpath->query("/export/Test");
     foreach ($elements as $element) {
         $element_id = $element->getAttribute("id");
         $this->xml_hash = $element->getAttribute("xml_hash");
         $children = $element->childNodes;
         foreach ($children as $child) {
             switch ($child->nodeName) {
                 case "name":
                     $this->name = $child->nodeValue;
                     break;
                 case "description":
                     $this->description = $child->nodeValue;
                     break;
                 case "type":
                     $this->type = $child->nodeValue;
                     break;
                 case "code":
                     $this->code = $child->nodeValue;
                     break;
             }
         }
         $last_result = $this->mysql_save();
         $elements = $xpath->query("/export/Test[@id='" . $element_id . "']/TestVariables/TestVariable");
         foreach ($elements as $element) {
             $tv = new TestVariable();
             $tv->Test_id = $last_result;
             $children = $element->childNodes;
             foreach ($children as $child) {
                 switch ($child->nodeName) {
                     case "index":
                         $tv->index = $child->nodeValue;
                         break;
                     case "name":
                         $tv->name = $child->nodeValue;
                         break;
                     case "description":
                         $tv->description = $child->nodeValue;
                         break;
                     case "type":
                         $tv->type = $child->nodeValue;
                         break;
                 }
             }
             $tv->mysql_save();
         }
     }
     return $last_result;
 }
Пример #2
0
 public function mysql_save_from_post($post)
 {
     $lid = parent::mysql_save_from_post($post);
     $sections = array();
     if (isset($post['sections'])) {
         $sections = json_decode($post["sections"], true);
     }
     if ($this->id != 0) {
         $this->delete_sections();
         $this->delete_templates();
         $this->delete_object_links(TestVariable::get_mysql_table());
         $i = 0;
     } else {
         $found = false;
         foreach ($sections as $section) {
             if ($section['counter'] == 1) {
                 $found = true;
                 break;
             }
         }
         if (!$found) {
             $start_section = new TestSection();
             $start_section->TestSectionType_id = DS_TestSectionType::START;
             $start_section->Test_id = $lid;
             $start_section->counter = 1;
             $start_section->mysql_save();
         }
         $found = false;
         foreach ($sections as $section) {
             if ($section['counter'] == 2) {
                 $found = true;
                 break;
             }
         }
         if (!$found) {
             $end_section = new TestSection();
             $end_section->TestSectionType_id = DS_TestSectionType::END;
             $end_section->Test_id = $lid;
             $end_section->counter = 2;
             $end_section->mysql_save();
         }
     }
     $i = 0;
     if (array_key_exists("parameters", $post)) {
         foreach ($post["parameters"] as $param) {
             $p = json_decode($param);
             $var = new TestVariable();
             $var->description = $p->description;
             $var->name = $p->name;
             $var->index = $i;
             $var->type = 0;
             $var->Test_id = $lid;
             $var->mysql_save();
             $i++;
         }
     }
     if (array_key_exists("returns", $post)) {
         foreach ($post["returns"] as $ret) {
             $r = json_decode($ret);
             $var = new TestVariable();
             $var->description = $r->description;
             $var->name = $r->name;
             $var->index = $i;
             $var->type = 1;
             $var->Test_id = $lid;
             $var->mysql_save();
             $i++;
         }
     }
     foreach ($sections as $section) {
         $s = new TestSection();
         $s->counter = $section['counter'];
         $s->TestSectionType_id = $section['type'];
         $s->end = $section['end'];
         $s->Test_id = $lid;
         $s->parent_counter = $section['parent'];
         $slid = $s->mysql_save();
         $vals = $section['value'];
         foreach ($vals as $k => $v) {
             $index = substr($k, 1);
             $value = $v;
             $sv = new TestSectionValue();
             $sv->TestSection_id = $slid;
             $sv->index = $index;
             $sv->value = $value;
             $sv->mysql_save();
         }
         if ($s->TestSectionType_id == DS_TestSectionType::LOAD_HTML_TEMPLATE) {
             $ts = TestSection::from_mysql_id($slid);
             $vals = $ts->get_values();
             $template = Template::from_mysql_id($vals[0]);
             if ($template != null) {
                 $html = Template::output_html($template->HTML, $vals, $template->get_outputs(), $template->get_inserts());
                 $test_template = new TestTemplate();
                 $test_template->Test_id = $lid;
                 $test_template->TestSection_id = $slid;
                 $test_template->Template_id = $vals[0];
                 $test_template->HTML = $html;
                 $test_template->mysql_save();
             }
         }
     }
     $sql = sprintf("DELETE FROM `%s` WHERE `Test_id`=%d", TestProtectedVariable::get_mysql_table(), $lid);
     mysql_query($sql);
     if (array_key_exists("protected", $post)) {
         foreach ($post['protected'] as $var) {
             $var = json_decode($var);
             $s = new TestProtectedVariable();
             $s->name = $var->name;
             $s->Test_id = $lid;
             $slid = $s->mysql_save();
         }
     }
     $obj = static::from_mysql_id($lid);
     if ($obj != null) {
         $xml_hash = $obj->calculate_xml_hash();
         $obj->xml_hash = $xml_hash;
         $obj->mysql_save();
     }
     return $lid;
 }