Project.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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_Tag.php");
  7. require_once($path["entity"] . "Project_Url.php");
  8. require_once($path["helper"] . "text.php");
  9. /**
  10. * Project.
  11. *
  12. * Represents an object from the table 'project'.
  13. */
  14. class Project extends Entity{
  15. /**
  16. * Project identifier.
  17. */
  18. public $id;
  19. /**
  20. * Permalink for linking the project (relative).
  21. */
  22. public $permalink;
  23. /**
  24. * Project index for sorting.
  25. */
  26. public $idx;
  27. /**
  28. * {@see Project_Type} of project.
  29. */
  30. public $type;
  31. /**
  32. * Project title in the defined language.
  33. */
  34. public $title;
  35. /**
  36. * Project logo filename.
  37. */
  38. public $logo;
  39. /**
  40. * Project summary in the defined language.
  41. */
  42. public $header;
  43. /**
  44. * Project description in the defined language.
  45. */
  46. public $text;
  47. /**
  48. * Project {@see License}.
  49. */
  50. public $license;
  51. /**
  52. * Array with the project {@see Project_Image}.
  53. */
  54. public $image = [];
  55. /**
  56. * Array with the {@see Project_Tag} of the project.
  57. */
  58. public $tag = [];
  59. /**
  60. * Array with {@see Project_Url} related to the project.
  61. */
  62. public $url = [];
  63. /**
  64. * Constructor.
  65. *
  66. * Searches the database and retrieves the information about the
  67. * project, populating it and it's items.
  68. *
  69. * @param MySQL_connection $db Connection to the database.
  70. * @param string $lang Lowercase, two-letter language code.
  71. * @param string $id Identifier or permalink of the project.
  72. */
  73. public function __construct($db, $lang, $id){
  74. parent::__construct($db, $lang);
  75. $s =
  76. "SELECT " .
  77. " id, " .
  78. " permalink, " .
  79. " idx, " .
  80. " type, " .
  81. " title, " .
  82. " logo, " .
  83. " header, " .
  84. " text, " .
  85. " license " .
  86. "FROM project " .
  87. "WHERE " .
  88. " visible = 1 AND " .
  89. " ( " .
  90. " id = '$id' OR " .
  91. " permalink = '$id' " .
  92. " );";
  93. $q = mysqli_query($this->db, $s);
  94. if (mysqli_num_rows($q) > 0){
  95. $r = mysqli_fetch_array($q);
  96. $this->id = $r["id"];
  97. $this->permalink = $r["permalink"];
  98. $this->idx = $r["idx"];
  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. }
  133. }
  134. ?>