ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
TestManScoringDoneHelper.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\Test;
22 
23 use ilDBInterface;
24 
31 {
32  private ?ilDBInterface $db;
33  private const TABLE_NAME = "manscoring_done";
34 
35  public function __construct(?ilDBInterface $db = null)
36  {
37  if (!$db) {
38  global $DIC;
39  $db = $DIC->database();
40  }
41  $this->db = $db;
42  }
43 
44  public function isDone(int $activeId): bool
45  {
46  $result = $this->db->queryF(
47  "SELECT done FROM " . self::TABLE_NAME . " WHERE active_id = %s AND done = 1",
48  ["integer"],
49  [$activeId]
50  );
51 
52  return $result->numRows() === 1;
53  }
54 
55  public function exists(int $activeId): bool
56  {
57  $result = $this->db->queryF(
58  "SELECT active_id FROM " . self::TABLE_NAME . " WHERE active_id = %s",
59  ["integer"],
60  [$activeId]
61  );
62 
63  return $result->numRows() === 1;
64  }
65 
66  public function setDone(int $activeId, bool $done): void
67  {
68  if ($this->exists($activeId)) {
69  $this->db->manipulateF(
70  "UPDATE " . self::TABLE_NAME . " SET done = %s WHERE active_id = %s",
71  ["integer", "integer"],
72  [$done, $activeId]
73  );
74  return;
75  }
76 
77  $this->db->manipulateF(
78  "INSERT INTO " . self::TABLE_NAME . " (active_id, done) VALUES (%s, %s)",
79  ["integer", "integer"],
80  [$activeId, $done]
81  );
82  }
83 }
global $DIC
Definition: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...