ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilGlobalCacheQueryWrapper.php
Go to the documentation of this file.
1 <?php
2 require_once('./Services/GlobalCache/classes/class.ilGlobalCache.php');
3 
13 {
14  const FETCH_TYPE_ASSOC = 1;
15  const FETCH_TYPE_OBJECT = 2;
16  const MODE_SINGLE = 1;
17  const MODE_MULTIPLE = 2;
21  protected $query = '';
25  protected $cache_key = '';
29  protected $fetch_type = self::FETCH_TYPE_OBJECT;
33  protected $mode = self::MODE_SINGLE;
34 
35 
42  public function __construct($cache_key, $query, $fetch_type = self::FETCH_TYPE_OBJECT, $mode = self::MODE_SINGLE)
43  {
44  $this->cache_key = $cache_key;
45  $this->fetch_type = $fetch_type;
46  $this->mode = $mode;
47  $this->query = $query;
48  }
49 
50 
54  public function get()
55  {
56  $ilGlobalCache = ilGlobalCache::getInstance();
57  if ($ilGlobalCache->isActive()) {
58  $rec = $ilGlobalCache->get($this->cache_key);
59  if (!$rec) {
60  $rec = $this->getFromDb();
61  $ilGlobalCache->set($this->cache_key, $rec, 600);
62  }
63  } else {
64  $rec = $this->getFromDb();
65  }
66 
67  return $rec;
68  }
69 
70 
74  protected function getFromDb()
75  {
76  global $DIC;
77  $ilDB = $DIC['ilDB'];
81  $return = array();
82  $res = $ilDB->query($this->query);
83  switch ($this->getFetchType()) {
84  case self::FETCH_TYPE_OBJECT:
85  while ($rec = $ilDB->fetchObject($res)) {
86  $return[] = $rec;
87  }
88  break;
89  case self::FETCH_TYPE_ASSOC:
90  while ($rec = $ilDB->fetchAssoc($res)) {
91  $return[] = $rec;
92  }
93  break;
94  }
95 
96  if ($this->getMode() == self::MODE_SINGLE) {
97  return $return[0];
98  } else {
99  return $return;
100  }
101  }
102 
103 
107  public function setFetchType($fetch_type)
108  {
109  $this->fetch_type = $fetch_type;
110  }
111 
112 
116  public function getFetchType()
117  {
118  return $this->fetch_type;
119  }
120 
121 
125  public function setMode($mode)
126  {
127  $this->mode = $mode;
128  }
129 
130 
134  public function getMode()
135  {
136  return $this->mode;
137  }
138 }
global $DIC
Definition: saml.php:7
static getInstance($component)
Class ilGlobalCacheQueryWrapper.
foreach($_POST as $key=> $value) $res
__construct($cache_key, $query, $fetch_type=self::FETCH_TYPE_OBJECT, $mode=self::MODE_SINGLE)
global $ilDB