Echo details from another section??
36 posts by 5 authors in: Forums > CMS Builder
Last Post: May 31, 2010 (RSS)
By gkornbluth - March 1, 2010
I'm about to create an "Address Book" implementation based on the above, so that various fields from a "venue address book" section (Venue name, address, map URL, Driving Directions, Contact info, etc.) can automatically be displayed on an event detail page along with specific event information. (Some of the fields will have to be displayed on the list page as well)
Are there any changes that you'd recommend to the above approach based on the new "Related Records" functionality in V2.03?
Thanks,
Jerry Kornbluth
Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php
Re: [gkornbluth] Echo details from another section??
By Chris - March 1, 2010
For now, the two approaches are entirely separate, so there won't be any changes needed. Please note that the plugin above is entirely beta and I'm hoping we can provide a much simpler interface in the near future.
Chris
By gkornbluth - March 1, 2010
Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php
By gkornbluth - March 2, 2010 - edited: March 2, 2010
I think I’m really close, but I’m missing something and could use some of your words of wisdom.
Here’s what I did.
I set up a multirecord editor called venue_address_book with fields like venue_name, venue_address, venue_contact_e_mail, venue_phone, etc.
Then I set up a multirecord editor called eblast_events_notice with a number of event related fields and one list field called "venue".
The field has the following parameters:
Field Label: Venue
Field Name: venue
Field Type: list
Field Options:
Display As: checkboxes (multi value)
List Options: Get options from database (advanced)
Section Tablename: venue_address_book
Use this field for option values: num
Use this field for option labels: venue_name
I uploaded and activated the later version of the Related Record Lookup Functions Plugin
I populated the venue_address_book with a few records and selected (checked) one in a record in the eblast_events_notice table.
Then I set up a detail viewer with the following get records code at the top.
<?php
require_once "/hsphere/local/home/apbcweb/artistsofpalmbeachcounty.org/cmsAdmin/lib/viewer_functions.php";
list($e_blast_events_noticeRecords, $e_blast_events_noticeMetaData) = getRecords(array(
'tableName' => 'e_blast_events_notice',
'where' => whereRecordNumberInUrl(1),
'limit' => '1',
));
$e_blast_events_noticeRecord = @$e_blast_events_noticeRecords[0]; // get first record
list($venue_address_bookRecords, $venue_address_bookMetaData) = getRecords(array(
'tableName' => 'venue_address_book',
));
beta_lookupRelatedFields(array(
'table' => 'venue_address_book',
'recordList' => &$venue_address_bookRecords,
'fieldList' => array( 'venue_name' )
));
// show error message if no matching record is found
if (!$e_blast_events_noticeRecord) {
header("HTTP/1.0 404 Not Found");
print "Record not found!";
exit;
}
?>
And this code in the body:
<?php if (empty($venue_address_bookRecord['venue_name'])): ?>
No Venue Information.
<?php else: ?>
Venue Information:
<ul>
<li>
<?php echo $venue_address_bookRecord['venue_name'] ?>
<?php echo $venue_address_bookRecord['venue_contact_e_mail'] ?>
<?php echo $venue_address_bookRecord['venue_phone'] ?>
</li>
</ul>
<?php endif ?>
When I try to bring up that record’s detail page a browser, I get the following error:
lookupRelatedFields: field 'venue_name' is not set to 'Get options from database (advanced)'
Thanks,
Jerry Kornbluth
Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php
Re: [gkornbluth] Echo details from another section??
By Chris - March 2, 2010 - edited: March 2, 2010
I think you'll want to change the fieldList you're passing to beta_lookupRelatedFields() from:
'fieldList' => array( 'venue_name' )
to match your list field:
'fieldList' => array( 'venue' )
Also, since you're using a "multi value" list field, in the body of you're page you'll need to use a foreach:
<?php foreach($venue_address_bookRecord['venue'] as $venue): ?>
<?php echo $venue['venue_name'] ?>
<?php endforeach ?>
I hope this helps (and works!) Please let me know if you have any questions.
Chris
By gkornbluth - March 2, 2010 - edited: March 2, 2010
Thanks for the quick response, but that didn't seem to work.
I now get the error:
Notice: Undefined index: venue in /hsphere/local/home/apbcweb/artistsofpalmbeachcounty.org/cmsAdmin/plugins/relatedRecordLookupFunctions.php on line 47 lookupRelatedFields: field 'venue' not found
Hope that sheds some light on the issue.Jerry
Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php
Re: [gkornbluth] Echo details from another section??
By Chris - March 3, 2010
After taking a closer look at your post, please ignore my last post. :)
lookupRelatedFields is meant to be used from the table with the list field. It does its own getRecords call on the foreign table. Try this instead:
beta_lookupRelatedFields(array(
'table' => 'e_blast_events_notice',
'recordList' => &$e_blast_events_noticeRecords,
'fieldList' => array( 'venue' )
));
Also, you can remove this:
list($venue_address_bookRecords, $venue_address_bookMetaData) = getRecords(array(
'tableName' => 'venue_address_book',
));
I think you'll also need to move this line down below the call to beta_lookupRelatedFields:
$e_blast_events_noticeRecord = @$e_blast_events_noticeRecords[0]; // get first record
Finally, you'll want this code in the body:
<?php if (empty($e_blast_events_noticeRecord['venue'])): ?>
No Venue Information.
<?php else: ?>
Venue Information:
<ul>
<?php foreach ($e_blast_events_noticeRecord['venue'] as $venue): ?>
<li>
<?php echo $venue['venue_name'] ?>
<?php echo $venue['venue_contact_e_mail'] ?>
<?php echo $venue['venue_phone'] ?>
</li>
<?php endforeach ?>
</ul>
<?php endif ?>
Does that work?
As you can see, this isn't quite ready for prime-time yet. ;)
Chris
By gkornbluth - March 6, 2010
The modifications that you suggested work perfectly.
However, the way the relatedRecordLookupFunctions plugin is set up it seems that it will only work with multi value lists.
Is there a possibility that it could be modified to work with either single or multi value lists.
That way we could use the list type of our choice for various applications?
Thanks,
Jerry
Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php
Re: [gkornbluth] Echo details from another section??
By Chris - March 8, 2010
It works with single value lists too, but the interface is slightly different. The plugin replaces the field with the associated record, instead of a list of records. For this reason, you wouldn't use foreach to loop over the records, but instead you could say: (if venue was a single value list field)
$venue = $e_blast_events_noticeRecord['venue'];
echo $venue['venue_name'];
or even:
echo $e_blast_events_noticeRecord['venue']['venue_name'];
This is, of course, subject to change. It may be simpler to just always provide records in a list. :)
Chris
By gkornbluth - March 8, 2010
I'll plug that in tomorrow.
Much appreciated,
Jerry
Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php