Completed
Push — master ( 95b9d3...1cdd25 )
by
unknown
07:56
created

sidebar.php ➔ get_mutual_friendship_where_clause()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 8
ccs 0
cts 7
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
User profile Sidebar
5
*/
6
$owner = elgg_get_page_owner_entity();
7
8
$options = array(
9
    'type' => 'user',
10
    'pagination' => FALSE,
11
    'relationship' => 'friend',
12
    'relationship_guid' => $owner->getGUID(),
13
    'list_type' => 'gallery',
14
    'limit' => 14,
15
    'size' => 'small'
16
);
17
18
// add secondary clause for mutual relationships
19
$options['wheres'][] = get_mutual_friendship_where_clause();
20
$list = elgg_list_entities_from_relationship($options);
21
$count = count(elgg_get_entities_from_relationship($options));
22
23
$all_link = elgg_view('output/url', array(
24
	'href' => 'friends/' . $owner->username,
25
	'text' => elgg_echo('profile:viewall:coll'),
26
	'is_trusted' => true,
27
    'class' => 'text-center btn btn-default center-block',
28
));
29
30
$footer = "<div class='text-right'>$all_link</div>";
31
32
if($count <= 0) {
33
    $friends = elgg_echo('gcprofile:nocoll', array($owner->getDisplayName()));
34
    $footer = '';
35
}
36
37
echo elgg_view_module('aside', elgg_echo('friends'), $list, array('footer' => $footer));
38
39
40
// checks for reciprical friend relationship
41
function get_mutual_friendship_where_clause() {
42
    $db_prefix = get_config('dbprefix');
43
    return "EXISTS (
44
        SELECT 1 FROM {$db_prefix}entity_relationships r2
45
            WHERE r2.guid_one = r.guid_two
46
            AND r2.relationship = 'friend'
47
            AND r2.guid_two = r.guid_one)";
48
}
49
50
/*
51
User Profile Groups
52
*/
53
54
$owner = elgg_get_page_owner_entity();
55
56
$groups = elgg_get_entities_from_relationship(array(
57
    'relationship'=> 'member', 
58
    'relationship_guid'=> $owner->guid, 
59
    'inverse_relationship'=> FALSE, 
60
    'type'=> 'group', 
61
    'limit'=> 3
62
));
63
64
$count = elgg_get_entities_from_relationship(array(
65
    'relationship'=> 'member',
66
    'relationship_guid'=> $owner->guid,
67
    'inverse_relationship'=> FALSE,
68
    'type'=> 'group',
69
    'limit'=> false,
70
    'count'=>true,
71
));
72
73
$options = array(
74
            'full_view' => false,
75
            'list_type' => 'list',
76
            'pagination' => false,
77
        );
78
79
$content = elgg_view_entity_list($groups, $options);
80
81
$groupCount = '(' . $count . ')';
82
83
$all_link = elgg_view('output/url', array(
84
	'href' => 'groups/member/' . $owner->username,
85
	'text' => elgg_echo('profile:viewall:groups') . $groupCount,
86
	'is_trusted' => true,
87
    'class' => 'text-center btn btn-default center-block',
88
));
89
90
$footer = "<div class='text-right'>$all_link</div>";
91
92
if(!($groups)) {
93
94
    $content = elgg_echo('gcprofile:nogroups', array($owner->getDisplayName()));
95
    $footer='';
96
}
97
98
echo elgg_view_module('aside', elgg_echo('groups'), $content, array('footer' => $footer));
99
100
//echo elgg_view('profile/sidebar/colleagues', $vars);
101
//echo elgg_view('profile/sidebar/user_groups', $vars);
102
103
?>
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...