Unit_Page.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. * Unit view page file.
  4. *
  5. * Provides a class with all the properties and methods to display the page.
  6. *
  7. * @author Iñigo Valentin <i@inigovalentin.com>
  8. * @license https://www.gnu.org/licenses/gpl-3.0.en.html GNU General Public License V3
  9. * @package SWDB
  10. */
  11. require_once(PATH::PAGE . "Page.php");
  12. require_once(PATH::ENTITY . "Unit.php");
  13. /**
  14. * Unit view page model.
  15. *
  16. * @category Page
  17. */
  18. class Unit_Page extends Page{
  19. /**
  20. * @var Unit Selected Unit.
  21. */
  22. private $unit;
  23. /**
  24. * Constructor.
  25. *
  26. * Retrieves the data and initializes the variables.
  27. *
  28. * @param string $id Selected unit id
  29. */
  30. public function __construct($id){
  31. parent::__construct();
  32. $this->set_public(true);
  33. $this->set_view("unit.php");
  34. $this->unit = new Unit($id, true);
  35. if ($this->unit == null || $this->unit->get_id() == null){
  36. $this->set_code(404);
  37. $this->set_message("Unit not found");
  38. }
  39. else{
  40. $this->set_code(200);
  41. $this->set_message("OK");
  42. }
  43. $this->set_title($this->unit->get_title());
  44. $this->set_description(get_context()->get_player()->get_name() . "'s " . $this->unit->get_title());
  45. $this->set_canonical("player/" . get_context()->get_player()->get_id() . "/unit/" . $this->unit->get_id());
  46. $this->add_css("unit.css");
  47. }
  48. /**
  49. * Retrieves the selected unit.
  50. *
  51. * @return Unit Selected unit.
  52. */
  53. public function get_unit(){
  54. return $this->unit;
  55. }
  56. }