ModuleProductGroup   A
last analyzed

Complexity

Total Complexity 26

Size/Duplication

Total Lines 159
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 26
lcom 0
cbo 3
dl 0
loc 159
c 0
b 0
f 0
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A i18n_singular_name() 0 4 1
A i18n_plural_name() 0 4 1
A getCMSFields() 0 6 1
C currentInitialProducts() 0 44 13
A getClassNameSQL() 0 4 1
A currentClassNameSQL() 0 4 1
C DefaultEcommerceProductTags() 0 38 8
1
<?php
2
3
/**
4
 * extension of Product Group
5
 *
6
 *
7
 *
8
 **/
9
10
11
class ModuleProductGroup extends ProductGroupWithTags
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
14
    /**
15
     * Standard SS variable.
16
     */
17
    private static $singular_name = "Module";
0 ignored issues
show
Unused Code introduced by
The property $singular_name 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...
18
    public function i18n_singular_name()
19
    {
20
        return _t("ProductGroup.MODULEPRODUCTGROUP", "Module");
21
    }
22
23
    /**
24
     * Standard SS variable.
25
     */
26
    private static $plural_name = "Modules";
0 ignored issues
show
Unused Code introduced by
The property $plural_name 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...
27
    public function i18n_plural_name()
28
    {
29
        return _t("ProductGroup.MODULEPRODUCTGROUPS", "Modules");
30
    }
31
32
33
    private static $default_child = 'ModuleProduct';
0 ignored issues
show
Unused Code introduced by
The property $default_child 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...
34
35
    private static $icon = "ecommerce_software/images/treeicons/ModuleProductGroup";
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...
36
37
38
    /**
39
     * standard SS method
40
     */
41
    public function getCMSFields()
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...
42
    {
43
        $fields = parent::getCMSFields();
44
        $fields->removeByName("Tags");
45
        return $fields;
46
    }
47
48
    /**
49
     * returns the inital (all) products, based on the all the eligile products
50
     * for the page.
51
     *
52
     * This is THE pivotal method that probably changes for classes that
53
     * extend ProductGroup as here you can determine what products or other buyables are shown.
54
     *
55
     * The return from this method will then be sorted and filtered to product the final product list
56
     *
57
     * @param string $extraFilter Additional SQL filters to apply to the Product retrieval
0 ignored issues
show
Documentation introduced by
Should the type for parameter $extraFilter not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
58
     * @param boolean $recursive
0 ignored issues
show
Bug introduced by
There is no parameter named $recursive. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
59
     * @return DataObjectSet | Null
60
     **/
61
    public function currentInitialProducts($extraFilter = null, $alternativeFilterKey = '')
62
    {
63
        $this->allProducts = parent::currentInitialProducts($extraFilter, $alternativeFilterKey);
64
        if ($extraFilter) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $extraFilter of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
65
            if ($extraFilter instanceof DataObjectSet) {
0 ignored issues
show
Bug introduced by
The class DataObjectSet does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
66
                $tags = $extraFilter;
67
                //do nothing
68
            } elseif ($extraFilter instanceof DataObject) {
69
                $tags = new ArrayList(array($extraFilter));
70
            } elseif (is_array($extraFilter) || intval($extraFilter) == $extraFilter) {
71
                $tags = EcommerceProductTag::get()
72
                    ->filter(array("ID" => $extraFilter));
73
            } else {
74
                user_error("Error in tags", E_USER_NOTICE);
75
            }
76
            $idArray = array();
77
            if ($tags->count()) {
78
                $stage = '';
79
                if (Versioned::current_stage() == "Live") {
80
                    $stage = "_Live";
81
                }
82
                if ($tags->count()) {
83
                    foreach ($tags as $tag) {
84
                        $rows = DB::query("
85
							SELECT \"ProductID\"
86
							FROM \"EcommerceProductTag_Products\"
87
								INNER JOIN \"ModuleProduct{$stage}\"
88
									ON \"ModuleProduct{$stage}\".\"ID\" = \"EcommerceProductTag_Products\".\"ProductID\"
89
							WHERE \"EcommerceProductTag_Products\".\"EcommerceProductTagID\" IN (".implode(",", $tags->column("ID")).")
0 ignored issues
show
Bug introduced by
The variable $tags does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
90
						");
91
                        if ($rows) {
92
                            foreach ($rows as $row) {
93
                                $idArray[$row["ProductID"]] = $row["ProductID"];
94
                            }
95
                        }
96
                    }
97
                    if (count($idArray)) {
98
                        $this->allProducts = $this->allProducts->filter(array("ID" => $idArray));
99
                    }
100
                }
101
            }
102
        }
103
        return $this->allProducts;
104
    }
105
106
    /**
107
     * Returns the class we are working with for the initial product selection
108
     * @return String
109
     */
110
    protected function getClassNameSQL()
111
    {
112
        return "ModuleProduct";
113
    }
114
115
116
117
    /**
118
     * returns the CLASSNAME part of the final selection of products.
119
     * @return String
120
     */
121
    protected function currentClassNameSQL()
122
    {
123
        return "ModuleProduct";
124
    }
125
126
127
    /**
128
     * @param String $tagCode - code of the current tag.
129
     * @return Object - DataObjectSet - Tags that are related to ModuleProducts
130
     */
131
    public function DefaultEcommerceProductTags($tagCode = "")
132
    {
133
        $stage = '';
134
        if (Versioned::current_stage() == "Live") {
135
            $stage = "_Live";
136
        }
137
        $idArray = array();
138
        $productIDs[0] = 0;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$productIDs was never initialized. Although not strictly required by PHP, it is generally a good practice to add $productIDs = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
139
        $rows = DB::query("
140
			SELECT \"EcommerceProductTagID\"
141
			FROM \"EcommerceProductTag_Products\"
142
				INNER JOIN \"ModuleProduct{$stage}\"
143
					ON \"ModuleProduct{$stage}\".\"ID\" = \"EcommerceProductTag_Products\".\"ProductID\"
144
				INNER JOIN \"SiteTree{$stage}\"
145
					ON \"ModuleProduct{$stage}\".\"ID\" = \"SiteTree{$stage}\".\"ID\"
146
			WHERE \"SiteTree{$stage}\".ShowInSearch = 1
147
		");
148
        if ($rows) {
149
            foreach ($rows as $row) {
150
                $idArray[$row["EcommerceProductTagID"]] = $row["EcommerceProductTagID"];
151
            }
152
        }
153
        if (count($idArray)) {
154
            $tags = EcommerceProductTag::get()
155
                ->filter(array("ID" => $idArray));
156
            if ($tags->count()) {
157
                foreach ($tags as $tag) {
158
                    $tag->Link = $this->Link("show")."/".$tag->Code."/";
159
                    if ($tag->Code == $tagCode) {
160
                        $tag->LinkingMode = "current";
161
                    } else {
162
                        $tag->LinkingMode = "link";
163
                    }
164
                }
165
            }
166
            return $tags;
167
        }
168
    }
169
}
170
171
172
class ModuleProductGroup_Controller extends ProductGroupWithTags_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...
173
{
174
    public function init()
175
    {
176
        parent::init();
177
        Requirements::javascript("ecommerce_software/javascript/ModuleProductGroup.js");
178
        Requirements::themedCSS("ModuleProduct", "ecommerce_software");
179
    }
180
181
182
    /**
183
     * Return the products for this group.
184
     *
185
     * @return DataObjectSet(Products)
0 ignored issues
show
Documentation introduced by
The doc-type DataObjectSet(Products) could not be parsed: Expected "|" or "end of type", but got "(" at position 13. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
186
     **/
187
    public function Products()
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...
188
    {
189
        if ($this->tag) {
190
            $toShow = $this->tag;
191
            Requirements::customScript("ModuleProductGroup.set_urlFiltered(true)", "set_urlFiltered");
192
        } else {
193
            $toShow = null;
194
        }
195
        return $this->ProductsShowable($toShow);
196
    }
197
198
199
    /**
200
     * Tags available in the template
201
     */
202
    public function Tags()
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...
203
    {
204
        $tagCode = "";
205
        if ($this->tag) {
206
            $tagCode = $this->tag->Code;
207
        }
208
        return $this->DefaultEcommerceProductTags($tagCode);
209
    }
210
211
212
213
    /**
214
     * Site search form
215
     */
216
    public function ModuleSearchForm()
217
    {
218
        $searchText =  _t('ModuleProductGroup.KEYWORDS', 'keywords');
219
220
        if ($this->request) {
221
            $searchText = $this->request->getVar('Search');
222
        }
223
224
        $fields = new FieldList(
225
            new TextField('Search', _t('ModuleProductGroup.KEYWORDS', 'keywords'), $searchText)
226
        );
227
        $actions = new FieldList(
228
            new FormAction('modulesearchformresults',  _t('ModuleSearchForm.FILTER', 'Filter'))
229
        );
230
        $form = new SearchForm($this, 'ModuleSearchForm', $fields, $actions);
231
        $form->classesToSearch(array("SiteTree"));
232
        return $form;
233
    }
234
235
    /**
236
     * Process and render search results.
237
     *
238
     * @param array $data The raw request data submitted by user
239
     * @param SearchForm $form The form instance that was submitted
240
     * @param SS_HTTPRequest $request Request generated for this action
241
     */
242
    public function modulesearchformresults($data, $form, $request)
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...
243
    {
244
        $data = array(
245
            'Results' => $form->getResults(),
246
            'Query' => $form->getSearchQuery(),
247
            'Title' => _t('SearchForm.SearchResults', 'Search Results')
248
        );
249
        //search tags
250
        //search authors
251
        if ($data["Results"]) {
252
            foreach ($data["Results"] as $key => $resultItem) {
253
                if (!($resultItem instanceof ModuleProduct)) {
254
                    ($data["Results"]->remove($resultItem));
255
                }
256
            }
257
        } else {
258
            $data["Results"] = new ArrayList();
259
        }
260
        $search = Convert::raw2sql($data["Query"]);
261
        if (strlen($search) > 2) {
262
            $additionalProducts = ModuleProduct::get()->filterAny(array("Code:PartialMatch" => $search, "MenuTitle:PartialMatch" => $search));
263
            if ($additionalProducts) {
264
                foreach ($additionalProducts as $moduleProduct) {
265
                    $data["Results"]->push($moduleProduct);
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface SS_List as the method push() does only exist in the following implementations of said interface: ArrayList, DataList, FieldList, HasManyList, ManyManyList, Member_GroupSet, PolymorphicHasManyList, RelationList, UnsavedRelationList.

Let’s take a look at an example:

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

class MyUser implements 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 implementation 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 interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
266
                }
267
            }
268
            $tags = EcommerceProductTag::get()->filterAny(array("Title:PartialMatch" => $search, "Synonyms:PartialMatch" => $search, "Explanation:PartialMatch" => $search));
269 View Code Duplication
            if ($tags->count()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
270
                foreach ($tags as $tag) {
271
                    $rows = DB::query("SELECT ProductID FROM EcommerceProductTag_Products WHERE EcommerceProductTagID = ".$tag->ID);
272
                    if ($rows) {
273
                        foreach ($rows as $row) {
274
                            $item = ModuleProduct::get()->byID($row["ProductID"]);
275
                            if ($item) {
276
                                $data["Results"]->push($item);
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface SS_List as the method push() does only exist in the following implementations of said interface: ArrayList, DataList, FieldList, HasManyList, ManyManyList, Member_GroupSet, PolymorphicHasManyList, RelationList, UnsavedRelationList.

Let’s take a look at an example:

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

class MyUser implements 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 implementation 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 interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
277
                            }
278
                        }
279
                    }
280
                }
281
            }
282
            $authors = Member::get()
283
                ->filterAny(
284
                    array(
285
                        "ScreenName:PartialMatch" => $search,
286
                        "FirstName:PartialMatch" => $search,
287
                        "Surname:PartialMatch" => $search)
288
                );
289 View Code Duplication
            if ($authors->count()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
290
                foreach ($authors as $author) {
291
                    $rows = DB::query("SELECT \"ModuleProductID\" FROM \"ModuleProduct_Authors\" WHERE \"MemberID\" = ".$author->ID);
292
                    if ($rows) {
293
                        foreach ($rows as $row) {
294
                            $item = ModuleProduct::get()->byID($row["ModuleProductID"]);
295
                            if ($item) {
296
                                $data["Results"]->push($item);
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface SS_List as the method push() does only exist in the following implementations of said interface: ArrayList, DataList, FieldList, HasManyList, ManyManyList, Member_GroupSet, PolymorphicHasManyList, RelationList, UnsavedRelationList.

Let’s take a look at an example:

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

class MyUser implements 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 implementation 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 interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
297
                            }
298
                        }
299
                    }
300
                }
301
            }
302
        }
303
        if ($data["Results"] && $data["Results"] instanceof DataObjectSet) {
0 ignored issues
show
Bug introduced by
The class DataObjectSet does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
304
            $data["Results"]->removeDuplicates();
305
        }
306
        if (Director::is_ajax()) {
307
            return Convert::array2json(array("ModuleProducts" => $data["Results"]->column("ID")));
308
        }
309
        return $this->customise(array("Products" => $data["Results"]));
310
    }
311
312
    /**
313
     * Admin ONLY action
314
     * to view a list of all developers
315
     * that have not been contacted yet
316
     */
317
    public function introemails()
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...
318
    {
319
        $i = 0;
320
        $member = Member::currentUser();
321
        $dos = new ArrayList();
322
        if ($member && $member->inGroup("ADMIN")) {
323
            $modules = ModuleProduct::get()
324
                ->filter(array("ShowInSearch" => 1, "ShowInMenus" => 1));
325
            foreach ($modules as $module) {
326
                if (!$module->HasEmail() && !$module->HasMemberContact()) {
327
                    $i++;
328
                    if ($i < 10) {
329
                        $dos->push($module);
330
                    } else {
331
                        break;
332
                    }
333
                }
334
            }
335
            return $this->customise(array("Products" => $dos));
336
        }
337
        Security::permissionFailure($this, "You need to log in as an Administrator.");
338
    }
339
}
340