Open Journal Systems  2.4.3
 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  unset($result);
82 
83  return $returner;
84  }
85 
90  function &getDefaultSource() {
91  $result =& $this->retrieve(
92  'SELECT * FROM auth_sources WHERE auth_default = 1'
93  );
94 
95  $returner = null;
96  if ($result->RecordCount() != 0) {
97  $returner =& $this->_returnAuthSourceFromRow($result->GetRowAssoc(false));
98  }
99 
100  $result->Close();
101  unset($result);
102 
103  return $returner;
104  }
105 
110  function newDataObject() {
111  return new AuthSource();
112  }
113 
119  function &_returnAuthSourceFromRow(&$row) {
120  $auth = $this->newDataObject();
121  $auth->setAuthId($row['auth_id']);
122  $auth->setTitle($row['title']);
123  $auth->setPlugin($row['plugin']);
124  $auth->setPluginClass(@$this->plugins[$row['plugin']]);
125  $auth->setDefault($row['auth_default']);
126  $auth->setSettings(unserialize($row['settings']));
127  return $auth;
128  }
129 
134  function insertSource(&$auth) {
135  if (!isset($this->plugins[$auth->getPlugin()])) return false;
136  if (!$auth->getTitle()) $auth->setTitle($this->plugins[$auth->getPlugin()]->getDisplayName());
137  $this->update(
138  'INSERT INTO auth_sources
139  (title, plugin, settings)
140  VALUES
141  (?, ?, ?)',
142  array(
143  $auth->getTitle(),
144  $auth->getPlugin(),
145  serialize($auth->getSettings() ? $auth->getSettings() : array())
146  )
147  );
148 
149  $auth->setAuthId($this->getInsertId('auth_sources', 'auth_id'));
150  return $auth->getAuthId();
151  }
152 
157  function updateObject(&$auth) {
158  return $this->update(
159  'UPDATE auth_sources SET
160  title = ?,
161  settings = ?
162  WHERE auth_id = ?',
163  array(
164  $auth->getTitle(),
165  serialize($auth->getSettings() ? $auth->getSettings() : array()),
166  (int) $auth->getAuthId()
167  )
168  );
169  }
170 
171  function updateSource(&$auth) {
172  if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
173  return $this->updateObject($auth);
174  }
175 
180  function deleteObject($authId) {
181  return $this->update(
182  'DELETE FROM auth_sources WHERE auth_id = ?', $authId
183  );
184  }
185 
186  function deleteSource(&$auth) {
187  if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
188  return $this->deleteObject($auth);
189  }
190 
195  function setDefault($authId) {
196  $this->update(
197  'UPDATE auth_sources SET auth_default = 0'
198  );
199  $this->update(
200  'UPDATE auth_sources SET auth_default = 1 WHERE auth_id = ?',
201  array((int) $authId)
202  );
203  }
204 
209  function &getSources($rangeInfo = null) {
210  $result =& $this->retrieveRange(
211  'SELECT * FROM auth_sources ORDER BY auth_id',
212  false,
213  $rangeInfo
214  );
215 
216  $returner = new DAOResultFactory($result, $this, '_returnAuthSourceFromRow');
217  return $returner;
218  }
219 }
220 
221 ?>
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
& getSources($rangeInfo=null)
Operations for retrieving and modifying AuthSource objects.
& retrieveRange($sql, $params=false, $dbResultRange=null, $callHooks=true)
Definition: DAO.inc.php:176
& getSource($authId)
& _returnAuthSourceFromRow(&$row)
Wrapper around ADORecordSet providing &quot;factory&quot; features for generating objects from DAOs...
getVar($section, $key, $default=null)
Definition: Config.inc.php:34
Describes an authentication source.
& getPlugin($authId)
& loadCategory($category, $enabledOnly=false, $mainContextId=null)
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:211