Completed
Push — master ( 01b1a5...81f493 )
by Michael
04:03
created

customtag.php ➔ editcustomtag()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 29
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 17
c 1
b 0
f 0
nc 4
nop 3
dl 0
loc 29
rs 8.439
1
<?php
2
3
/**
4
 *
5
 * Module: Class_Booking
6
 * Author: The SmartFactory <www.smartfactory.ca>
7
 * Licence: GNU
8
 * @param bool $showmenu
9
 * @param int  $customtagid
10
 * @param bool $clone
11
 */
12
13
function editcustomtag($showmenu = false, $customtagid = 0, $clone = false)
14
{
15
    global $smartobjectCustomtagHandler;
16
17
    $customtagObj = $smartobjectCustomtagHandler->get($customtagid);
18
19
    if (!$clone && !$customtagObj->isNew()) {
20
        if ($showmenu) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
21
            //smart_adminMenu(2, _AM_SOBJECT_CUSTOMTAGS . " > " . _AM_SOBJECT_EDITING);
0 ignored issues
show
Unused Code Comprehensibility introduced by
38% 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...
22
        }
23
        smart_collapsableBar('customtagedit', _AM_SOBJECT_CUSTOMTAGS_EDIT, _AM_SOBJECT_CUSTOMTAGS_EDIT_INFO);
24
25
        $sform = $customtagObj->getForm(_AM_SOBJECT_CUSTOMTAGS_EDIT, 'addcustomtag');
26
        $sform->display();
27
        smart_close_collapsable('customtagedit');
28
    } else {
29
        $customtagObj->setVar('customtagid', 0);
30
        $customtagObj->setVar('tag', '');
31
32
        if ($showmenu) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
33
            //smart_adminMenu(2, _AM_SOBJECT_CUSTOMTAGS . " > " . _CO_SOBJECT_CREATINGNEW);
0 ignored issues
show
Unused Code Comprehensibility introduced by
38% 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...
34
        }
35
36
        smart_collapsableBar('customtagcreate', _AM_SOBJECT_CUSTOMTAGS_CREATE, _AM_SOBJECT_CUSTOMTAGS_CREATE_INFO);
37
        $sform = $customtagObj->getForm(_AM_SOBJECT_CUSTOMTAGS_CREATE, 'addcustomtag');
38
        $sform->display();
39
        smart_close_collapsable('customtagcreate');
40
    }
41
}
42
43
include_once __DIR__ . '/admin_header.php';
44
smart_loadLanguageFile('smartobject', 'customtag');
45
46
include_once SMARTOBJECT_ROOT_PATH . 'class/smartobjecttable.php';
47
include_once SMARTOBJECT_ROOT_PATH . 'class/customtag.php';
48
$smartobjectCustomtagHandler = xoops_getModuleHandler('customtag');
49
50
$indexAdmin = new ModuleAdmin();
51
52
$op = '';
53
54
if (isset($_GET['op'])) {
55
    $op = $_GET['op'];
56
}
57
if (isset($_POST['op'])) {
58
    $op = $_POST['op'];
59
}
60
61
switch ($op) {
62 View Code Duplication
    case 'mod':
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...
63
64
        $customtagid = isset($_GET['customtagid']) ? (int)$_GET['customtagid'] : 0;
65
66
        smart_xoops_cp_header();
67
        echo $indexAdmin->addNavigation(basename(__FILE__));
68
69
        editcustomtag(true, $customtagid);
70
        break;
71
72 View Code Duplication
    case 'clone':
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...
73
74
        $customtagid = isset($_GET['customtagid']) ? (int)$_GET['customtagid'] : 0;
75
76
        smart_xoops_cp_header();
77
        echo $indexAdmin->addNavigation(basename(__FILE__));
78
79
        editcustomtag(true, $customtagid, true);
80
        break;
81
82
    case 'addcustomtag':
83
        include_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartobjectcontroller.php';
84
        $controller = new SmartObjectController($smartobjectCustomtagHandler);
85
        $controller->storeFromDefaultForm(_AM_SOBJECT_CUSTOMTAGS_CREATED, _AM_SOBJECT_CUSTOMTAGS_MODIFIED);
86
        break;
87
88
    case 'del':
89
90
        include_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartobjectcontroller.php';
91
        $controller = new SmartObjectController($smartobjectCustomtagHandler);
92
        $controller->handleObjectDeletion();
93
94
        break;
95
96
    default:
97
98
        smart_xoops_cp_header();
99
        echo $indexAdmin->addNavigation(basename(__FILE__));
100
        $indexAdmin->addItemButton(_AM_SOBJECT_CUSTOMTAGS_CREATE, 'customtag.php?op=mod', 'add', '');
101
        echo $indexAdmin->renderButton('left', '');
102
103
        //smart_adminMenu(2, _AM_SOBJECT_CUSTOMTAGS);
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% 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...
104
105
        smart_collapsableBar('createdcustomtags', _AM_SOBJECT_CUSTOMTAGS, _AM_SOBJECT_CUSTOMTAGS_DSC);
106
107
        include_once SMARTOBJECT_ROOT_PATH . 'class/smartobjecttable.php';
108
        $objectTable = new SmartObjectTable($smartobjectCustomtagHandler);
109
        $objectTable->addColumn(new SmartObjectColumn('name', 'left', 150, 'getCustomtagName'));
0 ignored issues
show
Documentation introduced by
150 is of type integer, 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...
Documentation introduced by
'getCustomtagName' 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...
110
        $objectTable->addColumn(new SmartObjectColumn('description', 'left'));
111
        $objectTable->addColumn(new SmartObjectColumn('language', 'center', 150));
0 ignored issues
show
Documentation introduced by
150 is of type integer, 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...
112
113
        //      $objectTable->addCustomAction('getCreateItemLink');
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% 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...
114
        //      $objectTable->addCustomAction('getCreateAttributLink');
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% 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...
115
116
        //      $objectTable->addIntroButton('addcustomtag', 'customtag.php?op=mod', _AM_SOBJECT_CUSTOMTAGS_CREATE); //mb button
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% 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...
117
118
        /*
0 ignored issues
show
Unused Code Comprehensibility introduced by
57% 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...
119
                $criteria_upcoming = new CriteriaCompo();
120
                $criteria_upcoming->add(new Criteria('start_date', time(), '>'));
121
                $objectTable->addFilter(_AM_SOBJECT_FILTER_UPCOMING, array(
122
                                            'key' => 'start_date',
123
                                            'criteria' => $criteria_upcoming
124
                ));
125
126
                $criteria_last7days = new CriteriaCompo();
127
                $criteria_last7days->add(new Criteria('start_date', time() - 30 *(60 * 60 * 24), '>'));
128
                $criteria_last7days->add(new Criteria('start_date', time(), '<'));
129
                $objectTable->addFilter(_AM_SOBJECT_FILTER_LAST7DAYS, array(
130
                                            'key' => 'start_date',
131
                                            'criteria' => $criteria_last7days
132
                ));
133
134
                $criteria_last30days = new CriteriaCompo();
135
                $criteria_last30days->add(new Criteria('start_date', time() - 30 *(60 * 60 * 24), '>'));
136
                $criteria_last30days->add(new Criteria('start_date', time(), '<'));
137
                $objectTable->addFilter(_AM_SOBJECT_FILTER_LAST30DAYS, array(
138
                                            'key' => 'start_date',
139
                                            'criteria' => $criteria_last30days
140
                ));
141
        */
142
        $objectTable->addQuickSearch(array('title', 'summary', 'description'));
143
        $objectTable->addCustomAction('getCloneLink');
144
145
        $objectTable->render();
146
147
        echo '<br>';
148
        smart_close_collapsable('createdcustomtags');
149
        echo '<br>';
150
151
        break;
152
}
153
154
//smart_modFooter();
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% 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...
155
//xoops_cp_footer();
156
include_once __DIR__ . '/admin_footer.php';
157