Project_Comment.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. require_once($path["entity"] . "Entity.php");
  3. /**
  4. * Project posted on a comment.
  5. *
  6. * Represents an object from the table 'project_comment'.
  7. */
  8. class Project_Comment extends Entity{
  9. /**
  10. * Comment unique identifier.
  11. */
  12. public $id;
  13. /**
  14. * Identifier of the project the comment is on.
  15. */
  16. public $project;
  17. /**
  18. * Text of the comment.
  19. */
  20. public $text;
  21. /**
  22. * Time the comment was published.
  23. */
  24. public $dtime;
  25. /**
  26. * User identifier of the poster, if it was a registered user.
  27. */
  28. public $user;
  29. /**
  30. * Username of the poster, if it was not a registered user.
  31. */
  32. public $username;
  33. /**
  34. * Lowercase, two-letter language code of the comment. Guessed at the
  35. * time of posting.
  36. */
  37. public $lang;
  38. /**
  39. * Indicates wether the comment has been approved and can be displayed.
  40. */
  41. public $approved;
  42. /**
  43. * Constructor.
  44. *
  45. * Searches the database and retrieves the information about the
  46. * comment, populating it.
  47. *
  48. * @param MySQL_connection $db Connection to the database.
  49. * @param int $id Identifier of the comment.
  50. */
  51. public function __construct($db, $id){
  52. parent::__construct($db, null);
  53. $s =
  54. "SELECT " .
  55. " id, " .
  56. " project, " .
  57. " text, " .
  58. " dtime, " .
  59. " user, " .
  60. " username, " .
  61. " lang, " .
  62. " approved " .
  63. "FROM project_comment " .
  64. "WHERE id = $id ;";
  65. $q = mysqli_query($this->db, $s);
  66. if (mysqli_num_rows($q) > 0){
  67. $r = mysqli_fetch_array($q);
  68. $this->id = $r["id"];
  69. $this->project = $r["project"];
  70. $this->text = $r["text"];
  71. $this->dtime = $r["dtime"];
  72. $this->user = $r["user"];
  73. $this->username = $r["username"];
  74. $this->lang = $r["lang"];
  75. $this->approved = $r["approved"];
  76. }
  77. }
  78. }
  79. ?>