Open Journal Systems  2.4.4
 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  $journalId,
33  $sectionId,
34  $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  $journalId,
52  $sectionId,
53  $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($journalId, $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  unset($result);
86 
87  return $users;
88  }
89 
96  function &getEditorsNotInSection($journalId, $sectionId) {
97  $users = array();
98 
99  $userDao =& DAORegistry::getDAO('UserDAO');
100 
101  $result =& $this->retrieve(
102  'SELECT u.*
103  FROM users u
104  LEFT JOIN roles r ON (r.user_id = u.user_id)
105  LEFT JOIN section_editors e ON (e.user_id = u.user_id AND e.journal_id = r.journal_id AND e.section_id = ?)
106  WHERE r.journal_id = ? AND
107  r.role_id = ? AND
108  e.section_id IS NULL
109  ORDER BY last_name, first_name',
110  array($sectionId, $journalId, ROLE_ID_SECTION_EDITOR)
111  );
112 
113  while (!$result->EOF) {
114  $users[] =& $userDao->_returnUserFromRow($result->GetRowAssoc(false));
115  $result->moveNext();
116  }
117 
118  $result->Close();
119  unset($result);
120 
121  return $users;
122  }
123 
129  function deleteEditorsBySectionId($sectionId, $journalId = null) {
130  if (isset($journalId)) return $this->update(
131  'DELETE FROM section_editors WHERE journal_id = ? AND section_id = ?',
132  array($journalId, $sectionId)
133  );
134  else return $this->update(
135  'DELETE FROM section_editors WHERE section_id = ?',
136  $sectionId
137  );
138  }
139 
144  function deleteEditorsByJournalId($journalId) {
145  return $this->update(
146  'DELETE FROM section_editors WHERE journal_id = ?', $journalId
147  );
148  }
149 
156  function deleteEditorsByUserId($userId, $journalId = null, $sectionId = null) {
157  return $this->update(
158  'DELETE FROM section_editors WHERE user_id = ?' . (isset($journalId) ? ' AND journal_id = ?' : '') . (isset($sectionId) ? ' AND section_id = ?' : ''),
159  isset($journalId) && isset($sectionId) ? array($userId, $journalId, $sectionId)
160  : (isset($journalId) ? array($userId, $journalId)
161  : (isset($sectionId) ? array($userId, $sectionId) : $userId))
162  );
163  }
164 
172  function editorExists($journalId, $sectionId, $userId) {
173  $result =& $this->retrieve(
174  'SELECT COUNT(*) FROM section_editors WHERE journal_id = ? AND section_id = ? AND user_id = ?', array($journalId, $sectionId, $userId)
175  );
176  $returner = isset($result->fields[0]) && $result->fields[0] == 1 ? true : false;
177 
178  $result->Close();
179  unset($result);
180 
181  return $returner;
182  }
183 }
184 
185 ?>
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:29
deleteEditorsByUserId($userId, $journalId=null, $sectionId=null)
Class for DAO relating sections to editors.
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:83
editorExists($journalId, $sectionId, $userId)
& getEditorsBySectionId($journalId, $sectionId)
deleteEditorsByJournalId($journalId)
& getEditorsNotInSection($journalId, $sectionId)
& getDAO($name, $dbconn=null)
insertEditor($journalId, $sectionId, $userId, $canReview, $canEdit)
deleteEditor($journalId, $sectionId, $userId)
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:211
deleteEditorsBySectionId($sectionId, $journalId=null)