/ojs/ojs-2.0.1/classes/submission/layoutAssignment/LayoutAssignmentDAO.inc.php

https://github.com/mcrider/pkpUpgradeTestSuite · PHP · 182 lines · 111 code · 21 blank · 50 comment · 8 complexity · e4bf3475cbdde6a0d8e078f62df9bd93 MD5 · raw file

  1. <?php
  2. /**
  3. * LayoutAssignmentDAO.inc.php
  4. *
  5. * Copyright (c) 2003-2004 The Public Knowledge Project
  6. * Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
  7. *
  8. * @package submission.layoutAssignment
  9. *
  10. * DAO class for layout editing assignments.
  11. *
  12. * $Id: LayoutAssignmentDAO.inc.php,v 1.5 2005/04/27 19:53:22 alec Exp $
  13. */
  14. import('submission.layoutAssignment.LayoutAssignment');
  15. class LayoutAssignmentDAO extends DAO {
  16. var $articleFileDao;
  17. /**
  18. * Constructor.
  19. */
  20. function LayoutAssignmentDAO() {
  21. parent::DAO();
  22. $this->articleFileDao = &DAORegistry::getDAO('ArticleFileDAO');
  23. }
  24. /**
  25. * Retrieve a layout assignment by assignment ID.
  26. * @param $layoutId int
  27. * @return LayoutAssignment
  28. */
  29. function &getLayoutAssignmentById($layoutId) {
  30. $result = &$this->retrieve(
  31. 'SELECT l.*, u.first_name, u.last_name, u.email
  32. FROM layouted_assignments l
  33. LEFT JOIN users u ON (l.editor_id = u.user_id)
  34. WHERE layouted_id = ?',
  35. $layoutId
  36. );
  37. if ($result->RecordCount() == 0) {
  38. return null;
  39. } else {
  40. return $this->_returnLayoutAssignmentFromRow($result->GetRowAssoc(false));
  41. }
  42. }
  43. /**
  44. * Retrieve the layout editing assignment for an article.
  45. * @param $articleId int
  46. * @return LayoutAssignment
  47. */
  48. function &getLayoutAssignmentByArticleId($articleId) {
  49. $result = &$this->retrieve(
  50. 'SELECT l.*, u.first_name, u.last_name, u.email
  51. FROM layouted_assignments l
  52. LEFT JOIN users u ON (l.editor_id = u.user_id)
  53. WHERE article_id = ?',
  54. $articleId
  55. );
  56. if ($result->RecordCount() == 0) {
  57. return null;
  58. } else {
  59. return $this->_returnLayoutAssignmentFromRow($result->GetRowAssoc(false));
  60. }
  61. }
  62. /**
  63. * Internal function to return a layout assignment object from a row.
  64. * @param $row array
  65. * @return LayoutAssignment
  66. */
  67. function &_returnLayoutAssignmentFromRow(&$row) {
  68. $layoutAssignment = &new LayoutAssignment();
  69. $layoutAssignment->setLayoutId($row['layouted_id']);
  70. $layoutAssignment->setArticleId($row['article_id']);
  71. $layoutAssignment->setEditorId($row['editor_id']);
  72. $layoutAssignment->setEditorFullName($row['first_name'].' '.$row['last_name']);
  73. $layoutAssignment->setEditorEmail($row['email']);
  74. $layoutAssignment->setDateNotified($row['date_notified']);
  75. $layoutAssignment->setDateUnderway($row['date_underway']);
  76. $layoutAssignment->setDateCompleted($row['date_completed']);
  77. $layoutAssignment->setDateAcknowledged($row['date_acknowledged']);
  78. $layoutAssignment->setLayoutFileId($row['layout_file_id']);
  79. if ($row['layout_file_id'] && $row['layout_file_id']) {
  80. $layoutAssignment->setLayoutFile($this->articleFileDao->getArticleFile($row['layout_file_id']));
  81. }
  82. return $layoutAssignment;
  83. }
  84. /**
  85. * Insert a new layout assignment.
  86. * @param $layoutAssignment LayoutAssignment
  87. */
  88. function insertLayoutAssignment(&$layoutAssignment) {
  89. $this->update(
  90. 'INSERT INTO layouted_assignments
  91. (article_id, editor_id, date_notified, date_underway, date_completed, date_acknowledged, layout_file_id)
  92. VALUES
  93. (?, ?, ?, ?, ?, ?, ?)',
  94. array(
  95. $layoutAssignment->getArticleId(),
  96. $layoutAssignment->getEditorId(),
  97. $layoutAssignment->getDateNotified(),
  98. $layoutAssignment->getDateUnderway(),
  99. $layoutAssignment->getDateCompleted(),
  100. $layoutAssignment->getDateAcknowledged(),
  101. $layoutAssignment->getLayoutFileId()
  102. )
  103. );
  104. $layoutAssignment->setLayoutId($this->getInsertLayoutId());
  105. }
  106. /**
  107. * Update an layout assignment.
  108. * @param $layoutAssignment LayoutAssignment
  109. */
  110. function updateLayoutAssignment(&$layoutAssignment) {
  111. return $this->update(
  112. 'UPDATE layouted_assignments
  113. SET article_id = ?,
  114. editor_id = ?,
  115. date_notified = ?,
  116. date_underway = ?,
  117. date_completed = ?,
  118. date_acknowledged = ?,
  119. layout_file_id = ?
  120. WHERE layouted_id = ?',
  121. array(
  122. $layoutAssignment->getArticleId(),
  123. $layoutAssignment->getEditorId(),
  124. $layoutAssignment->getDateNotified(),
  125. $layoutAssignment->getDateUnderway(),
  126. $layoutAssignment->getDateCompleted(),
  127. $layoutAssignment->getDateAcknowledged(),
  128. $layoutAssignment->getLayoutFileId(),
  129. $layoutAssignment->getLayoutId()
  130. )
  131. );
  132. }
  133. /**
  134. * Delete layout assignment.
  135. * @param $layoutId int
  136. */
  137. function deleteLayoutAssignmentById($layoutId) {
  138. return $this->update(
  139. 'DELETE FROM layouted_assignments WHERE layouted_id = ?',
  140. $layoutId
  141. );
  142. }
  143. /**
  144. * Delete layout assignments by article.
  145. * @param $articleId int
  146. */
  147. function deleteLayoutAssignmentsByArticle($articleId) {
  148. return $this->update(
  149. 'DELETE FROM layouted_assignments WHERE article_id = ?',
  150. $articleId
  151. );
  152. }
  153. /**
  154. * Get the ID of the last inserted layout assignment.
  155. * @return int
  156. */
  157. function getInsertLayoutId() {
  158. return $this->getInsertId('layouted_assignments', 'layouted_id');
  159. }
  160. }
  161. ?>