Completed
Push — master ( 692213...d4ec0d )
by Goffy
03:18 queued 01:37
created

XnewsletterTaskHandler   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 17
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 5 5 1

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
 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
 * xnewsletter module for xoops
13
 *
14
 * @copyright       The TXMod XOOPS Project http://sourceforge.net/projects/thmod/
15
 * @copyright       The XOOPS Project http://sourceforge.net/projects/xoops/
16
 * @license         GPL 2.0 or later
17
 * @package         xnewsletter
18
 * @since           2.5.x
19
 * @author          XOOPS Development Team ( [email protected] ) - ( http://xoops.org )
20
 * @version         $Id: xnewsletter_task.php 12559 2014-06-02 08:10:39Z beckmi $
21
 */
22
23
// defined("XOOPS_ROOT_PATH") || die("XOOPS root path not defined");
24
include_once dirname(__DIR__) . '/include/common.php';
25
26
/**
27
 * Class XnewsletterTask
28
 */
29
class XnewsletterTask extends XoopsObject
30
{
31
    public $xnewsletter = null;
32
33
    //Constructor
34
    /**
35
     * Class Constructor
36
     */
37 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...
38
    {
39
        $this->xnewsletter = xnewsletterxnewsletter::getInstance();
40
        $this->db          = XoopsDatabaseFactory::getDatabaseConnection();
41
        $this->XoopsObject();
42
        $this->initVar("task_id", XOBJ_DTYPE_INT, null, false, 8);
43
        $this->initVar("task_letter_id", XOBJ_DTYPE_INT, null, false, 8);
44
        $this->initVar("task_subscr_id", XOBJ_DTYPE_INT, null, false, 8);
45
        $this->initVar("task_starttime", XOBJ_DTYPE_INT, null, false, 8);
46
        $this->initVar("task_submitter", XOBJ_DTYPE_INT, null, false, 8);
47
        $this->initVar("task_created", XOBJ_DTYPE_INT, null, false, 8);
48
    }
49
50
    /**
51
     * @param bool $action
52
     *
53
     * @return XoopsThemeForm
54
     */
55
    function getForm($action = false)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
56
    {
57
        global $xoopsDB;
58
59
        if ($action === false) {
60
            $action = $_SERVER["REQUEST_URI"];
61
        }
62
63
        $title = $this->isNew() ? sprintf(_AM_XNEWSLETTER_TASK_ADD) : sprintf(_AM_XNEWSLETTER_TASK_EDIT);
64
65
        include_once XOOPS_ROOT_PATH . "/class/xoopsformloader.php";
66
67
        $form = new XoopsThemeForm($title, "form", $action, "post", true);
68
        $form->setExtra('enctype="multipart/form-data"');
69
70
        $letterCriteria = new CriteriaCompo();
71
        $letterCriteria->setSort('letter_id');
72
        $letterCriteria->setOrder('DESC');
73
        $letter_select = new XoopsFormSelect(_AM_XNEWSLETTER_TASK_LETTER_ID, "task_letter_id", $this->getVar("task_letter_id"));
74
        $letter_select->addOptionArray($this->xnewsletter->getHandler('letter')->getList($letterCriteria));
75
        $form->addElement($letter_select, true);
76
77
        $subscrCriteria = new CriteriaCompo();
78
        $subscrCriteria->setSort('subscr_id');
79
        $subscrCriteria->setOrder('ASC');
80
        $subscr_select = new XoopsFormSelect(_AM_XNEWSLETTER_TASK_SUBSCR_ID, "task_subscr_id", $this->getVar("task_subscr_id"));
81
        $subscr_select->addOptionArray($this->xnewsletter->getHandler('subscr')->getList($subscrCriteria));
82
        $form->addElement($subscr_select, true);
83
84
        $form->addElement(new XoopsFormTextDateSelect(_AM_XNEWSLETTER_TASK_STARTTIME, "task_starttime", "", $this->getVar("task_starttime")));
85
86
        $form->addElement(new XoopsFormSelectUser(_AM_XNEWSLETTER_TASK_SUBMITTER, "task_submitter", false, $this->getVar("task_submitter"), 1, false), true);
87
88
        $form->addElement(new XoopsFormTextDateSelect(_AM_XNEWSLETTER_TASK_CREATED, "task_created", "", $this->getVar("task_created")));
89
90
        $form->addElement(new XoopsFormHidden("op", "save_task"));
91
        $form->addElement(new XoopsFormButton("", "submit", _SUBMIT, "submit"));
92
93
        return $form;
94
    }
95
}
96
97
/**
98
 * Class XnewsletterTaskHandler
99
 */
100 View Code Duplication
class XnewsletterTaskHandler extends XoopsPersistableObjectHandler
0 ignored issues
show
Duplication introduced by
This class 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...
101
{
102
    /**
103
     * @var xnewsletterxnewsletter
104
     * @access public
105
     */
106
    public $xnewsletter = null;
107
108
    /**
109
     * @param null|object $db
110
     */
111
    public function __construct(&$db)
112
    {
113
        parent::__construct($db, "xnewsletter_task", "XnewsletterTask", "task_id", "task_letter_id");
114
        $this->xnewsletter = xnewsletterxnewsletter::getInstance();
115
    }
116
}
117