SoftwareAuthorMemberDOD   A
last analyzed

Complexity

Total Complexity 18

Size/Duplication

Total Lines 147
Duplicated Lines 0 %

Coupling/Cohesion

Components 4
Dependencies 4

Importance

Changes 0
Metric Value
wmc 18
lcom 4
cbo 4
dl 0
loc 147
c 0
b 0
f 0
rs 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A set_register_group_title() 0 4 1
A get_register_group_title() 0 4 1
A set_register_group_code() 0 4 1
A get_register_group_code() 0 4 1
A set_register_group_access_key() 0 4 1
A get_register_group_access_key() 0 4 1
A Currency() 0 5 1
B updateMemberFormFields() 0 42 5
A onBeforeWrite() 0 21 4
A ListOfModulesLink() 0 9 2
1
<?php
2
3
/**
4
 * extends Member with fields specific to the Software Author
5
 * @author nicolaas [at] sunnysideup.co.nz
6
 *
7
 *
8
 **/
9
10
class SoftwareAuthorMemberDOD extends DataExtension
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
    private static $register_group_title = "Software Authors";
13
    public function set_register_group_title($s)
14
    {
15
        self::$register_group_title = $s;
16
    }
17
    public function get_register_group_title()
18
    {
19
        return self::$register_group_title;
20
    }
21
22
    private static $register_group_code = "softwareauthors";
23
    public function set_register_group_code($s)
24
    {
25
        self::$register_group_code = $s;
26
    }
27
    public function get_register_group_code()
28
    {
29
        return self::$register_group_code;
30
    }
31
32
    private static $register_group_access_key = "SOFTWAREAUTHORS";
33
    public function set_register_group_access_key($s)
34
    {
35
        self::$register_group_access_key = $s;
36
    }
37
    public function get_register_group_access_key()
38
    {
39
        return self::$register_group_access_key;
40
    }
41
42
    private static $db = array(
0 ignored issues
show
Unused Code introduced by
The property $db is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
43
        "ScreenName" => "Varchar(255)",
44
        "GithubURL" => "Varchar(255)",
45
        "SilverstripeDotOrgURL" => "Varchar(255)",
46
        "CompanyName" => "Varchar(255)",
47
        "CompanyURL" => "Varchar(255)",
48
        "AreYouHappyForPeopleToContactYou" => "Boolean",
49
        "ContactDetailURL" => "Varchar(255)",
50
        "OtherURL" => "Varchar(255)",
51
        "AreYouAvailableForPaidSupport" => "Boolean",
52
        "Rate15Mins" => "Currency",
53
        "Rate120Mins" => "Currency",
54
        "Rate480Mins" => "Currency"
55
    );
56
57
    private static $belongs_many_many = array(
0 ignored issues
show
Unused Code introduced by
The property $belongs_many_many is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
58
        "ModuleProducts" => "ModuleProduct"
59
    );
60
61
    private static $defaults= array(
0 ignored issues
show
Unused Code introduced by
The property $defaults is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
62
        "Rate15Mins" => 0,
63
        "Rate120Mins" => 0,
64
        "Rate480Mins" => 0
65
    );
66
67
    private static $api_acces = array(
0 ignored issues
show
Unused Code introduced by
The property $api_acces is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
68
        "view" => array("ModuleProducts", "ScreenName")
69
    );
70
71
    /**
72
     * Returns the currency used on the site.
73
     * @return String
0 ignored issues
show
Documentation introduced by
Should the return type not be array|integer|double|string|boolean?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
74
     */
75
    public function Currency()
76
    {
77
        $currency = EcommercePayment::site_currency();
78
        return $currency;
79
    }
80
81
    public function updateMemberFormFields(&$fields)
82
    {
83
        $currency = $this->Currency();
84
        $fields->RemoveByName("PreferredCurrencyID");
85
        $field = $fields->fieldByName("ScreenName");
86
        $field->setTitle("Screen Name / Alias");
87
        $field = $fields->fieldByName("GithubURL");
88
        $field->setTitle("Github URL - e.g. https://github.com/mynamehere");
89
        $field = $fields->fieldByName("SilverstripeDotOrgURL");
90
        $field->setTitle("www.silverstripe.org URL - e.g. http://www.silverstripe.org/ForumMemberProfile/show/1");
91
        $field = $fields->fieldByName("CompanyName");
92
        $field->setTitle("Company Name (if any)");
93
        $field = $fields->fieldByName("CompanyURL");
94
        $field->setTitle("Company Link - e.g. http://www.the-company-i-work-for.co.nz/");
95
        $field = $fields->fieldByName("AreYouHappyForPeopleToContactYou");
96
        $field->setTitle("Are you happy to answer private questions about your code?");
97
        $field = $fields->fieldByName("ContactDetailURL");
98
        $field->setTitle("Contact Details URL - e.g. http://www.mysite.com/contact/");
99
        $field = $fields->fieldByName("OtherURL");
100
        $field->setTitle("other URL - e.g.  - e.g. http://www.mysite.com/about-me/");
101
        $field = $fields->fieldByName("AreYouAvailableForPaidSupport");
102
        $field->setTitle("Are you available for paid support?");
103
        $field = $fields->fieldByName("Rate15Mins");
104
        $field->setTitle("If applicable, approximate charge (in $currency) for a fifteen minute skype chat?");
105
        $field = $fields->fieldByName("Rate120Mins");
106
        $field->setTitle("If applicable, approximate charge (in $currency) for a two hour support block?");
107
        $field = $fields->fieldByName("Rate480Mins");
108
        $field->setTitle("If applicable, approximate charge (in $currency) for a development day (eight hours)?");
109
        if ($modules = $this->owner->ModuleProducts()) {
110
            if ($modules->count()) {
111
                $html = "<h3 id=\"ModuleListHeading\" class=\"clear\"><a href=\"".$this->ListOfModulesLink()."\">Currently Listed Modules ...</a></h3><ul>";
112
                foreach ($modules as $module) {
113
                    if ($module->ShowInSearch) {
114
                        $html .= "<li><a href=\"".$module->Link()."\">".$module->Title."</a></li>";
115
                    }
116
                }
117
                $html .= "</ul>";
118
                $fields->push(new LiteralField("ModuleList", $html));
119
            }
120
        }
121
        Requirements::javascript("ecommerce_software/javascript/SoftwareAuthorMemberDOD.js");
122
    }
123
124
125
    public function onBeforeWrite()
126
    {
127
        $id = intval($this->owner->ID);
128
        if (!$id) {
129
            $id = 0;
130
        }
131
        $i = 0;
132
        $startScreenName = $this->owner->ScreenName;
133
        $this->owner->ScreenName = preg_replace("[^A-Za-z0-9]", "", $this->owner->ScreenName);
134
        $className = $this->owner->ClassName;
135
        while ($className::get()
136
            ->filter(array("ScreenName" => $this->owner->ScreenName))
137
            ->exclude(array("ID" => $id ))
138
            ->first()
139
            && $i < 10
140
        ) {
141
            $i++;
142
            $this->ScreenName = $startScreenName."_".$i;
0 ignored issues
show
Bug introduced by
The property ScreenName does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
143
        }
144
        $this->owner->Locale = "en_GB";
145
    }
146
147
    public function ListOfModulesLink()
148
    {
149
        $page = ModuleProductGroup::get()
150
            ->filter(array("LevelOfProductsToShow" => 1))
151
            ->first();
152
        if ($page) {
153
            return $page->Link()."#author_".$this->owner->ScreenName;
154
        }
155
    }
156
}
157