classes/paper/PaperFileDAO.inc.php

Go to the documentation of this file.
00001 <?php
00002 
00016 //$Id$
00017 
00018 import('paper.PaperFile');
00019 
00020 class PaperFileDAO extends DAO {
00024    var $inlineableTypes;
00025 
00033    function &getPaperFile($fileId, $revision = null, $paperId = null) {
00034       if ($fileId === null) {
00035          $returner = null;
00036          return $returner;
00037       }
00038       if ($revision == null) {
00039          if ($paperId != null) {
00040             $result =& $this->retrieveLimit(
00041                'SELECT a.* FROM paper_files a WHERE file_id = ? AND paper_id = ? ORDER BY revision DESC',
00042                array($fileId, $paperId),
00043                1
00044             );
00045          } else {
00046             $result =& $this->retrieveLimit(
00047                'SELECT a.* FROM paper_files a WHERE file_id = ? ORDER BY revision DESC',
00048                $fileId,
00049                1
00050             );
00051          }
00052 
00053       } else {
00054          if ($paperId != null) {
00055             $result =& $this->retrieve(
00056                'SELECT a.* FROM paper_files a WHERE file_id = ? AND revision = ? AND paper_id = ?',
00057                array($fileId, $revision, $paperId)
00058             );
00059          } else {
00060             $result =& $this->retrieve(
00061                'SELECT a.* FROM paper_files a WHERE file_id = ? AND revision = ?',
00062                array($fileId, $revision)
00063             );
00064          }
00065       }
00066 
00067       $returner = null;
00068       if (isset($result) && $result->RecordCount() != 0) {
00069          $returner =& $this->_returnPaperFileFromRow($result->GetRowAssoc(false));
00070       }
00071 
00072       $result->Close();
00073       unset($result);
00074 
00075       return $returner;
00076    }
00077 
00083    function &getPaperFileRevisions($fileId, $stage = null) {
00084       if ($fileId === null) {
00085          $returner = null;
00086          return $returner;
00087       }
00088       $paperFiles = array();
00089 
00090       $params = array($fileId);
00091       if ($stage !== null) $params[] = $stage;
00092 
00093       $result =& $this->retrieve(
00094          'SELECT a.* FROM paper_files a WHERE file_id = ? ' .
00095          ($stage!==null?'AND a.stage = ? ':'') .
00096          'ORDER BY revision',
00097          array($params)
00098       );
00099 
00100       while (!$result->EOF) {
00101          $paperFiles[] =& $this->_returnPaperFileFromRow($result->GetRowAssoc(false));
00102          $result->moveNext();
00103       }
00104 
00105       $result->Close();
00106       unset($result);
00107 
00108       return $paperFiles;
00109    }
00110 
00116    function &getPaperFileRevisionsInRange($fileId, $start = 1, $end = null) {
00117       if ($fileId === null) {
00118          $returner = null;
00119          return $returner;
00120       }
00121       $paperFiles = array();
00122 
00123       if ($end == null) {
00124          $result =& $this->retrieve(
00125             'SELECT a.* FROM paper_files a WHERE file_id = ? AND revision >= ?',
00126             array($fileId, $start)
00127          );
00128       } else {
00129          $result =& $this->retrieve(
00130             'SELECT a.* FROM paper_files a WHERE file_id = ? AND revision >= ? AND revision <= ?',
00131             array($fileId, $start, $end)
00132          );    
00133       }
00134 
00135       while (!$result->EOF) {
00136          $paperFiles[] =& $this->_returnPaperFileFromRow($result->GetRowAssoc(false));
00137          $result->moveNext();
00138       }
00139 
00140       $result->Close();
00141       unset($result);
00142 
00143       return $paperFiles;
00144    }
00145 
00151    function &getRevisionNumber($fileId) {
00152       if ($fileId === null) {
00153          $returner = null;
00154          return $returner;
00155       }
00156       $result =& $this->retrieve(
00157          'SELECT MAX(revision) AS max_revision FROM paper_files a WHERE file_id = ?',
00158          $fileId
00159       );
00160 
00161       if ($result->RecordCount() == 0) {
00162          $returner = null;
00163       } else {
00164          $row = $result->FetchRow();
00165          $returner = $row['max_revision'];
00166       }
00167 
00168       $result->Close();
00169       unset($result);
00170 
00171       return $returner;
00172    }
00173 
00179    function &getPaperFilesByPaper($paperId) {
00180       $paperFiles = array();
00181 
00182       $result =& $this->retrieve(
00183          'SELECT * FROM paper_files WHERE paper_id = ?',
00184          $paperId
00185       );
00186 
00187       while (!$result->EOF) {
00188          $paperFiles[] =& $this->_returnPaperFileFromRow($result->GetRowAssoc(false));
00189          $result->moveNext();
00190       }
00191 
00192       $result->Close();
00193       unset($result);
00194 
00195       return $paperFiles;
00196    }
00197 
00203    function &_returnPaperFileFromRow(&$row) {
00204       $paperFile = new PaperFile();
00205       $paperFile->setFileId($row['file_id']);
00206       $paperFile->setRevision($row['revision']);
00207       $paperFile->setPaperId($row['paper_id']);
00208       $paperFile->setFileName($row['file_name']);
00209       $paperFile->setFileType($row['file_type']);
00210       $paperFile->setFileSize($row['file_size']);
00211       $paperFile->setOriginalFileName($row['original_file_name']);
00212       $paperFile->setType($row['type']);
00213       $paperFile->setStage($row['stage']);
00214       $paperFile->setDateUploaded($this->datetimeFromDB($row['date_uploaded']));
00215       $paperFile->setDateModified($this->datetimeFromDB($row['date_modified']));
00216       $paperFile->setViewable($row['viewable']);
00217       HookRegistry::call('PaperFileDAO::_returnPaperFileFromRow', array(&$paperFile, &$row));
00218       return $paperFile;
00219    }
00220 
00226    function insertPaperFile(&$paperFile) {
00227       $fileId = $paperFile->getFileId();
00228       $params = array(
00229          $paperFile->getRevision() === null ? 1 : $paperFile->getRevision(),
00230          (int) $paperFile->getPaperId(),
00231          $paperFile->getFileName(),
00232          $paperFile->getFileType(),
00233          $paperFile->getFileSize(),
00234          $paperFile->getOriginalFileName(),
00235          $paperFile->getType(),
00236          (int) $paperFile->getStage(),
00237          $paperFile->getViewable()
00238       );
00239 
00240       if ($fileId) {
00241          array_unshift($params, $fileId);
00242       }
00243 
00244       $this->update(
00245          sprintf('INSERT INTO paper_files
00246             (' . ($fileId ? 'file_id, ' : '') . 'revision, paper_id, file_name, file_type, file_size, original_file_name, type, stage, date_uploaded, date_modified, viewable)
00247             VALUES
00248             (' . ($fileId ? '?, ' : '') . '?, ?, ?, ?, ?, ?, ?, ?, %s, %s, ?)',
00249             $this->datetimeToDB($paperFile->getDateUploaded()), $this->datetimeToDB($paperFile->getDateModified())),
00250          $params
00251       );
00252 
00253       if (!$fileId) {
00254          $paperFile->setFileId($this->getInsertPaperFileId());
00255       }
00256 
00257       return $paperFile->getFileId();
00258    }
00259 
00264    function updatePaperFile(&$paperFile) {
00265       $this->update(
00266          sprintf('UPDATE paper_files
00267             SET
00268                paper_id = ?,
00269                file_name = ?,
00270                file_type = ?,
00271                file_size = ?,
00272                original_file_name = ?,
00273                type = ?,
00274                stage = ?,
00275                date_uploaded = %s,
00276                date_modified = %s,
00277                viewable = ?
00278             WHERE file_id = ? AND revision = ?',
00279             $this->datetimeToDB($paperFile->getDateUploaded()), $this->datetimeToDB($paperFile->getDateModified())),
00280          array(
00281             (int) $paperFile->getPaperId(),
00282             $paperFile->getFileName(),
00283             $paperFile->getFileType(),
00284             $paperFile->getFileSize(),
00285             $paperFile->getOriginalFileName(),
00286             $paperFile->getType(),
00287             (int) $paperFile->getStage(),
00288             $paperFile->getViewable(),
00289             $paperFile->getFileId(),
00290             $paperFile->getRevision()
00291          )
00292       );
00293 
00294       return $paperFile->getFileId();
00295 
00296    }
00297 
00302    function deletePaperFile(&$paperFile) {
00303       return $this->deletePaperFileById($paperFile->getFileId(), $paperFile->getRevision());
00304    }
00305 
00311    function deletePaperFileById($fileId, $revision = null) {
00312       if ($revision == null) {
00313          return $this->update(
00314             'DELETE FROM paper_files WHERE file_id = ?', $fileId
00315          );
00316       } else {
00317          return $this->update(
00318             'DELETE FROM paper_files WHERE file_id = ? AND revision = ?', array($fileId, $revision)
00319          );
00320       }
00321    }
00322 
00327    function deletePaperFiles($paperId) {
00328       return $this->update(
00329          'DELETE FROM paper_files WHERE paper_id = ?', $paperId
00330       );
00331    }
00332 
00337    function getInsertPaperFileId() {
00338       return $this->getInsertId('paper_files', 'file_id');
00339    }
00340 
00346    function isInlineable(&$paperFile) {
00347       if (!isset($this->inlineableTypes)) {
00348          $this->inlineableTypes = array_filter(file(Config::getVar('general', 'registry_dir') . '/inlineTypes.txt'), create_function('&$a', 'return ($a = trim($a)) && !empty($a) && $a[0] != \'#\';'));
00349       }
00350       return in_array($paperFile->getFileType(), $this->inlineableTypes);
00351    }
00352 }
00353 
00354 ?>

Generated on 25 Jul 2013 for Open Conference Systems by  doxygen 1.4.7