Search:

# CWIS Developers Documentation

- Main Page
- Classes
- Files

- Search for |

- File List
- File Members

# 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("SELECT FileId, FileName FROM Files"
    00038                 ." WHERE ResourceId = ".$ResourceOrResourceId
    00039                         .($this->FieldId ? " AND FieldId = ".$this->FieldId : ""));
    00040         $FileNames = $this->DB->FetchColumn("FileName", "FileId");
    00041
    00042         # if files were found
    00043         if (count($FileNames))
    00044         {
    00045             # if caller asked us to return objects
    00046             if ($ReturnObjects)
    00047             {
    00048                 # for each file
    00049                 foreach ($FileNames as $FileId => $FileName)
    00050                 {
    00051                     # create file object and add it to array
    00052                     $ReturnValue[$FileId] = new File($FileId);
    00053                 }
    00054             }
    00055             else
    00056             {
    00057                 # return array of file names with IDs as index
    00058                 $ReturnValue = $FileNames;
    00059             }
    00060         }
    00061
    00062         # return resulting array of files or file names to caller
    00063         return $ReturnValue;
    00064     }
    00065
    00066     # create copy of File and return to caller
    00067     function Copy($FileToCopy)
    00068     {
    00069         return new File($FileToCopy->GetNameOfStoredFile(),
    00070                 $FileToCopy->ResourceId(),
    00071                 $FileToCopy->FieldId(),
    00072                 $FileToCopy->Name());
    00073     }
    00074
    00075
    00076     # ---- PRIVATE INTERFACE -------------------------------------------------
    00077
    00078 }
    00079
    00080
    00081 ?>

Copyright 2009 Internet Scout