Source for file case06_debug.php
Documentation is available at case06_debug.php
require_once 'XML/Query2XML.php';
require_once 'XML/Query2XML/Callback.php';
/**Static class that provides validation and parsing methods for
* It is static so that we can easyly call its methods from inside
* Query2XML using eval'd code.
/**Associative array of US postal state codes*/
public static $statePostalCodes = array (
'ALABAMA' => 'AL', 'ALASKA' => 'AK', 'AMERICAN SAMOA' => 'AS', 'ARIZONA' => 'AZ', 'ARKANSAS' => 'AR', 'CALIFORNIA' => 'CA',
'COLORADO' => 'CO', 'CONNECTICUT' => 'CT', 'DELAWARE' => 'DE', 'DISTRICT OF COLUMBIA' => 'DC', 'FEDERATED STATES OF MICRONESIA' => 'FM',
'FLORIDA' => 'FL', 'GEORGIA' => 'GA', 'GUAM' => 'GU', 'HAWAII' => 'HI', 'IDAHO' => 'ID', 'ILLINOIS' => 'IL', 'INDIANA' => 'IN',
'IOWA' => 'IA', 'KANSAS' => 'KS', 'KENTUCKY' => 'KY', 'LOUISIANA' => 'LA', 'MAINE' => 'ME', 'MARSHALL ISLANDS' => 'MH', 'MARYLAND' => 'MD',
'MASSACHUSETTS' => 'MA', 'MICHIGAN' => 'MI', 'MINNESOTA' => 'MN', 'MISSISSIPPI' => 'MS', 'MISSOURI' => 'MO', 'MONTANA' => 'MT',
'NEBRASKA' => 'NE', 'NEVADA' => 'NV', 'NEW HAMPSHIRE' => 'NH', 'NEW JERSEY' => 'NJ', 'NEW JESEY' => 'NJ', 'NEW MEXICO' => 'NM', 'NEW YORK' => 'NY',
'NORTH CAROLINA' => 'NC', 'NORTH DAKOTA' => 'ND', 'NORTHERN MARIANA ISLANDS' => 'MP', 'OHIO' => 'OH', 'OKLAHOMA' => 'OK', 'OREGON' => 'OR',
'PALAU' => 'PW', 'PENNSYLVANIA' => 'PA', 'PUERTO RICO' => 'PR', 'RHODE ISLAND' => 'RI', 'SOUTH CAROLINA' => 'SC', 'SOUTH DAKOTA' => 'SD',
'TENNESSEE' => 'TN', 'TEXAS' => 'TX', 'UTAH' => 'UT', 'VERMONT' => 'VT', 'VIRGIN ISLANDS' => 'VI', 'VIRGINIA' => 'VA', 'WASHINGTON' => 'WA',
'WEST VIRGINIA' => 'WV', 'WISCONSIN' => 'WI', 'WYOMING' => 'WY'
/**Translates a US state name into its two-letter postal code.
* If the translation fails, $state is returned unchanged
* @param $record The record
public static function getStatePostalCode ($record)
$state = $record["state"];
if (isset (self ::$statePostalCodes[$s])) {
return self ::$statePostalCodes[$s];
function summarize ($str, $limit=50 , $appendString= ' ...')
if (strlen ($str) > $limit) {
$str = substr($str, 0 , $limit - strlen($appendString)) . $appendString;
function summarizeComment ($record, $limit)
return self ::summarize ($record["comment"], $limit);
/**Command class that implements the command pattern.
* It implements the XML_Query2XML_Callback interface
* and therefore has to provide the public non-static
* method execute(array $record).
class UppercaseColumnCommand implements XML_Query2XML_Callback
public function __construct ($columnName)
$this->_columnName = $columnName;
public function execute (array $record)
return strtoupper ($record[$this->_columnName ]);
$debugLogger = Log ::factory ('file', 'case06.log', 'XML_Query2XML');
$query2xml->enableDebugLog ($debugLogger);
$query2xml->startProfiling ();
$dom = $query2xml->getXML (
manager.employeeid AS manager_employeeid,
manager.employeename AS manager_employeename,
department_head.employeeid AS department_head_employeeid,
department_head.employeename AS department_head_employeename,
(SELECT COUNT(*) FROM sale WHERE sale.store_id = s.storeid) AS store_sales,
sale, employee, employee_department
sale.employee_id = employee.employeeid
employee_department.employee_id = employee.employeeid
employee_department.department_id = d.departmentid
employee, employee_department, department
employee_department.employee_id = employee.employeeid
employee_department.department_id = department.departmentid
department.store_id = s.storeid
employee, employee_department
employee_department.employee_id = employee.employeeid
employee_department.department_id = d.departmentid
) AS department_employees
LEFT JOIN employee manager ON s.manager = manager.employeeid
LEFT JOIN department d ON d.store_id = s.storeid
LEFT JOIN employee department_head ON department_head.employeeid = d.department_head
LEFT JOIN employee_department ed ON ed.department_id = d.departmentid
LEFT JOIN employee e ON e.employeeid = ed.employee_id
LEFT JOIN sale sa ON sa.employee_id = e.employeeid
LEFT JOIN customer c ON c.customerid = sa.customer_id
LEFT JOIN album al ON al.albumid = sa.album_id
LEFT JOIN artist ar ON ar.artistid = al.artist_id
department_head.employeeid,
'rootTag' => 'music_company',
'idColumn' => 'manager_employeeid',
'state' => '#Helper::getStatePostalCode()',
'city' => new UppercaseColumnCommand ('city'),
'idColumn' => 'departmentid',
'department_head' => array (
'idColumn' => 'department_head_employeeid',
'department_head_employeeid'
'department_head_employeename'
'rootTag' => 'employees',
'idColumn' => 'employeeid',
'idColumn' => 'customerid',
'comment' => '?#Helper::summarizeComment(12)',
'idColumn' => 'artistid',
$root = $dom->firstChild;
$root->setAttribute ('date_generated', '2005-08-23T14:52:50');
header('Content-Type: application/xml');
$dom->formatOutput = true;
$fp->write ('case06.profile', $query2xml->getProfile (), FILE_MODE_WRITE );
Documentation generated on Mon, 11 Mar 2019 15:43:31 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|