Public Member Functions | Data Fields

ilObjFile Class Reference
[Modules/File]

Class ilObjFile. More...

Inheritance diagram for ilObjFile:
Collaboration diagram for ilObjFile:

Public Member Functions

 ilObjFile ($a_id=0, $a_call_by_reference=true)
 Constructor public.
 create ()
 create object
 createMetaData ()
 create file object meta data
 MDUpdateListener ($a_element)
 Meta data update listener.
 getDirectory ($a_version=0)
 createDirectory ()
 raiseUploadError ($a_raise=true)
 getUploadFile ($a_upload_file, $a_filename)
 replaceFile ($a_upload_file, $a_filename)
 replace file with new file
 copy ($a_source, $a_destination)
 copy file
 clearDataDirectory ()
 clear data directory
 read ()
 read file properties
 update ()
 update file
 updateMetaData ()
 update meta data
 setFileName ($a_name)
 set filename
 getFileName ()
 setFileType ($a_type)
 getFileType ()
 setFileSize ($a_size)
 getFileSize ()
 setVersion ($a_version)
 getVersion ()
 setMode ($a_mode)
 mode is object or filelist
 getMode ()
 mode is object or filelist
 _writeFileType ($a_id, $a_format)
 _lookupFileName ($a_id)
 _lookupFileSize ($a_id, $a_as_string=false)
 _lookupVersion ($a_id)
 lookup version
 sendFile ($a_hist_entry_id=null)
 ilClone ($a_parent_ref)
 ilClone object into tree basic clone function.
 delete ()
 delete file and all related data
 export ($a_target_dir)
 export files of object to target directory note: target directory must be the export target directory, "/objects/il_<inst>_file_<file_id>/..." will be appended to this directory
 _deleteAllUsages ($a_type, $a_id)
 static delete all usages of
 _saveUsage ($a_mob_id, $a_type, $a_id)
 save usage
 getUsages ()
 get all usages of file object
 _getFilesOfObject ($a_type, $a_id)
 get all files of an object
 getXMLZip ()

Data Fields

 $filename
 $filetype
 $filemaxsize = "20000000"
 $raise_upload_error
 $mode = "object"

Detailed Description

Class ilObjFile.

Author:
Sascha Hofmann <shofmann@databay.de>
Version:
Id:
class.ilObjFile.php 11692 2006-07-29 23:35:47Z akill

Definition at line 37 of file class.ilObjFile.php.


Member Function Documentation

ilObjFile::_deleteAllUsages ( a_type,
a_id 
)

static delete all usages of

Definition at line 548 of file class.ilObjFile.php.

References $q.

Referenced by ilPageObject::delete(), and ilPageObject::saveFileUsage().

        {
                $q = "DELETE FROM file_usage WHERE usage_type='$a_type' AND usage_id='$a_id'";
                $this->ilias->db->query($q);
        }

Here is the caller graph for this function:

ilObjFile::_getFilesOfObject ( a_type,
a_id 
)

get all files of an object

Parameters:
string $a_type object type (e.g. "lm:pg")
int $a_id object id
Returns:
array array of file ids

Definition at line 592 of file class.ilObjFile.php.

References $q.

Referenced by ilObjGlossary::exportHTMLGlossaryTerms(), ilObjContentObject::exportHTMLGlossaryTerms(), ilObjContentObject::exportHTMLPages(), and ilPageObject::update().

        {
                global $ilDB;

                // get usages in learning modules
                $q = "SELECT * FROM file_usage WHERE usage_id = ".$ilDB->quote($a_id).
                        " AND usage_type = ".$ilDB->quote($a_type);
                $file_set = $ilDB->query($q);
                $ret = array();
                while($file_rec = $file_set->fetchRow(DB_FETCHMODE_ASSOC))
                {
                        $ret[$file_rec["id"]] = $file_rec["id"];
                }

                return $ret;
        }

Here is the caller graph for this function:

ilObjFile::_lookupFileName ( a_id  ) 

Definition at line 363 of file class.ilObjFile.php.

References $q, $row, and ilUtil::stripSlashes().

        {
                global $ilDB;

                $q = "SELECT * FROM file_data WHERE file_id = '".$a_id."'";
                $r = $ilDB->query($q);
                $row = $r->fetchRow(DB_FETCHMODE_OBJECT);

                return ilUtil::stripSlashes($row->file_name);
        }

Here is the call graph for this function:

ilObjFile::_lookupFileSize ( a_id,
a_as_string = false 
)

Definition at line 375 of file class.ilObjFile.php.

Referenced by ilPageObject::addFileSizes(), and ilObjFileGUI::infoScreen().

        {
                include_once("classes/class.ilObjFileAccess.php");
                return ilObjFileAccess::_lookupFileSize($a_id, $a_as_string);
        }

Here is the caller graph for this function:

ilObjFile::_lookupVersion ( a_id  ) 

lookup version

Definition at line 384 of file class.ilObjFile.php.

        {
                include_once("classes/class.ilObjFileAccess.php");
                return ilObjFileAccess::_lookupVersion($a_id);
        }

ilObjFile::_saveUsage ( a_mob_id,
a_type,
a_id 
)

save usage

Definition at line 557 of file class.ilObjFile.php.

References $q.

Referenced by ilPageObject::saveFileUsage().

        {
                $q = "REPLACE INTO file_usage (id, usage_type, usage_id) VALUES".
                        " ('$a_mob_id', '$a_type', '$a_id')";
                $this->ilias->db->query($q);
        }

Here is the caller graph for this function:

ilObjFile::_writeFileType ( a_id,
a_format 
)

Definition at line 352 of file class.ilObjFile.php.

References $q.

Referenced by MDUpdateListener().

        {
                global $ilDB;
                
                $q = "UPDATE file_data SET ".
                        " file_type = ".$ilDB->quote($a_format).
                        " WHERE file_id = ".$ilDB->quote($a_id);
                $ilDB->query($q);
                
        }

Here is the caller graph for this function:

ilObjFile::clearDataDirectory (  ) 

clear data directory

Definition at line 210 of file class.ilObjFile.php.

References createDirectory(), ilUtil::delDir(), and getDirectory().

        {
                ilUtil::delDir($this->getDirectory());
                $this->createDirectory();
        }

Here is the call graph for this function:

ilObjFile::copy ( a_source,
a_destination 
)

copy file

Definition at line 202 of file class.ilObjFile.php.

References getDirectory().

        {
                return copy($a_source,$this->getDirectory()."/".$a_destination);
        }

Here is the call graph for this function:

ilObjFile::create (  ) 

create object

Reimplemented from ilObject.

Definition at line 62 of file class.ilObjFile.php.

References $q, ilHistory::_createEntry(), createMetaData(), getFileName(), ilObject::getId(), and getMode().

        {
                global $ilDB;
                
                parent::create();

                require_once("classes/class.ilHistory.php");
                ilHistory::_createEntry($this->getId(), "create", $this->getFileName().",1");

                $q = "INSERT INTO file_data (file_id,file_name,file_type,version,mode) "
                        ."VALUES ('".$this->getId()."','"
                        .ilUtil::prepareDBString($this->getFileName())."','"
                        .$this->getFileType()."','"
                        ."1"."',".$ilDB->quote($this->getMode()).")";
                $this->ilias->db->query($q);
                
                // no meta data handling for file list files
                if ($this->getMode() != "filelist")
                {
                        $this->createMetaData();
                }
        }

Here is the call graph for this function:

ilObjFile::createDirectory (  ) 

Definition at line 161 of file class.ilObjFile.php.

References getDirectory(), and ilUtil::makeDir().

Referenced by clearDataDirectory().

        {
                ilUtil::makeDir($this->getDirectory());
        }

Here is the call graph for this function:

Here is the caller graph for this function:

ilObjFile::createMetaData (  ) 

create file object meta data

Reimplemented from ilObject.

Definition at line 88 of file class.ilObjFile.php.

References getFileSize(), getFileType(), ilObject::getId(), and ilObject::getType().

Referenced by create().

        {
                parent::createMetaData();
                
                // add technical section with file size and format
                $md_obj =& new ilMD($this->getId(),0,$this->getType());
                $technical = $md_obj->addTechnical();
                $technical->setSize($this->getFileSize());
                $technical->save();
                $format = $technical->addFormat();
                $format->setFormat($this->getFileType());
                $format->save();
                $technical->update();
        }

Here is the call graph for this function:

Here is the caller graph for this function:

ilObjFile::delete (  ) 

delete file and all related data

public

Returns:
boolean true if all object data were removed; false if only a references were removed

Reimplemented from ilObject.

Definition at line 484 of file class.ilObjFile.php.

References $q, ilHistory::_removeEntriesForObject(), ilUtil::delDir(), ilObject::deleteMetaData(), getDirectory(), ilObject::getId(), getMode(), and getUsages().

        {
                // check, if file is used somewhere
                $usages = $this->getUsages();

                if (count($usages) == 0)
                {
                        // always call parent delete function first!!
                        if (!parent::delete())
                        {
                                return false;
                        }

                        // delete file data entry
                        $q = "DELETE FROM file_data WHERE file_id = '".$this->getId()."'";
                        $this->ilias->db->query($q);
                        
                        // delete history entries
                        require_once("classes/class.ilHistory.php");
                        ilHistory::_removeEntriesForObject($this->getId());
                        
                        // delete entire directory and its content
                        if (@is_dir($this->getDirectory()))
                        {
                                ilUtil::delDir($this->getDirectory());
                        }
                        
                        // delete meta data
                        if ($this->getMode() != "filelist")
                        {
                                $this->deleteMetaData();
                        }

                        return true;
                }

                return false;
        }

Here is the call graph for this function:

ilObjFile::export ( a_target_dir  ) 

export files of object to target directory note: target directory must be the export target directory, "/objects/il_<inst>_file_<file_id>/..." will be appended to this directory

Parameters:
string $a_target_dir target directory

Definition at line 530 of file class.ilObjFile.php.

References getDirectory(), ilObject::getId(), getVersion(), ilUtil::makeDir(), and ilUtil::rCopy().

        {
                $subdir = "il_".IL_INST_ID."_file_".$this->getId();
                ilUtil::makeDir($a_target_dir."/objects/".$subdir);

                $filedir = $this->getDirectory($this->getVersion());
                
                if (@!is_dir($filedir))
                {
                        $filedir = $this->getDirectory();
                }
                
                ilUtil::rCopy($filedir, $a_target_dir."/objects/".$subdir);
        }

Here is the call graph for this function:

ilObjFile::getDirectory ( a_version = 0  ) 

Definition at line 149 of file class.ilObjFile.php.

References ilUtil::getDataDir(), and ilObject::getId().

Referenced by clearDataDirectory(), copy(), createDirectory(), delete(), export(), getUploadFile(), getXMLZip(), ilClone(), and sendFile().

        {
                $version_subdir = "";

                if ($a_version)
                {
                        $version_subdir = "/".sprintf("%03d", $a_version);
                }
                
                return ilUtil::getDataDir()."/files/file_".$this->getId().$version_subdir;
        }

Here is the call graph for this function:

Here is the caller graph for this function:

ilObjFile::getFileName (  ) 

Definition at line 297 of file class.ilObjFile.php.

Referenced by create(), getXMLZip(), ilClone(), sendFile(), and update().

        {
                return $this->filename;
        }

Here is the caller graph for this function:

ilObjFile::getFileSize (  ) 

Definition at line 317 of file class.ilObjFile.php.

Referenced by createMetaData(), and updateMetaData().

        {
                return $this->filesize;
        }

Here is the caller graph for this function:

ilObjFile::getFileType (  ) 

Definition at line 307 of file class.ilObjFile.php.

Referenced by createMetaData(), and updateMetaData().

        {
                return $this->filetype;
        }

Here is the caller graph for this function:

ilObjFile::getMode (  ) 

mode is object or filelist

Returns:
string mode

Definition at line 347 of file class.ilObjFile.php.

Referenced by create(), delete(), ilClone(), and update().

        {
                return $this->mode;
        }

Here is the caller graph for this function:

ilObjFile::getUploadFile ( a_upload_file,
a_filename 
)

Definition at line 171 of file class.ilObjFile.php.

References $file, getDirectory(), getVersion(), ilUtil::makeDir(), ilUtil::moveUploadedFile(), and setVersion().

Referenced by replaceFile().

        {
                $this->setVersion($this->getVersion() + 1);

                if (@!is_dir($this->getDirectory($this->getVersion())))
                {
                        ilUtil::makeDir($this->getDirectory($this->getVersion()));
                }

                $file = $this->getDirectory($this->getVersion())."/".$a_filename;
                //move_uploaded_file($a_upload_file, $file);
                ilUtil::moveUploadedFile($a_upload_file, $a_filename, $file, $this->raise_upload_error);
        }

Here is the call graph for this function:

Here is the caller graph for this function:

ilObjFile::getUsages (  ) 

get all usages of file object

Definition at line 567 of file class.ilObjFile.php.

References $q.

Referenced by delete().

        {
                global $ilDB;

                // get usages in learning modules
                $q = "SELECT * FROM file_usage WHERE id = '".$this->getId()."'";
                $us_set = $ilDB->query($q);
                $ret = array();
                while($us_rec = $us_set->fetchRow(DB_FETCHMODE_ASSOC))
                {
                        $ret[] = array("type" => $us_rec["usage_type"],
                                "id" => $us_rec["usage_id"]);
                }

                return $ret;
        }

Here is the caller graph for this function:

ilObjFile::getVersion (  ) 

Definition at line 327 of file class.ilObjFile.php.

Referenced by export(), getUploadFile(), ilClone(), and sendFile().

        {
                return $this->version;
        }

Here is the caller graph for this function:

ilObjFile::getXMLZip (  ) 

Reimplemented from ilObject.

Definition at line 610 of file class.ilObjFile.php.

References ilObject::$ilias, ilUtil::escapeShellArg(), getDirectory(), and getFileName().

        {
                global $ilias;

                $zip = PATH_TO_ZIP;

                exec($zip.' '.ilUtil::escapeShellArg($this->getDirectory().'/'.$this->getFileName())." ".
                         ilUtil::escapeShellArg($this->getDirectory().'/'.'1.zip'));

                return $this->getDirectory().'/1.zip';
        }

Here is the call graph for this function:

ilObjFile::ilClone ( a_parent_ref  ) 

ilClone object into tree basic clone function.

Register new object in object_data, creates reference and insert reference ID in tree. All object specific data must be copied in the ilClone function of the appropriate object class. Look in ilObjForum::ilClone() for example code

public

Parameters:
integer $a_parent_ref ref id of parent object
Returns:
integer new ref id

Reimplemented from ilObject.

Definition at line 445 of file class.ilObjFile.php.

References $q, ilHistory::_copyEntriesForObject(), getDirectory(), getFileName(), ilObject::getId(), getMode(), getVersion(), and ilUtil::rCopy().

        {
                global $ilDB;
                
                // always call parent clone function first!!
                $new_ref_id = parent::ilClone($a_parent_ref);

                $fileObj =& $this->ilias->obj_factory->getInstanceByRefId($new_ref_id);
                $fileObj->createDirectory();
                
                // copy all versions of file
                ilUtil::rCopy($this->getDirectory(),$fileObj->getDirectory());
                //copy($this->getDirectory()."/".$this->getFileName(),$fileObj->getDirectory()."/".$this->getFileName());

                $q = "INSERT INTO file_data (file_id,file_name,file_type,version,mode) VALUES ('"
                        .$fileObj->getId()."','"
                        .ilUtil::prepareDBString($this->getFileName())."','"
                        .$this->getFileType()."','".$this->getVersion()
                        ."',".$ilDB->quote($this->getMode()).")";

                $this->ilias->db->query($q);

                // copy history entries
                require_once("classes/class.ilHistory.php");
                ilHistory::_copyEntriesForObject($this->getId(),$fileObj->getId());

                // dump object
                unset($fileObj);

                // ... and finally always return new reference ID!!
                return $new_ref_id;
        }

Here is the call graph for this function:

ilObjFile::ilObjFile ( a_id = 0,
a_call_by_reference = true 
)

Constructor public.

Parameters:
integer reference_id or object_id
boolean treat the id as reference_id (true) or object_id (false)

Definition at line 51 of file class.ilObjFile.php.

References ilObject::ilObject().

        {
                $this->version = 0;
                $this->type = "file";
                $this->raise_upload_error = true;
                $this->ilObject($a_id,$a_call_by_reference);
        }

Here is the call graph for this function:

ilObjFile::MDUpdateListener ( a_element  ) 

Meta data update listener.

Important note: Do never call create() or update() method of ilObject here. It would result in an endless loop: update object -> update meta -> update object -> ... Use static _writeTitle() ... methods instead.

Parameters:
string $a_element

Reimplemented from ilObject.

Definition at line 114 of file class.ilObjFile.php.

References ilObject::$id, _writeFileType(), ilObject::getId(), ilObject::getType(), and setFileType().

        {
                // handling for general section
                parent::MDUpdateListener($a_element);
                
                // handling for technical section 
                include_once 'Services/MetaData/classes/class.ilMD.php';
//echo "-".$a_element."-";
                switch($a_element)
                {
                        case 'Technical':

                                // Update Format (size is not stored in db)
                                $md = new ilMD($this->getId(),0, $this->getType());
                                if(!is_object($md_technical = $md->getTechnical()))
                                {
                                        return false;
                                }

                                foreach($md_technical->getFormatIds() as $id)
                                {
                                        $md_format = $md_technical->getFormat($id);
                                        ilObjFile::_writeFileType($this->getId(),$md_format->getFormat());
                                        $this->setFileType($md_format->getFormat());
                                        break;
                                }

                                break;

                        default:
                }
                return true;
        }

Here is the call graph for this function:

ilObjFile::raiseUploadError ( a_raise = true  ) 

Definition at line 166 of file class.ilObjFile.php.

        {
                $this->raise_upload_error = $a_raise;
        }

ilObjFile::read (  ) 

read file properties

Definition at line 219 of file class.ilObjFile.php.

References $q, $row, setFileName(), setFileType(), setMode(), and setVersion().

        {
                parent::read();

                $q = "SELECT * FROM file_data WHERE file_id = '".$this->getId()."'";
                $r = $this->ilias->db->query($q);
                $row = $r->fetchRow(DB_FETCHMODE_OBJECT);

                $this->setFileName($row->file_name);
                $this->setFileType($row->file_type);
                $this->setVersion($row->version);
                $this->setMode($row->mode);
        }

Here is the call graph for this function:

ilObjFile::replaceFile ( a_upload_file,
a_filename 
)

replace file with new file

Definition at line 188 of file class.ilObjFile.php.

References ilHistory::_createEntry(), ilObject::getId(), and getUploadFile().

        {
                //$this->clearDataDirectory();          // ! This has to be changed, if multiple versions should be supported
                $this->getUploadFile($a_upload_file, $a_filename);
                
                require_once("classes/class.ilHistory.php");
                ilHistory::_createEntry($this->getId(), "replace",
                        $a_filename.",".$this->getVersion());
        }

Here is the call graph for this function:

ilObjFile::sendFile ( a_hist_entry_id = null  ) 

Definition at line 390 of file class.ilObjFile.php.

References $data, $file, ilHistory::_getEntryByHistoryID(), ilUtil::deliverFile(), getDirectory(), getFileName(), and getVersion().

        {       
                if (is_null($a_hist_entry_id))
                {
                        $file = $this->getDirectory($this->getVersion())."/".$this->getFileName();

                        // if not found lookup for file in file object's main directory for downward c  ompability
                        if (@!is_file($file))
                        {
                                $file = $this->getDirectory()."/".$this->getFileName();
                        }
                }
                else
                {
                        require_once("classes/class.ilHistory.php");
                        $entry = ilHistory::_getEntryByHistoryID($a_hist_entry_id);
                        
                        if ($entry === false)
                        {
                                echo "3";return false;
                        }

                        $data = explode(",",$entry["info_params"]);
                        
                        // bugfix: first created file had no version number
                        // this is a workaround for all files created before the bug was fixed
                        if (empty($data[1]))
                        {
                                $data[1] = "1";
                        }

                        $file = $this->getDirectory($data[1])."/".$data[0];
                        
                        // if not found lookup for file in file object's main directory for downward compability
                        if (@!is_file($file))
                        {
                                $file = $this->getDirectory()."/".$data[0];
                        }

                        if (@is_file($file))
                        {
                                ilUtil::deliverFile($file, $data[0]);
                                return true;
                        }
                }

                if (@is_file($file))
                {
                        ilUtil::deliverFile($file, $this->getFileName());
                        return true;
                }

                return false;
        }

Here is the call graph for this function:

ilObjFile::setFileName ( a_name  ) 

set filename

Definition at line 292 of file class.ilObjFile.php.

Referenced by read().

        {
                $this->filename = $a_name;
        }

Here is the caller graph for this function:

ilObjFile::setFileSize ( a_size  ) 

Definition at line 312 of file class.ilObjFile.php.

        {
                $this->filesize = $a_size;
        }

ilObjFile::setFileType ( a_type  ) 

Definition at line 302 of file class.ilObjFile.php.

Referenced by MDUpdateListener(), and read().

        {
                $this->filetype = $a_type;
        }

Here is the caller graph for this function:

ilObjFile::setMode ( a_mode  ) 

mode is object or filelist

Parameters:
string $a_mode mode

Definition at line 337 of file class.ilObjFile.php.

Referenced by read().

        {
                $this->mode = $a_mode;
        }

Here is the caller graph for this function:

ilObjFile::setVersion ( a_version  ) 

Definition at line 322 of file class.ilObjFile.php.

Referenced by getUploadFile(), and read().

        {
                $this->version = $a_version;
        }

Here is the caller graph for this function:

ilObjFile::update (  ) 

update file

Reimplemented from ilObject.

Definition at line 236 of file class.ilObjFile.php.

References $q, getFileName(), getMode(), and updateMetaData().

        {
                global $ilDB;
                
                // no meta data handling for file list files
                if ($this->getMode() != "filelist")
                {
                        $this->updateMetaData();
                }
                parent::update();
                
                $q = "UPDATE file_data SET file_name = '".ilUtil::prepareDBString($this->getFileName()).
                        "', file_type = '".$this->getFiletype()."' ".
                        ", version = '".$this->getVersion()."' ".
                        ", mode = ".$ilDB->quote($this->getMode())." ".
                        "WHERE file_id = '".$this->getId()."'";
                $this->ilias->db->query($q);
                
                return true;
        }

Here is the call graph for this function:

ilObjFile::updateMetaData (  ) 

update meta data

Reimplemented from ilObject.

Definition at line 260 of file class.ilObjFile.php.

References getFileSize(), getFileType(), ilObject::getId(), and ilObject::getType().

Referenced by update().

        {
                parent::updateMetaData();
                
                // add technical section with file size and format
                $md_obj =& new ilMD($this->getId(),0,$this->getType());
                if(!is_object($technical = $md_obj->getTechnical()))
                {
                        $technical = $md_obj->addTechnical();
                        $technical->save();
                }
                $technical->setSize($this->getFileSize());
                
                $format_ids = $technical->getFormatIds();
                if (count($format_ids) > 0)
                {
                        $format = $technical->getFormat($format_ids[0]);
                        $format->setFormat($this->getFileType());
                        $format->update();
                }
                else
                {
                        $format = $technical->addFormat();
                        $format->setFormat($this->getFileType());
                        $format->save();
                }
                $technical->update();
        }

Here is the call graph for this function:

Here is the caller graph for this function:


Field Documentation

ilObjFile::$filemaxsize = "20000000"

Definition at line 41 of file class.ilObjFile.php.

ilObjFile::$filename

Definition at line 39 of file class.ilObjFile.php.

ilObjFile::$filetype

Definition at line 40 of file class.ilObjFile.php.

ilObjFile::$mode = "object"

Definition at line 43 of file class.ilObjFile.php.

ilObjFile::$raise_upload_error

Definition at line 42 of file class.ilObjFile.php.


The documentation for this class was generated from the following file: