ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilOpenIdProviders.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once './Services/OpenId/classes/class.ilOpenIdProvider.php';
5 
14 {
15  private static $instance = null;
16 
17  private $providers = array();
18 
23  protected function __construct()
24  {
25  $this->read();
26  }
27 
32  public static function getInstance()
33  {
34  if(self::$instance)
35  {
36  return self::$instance;
37  }
38  return self::$instance = new ilOpenIdProviders();
39  }
40 
45  public function getProvider()
46  {
47  return (array) $this->providers;
48  }
49 
56  public function getProviderById($a_provider_id)
57  {
58  foreach($this->getProvider() as $provider)
59  {
60  if($provider->getId() == $a_provider_id)
61  {
62  return $provider;
63  }
64  }
65  throw new UnexpectedValueException();
66  }
67 
72  public function getProviderSelection()
73  {
74  global $lng;
75 
76  $options[0] = $lng->txt('select_one');
77  foreach($this->getProvider() as $provider)
78  {
79  $options[$provider->getId()] = $provider->getName();
80  }
81  return $options;
82  }
83 
90  public function getSelectedProvider()
91  {
92  include_once './Services/OpenId/classes/class.ilOpenIdSettings.php';
93  if(count($this->getProvider()) != 1 or !ilOpenIdSettings::getInstance()->forcedProviderSelection())
94  {
95  return 0;
96  }
97 
98  foreach($this->getProvider() as $pro)
99  {
100  return $pro->getId();
101  }
102  return 0;
103  }
104 
109  private function read()
110  {
111  global $ilDB;
112 
113  $query = "SELECT provider_id FROM openid_provider ORDER BY name ";
114  $res = $ilDB->query($query);
115  while($row = $res->fetchRow(DB_FETCHMODE_ASSOC))
116  {
117  $this->providers[] = new ilOpenIdProvider($row['provider_id']);
118  }
119  return true;
120  }
121 }
122 ?>