fork download
  1. <?php
  2.  
  3. class CommentDataGateway {
  4.  
  5. public function getNumber($fileID, $parentID)
  6. {
  7. $whereComments = "file_id = :file_id_bind AND
  8. parent_id = :parent_id_bind";
  9. if (empty($parentID)) {
  10. $whereComments = "file_id = :file_id_bind AND
  11. parent_id is null";
  12. }
  13. $query = "SELECT COUNT(*) + 1
  14. FROM comments
  15. WHERE {$whereComments}";
  16. $stmt = $this->pdo->prepare($query);
  17. $stmt->bindValue(":file_id_bind", $fileID, \PDO::PARAM_STR);
  18. if (!empty($parentID)) {
  19. $stmt->bindValue(":parent_id_bind", $parentID, \PDO::PARAM_INT);
  20. }
  21. $stmt->execute();
  22. $number = $stmt->fetchColumn();
  23. return $number;
  24. }
  25.  
  26. public function getPath($fileID, $parentID, $number)
  27. {
  28. return $this->getParentPath($fileID, $parentID) . "." . $this->getNumberForPath($number);
  29. }
  30.  
  31. private function getParentPath($fileID, $parentID)
  32. {
  33. $query = "SELECT path
  34. FROM comments
  35. WHERE file_id = :file_id_bind
  36. AND parent_id = :parent_id_bind";
  37. $stmt = $this->pdo->prepare($query);
  38. $stmt->bindValue(":file_id_bind", $fileID, \PDO::PARAM_STR);
  39. $stmt->bindValue(":parent_id_bind", $parentID, \PDO::PARAM_INT);
  40. $stmt->execute();
  41. $path = $stmt->fetchColumn();
  42. return $path;
  43. }
  44.  
  45. private function getNumberForPath($number)
  46. {
  47. return str_pad((string)$number, 3, "0", STR_PAD_LEFT);
  48. }
  49. }
  50.  
Success #stdin #stdout 0s 52488KB
stdin
Standard input is empty
stdout
Standard output is empty