ILIAS  trunk Revision v11.0_alpha-1689-g66c127b4ae8
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilLearningSequenceSettingsDB.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
25 {
26  public const TABLE_NAME = 'lso_settings';
27 
30 
31  public function __construct(ilDBInterface $database, ilLearningSequenceFilesystem $ls_filesystem)
32  {
33  $this->database = $database;
34  $this->ls_filesystem = $ls_filesystem;
35  }
36 
37  public function store(ilLearningSequenceSettings $settings): void
38  {
39  $uploads = $settings->getUploads();
40  foreach ($uploads as $pre => $info) {
41  $settings = $this->ls_filesystem->moveUploaded($pre, $info, $settings);
42  }
43 
44  $deletions = $settings->getDeletions();
45  foreach ($deletions as $pre) {
46  $settings = $this->ls_filesystem->delete_image($pre, $settings);
47  }
48 
49  $where = [
50  "obj_id" => ["integer", $settings->getObjId()]
51  ];
52 
53  $values = [
54  "abstract" => ["text", $settings->getAbstract()],
55  "extro" => ["text", $settings->getExtro()],
56  "abstract_image" => ["text", $settings->getAbstractImage()],
57  "extro_image" => ["text", $settings->getExtroImage()],
58  "gallery" => ["integer", $settings->getMembersGallery()]
59  ];
60 
61  $this->database->update(static::TABLE_NAME, $values, $where);
62  }
63 
64  public function delete(int $obj_id): void
65  {
66  $settings = $this->getSettingsFor($obj_id);
67 
69  $settings = $this->ls_filesystem->delete_image($pre, $settings);
70  }
71 
72  $query =
73  "DELETE FROM " . static::TABLE_NAME . PHP_EOL
74  . "WHERE obj_id = " . $this->database->quote($obj_id, "integer") . PHP_EOL
75  ;
76 
77  $this->database->manipulate($query);
78  }
79 
80  public function getSettingsFor(int $lso_obj_id): ilLearningSequenceSettings
81  {
82  $data = $this->select($lso_obj_id);
83 
84  if (count($data) == 0) {
85  $settings = $this->buildSettings($lso_obj_id);
86  $this->insert($settings);
87  } else {
88  $settings = $this->buildSettings(
89  $lso_obj_id,
90  $data['abstract'],
91  $data['extro'],
92  $data['abstract_image'],
93  $data['extro_image'],
94  (bool) $data['gallery']
95  );
96  }
97 
98  return $settings;
99  }
100 
104  protected function select(int $obj_id): array
105  {
106  $ret = [];
107  $query =
108  "SELECT abstract, extro, abstract_image, extro_image, gallery" . PHP_EOL
109  . "FROM " . static::TABLE_NAME . PHP_EOL
110  . "WHERE obj_id = " . $this->database->quote($obj_id, "integer") . PHP_EOL
111  ;
112 
113  $result = $this->database->query($query);
114 
115  if ($this->database->numRows($result) !== 0) {
116  // TODO PHP8 Review: Check array building, should be $ret[] = ... IMO
117  $ret = $this->database->fetchAssoc($result);
118  }
119 
120  return $ret;
121  }
122 
123  protected function buildSettings(
124  int $obj_id,
125  string $abstract = '',
126  string $extro = '',
127  ?string $abstract_image = null,
128  ?string $extro_image = null,
129  bool $gallery = false
131  return new ilLearningSequenceSettings(
132  $obj_id,
133  $abstract,
134  $extro,
135  $abstract_image,
136  $extro_image,
137  $gallery
138  );
139  }
140 
141  protected function insert(ilLearningSequenceSettings $settings): void
142  {
143  $values = [
144  "obj_id" => ["integer", $settings->getObjId()],
145  "abstract" => ["text", $settings->getAbstract()],
146  "extro" => ["text", $settings->getExtro()],
147  "gallery" => ["integer", $settings->getMembersGallery()]
148  ];
149  $this->database->insert(static::TABLE_NAME, $values);
150  }
151 }
store(ilLearningSequenceSettings $settings)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
Settings for an LSO (like abstract, extro)
Persistence for Settings (like abstract, extro)
insert(ilLearningSequenceSettings $settings)
buildSettings(int $obj_id, string $abstract='', string $extro='', ?string $abstract_image=null, ?string $extro_image=null, bool $gallery=false)
__construct(ilDBInterface $database, ilLearningSequenceFilesystem $ls_filesystem)