Open Journal Systems  3.0.0
 All Classes Namespaces Functions Variables Groups Pages
AuthSourceDAO.inc.php
1 <?php
2 
18 import('lib.pkp.classes.security.AuthSource');
19 
20 class AuthSourceDAO extends DAO {
21  var $plugins;
22 
26  function AuthSourceDAO() {
27  parent::DAO();
28  $this->plugins =& PluginRegistry::loadCategory(AUTH_PLUGIN_CATEGORY);
29  }
30 
36  function &getPlugin($authId) {
37  $plugin = null;
38  $auth =& $this->getSource($authId);
39  if ($auth != null) {
40  $plugin =& $auth->getPluginClass();
41  if ($plugin != null) {
42  $plugin =& $plugin->getInstance($auth->getSettings(), $auth->getAuthId());
43  }
44  }
45  return $plugin;
46  }
47 
52  function &getDefaultPlugin() {
53  $plugin = null;
54  $auth =& $this->getDefaultSource();
55  if ($auth != null) {
56  $plugin =& $auth->getPluginClass();
57  if ($plugin != null) {
58  $plugin =& $plugin->getInstance($auth->getSettings(), $auth->getAuthId());
59  }
60  }
61  return $plugin;
62  }
63 
69  function &getSource($authId) {
70  $result = $this->retrieve(
71  'SELECT * FROM auth_sources WHERE auth_id = ?',
72  array((int) $authId)
73  );
74 
75  $returner = null;
76  if ($result->RecordCount() != 0) {
77  $returner =& $this->_returnAuthSourceFromRow($result->GetRowAssoc(false));
78  }
79 
80  $result->Close();
81  return $returner;
82  }
83 
88  function &getDefaultSource() {
89  $result = $this->retrieve(
90  'SELECT * FROM auth_sources WHERE auth_default = 1'
91  );
92 
93  $returner = null;
94  if ($result->RecordCount() != 0) {
95  $returner =& $this->_returnAuthSourceFromRow($result->GetRowAssoc(false));
96  }
97 
98  $result->Close();
99  return $returner;
100  }
101 
106  function newDataObject() {
107  return new AuthSource();
108  }
109 
115  function &_returnAuthSourceFromRow($row) {
116  $auth = $this->newDataObject();
117  $auth->setAuthId($row['auth_id']);
118  $auth->setTitle($row['title']);
119  $auth->setPlugin($row['plugin']);
120  $auth->setPluginClass(@$this->plugins[$row['plugin']]);
121  $auth->setDefault($row['auth_default']);
122  $auth->setSettings(unserialize($row['settings']));
123  return $auth;
124  }
125 
130  function insertSource(&$auth) {
131  if (!isset($this->plugins[$auth->getPlugin()])) return false;
132  if (!$auth->getTitle()) $auth->setTitle($this->plugins[$auth->getPlugin()]->getDisplayName());
133  $this->update(
134  'INSERT INTO auth_sources
135  (title, plugin, settings)
136  VALUES
137  (?, ?, ?)',
138  array(
139  $auth->getTitle(),
140  $auth->getPlugin(),
141  serialize($auth->getSettings() ? $auth->getSettings() : array())
142  )
143  );
144 
145  $auth->setAuthId($this->_getInsertId('auth_sources', 'auth_id'));
146  return $auth->getAuthId();
147  }
148 
153  function updateObject(&$auth) {
154  return $this->update(
155  'UPDATE auth_sources SET
156  title = ?,
157  settings = ?
158  WHERE auth_id = ?',
159  array(
160  $auth->getTitle(),
161  serialize($auth->getSettings() ? $auth->getSettings() : array()),
162  (int) $auth->getAuthId()
163  )
164  );
165  }
166 
171  function deleteObject($authId) {
172  return $this->update(
173  'DELETE FROM auth_sources WHERE auth_id = ?', $authId
174  );
175  }
176 
181  function setDefault($authId) {
182  $this->update(
183  'UPDATE auth_sources SET auth_default = 0'
184  );
185  $this->update(
186  'UPDATE auth_sources SET auth_default = 1 WHERE auth_id = ?',
187  array((int) $authId)
188  );
189  }
190 
195  function &getSources($rangeInfo = null) {
196  $result = $this->retrieveRange(
197  'SELECT * FROM auth_sources ORDER BY auth_id',
198  false,
199  $rangeInfo
200  );
201 
202  $returner = new DAOResultFactory($result, $this, '_returnAuthSourceFromRow');
203  return $returner;
204  }
205 }
206 
207 ?>
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:30
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:84
& getSources($rangeInfo=null)
Operations for retrieving and modifying AuthSource objects.
static & loadCategory($category, $enabledOnly=false, $mainContextId=null)
& _returnAuthSourceFromRow($row)
& retrieveRange($sql, $params=false, $dbResultRange=null, $callHooks=true)
Definition: DAO.inc.php:174
_getInsertId($table= '', $id= '')
Definition: DAO.inc.php:249
& getSource($authId)
Wrapper around ADORecordSet providing &quot;factory&quot; features for generating objects from DAOs...
Describes an authentication source.
& getPlugin($authId)
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:208