page.class.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?php
  2. /**
  3. * Web page wrapper. Usage:
  4. *
  5. * Page::create()->title('my_title')->display($content);
  6. *
  7. * $page = Page::create()->title('my_title')->help('help')->content($content);
  8. * $page->display();
  9. *
  10. * @license see /license.txt
  11. * @author Laurent Opprecht <laurent@opprecht.info> for the Univesity of Geneva
  12. */
  13. class Page
  14. {
  15. protected $title = null;
  16. protected $help = null;
  17. protected $header = null;
  18. protected $content;
  19. protected $breadcrumbs = '';
  20. protected $message = null;
  21. protected $warning = null;
  22. protected $error = null;
  23. /**
  24. *
  25. * @return Page
  26. */
  27. static function create($title = '')
  28. {
  29. return new self($title);
  30. }
  31. function __construct($title = '')
  32. {
  33. $this->title = $title;
  34. }
  35. /**
  36. *
  37. * @param $header
  38. * @return Page
  39. */
  40. function header($header)
  41. {
  42. $this->header = $header;
  43. return $this;
  44. }
  45. /**
  46. *
  47. * @param string $title
  48. * @return Page
  49. */
  50. function title($title)
  51. {
  52. $this->title = $title;
  53. return $this;
  54. }
  55. /**
  56. *
  57. * @param array $crumbs_
  58. * @return Page
  59. */
  60. function breadcrumbs($crumbs)
  61. {
  62. $this->breadcrumbs = $crumbs;
  63. return $this;
  64. }
  65. /**
  66. *
  67. * @param string $help help file name
  68. * @return Page
  69. */
  70. function help($help)
  71. {
  72. $this->help = $help;
  73. return $this;
  74. }
  75. /**
  76. *
  77. * @param string $message
  78. * @return Page
  79. */
  80. function message($message)
  81. {
  82. $this->message = $message;
  83. return $this;
  84. }
  85. /**
  86. *
  87. * @param string $warning
  88. * @return Page
  89. */
  90. function warning($warning)
  91. {
  92. $this->warning = $warning;
  93. return $this;
  94. }
  95. /**
  96. *
  97. * @param string $error
  98. * @return Page
  99. */
  100. function error($error)
  101. {
  102. $this->error = $error;
  103. return $this;
  104. }
  105. /**
  106. *
  107. * @param object|string $content
  108. * @return Page
  109. */
  110. function content($content)
  111. {
  112. $this->content = $content;
  113. return $this;
  114. }
  115. function __toString()
  116. {
  117. $this->display($this->content);
  118. }
  119. function display($content = null)
  120. {
  121. $this->display_header();
  122. $this->display_content($content);
  123. $this->display_footer();
  124. }
  125. function display_header()
  126. {
  127. global $interbreadcrumb;
  128. $interbreadcrumb = $this->breadcrumbs;
  129. Display::display_header($this->title, $this->help, $this->header);
  130. if ($message = $this->message) {
  131. Display::display_confirmation_message($message);
  132. }
  133. if ($warning = $this->warning) {
  134. Display::display_warning_message($warning);
  135. }
  136. if ($error = $this->error) {
  137. Display::display_error_message($error);
  138. }
  139. }
  140. protected function display_content($content)
  141. {
  142. $content = $content ? $content : $this->content;
  143. echo $content;
  144. }
  145. function display_footer()
  146. {
  147. Display::display_footer();
  148. }
  149. }