Grima  2018-08
Whispering into Alma's ear
Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Private Attributes | Static Private Attributes | List of all members
GrimaDB Class Reference

Shared access to the database for GrimaUser and GrimaInstitution. More...

Inheritance diagram for GrimaDB:
GrimaInstitution GrimaUser

Public Member Functions

  offsetExists ($offset)
 
  offsetGet ($offset)
 
  offsetSet ($offset, $value)
 
  offsetUnset ($offset)
 
  getIterator ()
 

Static Public Member Functions

static  init ()
 
static  isEmpty ()
 
static  isStateless ()
 
static  getInstitutions ()
 

Protected Member Functions

  getPasswordAlgorithm ()
 

Static Protected Member Functions

static  getDb ()
 

Private Attributes

  $info
 

Static Private Attributes

static  $db = FALSE
 

Detailed Description

Shared access to the database for GrimaUser and GrimaInstitution.

Definition at line 3896 of file grima-lib.php.

Member Function Documentation

◆ getDb()

static GrimaDB::getDb ( )
staticprotected

Definition at line 3919 of file grima-lib.php.

References getenvWithFileFallbackAndDefault(), and tableExists().

3919  {
3920  if (!self::$db) {
3921  try {
3922  $db_url = getenvWithFileFallbackAndDefault('DATABASE_URL','');
3923  $db_user = getenvWithFileFallbackAndDefault('DATABASE_USER','');
3924  $db_pass = getenvWithFileFallbackAndDefault('DATABASE_PASS','');
3925  if ($db_user && $db_pass) {
3926  self::$db = new PDO($db_url, $db_user, $db_pass);
3927  } else {
3928  self::$db = new PDO($db_url);
3929  }
3930  if (!tableExists(self::$db,"institutions")) {
3931  self::$db->exec("CREATE TABLE institutions ( institution VARCHAR(100) PRIMARY KEY, apikey VARCHAR(100), server VARCHAR(100) )");
3932  }
3933  if (!tableExists(self::$db,"users")) {
3934  self::$db->exec("CREATE TABLE users ( institution VARCHAR(100), username VARCHAR(100), password VARCHAR(255), isAdmin INTEGER )");
3935  }
3936  } catch (Exception $e) {
3937  self::$db = 'stateless';
3938  }
3939  }
3940  return self::$db;
3941  }
tableExists($pdo, $table)
Definition: grima-lib.php:3877
getenvWithFileFallbackAndDefault( $env_name, $default=false)
Definition: grima-util.php:52

◆ getInstitutions()

static GrimaDB::getInstitutions ( )
static

Definition at line 3947 of file grima-lib.php.

Referenced by GrimaFormField\__construct().

3947  {
3948  $ret = array();
3949  try {
3950  $db = self::getDb();
3951  $result = $db->query( 'SELECT institution FROM institutions' );
3952  foreach( $result as $row ) {
3953  $ret[] = $row['institution'];
3954  }
3955  } catch (Exception $e) {
3956  }
3957  return $ret;
3958  }
static $db
Definition: grima-lib.php:3898

◆ getIterator()

GrimaDB::getIterator ( )

Definition at line 3976 of file grima-lib.php.

3976  {
3977  return new ArrayIterator($this->info);
3978  }

◆ getPasswordAlgorithm()

GrimaDB::getPasswordAlgorithm ( )
protected

Definition at line 3943 of file grima-lib.php.

3943  {
3944  return defined("PASSWORD_ARGON2I") ? constant("PASSWORD_ARGON2I") : PASSWORD_DEFAULT;
3945  }

◆ init()

static GrimaDB::init ( )
static

Definition at line 3901 of file grima-lib.php.

3901  {
3902  return self::getDb();
3903  }

◆ isEmpty()

static GrimaDB::isEmpty ( )
static

Definition at line 3905 of file grima-lib.php.

3905  {
3906  $db = self::getDb();
3907  $result = $db->query( 'SELECT COUNT(*) as c FROM institutions' );
3908  foreach( $result as $row ) {
3909  if ($row['c']>0) return false;
3910  }
3911  return true;
3912  }
static $db
Definition: grima-lib.php:3898

◆ isStateless()

static GrimaDB::isStateless ( )
static

Definition at line 3914 of file grima-lib.php.

3914  {
3915  $db = self::getDb();
3916  return $db === 'stateless';
3917  }
static $db
Definition: grima-lib.php:3898

◆ offsetExists()

GrimaDB::offsetExists (   $offset )

Definition at line 3960 of file grima-lib.php.

3960  {
3961  return isset($this->info[$offset]);
3962  }

◆ offsetGet()

GrimaDB::offsetGet (   $offset )

Definition at line 3964 of file grima-lib.php.

3964  {
3965  return isset($this->info[$offset]) ? $this->info[$offset] : '';
3966  }

◆ offsetSet()

GrimaDB::offsetSet (   $offset,
  $value 
)

Definition at line 3968 of file grima-lib.php.

3968  {
3969  $this->info[$offset] = $value;
3970  }

◆ offsetUnset()

GrimaDB::offsetUnset (   $offset )

Definition at line 3972 of file grima-lib.php.

3972  {
3973  unset($this->info[$offset]);
3974  }

Member Data Documentation

◆ $db

GrimaDB::$db = FALSE
staticprivate

Definition at line 3898 of file grima-lib.php.

◆ $info

GrimaDB::$info
private

Definition at line 3899 of file grima-lib.php.


The documentation for this class was generated from the following file: