Пример #1
0
 /**
  * Returns an xilyXML object of the table.
  * $mxtResource can be either an array (as a result of the chart() method)
  * or a string representing a WHERE statement to execute the chart() method.
  *
  * @param string|object $mxtResource Optional WHETE statement or an array containing the results of the chart() function
  * @return xilyXML|false Returns a xilyXML object
  */
 public function toXML($mxtResource = "")
 {
     if (is_string($mxtResource) || !$mxtResource) {
         $mxtResource = $this->chart($mxtResource);
     }
     if (is_array($mxtResource)) {
         $xlyXML = new \Xily\Xml($this->strID);
         // Array format should be $row[0]['name']
         for ($i = 0; $i < sizeof($mxtResource); $i++) {
             $arrAttributes = array();
             $arrChildren = array();
             $z = 0;
             foreach ($mxtResource[$i] as $key => $value) {
                 if (!$this->arrExclued[$key]) {
                     if ($this->arrAsTag[$key]) {
                         $arrChildren[$key] = $value;
                     } else {
                         $arrAttributes[$key] = $value;
                     }
                 }
             }
             if ($this->strMainTag) {
                 $strItemName = $this->strMainTag;
             } else {
                 $strItemName = 'item';
             }
             $xlyXML->addChild(new \Xily\Xml($strItemName, '', $i, '', $arrAttributes));
             // print_r($arrChildren);
             foreach ($arrChildren as $tag => $value) {
                 $xlyXML->child($i)->addChild(new \Xily\Xml($tag, '', $z, $value));
                 $z++;
             }
         }
         return $xlyXML;
     } else {
         throw new Exception('Could not generate XML object: No valid data resource available');
     }
 }