/** * 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'); } }
/** * Converts the array into an Xily\Xml object * * @param Xily\Xml $xmlNode * @param array $mxtData * @param bool $bolAssoc * @return Xily\Xml */ private function fromXml($xmlNode, $mxtData, $bolAssoc) { if (is_array($mxtData)) { if ($bolAssoc && self::checkAssoc($mxtData)) { foreach ($mxtData as $key => $value) { $xmlChild = new Xml($key); $xmlNode->addChild(self::fromXml($xmlChild, $value, $bolAssoc)); } } else { foreach ($mxtData as $key => $value) { $xmlChild = new Xml('node', null, array('key' => $key)); $xmlNode->addChild(self::fromXml($xmlChild, $value, $bolAssoc)); } } } else { $xmlNode->setValue($mxtData); } return $xmlNode; }
// The meta object will be passed on when the bean is run try { if (!preg_match('`^[a-z]{1,32}$`', $view)) { throw new Exception('View "' . $view . '" not found.'); } if (!$userAuthenticated) { if (isset($_REQUEST['username']) && $_REQUEST['username'] != '') { $message = 'Wrong username or password!'; } else { $message = 'Please login!'; } throw new Exception($message); } } catch (Exception $e) { if ($e->getMessage() != '') { $xmlMeta->addChild(new \Xily\Xml('message', $e->getMessage(), array('class' => 'alert alert-error'))); } $view = 'login'; } if ($view === 'login') { $returnUrl = HTTP::readGET('return', ''); if (!Form::verify('loginreturn', Form::METHOD_GET)) { $returnUrl = ''; } $xmlMeta->addChildren(array(new \Xily\Xml('tokenName', Form::getTokenName()), new \Xily\Xml('tokenValue', Form::getToken('login')), new \Xily\Xml('return', empty($returnUrl) ? $_SERVER['SCRIPT_URI'] : $returnUrl))); } // Check if there is a controller for the view if (file_exists(CONTROLLER_DIR . $view . '.php')) { include_once CONTROLLER_DIR . $view . '.php'; } $controllerClass = ucfirst($view) . 'Controller';