FacebookIdentifier::isConnectedToFacebook()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/**
4
 * adds Facebook functionality to Member.
5
 *
6
 *
7
 *
8
 */
9
10
class FacebookIdentifier extends DataObjectDecorator
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
11
{
12
    public function extraStatics()
13
    {
14
        return array(
15
            'db' => array(
16
                'FacebookID' => 'Varchar',
17
                'FacebookURL' => 'Varchar(255)',
18
                'FacebookPicture' => 'Text',
19
                'FacebookName' => 'Varchar(255)',
20
                'FacebookEmail' => 'Varchar(255)',
21
                'FacebookFirstName' => 'Varchar(255)',
22
                'FacebookMiddleName' => 'Varchar(255)',
23
                'FacebookLastName' => 'Varchar(255)',
24
                'FacebookUsername' => 'Varchar(255)'
25
            ),
26
            'indexes' => array(
27
                'FacebookID' => true,
28
                'FacebookUsername' => true
29
            ),
30
            'casting' => array(
31
                'FacebookButton' => 'ArrayData'
32
            )
33
        );
34
    }
35
36
37
    /**
38
     * connect and disconnect button
39
     * @return Object (IsConnected, Link, ConnectedName, ConnectedImageURL)
40
     */
41
    public function getFacebookButton($backURL = "")
42
    {
43
        return FacebookCallback::get_login_button($backURL, $this->owner);
44
    }
45
46
    /**
47
     *
48
     * user has logged in with facebook before?
49
     * @return Boolean
50
     */
51
    public function hasFacebook()
52
    {
53
        return (bool)$this->owner->FacebookID;
54
    }
55
56
    /**
57
     * user is currenctly connected to Faceboo
58
     *
59
     *
60
     */
61
    public function isConnectedToFacebook()
62
    {
63
        return FacebookCallback::get_current_user();
64
    }
65
66
67
    /**
68
     * link to profile
69
     * @return String
70
     */
71
    public function FacebookLink()
72
    {
73
        if ($this->owner->FacebookURL) {
74
            return $this->owner->FacebookURL;
75
        }
76
        if ($this->owner->FacebookID) {
77
            return "http://www.facebook.com/people/@/".$this->owner->FacebookID;
78
        }
79
        return "";
80
    }
81
82 View Code Duplication
    public function onBeforeWrite()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
83
    {
84
        if (!$this->owner->Email) {
85
            if ($this->owner->FacebookEmail) {
86
                $id = $this->owner->ID;
87
                if (!$id) {
88
                    $id = 0;
89
                }
90
                if (!DataObject::get_one("Member", "\"Email\" = '".$this->owner->FacebookEmail."' AND \"Member\".\"ID\" <> ".$id."")) {
91
                    $this->owner->Email = $this->owner->FacebookEmail;
92
                }
93
            }
94
        }
95
    }
96
}
97