Open Journal Systems  3.0.0
 All Classes Namespaces Functions Variables Groups Pages
SectionEditorsDAO.inc.php
1 <?php
2 
16 class SectionEditorsDAO extends DAO {
25  function insertEditor($journalId, $sectionId, $userId, $canReview, $canEdit) {
26  return $this->update(
27  'INSERT INTO section_editors
28  (journal_id, section_id, user_id, can_review, can_edit)
29  VALUES
30  (?, ?, ?, ?, ?)',
31  array(
32  (int) $journalId,
33  (int) $sectionId,
34  (int) $userId,
35  $canReview?1:0,
36  $canEdit?1:0
37  )
38  );
39  }
40 
47  function deleteEditor($journalId, $sectionId, $userId) {
48  return $this->update(
49  'DELETE FROM section_editors WHERE journal_id = ? AND section_id = ? AND user_id = ?',
50  array(
51  (int) $journalId,
52  (int) $sectionId,
53  (int) $userId
54  )
55  );
56  }
57 
64  function &getEditorsBySectionId($journalId, $sectionId) {
65  $users = array();
66 
67  $userDao = DAORegistry::getDAO('UserDAO');
68 
69  $result = $this->retrieve(
70  'SELECT u.*, e.can_review AS can_review, e.can_edit AS can_edit FROM users AS u, section_editors AS e WHERE u.user_id = e.user_id AND e.journal_id = ? AND e.section_id = ? ORDER BY last_name, first_name',
71  array((int) $journalId, (int) $sectionId)
72  );
73 
74  while (!$result->EOF) {
75  $row = $result->GetRowAssoc(false);
76  $users[] = array(
77  'user' => $userDao->_returnUserFromRow($row),
78  'canReview' => $row['can_review'],
79  'canEdit' => $row['can_edit']
80  );
81  $result->MoveNext();
82  }
83 
84  $result->Close();
85  return $users;
86  }
87 
94  function &getEditorsNotInSection($journalId, $sectionId) {
95  $users = array();
96 
97  $userDao = DAORegistry::getDAO('UserDAO');
98 
99  $result = $this->retrieve(
100  'SELECT u.*
101  FROM users u
102  JOIN user_user_groups uug ON (u.user_id = uug.user_id)
103  JOIN user_groups ug ON (uug.user_group_id = ug.user_group_id AND ug.role_id = ? AND ug.context_id = ?)
104  LEFT JOIN section_editors e ON (e.user_id = u.user_id AND e.journal_id = ug.context_id AND e.section_id = ?)
105  WHERE e.section_id IS NULL
106  ORDER BY last_name, first_name',
107  array(ROLE_ID_SUB_EDITOR, (int) $journalId, (int) $sectionId)
108  );
109 
110  while (!$result->EOF) {
111  $users[] = $userDao->_returnUserFromRow($result->GetRowAssoc(false));
112  $result->MoveNext();
113  }
114 
115  $result->Close();
116  return $users;
117  }
118 
124  function deleteEditorsBySectionId($sectionId, $journalId = null) {
125  if (isset($journalId)) return $this->update(
126  'DELETE FROM section_editors WHERE journal_id = ? AND section_id = ?',
127  array($journalId, $sectionId)
128  );
129  else return $this->update(
130  'DELETE FROM section_editors WHERE section_id = ?',
131  (int) $sectionId
132  );
133  }
134 
139  function deleteEditorsByJournalId($journalId) {
140  return $this->update(
141  'DELETE FROM section_editors WHERE journal_id = ?', (int) $journalId
142  );
143  }
144 
151  function deleteByUserId($userId, $journalId = null, $sectionId = null) {
152  return $this->update(
153  'DELETE FROM section_editors WHERE user_id = ?' . (isset($journalId) ? ' AND journal_id = ?' : '') . (isset($sectionId) ? ' AND section_id = ?' : ''),
154  isset($journalId) && isset($sectionId) ? array((int) $userId, (int) $journalId, (int) $sectionId)
155  : (isset($journalId) ? array((int) $userId, (int) $journalId)
156  : (isset($sectionId) ? array((int) $userId, (int) $sectionId) : (int) $userId))
157  );
158  }
159 
167  function editorExists($journalId, $sectionId, $userId) {
168  $result = $this->retrieve(
169  'SELECT COUNT(*) FROM section_editors WHERE journal_id = ? AND section_id = ? AND user_id = ?',
170  array((int) $journalId, (int) $sectionId, (int) $userId)
171  );
172  $returner = isset($result->fields[0]) && $result->fields[0] == 1 ? true : false;
173 
174  $result->Close();
175  return $returner;
176  }
177 }
178 
179 ?>
static & getDAO($name, $dbconn=null)
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:30
Class for DAO relating sections to editors.
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:84
editorExists($journalId, $sectionId, $userId)
& getEditorsBySectionId($journalId, $sectionId)
deleteEditorsByJournalId($journalId)
deleteByUserId($userId, $journalId=null, $sectionId=null)
& getEditorsNotInSection($journalId, $sectionId)
insertEditor($journalId, $sectionId, $userId, $canReview, $canEdit)
deleteEditor($journalId, $sectionId, $userId)
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:208
deleteEditorsBySectionId($sectionId, $journalId=null)