FileFactory.php
Go to the documentation of this file.
00001 <?PHP 00002 00003 # 00004 # FILE: FileFactory.php 00005 # 00006 # Part of the Collection Workflow Integration System 00007 # Copyright 2007-2009 Edward Almasy and Internet Scout 00008 # http://scout.wisc.edu 00009 # 00010 00014 class FileFactory extends ItemFactory { 00015 00016 # ---- PUBLIC INTERFACE -------------------------------------------------- 00017 00018 # object constructor 00019 function FileFactory($FieldId = NULL) 00020 { 00021 # set up item factory base class 00022 $this->ItemFactory("File", "Files", "FileId", "FileName", $FieldId); 00023 } 00024 00025 # retrieve all files (names or objects) for specified resource 00026 # (array index is file IDs) 00027 function GetFilesForResource($ResourceOrResourceId, $ReturnObjects = TRUE) 00028 { 00029 # start out assuming that no files will be found 00030 $ReturnValue = array(); 00031 00032 # sanitize resource ID or grab it from object 00033 $ResourceOrResourceId = is_object($ResourceOrResourceId) 00034 ? $ResourceOrResourceId->Id() : intval($ResourceOrResourceId); 00035 00036 # retrieve names and IDs of files associated with resource 00037 $this->DB->Query( 00038 "SELECT FileId, FileName FROM Files" 00039 ." WHERE ResourceId = ".$ResourceOrResourceId 00040 ." AND FieldId" 00041 .($this->FieldId ? "=".$this->FieldId : ">0")); 00042 $FileNames = $this->DB->FetchColumn("FileName", "FileId"); 00043 00044 # if files were found 00045 if (count($FileNames)) 00046 { 00047 # if caller asked us to return objects 00048 if ($ReturnObjects) 00049 { 00050 # for each file 00051 foreach ($FileNames as $FileId => $FileName) 00052 { 00053 # create file object and add it to array 00054 $ReturnValue[$FileId] = new File($FileId); 00055 } 00056 } 00057 else 00058 { 00059 # return array of file names with IDs as index 00060 $ReturnValue = $FileNames; 00061 } 00062 } 00063 00064 # return resulting array of files or file names to caller 00065 return $ReturnValue; 00066 } 00067 00068 # create copy of File and return to caller 00069 function Copy($FileToCopy) 00070 { 00071 return new File($FileToCopy->GetNameOfStoredFile(), 00072 $FileToCopy->ResourceId(), 00073 $FileToCopy->FieldId(), 00074 $FileToCopy->Name()); 00075 } 00076 00077 00078 # ---- PRIVATE INTERFACE ------------------------------------------------- 00079 00080 } 00081 00082 00083 ?>