1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13: class Agora_Block_Thread extends Horde_Core_Block
14: {
15: 16:
17: public function __construct($app, $params = array())
18: {
19: parent::__construct($app, $params);
20:
21: $this->_name = _("Single Thread");
22: }
23:
24: 25:
26: protected function _params()
27: {
28: $forumOb = $GLOBALS['injector']->getInstance('Agora_Factory_Driver')->create();
29: $forums_list = $forumOb->getForums(0, true, 'forum_name', 0, true);
30:
31: $threads = array(
32: 'name' => _("Thread"),
33: 'type' => 'mlenum',
34: 'values' => array()
35: );
36:
37: foreach ($forums_list as $forum) {
38: $threadsOb = $GLOBALS['injector']->getInstance('Agora_Factory_Driver')->create('agora', $forum['forum_id']);
39: $threads_list = $threadsOb->getThreads();
40: foreach ($threads_list as $thread) {
41: if (!isset($threads['default'])) {
42: $threads['default'] = $forum['forum_id'] . '.' . $thread['message_id'];
43: }
44: $threads['values'][$forum['indent'] . $forum['forum_name']][$forum['forum_id'] . '.' . $thread['message_id']] = $thread['message_subject'];
45: }
46: }
47:
48: return array('thread_id' => $threads);
49: }
50:
51: 52:
53: protected function _content()
54: {
55:
56: if (empty($this->_params['thread_id'])) {
57: return '';
58: }
59:
60:
61: list($forum_id, $message_id) = explode('.', $this->_params['thread_id']);
62: $messages = $GLOBALS['injector']->getInstance('Agora_Factory_Driver')->create('agora', $forum_id);
63:
64:
65: if ($messages instanceof PEAR_Error || empty($messages)) {
66: throw new Horde_Exception(_("Unable to fetch selected thread."));
67: }
68:
69:
70: $sort_by = Agora::getSortBy('threads');
71: $sort_dir = Agora::getSortDir('threads');
72: $view_bodies = $GLOBALS['prefs']->getValue('thread_view_bodies');
73:
74:
75: $threads_list = $messages->getThreads($messages->getThreadRoot($message_id), true, $sort_by, $sort_dir, $view_bodies, Horde::selfUrl());
76:
77:
78: $col_headers = array(array('message_thread' => _("Thread"), 'message_subject' => _("Subject")), 'message_author' => _("Posted by"), 'message_timestamp' => _("Date"));
79: $col_headers = Agora::formatColumnHeaders($col_headers, $sort_by, $sort_dir, 'threads');
80:
81:
82: $view = new Agora_View();
83: $view->col_headers = $col_headers;
84: $view->threads_list = $threads_list;
85: $view->threads_list_header = _("Thread List");
86: $view->thread_view_bodies = $view_bodies;
87:
88: return $view->render('block/thread');
89: }
90:
91: }
92: