ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilLearningSequenceSettingsDB.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
11 {
12  const TABLE_NAME = 'lso_settings';
13 
17  protected $database;
18 
22  protected $ls_filesystem;
23 
25  {
26  $this->database = $database;
27  $this->ls_filesystem = $ls_filesystem;
28  }
29 
30  public function store(ilLearningSequenceSettings $settings)
31  {
32  $uploads = $settings->getUploads();
33  if (count($uploads) > 0) {
34  foreach ($uploads as $pre => $info) {
35  $settings = $this->ls_filesystem->moveUploaded($pre, $info, $settings);
36  }
37  }
38 
39  $deletions = $settings->getDeletions();
40  if (count($deletions) > 0) {
41  foreach ($deletions as $pre) {
42  $settings = $this->ls_filesystem->delete_image($pre, $settings);
43  }
44  }
45 
46  $where = array(
47  "obj_id" => array("integer", $settings->getObjId())
48  );
49 
50  $values = array(
51  "abstract" => array("text", $settings->getAbstract()),
52  "extro" => array("text", $settings->getExtro()),
53  "abstract_image" => array("text", $settings->getAbstractImage()),
54  "extro_image" => array("text", $settings->getExtroImage()),
55  "gallery" => array("integer", $settings->getMembersGallery())
56  );
57 
58  $this->database->update(static::TABLE_NAME, $values, $where);
59  }
60 
61  public function delete(int $obj_id)
62  {
63  $settings = $this->getSettingsFor($obj_id);
64 
66  $settings = $this->ls_filesystem->delete_image($pre, $settings);
67  }
68 
69  $query =
70  "DELETE FROM " . static::TABLE_NAME . PHP_EOL
71  . "WHERE obj_id = " . $this->database->quote($obj_id, "integer") . PHP_EOL
72  ;
73 
74  $this->database->manipulate($query);
75  }
76 
77  public function getSettingsFor(int $lso_obj_id) : ilLearningSequenceSettings
78  {
79  $data = $this->select($lso_obj_id);
80 
81  if (count($data) == 0) {
82  $settings = $this->buildSettings($lso_obj_id);
83  $this->insert($settings);
84  } else {
85  $settings = $this->buildSettings(
86  $lso_obj_id,
87  $data['abstract'],
88  $data['extro'],
89  $data['abstract_image'],
90  $data['extro_image'],
91  (bool) $data['gallery']
92  );
93  }
94 
95  return $settings;
96  }
97 
98  protected function select(int $obj_id) : array
99  {
100  $ret = [];
101  $query =
102  "SELECT abstract, extro, abstract_image, extro_image, gallery" . PHP_EOL
103  . "FROM " . static::TABLE_NAME . PHP_EOL
104  . "WHERE obj_id = " . $this->database->quote($obj_id, "integer") . PHP_EOL
105  ;
106 
107  $result = $this->database->query($query);
108 
109  if ($result->numRows() !== 0) {
110  $ret = $this->database->fetchAssoc($result);
111  }
112 
113  return $ret;
114  }
115 
116  protected function buildSettings(
117  int $obj_id,
118  string $abstract = '',
119  string $extro = '',
120  string $abstract_image = null,
121  string $extro_image = null,
122  bool $gallery = false
124  return new ilLearningSequenceSettings(
125  $obj_id,
126  $abstract,
127  $extro,
128  $abstract_image,
129  $extro_image,
130  $gallery
131  );
132  }
133 
134  protected function insert(ilLearningSequenceSettings $settings)
135  {
136  $values = array(
137  "obj_id" => array("integer", $settings->getObjId()),
138  "abstract" => array("text", $settings->getAbstract()),
139  "extro" => array("text", $settings->getExtro()),
140  "gallery" => array("integer", $settings->getMembersGallery())
141  );
142  $this->database->insert(static::TABLE_NAME, $values);
143  }
144 }
$result
PHP_EOL
Definition: complexTest.php:5
store(ilLearningSequenceSettings $settings)
Settings for an LSO (like abstract, extro)
$values
$query
Persistence for Settings (like abstract, extro)
insert(ilLearningSequenceSettings $settings)
$ret
Definition: parser.php:6
__construct(ilDBInterface $database, ilLearningSequenceFilesystem $ls_filesystem)
$info
Definition: index.php:5
buildSettings(int $obj_id, string $abstract='', string $extro='', string $abstract_image=null, string $extro_image=null, bool $gallery=false)
$data
Definition: bench.php:6