ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilSCGroups.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
25 {
26  private static ?ilSCGroups $instance = null;
27 
28  private array $groups = array();
29 
30  protected ilDBInterface $db;
31 
32  private function __construct()
33  {
34  global $DIC;
35 
36  $this->db = $DIC->database();
37  $this->read();
38  }
39 
40  public static function getInstance(): ilSCGroups
41  {
42  return self::$instance ?? (self::$instance = new self());
43  }
44 
45  public function updateFromComponentDefinition(string $a_component_id): int
46  {
47  foreach ($this->getGroups() as $group) {
48  if ($group->getComponentId() === $a_component_id) {
49  return $group->getId();
50  }
51  }
52 
53  $component_group = new ilSCGroup();
54  $component_group->setComponentId($a_component_id);
55  $component_group->create();
56 
57  return $component_group->getId();
58  }
59 
60  public function lookupGroupByComponentId(string $a_component_id): int
61  {
62  $query = 'SELECT id FROM sysc_groups ' .
63  'WHERE component = ' . $this->db->quote($a_component_id, ilDBConstants::T_TEXT);
64  $res = $this->db->query($query);
65  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
66  return (int) $row->id;
67  }
68  return 0;
69  }
70 
74  public function getGroups(): array
75  {
76  return $this->groups;
77  }
78 
79  protected function read(): void
80  {
81  $query = 'SELECT id FROM sysc_groups ' .
82  'ORDER BY id ';
83  $res = $this->db->query($query);
84 
85  $this->groups = array();
86  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
87  $this->groups[] = new ilSCGroup((int) $row->id);
88  }
89  }
90 }
$res
Definition: ltiservices.php:69
updateFromComponentDefinition(string $a_component_id)
global $DIC
Definition: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static ilSCGroups $instance
static getInstance()
$query
ilDBInterface $db
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
lookupGroupByComponentId(string $a_component_id)