ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 return self::$instance[$a_sid][$a_cid];
68 }
69 return self::$instance[$a_sid][$a_cid] = new ilECSCommunityCache($a_sid, $a_cid);
70 }
71
72
73
74 public function getServerId()
75 {
76 return $this->sid;
77 }
78
79 public function getCommunityId()
80 {
81 return $this->cid;
82 }
83
84 public function setOwnId($a_id)
85 {
86 $this->own_id = $a_id;
87 }
88
89 public function getOwnId()
90 {
91 return $this->own_id;
92 }
93
94 public function setCommunityName($a_name)
95 {
96 $this->cname = $a_name;
97 }
98
99 public function getCommunityName()
100 {
101 return $this->cname;
102 }
103
104 public function setMids($a_mids)
105 {
106 $this->mids = $a_mids;
107 }
108
109 public function getMids()
110 {
111 return $this->mids;
112 }
113
119 public function update()
120 {
121 global $ilDB;
122
123 if (!$this->entryExists) {
124 return $this->create();
125 }
126
127 $query = 'UPDATE ecs_community ' .
128 'SET own_id = ' . $ilDB->quote($this->getOwnId(), 'integer') . ', ' .
129 'cname = ' . $ilDB->quote($this->getCommunityName(), 'text') . ', ' .
130 'mids = ' . $ilDB->quote(serialize($this->getMids()), 'text') . ' ' .
131 'WHERE sid = ' . $ilDB->quote($this->getServerId(), 'integer') . ' ' .
132 'AND cid = ' . $ilDB->quote($this->getCommunityId(), 'integer');
133 $ilDB->manipulate($query);
134 return true;
135 }
136
137
138
143 protected function create()
144 {
145 global $ilDB;
146
147 $query = 'INSERT INTO ecs_community (sid,cid,own_id,cname,mids) ' .
148 'VALUES( ' .
149 $ilDB->quote($this->getServerId(), 'integer') . ', ' .
150 $ilDB->quote($this->getCommunityId(), 'integer') . ', ' .
151 $ilDB->quote($this->getOwnId(), 'integer') . ', ' .
152 $ilDB->quote($this->getCommunityName(), 'text') . ', ' .
153 $ilDB->quote(serialize($this->getMids()), 'text') . ' ' .
154 ')';
155 $ilDB->manipulate($query);
156 return true;
157 }
158
164 protected function read()
165 {
166 global $ilDB;
167
168 $this->entryExists = false;
169
170 $query = 'SELECT * FROM ecs_community ' .
171 'WHERE sid = ' . $ilDB->quote($this->getServerId(), 'integer') . ' ' .
172 'AND cid = ' . $ilDB->quote($this->getCommunityId(), 'integer');
173 $res = $ilDB->query($query);
174 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
175 $this->entryExists = true;
176 $this->setOwnId($row->own_id);
177 $this->setCommunityName($row->cname);
178 $this->setMids(unserialize($row->mids));
179 }
180 return true;
181 }
182
183 public static function deleteByServerId($a_server_id)
184 {
185 global $ilDB;
186
187 $query = 'DELETE FROM ecs_community' .
188 ' WHERE sid = ' . $ilDB->quote($a_server_id, 'integer');
189 $ilDB->manipulate($query);
190 return true;
191 }
192}
An exception for terminatinating execution or to throw for unit testing.
+--------------------------------------------------------------------------—+ | 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.
$query
foreach($_POST as $key=> $value) $res
global $ilDB