ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
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  $flash_mode = ($record['flash_mode'] == "")
73  ? "term"
74  : $record['flash_mode'];
75  return $this->data->settings(
76  (int) $record['id'],
77  $this->textToBool($record['is_online']),
78  (string) $record['virtual'],
79  $this->textToBool($record['glo_menu_active']),
80  (string) $record['pres_mode'],
81  (int) $record['show_tax'],
82  (int) $record['snippet_length'],
83  $this->textToBool($record['flash_active']),
84  (string) $flash_mode
85  );
86  }
87 
88  protected function boolToText(bool $value): string
89  {
90  return $value ? 'y' : 'n';
91  }
92 
93  protected function textToBool(string $value): bool
94  {
95  return $value === 'y';
96  }
97 }
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