Open Journal Systems  2.4.3
 All Classes Namespaces Functions Variables Groups Pages
EditAssignmentDAO.inc.php
1 <?php
2 
17 import('classes.submission.editAssignment.EditAssignment');
18 
19 class EditAssignmentDAO extends DAO {
25  function &getEditAssignment($editId) {
26  $result =& $this->retrieve(
27  'SELECT e.*, u.first_name, u.last_name, u.email, u.initials, r.role_id AS editor_role_id FROM articles a LEFT JOIN edit_assignments e ON (a.article_id = e.article_id) LEFT JOIN users u ON (e.editor_id = u.user_id) LEFT JOIN roles r ON (r.user_id = e.editor_id AND r.role_id = ' . ROLE_ID_EDITOR . ' AND r.journal_id = a.journal_id) WHERE e.edit_id = ? AND a.article_id = e.article_id',
28  $editId
29  );
30 
31  $returner = null;
32  if ($result->RecordCount() != 0) {
33  $returner =& $this->_returnEditAssignmentFromRow($result->GetRowAssoc(false));
34  }
35 
36  $result->Close();
37  unset($result);
38 
39  return $returner;
40  }
41 
47  function &getEditAssignmentsByArticleId($articleId) {
48  $result =& $this->retrieve(
49  'SELECT e.*, u.first_name, u.last_name, u.email, u.initials, r.role_id AS editor_role_id FROM articles a LEFT JOIN edit_assignments e ON (a.article_id = e.article_id) LEFT JOIN users u ON (e.editor_id = u.user_id) LEFT JOIN roles r ON (r.user_id = e.editor_id AND r.role_id = ' . ROLE_ID_EDITOR . ' AND r.journal_id = a.journal_id) WHERE e.article_id = ? AND a.article_id = e.article_id ORDER BY e.date_notified ASC',
50  $articleId
51  );
52 
53  $returner = new DAOResultFactory($result, $this, '_returnEditAssignmentFromRow');
54  return $returner;
55  }
56 
62  function &getEditorAssignmentsByArticleId($articleId) {
63  $result =& $this->retrieve(
64  'SELECT e.*, u.first_name, u.last_name, u.email, u.initials, r.role_id AS editor_role_id FROM articles a, edit_assignments e, users u, roles r WHERE r.user_id = e.editor_id AND r.role_id = ' . ROLE_ID_EDITOR . ' AND e.article_id = ? AND r.journal_id = a.journal_id AND a.article_id = e.article_id AND e.editor_id = u.user_id ORDER BY e.date_notified ASC',
65  $articleId
66  );
67 
68  $returner = new DAOResultFactory($result, $this, '_returnEditAssignmentFromRow');
69  return $returner;
70  }
71 
79  $result =& $this->retrieve(
80  'SELECT e.*, u.first_name, u.last_name, u.email, u.initials, r.role_id AS editor_role_id FROM articles a LEFT JOIN edit_assignments e ON (a.article_id = e.article_id) LEFT JOIN users u ON (e.editor_id = u.user_id) LEFT JOIN roles r ON (r.user_id = e.editor_id AND r.role_id = ' . ROLE_ID_EDITOR . ' AND r.journal_id = a.journal_id) WHERE e.article_id = ? AND a.article_id = e.article_id AND r.role_id IS NULL AND e.can_review = 1 ORDER BY e.date_notified ASC',
81  $articleId
82  );
83 
84  $returner = new DAOResultFactory($result, $this, '_returnEditAssignmentFromRow');
85  return $returner;
86  }
87 
95  $result =& $this->retrieve(
96  'SELECT e.*, u.first_name, u.last_name, u.email, u.initials, r.role_id AS editor_role_id FROM articles a LEFT JOIN edit_assignments e ON (a.article_id = e.article_id) LEFT JOIN users u ON (e.editor_id = u.user_id) LEFT JOIN roles r ON (r.user_id = e.editor_id AND r.role_id = ' . ROLE_ID_EDITOR . ' AND r.journal_id = a.journal_id) WHERE e.article_id = ? AND a.article_id = e.article_id AND r.role_id IS NULL AND e.can_edit = 1 ORDER BY e.date_notified ASC',
97  $articleId
98  );
99 
100  $returner = new DAOResultFactory($result, $this, '_returnEditAssignmentFromRow');
101  return $returner;
102  }
103 
109  function &getEditAssignmentsByUserId($userId) {
110  $result =& $this->retrieve(
111  'SELECT e.*, u.first_name, u.last_name, u.email, u.initials, r.role_id AS editor_role_id FROM articles a LEFT JOIN edit_assignments e ON (a.article_id = e.article_id) LEFT JOIN users u ON (e.editor_id = u.user_id) LEFT JOIN roles r ON (r.user_id = e.editor_id AND r.role_id = ' . ROLE_ID_EDITOR . ' AND r.journal_id = a.journal_id) WHERE e.editor_id = ? AND a.article_id = e.article_id ORDER BY e.date_notified ASC',
112  $userId
113  );
114 
115  $returner = new DAOResultFactory($result, $this, '_returnEditAssignmentFromRow');
116  return $returner;
117  }
118 
124  function &_returnEditAssignmentFromRow(&$row) {
125  $editAssignment = new EditAssignment();
126  $editAssignment->setEditId($row['edit_id']);
127  $editAssignment->setArticleId($row['article_id']);
128  $editAssignment->setEditorId($row['editor_id']);
129  $editAssignment->setCanReview($row['can_review']);
130  $editAssignment->setCanEdit($row['can_edit']);
131  $editAssignment->setEditorFullName($row['first_name'].' '.$row['last_name']);
132  $editAssignment->setEditorFirstName($row['first_name']);
133  $editAssignment->setEditorLastName($row['last_name']);
134  $editAssignment->setEditorInitials($row['initials']);
135  $editAssignment->setEditorEmail($row['email']);
136  $editAssignment->setIsEditor($row['editor_role_id']==ROLE_ID_EDITOR?1:0);
137  $editAssignment->setDateUnderway($this->datetimeFromDB($row['date_underway']));
138  $editAssignment->setDateNotified($this->datetimeFromDB($row['date_notified']));
139 
140  HookRegistry::call('EditAssignmentDAO::_returnEditAssignmentFromRow', array(&$editAssignment, &$row));
141 
142  return $editAssignment;
143  }
144 
149  function insertEditAssignment(&$editAssignment) {
150  $this->update(
151  sprintf('INSERT INTO edit_assignments
152  (article_id, editor_id, can_edit, can_review, date_notified, date_underway)
153  VALUES
154  (?, ?, ?, ?, %s, %s)',
155  $this->datetimeToDB($editAssignment->getDateNotified()),
156  $this->datetimeToDB($editAssignment->getDateUnderway())),
157  array(
158  $editAssignment->getArticleId(),
159  $editAssignment->getEditorId(),
160  $editAssignment->getCanEdit()?1:0,
161  $editAssignment->getCanReview()?1:0
162  )
163  );
164 
165  $editAssignment->setEditId($this->getInsertEditId());
166  return $editAssignment->getEditId();
167  }
168 
173  function updateEditAssignment(&$editAssignment) {
174  return $this->update(
175  sprintf('UPDATE edit_assignments
176  SET article_id = ?,
177  editor_id = ?,
178  can_review = ?,
179  can_edit = ?,
180  date_notified = %s,
181  date_underway = %s
182  WHERE edit_id = ?',
183  $this->datetimeToDB($editAssignment->getDateNotified()),
184  $this->datetimeToDB($editAssignment->getDateUnderway())),
185  array(
186  $editAssignment->getArticleId(),
187  $editAssignment->getEditorId(),
188  $editAssignment->getCanReview() ? 1:0,
189  $editAssignment->getCanEdit() ? 1:0,
190  $editAssignment->getEditId()
191  )
192  );
193  }
194 
199  function deleteEditAssignmentById($editId) {
200  return $this->update(
201  'DELETE FROM edit_assignments WHERE edit_id = ?',
202  $editId
203  );
204  }
205 
210  function deleteEditAssignmentsByArticle($articleId) {
211  return $this->update(
212  'DELETE FROM edit_assignments WHERE article_id = ?',
213  $articleId
214  );
215  }
216 
221  function getInsertEditId() {
222  return $this->getInsertId('edit_assignments', 'edit_id');
223  }
224 
229  function getEditorStatistics($journalId) {
230  $statistics = Array();
231 
232  // Get counts of completed submissions
233  $result =& $this->retrieve(
234  'SELECT ea.editor_id,
235  COUNT(ea.article_id) AS complete
236  FROM edit_assignments ea,
237  articles a
238  WHERE ea.article_id = a.article_id AND
239  a.journal_id = ? AND (
240  a.status = ' . STATUS_ARCHIVED . ' OR
241  a.status = ' . STATUS_PUBLISHED . ' OR
242  a.status = ' . STATUS_DECLINED . '
243  )
244  GROUP BY ea.editor_id',
245  $journalId
246  );
247 
248  while (!$result->EOF) {
249  $row = $result->GetRowAssoc(false);
250  if (!isset($statistics[$row['editor_id']])) $statistics[$row['editor_id']] = array();
251  $statistics[$row['editor_id']]['complete'] = $row['complete'];
252  $result->MoveNext();
253  }
254  $result->Close();
255  unset($result);
256 
257  // Get counts of incomplete submissions
258  $result =& $this->retrieve(
259  'SELECT ea.editor_id,
260  COUNT(ea.article_id) AS incomplete
261  FROM edit_assignments ea,
262  articles a
263  WHERE ea.article_id = a.article_id AND
264  a.journal_id = ? AND
265  a.status = ' . STATUS_QUEUED . '
266  GROUP BY ea.editor_id',
267  $journalId
268  );
269 
270  while (!$result->EOF) {
271  $row = $result->GetRowAssoc(false);
272  if (!isset($statistics[$row['editor_id']])) $statistics[$row['editor_id']] = array();
273  $statistics[$row['editor_id']]['incomplete'] = $row['incomplete'];
274  $result->MoveNext();
275  }
276  $result->Close();
277  unset($result);
278 
279  return $statistics;
280  }
281 }
282 
283 ?>
updateEditAssignment(&$editAssignment)
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:29
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:83
getInsertId($table= '', $id= '', $callHooks=true)
Definition: DAO.inc.php:252
Describes edit assignment properties.
deleteEditAssignmentsByArticle($articleId)
& getEditingSectionEditorAssignmentsByArticleId($articleId)
datetimeFromDB($dt)
Definition: DAO.inc.php:316
Class for DAO relating editors to articles.
& getEditAssignmentsByArticleId($articleId)
Wrapper around ADORecordSet providing &quot;factory&quot; features for generating objects from DAOs...
& getEditAssignmentsByUserId($userId)
insertEditAssignment(&$editAssignment)
call($hookName, $args=null)
& getReviewingSectionEditorAssignmentsByArticleId($articleId)
datetimeToDB($dt)
Definition: DAO.inc.php:296
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:211
& getEditorAssignmentsByArticleId($articleId)