ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilECSCommunityCache.php
Go to the documentation of this file.
1<?php
33{
34 protected static $instance = null;
35
36 protected $sid = 0;
37 protected $cid = 0;
38 protected $own_id = 0;
39 protected $cname = '';
40 protected $mids = array();
41
42 protected $entryExists = false;
43
44
50 protected function __construct($sid,$cid)
51 {
52 $this->sid = $sid;
53 $this->cid = $cid;
54
55 $this->read();
56 }
57
64 public static function getInstance($a_sid,$a_cid)
65 {
66 if(isset(self::$instance[$a_sid][$a_cid]))
67 {
68 return self::$instance[$a_sid][$a_cid];
69 }
70 return self::$instance[$a_sid][$a_cid] = new ilECSCommunityCache($a_sid, $a_cid);
71 }
72
73
74
75 public function getServerId()
76 {
77 return $this->sid;
78 }
79
80 public function getCommunityId()
81 {
82 return $this->cid;
83 }
84
85 public function setOwnId($a_id)
86 {
87 $this->own_id = $a_id;
88 }
89
90 public function getOwnId()
91 {
92 return $this->own_id;
93 }
94
95 public function setCommunityName($a_name)
96 {
97 $this->cname = $a_name;
98 }
99
100 public function getCommunityName()
101 {
102 return $this->cname;
103 }
104
105 public function setMids($a_mids)
106 {
107 $this->mids = $a_mids;
108 }
109
110 public function getMids()
111 {
112 return $this->mids;
113 }
114
120 public function update()
121 {
122 global $ilDB;
123
124 if(!$this->entryExists)
125 {
126 return $this->create();
127 }
128
129 $query = 'UPDATE ecs_community '.
130 'SET own_id = '.$ilDB->quote($this->getOwnId(),'integer').', '.
131 'cname = '.$ilDB->quote($this->getCommunityName(),'text').', '.
132 'mids = '.$ilDB->quote(serialize($this->getMids()),'text').' '.
133 'WHERE sid = '.$ilDB->quote($this->getServerId(),'integer').' '.
134 'AND cid = '.$ilDB->quote($this->getCommunityId(),'integer');
135 $ilDB->manipulate($query);
136 return true;
137 }
138
139
140
145 protected function create()
146 {
147 global $ilDB;
148
149 $query = 'INSERT INTO ecs_community (sid,cid,own_id,cname,mids) '.
150 'VALUES( '.
151 $ilDB->quote($this->getServerId(),'integer').', '.
152 $ilDB->quote($this->getCommunityId(),'integer').', '.
153 $ilDB->quote($this->getOwnId(),'integer').', '.
154 $ilDB->quote($this->getCommunityName(), 'text').', '.
155 $ilDB->quote(serialize($this->getMids()),'text').' '.
156 ')';
157 $ilDB->manipulate($query);
158 return true;
159 }
160
166 protected function read()
167 {
168 global $ilDB;
169
170 $this->entryExists = false;
171
172 $query = 'SELECT * FROM ecs_community '.
173 'WHERE sid = '.$ilDB->quote($this->getServerId(),'integer').' '.
174 'AND cid = '.$ilDB->quote($this->getCommunityId(),'integer');
175 $res = $ilDB->query($query);
176 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
177 {
178 $this->entryExists = true;
179 $this->setOwnId($row->own_id);
180 $this->setCommunityName($row->cname);
181 $this->setMids(unserialize($row->mids));
182 }
183 return true;
184 }
185
186 public static function deleteByServerId($a_server_id)
187 {
188 global $ilDB;
189
190 $query = 'DELETE FROM ecs_community'.
191 ' WHERE sid = '.$ilDB->quote($a_server_id,'integer');
192 $ilDB->manipulate($query);
193 return true;
194 }
195}
196?>
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
+--------------------------------------------------------------------------—+ | ILIAS open source | +...
create()
Create new dataset @global ilDB $ilDB.
read()
Read dataset @global ilDB $ilDB.
static deleteByServerId($a_server_id)
__construct($sid, $cid)
Singleton constructor.
static getInstance($a_sid, $a_cid)
Get instance.
update()
Create or update ecs community @global ilDB $ilDB.
global $ilDB