Passed
Push — my_friends ( be7556 )
by
unknown
23:37
created

colleagues.php ➔ get_mutual_friendship_where_clause()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 8
ccs 0
cts 7
cp 0
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php 
2
/*
3
User profile Colleagues
4
*/
5
6
$owner = elgg_get_page_owner_entity();
7
8
$options = array(
9
    'type' => 'user',
10
    'relationship' => 'friend',
11
    'relationship_guid' => $owner->getGUID(),
12
    'list_type' => 'gallery',
13
    'size' => 'small'
14
);
15
16
// add secondary clause for mutual relationships
17
$options['wheres'][] = get_mutual_friendship_where_clause();
18
$list = elgg_list_entities_from_relationship($options);
19
20
$count = count(elgg_get_entities_from_relationship($options));
21
$friendCount = "({$count})";
22
23
24
$all_link = elgg_view('output/url', array(
25
	'href' => 'friends/' . $owner->username,
26
	'text' => elgg_echo('profile:viewall:coll') . $friendCount,
27
	'is_trusted' => true,
28
    'class' => 'text-center btn btn-default center-block',
29
));
30
31
$footer = "<div class='text-right'>$all_link</div>";
32
33
if($count <= 0) {
34
    $friends = elgg_echo('gcprofile:nocoll', array($owner->getDisplayName()));
35
    $footer = '';
36
}
37
38
echo elgg_view_module('aside', elgg_echo('friends'), $list, array('footer' => $footer));
39
40
41
// checks for reciprical friend relationship
42
function get_mutual_friendship_where_clause() {
43
    $db_prefix = get_config('dbprefix');
44
    return "EXISTS (
45
        SELECT 1 FROM {$db_prefix}entity_relationships r2
46
            WHERE r2.guid_one = r.guid_two
47
            AND r2.relationship = 'friend'
48
            AND r2.guid_two = r.guid_one)";
49
}
50
51
52
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...