00001 <?php
00002
00016
00017
00018
00019 import('article.ArticleNote');
00020
00021 class ArticleNoteDAO extends DAO {
00027 function &getArticleNotes($articleId, $rangeInfo = NULL) {
00028 $sql = 'SELECT n.*, a.file_name, a.original_file_name FROM article_notes n LEFT JOIN article_files a ON (n.file_id = a.file_id) WHERE a.article_id = ? OR (n.file_id = 0 AND n.article_id = ?) ORDER BY n.date_created DESC';
00029
00030 $result = &$this->retrieveRange($sql, array($articleId, $articleId), $rangeInfo);
00031
00032 $returner = &new DAOResultFactory($result, $this, '_returnArticleNoteFromRow');
00033 return $returner;
00034 }
00035
00041 function &getArticleNotesByUserId($userId, $rangeInfo = NULL) {
00042 $sql = 'SELECT n.*, a.file_name, a.original_file_name FROM article_notes n LEFT JOIN article_files a ON (n.file_id = a.file_id) WHERE n.user_id = ? ORDER BY n.date_created DESC';
00043
00044 $result = &$this->retrieveRange($sql, $userId, $rangeInfo);
00045
00046 $returner = &new DAOResultFactory($result, $this, '_returnArticleNoteFromRow');
00047 return $returner;
00048 }
00049
00055 function getArticleNoteById($noteId) {
00056 $result = &$this->retrieve(
00057 'SELECT n.*, a.file_name, a.original_file_name FROM article_notes n LEFT JOIN article_files a ON (n.file_id = a.file_id) WHERE n.note_id = ?', $noteId
00058 );
00059 $articleNote = &$this->_returnArticleNoteFromRow($result->GetRowAssoc(false));
00060
00061 $result->Close();
00062 unset($result);
00063
00064 return $articleNote;
00065 }
00066
00072 function &_returnArticleNoteFromRow($row) {
00073 $articleNote = &new ArticleNote();
00074 $articleNote->setNoteId($row['note_id']);
00075 $articleNote->setArticleId($row['article_id']);
00076 $articleNote->setUserId($row['user_id']);
00077 $articleNote->setDateCreated($this->datetimeFromDB($row['date_created']));
00078 $articleNote->setDateModified($this->datetimeFromDB($row['date_modified']));
00079 $articleNote->setTitle($row['title']);
00080 $articleNote->setNote($row['note']);
00081 $articleNote->setFileId($row['file_id']);
00082
00083 $articleNote->setFileName($row['file_name']);
00084 $articleNote->setOriginalFileName($row['original_file_name']);
00085
00086 HookRegistry::call('ArticleNoteDAO::_returnArticleNoteFromRow', array(&$articleNote, &$row));
00087
00088 return $articleNote;
00089 }
00090
00096 function insertArticleNote(&$articleNote) {
00097 $this->update(
00098 sprintf('INSERT INTO article_notes
00099 (article_id, user_id, date_created, date_modified, title, note, file_id)
00100 VALUES
00101 (?, ?, %s, %s, ?, ?, ?)',
00102 $this->datetimeToDB($articleNote->getDateCreated()), $this->datetimeToDB($articleNote->getDateModified())),
00103 array(
00104 $articleNote->getArticleId(),
00105 $articleNote->getUserId(),
00106 $articleNote->getTitle(),
00107 $articleNote->getNote(),
00108 $articleNote->getFileId()
00109 )
00110 );
00111
00112 $articleNote->setNoteId($this->getInsertArticleNoteId());
00113 return $articleNote->getNoteId();
00114 }
00115
00120 function getInsertArticleNoteId() {
00121 return $this->getInsertId('article_notes', 'note_id');
00122 }
00123
00128 function deleteArticleNoteById($noteId) {
00129 $this->update(
00130 'DELETE FROM article_notes WHERE note_id = ?', $noteId
00131 );
00132 }
00133
00138 function updateArticleNote($articleNote) {
00139 $this->update(
00140 sprintf('UPDATE article_notes
00141 SET
00142 user_id = ?,
00143 date_modified = %s,
00144 title = ?,
00145 note = ?,
00146 file_id = ?
00147 WHERE note_id = ?',
00148 $this->datetimeToDB($articleNote->getDateModified())),
00149 array(
00150 $articleNote->getUserId(),
00151 $articleNote->getTitle(),
00152 $articleNote->getNote(),
00153 $articleNote->getFileId(),
00154 $articleNote->getNoteId()
00155 )
00156 );
00157 }
00158
00163 function getAllArticleNoteFileIds($articleId) {
00164 $fileIds = array();
00165
00166 $result = &$this->retrieve(
00167 'SELECT a.file_id FROM article_notes a WHERE article_id = ? AND file_id > ?', array($articleId, 0)
00168 );
00169
00170 while (!$result->EOF) {
00171 $row = $result->GetRowAssoc(false);
00172 $fileIds[] = $row['file_id'];
00173 $result->moveNext();
00174 }
00175
00176 $result->Close();
00177 unset($result);
00178
00179 return $fileIds;
00180 }
00181
00186 function clearAllArticleNotes($articleId) {
00187 $result = &$this->retrieve(
00188 'DELETE FROM article_notes WHERE article_id = ?', $articleId
00189 );
00190
00191 $result->Close();
00192 }
00193 }
00194
00195 ?>