ILIAS  trunk Revision v11.0_alpha-1702-gfd3ecb7f852
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
FlavourDBRepository.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
26 
31 {
32  protected const TABLE_NAME = 'il_resource_flavour';
33  protected const F_RESOURCE_ID = 'rid';
34  protected const F_REVISION = 'revision';
35  protected const F_DEFINITION = 'definition_id';
36  protected const F_VARIANT = 'variant';
37  private array $results_cache = [];
38 
39  public function __construct(private \ilDBInterface $db)
40  {
41  }
42 
43 
44  public function has(ResourceIdentification $rid, int $revision, FlavourDefinition $definition): bool
45  {
46  return $this->buildResult($rid, $revision, $definition, false)->numRows() > 0;
47  }
48 
49  public function store(Flavour $flavour): void
50  {
51  if (!$this->has($flavour->getResourceId(), $flavour->getRevision(), $flavour->getDefinition())) {
52  $this->db->insert(
53  self::TABLE_NAME,
54  [
55  self::F_RESOURCE_ID => ['text', $flavour->getResourceId()->serialize()],
56  self::F_REVISION => ['integer', $flavour->getRevision()],
57  self::F_DEFINITION => ['text', $flavour->getDefinition()->getId()],
58  self::F_VARIANT => ['text', $flavour->getDefinition()->getVariantName() ?? '']
59  ]
60  );
61  }
62  }
63 
64  public function get(ResourceIdentification $rid, int $revision, FlavourDefinition $definition): Flavour
65  {
66  return new Flavour(
67  $definition,
68  $rid,
69  $revision
70  );
71  }
72 
73 
74  public function delete(Flavour $flavour): void
75  {
76  $rid = $flavour->getResourceId();
77  $definition = $flavour->getDefinition();
78 
79  $r = $this->db->manipulateF(
80  "DELETE FROM " . self::TABLE_NAME
81  . " WHERE " . self::F_RESOURCE_ID . " = %s AND "
82  . self::F_REVISION . " = %s AND "
83  . self::F_DEFINITION . " = %s AND (" . self::F_VARIANT . " = %s OR " . self::F_VARIANT . " IS NULL)",
84  ['text', 'integer', 'text', 'text'],
85  [$rid->serialize(), $flavour->getRevision(), $definition->getId(), $definition->getVariantName()]
86  );
87  }
88 
89 
90  public function preload(array $identification_strings): void
91  {
92  // TODO: Implement preload() method.
93  }
94 
95  public function populateFromArray(array $data): void
96  {
97  // TODO: Implement populateFromArray() method.
98  }
99 
100 
101  private function buildResult(
103  int $revision,
104  FlavourDefinition $definition,
105  bool $use_cache = true
106  ): \ilDBStatement {
107  $rcache = $rid->serialize() . $definition->getId() . $definition->getVariantName();
108  if ($use_cache && isset($this->results_cache[$rcache])) {
109  return $this->results_cache[$rcache];
110  }
111 
112  $r = $this->db->queryF(
113  "SELECT * FROM " . self::TABLE_NAME
114  . " WHERE " . self::F_RESOURCE_ID . " = %s AND "
115  . self::F_REVISION . " = %s AND "
116  . self::F_DEFINITION . " = %s AND (" . self::F_VARIANT . " = %s OR " . self::F_VARIANT . " IS NULL)",
117  [
118  'text',
119  'integer',
120  'text',
121  'text'
122  ],
123  [
124  $rid->serialize(),
125  $revision,
126  $definition->getId(),
127  $definition->getVariantName() ?? ''
128  ]
129  );
130  return $this->results_cache[$rcache] = $r;
131  }
132 }
getVariantName()
If a definition can be used in several variants (e.g.
buildResult(ResourceIdentification $rid, int $revision, FlavourDefinition $definition, bool $use_cache=true)
has(ResourceIdentification $rid, int $revision, FlavourDefinition $definition)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$r