Completed
Push — master ( ca3f3f...3c943f )
by Michael
03:20
created

PublisherUtilities::editCategory()   C

Complexity

Conditions 11
Paths 80

Size

Total Lines 120
Code Lines 91

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 120
rs 5.2653
cc 11
eloc 91
nc 80
nop 4

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
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 30 and the first side effect is on line 23.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/*
3
 You may not change or alter any portion of this comment or credits
4
 of supporting developers from this source code or any supporting source code
5
 which is considered copyrighted (c) material of the original comment or credit authors.
6
7
 This program is distributed in the hope that it will be useful,
8
 but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
 */
11
/**
12
 * PublisherUtilities Class
13
 *
14
 * @copyright   The XOOPS Project http://sourceforge.net/projects/xoops/
15
 * @license     http://www.fsf.org/copyleft/gpl.html GNU public license
16
 * @author      XOOPS Development Team
17
 * @package     Publisher
18
 * @since       1.03
19
 * @version     $Id: breadcrumb.php 12277 2014-01-26 01:21:57Z beckmi $
20
 *
21
 */
22
23
include_once dirname(__DIR__) . '/include/common.php';
24
25
//namespace Publisher;
26
27
/**
28
 * Class PublisherUtilities
29
 */
30
class PublisherUtilities
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...
31
{
32
    /**
33
     * Function responsible for checking if a directory exists, we can also write in and create an index.html file
34
     *
35
     * @param string $folder The full path of the directory to check
36
     *
37
     * @return void
38
     */
39
    public static function createFolder($folder)
40
    {
41
        try {
42
            if (!@mkdir($folder) && !is_dir($folder)) {
43
                throw new \RuntimeException(sprintf('Unable to create the %s directory', $folder));
44
            } else {
45
                file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>');
46
            }
47
        } catch (Exception $e) {
48
            echo 'Caught exception: ', $e->getMessage(), "\n", '<br/>';
49
        }
50
    }
51
52
    /**
53
     * @param $file
54
     * @param $folder
55
     * @return bool
56
     */
57
    public static function copyFile($file, $folder)
58
    {
59
        return copy($file, $folder);
60
//        try {
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% 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...
61
//            if (!is_dir($folder)) {
62
//                throw new \RuntimeException(sprintf('Unable to copy file as: %s ', $folder));
63
//            } else {
64
//                return copy($file, $folder);
65
//            }
66
//        } catch (Exception $e) {
67
//            echo 'Caught exception: ', $e->getMessage(), "\n", "<br/>";
68
//        }
69
//        return false;
70
    }
71
72
    /**
73
     * @param $src
74
     * @param $dst
75
     */
76
    public static function recurseCopy($src, $dst)
77
    {
78
        $dir = opendir($src);
79
        //    @mkdir($dst);
80
        while (false !== ($file = readdir($dir))) {
81
            if (($file !== '.') && ($file !== '..')) {
82
                if (is_dir($src . '/' . $file)) {
83
                    self::recurseCopy($src . '/' . $file, $dst . '/' . $file);
84
                } else {
85
                    copy($src . '/' . $file, $dst . '/' . $file);
86
                }
87
            }
88
        }
89
        closedir($dir);
90
    }
91
92
    // auto create folders----------------------------------------
93
    //TODO rename this function? And exclude image folder?
94
    public static function createDir()
95
    {
96
        // auto crate folders
97
        //        $thePath = publisherGetUploadDir();
0 ignored issues
show
Unused Code Comprehensibility introduced by
45% 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...
98
99 View Code Duplication
        if (publisherGetPathStatus('root', true) < 0) {
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...
100
            $thePath = publisherGetUploadDir();
101
            $res     = publisherMkdir($thePath);
102
            $msg     = $res ? _AM_PUBLISHER_DIRCREATED : _AM_PUBLISHER_DIRNOTCREATED;
0 ignored issues
show
Unused Code introduced by
$msg 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...
103
        }
104
105 View Code Duplication
        if (publisherGetPathStatus('images', true) < 0) {
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...
106
            $thePath = publisherGetImageDir();
107
            $res     = publisherMkdir($thePath);
108
109
            if ($res) {
110
                $source = PUBLISHER_ROOT_PATH . '/assets/images/blank.png';
111
                $dest   = $thePath . 'blank.png';
112
                publisherCopyr($source, $dest);
113
            }
114
            $msg = $res ? _AM_PUBLISHER_DIRCREATED : _AM_PUBLISHER_DIRNOTCREATED;
0 ignored issues
show
Unused Code introduced by
$msg 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...
115
        }
116
117 View Code Duplication
        if (publisherGetPathStatus('images/category', true) < 0) {
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...
118
            $thePath = publisherGetImageDir('category');
119
            $res     = publisherMkdir($thePath);
120
121
            if ($res) {
122
                $source = PUBLISHER_ROOT_PATH . '/assets/images/blank.png';
123
                $dest   = $thePath . 'blank.png';
124
                publisherCopyr($source, $dest);
125
            }
126
            $msg = $res ? _AM_PUBLISHER_DIRCREATED : _AM_PUBLISHER_DIRNOTCREATED;
0 ignored issues
show
Unused Code introduced by
$msg 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...
127
        }
128
129 View Code Duplication
        if (publisherGetPathStatus('images/item', true) < 0) {
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...
130
            $thePath = publisherGetImageDir('item');
131
            $res     = publisherMkdir($thePath);
132
133
            if ($res) {
134
                $source = PUBLISHER_ROOT_PATH . '/assets/images/blank.png';
135
                $dest   = $thePath . 'blank.png';
136
                publisherCopyr($source, $dest);
137
            }
138
            $msg = $res ? _AM_PUBLISHER_DIRCREATED : _AM_PUBLISHER_DIRNOTCREATED;
0 ignored issues
show
Unused Code introduced by
$msg 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...
139
        }
140
141 View Code Duplication
        if (publisherGetPathStatus('content', true) < 0) {
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...
142
            $thePath = publisherGetUploadDir(true, 'content');
0 ignored issues
show
Documentation introduced by
'content' is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
143
            $res     = publisherMkdir($thePath);
144
            $msg     = $res ? _AM_PUBLISHER_DIRCREATED : _AM_PUBLISHER_DIRNOTCREATED;
0 ignored issues
show
Unused Code introduced by
$msg 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...
145
        }
146
    }
147
148
    public static function buildTableItemTitleRow()
149
    {
150
        echo "<table width='100%' cellspacing='1' cellpadding='3' border='0' class='outer'>";
151
        echo '<tr>';
152
        echo "<th width='40px' class='bg3' align='center'><strong>" . _AM_PUBLISHER_ITEMID . '</strong></td>';
153
        echo "<th width='100px' class='bg3' align='center'><strong>" . _AM_PUBLISHER_ITEMCAT . '</strong></td>';
154
        echo "<th class='bg3' align='center'><strong>" . _AM_PUBLISHER_TITLE . '</strong></td>';
155
        echo "<th width='100px' class='bg3' align='center'><strong>" . _AM_PUBLISHER_CREATED . '</strong></td>';
156
157
        echo "<th width='50px' class='bg3' align='center'><strong>" . _CO_PUBLISHER_WEIGHT . '</strong></td>';
158
        echo "<th width='50px' class='bg3' align='center'><strong>" . _AM_PUBLISHER_HITS . '</strong></td>';
159
        echo "<th width='60px' class='bg3' align='center'><strong>" . _AM_PUBLISHER_RATE . '</strong></td>';
160
        echo "<th width='50px' class='bg3' align='center'><strong>" . _AM_PUBLISHER_VOTES . '</strong></td>';
161
        echo "<th width='60px' class='bg3' align='center'><strong>" . _AM_PUBLISHER_COMMENTS_COUNT . '</strong></td>';
162
163
        echo "<th width='90px' class='bg3' align='center'><strong>" . _CO_PUBLISHER_STATUS . '</strong></td>';
164
        echo "<th width='90px' class='bg3' align='center'><strong>" . _AM_PUBLISHER_ACTION . '</strong></td>';
165
        echo '</tr>';
166
    }
167
168
    /**
169
     * @param     $categoryObj
170
     * @param int $level
171
     */
172
    public static function displayCategory(PublisherCategory $categoryObj, $level = 0)
173
    {
174
        $publisher = PublisherPublisher::getInstance();
175
176
        $description = $categoryObj->description();
177
        if (!XOOPS_USE_MULTIBYTES) {
178
            if (strlen($description) >= 100) {
179
                $description = substr($description, 0, 100 - 1) . '...';
0 ignored issues
show
Unused Code introduced by
$description 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...
180
            }
181
        }
182
        $modify = "<a href='category.php?op=mod&amp;categoryid=" . $categoryObj->categoryid() . '&amp;parentid=' . $categoryObj->parentid() . "'><img src='" . PUBLISHER_URL . "/assets/images/links/edit.gif' title='" . _AM_PUBLISHER_EDITCOL . "' alt='" . _AM_PUBLISHER_EDITCOL . "' /></a>";
183
        $delete = "<a href='category.php?op=del&amp;categoryid=" . $categoryObj->categoryid() . "'><img src='" . PUBLISHER_URL . "/assets/images/links/delete.png' title='" . _AM_PUBLISHER_DELETECOL . "' alt='" . _AM_PUBLISHER_DELETECOL . "' /></a>";
184
185
        $spaces = '';
186
        for ($j = 0; $j < $level; ++$j) {
187
            $spaces .= '&nbsp;&nbsp;&nbsp;';
188
        }
189
190
        echo '<tr>';
191
        echo "<td class='even' align='center'>" . $categoryObj->categoryid() . '</td>';
192
        echo "<td class='even' align='left'>" . $spaces . "<a href='" . PUBLISHER_URL . '/category.php?categoryid=' . $categoryObj->categoryid() . "'><img src='" . PUBLISHER_URL . "/assets/images/links/subcat.gif' alt='' />&nbsp;" . $categoryObj->name() . '</a></td>';
193
        echo "<td class='even' align='center'>" . $categoryObj->weight() . '</td>';
194
        echo "<td class='even' align='center'> $modify $delete </td>";
195
        echo '</tr>';
196
        $subCategoriesObj = $publisher->getHandler('category')->getCategories(0, 0, $categoryObj->categoryid());
197
        if (count($subCategoriesObj) > 0) {
198
            ++$level;
199
            foreach ($subCategoriesObj as $key => $thiscat) {
200
                self::displayCategory($thiscat, $level);
201
            }
202
            unset($key, $thiscat);
203
        }
204
        //        unset($categoryObj);
0 ignored issues
show
Unused Code Comprehensibility introduced by
84% 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...
205
    }
206
207
    /**
208
     * @param bool $showmenu
209
     * @param int  $categoryId
210
     * @param int  $nbSubCats
211
     * @param null $categoryObj
212
     */
213
    public static function editCategory($showmenu = false, $categoryId = 0, $nbSubCats = 4, $categoryObj = null)
0 ignored issues
show
Unused Code introduced by
The parameter $showmenu 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...
214
    {
215
        $publisher = PublisherPublisher::getInstance();
216
217
        // if there is a parameter, and the id exists, retrieve data: we're editing a category
218
        if ($categoryId != 0) {
219
            // Creating the category object for the selected category
220
            $categoryObj = $publisher->getHandler('category')->get($categoryId);
221
            if ($categoryObj->notLoaded()) {
222
                redirect_header('category.php', 1, _AM_PUBLISHER_NOCOLTOEDIT);
223
                //            exit();
224
            }
225
        } else {
226
            if (!$categoryObj) {
227
                $categoryObj = $publisher->getHandler('category')->create();
228
            }
229
        }
230
231
        if ($categoryId != 0) {
232
            echo "<br />\n";
233
            publisherOpenCollapsableBar('edittable', 'edittableicon', _AM_PUBLISHER_EDITCOL, _AM_PUBLISHER_CATEGORY_EDIT_INFO);
234
        } else {
235
            publisherOpenCollapsableBar('createtable', 'createtableicon', _AM_PUBLISHER_CATEGORY_CREATE, _AM_PUBLISHER_CATEGORY_CREATE_INFO);
236
        }
237
238
        $sform = $categoryObj->getForm($nbSubCats);
239
        $sform->display();
240
241
        if (!$categoryId) {
242
            publisherCloseCollapsableBar('createtable', 'createtableicon');
243
        } else {
244
            publisherCloseCollapsableBar('edittable', 'edittableicon');
245
        }
246
247
        //Added by fx2024
248
        if ($categoryId) {
249
            $selCat = $categoryId;
250
251
            publisherOpenCollapsableBar('subcatstable', 'subcatsicon', _AM_PUBLISHER_SUBCAT_CAT, _AM_PUBLISHER_SUBCAT_CAT_DSC);
252
            // Get the total number of sub-categories
253
            $categoriesObj = $publisher->getHandler('category')->get($selCat);
254
            $totalsubs     = $publisher->getHandler('category')->getCategoriesCount($selCat);
255
            // creating the categories objects that are published
256
            $subcatsObj    = $publisher->getHandler('category')->getCategories(0, 0, $categoriesObj->categoryid());
257
            $totalSCOnPage = count($subcatsObj);
0 ignored issues
show
Unused Code introduced by
$totalSCOnPage 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...
258
            echo "<table width='100%' cellspacing=1 cellpadding=3 border=0 class = outer>";
259
            echo '<tr>';
260
            echo "<td width='60' class='bg3' align='left'><strong>" . _AM_PUBLISHER_CATID . '</strong></td>';
261
            echo "<td width='20%' class='bg3' align='left'><strong>" . _AM_PUBLISHER_CATCOLNAME . '</strong></td>';
262
            echo "<td class='bg3' align='left'><strong>" . _AM_PUBLISHER_SUBDESCRIPT . '</strong></td>';
263
            echo "<td width='60' class='bg3' align='right'><strong>" . _AM_PUBLISHER_ACTION . '</strong></td>';
264
            echo '</tr>';
265
            if ($totalsubs > 0) {
266
                foreach ($subcatsObj as $subcat) {
267
                    $modify = "<a href='category.php?op=mod&amp;categoryid=" . $subcat->categoryid() . "'><img src='" . XOOPS_URL . '/modules/' . $publisher->getModule()->dirname() . "/assets/images/links/edit.gif' title='" . _AM_PUBLISHER_MODIFY . "' alt='" . _AM_PUBLISHER_MODIFY . "' /></a>";
0 ignored issues
show
Bug introduced by
The method dirname cannot be called on $publisher->getModule() (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
268
                    $delete = "<a href='category.php?op=del&amp;categoryid=" . $subcat->categoryid() . "'><img src='" . XOOPS_URL . '/modules/' . $publisher->getModule()->dirname() . "/assets/images/links/delete.png' title='" . _AM_PUBLISHER_DELETE . "' alt='" . _AM_PUBLISHER_DELETE . "' /></a>";
0 ignored issues
show
Bug introduced by
The method dirname cannot be called on $publisher->getModule() (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
269
                    echo '<tr>';
270
                    echo "<td class='head' align='left'>" . $subcat->categoryid() . '</td>';
271
                    echo "<td class='even' align='left'><a href='" . XOOPS_URL . '/modules/' . $publisher->getModule()->dirname() . '/category.php?categoryid=' . $subcat->categoryid() . '&amp;parentid=' . $subcat->parentid() . "'>" . $subcat->name() . '</a></td>';
0 ignored issues
show
Bug introduced by
The method dirname cannot be called on $publisher->getModule() (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
272
                    echo "<td class='even' align='left'>" . $subcat->description() . '</td>';
273
                    echo "<td class='even' align='right'> {$modify} {$delete} </td>";
274
                    echo '</tr>';
275
                }
276
                //                unset($subcat);
0 ignored issues
show
Unused Code Comprehensibility introduced by
84% 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...
277
            } else {
278
                echo '<tr>';
279
                echo "<td class='head' align='center' colspan= '7'>" . _AM_PUBLISHER_NOSUBCAT . '</td>';
280
                echo '</tr>';
281
            }
282
            echo "</table>\n";
283
            echo "<br />\n";
284
            publisherCloseCollapsableBar('subcatstable', 'subcatsicon');
285
286
            publisherOpenCollapsableBar('bottomtable', 'bottomtableicon', _AM_PUBLISHER_CAT_ITEMS, _AM_PUBLISHER_CAT_ITEMS_DSC);
287
            $startitem = XoopsRequest::getInt('startitem');
288
            // Get the total number of published ITEMS
289
            $totalitems = $publisher->getHandler('item')->getItemsCount($selCat, array(PublisherConstants::PUBLISHER_STATUS_PUBLISHED));
290
            // creating the items objects that are published
291
            $itemsObj         = $publisher->getHandler('item')->getAllPublished($publisher->getConfig('idxcat_perpage'), $startitem, $selCat);
292
            $totalitemsOnPage = count($itemsObj);
293
            $allcats          = $publisher->getHandler('category')->getObjects(null, true);
294
            echo "<table width='100%' cellspacing=1 cellpadding=3 border=0 class = outer>";
295
            echo '<tr>';
296
            echo "<td width='40' class='bg3' align='center'><strong>" . _AM_PUBLISHER_ITEMID . '</strong></td>';
297
            echo "<td width='20%' class='bg3' align='left'><strong>" . _AM_PUBLISHER_ITEMCOLNAME . '</strong></td>';
298
            echo "<td class='bg3' align='left'><strong>" . _AM_PUBLISHER_ITEMDESC . '</strong></td>';
299
            echo "<td width='90' class='bg3' align='center'><strong>" . _AM_PUBLISHER_CREATED . '</strong></td>';
300
            echo "<td width='60' class='bg3' align='center'><strong>" . _AM_PUBLISHER_ACTION . '</strong></td>';
301
            echo '</tr>';
302
            if ($totalitems > 0) {
303
                for ($i = 0; $i < $totalitemsOnPage; ++$i) {
304
                    $categoryObj = $allcats[$itemsObj[$i]->categoryid()];
305
                    $modify      = "<a href='item.php?op=mod&amp;itemid=" . $itemsObj[$i]->itemid() . "'><img src='" . XOOPS_URL . '/modules/' . $publisher->getModule()->dirname() . "/assets/images/links/edit.gif' title='" . _AM_PUBLISHER_EDITITEM . "' alt='" . _AM_PUBLISHER_EDITITEM . "' /></a>";
0 ignored issues
show
Bug introduced by
The method dirname cannot be called on $publisher->getModule() (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
306
                    $delete      = "<a href='item.php?op=del&amp;itemid=" . $itemsObj[$i]->itemid() . "'><img src='" . XOOPS_URL . '/modules/' . $publisher->getModule()->dirname() . "/assets/images/links/delete.png' title='" . _AM_PUBLISHER_DELETEITEM . "' alt='" . _AM_PUBLISHER_DELETEITEM . "'/></a>";
0 ignored issues
show
Bug introduced by
The method dirname cannot be called on $publisher->getModule() (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
307
                    echo '<tr>';
308
                    echo "<td class='head' align='center'>" . $itemsObj[$i]->itemid() . '</td>';
309
                    echo "<td class='even' align='left'>" . $categoryObj->name() . '</td>';
310
                    echo "<td class='even' align='left'>" . $itemsObj[$i]->getitemLink() . '</td>';
311
                    echo "<td class='even' align='center'>" . $itemsObj[$i]->getDatesub('s') . '</td>';
312
                    echo "<td class='even' align='center'> $modify $delete </td>";
313
                    echo '</tr>';
314
                }
315
            } else {
316
                $itemid = -1;
0 ignored issues
show
Unused Code introduced by
$itemid 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...
317
                echo '<tr>';
318
                echo "<td class='head' align='center' colspan= '7'>" . _AM_PUBLISHER_NOITEMS . '</td>';
319
                echo '</tr>';
320
            }
321
            echo "</table>\n";
322
            echo "<br />\n";
323
            $parentid         = XoopsRequest::getInt('parentid', 0, 'GET');
324
            $pagenavExtraArgs = "op=mod&categoryid=$selCat&parentid=$parentid";
325
            xoops_load('XoopsPageNav');
326
            $pagenav = new XoopsPageNav($totalitems, $publisher->getConfig('idxcat_perpage'), $startitem, 'startitem', $pagenavExtraArgs);
327
            echo '<div style="text-align:right;">' . $pagenav->renderNav() . '</div>';
328
            echo "<input type='button' name='button' onclick=\"location='item.php?op=mod&categoryid=" . $selCat . "'\" value='" . _AM_PUBLISHER_CREATEITEM . "'>&nbsp;&nbsp;";
329
            echo '</div>';
330
        }
331
        //end of fx2024 code
332
    }
333
}
334