printable_report modification

A place for users and developers of the Xataface to discuss and receive support.

printable_report modification

Postby manifold » Mon Aug 08, 2011 5:26 am

Hello all,

This may be a simple one, but I can't figure it out...

I'm using the printable_report. However, I've modified the class actions_printable_report file so as to have a series of if/elseif statements; my goal is to print out a simple, different report depending on which table is creating the data. Thus, on my 'depts' page, some fields from my fire departments table is accessed and printed; but on the 'apparatus' page, some fields from my fire apparatus table is accessed and printed.

I believe that this line in the actions.ini file is the one to mod:

condition="query['-table'] == 'depts' "

Rather than specifying a single table, I'd like to specify the current table from which the information is generated. Here is how I've written up the
action:

if ( $query['-table'] = 'apparatus' ){
$apparatus = df_get_records_array('apparatus', $query);
foreach ($apparatus as $p){


echo '<table>'
.'<tr><th>Department</th><td>'.$p->htmlValue('fdname').'</td></tr>'
.'<tr><th>Designation</th><td>'.$p->htmlValue('designation').'</td></tr>'
.'<tr><th>NIMS Resource</th><td>'.$p->htmlValue('resource').'</td></tr>'
.'<tr><th>Availability</th><td>'.$p->htmlValue('status').'</td></tr>'
.'</table>';
}
}
elseif ( $query['-table'] = 'depts' ){
$depts = df_get_records_array('depts', $query);
foreach ($depts as $p){


echo '<table>'
.'<tr><th>Department</th><td>'.$p->htmlValue('fdname').'</td></tr>'
.'<tr><th>City</th><td>'.$p->htmlValue('city').'</td></tr>'
.'<tr><th>State</th><td>'.$p->htmlValue('state').'</td></tr>'
.'<tr><th>Type</th><td>'.$p->htmlValue('type').'</td></tr>'
.'</table>';
}
}

... and so on.

Initially, all that would get printed would be the information from the first table referenced, since its existence was 'true'.

I've tried replacing the single element assignment in the actions.ini file (condition="query['-table'] == 'depts' ") with a multiple elements like so:

condition="query['-table'] == 'apparatus', 'depts', 'gis', 'nims', 'workorders', 'users' " ... but this doesn't work.

With this change, even the printer icon vanishes, and I can print nothing.

So, I need to find a way to indicate 'current table' rather than hard-code a specific table in the actions.ini file... or do something else?

I'd appreciate any suggestions!

TYIA,
-manifold
"Heisenberg may have slept here."

"I'm positive I've lost an electron...."
manifold
 
Posts: 31
Joined: Wed Jun 29, 2011 8:49 am

Re: printable_report modification

Postby shannah » Mon Aug 08, 2011 9:16 am

Code: Select all
condition="in_array(query['-table'], array( 'apparatus', 'depts', 'gis', 'nims', 'workorders', 'users')) "
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: printable_report modification

Postby manifold » Tue Aug 09, 2011 8:11 pm

Thank you Steve for your response; I'm not sure how you manage to find the time to help out so many folks.

I did try this, and it fails in the same way: it prints the fields from the first table it finds in the array.

I think that I need to find a way to cycle through the elements of the tables array comparing them against the table that is the source of the fields/records to be printed.

Is this the right path to investigate? And if so, how to get the current table identified for the comparison against the array elements?

Thanks!
-manifold
"Heisenberg may have slept here."

"I'm positive I've lost an electron...."
manifold
 
Posts: 31
Joined: Wed Jun 29, 2011 8:49 am

Re: printable_report modification

Postby shannah » Wed Aug 10, 2011 9:34 am

I think I may not understand what you are trying to achieve. The condition statement in the actions.ini is a boolean expression that, when true, causes the action to be present - and when false, causes the action to not be present.

(There's a typo in all previous references to the condition directive. query['-table'] should be $query['-table'])
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: printable_report modification SOLVED

Postby manifold » Fri Aug 12, 2011 3:28 pm

Happily I found the problem: I was using an assignment operator (=) rather than the equality operator (==) when comparing the table name against the array elements.

The final code follows; this allows a separate report to be created for each table (using the printable_reports.php code). Thanks much Steve for your assist!
-manifold

<?php
class actions_printable_report {
function handle(&$params){
$app =& Dataface_Application::getInstance();
$query =& $app->getQuery();
$query['-skip'] = 0;
$query['-limit'] = 10000;

if ( $query['-table'] == 'apparatus' ){
$apparatus = df_get_records_array('apparatus', $query);
foreach ($apparatus as $p){


echo '<table>'
.'<tr><th>Department</th><td>'.$p->htmlValue('fdname').'</td></tr>'
.'<tr><th>Designation</th><td>'.$p->htmlValue('designation').'</td></tr>'
.'<tr><th>NIMS Resource</th><td>'.$p->htmlValue('resource').'</td></tr>'
.'<tr><th>Availability</th><td>'.$p->htmlValue('status').'</td></tr><br><hr/>'
.'</table>';
}
}
elseif ( $query['-table'] == 'depts' ){
$depts = df_get_records_array('depts', $query);
foreach ($depts as $p){


echo '<table>'
.'<tr><th>Department</th><td>'.$p->htmlValue('fdname').'</td></tr>'
.'<tr><th>City</th><td>'.$p->htmlValue('city').'</td></tr>'
.'<tr><th>State</th><td>'.$p->htmlValue('state').'</td></tr>'
.'<tr><th>Type</th><td>'.$p->htmlValue('type').'</td></tr><br><hr/>'
.'</table>';
}
}
elseif ( $query['-table'] == 'gis' ){
$gis = df_get_records_array('gis', $query);
foreach ($gis as $p){


echo '<table>'
.'<tr><th>Region</th><td>'.$p->htmlValue('locationtext').'</td></tr>'
.'<tr><th>Population</th><td>'.$p->htmlValue('population').'</td></tr>'
.'<tr><th>Housing Units</th><td>'.$p->htmlValue('housingunits').'</td></tr>'
.'<tr><th>Land Area</th><td>'.$p->htmlValue('landarea').'</td></tr><br><hr/>'
.'</table>';
}
}
elseif ( $query['-table'] == 'nims' ){
$nims = df_get_records_array('nims', $query);
foreach ($nims as $p){


echo '<table>'
.'<tr><th>NIMS Resource</th><td>'.$p->htmlValue('resource').'</td></tr>'
.'<tr><th>Description</th><td>'.$p->htmlValue('description').'</td></tr>'
.'<tr><th>Example</th><td>'.$p->htmlValue('example').'</td></tr><br><hr/>'
.'</table>';
}
}
elseif ( $query['-table'] == 'shops' ){
$shops = df_get_records_array('shops', $query);
foreach ($shops as $p){


echo '<table>'
.'<tr><th>Company</th><td>'.$p->htmlValue('name').'</td></tr>'
.'<tr><th>Category</th><td>'.$p->htmlValue('Category').'</td></tr>'
.'<tr><th>Territory</th><td>'.$p->htmlValue('Territory').'</td></tr>'
.'<tr><th>Web Site</th><td>'.$p->htmlValue('Website').'</td></tr><br><hr/>'
.'</table>';
}
}
elseif ( $query['-table'] == 'workorder' ){
$workorder = df_get_records_array('workorder', $query);
foreach ($workorder as $p){


echo '<table>'
.'<tr><th>Work Order Number</th><td>'.$p->htmlValue('reqid').'</td></tr>'
.'<tr><th>Vehicle</th><td>'.$p->htmlValue('vin').'</td></tr>'
.'<tr><th>Requisition Date</th><td>'.$p->htmlValue('reqdate').'</td></tr>'
.'<tr><th>Order Status</th><td>'.$p->htmlValue('orderstatus').'</td></tr><br><hr/>'
.'</table>';
}
}
elseif ( $query['-table'] == 'users' ){
$users = df_get_records_array('users', $query);
foreach ($users as $p){


echo '<table>'
.'<tr><th>User Name</th><td>'.$p->htmlValue('username').'</td></tr>'
.'<tr><th>Email</th><td>'.$p->htmlValue('email').'</td></tr>'
.'<tr><th>Role</th><td>'.$p->htmlValue('role').'</td></tr><br><hr/>'
.'</table>';
}
}
else return PEAR::raiseError('This action can only be called on a valid table.');
}

}
?>
"Heisenberg may have slept here."

"I'm positive I've lost an electron...."
manifold
 
Posts: 31
Joined: Wed Jun 29, 2011 8:49 am


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 23 guests

Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved