示例#1
0
 public function parse($xml)
 {
     $root = simplexml_load_string($xml);
     $model = $root->model[0];
     foreach ($model->submission[0]->attributes() as $name => $val) {
         switch ($name) {
             case "id":
                 $this->submission_id = (string) $val;
                 break;
             case "projectName":
                 $this->name = (string) $val;
                 break;
             case "allowDownloadEdits":
                 $this->allowDownloadEdits = (string) $val == "true";
                 break;
             case "versionNumber":
                 $this->versionNumber = (string) $val;
                 break;
         }
     }
     //check the version of the xml (version 1 does not contain table tags)
     if ($root->form) {
         $this->ecVersionNumber = "3";
         if ($model->uploadToLocalServer) {
             $this->uploadToLocalServer = (string) $model->uploadToLocalServer[0];
         }
         for ($t = 0; $t < count($root->form); $t++) {
             $atts = $root->form[$t]->attributes();
             if (!array_key_exists((string) $atts['name'], $this->tables)) {
                 $tbl = new EcTable($this);
             } else {
                 $tbl = $this->tables[(string) $atts['name']];
             }
             $tbl->parse($root->form[$t]);
             $this->tables[$tbl->name] = $tbl;
         }
     } elseif ($root->table) {
         //parse version 2 tables
         $this->ecVersionNumber = "2";
         if ($model->uploadToLocalServer) {
             $this->uploadToLocalServer = (string) $model->uploadToLocalServer[0];
         }
         for ($t = 0; $t < count($root->table); $t++) {
             if (!array_key_exists((string) $root->table[$t]->name, $this->tables)) {
                 $tbl = new EcTable($this);
             } else {
                 $tbl = $this->tables[$root->table[$t]->name];
             }
             $tbl->parse($root->table[$t]);
             $tbl->version = $this->versionNumber;
             $this->tables[$tbl->name] = $tbl;
         }
     } else {
         //parse version 1 table
         $this->ecVersionNumber = "1";
         $tbl = new EcTable($this);
         $tbl->parse($root);
         $tbl->projectName = $this->name;
         $this->tables[$this->name] = $tbl;
     }
     $this->uploadToServer = (string) $model->uploadToServer[0];
 }
示例#2
0
 public function parse($xml, $edit = false)
 {
     global $XML_VERSION;
     $root = simplexml_load_string($xml);
     foreach ($root->attrubutes as $name => $val) {
         if ($name == 'version') {
             $ecv = doubleval($val);
             if ($ecv <= $XML_VERSION) {
                 $this->ecml_version = $ecv;
             } else {
                 throw new Exception(sprintf('This version of the server will only handle XML version %s or earlier.', $XML_VERSION));
             }
         }
     }
     $model = $root->model[0];
     if ($model->uploadToLocalServer) {
         $this->uploadToLocalServer = (string) $model->uploadToLocalServer[0];
     }
     if ($model->downloadFromLocalServer) {
         $this->downloadFromLocalServer = (string) $model->downloadFromLocalServer[0];
     }
     $adeIsSet = false;
     foreach ($model->submission[0]->attributes() as $name => $val) {
         switch ($name) {
             case "id":
                 $this->submission_id = (string) $val;
                 break;
             case "projectName":
                 $this->name = (string) $val;
                 break;
             case "allowDownloadEdits":
                 try {
                     $this->allowDownloadEdits = parseBool((string) $val);
                     $adeIsSet = true;
                 } catch (Exception $e) {
                     throw new InvalidArgumentException("allowDownloadEdits must be true or false");
                 }
                 break;
             case "versionNumber":
                 $this->versionNumber = (string) $val;
                 break;
         }
     }
     if (!$this->submission_id || $this->submission_id == '_' || $this->submission_id == '') {
         $this->submission_id = strtolower($this->name);
     }
     if (!$adeIsSet) {
         throw new Exception("allowDownloadEdits must be set for every project.");
     }
     //check the version of the xml (version 1 does not contain table tags)
     if ($root->description) {
         $this->description = (string) $root->description[0];
     }
     //Clear table array to prevent discrepancy
     $this->tables = array();
     if ($root->form) {
         $this->ecVersionNumber = "3";
         for ($t = 0; $t < count($root->form); $t++) {
             $atts = $root->form[$t]->attributes();
             if (!array_key_exists((string) $atts['name'], $this->tables)) {
                 $tbl = new EcTable($this);
             } elseif ($this->tables[(string) $atts['name']]->id) {
                 $oldTbl = $this->tables[(string) $atts['name']];
                 //unset($this->tables[(string)$atts['name']]);
                 $tbl = new EcTable($this);
                 $tbl->id = $oldTbl->id;
                 foreach ($oldTbl->fields as $name => $fld) {
                     $tbl->fields[$name] = new EcField();
                     $tbl->fields[$name]->idField = $fld->idField;
                 }
                 unset($oldTbl);
             } else {
                 throw new Exception("Table names must be unique. More that one table called " . (string) $atts['name'] . " in {$this->name}");
                 //$tbl = $this->tables[(string)$atts['name']];
             }
             $tbl->parse($root->form[$t]);
             $this->tables[$tbl->name] = $tbl;
         }
     } elseif ($root->table) {
         //parse version 2 tables
         $this->ecVersionNumber = "2";
         if ($model->uploadToLocalServer) {
             $this->uploadToLocalServer = (string) $model->uploadToLocalServer[0];
         }
         for ($t = 0; $t < count($root->table); $t++) {
             if (!array_key_exists((string) $root->table[$t]->name, $this->tables) || $this->tables[(string) $root->table[$t]->name]->id) {
                 $tbl = new EcTable($this);
             } else {
                 throw new Exception("Table names must be unique. More that one table called " . (string) $root->table[$t]->name . "in {$this->name}");
                 //$tbl = $this->tables[(string)$atts['name']];
             }
             $tbl->parse($root->table[$t]);
             $tbl->version = $this->versionNumber;
             $this->tables[$tbl->name] = $tbl;
         }
     } else {
         //parse version 1 table
         $this->ecVersionNumber = "1";
         $tbl = new EcTable($this);
         $tbl->parse($root);
         $tbl->projectName = $this->name;
         $this->tables[$this->name] = $tbl;
         foreach ($tbl->fields as $fld) {
             if ($fld->title) {
                 $this->tables[$this->name]->key = $fld->name;
                 break;
             }
         }
     }
     $this->uploadToServer = (string) $model->uploadToServer[0];
     foreach ($this->tables as $t) {
         if (!$t->isMain) {
             continue;
         }
         $tn = $this->getNextTable($t->name, true);
         if ($tn && !array_key_exists($t->key, $tn->fields)) {
             $f = new EcField();
             $f->name = $t->fields[$t->key]->name;
             $f->label = $t->fields[$t->key]->label;
             $f->form = $tn;
             $f->type = 'input';
             $f->fkTable = $t->name;
             $f->fkField = $t->key;
             $tn->fields[$f->name] = $f;
         }
     }
 }