ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
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
123 
125  return new ilLearningSequenceSettings(
126  $obj_id,
127  $abstract,
128  $extro,
129  $abstract_image,
130  $extro_image,
131  $gallery
132  );
133  }
134 
135  protected function insert(ilLearningSequenceSettings $settings)
136  {
137  $values = array(
138  "obj_id" => array("integer", $settings->getObjId()),
139  "abstract" => array("text", $settings->getAbstract()),
140  "extro" => array("text", $settings->getExtro()),
141  "gallery" => array("integer", $settings->getMembersGallery())
142  );
143  $this->database->insert(static::TABLE_NAME, $values);
144  }
145 }
$data
Definition: storeScorm.php:23
$result
store(ilLearningSequenceSettings $settings)
Interface ilDBInterface.
Settings for an LSO (like abstract, extro)
$query
Persistence for Settings (like abstract, extro)
insert(ilLearningSequenceSettings $settings)
$ret
Definition: parser.php:6
__construct(ilDBInterface $database, ilLearningSequenceFilesystem $ls_filesystem)
buildSettings(int $obj_id, string $abstract='', string $extro='', string $abstract_image=null, string $extro_image=null, bool $gallery=false)