ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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 $DIC;
122
123 $ilDB = $DIC['ilDB'];
124
125 if (!$this->entryExists) {
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 $DIC;
148
149 $ilDB = $DIC['ilDB'];
150
151 $query = 'INSERT INTO ecs_community (sid,cid,own_id,cname,mids) ' .
152 'VALUES( ' .
153 $ilDB->quote($this->getServerId(), 'integer') . ', ' .
154 $ilDB->quote($this->getCommunityId(), 'integer') . ', ' .
155 $ilDB->quote($this->getOwnId(), 'integer') . ', ' .
156 $ilDB->quote($this->getCommunityName(), 'text') . ', ' .
157 $ilDB->quote(serialize($this->getMids()), 'text') . ' ' .
158 ')';
159 $ilDB->manipulate($query);
160 return true;
161 }
162
168 protected function read()
169 {
170 global $DIC;
171
172 $ilDB = $DIC['ilDB'];
173
174 $this->entryExists = false;
175
176 $query = 'SELECT * FROM ecs_community ' .
177 'WHERE sid = ' . $ilDB->quote($this->getServerId(), 'integer') . ' ' .
178 'AND cid = ' . $ilDB->quote($this->getCommunityId(), 'integer');
179 $res = $ilDB->query($query);
180 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
181 $this->entryExists = true;
182 $this->setOwnId($row->own_id);
183 $this->setCommunityName($row->cname);
184 $this->setMids(unserialize($row->mids));
185 }
186 return true;
187 }
188
189 public static function deleteByServerId($a_server_id)
190 {
191 global $DIC;
192
193 $ilDB = $DIC['ilDB'];
194
195 $query = 'DELETE FROM ecs_community' .
196 ' WHERE sid = ' . $ilDB->quote($a_server_id, 'integer');
197 $ilDB->manipulate($query);
198 return true;
199 }
200}
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
$DIC
Definition: xapitoken.php:46