2 require_once(
'./Services/GlobalCache/classes/class.ilGlobalCache.php');
70 if ($this->global_cache->isActive()) {
71 $data = $this->global_cache->get($this->
getTableName() .
'_raw_data');
73 if (is_array($data)) {
83 if ($this->global_cache->isActive()) {
90 protected function readFromDB() {
96 $res = $ilDB->query($q);
98 while ($set = $ilDB->fetchObject(
$res)) {
112 public function getWhere($field, $value, $case_sensitive =
true) {
128 public function filter(array $data, $field, $value, $case_sensitive =
true, $strip =
true) {
129 if (is_array($value)) {
130 $index = md5(serialize($value)) . $case_sensitive;
132 $index = $value . $case_sensitive;
134 if (isset($this->cached_results[$this->
getTableName()][$field][$index])) {
135 return $this->cached_results[$this->
getTableName()][$field][$index];
138 foreach ($data as $dat) {
139 if ($case_sensitive) {
140 if (is_array($value)) {
141 if (in_array($dat->{$field}, $value)) {
144 } elseif ($dat->{$field} == $value) {
149 if (is_array($value)) {
150 if (preg_grep(
"/" . $dat->{$field} .
"/i", $value)) {
153 } elseif (strcasecmp($dat->{$field}, $value) == 0) {
158 if (count(
$result) == 1 AND $strip) {
162 $this->cached_results[$this->getTableName()][$field][$index] =
$result;
163 $this->updateCachedResults();
170 $this->global_cache->set($this->getTableName() .
'_cached_results', $this->getCachedResults());
181 public function where($field, $value, $case_sensitive =
true) {
183 $ilGcDbWhere->setField($field);
184 $ilGcDbWhere->setValue($value);
185 $ilGcDbWhere->setCaseSensitive($case_sensitive);
186 $this->wheres[] = $ilGcDbWhere;
197 public function get($strip =
true) {
199 foreach ($this->wheres as $ilGcDbWhere) {
200 $result = $this->filter(
$result, $ilGcDbWhere->getField(), $ilGcDbWhere->getValue(), $ilGcDbWhere->getCaseSensitive(),
false);
203 if (count(
$result) == 1 AND $strip) {
219 if (! isset(self::$instances[$component . $table_name])) {
220 self::$instances[$component . $table_name] =
new self($component, $table_name);
223 return self::$instances[$component . $table_name];
231 $this->cached_results = $cached_results;
239 return $this->cached_results;
247 $this->raw_data = $raw_data;
255 return $this->raw_data;
263 $this->table_name = $table_name;
271 return $this->table_name;
279 $this->loaded = $loaded;
287 return $this->loaded;
295 $this->component = $component;
303 return $this->component;