ILIAS  trunk Revision v11.0_alpha-1851-ga8564da6fed
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
SettingsDBRepository.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\Glossary\Settings;
22 
23 use ilDBInterface;
25 
27 {
28  public function __construct(
29  protected ilDBInterface $db,
30  protected InternalDataService $data
31  ) {
32  }
33 
34  public function update(Settings $settings): void
35  {
36  $this->db->update(
37  'glossary',
38  [
39  'is_online' => ['text', $this->boolToText($settings->getOnline())],
40  'virtual' => ['text', $settings->getVirtualMode()],
41  'glo_menu_active' => ['text', $this->boolToText($settings->getActiveGlossaryMenu())],
42  'pres_mode' => ['text', $settings->getPresentationMode()],
43  'show_tax' => ['integer', $settings->getShowTaxonomy()],
44  'snippet_length' => ['integer', $settings->getSnippetLength()],
45  'flash_active' => ['text', $this->boolToText($settings->getActiveFlashcards())],
46  'flash_mode' => ['text', $settings->getFlashcardsMode()]
47  ],
48  [
49  'id' => ['integer', $settings->getId()]
50  ]
51  );
52  }
53 
54  public function getById(int $id): ?Settings
55  {
56  $set = $this->db->queryF(
57  'SELECT * FROM glossary WHERE id = %s',
58  ['integer'],
59  [$id]
60  );
61 
62  $record = $this->db->fetchAssoc($set);
63  if ($record) {
64  return $this->getSettingsFromRecord($record);
65  }
66 
67  return null;
68  }
69 
70  protected function getSettingsFromRecord(array $record): Settings
71  {
72  return $this->data->settings(
73  (int) $record['id'],
74  $this->textToBool($record['is_online']),
75  (string) $record['virtual'],
76  $this->textToBool($record['glo_menu_active']),
77  (string) $record['pres_mode'],
78  (int) $record['show_tax'],
79  (int) $record['snippet_length'],
80  $this->textToBool($record['flash_active']),
81  (string) $record['flash_mode']
82  );
83  }
84 
85  protected function boolToText(bool $value): string
86  {
87  return $value ? 'y' : 'n';
88  }
89 
90  protected function textToBool(string $value): bool
91  {
92  return $value === 'y';
93  }
94 }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
__construct(protected ilDBInterface $db, protected InternalDataService $data)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23