"Packing" a Dataface Records object

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

"Packing" a Dataface Records object

Postby gthorne » Thu Aug 09, 2012 3:29 pm

So, I'm moving along on my custom dashboard page. I have some data normalized across a few tables, so I went from this:

Code: Select all
$events = df_get_records_array('calendar', array());
df_display(array('events'=>$events), 'dashboard.html');


To this:

Code: Select all
$result = mysql_query ("SELECT `event_start_time` , `event_end_time` , `short_desc` , maint_types.description AS maint_type, vendors.vendor_name AS vendor_name, ".
   "`trouble_ticket_number` , personnel.personnel_name AS assigned_to, `city` , states.postal_abbr AS state, `notes` , `submitted_by` , `submitted_date` ".
   "FROM `calendar` ".
   "LEFT JOIN maint_types ON ( calendar.type_id = maint_types.type_id ) ".
   "LEFT JOIN personnel ON ( calendar.assigned_to_id = personnel.personnel_id ) ".
   "LEFT JOIN states ON ( calendar.state_id = states.state_id ) ".
   "LEFT JOIN vendors ON ( calendar.vendor_id = vendors.vendor_id )", $app->db());

while ($row = mysql_fetch_assoc($result))
{
   $events[] = $row;
}

df_display(array('events'=>$events), 'dashboard.html');


But now, it's no longer a DF Recordset object, so member functions like 'getURL' don't work anymore. Am I going about this the right way? Is there a way to just 'pack' the recordset object with my array once I get it? Or am I missing out on some DF function that is equivalent to mysql_query but returns a Recordset?

Thanks again.
gthorne
 
Posts: 32
Joined: Tue Jul 17, 2012 2:47 pm

Re: "Packing" a Dataface Records object

Postby shannah » Thu Aug 09, 2012 3:35 pm

Code: Select all
$evt = new Dataface_Record('calendar', $row);
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: "Packing" a Dataface Records object

Postby shannah » Thu Aug 09, 2012 3:36 pm

Although, this object will only have the values that are in $row... You need at least the primary key to be in there for things like getURL() to work correctly.
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: "Packing" a Dataface Records object

Postby gthorne » Thu Aug 09, 2012 4:18 pm

So a Dataface_Record is just a single row?


Code: Select all
while ($row = mysql_fetch_assoc($result))
{
   $evt = new Dataface_Record('calendar', $row);
   $events[] = $evt;
}
gthorne
 
Posts: 32
Joined: Tue Jul 17, 2012 2:47 pm

Re: "Packing" a Dataface Records object

Postby shannah » Thu Aug 09, 2012 4:31 pm

Yes.
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: "Packing" a Dataface Records object

Postby gthorne » Thu Aug 09, 2012 5:01 pm

I guess I should've just tried it instead of asking. :)

One last issue. Now $evt->val('state') doesn't work in the {foreach} loop. The val() call works for all native fields, but not for the fields I got out of the JOIN. I'm not a Smarty expert, so this is probably something easy that I'm missing.
gthorne
 
Posts: 32
Joined: Tue Jul 17, 2012 2:47 pm

Re: "Packing" a Dataface Records object

Postby gthorne » Thu Aug 09, 2012 5:49 pm

Just verified that the _values array in the Dataface_Record object only has keys for the fields in the selected table.:

Code: Select all
id => 1
event_start_time => Array
event_end_time => Array
short_desc => Test event
city => Arlington
notes => Test event
submitted_by => Jon Smith
submitted_date => Array
type_id =>
vendor_id =>
assigned_to_id =>
state_id =>
gthorne
 
Posts: 32
Joined: Tue Jul 17, 2012 2:47 pm

Re: "Packing" a Dataface Records object

Postby shannah » Thu Aug 09, 2012 7:27 pm

Yes. It encapsulates a single row of the table specified in the first parameter of the constructor. val() only works for:
1. Fields of the table.
2. Grafted fields.
3. Calculated fields.
4. Transient Fields

Some of the values from your query you'll need to use directly from the $row result.
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 26 guests

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