global $lang; $id = (int) $id; $cat = new Categories($id); $info = $cat->findCategory(); $jobs = $cat->findAllCategoryJobs(); $app->response->headers->set('Content-Type', 'application/rss+xml;charset=utf-8'); $xml = new SimpleXMLElement('<rss version="2.0"></rss>'); $xml->addChild('channel'); $xml->channel->addChild('title', htmlentities(escapeXML($info->name)) . " " . $lang->t('jobs|jobs') . ' | ' . APP_NAME); $xml->channel->addChild('link', BASE_URL . "categories/{$info->id}/{$info->url}"); $xml->channel->addChild('description', htmlentities(escapeXML($info->description))); foreach ($jobs as $job) { $item = $xml->channel->addChild('item'); $item->addChild('title', htmlentities(escapeXML($job->title))); $item->addChild('link', BASE_URL . "jobs/{$job->id}/" . slugify($job->title . " {$lang->t('jobs|at')} " . $job->company_name)); $item->addChild('description', htmlentities(escapeXML($job->description))); $guid = $item->addChild('guid', $job->id . '@' . BASE_URL); $guid->addAttribute('isPermaLink', "false"); $item->addChild('pubDate', date(DATE_RSS, strtotime($job->created))); } $dom = new DOMDocument(); $dom->preserveWhiteSpace = false; $dom->formatOutput = true; $dom->loadXML(html_entity_decode($xml->asXML())); echo $dom->saveXML(); }); // get category jobs $app->get('/:id(/:name(/:page))', function ($id, $name = null, $page = 1) use($app) { global $lang; $id = (int) $id; $cat = new Categories($id);
/** * Does a normal print_r but outputs inside <pre> Elements with a optional class-Attribute. * * @param mixed $value The value to print out * @param string $preClass Optional class attribute value of generated pre HTML element * @return string * @uses \Beluga\mask_xml * @since v0.1 */ function print_h(string $value, string $preClass = null) { echo '<pre', !empty($preClass) ? " class=\"{$preClass}\">" : '>', escapeXML(\print_r($value, true)), '</pre>'; }
function getSalesByProdCatXML($intYear, $catId, $forDataURL) { // Function to connect to the DB $link = connectToDB(); $strSQL = "SELECT g.CategoryName,p.ProductName,ROUND(SUM(d.Quantity),0) as Quantity, ROUND(SUM(d.Quantity*p.UnitPrice),0) As Total FROM FC_Categories as g, FC_Products as p, FC_Orders as o, FC_OrderDetails as d WHERE year(o.OrderDate)=" . $intYear . " and g.CategoryID=" . $catId . " and d.ProductID=p.ProductID and g.CategoryID=p.CategoryID and o.OrderID=d.OrderID GROUP BY g.CategoryName,p.ProductName"; $result = mysql_query($strSQL) or die(mysql_error()); //Initialize <categories> element $strCat = "<categories>"; //Initialize datasets $strAmtDS = "<dataset seriesname='Revenue'>"; $strQtyDS = "<dataset seriesName='Quantity' parentYAxis='S'>"; //Iterate through each data row if ($result) { while ($ors = mysql_fetch_array($result)) { //Product Names are long - so show 8 characters and ... and show full thing in tooltip if (strlen($ors['ProductName']) > 8) { $shortName = escapeXML(substr($ors['ProductName'], 0, 8) . "...", $forDataURL); } else { $shortName = escapeXML($ors['ProductName'], $forDataURL); } $strCat .= "<category label='" . $shortName . "' toolText='" . escapeXML($ors['ProductName'], $forDataURL) . "'/>"; $strAmtDS .= "<set value='" . $ors['Total'] . "' />"; $strQtyDS .= "<set value='" . $ors['Quantity'] . "'/>"; } } mysql_close($link); //Closing elements $strCat .= "</categories>"; $strAmtDS .= "</dataset>"; $strQtyDS .= "</dataset>"; //Entire XML - concatenation $strXML = $strCat . $strAmtDS . $strQtyDS; return $strXML; }