Test Failed
Push — master ( 8c47c2...3acf9f )
by Steve
12:37
created

discussions/views/default/object/discussion.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * Forum topic entity view
4
 */
5
6
$full = elgg_extract('full_view', $vars, false);
7
$topic = elgg_extract('entity', $vars, false);
8
9
if (!$topic) {
10
	return;
11
}
12
13
$poster = $topic->getOwnerEntity();
14
if (!$poster) {
15
	elgg_log("User {$topic->owner_guid} could not be loaded, and is needed to display entity {$topic->guid}", 'WARNING');
16
	if ($full) {
17
		forward('', '404');
18
	}
19
	return;
20
}
21
22
$excerpt = elgg_get_excerpt($topic->description);
23
24
$poster_icon = elgg_view_entity_icon($poster, 'tiny');
25
26
$by_line = elgg_view('object/elements/imprint', $vars);
27
28
$replies_link = '';
29
$reply_text = '';
30
31
$num_replies = elgg_get_entities([
32
	'type' => 'object',
33
	'subtype' => 'discussion_reply',
34
	'container_guid' => $topic->getGUID(),
35
	'count' => true,
36
	'distinct' => false,
37
]);
38
39
if ($num_replies != 0) {
40
	$last_reply = elgg_get_entities([
41
		'type' => 'object',
42
		'subtype' => 'discussion_reply',
43
		'container_guid' => $topic->getGUID(),
44
		'limit' => 1,
45
		'distinct' => false,
46
	]);
47
	if (isset($last_reply[0])) {
48
		$last_reply = $last_reply[0];
49
	}
50
	/* @var ElggDiscussionReply $last_reply */
51
52
	$poster = $last_reply->getOwnerEntity();
53
	$reply_time = elgg_view_friendly_time($last_reply->time_created);
54
55
	$reply_text = elgg_view('output/url', [
56
		'text' => elgg_echo('discussion:updated', [$poster->name, $reply_time]),
57
		'href' => $last_reply->getURL(),
58
		'is_trusted' => true,
59
	]);
60
61
	$replies_link = elgg_view('output/url', [
62
		'href' => $topic->getURL() . '#group-replies',
63
		'text' => elgg_echo('discussion:replies') . " ($num_replies)",
64
		'is_trusted' => true,
65
	]);
66
}
67
68
// do not show the metadata and controls in widget view
69
$metadata = '';
70 View Code Duplication
if (!elgg_in_context('widgets')) {
1 ignored issue
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
71
	// only show entity menu outside of widgets
72
	$metadata = elgg_view_menu('entity', [
73
		'entity' => $vars['entity'],
74
		'handler' => 'discussion',
75
		'sort_by' => 'priority',
76
		'class' => 'elgg-menu-hz',
77
	]);
78
}
79
80
if ($full) {
81
	$subtitle = "$by_line $replies_link";
82
83
	$params = [
84
		'entity' => $topic,
85
		'title' => false,
86
		'metadata' => $metadata,
87
		'subtitle' => $subtitle,
88
	];
89
90
	$params = $params + $vars;
91
	$summary = elgg_view('object/elements/summary', $params);
92
93
	$body = elgg_view('output/longtext', [
94
		'value' => $topic->description,
95
		'class' => 'clearfix',
96
	]);
97
98
	$responses = '';
99
	if (elgg_extract('show_responses', $vars)) {
100
		$params = [
101
			'topic' => $topic,
102
			'show_add_form' => $topic->canWriteToContainer(0, 'object', 'discussion_reply'),
103
		];
104
		$responses = elgg_view('discussion/replies', $params);
105
		if ($topic->status == 'closed') {
106
			$responses .= elgg_view('discussion/closed');
107
		}
108
	}
109
110
	echo elgg_view('object/elements/full', [
111
		'entity' => $topic,
112
		'icon' => $poster_icon,
113
		'summary' => $summary,
114
		'body' => $body,
115
		'responses' => $responses,
116
		'show_navigation' => true,
117
	]);
118 View Code Duplication
} else {
119
	// brief view
120
	$subtitle = "$by_line $replies_link <span class=\"float-alt\">$reply_text</span>";
121
122
	$params = [
123
		'entity' => $topic,
124
		'metadata' => $metadata,
125
		'subtitle' => $subtitle,
126
		'content' => $excerpt,
127
		'icon' => $poster_icon,
128
	];
129
	$params = $params + $vars;
130
	echo elgg_view('object/elements/summary', $params);
131
}
132