ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilCloudPluginConfig.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once('./Modules/Cloud/exceptions/class.ilCloudPluginConfigException.php');
5
18{
22 protected $table_name = "";
23
27 protected $cache = array();
28
32 public function __construct($table_name)
33 {
34 $this->table_name = $table_name;
35 }
36
40 public function setTableName($table_name)
41 {
42 $this->table_name = $table_name;
43 }
44
48 public function getTableName()
49 {
50 return $this->table_name;
51 }
52
58 public function __call($method, $params)
59 {
60 $index = substr($method, 3);
61 if (substr($method, 0, 3) == 'get') {
62 if (!isset($this->cache[$index])) {
63 $this->cache[$index] = $this->getValue(self::_fromCamelCase(substr($method, 3)));
64 }
65 if ($this->cache[$index] == null) {
66 $this->cache[$index] = false;
67 }
68
69 return $this->cache[$index];
70 } elseif (substr($method, 0, 3) == 'set') {
71 $this->cache[$index] = $params[0];
72 $this->setValue(self::_fromCamelCase(substr($method, 3)), $params[0]);
73 return true;
74 } else {
76 }
77 }
78
83 public function setValue($key, $value)
84 {
85 global $DIC;
86 $ilDB = $DIC['ilDB'];
87
88 if (!$ilDB->tableExists($this->table_name)) {
90 }
91
92 if (!is_string($this->getValue($key))) {
93 $ilDB->insert($this->table_name, array("config_key" => array("text", $key), "config_value" => array("text", $value)));
94 } else {
95 $ilDB->update($this->table_name, array("config_key" => array("text", $key), "config_value" => array("text", $value)), array("config_key" => array("text", $key)));
96 }
97 }
98
103 public function getValue($key)
104 {
105 global $DIC;
106 $ilDB = $DIC['ilDB'];
107
108
109 if (!$this->tableExists($this->table_name)) {
111 }
112
113 $result = $ilDB->query("SELECT config_value FROM " . $this->table_name . " WHERE config_key = " . $ilDB->quote($key, "text"));
114
115 if ($result->numRows() == 0) {
116 return false;
117 }
118 $record = $ilDB->fetchAssoc($result);
119 return (string) $record['config_value'];
120 }
121
122
123
127 public function initDB()
128 {
129 global $DIC;
130 $ilDB = $DIC['ilDB'];
131
132 if (!$ilDB->tableExists($this->getTableName())) {
133 $fields = array(
134 'config_key' => array(
135 'type' => 'text',
136 'length' => 128,
137 'notnull' => true),
138 'config_value' => array(
139 'type' => 'clob',
140 'notnull' => false),);
141 $ilDB->createTable($this->getTableName(), $fields);
142 $ilDB->addPrimaryKey($this->getTableName(), array("config_key"));
143 }
144
145 return true;
146 }
147
148
149 //
150 // Helper
151 //
152
153
158 public static function _fromCamelCase($str)
159 {
160 $str[0] = strtolower($str[0]);
161 $func = create_function('$c', 'return "_" . strtolower($c[1]);');
162 return preg_replace_callback('/([A-Z])/', $func, $str);
163 }
164
170 public static function _toCamelCase($str, $capitalise_first_char = false)
171 {
172 if ($capitalise_first_char) {
173 $str[0] = strtoupper($str[0]);
174 }
175 $func = create_function('$c', 'return strtoupper($c[1]);');
176 return preg_replace_callback('/-([a-z])/', $func, $str);
177 }
178
179 public function tableExists()
180 {
181 global $DIC;
182 $ilDB = $DIC['ilDB'];
183 $result = $ilDB->query("show tables like '" . $this->getTableName() . "'");
184
185 if ($result->numRows() == 0) {
186 return false;
187 } else {
188 return true;
189 }
190 }
191}
$result
An exception for terminatinating execution or to throw for unit testing.
Class ilCloudPluginConfigException.
Class ilCloudPluginConfig.
static _toCamelCase($str, $capitalise_first_char=false)
$key
Definition: croninfo.php:18
$index
Definition: metadata.php:60
global $DIC
Definition: saml.php:7
global $ilDB
$params
Definition: disable.php:11