Project.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <?php
  2. require_once($path["entity"] . "Entity.php");
  3. require_once($path["entity"] . "License.php");
  4. require_once($path["entity"] . "Project_Type.php");
  5. require_once($path["entity"] . "Project_Image.php");
  6. require_once($path["entity"] . "Project_Comment.php");
  7. require_once($path["entity"] . "Project_Tag.php");
  8. require_once($path["entity"] . "Project_Url.php");
  9. require_once($path["helper"] . "text.php");
  10. /**
  11. * Project.
  12. *
  13. * Represents an object from the table 'project'.
  14. */
  15. class Project extends Entity{
  16. /**
  17. * Project identifier.
  18. */
  19. public $id;
  20. /**
  21. * Permalink for linking the project (relative).
  22. */
  23. public $permalink;
  24. /**
  25. * {@see Project_Type} of project.
  26. */
  27. public $type;
  28. /**
  29. * Project title in the defined language.
  30. */
  31. public $title;
  32. /**
  33. * Project logo filename.
  34. */
  35. public $logo;
  36. /**
  37. * Project summary in the defined language.
  38. */
  39. public $header;
  40. /**
  41. * Project description in the defined language.
  42. */
  43. public $text;
  44. /**
  45. * Project {@see License}.
  46. */
  47. public $license;
  48. /**
  49. * Array with the project {@see Project_Image}.
  50. */
  51. public $image = [];
  52. /**
  53. * Array with the {@see Project_Comment} posted in the project, sorted
  54. * from new to old.
  55. */
  56. public $comment = [];
  57. /**
  58. * Array with the {@see Project_Tag} of the project.
  59. */
  60. public $tag = [];
  61. /**
  62. * Array with {@see Project_Url} related to the project.
  63. */
  64. public $url = [];
  65. /**
  66. * Constructor.
  67. *
  68. * Searches the database and retrieves the information about the
  69. * project, populating it and it's items.
  70. *
  71. * @param MySQL_connection $db Connection to the database.
  72. * @param string $lang Lowercase, two-letter language code.
  73. * @param string $id Identifier or permalink of the project.
  74. */
  75. public function __construct($db, $lang, $id){
  76. parent::__construct($db, $lang);
  77. $s =
  78. "SELECT " .
  79. " id, " .
  80. " permalink, " .
  81. " type, " .
  82. " title, " .
  83. " logo, " .
  84. " header, " .
  85. " text, " .
  86. " license " .
  87. "FROM project " .
  88. "WHERE " .
  89. " visible = 1 AND " .
  90. " ( " .
  91. " id = '$id' OR " .
  92. " permalink = '$id' " .
  93. " );";
  94. $q = mysqli_query($this->db, $s);
  95. if (mysqli_num_rows($q) > 0){
  96. $r = mysqli_fetch_array($q);
  97. $this->id = $r["id"];
  98. $this->permalink = $r["permalink"];
  99. $this->title = text($this, $r["title"]);
  100. $this->logo = $r["logo"];
  101. $this->header = text($this, $r["header"]);
  102. $this->text = text($this, $r["text"]);
  103. $this->type = new Project_Type($this->db, $this->lang, $r["type"]);
  104. $this->license = new License($this->db, $this->lang, $r["license"]);
  105. }
  106. $s_image =
  107. "SELECT id " .
  108. "FROM project_image " .
  109. "WHERE project = " . $this->id . " " .
  110. "ORDER BY idx; ";
  111. $q_image = mysqli_query($this->db, $s_image);
  112. while($r_image = mysqli_fetch_array($q_image)){
  113. array_push($this->image, new Project_Image($this->db, $r_image["id"]));
  114. }
  115. $s_tag =
  116. "SELECT tag " .
  117. "FROM project_tag " .
  118. "WHERE project = " . $this->id . ";";
  119. $q_tag = mysqli_query($this->db, $s_tag);
  120. while($r_tag = mysqli_fetch_array($q_tag)){
  121. array_push($this->tag, new Project_Tag($this->db, $this->lang, $this->id, $r_tag["tag"]));
  122. }
  123. $s_url =
  124. "SELECT id " .
  125. "FROM project_url " .
  126. "WHERE project = " . $this->id . ";";
  127. error_log($s_url);
  128. $q_url = mysqli_query($this->db, $s_url);
  129. while($r_url = mysqli_fetch_array($q_url)){
  130. array_push($this->url, new Project_Url($this->db, $this->lang, $r_url["id"]));
  131. }
  132. $s_comment =
  133. "SELECT id " .
  134. "FROM project_comment " .
  135. "WHERE project = " . $this->id . ";";
  136. $q_comment = mysqli_query($this->db, $s_comment);
  137. while($r_comment = mysqli_fetch_array($q_comment)){
  138. array_push($this->comment, new Project_Comment($this->db, $r_comment["id"]));
  139. }
  140. }
  141. }
  142. ?>