Project_Comment.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. require_once($path["model"] . "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. * Version identifier of the project at the time the post was posted.
  19. */
  20. public $version;
  21. /**
  22. * Text of the comment.
  23. */
  24. public $text;
  25. /**
  26. * Time the comment was published.
  27. */
  28. public $dtime;
  29. /**
  30. * User identifier of the poster, if it was a registered user.
  31. */
  32. public $user;
  33. /**
  34. * Username of the poster, if it was not a registered user.
  35. */
  36. public $username;
  37. /**
  38. * Lowercase, two-letter language code of the comment. Guessed at the
  39. * time of posting.
  40. */
  41. public $lang;
  42. /**
  43. * Indicates wether the comment has been approved and can be displayed.
  44. */
  45. public $approved;
  46. /**
  47. * Constructor.
  48. *
  49. * Searches the database and retrieves the information about the
  50. * comment, populating it.
  51. *
  52. * @param MySQL_connection $db Connection to the database.
  53. * @param int $id Identifier of the comment.
  54. */
  55. public function __construct($db, $id){
  56. parent::__construct($db, null);
  57. $s =
  58. "SELECT " .
  59. " id, " .
  60. " project, " .
  61. " version, " .
  62. " text, " .
  63. " dtime, " .
  64. " user, " .
  65. " username, " .
  66. " lang, " .
  67. " approved " .
  68. "FROM project_comment " .
  69. "WHERE id = $id ;";
  70. $q = mysqli_query($this->db, $s);
  71. if (mysqli_num_rows($q) > 0){
  72. $r = mysqli_fetch_array($q);
  73. $this->id = $r["id"];
  74. $this->project = $r["project"];
  75. $this->version = $r["version"];
  76. $this->text = $r["text"];
  77. $this->dtime = $r["dtime"];
  78. $this->user = $r["user"];
  79. $this->username = $r["username"];
  80. $this->lang = $r["lang"];
  81. $this->approved = $r["approved"];
  82. }
  83. }
  84. }
  85. ?>