| | 163 | |
|---|
| | 164 | |
|---|
| | 165 | /** |
|---|
| | 166 | * @param mixed $handler_id The ID of the handler. |
|---|
| | 167 | * @param Array $args The argument list. |
|---|
| | 168 | * @param Array &$data The local request data. |
|---|
| | 169 | * @return bool Indicating success. |
|---|
| | 170 | */ |
|---|
| | 171 | function _handler_tag($handler_id, $args, &$data) |
|---|
| | 172 | { |
|---|
| | 173 | $data['forum'] =& $this->_topic; |
|---|
| | 174 | $data['tag'] = $args[0]; |
|---|
| | 175 | |
|---|
| | 176 | $_MIDCOM->load_library('net.nemein.tag'); |
|---|
| | 177 | |
|---|
| | 178 | // Set context data |
|---|
| | 179 | /** |
|---|
| | 180 | * TODO: Figure out the latest thread/post metadata_revised to get the correct timestamp |
|---|
| | 181 | * this should give us reasonably working caching but the MIDCOM_CONTEXT_LASTMODIFIED is |
|---|
| | 182 | * naturally wrong |
|---|
| | 183 | */ |
|---|
| | 184 | $_MIDCOM->set_26_request_metadata(time(), $this->_topic->guid); |
|---|
| | 185 | |
|---|
| | 186 | // Prepare datamanager |
|---|
| | 187 | $data['datamanager'] = new midcom_helper_datamanager2_datamanager($data['schemadb']); |
|---|
| | 188 | |
|---|
| | 189 | // Get discussion thread GUIDs from tags |
|---|
| | 190 | $data['mc'] = net_nemein_tag_link_dba::new_collector('sitegroup', $_MIDGARD['sitegroup']); |
|---|
| | 191 | $data['mc']->add_value_property('fromGuid'); |
|---|
| | 192 | |
|---|
| | 193 | $data['mc']->begin_group('OR'); |
|---|
| | 194 | $data['mc']->add_constraint('fromClass', '=', 'net_nemein_discussion_thread_dba'); |
|---|
| | 195 | $data['mc']->add_constraint('fromClass', '=', 'net_nemein_discussion_thread'); |
|---|
| | 196 | $data['mc']->end_group(); |
|---|
| | 197 | |
|---|
| | 198 | $data['mc']->add_constraint('tag.tag', '=', $data['tag']); |
|---|
| | 199 | $data['mc']->execute(); |
|---|
| | 200 | |
|---|
| | 201 | $data['tags_links'] = $data['mc']->list_keys(); |
|---|
| | 202 | |
|---|
| | 203 | if (count($data['tags_links']) == 0) |
|---|
| | 204 | { |
|---|
| | 205 | $_MIDCOM->generate_error(MIDCOM_ERRNOTFOUND, "No discussion threads with tag '{$data['tag']}' found."); |
|---|
| | 206 | // This will exit |
|---|
| | 207 | } |
|---|
| | 208 | |
|---|
| | 209 | return true; |
|---|
| | 210 | } |
|---|
| | 211 | |
|---|
| | 212 | /** |
|---|
| | 213 | * |
|---|
| | 214 | * @param mixed $handler_id The ID of the handler. |
|---|
| | 215 | * @param mixed &$data The local request data. |
|---|
| | 216 | */ |
|---|
| | 217 | function _show_tag($handler_id, &$data) |
|---|
| | 218 | { |
|---|
| | 219 | // List threads |
|---|
| | 220 | $qb = new org_openpsa_qbpager('net_nemein_discussion_thread_dba', 'net_nemein_discussion_thread'); |
|---|
| | 221 | $qb->results_per_page = $this->_config->get('display_threads'); |
|---|
| | 222 | $qb->display_pages = $this->_config->get('display_pages'); |
|---|
| | 223 | |
|---|
| | 224 | // Constrain by tag links |
|---|
| | 225 | $qb->begin_group('OR'); |
|---|
| | 226 | foreach ($data['tags_links'] as $guid => $array) |
|---|
| | 227 | { |
|---|
| | 228 | $thread_guid = $data['mc']->get_subkey($guid, 'fromGuid'); |
|---|
| | 229 | $qb->add_constraint('guid', '=', $thread_guid); |
|---|
| | 230 | } |
|---|
| | 231 | $qb->end_group(); |
|---|
| | 232 | |
|---|
| | 233 | $qb->add_constraint('node', '=', $this->_topic->id); |
|---|
| | 234 | $qb->add_constraint('posts', '>', 0); |
|---|
| | 235 | $qb->add_order('sticky', 'DESC'); |
|---|
| | 236 | $qb->add_order($this->_config->get('order_threads_by'), 'DESC'); |
|---|
| | 237 | $threads = $qb->execute_unchecked(); |
|---|
| | 238 | $data['thread_qb'] =& $qb; |
|---|
| | 239 | $date = null; |
|---|
| | 240 | midcom_show_style('view-index-header'); |
|---|
| | 241 | |
|---|
| | 242 | if ($threads) |
|---|
| | 243 | { |
|---|
| | 244 | foreach ($threads as $i => $thread) |
|---|
| | 245 | { |
|---|
| | 246 | if ($this->_config->get('order_threads_by') == 'latestposttime') |
|---|
| | 247 | { |
|---|
| | 248 | $thread_date = date('Y-m-d', $thread->latestposttime); |
|---|
| | 249 | $thread_time = $thread->latestposttime; |
|---|
| | 250 | } |
|---|
| | 251 | else |
|---|
| | 252 | { |
|---|
| | 253 | $thread_date = date('Y-m-d', $thread->metadata->published); |
|---|
| | 254 | $thread_time = $thread->metadata->published; |
|---|
| | 255 | } |
|---|
| | 256 | |
|---|
| | 257 | if ($date != $thread_date) |
|---|
| | 258 | { |
|---|
| | 259 | $data['date'] = $thread_time; |
|---|
| | 260 | if (!is_null($date)) |
|---|
| | 261 | { |
|---|
| | 262 | midcom_show_style('view-index-date-footer'); |
|---|
| | 263 | } |
|---|
| | 264 | midcom_show_style('view-index-date-header'); |
|---|
| | 265 | $date = $thread_date; |
|---|
| | 266 | } |
|---|
| | 267 | |
|---|
| | 268 | $data['index_count'] =& $i; |
|---|
| | 269 | $data['thread'] =& $thread; |
|---|
| | 270 | |
|---|
| | 271 | $data['latest_post'] = new net_nemein_discussion_post_dba($thread->latestpost); |
|---|
| | 272 | $data['view_latest_post'] = array(); |
|---|
| | 273 | if ($data['datamanager']->autoset_storage($data['latest_post'])) |
|---|
| | 274 | { |
|---|
| | 275 | $data['view_latest_post'] = $data['datamanager']->get_content_html(); |
|---|
| | 276 | } |
|---|
| | 277 | |
|---|
| | 278 | $data['first_post'] = null; |
|---|
| | 279 | $data['view_first_post'] = array(); |
|---|
| | 280 | if ($thread->firstpost) |
|---|
| | 281 | { |
|---|
| | 282 | $data['first_post'] = new net_nemein_discussion_post_dba($thread->firstpost); |
|---|
| | 283 | |
|---|
| | 284 | if ($data['datamanager']->autoset_storage($data['first_post'])) |
|---|
| | 285 | { |
|---|
| | 286 | $data['view_first_post'] = $data['datamanager']->get_content_html(); |
|---|
| | 287 | } |
|---|
| | 288 | } |
|---|
| | 289 | |
|---|
| | 290 | midcom_show_style('view-index-item'); |
|---|
| | 291 | } |
|---|
| | 292 | } |
|---|
| | 293 | midcom_show_style('view-index-date-footer'); |
|---|
| | 294 | midcom_show_style('view-index-footer'); |
|---|
| | 295 | } |
|---|