<?php
class CommentDataGateway {
public function getNumber($properties, $commentParentID)
{
if (!empty($commentParentID)) { $query = "SELECT COUNT(*) + 1
FROM comments
WHERE fileID = :fileID AND
path LIKE CONCAT(
(SELECT path
FROM comments
WHERE commentID = :commentParentID), '.%')";
} else {
$query = "SELECT COUNT(*) + 1
FROM comments
WHERE fileID = :fileID AND
CHAR_LENGTH (path) = 3";
}
$stmt = $this->pdo->prepare($query);
$stmt->bindValue(":fileID", $properties["fileID"], \PDO::PARAM_STR);
if (!empty($commentParentID)) { $stmt->bindValue(":commentParentID", $commentParentID, \PDO::PARAM_INT);
}
$stmt->execute();
$number = $stmt->fetchColumn();
return $number;
}
public function getPath($properties, $commentParentID)
{
$query = "SELECT CONCAT(path, '.00', :number)
FROM comments
WHERE fileID = :fileID
AND commentID = :commentParentID";
$stmt = $this->pdo->prepare($query);
$stmt->bindValue(":number", $properties["number"], \PDO::PARAM_INT);
$stmt->bindValue(":fileID", $properties["fileID"], \PDO::PARAM_STR);
$stmt->bindValue(":commentParentID", $commentParentID, \PDO::PARAM_INT);
$stmt->execute();
$path = $stmt->fetchColumn();
return $path;
}
}
PD9waHAKCmNsYXNzIENvbW1lbnREYXRhR2F0ZXdheSB7CgkKCXB1YmxpYyBmdW5jdGlvbiBnZXROdW1iZXIoJHByb3BlcnRpZXMsICRjb21tZW50UGFyZW50SUQpCiAgICB7CiAgICAgICAgaWYgKCFlbXB0eSgkY29tbWVudFBhcmVudElEKSkgewogICAgICAgICAgICAkcXVlcnkgPSAiU0VMRUNUIENPVU5UKCopICsgMQogICAgICAgICAgICAgICAgICAgICAgICBGUk9NIGNvbW1lbnRzCiAgICAgICAgICAgICAgICAgICAgICAgV0hFUkUgZmlsZUlEID0gOmZpbGVJRCBBTkQKICAgICAgICAgICAgICAgICAgICAgICAgICAgICBwYXRoIExJS0UgQ09OQ0FUKAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAoU0VMRUNUIHBhdGgKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgRlJPTSBjb21tZW50cwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFdIRVJFIGNvbW1lbnRJRCAgPSA6Y29tbWVudFBhcmVudElEKSwgJy4lJykiOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICRxdWVyeSA9ICJTRUxFQ1QgQ09VTlQoKikgKyAxCiAgICAgICAgICAgICAgICAgICAgICAgIEZST00gY29tbWVudHMKICAgICAgICAgICAgICAgICAgICAgICBXSEVSRSBmaWxlSUQgPSA6ZmlsZUlEIEFORAogICAgICAgICAgICAgICAgIENIQVJfTEVOR1RIIChwYXRoKSA9IDMiOwogICAgICAgIH0KICAgICAgICAkc3RtdCA9ICR0aGlzLT5wZG8tPnByZXBhcmUoJHF1ZXJ5KTsKICAgICAgICAkc3RtdC0+YmluZFZhbHVlKCI6ZmlsZUlEIiwgJHByb3BlcnRpZXNbImZpbGVJRCJdLCBcUERPOjpQQVJBTV9TVFIpOwogICAgICAgIGlmICghZW1wdHkoJGNvbW1lbnRQYXJlbnRJRCkpIHsKICAgICAgICAgICAgJHN0bXQtPmJpbmRWYWx1ZSgiOmNvbW1lbnRQYXJlbnRJRCIsICRjb21tZW50UGFyZW50SUQsIFxQRE86OlBBUkFNX0lOVCk7CiAgICAgICAgfQogICAgICAgICRzdG10LT5leGVjdXRlKCk7CiAgICAgICAgJG51bWJlciA9ICRzdG10LT5mZXRjaENvbHVtbigpOwogICAgICAgIHJldHVybiAkbnVtYmVyOwogICAgfQoKICAgIHB1YmxpYyBmdW5jdGlvbiBnZXRQYXRoKCRwcm9wZXJ0aWVzLCAkY29tbWVudFBhcmVudElEKQogICAgewogICAgICAgICRxdWVyeSA9ICJTRUxFQ1QgQ09OQ0FUKHBhdGgsICcuMDAnLCA6bnVtYmVyKQogICAgICAgICAgICAgICAgICAgIEZST00gY29tbWVudHMKICAgICAgICAgICAgICAgICAgIFdIRVJFIGZpbGVJRCAgICA9IDpmaWxlSUQKICAgICAgICAgICAgICAgICAgICAgQU5EIGNvbW1lbnRJRCA9IDpjb21tZW50UGFyZW50SUQiOwogICAgICAgICRzdG10ID0gJHRoaXMtPnBkby0+cHJlcGFyZSgkcXVlcnkpOwogICAgICAgICRzdG10LT5iaW5kVmFsdWUoIjpudW1iZXIiLCAgICAgICAgICAkcHJvcGVydGllc1sibnVtYmVyIl0sIFxQRE86OlBBUkFNX0lOVCk7CiAgICAgICAgJHN0bXQtPmJpbmRWYWx1ZSgiOmZpbGVJRCIsICAgICAgICAgICRwcm9wZXJ0aWVzWyJmaWxlSUQiXSwgXFBETzo6UEFSQU1fU1RSKTsKICAgICAgICAkc3RtdC0+YmluZFZhbHVlKCI6Y29tbWVudFBhcmVudElEIiwgJGNvbW1lbnRQYXJlbnRJRCwgICAgICBcUERPOjpQQVJBTV9JTlQpOwogICAgICAgICRzdG10LT5leGVjdXRlKCk7CiAgICAgICAgJHBhdGggPSAkc3RtdC0+ZmV0Y2hDb2x1bW4oKTsKICAgICAgICByZXR1cm4gJHBhdGg7CiAgICB9Cn0=