Source for file viewer.php

Documentation is available at viewer.php

  1. <?php
  2. /**
  3. * @package de.linkm.events
  4. * @author The Midgard Project, http://www.midgard-project.org
  5. * @version $Id: viewer.php,v 1.7.2.1 2005/07/18 08:11:46 torben Exp $
  6. * @copyright The Midgard Project, http://www.midgard-project.org
  7. * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
  8. */
  9.  
  10. /**
  11. * Events Viewer interface class
  12. *
  13. * @todo document
  14. *
  15. * @package de.linkm.events
  16. */
  17. class de_linkm_events_viewer {
  18.  
  19. var $_topic;
  20. var $_config;
  21. var $_mode;
  22. var $_display;
  23. var $errcode;
  24. var $errstr;
  25. var $_metadata;
  26. var $_latest;
  27.  
  28. function de_linkm_events_viewer ($topic, $config) {
  29. $this->_topic = $topic;
  30. $this->_config = $config;
  31. $this->_mode = "";
  32. $this->_display = null;
  33. $this->errcode = MIDCOM_ERROK;
  34. $this->errstr = "";
  35. $this->_metadata = null;
  36. $this->_latest = null;
  37. $this->_upcoming = null;
  38. if ($this->_config->get('schemadb') == 'file:/de/linkm/events/config/schemadb_default.dat')
  39. {
  40. // Hotfix for a bad config interface
  41. $this->_config->store(Array('schemadb' => 'file:/de/linkm/events/config/schemadb_default.inc'), false);
  42. }
  43. }
  44. function can_handle ($argc, $argv) {
  45. if ($argc == 0)
  46. return true;
  47. if ($argc == 2 && is_numeric($argv[1]) && ($argv[0] === 'latest' || $argv[0] === 'upcoming'))
  48. return true;
  49. if ($argc > 2)
  50. return false;
  51. $display = mgd_get_article_by_name($this->_topic->id, $argv[0]);
  52. if ( (!$display) || ($display->topic != $this->_topic->id) )
  53. return false;
  54. $this->_display = $display;
  55. $GLOBALS['midcom_component_data']['de.linkm.events']['active_leaf'] = $this->_display->id;
  56.  
  57. // Support for old string-formatted dates
  58. if (!is_numeric($this->_display->extra2)) {
  59. $this->_display->extra2 = @strtotime($this->_display->extra2);
  60. }
  61.  
  62. return true;
  63. }
  64.  
  65. function handle ($argc, $argv) {
  66. if ($argc == 0) {
  67. $this->_mode = "list";
  68. $newest_article = $this->_get_newest();
  69. $this->_metadata = Array (
  70. MIDCOM_META_CREATOR => $this->_topic->creator,
  71. MIDCOM_META_CREATED => $this->_topic->created,
  72. MIDCOM_META_EDITOR => $newest_article->revisor,
  73. MIDCOM_META_EDITED => $newest_article->revised
  74. );
  75. $GLOBALS["midcom"]->set_pagetitle($this->_config->get("title"));
  76. return true;
  77. } elseif ($argc == 1) {
  78. $this->_mode = "detail";
  79. $this->_metadata = Array (
  80. MIDCOM_META_CREATOR => $this->_display->creator,
  81. MIDCOM_META_CREATED => $this->_display->created,
  82. MIDCOM_META_EDITOR => $this->_display->revisor,
  83. MIDCOM_META_EDITED => $this->_display->revised
  84. );
  85. $GLOBALS["midcom"]->set_pagetitle($this->_display->title);
  86. $GLOBALS['midcom_component_data']['de.linkm.events']['active_leaf'] = $this->_display->id;
  87. return true;
  88. } else {
  89. $this->_mode = "list";
  90. $newest_article = $this->_get_newest();
  91. $this->_metadata = Array (
  92. MIDCOM_META_CREATOR => $this->_topic->creator,
  93. MIDCOM_META_CREATED => $this->_topic->created,
  94. MIDCOM_META_EDITOR => $newest_article->revisor,
  95. MIDCOM_META_EDITED => $newest_article->revised
  96. );
  97. $GLOBALS["midcom"]->set_pagetitle($this->_config->get("title"));
  98. switch ($argv[0]) {
  99. case 'upcoming':
  100. $this->_upcoming = $argv[1];
  101. break;
  102. case 'latest':
  103. $this->_latest = $argv[1];
  104. break;
  105. }
  106. return true;
  107. }
  108. die ("We should not come to this line. This is definitly a bug.");
  109. }
  110.  
  111. function show () {
  112.  
  113. // get l10n libraries
  114. $i18n =& $GLOBALS["midcom"]->get_service("i18n");
  115. $GLOBALS["view_l10n"] = $i18n->get_l10n("de.linkm.events");
  116.  
  117. switch ($this->_mode) {
  118. case "list":
  119. $this->_show_list();
  120. break;
  121. case "detail":
  122. $this->_show_detail();
  123. break;
  124. default:
  125. die ("We should not reach this line. Event Viewer mode was "
  126. . $this->_mode . ", which is not supported.");
  127. break;
  128. }
  129. }
  130.  
  131. function _show_list() {
  132. debug_push("de.linkm.events::show_list");
  133. if (is_null($this->_latest))
  134. $latest = false;
  135. else
  136. $latest = true;
  137.  
  138. if (is_null($this->_upcoming))
  139. $upcoming = false;
  140. else
  141. $upcoming = true;
  142. $ids = de_linkm_events_helpers_getarticleids ($this->_topic, $this->_config, $latest, $upcoming);
  143. $GLOBALS["view_config"] =& $this->_config;
  144. global $view;
  145. global $view_id;
  146. global $view_detail;
  147. $view_detail = $this->_config->get("enable_details");
  148. if (count($ids) == 0) {
  149. // No Events Found
  150. midcom_show_style("events-index-none");
  151. } else {
  152. // Events Found
  153. midcom_show_style("events-index-init");
  154. $first = true;
  155. if ($latest || $upcoming)
  156. $count = 0;
  157. foreach ($ids as $article) {
  158.  
  159. // Support for old string-formatted dates
  160. if (!is_numeric($article->extra2)) {
  161. $article->extra2 = @strtotime($article->extra2);
  162. }
  163.  
  164. $layout = new midcom_helper_datamanager($this->_config->get("schemadb"));
  165.  
  166. if (!$layout)
  167. $GLOBALS["midcom"]->generate_error(MIDCOM_ERRCRIT,
  168. "Layout class could not be instantinated. de_linkm_events_viewer::_show_detail Aborting.");
  169. if (!$layout->init($article))
  170. $GLOBALS["midcom"]->generate_error(MIDCOM_ERRCRIT,
  171. "Layout class could not be initialized. de_linkm_events_viewer::_show_detail Aborting.");
  172.  
  173. $view_id = $article->name;
  174. $view = $layout->get_array();
  175.  
  176. if (isset($view['startdate']))
  177. {
  178. $currMonth = date("Ym", $view['startdate']['timestamp']);
  179. if (!isset($prevMonth))
  180. {
  181. $prevMonth = $currMonth;
  182. }
  183. if ($prevMonth < $currMonth)
  184. {
  185. midcom_show_style("events-month-change");
  186. $prevMonth = $currMonth;
  187. }
  188. }
  189.  
  190. midcom_show_style("events-index-element");
  191.  
  192. if ($latest) {
  193. $count++;
  194. if ($count >= $this->_latest)
  195. break;
  196. }
  197. if ($upcoming) {
  198. $count++;
  199. if ($count >= $this->_upcoming)
  200. break;
  201. }
  202. if ($first) {
  203. $GLOBALS["midcom"]->cache->content->expires($view['date']['timestamp']);
  204. $first = false;
  205. }
  206. }
  207. midcom_show_style("events-index-finish");
  208. }
  209. debug_pop();
  210. }
  211.  
  212. function _show_detail() {
  213. debug_add ("Layout: " . $this->_config->get("schemadb"));
  214. $layout = new midcom_helper_datamanager($this->_config->get("schemadb"));
  215. if (!$layout)
  216. $GLOBALS["midcom"]->generate_error(MIDCOM_ERRCRIT,
  217. "Layout class could not be instantinated. de_linkm_events_viewer::_show_detail Aborting.");
  218. if (!$layout->init($this->_display))
  219. $GLOBALS["midcom"]->generate_error(MIDCOM_ERRCRIT,
  220. "Layout class could not be initialized. de_linkm_events_viewer::_show_detail Aborting.");
  221. $GLOBALS["view"] = $layout->get_array();
  222. $GLOBALS["view_config"] =& $this->_config;
  223. midcom_show_style("events-show-detail");
  224. }
  225.  
  226. function get_metadata() {
  227. return $this->_metadata;
  228. }
  229.  
  230. function _get_newest() {
  231. $articles = mgd_list_topic_articles($this->_topic->id, "revised");
  232. if (!$articles)
  233. return false;
  234. $articles->fetch();
  235. return mgd_get_article($articles->id);
  236. }
  237.  
  238. }
  239.  
  240. ?>

Documentation generated on Mon, 21 Nov 2005 18:22:52 +0100 by phpDocumentor 1.3.0RC3