Exemplo n.º 1
0
 function import($data_type, $formFields)
 {
     extract($formFields);
     $this->logger->debug("XMLImport: " . print_r($formFields, 1));
     $file = $formFields['source'];
     include_once 'xml.class.php';
     $xml = new EF_XML_Helper();
     $d = $xml->toArray(file_get_contents($file));
     $na = substr($data_type, 0, -1);
     $d = $d[$na];
     $this->logger->debug("XML Array to import from:" . print_r($d, 1));
     if (isset($limit) && is_array($limit) && is_numeric($limit['x'])) {
         $this->logger->debug("Limit Range had been defined: {$limit['x']} - {$limit['y']}");
         for ($i = 0; $i < $limit['y']; $i++) {
             $dataSet[] = $d[$limit['x'] + $i];
         }
     } elseif (is_numeric($limit)) {
         $this->logger->debug("Limit, return row {$limit}");
         $dataSet[] = $d[$limit];
     } else {
         $this->logger->debug("No Limit set, return all");
         $dataSet =& $d;
     }
     //get xml into array
     $this->runDataTypeImport($data_type, $dataSet);
 }
Exemplo n.º 2
0
 /**
  * Convert an XML document to a multi dimensional array
  * Pass in an XML document (or SimpleXMLElement object) and this recrusively loops through and builds a representative array
  *
  * @param string $xml - XML document - can optionally be a SimpleXMLElement object
  * @return array ARRAY
  */
 public static function toArray($xml)
 {
     if (is_string($xml)) {
         $xml = new SimpleXMLElement($xml);
     }
     $children = $xml->children();
     if (!$children) {
         return (string) $xml;
     }
     $arr = array();
     foreach ($children as $key => $node) {
         $node = EF_XML_Helper::toArray($node);
         if (is_string($node)) {
             $node = html_entity_decode($node, ENT_QUOTES);
         }
         // support for 'anon' non-associative arrays
         if ($key == 'anon') {
             $key = count($arr);
         }
         // if the node is already set, put it into an array
         if (isset($arr[$key])) {
             if (!is_array($arr[$key]) || !isset($arr[$key][0]) || $arr[$key][0] == null) {
                 $arr[$key] = array($arr[$key]);
             }
             $arr[$key][] = $node;
         } else {
             $arr[$key] = $node;
         }
     }
     global $logger;
     return $arr;
 }