Home_Page.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. parent::__construct();
  20. $this->set_view("home.php");
  21. $this->set_title("");
  22. $this->set_description(get_context()->get_user()->get_text("TAGLINE"));
  23. $this->set_canonical("");
  24. $this->add_css("home.css");
  25. $this->set_code(200);
  26. $this->set_message("OK");
  27. $statement = get_context()->get_db()->prepare(
  28. "SELECT id FROM project WHERE user = :user AND visible = 1 ORDER BY idx LIMIT :limit"
  29. );
  30. $statement->bindValue(':limit', $this->max_projects, PDO::PARAM_INT);
  31. $statement->bindValue(':user', get_context()->get_user()->get_id(), PDO::PARAM_INT);
  32. $statement->execute();
  33. while ($r_project = $statement->fetch(PDO::FETCH_ASSOC)){
  34. Log::debug("Instantiating new project: " . $r_project["id"]);
  35. array_push($this->projects, new Project($r_project["id"]));
  36. }
  37. }
  38. /**
  39. * Retrieves the projects to show on the page.
  40. *
  41. * @return Project[] Project list.
  42. */
  43. public function get_projects(){return $this->projects;}
  44. }