<?php
class CommentDataGateway {
public function getNumber($fileID, $parentID)
{
$whereComments = "file_id = :file_id_bind AND
parent_id = :parent_id_bind";
$whereComments = "file_id = :file_id_bind AND
parent_id is null";
}
$query = "SELECT COUNT(*) + 1
FROM comments
WHERE {$whereComments}";
$stmt = $this->pdo->prepare($query);
$stmt->bindValue(":file_id_bind", $fileID, \PDO::PARAM_STR);
$stmt->bindValue(":parent_id_bind", $parentID, \PDO::PARAM_INT);
}
$stmt->execute();
$number = $stmt->fetchColumn();
return $number;
}
public function getPath($fileID, $parentID, $number)
{
return $this->getParentPath($fileID, $parentID) . "." . $this->getNumberForPath($number);
}
private function getParentPath($fileID, $parentID)
{
$query = "SELECT path
FROM comments
WHERE file_id = :file_id_bind
AND parent_id = :parent_id_bind";
$stmt = $this->pdo->prepare($query);
$stmt->bindValue(":file_id_bind", $fileID, \PDO::PARAM_STR);
$stmt->bindValue(":parent_id_bind", $parentID, \PDO::PARAM_INT);
$stmt->execute();
$path = $stmt->fetchColumn();
return $path;
}
private function getNumberForPath($number)
{
return str_pad((string
)$number, 3, "0", STR_PAD_LEFT
); }
}
PD9waHAKCmNsYXNzIENvbW1lbnREYXRhR2F0ZXdheSB7CgkKICAgIHB1YmxpYyBmdW5jdGlvbiBnZXROdW1iZXIoJGZpbGVJRCwgJHBhcmVudElEKQogICAgewogICAgICAgICR3aGVyZUNvbW1lbnRzID0gImZpbGVfaWQgICA9IDpmaWxlX2lkX2JpbmQgQU5ECiAgICAgICAgICAgICAgICAgICAgICAgICAgcGFyZW50X2lkID0gOnBhcmVudF9pZF9iaW5kIjsKICAgICAgICBpZiAoZW1wdHkoJHBhcmVudElEKSkgewogICAgICAgICAgICAkd2hlcmVDb21tZW50cyAgPSAiZmlsZV9pZCA9IDpmaWxlX2lkX2JpbmQgQU5ECiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBwYXJlbnRfaWQgaXMgbnVsbCI7CiAgICAgICAgfQogICAgICAgICRxdWVyeSA9ICJTRUxFQ1QgQ09VTlQoKikgKyAxCiAgICAgICAgICAgICAgICAgICAgRlJPTSBjb21tZW50cwogICAgICAgICAgICAgICAgICAgV0hFUkUgeyR3aGVyZUNvbW1lbnRzfSI7CiAgICAgICAgJHN0bXQgPSAkdGhpcy0+cGRvLT5wcmVwYXJlKCRxdWVyeSk7CiAgICAgICAgJHN0bXQtPmJpbmRWYWx1ZSgiOmZpbGVfaWRfYmluZCIsICAgJGZpbGVJRCwgICBcUERPOjpQQVJBTV9TVFIpOwogICAgICAgIGlmICghZW1wdHkoJHBhcmVudElEKSkgewogICAgICAgICAgICAkc3RtdC0+YmluZFZhbHVlKCI6cGFyZW50X2lkX2JpbmQiLCAkcGFyZW50SUQsIFxQRE86OlBBUkFNX0lOVCk7CiAgICAgICAgfQogICAgICAgICRzdG10LT5leGVjdXRlKCk7CiAgICAgICAgJG51bWJlciA9ICRzdG10LT5mZXRjaENvbHVtbigpOwogICAgICAgIHJldHVybiAkbnVtYmVyOwogICAgfQoKICAgIHB1YmxpYyBmdW5jdGlvbiBnZXRQYXRoKCRmaWxlSUQsICRwYXJlbnRJRCwgJG51bWJlcikKICAgIHsKICAgICAgICByZXR1cm4gJHRoaXMtPmdldFBhcmVudFBhdGgoJGZpbGVJRCwgJHBhcmVudElEKSAuICIuIiAuICR0aGlzLT5nZXROdW1iZXJGb3JQYXRoKCRudW1iZXIpOwogICAgfQoKICAgIHByaXZhdGUgZnVuY3Rpb24gZ2V0UGFyZW50UGF0aCgkZmlsZUlELCAkcGFyZW50SUQpCiAgICB7CiAgICAgICAgJHF1ZXJ5ID0gIlNFTEVDVCBwYXRoCiAgICAgICAgICAgICAgICAgICAgRlJPTSBjb21tZW50cwogICAgICAgICAgICAgICAgICAgV0hFUkUgZmlsZV9pZCAgID0gOmZpbGVfaWRfYmluZAogICAgICAgICAgICAgICAgICAgICBBTkQgcGFyZW50X2lkID0gOnBhcmVudF9pZF9iaW5kIjsKICAgICAgICAkc3RtdCA9ICR0aGlzLT5wZG8tPnByZX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