ILIAS  release_8 Revision v8.23
class.ilOerHarvesterObjectStatus.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
28 {
29  private int $obj_id;
30 
31  private int $harvest_ref_id = 0;
32 
33  private bool $blocked = false;
34 
35  protected ilDBInterface $db;
36 
37  public function __construct(int $obj_id = 0)
38  {
39  global $DIC;
40 
41  $this->db = $DIC->database();
42 
43  $this->obj_id = $obj_id;
44  if ($this->obj_id) {
45  $this->read();
46  }
47  }
48 
52  public static function lookupHarvested(): array
53  {
54  global $DIC;
55 
56  $db = $DIC->database();
57 
58  $query = 'SELECT href_id FROM il_meta_oer_stat ';
59  $res = $db->query($query);
60 
61  $hids = [];
62  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
63  $hids[] = (int) $row->href_id;
64  }
65  return $hids;
66  }
67 
68  public static function lookupObjIdByHarvestingId(int $a_href_id): int
69  {
70  global $DIC;
71 
72  $db = $DIC->database();
73  $query = 'SELECT obj_id FROM il_meta_oer_stat ' .
74  'WHERE href_id = ' . $db->quote($a_href_id, 'integer');
75  $res = $db->query($query);
76  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
77  return (int) $row->obj_id;
78  }
79  return 0;
80  }
81 
82  public function setObjId(int $a_obj_id): void
83  {
84  $this->obj_id = $a_obj_id;
85  }
86 
87  public function getObjId(): int
88  {
89  return $this->obj_id;
90  }
91 
92  public function setHarvestRefId(int $a_ref_id): void
93  {
94  $this->harvest_ref_id = $a_ref_id;
95  }
96 
97  public function getHarvestRefId(): int
98  {
99  return $this->harvest_ref_id;
100  }
101 
102  public function setBlocked(bool $a_stat): void
103  {
104  $this->blocked = $a_stat;
105  }
106 
107  public function isBlocked(): bool
108  {
109  return $this->blocked;
110  }
111 
112  public function isCreated(): bool
113  {
114  return (bool) $this->harvest_ref_id;
115  }
116 
117  public function save(): bool
118  {
119  $this->delete();
120  $query = 'INSERT INTO il_meta_oer_stat ' .
121  '(obj_id, href_id, blocked ) ' .
122  'VALUES (' .
123  $this->db->quote($this->getObjId(), 'integer') . ', ' .
124  $this->db->quote($this->getHarvestRefId(), 'integer') . ', ' .
125  $this->db->quote($this->isBlocked(), 'integer') .
126  ')';
127  $res = $this->db->manipulate($query);
128  return true;
129  }
130 
131  public function delete(): bool
132  {
133  $query = 'DELETE FROM il_meta_oer_stat ' .
134  'WHERE obj_id = ' . $this->db->quote($this->getObjId(), 'integer');
135  $this->db->manipulate($query);
136  return true;
137  }
138 
139  public function read(): void
140  {
141  $query = 'SELECT * FROM il_meta_oer_stat ' .
142  'WHERE obj_id = ' . $this->db->quote($this->getObjId(), 'integer');
143  $res = $this->db->query($query);
144  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
145  $this->setObjId((int) $row->obj_id);
146  $this->setHarvestRefId((int) $row->href_id);
147  $this->setBlocked((bool) $row->blocked);
148  }
149  }
150 }
$res
Definition: ltiservices.php:69
quote($value, string $type)
global $DIC
Definition: feed.php:28
query(string $query)
Run a (read-only) Query on the database.
$query
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...