Open Journal Systems  2.4.8
 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 
123  function newDataObject() {
124  return new EditAssignment();
125  }
126 
132  function &_returnEditAssignmentFromRow(&$row) {
133  $editAssignment = $this->newDataObject();
134  $editAssignment->setEditId($row['edit_id']);
135  $editAssignment->setArticleId($row['article_id']);
136  $editAssignment->setEditorId($row['editor_id']);
137  $editAssignment->setCanReview($row['can_review']);
138  $editAssignment->setCanEdit($row['can_edit']);
139  $editAssignment->setEditorFullName($row['first_name'].' '.$row['last_name']);
140  $editAssignment->setEditorFirstName($row['first_name']);
141  $editAssignment->setEditorLastName($row['last_name']);
142  $editAssignment->setEditorInitials($row['initials']);
143  $editAssignment->setEditorEmail($row['email']);
144  $editAssignment->setIsEditor($row['editor_role_id']==ROLE_ID_EDITOR?1:0);
145  $editAssignment->setDateUnderway($this->datetimeFromDB($row['date_underway']));
146  $editAssignment->setDateNotified($this->datetimeFromDB($row['date_notified']));
147  $editAssignment->setDateAssigned($this->datetimeFromDB($row['date_assigned']));
148 
149  HookRegistry::call('EditAssignmentDAO::_returnEditAssignmentFromRow', array(&$editAssignment, &$row));
150 
151  return $editAssignment;
152  }
153 
158  function insertEditAssignment(&$editAssignment) {
159  $this->update(
160  sprintf('INSERT INTO edit_assignments
161  (article_id, editor_id, can_edit, can_review, date_assigned, date_notified, date_underway)
162  VALUES
163  (?, ?, ?, ?, %s, %s, %s)',
164  $this->datetimeToDB($editAssignment->getDateAssigned()),
165  $this->datetimeToDB($editAssignment->getDateNotified()),
166  $this->datetimeToDB($editAssignment->getDateUnderway())),
167  array(
168  $editAssignment->getArticleId(),
169  $editAssignment->getEditorId(),
170  $editAssignment->getCanEdit()?1:0,
171  $editAssignment->getCanReview()?1:0
172  )
173  );
174 
175  $editAssignment->setEditId($this->getInsertEditId());
176  return $editAssignment->getEditId();
177  }
178 
183  function updateEditAssignment(&$editAssignment) {
184  return $this->update(
185  sprintf('UPDATE edit_assignments
186  SET article_id = ?,
187  editor_id = ?,
188  can_review = ?,
189  can_edit = ?,
190  date_assigned = %s,
191  date_notified = %s,
192  date_underway = %s
193  WHERE edit_id = ?',
194  $this->datetimeToDB($editAssignment->getDateAssigned()),
195  $this->datetimeToDB($editAssignment->getDateNotified()),
196  $this->datetimeToDB($editAssignment->getDateUnderway())),
197  array(
198  $editAssignment->getArticleId(),
199  $editAssignment->getEditorId(),
200  $editAssignment->getCanReview() ? 1:0,
201  $editAssignment->getCanEdit() ? 1:0,
202  $editAssignment->getEditId()
203  )
204  );
205  }
206 
211  function deleteEditAssignmentById($editId) {
212  return $this->update(
213  'DELETE FROM edit_assignments WHERE edit_id = ?',
214  $editId
215  );
216  }
217 
222  function deleteEditAssignmentsByArticle($articleId) {
223  return $this->update(
224  'DELETE FROM edit_assignments WHERE article_id = ?',
225  $articleId
226  );
227  }
228 
233  function getInsertEditId() {
234  return $this->getInsertId('edit_assignments', 'edit_id');
235  }
236 
241  function getEditorStatistics($journalId) {
242  $statistics = Array();
243 
244  // Get counts of completed submissions
245  $result =& $this->retrieve(
246  'SELECT ea.editor_id,
247  COUNT(ea.article_id) AS complete
248  FROM edit_assignments ea,
249  articles a
250  WHERE ea.article_id = a.article_id AND
251  a.journal_id = ? AND (
252  a.status = ' . STATUS_ARCHIVED . ' OR
253  a.status = ' . STATUS_PUBLISHED . ' OR
254  a.status = ' . STATUS_DECLINED . '
255  )
256  GROUP BY ea.editor_id',
257  $journalId
258  );
259 
260  while (!$result->EOF) {
261  $row = $result->GetRowAssoc(false);
262  if (!isset($statistics[$row['editor_id']])) $statistics[$row['editor_id']] = array();
263  $statistics[$row['editor_id']]['complete'] = $row['complete'];
264  $result->MoveNext();
265  }
266  $result->Close();
267  unset($result);
268 
269  // Get counts of incomplete submissions
270  $result =& $this->retrieve(
271  'SELECT ea.editor_id,
272  COUNT(ea.article_id) AS incomplete
273  FROM edit_assignments ea,
274  articles a
275  WHERE ea.article_id = a.article_id AND
276  a.journal_id = ? AND
277  a.status = ' . STATUS_QUEUED . '
278  GROUP BY ea.editor_id',
279  $journalId
280  );
281 
282  while (!$result->EOF) {
283  $row = $result->GetRowAssoc(false);
284  if (!isset($statistics[$row['editor_id']])) $statistics[$row['editor_id']] = array();
285  $statistics[$row['editor_id']]['incomplete'] = $row['incomplete'];
286  $result->MoveNext();
287  }
288  $result->Close();
289  unset($result);
290 
291  return $statistics;
292  }
293 }
294 
295 ?>
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)