Jump to content

Directory


Adam

Recommended Posts

I've got a somewhat complicated project going on and I'm not quite sure which way to go with it.

 

This project is a directory that lists a whole bunch of people, each with a photo, name and contact info. The page has a header and footer, and then room for six directory entries.

 

So, I'm using a template page and FPRepeatableComponent. This works great for one record, but I need to get six records on this page. I know I need to run my function 6 times, but it will just use the same record 6 times.

 

How do I get it to use the next record. Do I need to use an external data file instead of an input file? My code is below.

 

Thanks,

Adam

 

// Initialize the output variable
output = "";

output += dir_listing();
output += dir_listing();
output += dir_listing();
output += dir_listing();
output += dir_listing();
output += dir_listing();

// Return the output string
return output;

// this function builds a listing
function dir_listing() {
   // create the object using the template
   listing = new FPRepeatableComponent("1-slot");

   // populate the object with variables
   listing.AddGraphic("photo", Rule("Photo"));
   listing.AddTextVar("name", Trim(Field("FirstName")) + " " + Trim(Field("LastName")) + ", " + Trim(Field("Degree")));
   listing.AddTextVar("address", Trim(Field("Primary Practice Address")));
   listing.AddTextVar("csz", Trim(Field("City")) + ", WI " + Trim(Field("Zip")));
   listing.AddTextVar("phone", Rule("Formatted Phone"));
   listing.AddTextVar("fax", Rule("Formatted Fax"));

   // return the object, which will be added to the output string
   return listing;
}

Link to comment
Share on other sites

No help here. I guess I'm going to have to bite the bullet and just do this with InDesign.

 

I guess I just assumed that something like this could be done with FP. But, now that I look at the manual again, the repeatable template example doesn't use any variable data.

Link to comment
Share on other sites

Yes, I am answering my own post again. Got it figured out. Here was the situation: a directory of doctors - photo, name, address, phone, fax, etc., 6 to a page. This was complicated by the fact that some doctors had multiple addresses (as many as 6), each address was its own record. But, they only wanted the photo and name once, and all of the addresses were to appear together as part of a single listing. Also, some doctors had no photo, in which case we were to substitute a screened logo.

 

So, here's what I wound up with:

 

  • 1 main page
  • 1 overflow page (same as the main page)
  • 6 template pages (one for a doctor with a single address, one for a doctor with two addresses, etc.)
  • No main data file, just an external one
  • One long rule - which I've pasted in at the end of this post

I still have two more tasks, though, and I'm hoping Dan or one of the other gurus can help.

 

  1. These doctors are sorted by specialty (Cardiology, for example), and there are 3-6 doctors per page. The customer wants a heading at the top of the page that shows the specialty of the first doctor on the page. Is there a way to, in my main rule, determine when we've flowed onto a new page, then set a variable that could be used in another text box?
  2. I also need to number the pages, but I need to change the starting page number. I can't seem to use the $pagenum variable in any of my rules.

 

// Initialize the output variable
$output = '';

// Initialize data row counter at 1 (row 0 is the headers)
$data_ctr = 1;

// Initialize the add'l addresses counter
$addl_addresses = 0;

// Load external data
$data = new ExternalDataFileEx('Processed Phone List.csv', ',');

// Get field names
$fields = get_field_names();

// Loop through the data file
while ($data_ctr <= $data.recordCount) {
   // Is the current row an additional address?
   if ($data.GetFieldValue($data_ctr, 'Alt Address') == 'Y') {
       $addl_addresses++;
       $cur['add' + $addl_addresses] = row_to_a($data_ctr);
   } else {
       // If $cur exists, it's the previous listing, so process it,
       // reinitialize the variable
       if (typeof($cur) != 'undefined') {
           $output += dir_listing($cur, $addl_addresses);
           $cur = '';
       }
       // Load the new row and reset the add'l address counter
       $cur = row_to_a($data_ctr);
       $addl_addresses = 0;
   }
   // In either case, increment the counter
   $data_ctr++;
}

// Process the last listing
$output += dir_listing($cur, $addl_addresses);

// Return the output string
return $output;

// Functions --------------------------------------------------------------

// Function builds a directory listing
function dir_listing(record, addl_addresses) {
   // Create the template object using the appropriate template    
   var listing = new FPRepeatableComponent(addl_addresses + 1 + '-slot');

   // Populate the object with variables
   listing.AddGraphic('photo', dir_photo(Trim(record['LastName']) + "=" + Trim(record['FirstName']) + '.tif'));
   listing.AddTextVar('name', Trim(record['FirstName']) + ' ' + Trim(record['LastName']) + ', ' + Trim(record['Degree']));
   listing.AddTextVar('add0', Trim(record['Primary Practice Address']));
   listing.AddTextVar('csz0', Trim(record['City']) + ', WI ' + Trim(record['Zip']));
   listing.AddTextVar('phone0', dir_phone(record['Phone Number']));
   if (record['Fax Number'] != '') {
       listing.AddTextVar('fax0', 'Fax ' + dir_phone(record['Fax Number']));
   } else {
       listing.AddTextVar('fax0', '');
   }

   // Add more if ther are additional addresses
   if (addl_addresses > 0) {
       for (i = 1; i <= addl_addresses; i++) {
           listing.AddTextVar('add' + i, Trim(record['add' + i]['Primary Practice Address']));
           listing.AddTextVar('csz' + i, Trim(record['add' + i]['City']) + ', WI ' + Trim(record['Zip']));
           listing.AddTextVar('phone' + i, dir_phone(record['add' + i]['Phone Number']));
           if (record['add' + i]['Fax Number'] != '') {
               listing.AddTextVar('fax' + i, 'Fax ' + dir_phone(record['add' + i]['Fax Number']));
           } else {
               listing.AddTextVar('fax' + i, '');
           }
       }
   }
   return listing;
}

// Function returns the first row as an indexed array
// Utilizes the data file ($data)
function get_field_names() {
   var fields = []
   for (i = 0; i < $data.fieldCount; i++) {
       fields.push($data.GetFieldValue(0, i));
   }
   return fields;
}

// Function turns a row of data into an associative array
// Utilizes the data file ($data) and the field names array ($fields)
function row_to_a(row) {
   var row_a = [];
   for (i = 0; i < $data.fieldCount; i++) {
       row_a[$fields[i]] = $data.GetFieldValue(row, i);
   }
   return row_a;
}

// Function returns a photo, or the Tau symbol along with a warning if the photo is not found
// The Tau symbol should already be defined as a resource
function dir_photo(filename) {
   // Specify the directory where the photos are
   var path = "Photos/";

   // Build the file name and create a resource
   var photo = CreateResource(path + filename, "graphic", true);

   // Return the appropriate graphic
   if (photo.exists) {
       return photo;
   } else {
   ReportWarning('No photo named "' + filename + '" was found.');
       return Resource("Tau_12% K.eps");
   }
}

// Function returns a formatted phone or fax number
function dir_phone(data) {
 // omitted this - it's just a slightly modified version of the format phone number rule that comes with FP.
}

Link to comment
Share on other sites

Thanks for replying to your own dilemma with your solution -- if I could give you a rep point on this forum I would! I may proclaim myself as a prepress guru, but JS guru I am not, and this is a lot to chew on when I can find the time to work through it. In the absence of a good example in the official documentation, I'll be glad to have this in it's place. (Sorry for not having an answer to either of your two questions in this post.)
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...