• Main Page
  • Modules
  • Classes
  • Files
  • File List

classes/press/LibraryFileDAO.inc.php

00001 <?php
00002 
00016 import('classes.press.LibraryFile');
00017 
00018 class LibraryFileDAO extends DAO {
00022    function LibraryFileDAO() {
00023       parent::DAO();
00024    }
00025 
00033    function &getById($fileId) {
00034       $result =& $this->retrieve(
00035          'SELECT file_id, press_id, file_name, original_file_name, file_type, file_size, type, date_uploaded, monograph_id FROM library_files WHERE file_id = ?',
00036          array((int) $fileId)
00037       );
00038 
00039       $returner = null;
00040       if (isset($result) && $result->RecordCount() != 0) {
00041          $returner =& $this->_fromRow($result->GetRowAssoc(false));
00042       }
00043 
00044       $result->Close();
00045       unset($result);
00046 
00047       return $returner;
00048    }
00049 
00056    function &getByPressId($pressId, $type = null) {
00057       $params = array((int) $pressId);
00058       if (isset($type)) $params[] = (int) $type;
00059 
00060       $result =& $this->retrieve(
00061          'SELECT  *
00062          FROM  library_files
00063          WHERE press_id = ? AND monograph_id = 0 ' . (isset($type)?' AND type = ?' : ''),
00064          $params
00065       );
00066       $returner = new DAOResultFactory($result, $this, '_fromRow', array('id'));
00067       return $returner;
00068    }
00069 
00077    function &getByMonographId($monographId, $type = null, $pressId = null) {
00078       $params = array((int) $monographId);
00079       if (isset($type)) $params[] = (int) $type;
00080       if (isset($pressId)) $params[] = (int) $pressId;
00081 
00082       $result =& $this->retrieve(
00083             'SELECT  *
00084             FROM  library_files
00085             WHERE monograph_id = ? ' . (isset($pressId)?' AND press_id = ?' : '') . (isset($type)?' AND type = ?' : ''),
00086             $params
00087       );
00088       $returner = new DAOResultFactory($result, $this, '_fromRow', array('id'));
00089       return $returner;
00090    }
00091 
00096    function newDataObject() {
00097       return new LibraryFile();
00098    }
00099 
00100 
00105    function getLocaleFieldNames() {
00106       return array('name');
00107    }
00108 
00113    function updateLocaleFields(&$libraryFile) {
00114       $this->updateDataObjectSettings(
00115          'library_file_settings',
00116          $libraryFile,
00117          array('file_id' => $libraryFile->getId())
00118       );
00119    }
00120 
00126    function &_fromRow(&$row) {
00127       $libraryFile = $this->newDataObject();
00128 
00129       $libraryFile->setId($row['file_id']);
00130       $libraryFile->setPressId($row['press_id']);
00131       $libraryFile->setFileName($row['file_name']);
00132       $libraryFile->setOriginalFileName($row['original_file_name']);
00133       $libraryFile->setFileType($row['file_type']);
00134       $libraryFile->setFileSize($row['file_size']);
00135       $libraryFile->setType($row['type']);
00136       $libraryFile->setDateUploaded($this->datetimeFromDB($row['date_uploaded']));
00137       $libraryFile->setMonographId($row['monograph_id']);
00138 
00139       $this->getDataObjectSettings('library_file_settings', 'file_id', $row['file_id'], $libraryFile);
00140 
00141       HookRegistry::call('LibraryFileDAO::_fromRow', array(&$libraryFile, &$row));
00142 
00143       return $libraryFile;
00144    }
00145 
00151    function insertObject(&$libraryFile) {
00152       $params = array(
00153          (int) $libraryFile->getPressId(),
00154          $libraryFile->getFileName(),
00155          $libraryFile->getOriginalFileName(),
00156          $libraryFile->getFileType(),
00157          (int) $libraryFile->getFileSize(),
00158          (int) $libraryFile->getType(),
00159          (int) $libraryFile->getMonographId(),
00160       );
00161 
00162       if ($libraryFile->getId()) $params[] = (int) $libraryFile->getId();
00163 
00164       $this->update(
00165          sprintf('INSERT INTO library_files
00166             (press_id, file_name, original_file_name, file_type, file_size, type, monograph_id, date_uploaded, date_modified' . ($libraryFile->getId()?', file_id':'') . ')
00167             VALUES
00168             (?, ?, ?, ?, ?, ?, ?, %s, %s' . ($libraryFile->getId()?', ?':'') . ')',
00169             $this->datetimeToDB($libraryFile->getDateUploaded()),
00170                $this->datetimeToDB($libraryFile->getDateModified())
00171          ),
00172          $params
00173       );
00174 
00175       if (!$libraryFile->getId()) $libraryFile->setId($this->getInsertLibraryFileId());
00176 
00177       $this->updateLocaleFields($libraryFile);
00178       return $libraryFile->getId();
00179    }
00180 
00186    function updateObject(&$libraryFile) {
00187       $this->update(
00188          sprintf('UPDATE   library_files
00189             SET   press_id = ?,
00190                file_name = ?,
00191                original_file_name = ?,
00192                file_type = ?,
00193                file_size = ?,
00194                type = ?,
00195                monograph_id = ?,
00196                date_uploaded = %s
00197             WHERE file_id = ?',
00198             $this->datetimeToDB($libraryFile->getDateUploaded())
00199          ), array(
00200             (int) $libraryFile->getPressId(),
00201             $libraryFile->getFileName(),
00202             $libraryFile->getOriginalFileName(),
00203             $libraryFile->getFileType(),
00204             (int) $libraryFile->getFileSize(),
00205             (int) $libraryFile->getType(),
00206             (int) $libraryFile->getMonographId(),
00207             (int) $libraryFile->getId()
00208          )
00209       );
00210 
00211       $this->updateLocaleFields($libraryFile);
00212       return $libraryFile->getId();
00213    }
00214 
00220    function deleteById($fileId, $revision = null) {
00221       $this->update(
00222          'DELETE FROM library_files WHERE file_id = ?',
00223          (int) $fileId
00224       );
00225       $this->update(
00226          'DELETE FROM library_file_settings WHERE file_id = ?',
00227          (int) $fileId
00228       );
00229    }
00230 
00236    function filenameExists($pressId, $fileName) {
00237       $result = $this->retrieve(
00238          'SELECT COUNT(*) FROM library_files WHERE press_id = ? AND file_name = ?',
00239          array((int) $pressId, $fileName)
00240       );
00241 
00242       $returner = (isset($result->fields[0]) && $result->fields[0] > 0) ? true : false;
00243       $result->Close();
00244       unset($result);
00245 
00246       return $returner;
00247    }
00248 
00253    function getInsertLibraryFileId() {
00254       return $this->getInsertId('library_files', 'file_id');
00255    }
00256 }
00257 
00258 ?>

Generated on Mon Sep 17 2012 13:58:55 for Open Monograph Press by  doxygen 1.7.1