Home_Page.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. require_once(PATH::PAGE . "Page.php");
  3. require_once(PATH::ENTITY . "Project.php");
  4. /**
  5. * Home page model.
  6. */
  7. class Home_Page extends Page{
  8. private $max_projects = 3;
  9. /**
  10. * List of recent projects.
  11. */
  12. private $projects = [];
  13. /**
  14. * Constructor.
  15. *
  16. * Retrieves the data and initializes the variables.
  17. */
  18. public function __construct(){
  19. $this->view = PATH::VIEW . "home.php";
  20. parent::__construct();
  21. $this->set_view("home.php");
  22. $this->set_title(Text::get("USER_NAME"));
  23. $this->set_description(Text::get("USER_NAME"));
  24. $this->set_canonical("");
  25. $this->add_css("home.css");
  26. $this->set_code(200);
  27. $this->set_message("OK");
  28. $statement = get_context()->get_db()->prepare("
  29. SELECT id
  30. FROM project
  31. WHERE visible = 1
  32. ORDER BY idx DESC
  33. LIMIT :limit
  34. ");
  35. $statement->bindValue(':limit', $this->max_projects, PDO::PARAM_INT);
  36. $statement->execute();
  37. while ($r_project = $statement->fetch(PDO::FETCH_ASSOC)) {
  38. Log::debug("Instantiating new project: " . $r_project["id"]);
  39. array_push($this->project, new Project($r_project["id"]));
  40. }
  41. }
  42. /**
  43. * Retrieves the projects to show on the page.
  44. *
  45. * @return Project[] Project list.
  46. */
  47. public function get_projects(){
  48. return $this->projects;
  49. }
  50. }