ILIAS  trunk Revision v11.0_alpha-1702-gfd3ecb7f852
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\Blog\Settings;
22 
23 use ilDBInterface;
25 
27 {
28  public function __construct(
29  protected ilDBInterface $db,
30  protected InternalDataService $data
31  ) {
32  }
33 
34  protected function getSettingsFromRecord(array $rec): Settings
35  {
36  $order = explode(';', $rec['nav_order'] ?? "");
37  if (count($order) === 1 && current($order) === "") {
38  $order = [];
39  }
40  return $this->data->settings(
41  (int) $rec['id'],
42  (bool) $rec['ppic'],
43  (string) $rec['bg_color'],
44  (string) $rec['font_color'],
45  (bool) $rec['rss_active'],
46  (bool) $rec['approval'],
47  (bool) $rec['abs_shorten'],
48  (int) $rec['abs_shorten_len'],
49  (bool) $rec['abs_image'],
50  (int) $rec['abs_img_width'],
51  (int) $rec['abs_img_height'],
52  (bool) $rec['keywords'],
53  (bool) $rec['authors'],
54  (int) $rec['nav_mode'],
55  (int) $rec['nav_list_mon_with_post'],
56  (int) $rec['nav_list_mon'],
57  (int) $rec['ov_post'],
58  $order
59  );
60  }
61 
62  public function create(Settings $setting): void
63  {
64  $this->db->insert("il_blog", [
65  "id" => ["integer", $setting->getId()],
66  "ppic" => ["integer", $setting->getProfilePicture()],
67  "bg_color" => ["text", $setting->getBackgroundColor()],
68  "font_color" => ["text", $setting->getFontColor()],
69  "rss_active" => ["integer", $setting->getRSS()],
70  "approval" => ["integer", $setting->getApproval()],
71  "abs_shorten" => ["integer", $setting->getAbstractShorten()],
72  "abs_shorten_len" => ["integer", $setting->getAbstractShortenLength()],
73  "abs_image" => ["integer", $setting->getAbstractImage()],
74  "abs_img_width" => ["integer", $setting->getAbstractImageWidth()],
75  "abs_img_height" => ["integer", $setting->getAbstractImageHeight()],
76  "keywords" => ["integer", $setting->getKeywords()],
77  "authors" => ["integer", $setting->getAuthors()],
78  "nav_mode" => ["integer", $setting->getNavMode()],
79  "nav_list_mon_with_post" => ["integer", $setting->getNavModeListMonthsWithPostings()],
80  "nav_list_mon" => ["integer", $setting->getNavModeListMonths()],
81  "ov_post" => ["integer", $setting->getOverviewPostings()],
82  "nav_order" => ["text", implode(';', $setting->getOrder())]
83  ]);
84  }
85 
86  public function update(Settings $setting): void
87  {
88  $this->db->update("il_blog", [
89  "ppic" => ["integer", $setting->getProfilePicture()],
90  "bg_color" => ["text", $setting->getBackgroundColor()],
91  "font_color" => ["text", $setting->getFontColor()],
92  "rss_active" => ["integer", $setting->getRSS()],
93  "approval" => ["integer", $setting->getApproval()],
94  "abs_shorten" => ["integer", $setting->getAbstractShorten()],
95  "abs_shorten_len" => ["integer", $setting->getAbstractShortenLength()],
96  "abs_image" => ["integer", $setting->getAbstractImage()],
97  "abs_img_width" => ["integer", $setting->getAbstractImageWidth()],
98  "abs_img_height" => ["integer", $setting->getAbstractImageHeight()],
99  "keywords" => ["integer", $setting->getKeywords()],
100  "authors" => ["integer", $setting->getAuthors()],
101  "nav_mode" => ["integer", $setting->getNavMode()],
102  "nav_list_mon_with_post" => ["integer", $setting->getNavModeListMonthsWithPostings()],
103  "nav_list_mon" => ["integer", $setting->getNavModeListMonths()],
104  "ov_post" => ["integer", $setting->getOverviewPostings()],
105  "nav_order" => ["text", implode(';', $setting->getOrder())]
106  ], [
107  "id" => ["integer", $setting->getId() ?? 0]
108  ]);
109  }
110 
111  public function getByObjId(int $id): ?Settings
112  {
113  $set = $this->db->queryF(
114  "SELECT * FROM il_blog WHERE id = %s",
115  ["integer"],
116  [$id]
117  );
118 
119  $rec = $this->db->fetchAssoc($set);
120  if ($rec !== false) {
121  return $this->getSettingsFromRecord($rec);
122  }
123  return null;
124  }
125 
126  public function saveOrder(int $id, array $order): void
127  {
128  $this->db->update(
129  "il_blog",
130  [
131  "nav_order" => ["", implode(';', $order)]
132  ],
133  [
134  "id" => ["integer", $id]
135  ]
136  );
137  }
138 
139 }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
ilSetting $setting
Definition: class.ilias.php:68
__construct(protected ilDBInterface $db, protected InternalDataService $data)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23