Location: PHPKode > projects > Emailr > common/BaseClasses.inc
<?

/**
 * This file contains classes that serve as base classes within Emailr.
 *
 * This file provides classes that serve as base classes within Emailr, housing common logic 
 * to reduce repeated code, error entry points, and cut down on development time.
 * @package Emailr
 * @subpackage Common
 * @author Jon Herron
 * @version 0.0.0.1
 * @since 02.24.2008
 */


require_once realpath(dirname(__file__) . "/../common/Environment.inc");
require_once realpath(dirname(__file__) . "/../common/dbconn.inc");

require_once "Config.php";
require_once "Log.php";
require_once "Logger.inc";

/**
 * Class used as the base class for most Emailr classes
 *
 * This class will serve as the base class for most Emailr classes, providing common logic for 
 * logging and configuration.
 * @author Jon Herron
 * @package Emailr
 * @subpackage Common
 * @version 0.0.0.1
 * @since 02.24.2008
 */
class EmailrBase
{
	/**
	 * Private data member to hold a reference to the logger.
	 * @access protected
	 * @var Logger
	 * @author Jon Herron
	 * @version 0.0.0.1
	 * @since 02.24.2008
	 */
	protected $_logger;

	/**
	 * Public constructor for Logger
	 *
	 * This public constructor will create a new instance of the Logger class.
	 * @access public
	 * @author Jon Herron
	 * @returns DirectoryBrowser class instance
	 * @version 0.0.0.1
	 * @since 02.24.2008
	 */
	public function EmailrBase()
	{
		// create a new logger
		$this->_logger = new Logger();

		$this->_logger->Info("Inside EmailrBase Constructor");
		$this->_logger->Info("Leaving EmailrBase Constructor");
	}
}

/**
 * Class used as the base class for Emailr Plugins
 *
 * This class will serve as the base class for emailr plugins, and contains logic for common functionality such as logging
 * @author Jon Herron
 * @package Emailr
 * @subpackage Common
 * @version 0.1
 * @since 03.09.2008
 */
class EmailrPluginBase extends EmailrBase
{
	/**
	 * Public constructor for EmailrPluginBase
	 *
	 * This public constructor will create a new instance of the EmailrPluginBase class.
	 * @access public
	 * @author Jon Herron
	 * @returns EmailrPluginBase class instance
	 * @version 0.1
	 * @since 03.09.2008
	 */
	public function EmailrPluginBase()
	{
		parent::EmailrBase();
		
		$this->_logger->Debug("Inside EmailrPluginBase");
		$this->_logger->Debug("Leaving EmailrPluginBase");
	}
	
	/**
	 * Protected method to return the contents of a given section
	 *
	 * This protected method will return the contents of a given section, using the section id to read the 
	 * appropriate file from the parsed folder.
	 * @access protected
	 * @author Jon Herron
	 * @returns string section contents
	 * @version 0.1.5
	 * @since 03.15.2008
	 */
	protected function GetSectionContents($sectionid)
	{
		$this->_logger->Debug("Inside GetSectionContents");
		
		$contents = file_get_contents(realpath(dirname(__file__)) . "/../parsed/$sectionid.emlr");
		
		$this->_logger->Debug("Leaving GetSectionContents");
		
		return($contents);
	}
	
	/**
	 * Protected method to return sections for the given mail id
	 *
	 * This protected method will return a listing of the sections that are available for the passed in mail id, 
	 * which will allow each plugin to parse the appropriate sections as they see fit.
	 * @access protected
	 * @author Jon Herron
	 * @returns array of section ids to section sub types
	 * @version 0.1.5
	 * @since 03.15.2008
	 */
	protected function GetSectionsForMailID($mailid)
	{
		$this->_logger->Debug("Inside GetSectionsForMailID, mailid is $mailid");
		
		$sections = array();
		
		// get the structures available for this mail id
		$sql = "SELECT `structureid`, `subtype` FROM `emailr_mailstructure` WHERE `mailid` = $mailid";
		
		$this->_logger->Debug("SQL is $sql");
		
		// get the sections for the mail id
		$result = mysql_query($sql, GetMyConnection());
		
		if($result)
		{
			while($row = mysql_fetch_row($result))
			{
				$structureid = $row[0];
				$subtype = $row[1];
				
				$sections["$structureid"] = $subtype;
				
				$this->_logger->Debug("Found: section id = $structureid, sub type = $subtype");
			}
		}
		else
		{
			$this->_logger->Error(mysql_error());
		}
		
		$this->_logger->Debug("Leaving GetSectionsForMailID, found " . count($sections) . " sections");
		
		return($sections);
	}
}

?>
Return current item: Emailr