1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13:
14: class Agora_Block_Threads extends Horde_Core_Block
15: {
16: 17: 18: 19: 20:
21: private $_threads = array();
22:
23: 24:
25: public function __construct($app, $params = array())
26: {
27: parent::__construct($app, $params);
28:
29: $this->_name = _("Threads");
30: }
31:
32: 33:
34: protected function _params()
35: {
36: $params = array();
37:
38: $forums = $GLOBALS['injector']->getInstance('Agora_Factory_Driver')->create();
39:
40:
41: 42:
43: $forums_list = array();
44: foreach ($forums->getForums(0, false, 'forum_name', 0, !$GLOBALS['registry']->isAdmin()) as $forum) {
45: $forums_list[$forum['forum_id']] = $forum['forum_name'];
46: }
47: $params['forum_id'] = array(
48: 'name' => _("Forum"),
49: 'type' => 'enum',
50: 'values' => $forums_list,
51: );
52:
53:
54: $params['thread_display'] = array(
55: 'name' => _("Only display this many threads (0 to display all threads)"),
56: 'type' => 'int',
57: 'default' => 0,
58: 'values' => $GLOBALS['prefs']->getValue('threads_block_display'),
59: );
60:
61: return $params;
62: }
63:
64: 65:
66: protected function _title()
67: {
68: if (!isset($this->_params['forum_id'])) {
69: return $this->getName();
70: }
71:
72: if (empty($this->_threads)) {
73: $this->_threads = $GLOBALS['injector']->getInstance('Agora_Factory_Driver')->create('agora', $this->_params['forum_id']);
74: if ($this->_threads instanceof PEAR_Error) {
75: return $this->getName();
76: }
77: }
78:
79: $title = sprintf(_("Threads in \"%s\""), $this->_threads->_forum['forum_name']);
80: $url = Horde::url('threads.php', true);
81: if (!empty($scope)) {
82: $url = Horde_Util::addParameter($url, 'scope', $scope);
83: }
84:
85: return Horde::link(Agora::setAgoraId($this->_params['forum_id'], null, $url))
86: . $title . '</a>';
87: }
88:
89: 90:
91: protected function _content()
92: {
93: if (!isset($this->_params['forum_id'])) {
94: throw new Horde_Exception(_("No forum selected"));
95: }
96:
97: if (empty($this->_threads)) {
98: $this->_threads = $GLOBALS['injector']->getInstance('Agora_Factory_Driver')->create('agora', $this->_params['forum_id']);
99: if ($this->_threads instanceof PEAR_Error) {
100: throw new Horde_Exception(_("Unable to fetch threads for selected forum."));
101: }
102: }
103:
104:
105: $sort_by = Agora::getSortBy('threads');
106: $sort_dir = Agora::getSortDir('threads');
107:
108: 109:
110: $threads_list = $this->_threads->getThreads(0, false, $sort_by, $sort_dir, false, Horde::selfUrl(), null, 0, !empty($this->_params['thread_display']) ? $this->_params['thread_display'] : null);
111:
112: 113:
114: if (empty($threads_list)) {
115: return _("No available threads.");
116: }
117:
118:
119: $col_headers = array('message_subject' => _("Subject"), 'message_author' => _("Posted by"), 'message_timestamp' => _("Date"));
120: $col_headers = Agora::formatColumnHeaders($col_headers, $sort_by, $sort_dir, 'threads');
121:
122:
123: $view = new Agora_View();
124: $view->col_headers = $col_headers;
125: $view->threads = $threads_list;
126:
127: return $view->render('block/threads');
128: }
129:
130: }
131: