Completed
Push — master ( d21053...c59b30 )
by
unknown
08:11
created

start.php ➔ checkProfileStrength()   F

Complexity

Conditions 28
Paths 1536

Size

Total Lines 70

Duplication

Lines 5
Ratio 7.14 %

Importance

Changes 0
Metric Value
cc 28
nc 1536
nop 0
dl 5
loc 70
rs 0
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/*
4
5
Name: Achievement_Badges
6
Author: Globo Gym Purple Cobras
7
Coded By: Ethan Wallace
8
9
Description:
10
Expands user profile to add achievements/badges for the user to earn while using GCconnex.
11
Only the owner of the user profile can see the progress of the achievements.
12
Sidebar displays earned achievements/badges for everyone to see.
13
14
*/
15
16
17
elgg_register_event_handler('init', 'system', 'gcBadges_init');
18
19
function gcBadges_init() {
20
21
    elgg_extend_view('profile/sidebar', 'profile/sidebar_widget', 450);
22
    elgg_extend_view('profile/tab-content', 'profile/badge_progress');
23
    elgg_extend_view('profile/profile_tab_menu', 'profile/tab_menu', 451);
24
25
}
26
27
/*
28
 *
29
 * Grab all badge names
30
 * When adding new badge make sure everything shares this spelling of badge (ex: discussion)
31
 * To add new badge add name to $badges array below
32
 *
33
 */
34
35
36
function get_badges(){
37
38
    $badges = array('complete', 'bookmark', 'likes', 'discussion', 'colleague', 'comment');
39
40
    return $badges;
41
}
42
43
44
function checkProfileStrength(){
45
    $user_guid = elgg_get_page_owner_guid();
46
    $userEnt = get_user ( $user_guid );
47
48
    //avatar
49
    if($userEnt->getIconURL() !=  elgg_get_site_url() . '_graphics/icons/user/defaultmedium.gif'){
50
51
        $avTotal = 100;
52
    }else{
53
54
        $avTotal = 0;
55
    }
56
57
    //About me
58
    if($userEnt->description){
59
60
        $aboutTotal = 100;
61
    }else{
62
63
        $aboutTotal = 0;
64
    }
65
66
    //basic profile
67
    $basicCount = 0;
68
69
    if( strpos(elgg_get_site_entity()->name, 'collab') !== false && ($userEnt->university || $userEnt->college || $userEnt->highschool || $userEnt->federal || $userEnt->ministry || $userEnt->municipal || $userEnt->international || $userEnt->ngo || $userEnt->community || $userEnt->business || $userEnt->media || $userEnt->retired || $userEnt->other) ){
70
        $basicCount += 20;
71
    } else if($userEnt->department){
72
        $basicCount += 20;
73
    }
74
    if($userEnt->job){
75
        $basicCount += 20;
76
    }
77
    if($userEnt->location || $userEnt->addressString || $userEnt->addressStringFr){
78
        $basicCount += 20;
79
    }
80
    if($userEnt->email){
81
        $basicCount += 20;
82
    }
83
    if($userEnt->phone || $userEnt->mobile){
84
        $basicCount += 20;
85
    }
86
87
    //education
88
    if(count($userEnt->education) >= 1){
89
        $eduCount = 100;
90
    } else {
91
        $eduCount = 0;
92
    }
93
94
    //work experience
95
    if(count($userEnt->work) >= 1){
96
        $workCount = 100;
97
    } else {
98
        $workCount = 0;
99
    }
100
101
    //skills
102 View Code Duplication
    if(count($userEnt->gc_skills) >= 3){
103
        $skillCount = 100;
104
    } else {
105
        $skillCount = round(count($userEnt->gc_skills)/3*100);
106
    }
107
108
    //overall total
109
    $complete = round(($skillCount + $workCount + $eduCount + $basicCount + $aboutTotal + $avTotal)/6);
110
111
    //set up profile strength metadata
112
    $userEnt->profilestrength = $complete;
113
}
114