4in1_ws_web/lib/previous_texts.php

42 lines
1013 B
PHP

<?php
class PreviousText extends model {
const DB_TABLE = 'previous_texts';
const int TYPE_POST_TEXT = 0x0;
const int TYPE_PAGE = 0x1;
public int $id;
public int $objectType;
public int $objectId;
public string $md;
public int $ts;
}
class previous_texts {
static function add(int $object_type, int $object_id, string $md, int $ts) {
$db = DB();
$db->insert(PreviousText::DB_TABLE, [
'object_type' => $object_type,
'object_id' => $object_id,
'md' => $md,
'ts' => $ts
]);
}
static function delete(int $object_type, int|array $object_id): void {
$sql = "DELETE FROM ".PreviousText::DB_TABLE." WHERE object_type=? AND object_id";
$args = [$object_type];
if (is_array($object_id))
$sql .= " IN (".implode(',', $object_id).")";
else {
$sql .= '=?';
$args[] = $object_id;
}
DB()->query($sql, ...$args);
}
}