I have recently created something similar for my office. I work at a university and we generate funding announcements on a regular basis. My approach involved creating an "Announcement" class which included a function generateAnnouncement() that took the data from the database and ran it through a template.
So my steps were as follows:
1) Query the database for all new announcements
2) For each new announcement, create an array of new Announcement objects to hold all its information.
3) Send each object in the array through the template, and save the file (in my case, I did it as an html).
I imagine you're quite capable of getting the data from the database, so here is the code I used for the templating:
PHP Code:
class Announcement {
//DECLARE VARIABLES
var $spnsr_id; //sponsor ID
var $spnsr_name; //sponsor name
var $pgm_id; //program ID
var $pgm_name; //program name
var $pgm_type;
var $pgm_description; //program description
var $pgm_contact; //program contact
var $cmp_id; //competition ID
var $cmp_guideline_url; //competition URL
var $cmp_name; //competition name
var $cmp_awrd_range; //value of the award
var $cmp_open_dt; //is it an open-ended date?
var $cmp_internal_dt; //internal deadline
var $cmp_dean_dt; //dean's deadline
var $cmp_agency_dt; //agency deadline
var $cmp_detail; //compeition description
var $cmp_admin_info; //application details
var $cmp_int_contact_nm; //RDS contact person's name
var $interest_descr = array(); //array of keywords
var $address = array(array()); //2D array of addresses
var $discipline = array(); //array of disciplines (based on sponsor)
var $url; //URL to link to back to PeopleSoft
//CONSTRUCTOR
function Announcement($spnsr_id, $spnsr_name, $pgm_id, $pgm_name, $pgm_type, $pgm_description, $pgm_contact, $cmp_id, $cmp_guideline_url, $cmp_name, $cmp_awrd_range, $cmp_open_dt, $cmp_internal_dt, $cmp_dean_dt, $cmp_agency_dt, $cmp_detail, $cmp_admin_info, $cmp_int_contact_nm, $interest_descr, $address, $discipline, $url) {
$this->spnsr_id = $spnsr_id;
$this->spnsr_name = $spnsr_name;
$this->pgm_id = $pgm_id;
$this->pgm_name = $pgm_name;
$this->pgm_type = $pgm_type;
$this->pgm_description = $pgm_description;
$this->pgm_contact = $pgm_contact;
$this->cmp_id = $cmp_id;
$this->cmp_guideline_url = $cmp_guideline_url;
$this->cmp_name = $cmp_name;
$this->cmp_awrd_range = $cmp_awrd_range;
$this->cmp_open_dt = $cmp_open_dt;
$this->cmp_internal_dt = $cmp_internal_dt;
$this->cmp_dean_dt = $cmp_dean_dt;
$this->cmp_agency_dt = $cmp_agency_dt;
$this->cmp_detail = $cmp_detail;
$this->cmp_admin_info = $cmp_admin_info;
$this->cmp_int_contact_nm = $cmp_int_contact_nm;
$this->interest_descr = $interest_descr;
$this->address = $address;
$this->discipline = $discipline;
$this->url = $url;
}
//GENERATES THE ANNOUNCEMENT USING THE TEMPLATE
function createAnnouncement($listingType) {
ob_start(); //turn on output buffering
require("templates/tmpAnnouncement.php"); //parse the file
$output = ob_get_contents(); //save its contents
ob_end_clean(); //clear the buffer and turn off buffering
//make the directory if its not available
if (!is_dir("generatedAnnouncements")) {
mkdir("generatedAnnouncements") or die("Cannot make directory");
}
if (!is_dir("generatedAnnouncements/".date("Y"))) {
mkdir("generatedAnnouncements/".date("Y")) or die("Cannot make directory");
}
if (!is_dir("generatedAnnouncements/".date("Y")."/".date("M"))) {
mkdir("generatedAnnouncements/".date("Y")."/".date("M")) or die("Cannot make directory");
}
if (!is_dir("generatedAnnouncements/".date("Y")."/".date("M")."/".$listingType)) {
mkdir("generatedAnnouncements/".date("Y")."/".date("M")."/".$listingType) or die("Cannot make directory");
}
//put the file in the right spot
$outputFile = fopen("generatedAnnouncements/".date("Y")."/".date("M")."/".$listingType."/".$this->spnsr_id."-".$this->pgm_id."-".$this->cmp_id.".html", "w"); //open the file
fwrite($outputFile, $output); //write the file
fclose($outputFile); //close the file
}
and then my template this this calls looks like this:
PHP Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>RDS Announcement</title>
</head>
<body>
<center>
<table width="650" border="2">
<tr><td>
<table width="650">
<tr>
<td width="160">
<img src="../../../../images/logo.gif" alt="Research Western" />
</td>
<td align="left">
<center><b>Funding Opportunites - Research</b><br />
Further details regarding this announcement can be found at:<br />
<a href="<?php echo (trim($this->cmp_guideline_url) != "" ? $this->cmp_guideline_url : "N/A"); ?>" target="_blank"><?php echo (trim($this->cmp_guideline_url) != "" ? $this->cmp_guideline_url : "N/A"); ?></a></center>
</td>
</tr>
<tr>
<td>
<b>Agency/Award:</b>
</td>
<td align="left">
<?php echo (trim($this->spnsr_name) != "" ? $this->spnsr_name." - " : "N/A"); ?> <?php echo (trim($this->pgm_name) != "" ? $this->pgm_name." - " : "N/A"); ?> <?php echo (trim($this->cmp_name) != "" ? $this->cmp_name : "N/A"); ?> </td>
</tr>
<tr>
<td>
<b>Website: </b>
</td>
<td align="left">
<a href="<?php echo (trim($this->cmp_guideline_url) != "" ? $this->cmp_guideline_url : "N/A"); ?>" target="_blank"><?php echo $this->cmp_guideline_url; ?></a> </td>
</tr>
<tr>
<td colspan="2">
<hr />
</td>
</tr>
<tr>
<td>
<b>Grant Amount:</b>
</td>
<td align="left">
<?php echo (trim($this->cmp_award_range) != "" ? $this->cmp_award_range : "N/A"); ?> </td>
</tr>
<tr>
<td>
<b>Deadline:</b>
</td>
<td align="left">
<?php echo (trim($this->cmp_open_dt) == "Yes" ? "Deadline is Open<br />" : ""); ?>
<?php echo (trim($this->cmp_internal_dt) != "" ? "Internal: ".$this->cmp_internal_dt."<br />" : ""); ?>
<?php echo (trim($this->cmp_dean_dt) != "" ? "Dean's: ".$this->cmp_dean_dt."<br />" : ""); ?>
<?php echo (trim($this->cmp_agency_dt) != "" ? "Agency: ".$this->cmp_agency_dt."<br />" : ""); ?>
</td>
</tr>
<tr>
<td colspan="2">
<hr />
</td>
</tr>
<tr>
<td>
<b>Subject Areas:</b>
</td>
<td align="left">
<?php
for ($x = 0; $x < count($this->interest_descr); $x++) {
echo (trim($this->interest_descr[$x]) != "" ? $this->interest_descr[$x]." <br />" : "");
}
?> </td>
</tr>
<tr>
<td>
<b>Description:</b>
</td>
<td align="left">
<?php echo (trim($this->pgm_description) != "" ? $this->pgm_description : "N/A"); ?><br />
<?php echo (trim($this->cmp_detail) != "" ? $this->cmp_detail : "N/A"); ?>
</td>
</tr>
<tr>
<td colspan="2">
<hr />
</td>
</tr>
<tr>
<td>
<b>Application Details:</b>
</td>
<td align="left">
<?php echo (trim($this->cmp_admin_info) != "" ? $this->cmp_admin_info : "N/A"); ?> </td>
</tr>
<tr>
<td colspan="2" align="left">
<b>NOTE:</b> Letters of Intent and Full Applications are to be processed through Research Development Services for institutional signatures, and are to be accompanied by a completed RDAF form (bearing applicant, Chair and Dean signatures). Requests for Institutional signatures should be received no less than 3 days prior to the posted Agency deadline. </td>
</tr>
<tr>
<td>
<b>Western Contacts:</b>
</td>
<td align="left">
<?php echo (trim($this->cmp_int_contact_nm) != "" ? $this->cmp_int_contact_nm : "N/A"); ?> </td>
</tr>
<tr>
<td colspan="2">
<hr />
</td>
</tr>
<tr>
<td>
<b>Agency Contacts:</b>
</td>
<td align="left">
<?php echo (trim($this->pgm_contact) != "" ? $this->pgm_contact : "N/A"); ?><br />
<?php
//the array of addresses
for ($x = 0; $x < count($this->address); $x++) {
echo (trim($this->address[$this->numAddresses][spnsr_addr_descr]) != "" ? $this->address[$this->numAddresses][spnsr_addr_descr]." <br />" : "");
echo (trim($this->address[$this->numAddresses][spnsr_addr1]) != "" ? $this->address[$this->numAddresses][spnsr_addr1]." <br />" : "");
echo (trim($this->address[$this->numAddresses][spnsr_addr2]) != "" ? $this->address[$this->numAddresses][spnsr_addr2]." <br />" : "");
echo (trim($this->address[$this->numAddresses][spnsr_addr3]) != "" ? $this->address[$this->numAddresses][spnsr_addr3]." <br />" : "");
echo (trim($this->address[$this->numAddresses][spnsr_addr4]) != "" ? $this->address[$this->numAddresses][spnsr_addr4]." <br />" : "");
echo (trim($this->address[$this->numAddresses][spnsr_city]) != "" ? $this->address[$this->numAddresses][spnsr_city].", " : "");
echo (trim($this->address[$this->numAddresses][spnsr_state]) != "" ? $this->address[$this->numAddresses][spnsr_state].", " : "");
echo (trim($this->address[$this->numAddresses][spnsr_country_descr]) != "" ? $this->address[$this->numAddresses][spnsr_country_descr]." <br />" : "");
echo (trim($this->address[$this->numAddresses][spnsr_postal_cd]) != "" ? $this->address[$this->numAddresses][spnsr_postal_cd]." <br />" : "");
echo (trim($this->address[$this->numAddresses][spnsr_prefix]) != "" ? "Tel: ".$this->address[$this->numAddresses][spnsr_prefix]."-" : "");
echo (trim($this->address[$this->numAddresses][spnsr_phone]) != "" ? $this->address[$this->numAddresses][spnsr_phone]." " : "");
echo (trim($this->address[$this->numAddresses][spnsr_ext]) != "" ? "ext ".$this->address[$this->numAddresses][spnsr_ext]." <br />" : "");
echo (trim($this->address[$this->numAddresses][spnsr_fax]) != "" ? "Fax: ".$this->address[$this->numAddresses][spnsr_fax]." <br />" : "");
}
?>
</td>
</tr>
</table>
</td></tr>
</table>
</center>
</body>
</html>
Hope this helps.
Bookmarks