ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilECSCommunitiesCache.php
Go to the documentation of this file.
1 <?php
24 include_once './Services/WebServices/ECS/classes/class.ilECSCommunityCache.php';
25 
35 {
36  private static $instance = null;
37 
38  private $communities = array();
39 
43  protected function __construct()
44  {
45  $this->read();
46  }
47 
52  public static function getInstance()
53  {
54  if(isset(self::$instance))
55  {
56  return self::$instance;
57  }
58  return self::$instance = new ilECSCommunitiesCache();
59  }
60 
65  public static function delete($a_server_id)
66  {
67  global $ilDB;
68 
69  $query = 'DELETE FROM ecs_community '.
70  'WHERE sid = '.$ilDB->quote($a_server_id,'integer');
71  $ilDB->manipulate($query);
72  }
73 
78  public function getCommunities()
79  {
80  return (array) $this->communities;
81  }
82 
86  public function lookupOwnId($a_server_id,$a_mid)
87  {
88  foreach($this->getCommunities() as $com)
89  {
90  if($com->getServerId() == $a_server_id)
91  {
92  if(in_array($a_mid,$com->getMids()))
93  {
94  return $com->getOwnId();
95  }
96  }
97  }
98  return 0;
99  }
100 
106  public function lookupTitle($a_server_id, $a_mid)
107  {
108  foreach($this->getCommunities() as $com)
109  {
110  if($com->getServerId() == $a_server_id)
111  {
112  if(in_array($a_mid, $com->getMids()))
113  {
114  return $com->getCommunityName();
115  }
116  }
117  }
118  return '';
119  }
120 
124  private function read()
125  {
126  global $ilDB;
127 
128  $query = 'SELECT sid,cid FROM ecs_community ';
129  $res = $ilDB->query($query);
130  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
131  {
132  $this->communities[] = ilECSCommunityCache::getInstance($row->sid, $row->cid);
133  }
134  return true;
135  }
136 }
137 
138 ?>