Page 1 of 1

"Packing" a Dataface Records object

PostPosted: Thu Aug 09, 2012 3:29 pm
by gthorne
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.

Re: "Packing" a Dataface Records object

PostPosted: Thu Aug 09, 2012 3:35 pm
by shannah
Code: Select all
$evt = new Dataface_Record('calendar', $row);

Re: "Packing" a Dataface Records object

PostPosted: Thu Aug 09, 2012 3:36 pm
by shannah
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.

Re: "Packing" a Dataface Records object

PostPosted: Thu Aug 09, 2012 4:18 pm
by gthorne
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;
}

Re: "Packing" a Dataface Records object

PostPosted: Thu Aug 09, 2012 4:31 pm
by shannah
Yes.

Re: "Packing" a Dataface Records object

PostPosted: Thu Aug 09, 2012 5:01 pm
by gthorne
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.

Re: "Packing" a Dataface Records object

PostPosted: Thu Aug 09, 2012 5:49 pm
by gthorne
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 =>

Re: "Packing" a Dataface Records object

PostPosted: Thu Aug 09, 2012 7:27 pm
by shannah
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.