/** * Returns a single resquested topic. * @param array $args must contain 'resID' key with the resource identifier of the requested resource * @throws InvalidArgumentException if one of the paramaters is missing * @webservice{/module/MOBILE/CLANN/getSingleResource/cidReq/resId} * @ws_arg{Method,getSingleResource} * @ws_arg{cidReq,SYSCODE of requested cours} * @ws_arg{resID,Resource Id of requested resource} * @return announce object (can be null if not visible for the current user) */ function getSingleResource($args) { $resourceId = isset($args['resID']) ? $args['resID'] : null; $cid = claro_get_current_course_id(); if ($cid == null || $resourceId == null) { throw new InvalidArgumentException('Missing cid or resourceId argument!'); } FromKernel::uses('forum.lib'); $claroNotification = Claroline::getInstance()->notification; $date = $claroNotification->getLastActionBeforeLoginDate(claro_get_current_user_id()); $d = new DateTime($date); $d->sub(new DateInterval('PT1M')); $item = null; foreach (get_forum_list() as $forum) { if ($forum['forum_id'] == $resourceID) { $item = $forum; break; } } if ($item) { $item['resourceId'] = $item['forum_id']; $item['title'] = $item['forum_name']; foreach (get_category_list as $cat) { if ($cat['cat_id'] == $item['cat_id']) { $item['cat_title'] = $cat['cat_title']; $item['cat_order'] = $cat['cat_order']; break; } } $item['topics'] = array(); $topics = new topicLister($item['forum_id'], 0, $item['forum_topics']); foreach ($topics->get_topic_list() as $topic) { $topic['resourceId'] = $topic['topic_id']; $topic['title'] = $topic['topic_title']; $topic['poster_firstname'] = $topic['prenom']; $topic['poster_lastname'] = $topic['nom']; $topic['date'] = $topic['topic_time']; $topic['posts'] = array(); $posts = new postLister($topic['topic_id'], 0, $topic['topic_replies'] + 1); foreach ($posts->get_post_list() as $post) { $notified = $claroNotification->isANotifiedRessource($cid, $date, claro_get_current_user_id(), claro_get_current_group_id(), get_tool_id_from_module_label('CLFRM'), $item['forum_id'] . '-' . $topic['topic_id'] . '-' . $post['post_id'], false); $post['notifiedDate'] = $notified ? $date : $post['post_time']; $post['seenDate'] = $d->format('Y-m-d H:i'); $post['post_text'] = trim(strip_tags($post['post_text'])); $post['resourceId'] = $post['post_id']; $post['date'] = $post['post_time']; unset($post['post_id']); unset($post['topic_id']); unset($post['forum_id']); unset($post['poster_id']); unset($post['post_time']); unset($post['poster_ip']); $topic['posts'][] = $post; } unset($topic['topic_id']); unset($topic['topic_title']); unset($topic['topic_poster']); unset($topic['topic_time']); unset($topic['topic_replies']); unset($topic['topic_last_post_id']); unset($topic['forum_id']); unset($topic['topic_notify']); unset($topic['nom']); unset($topic['prenom']); unset($topic['post_time']); $item['topics'][] = $topic; } unset($item['forum_id']); unset($item['forum_name']); unset($item['forum_moderator']); unset($item['forum_topics']); unset($item['forum_posts']); unset($item['forum_last_post_id']); unset($item['forum_type']); unset($item['group_id']); unset($item['poster_id']); unset($item['post_time']); return $item; } else { throw new RuntimeException('Resource not found', 404); } }
$out .= claro_html_tool_title(get_lang('Forums'), $is_allowedToEdit ? get_help_page_url('blockForumsHelp', 'CLFRM') : false, $cmdList); if (!$viewAllowed) { $out .= $dialogBox->render(); } else { $colspan = $is_allowedToEdit ? 9 : 6; $is_allowedToEdit = claro_is_allowed_to_edit() || claro_is_group_tutor() && !claro_is_course_manager(); // ( claro_is_group_tutor() // is added to give admin status to tutor // && !claro_is_course_manager()) // is added to let course admin, tutor of current group, use student mode if (claro_is_allowed_to_edit()) { $out .= '<div style="float: right;">' . "\n" . '<img src="' . get_icon_url('html') . '" alt="" /> <a href="' . claro_htmlspecialchars(Url::Contextualize('export.php?type=HTML&forum=' . $forumId)) . '" target="_blank">' . get_lang('Export to HTML') . '</a>' . "\n" . '<img src="' . get_icon_url('mime/pdf') . '" alt="" /> <a href="' . claro_htmlspecialchars(Url::Contextualize('export.php?type=PDF&forum=' . $forumId)) . '" target="_blank">' . get_lang('Export to PDF') . '</a>' . "\n" . '</div>' . "\n"; } $out .= disp_forum_breadcrumb($pagetype, $forumId, $forum_name); $out .= $dialogBox->render(); $topicLister = new topicLister($forumId, $start, get_conf('topics_per_page')); $topicList = $topicLister->get_topic_list(); $pagerUrl = claro_htmlspecialchars(Url::Contextualize(get_module_url('CLFRM') . '/viewforum.php?forum=' . $forumId)); $out .= $topicLister->disp_pager_tool_bar($pagerUrl); try { $display = new ModuleTemplate('CLFRM', 'forum_viewforum.tpl.php'); $display->assign('forumId', $forumId); $display->assign('forumName', $display_name); $display->assign('forumSettings', $forumSettingList); $display->assign('topicList', $topicList); $display->assign('is_allowedToEdit', $is_allowedToEdit); $display->assign('claro_notifier', $claro_notifier); $out .= $display->render(); } catch (Exception $ex) { $dialogBox->error($ex); }