classes/paper/PaperNoteDAO.inc.php

Go to the documentation of this file.
00001 <?php
00002 
00016 //$Id$
00017 
00018 import('paper.PaperNote');
00019 
00020 class PaperNoteDAO extends DAO {
00026    function &getPaperNotes($paperId, $rangeInfo = NULL) {
00027       $sql = 'SELECT n.*, a.file_name, a.original_file_name FROM paper_notes n LEFT JOIN paper_files a ON (n.file_id = a.file_id) WHERE a.paper_id = ? OR (n.file_id = 0 AND n.paper_id = ?) ORDER BY n.date_created DESC';
00028 
00029       $result =& $this->retrieveRange($sql, array($paperId, $paperId), $rangeInfo);
00030 
00031       $returner = new DAOResultFactory($result, $this, '_returnPaperNoteFromRow');
00032       return $returner;
00033    }
00034 
00040    function &getPaperNotesByUserId($userId, $rangeInfo = NULL) {
00041       $sql = 'SELECT n.*, a.file_name, a.original_file_name FROM paper_notes n LEFT JOIN paper_files a ON (n.file_id = a.file_id) WHERE n.user_id = ? ORDER BY n.date_created DESC';
00042 
00043       $result =& $this->retrieveRange($sql, $userId, $rangeInfo);
00044 
00045       $returner = new DAOResultFactory($result, $this, '_returnPaperNoteFromRow');
00046       return $returner;
00047    }
00048 
00054    function getPaperNoteById($noteId) {
00055       $result =& $this->retrieve(
00056          'SELECT n.*, a.file_name, a.original_file_name FROM paper_notes n LEFT JOIN paper_files a ON (n.file_id = a.file_id) WHERE n.note_id = ?', $noteId
00057       );
00058       $paperNote =& $this->_returnPaperNoteFromRow($result->GetRowAssoc(false));
00059 
00060       $result->Close();
00061       unset($result);
00062 
00063       return $paperNote;
00064    }  
00065 
00071    function &_returnPaperNoteFromRow($row) {
00072       $paperNote = new PaperNote();
00073       $paperNote->setNoteId($row['note_id']);
00074       $paperNote->setPaperId($row['paper_id']);
00075       $paperNote->setUserId($row['user_id']);
00076       $paperNote->setDateCreated($this->datetimeFromDB($row['date_created']));
00077       $paperNote->setDateModified($this->datetimeFromDB($row['date_modified']));
00078       $paperNote->setTitle($row['title']);
00079       $paperNote->setNote($row['note']);
00080       $paperNote->setFileId($row['file_id']);
00081 
00082       $paperNote->setFileName($row['file_name']);
00083       $paperNote->setOriginalFileName($row['original_file_name']);
00084 
00085       HookRegistry::call('PaperNoteDAO::_returnPaperNoteFromRow', array(&$paperNote, &$row));
00086 
00087       return $paperNote;
00088    }
00089 
00095    function insertPaperNote(&$paperNote) {
00096       $this->update(
00097          sprintf('INSERT INTO paper_notes
00098             (paper_id, user_id, date_created, date_modified, title, note, file_id)
00099             VALUES
00100             (?, ?, %s, %s, ?, ?, ?)',
00101             $this->datetimeToDB($paperNote->getDateCreated()), $this->datetimeToDB($paperNote->getDateModified())),
00102          array(
00103             $paperNote->getPaperId(),
00104             $paperNote->getUserId(),
00105             $paperNote->getTitle(),
00106             $paperNote->getNote(),
00107             $paperNote->getFileId()
00108          )
00109       );
00110 
00111       $paperNote->setNoteId($this->getInsertPaperNoteId());
00112       return $paperNote->getNoteId();
00113    }
00114 
00119    function getInsertPaperNoteId() {
00120       return $this->getInsertId('paper_notes', 'note_id');
00121    }  
00122 
00127    function deletePaperNoteById($noteId) {
00128       $this->update(
00129          'DELETE FROM paper_notes WHERE note_id = ?', $noteId
00130       );
00131    }
00132 
00137    function updatePaperNote($paperNote) {
00138       $this->update(
00139          sprintf('UPDATE paper_notes
00140             SET
00141                user_id = ?,
00142                date_modified = %s,
00143                title = ?,
00144                note = ?,
00145                file_id = ?
00146             WHERE note_id = ?',
00147             $this->datetimeToDB($paperNote->getDateModified())),
00148          array(
00149             $paperNote->getUserId(),
00150             $paperNote->getTitle(),
00151             $paperNote->getNote(),
00152             $paperNote->getFileId(),
00153             $paperNote->getNoteId()
00154          )
00155       );
00156    }
00157 
00162    function getAllPaperNoteFileIds($paperId) {
00163       $fileIds = array();
00164 
00165       $result =& $this->retrieve(
00166          'SELECT a.file_id FROM paper_notes a WHERE paper_id = ? AND file_id > ?', array($paperId, 0)
00167       );
00168 
00169       while (!$result->EOF) {
00170          $row = $result->GetRowAssoc(false);
00171          $fileIds[] = $row['file_id'];
00172          $result->moveNext();
00173       }
00174 
00175       $result->Close();
00176       unset($result);
00177 
00178       return $fileIds;
00179    }  
00180 
00185    function clearAllPaperNotes($paperId) {
00186       $result =& $this->retrieve(
00187          'DELETE FROM paper_notes WHERE paper_id = ?', $paperId
00188       );
00189 
00190       $result->Close();
00191    }
00192 }
00193 
00194 ?>

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