00001 <?php
00002
00016
00017
00018
00019 import('submission.layoutAssignment.LayoutAssignment');
00020
00021 class LayoutAssignmentDAO extends DAO {
00022 var $articleFileDao;
00023
00027 function LayoutAssignmentDAO() {
00028 parent::DAO();
00029 $this->articleFileDao = &DAORegistry::getDAO('ArticleFileDAO');
00030 }
00031
00037 function &getLayoutAssignmentById($layoutId) {
00038 $result = &$this->retrieve(
00039 'SELECT l.*, u.first_name, u.last_name, u.email
00040 FROM layouted_assignments l
00041 LEFT JOIN users u ON (l.editor_id = u.user_id)
00042 WHERE layouted_id = ?',
00043 $layoutId
00044 );
00045
00046 $returner = null;
00047 if ($result->RecordCount() != 0) {
00048 $returner = &$this->_returnLayoutAssignmentFromRow($result->GetRowAssoc(false));
00049 }
00050
00051 $result->Close();
00052 unset($result);
00053
00054 return $returner;
00055 }
00056
00062 function getLayoutEditorIdByArticleId($articleId) {
00063 $result =& $this->retrieve(
00064 'SELECT editor_id FROM layouted_assignments WHERE article_id = ?',
00065 $articleId
00066 );
00067 $returner = null;
00068 if ($result->RecordCount() != 0) {
00069 $row = $result->GetRowAssoc(false);
00070 $returner = $row['editor_id'];
00071 }
00072 $result->Close();
00073 return $returner;
00074 }
00075
00081 function &getLayoutAssignmentByArticleId($articleId) {
00082 $result = &$this->retrieve(
00083 'SELECT l.*, u.first_name, u.last_name, u.email
00084 FROM layouted_assignments l
00085 LEFT JOIN users u ON (l.editor_id = u.user_id)
00086 WHERE article_id = ?',
00087 $articleId
00088 );
00089
00090 $returner = null;
00091 if ($result->RecordCount() != 0) {
00092 $returner = &$this->_returnLayoutAssignmentFromRow($result->GetRowAssoc(false));
00093 }
00094
00095 $result->Close();
00096 unset($result);
00097
00098 return $returner;
00099 }
00100
00106 function &_returnLayoutAssignmentFromRow(&$row) {
00107 $layoutAssignment = &new LayoutAssignment();
00108 $layoutAssignment->setLayoutId($row['layouted_id']);
00109 $layoutAssignment->setArticleId($row['article_id']);
00110 $layoutAssignment->setEditorId($row['editor_id']);
00111 $layoutAssignment->setEditorFullName($row['first_name'].' '.$row['last_name']);
00112 $layoutAssignment->setEditorEmail($row['email']);
00113 $layoutAssignment->setDateNotified($this->datetimeFromDB($row['date_notified']));
00114 $layoutAssignment->setDateUnderway($this->datetimeFromDB($row['date_underway']));
00115 $layoutAssignment->setDateCompleted($this->datetimeFromDB($row['date_completed']));
00116 $layoutAssignment->setDateAcknowledged($this->datetimeFromDB($row['date_acknowledged']));
00117 $layoutAssignment->setLayoutFileId($row['layout_file_id']);
00118
00119 if ($row['layout_file_id'] && $row['layout_file_id']) {
00120 $layoutAssignment->setLayoutFile($this->articleFileDao->getArticleFile($row['layout_file_id']));
00121 }
00122
00123 HookRegistry::call('LayoutAssignmentDAO::_returnLayoutAssignmentFromRow', array(&$layoutAssignment, &$row));
00124
00125 return $layoutAssignment;
00126 }
00127
00132 function insertLayoutAssignment(&$layoutAssignment) {
00133 $this->update(
00134 sprintf('INSERT INTO layouted_assignments
00135 (article_id, editor_id, date_notified, date_underway, date_completed, date_acknowledged, layout_file_id)
00136 VALUES
00137 (?, ?, %s, %s, %s, %s, ?)',
00138 $this->datetimeToDB($layoutAssignment->getDateNotified()), $this->datetimeToDB($layoutAssignment->getDateUnderway()), $this->datetimeToDB($layoutAssignment->getDateCompleted()), $this->datetimeToDB($layoutAssignment->getDateAcknowledged())),
00139 array(
00140 $layoutAssignment->getArticleId(),
00141 $layoutAssignment->getEditorId(),
00142 $layoutAssignment->getLayoutFileId()
00143 )
00144 );
00145
00146 $layoutAssignment->setLayoutId($this->getInsertLayoutId());
00147 return $layoutAssignment->getLayoutId();
00148 }
00149
00154 function updateLayoutAssignment(&$layoutAssignment) {
00155 return $this->update(
00156 sprintf('UPDATE layouted_assignments
00157 SET article_id = ?,
00158 editor_id = ?,
00159 date_notified = %s,
00160 date_underway = %s,
00161 date_completed = %s,
00162 date_acknowledged = %s,
00163 layout_file_id = ?
00164 WHERE layouted_id = ?',
00165 $this->datetimeToDB($layoutAssignment->getDateNotified()), $this->datetimeToDB($layoutAssignment->getDateUnderway()), $this->datetimeToDB($layoutAssignment->getDateCompleted()), $this->datetimeToDB($layoutAssignment->getDateAcknowledged())),
00166 array(
00167 $layoutAssignment->getArticleId(),
00168 $layoutAssignment->getEditorId(),
00169 $layoutAssignment->getLayoutFileId(),
00170 $layoutAssignment->getLayoutId()
00171 )
00172 );
00173 }
00174
00179 function deleteLayoutAssignmentById($layoutId) {
00180 return $this->update(
00181 'DELETE FROM layouted_assignments WHERE layouted_id = ?',
00182 $layoutId
00183 );
00184 }
00185
00190 function deleteLayoutAssignmentsByArticle($articleId) {
00191 return $this->update(
00192 'DELETE FROM layouted_assignments WHERE article_id = ?',
00193 $articleId
00194 );
00195 }
00196
00201 function getInsertLayoutId() {
00202 return $this->getInsertId('layouted_assignments', 'layouted_id');
00203 }
00204
00205 function getProofedArticlesByIssueId($issueId) {
00206 $articleIds = array();
00207
00208 $result = &$this->retrieve(
00209 'SELECT pa.article_id AS article_id FROM published_articles pa, proof_assignments pra WHERE pa.article_id = pra.article_id AND pa.issue_id = ? AND pra.date_layouteditor_completed IS NOT NULL',
00210 array($issueId)
00211 );
00212
00213 while (!$result->EOF) {
00214 $row = $result->GetRowAssoc(false);
00215 $articleIds[] = $row['article_id'];
00216 $result->MoveNext();
00217 }
00218
00219 $result->Close();
00220 unset($result);
00221
00222 return $articleIds;
00223 }
00224 }
00225
00226 ?>