ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
TestManScoringDoneHelper.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\Test;
22
29{
31 private const TABLE_NAME = "manscoring_done";
32
33 public function __construct(?\ilDBInterface $db = null)
34 {
35 if (!$db) {
36 global $DIC;
37 $db = $DIC->database();
38 }
39 $this->db = $db;
40 }
41
42 public function isDone(int $activeId): bool
43 {
44 $result = $this->db->queryF(
45 "SELECT done FROM " . self::TABLE_NAME . " WHERE active_id = %s AND done = 1",
46 ["integer"],
47 [$activeId]
48 );
49
50 return $result->numRows() === 1;
51 }
52
53 public function exists(int $activeId): bool
54 {
55 $result = $this->db->queryF(
56 "SELECT active_id FROM " . self::TABLE_NAME . " WHERE active_id = %s",
57 ["integer"],
58 [$activeId]
59 );
60
61 return $result->numRows() === 1;
62 }
63
64 public function setDone(int $activeId, bool $done): void
65 {
66 if ($this->exists($activeId)) {
67 $this->db->manipulateF(
68 "UPDATE " . self::TABLE_NAME . " SET done = %s WHERE active_id = %s",
69 ["integer", "integer"],
70 [$done, $activeId]
71 );
72 return;
73 }
74
75 $this->db->manipulateF(
76 "INSERT INTO " . self::TABLE_NAME . " (active_id, done) VALUES (%s, %s)",
77 ["integer", "integer"],
78 [$activeId, $done]
79 );
80 }
81}
Interface ilDBInterface.
global $DIC
Definition: shib_login.php:26