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 ()
 

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 3132 of file grima-lib.php.

Member Function Documentation

◆ getDb()

static GrimaDB::getDb ( )
staticprotected

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

References join_paths().

Referenced by GrimaInstitution\addToDB(), GrimaUser\addToDB(), GrimaUser\deleteFromDB(), and GrimaUser\updateDB().

3158  {
3159  if (!self::$db) {
3160  $db_url = getenv('DATABASE_URL');
3161  if (!$db_url) $db_url = "sqlite:" . join_paths( sys_get_temp_dir(), "grima/grima.sql");
3162  self::$db = new PDO($db_url);
3163  }
3164  return self::$db;
3165  }
join_paths(... $paths)
Definition: grima-util.php:114

◆ getIterator()

GrimaDB::getIterator ( )

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

3189  {
3190  return new ArrayIterator($this->info);
3191  }

◆ getPasswordAlgorithm()

GrimaDB::getPasswordAlgorithm ( )
protected

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

Referenced by GrimaUser\addToDB(), and GrimaUser\updateDB().

3166  {
3167  return defined("PASSWORD_ARGON2I") ? constant("PASSWORD_ARGON2I") : PASSWORD_DEFAULT;
3168  }

◆ init()

static GrimaDB::init ( )
static

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

References $db, and tableExists().

3133  {
3134  try {
3135  $db = self::getDb();
3136  if (!tableExists($db,"institutions")) {
3137  $db->exec("CREATE TABLE institutions ( institution VARCHAR(100) PRIMARY KEY, apikey VARCHAR(100), server VARCHAR(100) )");
3138  }
3139  if (!tableExists($db,"users")) {
3140  $db->exec("CREATE TABLE users ( institution VARCHAR(100), username VARCHAR(100), password VARCHAR(255), isAdmin BOOLEAN )");
3141  }
3142  return true;
3143  } catch(Exception $x) {
3144  # create the database
3145  return false;
3146  }
3147  }
tableExists($pdo, $table)
Definition: grima-lib.php:3113
static $db
Definition: grima-lib.php:3170

◆ isEmpty()

static GrimaDB::isEmpty ( )
static

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

References $db.

3148  {
3149  self::init();
3150  $db = self::getDb();
3151  $result = $db->query( 'SELECT COUNT(*) as c FROM institutions' );
3152  foreach( $result as $row ) {
3153  if ($row['c']>0) return false;
3154  }
3155  return true;
3156  }
static $db
Definition: grima-lib.php:3170

◆ offsetExists()

GrimaDB::offsetExists (   $offset)

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

3173  {
3174  return isset($this->info[$offset]);
3175  }

◆ offsetGet()

GrimaDB::offsetGet (   $offset)

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

3177  {
3178  return isset($this->info[$offset]) ? $this->info[$offset] : '';
3179  }

◆ offsetSet()

GrimaDB::offsetSet (   $offset,
  $value 
)

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

3181  {
3182  $this->info[$offset] = $value;
3183  }

◆ offsetUnset()

GrimaDB::offsetUnset (   $offset)

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

3185  {
3186  unset($this->info[$offset]);
3187  }

Member Data Documentation

◆ $db

GrimaDB::$db = FALSE
staticprivate

◆ $info

GrimaDB::$info
private

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


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