AddingModuleProduct_RequiredFields::php()   B
last analyzed

Complexity

Conditions 5
Paths 10

Size

Total Lines 28
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 28
c 0
b 0
f 0
rs 8.439
cc 5
eloc 20
nc 10
nop 1
1
<?php
2
3
/**
4
 *
5
 *
6
 *
7
 *
8
 **/
9
10
11
class AddingModuleProduct extends Page
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...
12
{
13
    private static $icon = "ecommerce_software/images/treeicons/AddingModuleProduct";
0 ignored issues
show
Unused Code introduced by
The property $icon 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...
14
}
15
16
17
class AddingModuleProduct_Controller extends Page_Controller
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
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...
18
{
19
    public function init()
0 ignored issues
show
Coding Style introduced by
init uses the super-global variable $_REQUEST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
20
    {
21
        parent::init();
22
        if (!Member::currentUser()) {
23
            $link = RegisterAndEditDetailsPage::link_for_going_to_page_via_making_user($this->Link());
24
            $this->redirect($link);
25
        }
26
        if (isset($_REQUEST["ModuleProductID"])) {
27
            $this->moduleProductID = intval($_REQUEST["ModuleProductID"]);
28
        }
29
    }
30
31
    public function Form()
32
    {
33
        if (Member::currentUser()) {
34
            return new AddingModuleProduct_Form($this, "Form", $this->moduleProductID);
35
        }
36
    }
37
}
38
39
class AddingModuleProduct_Form extends Form
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
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...
40
{
41
    public function __construct($controller, $name, $moduleProductID = 0)
42
    {
43
        $fields = new FieldList();
44
        $moduleProduct = null;
45
        if ($moduleProductID) {
46
            $fields->push(new HeaderField('AddEditModule', 'Edit '.$controller->dataRecord->Title, 2));
47
            $fields->push(new HiddenField('ModuleProductID', $moduleProductID, $moduleProductID));
48
            $moduleProduct = ModuleProduct::get()->byID($moduleProductID);
49
        } else {
50
            $fields->push(new HeaderField('AddEditModule', $controller->dataRecord->Title, 2));
51
            $fields->push(new HiddenField('ModuleProductID', 0, 0));
52
        }
53
        $fields->push(new TextField('Code', 'Code (folder name)'));
54
        $moduleProductGroups = ModuleProductGroup::get()
0 ignored issues
show
Unused Code introduced by
$moduleProductGroups is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
55
            ->filter(array("ParentID:GreaterThan" => 0));
56
        if (ModuleProductGroup::get()->count()) {
57
            $types = array("" => " --- please select ---");
58
            $types += ModuleProductGroup::get()->map($index = 'ID', $titleField = 'MenuTitle')->toArray();
59
        } else {
60
            $types = array();
0 ignored issues
show
Unused Code introduced by
$types is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
61
        }
62
        //$fields->push(new DropdownField('ParentID','Type', $types, $controller->dataRecord->ID));
0 ignored issues
show
Unused Code Comprehensibility introduced by
71% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
63
        $fields->push(new TextField('Title', 'Title'));
64
        $fields->push(new TextareaField('MetaDescription', 'Three sentence Introduction'));
65
        $fields->push(new HtmlEditorField('Content', 'Long Description'));
66
        $fields->push(new TextField('AdditionalTags', 'Additional Keyword(s), comma separated'));
67
        $fields->push(new HeaderField('LinkHeader', 'Links', 4));
68
        $fields->push(new TextField('MainURL', 'Home page'));
69
        $fields->push(new TextField('ReadMeURL', 'Read me file - e.g. http://www.mymodule.com/readme.md'));
70
        $fields->push(new TextField('DemoURL', 'Demo - e.g. http://demo.mymodule.com/'));
71
        $fields->push(new TextField('SvnURL', 'SVN repository - allowing you to checkout trunk or latest version - e.g. http://svn.mymodule.com/svn/trunk/'));
72
        $fields->push(new TextField('GitURL', 'GIT repository - e.g. https://github.com/my-github-username/silverstripe-my-module'));
73
        $fields->push(new TextField('OtherURL', 'Link to other repository or download URL - e.g. http://www.mymodule.com/downloads/'));
74
        $fields->push(new CheckboxSetField('EcommerceProductTags', 'Tags', EcommerceProductTag::get()->map()->toArray()));
75
        $member = Member::currentUser();
76
        if ($member->inGroup("ADMIN")) {
77
            $fields->push(new CheckboxSetField('Authors', 'Author(s)', Member::get()->exclude("Email", "")->map("ID", "Email")->toArray()));
78
            $fields->push(new DropdownField('ParentID', 'Move to', ProductGroup::get()->map()->toArray()));
79
            $fields->push(new CheckboxField('ShowInMenus', 'Show in menus (unticking both boxes here will hide the module)'));
80
            $fields->push(new CheckboxField('ShowInSearch', 'Show in search (unticking both boxes here will hide the module)'));
81
        } else {
82
            $fields->push(new HiddenField('ShowInMenus', '', 0));
83
            $fields->push(new HiddenField('ShowInSearch', '', 0));
84
            $fields->push(new HiddenField('ParentID', '', $controller->dataRecord->ID));
85
            if ($moduleProduct) {
86
                $moduleProduct->ParentID = $controller->dataRecord->ID;
87
                $moduleProduct->ShowInSearch = 0;
88
                $moduleProduct->ShowInMenus = 0;
89
            }
90
        }
91
        if ($moduleProduct && $moduleProduct->canEdit()) {
92
            if ($authors = $moduleProduct->Authors()) {
93
                $authorsIDArray = $authors->map("ID", "ID")->toArray();
94
                $authorsIDArray[0] = 0;
95
                $fields->push($this->ManyManyComplexTableFieldAuthorsField($controller, $authorsIDArray));
96
                //$controller, $name, $sourceClass, $fieldList = null, $detailFormFields = null, $sourceFilter = "", $sourceSort = "", $sourceJoin = ""
0 ignored issues
show
Unused Code Comprehensibility introduced by
48% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
97
            }
98
        }
99
        $actions = new FieldList(new FormAction("submit", "submit"));
100
        $validator = new AddingModuleProduct_RequiredFields($moduleProductID, array('Code', 'Name', 'ParentID', 'MainURL'));
101
        parent::__construct($controller, $name, $fields, $actions, $validator);
102
        if ($moduleProduct) {
103
            $this->loadDataFrom($moduleProduct);
104
        }
105
        return $this;
0 ignored issues
show
Bug introduced by
Constructors do not have meaningful return values, anything that is returned from here is discarded. Are you sure this is correct?
Loading history...
106
    }
107
108
    public function submit($data, $form)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
109
    {
110
        $member = Member::currentUser();
111
        if (!$member) {
112
            $form->setMessage("You need to be logged in to edit this module.", "bad");
113
            $this->redirectBack();
0 ignored issues
show
Documentation Bug introduced by
The method redirectBack does not exist on object<AddingModuleProduct_Form>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
114
            return;
115
        }
116
        $data = Convert::raw2sql($data);
117
        $page = null;
118
        if (isset($data["ModuleProductID"])) {
119
            $page = ModuleProduct::get()->byID(intval($data["ModuleProductID"]));
120
        }
121
        if (!$page) {
122
            $page = new ModuleProduct();
123
        }
124
        if (isset($page->ParentID)) {
125
            $oldParentID = $page->ParentID;
0 ignored issues
show
Unused Code introduced by
$oldParentID is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
126
        }
127
        $form->saveInto($page);
128
        $page->Title = $data["Title"];
129
        $page->MenuTitle = $data["Title"];
130
        if (!$member->inGroup("ADMIN")) {
131
            $page->ShowInMenus = 0;
132
            $page->ShowInMenus = 0;
133
            $parentPage = AddingModuleProduct::get()->First();
134
            if ($parentPage) {
135
                $page->ParentID = $parentPage->ID;
136
            }
137
        }
138
        $page->writeToStage('Stage');
139
        $page->Publish('Stage', 'Live');
140
        $page->Status = "Published";
141
        $page->flushCache();
142
        if ($page->Authors()->count() == 0 && $member) {
143
            $page->Authors()->addMany(array($member->ID => $member->ID));
144
        }
145
        if (!isset($data["EcommerceProductTags"]) || ! is_array($data["EcommerceProductTags"]) || !count($data["EcommerceProductTags"])) {
146
            $data["EcommerceProductTags"] = array(-1 => -1);
147
        }
148
        if (isset($data["AdditionalTags"]) && $data["AdditionalTags"]) {
149
            $extraTagsArray = explode(",", $data["AdditionalTags"]);
150
            if (is_array($extraTagsArray) && count($extraTagsArray)) {
151
                foreach ($extraTagsArray as $tag) {
152
                    $tag = trim($tag);
153
                    $obj = EcommerceProductTag::get()
154
                        ->filter(array("Title" => $tag))
155
                        ->first();
156
                    if (!$obj) {
157
                        $obj = new EcommerceProductTag();
158
                        $obj->Title = $tag;
159
                        $obj->write();
160
                    }
161
                    $data["EcommerceProductTags"][$obj->ID] = $obj->ID;
162
                }
163
            }
164
        }
165
        DB::query("DELETE FROM \"EcommerceProductTag_Products\" WHERE \"ProductID\" = ".$page->ID. " AND \"EcommerceProductTagID\" NOT IN (".implode(",", $data["EcommerceProductTags"]).")");
166
        if (is_array($data["EcommerceProductTags"]) && count($data["EcommerceProductTags"])) {
167
            $page->EcommerceProductTags()->addMany($data["EcommerceProductTags"]);
168
        }
169
        if (Director::is_ajax()) {
170
            return $page->renderWith("ModuleProductInner");
171
        } else {
172
            $this->redirect($page->Link());
0 ignored issues
show
Bug introduced by
The method redirect() does not exist on AddingModuleProduct_Form. Did you maybe mean getRedirectToFormOnValidationError()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
173
        }
174
    }
175
176
177
    protected function ManyManyComplexTableFieldAuthorsField($controller, $authorsIDArray)
0 ignored issues
show
Unused Code introduced by
The parameter $controller is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $authorsIDArray is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
178
    {
179
        $detailFields = new FieldList();
180
        $detailFields->push(new TextField("ScreenName"));
181
        $detailFields->push(new TextField("FirstName"));
182
        $detailFields->push(new TextField("Surname"));
183
        $detailFields->push(new TextField("Email"));
184
        $detailFields->push(new TextField("GithubURL", "Github URL"));
185
        $detailFields->push(new TextField("SilverstripeDotOrgURL", "www.silverstripe.org URL"));
186
        $detailFields->push(new TextField("CompanyName", "Company Name"));
187
        $detailFields->push(new TextField("CompanyURL", "Company URL"));
188
        $detailFields->push(new CheckboxField("AreYouHappyForPeopleToContactYou", "are you happy for people to contact you about your module?"));
189
        $detailFields->push(new TextField("ContactDetailURL", "Contact details URL"));
190
        $detailFields->push(new TextField("OtherURL", "Other URL"));
191
        $detailFields->push(new CheckboxField("AreYouAvailableForPaidSupport", "are you available for paid support?"));
192
        $detailFields->push(new NumericField("Rate15Mins", "Indicative rate for 15 minute skype chat"));
193
        $detailFields->push(new NumericField("Rate120Mins", "Indicative rate for two hour work slot"));
194
        $detailFields->push(new NumericField("Rate480Mins", "Indicative rate for one day of work"));
195
        $field = new GridField(
196
            'Authors',
197
            'Member',
198
            Member::get()
199
        );
200
            /*
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
201
            array(
202
                "ScreenName" => "Screen name",
203
                "FirstName" => "First name",
204
                "Surname" => "Surname",
205
                "Email" => "Email"
206
                ),//fieldList
207
            $detailFields,//detailFormFields
208
            "\"Member\".\"ID\" IN (".implode(",", $authorsIDArray).")",//sourceFilter
209
            "",//sourceSort
210
            null//sourceJoin
211
            */
212
        //$field->setPopupCaption("Edit Author");
0 ignored issues
show
Unused Code Comprehensibility introduced by
86% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
213
        //$field->setAddTitle("Author");
0 ignored issues
show
Unused Code Comprehensibility introduced by
86% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
214
        return $field;
215
    }
216
}
217
218
class AddingModuleProduct_RequiredFields extends RequiredFields
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
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...
219
{
220
    protected $currentID = 0;
221
222
    public function __construct($currentID, $array)
223
    {
224
        $this->currentID = $currentID;
225
        parent::__construct($array);
226
    }
227
228
    public function javascript()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
229
    {
230
        $codes = DB::query("SELECT \"Code\" FROM ModuleProduct WHERE ModuleProduct.ID <> ".($this->currentID - 0))->column();
231
        if ($codes) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $codes of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
232
            $js = '
233
				jQuery(document).ready(
234
					function() {
235
						var AddingModuleProductCodes = new Array(\''.implode("','", $codes).'\');
236
						jQuery("#Code input").change(
237
							function(){
238
								var val = jQuery("#Code input").val();
239
								jQuery("#Code input").css("color", "green");
240
								for(i = 0; i < AddingModuleProductCodes.length; i++) {
241
									if(AddingModuleProductCodes[i] == val) {
242
										i = 999999999;
243
										alert("Your code \'"+val+"\' is already in use - please use an alternative code.");
244
										jQuery("#Code input").focus().css("color", "red");
245
									}
246
								}
247
							}
248
						);
249
					}
250
				);
251
			';
252
            Requirements::customScript($js, "AddingModuleProductCodes");
253
        }
254
        return parent::javascript();
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class RequiredFields as the method javascript() does only exist in the following sub-classes of RequiredFields: AddingModuleProduct_RequiredFields, ModuleProductEmail_RequiredFields. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
255
    }
256
257
258
    /**
259
    * Allows validation of fields via specification of a php function for validation which is executed after
260
    * the form is submitted
261
    */
262
    public function php($data)
263
    {
264
        $valid = true;
265
        if (isset($data["Code"])) {
266
            $type = Convert::raw2sql($data["Code"]);
267
            $extension = '';
0 ignored issues
show
Unused Code introduced by
$extension is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
268
            if (Versioned::current_stage() == "Live") {
269
                $extension = "_Live";
0 ignored issues
show
Unused Code introduced by
$extension is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
270
            }
271
            if (ModuleProduct::get()
272
                ->filter(array("Code" => $type))
273
                ->exclude("ModuleProduct", $this->currentID - 0)
274
                ->count()
275
            ) {
276
                $errorMessage = sprintf(_t('Form.CODEALREADYINUSE', "Your code %s is already in use - please check if your code is listed already or use an alternative code."), $type);
277
                $this->validationError(
278
                    $fieldName = "Code",
279
                    $errorMessage,
280
                    "required"
281
                );
282
                $valid = false;
283
            }
284
        }
285
        if (!$valid) {
286
            return false;
287
        }
288
        return parent::php($data);
289
    }
290
}
291