ok, i think it's best if i answer your post in reverse order.
Who handles unpacking the data and wrapping it in HTML tags? Is that part not on your diagram?
that is taken care of in the outputter. Basically, flow would be like this:
-the Manager would take in id variable (this id is set in the nav on the html page)
-the Manager then calls the either the Outputter factory, or the RecordHandlerFactory, and instansiates the correct object based on the id that was passed in.
Here is how the SiteManager looks. i took out some of hte methods, but the other ones look very similar to these:
PHP Code:
<?php
class SiteManager{
function SiteManager(){}
function doConnect($host, $user, $pass, $db){
$conn = mysql_pconnect ($host, $user, $pass);
if (!$conn){
echo 'Error connecting to db'.'<br>';
}
//select the right database to use
$db = mysql_select_db($db);
if (!$db){
echo 'Error selecting database'.'<br>';
}
}
function getDynamicContent($cat, $sortBy, $sortDirection, $limit){
require_once("outputters/DynamicContentFactory.php");
$outputter = DynamicContentFactory::getDynamicOutputter($cat);
$content = $outputter->getContent($sortBy, $sortDirection, $limit);
return $content;
}
function insertNewRecord($section, $withFile){
//the $withFile parameter is letting us know there is a file to upload as well
require_once("record_handlers/RecordHandlerFactory.php");
$recordHandler = RecordHandlerFactory::getRecordHandler($section, $withFile) or die('Error Getting Record Handler');
$res = $recordHandler->insertRecord();
if ($res){
$message = 'Record inserted successfully.';
}else{
$message = 'Error inserting record.';
}
$this->onRecordResult($message);
}
}
Now, the outputter gets created in the getDynamicContent() method autmatically gets composed with its corresponding RecordHandler...so for the News_Ouputter object, it gets composed with a News_RecordHandler on creation. I have a different *_Outputter and *_RecordHandler for each section.
So, when I call $outputter->getContent(), the $outputter calls a method on it's RecordHandler. The record handler retireves the records from it's assigned table(each table in the database also has the corresponding id for each section...so there is a site_news table, site_about table, etc.) and returns the results to the outputter. The outputter then formats the data and outputs that formatted data.. Here is how it looks in the News_Outputter:
PHP Code:
function getContent($sortBy, $sortDirection, $limit){
$rh = $this->recHandler;
$res = $rh->getAllFromTable($sortBy, $sortDirection, $limit);
$this->outString = "";
while($row = mysql_fetch_array($res) ){
$newsDate = $row['date'];
$blurb = $row['blurb'];
$this->outString .= '<p><div class="date">'. $newsDate . '</div>';
$this->outString .= $blurb;
$this->outString .= "<br /><br />";
}
return $this->outString;
}
The your manager class has to have this capability upgraded for every new view and record set.
Hmm..how so? All the names of my classes correspond to the id being passed in...it just takes the id and asks the factory for the right object. Here's what the entire factory looks like:
PHP Code:
<?php
require_once("DynamicContentOutputter.php");
class DynamicContentFactory{
function DynamicContentFactory(){}
function getDynamicOutputter($id){
$id = strtoupper($id);
$classFile = "{$id}_Outputter.php";
$class = $id.'_Outputter';
require_once( $classFile );
return new $class($withImage);
}
}
The View should not know it is writing to a web page or an e-mail or whatever.
ok, i thought i was following along but now i'm really confused. How could the View NOT know what it's writing to? I would think it would need to call very different methods for printing to an html page than printing to an rss feed?
Bookmarks