* @copyright 2001-2007 VIKO team and contributors * @license http://www.gnu.org/licenses/gpl.html GPL 2.0 */ /** * This abstract factory produces instances of File */ require_once 'File.php'; /** * This abstract factory produces instances of Folder */ require_once 'Folder.php'; /** * This abstract factory produces instances of Link */ require_once 'Link.php'; /** * Generates course materials: files, folders and links * */ class MaterialFactory { /** * Constructs a material object based on passed in parameters * * Allowed values for $type are: 'FILE', 'FOLDER' and 'LINK'. * * @static * @param string $type the type of the material to create * @param int $material_id the database ID of the material * @return Material instance */ function material( $type, $material_id=null ) { switch ( $type ) { case "FILE": return MaterialFactory::file( $material_id ); break; case "FOLDER": return MaterialFactory::folder( $material_id ); break; case "LINK": return MaterialFactory::link( $material_id ); break; default: trigger_error( "Unknown type '$type'.", E_USER_ERROR ); } } /** * Constructs a material object based on material_id * * @static * @param int $material_id the database ID of the material * @return mixed on success Material instance (if loading fails, false is returned) */ function materialByID( $material_id ) { $db = DBInstance::get(); $record = $db->getRow( "SELECT * FROM Materials WHERE material_id=?", array( $material_id ) ); if ( PEAR::isError( $record ) ) { trigger_error( $record->getMessage(), E_USER_ERROR ); } if ( isset($record) ) { $material = MaterialFactory::material( $record['material_type'], $record['material_id'] ); $material->readFromDatabaseRecord( $record ); return $material; } else { return false; } } /** * Returns file object * * @static * @return Material instance */ function file( $material_id=null ) { $file =& new File( $material_id ); return $file; } /** * Returns folder object * * @return Material instance */ function folder( $material_id=null ) { $folder =& new Folder( $material_id ); return $folder; } /** * Returns Link object * * @return Material instance */ function link( $material_id=null ) { $link =& new Link( $material_id ); return $link; } } ?>