Project.php 5.6 KB

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