Completed
Push — master ( 592643...f454c2 )
by Michael
03:05 queued 01:21
created

Mailinglist   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 70
Duplicated Lines 18.57 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 13
loc 70
rs 10
c 0
b 0
f 0
wmc 10
lcom 0
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 13 13 1
C getForm() 0 44 9

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace XoopsModules\Xnewsletter;
4
5
/**
6
 * ****************************************************************************
7
 *  - A Project by Developers TEAM For Xoops - ( https://xoops.org )
8
 * ****************************************************************************
9
 *  XNEWSLETTER - MODULE FOR XOOPS
10
 *  Copyright (c) 2007 - 2012
11
 *  Goffy ( wedega.com )
12
 *
13
 *  You may not change or alter any portion of this comment or credits
14
 *  of supporting developers from this source code or any supporting
15
 *  source code which is considered copyrighted (c) material of the
16
 *  original comment or credit authors.
17
 *
18
 *  This program is distributed in the hope that it will be useful,
19
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
 *  GNU General Public License for more details.
22
 *  ---------------------------------------------------------------------------
23
 * @copyright  Goffy ( wedega.com )
24
 * @license    GNU General Public License 2.0
25
 * @package    xnewsletter
26
 * @author     Goffy ( [email protected] )
27
 *
28
 * ****************************************************************************
29
 */
30
31
//use XoopsModules\Xnewsletter;
32
33
require_once dirname(__DIR__) . '/include/common.php';
34
35
/**
36
 * Class Mailinglist
37
 */
38
class Mailinglist extends \XoopsObject
39
{
40
    public $helper = null;
41
42
    //Constructor
43
44 View Code Duplication
    public function __construct()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
45
    {
46
        $this->helper = Helper::getInstance();
47
        $this->db     = \XoopsDatabaseFactory::getDatabaseConnection();
48
        $this->initVar('mailinglist_id', XOBJ_DTYPE_INT, null, false);
49
        $this->initVar('mailinglist_name', XOBJ_DTYPE_TXTBOX, null, false, 100);
50
        $this->initVar('mailinglist_email', XOBJ_DTYPE_TXTBOX, null, false, 100);
51
        $this->initVar('mailinglist_listname', XOBJ_DTYPE_TXTBOX, null, false, 100);
52
        $this->initVar('mailinglist_subscribe', XOBJ_DTYPE_TXTBOX, null, false, 100);
53
        $this->initVar('mailinglist_unsubscribe', XOBJ_DTYPE_TXTBOX, null, false, 100);
54
        $this->initVar('mailinglist_submitter', XOBJ_DTYPE_INT, null, false);
55
        $this->initVar('mailinglist_created', XOBJ_DTYPE_INT, time(), false);
56
    }
57
58
    /**
59
     * @param bool $action
60
     *
61
     * @return \XoopsThemeForm
62
     */
63
    public function getForm($action = false)
64
    {
65
        global $xoopsDB;
66
67
        if (false === $action) {
68
            $action = $_SERVER['REQUEST_URI'];
69
        }
70
71
        $title = $this->isNew() ? sprintf(_AM_XNEWSLETTER_MAILINGLIST_ADD) : sprintf(_AM_XNEWSLETTER_MAILINGLIST_EDIT);
72
73
        require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
74
        $form = new \XoopsThemeForm($title, 'form', $action, 'post', true);
75
        $form->setExtra('enctype="multipart/form-data"');
76
77
        $mailinglist_name = $this->isNew() ? 'myname' : $this->getVar('mailinglist_name');
78
        $form->addElement(new \XoopsFormText(_AM_XNEWSLETTER_MAILINGLIST_NAME, 'mailinglist_name', 50, 255, $mailinglist_name), true);
79
80
        $mailinglist_email = $this->isNew() ? '[email protected]' : $this->getVar('mailinglist_email');
81
        $form->addElement(new \XoopsFormText(_AM_XNEWSLETTER_MAILINGLIST_EMAIL_DESC, 'mailinglist_email', 50, 255, $mailinglist_email), true);
82
83
        $mailinglist_listname = $this->isNew() ? 'nameofmylist' : $this->getVar('mailinglist_listname');
84
        $form->addElement(new \XoopsFormText(_AM_XNEWSLETTER_MAILINGLIST_LISTNAME, 'mailinglist_listname', 50, 255, $mailinglist_listname), true);
85
86
        $mailinglist_subscribe = $this->isNew() ? 'subscribe nameofmylist {email}' : $this->getVar('mailinglist_subscribe');
87
        $form->addElement(new \XoopsFormText(_AM_XNEWSLETTER_MAILINGLIST_SUBSCRIBE . "<br><span style='font-size:0,75em'>" . _AM_XNEWSLETTER_MAILINGLIST_SUBSCRIBE_DESC . '</span>', 'mailinglist_subscribe', 50, 255, $mailinglist_subscribe), true);
88
89
        $mailinglist_unsubscribe = $this->isNew() ? 'unsubscribe nameofmylist {email}' : $this->getVar('mailinglist_unsubscribe');
90
        $form->addElement(new \XoopsFormText(_AM_XNEWSLETTER_MAILINGLIST_UNSUBSCRIBE . "<br><span style='font-size:0,75em'>" . _AM_XNEWSLETTER_MAILINGLIST_SUBSCRIBE_DESC . '</span>', 'mailinglist_unsubscribe', 50, 255, $mailinglist_unsubscribe), true);
91
92
        $time = $this->isNew() ? time() : $this->getVar('mailinglist_created');
93
        $form->addElement(new \XoopsFormHidden('mailinglist_submitter', $GLOBALS['xoopsUser']->uid()));
94
        $form->addElement(new \XoopsFormHidden('mailinglist_created', $time));
95
96
        $form->addElement(new \XoopsFormLabel(_AM_XNEWSLETTER_ACCOUNTS_SUBMITTER, $GLOBALS['xoopsUser']->uname()));
97
        $form->addElement(new \XoopsFormLabel(_AM_XNEWSLETTER_ACCOUNTS_CREATED, formatTimestamp($time, 's')));
98
99
        //$form->addElement(new \XoopsFormSelectUser(_AM_XNEWSLETTER_MAILINGLIST_SUBMITTER, "mailinglist_submitter", false, $this->getVar("mailinglist_submitter"), 1, false), true);
100
        //$form->addElement(new \XoopsFormTextDateSelect(_AM_XNEWSLETTER_MAILINGLIST_CREATED, "mailinglist_created", "", $this->getVar("mailinglist_created")));
101
102
        $form->addElement(new \XoopsFormHidden('op', 'save_mailinglist'));
103
        $form->addElement(new \XoopsFormButton('', 'submit', _SUBMIT, 'submit'));
104
105
        return $form;
106
    }
107
}
108