Conditions | 8 |
Paths | 48 |
Total Lines | 98 |
Code Lines | 61 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
55 | public function __construct($target) |
||
56 | { |
||
57 | $helper = \XoopsModules\Countdown\Helper::getInstance(); |
||
58 | |||
59 | $this->targetObject = $target; |
||
60 | |||
61 | $title = $this->targetObject->isNew() ? sprintf(_AM_COUNTDOWN_EVENTS_ADD) : sprintf(_AM_COUNTDOWN_EVENTS_EDIT); |
||
62 | parent::__construct($title, 'form', xoops_getenv('PHP_SELF'), 'post', true); |
||
63 | $this->setExtra('enctype="multipart/form-data"'); |
||
64 | |||
65 | //include ID field, it's needed so the module knows if it is a new form or an edited form |
||
66 | |||
67 | $hidden = new \XoopsFormHidden('event_id', $this->targetObject->getVar('event_id')); |
||
68 | $this->addElement($hidden); |
||
69 | unset($hidden); |
||
70 | |||
71 | // Id |
||
72 | $this->addElement(new \XoopsFormLabel(_AM_COUNTDOWN_EVENTS_ID, $this->targetObject->getVar('event_id'), 'event_id')); |
||
73 | //Category |
||
74 | $category_id = 0; |
||
|
|||
75 | if (!$this->targetObject->isNew()) { |
||
76 | $category_id = $this->targetObject->getVar('event_categoryid'); |
||
77 | } |
||
78 | |||
79 | $categoryHandler = $helper->getHandler('category'); |
||
80 | $categories = $categoryHandler->getObjects(); |
||
81 | $category_sel = new XoopsFormSelect(_AM_COUNTDOWN_CATEGORY, 'event_categoryid', $this->targetObject->getVar('event_categoryid')); |
||
82 | $i = 1; |
||
83 | |||
84 | foreach (array_keys($categories) as $i) { |
||
85 | $category_sel->addOption($categories[$i]->getVar('category_id'), $categories[$i]->getVar('category_title')); |
||
86 | } |
||
87 | $this->addElement($category_sel); |
||
88 | |||
89 | // Name |
||
90 | $this->addElement(new \XoopsFormText(_AM_COUNTDOWN_EVENTS_NAME, 'event_name', 50, 255, $this->targetObject->getVar('event_name')), false); |
||
91 | // Description |
||
92 | if (class_exists('XoopsFormEditor')) { |
||
93 | $editorOptions = []; |
||
94 | $editorOptions['name'] = 'event_description'; |
||
95 | $editorOptions['value'] = $this->targetObject->getVar('event_description', 'e'); |
||
96 | $editorOptions['rows'] = 5; |
||
97 | $editorOptions['cols'] = 40; |
||
98 | $editorOptions['width'] = '100%'; |
||
99 | $editorOptions['height'] = '400px'; |
||
100 | //$editorOptions['editor'] = xoops_getModuleOption('countdown_editor', 'countdown'); |
||
101 | //$this->addElement( new \XoopsFormEditor(_AM_COUNTDOWN_EVENTS_DESCRIPTION, 'description', $editorOptions), false ); |
||
102 | if ($helper->isUserAdmin()) { |
||
103 | $descEditor = new \XoopsFormEditor(_AM_COUNTDOWN_EVENTS_DESCRIPTION, $helper->getConfig('countdownEditorAdmin'), $editorOptions, $nohtml = false, $onfailure = 'textarea'); |
||
104 | } else { |
||
105 | $descEditor = new \XoopsFormEditor(_AM_COUNTDOWN_EVENTS_DESCRIPTION, $helper->getConfig('countdownEditorUser'), $editorOptions, $nohtml = false, $onfailure = 'textarea'); |
||
106 | } |
||
107 | } else { |
||
108 | $descEditor = new \XoopsFormDhtmlTextArea(_AM_COUNTDOWN_EVENTS_DESCRIPTION, 'event_description', $this->targetObject->getVar('event_description', 'e'), '100%', '100%'); |
||
109 | } |
||
110 | $this->addElement($descEditor); |
||
111 | |||
112 | // Event Date |
||
113 | $this->addElement(new \XoopsFormDateTime(_AM_COUNTDOWN_EVENTS_DATE, 'event_date', '', strtotime($this->targetObject->getVar('event_date')))); |
||
114 | |||
115 | // Logo |
||
116 | $logo = $this->targetObject->getVar('event_logo') ?: 'blank.png'; |
||
117 | |||
118 | $uploadDir = '/uploads/countdown/images/'; |
||
119 | $imgtray = new \XoopsFormElementTray(_AM_COUNTDOWN_EVENTS_LOGO, '<br>'); |
||
120 | $imgpath = sprintf(_AM_COUNTDOWN_FORMIMAGE_PATH, $uploadDir); |
||
121 | $imageselect = new \XoopsFormSelect($imgpath, 'event_logo', $logo); |
||
122 | $imageArray = \XoopsLists::getImgListAsArray(XOOPS_ROOT_PATH . $uploadDir); |
||
123 | foreach ($imageArray as $image) { |
||
124 | $imageselect->addOption((string)$image, $image); |
||
125 | } |
||
126 | $imageselect->setExtra("onchange='showImgSelected(\"image_logo\", \"logo\", \"" . $uploadDir . '", "", "' . XOOPS_URL . "\")'"); |
||
127 | $imgtray->addElement($imageselect); |
||
128 | $imgtray->addElement(new \XoopsFormLabel('', "<br><img src='" . XOOPS_URL . '/' . $uploadDir . '/' . $logo . "' name='image_logo' id='image_logo' alt=''>")); |
||
129 | $fileseltray = new \XoopsFormElementTray('', '<br>'); |
||
130 | $fileseltray->addElement(new \XoopsFormFile(_AM_COUNTDOWN_FORMUPLOAD, 'event_logo', $helper->getConfig('maxsize'))); |
||
131 | $fileseltray->addElement(new \XoopsFormLabel('')); |
||
132 | $imgtray->addElement($fileseltray); |
||
133 | $this->addElement($imgtray); |
||
134 | |||
135 | // Submitter |
||
136 | $this->addElement(new \XoopsFormSelectUser(_AM_COUNTDOWN_EVENTS_POSTERNAME, 'event_uid', false, $this->targetObject->getVar('event_uid'), 1, false), false); |
||
137 | |||
138 | // Data_creation |
||
139 | $this->addElement( |
||
140 | new XoopsFormTextDateSelect( |
||
141 | \_AM_COUNTDOWN_EVENTS_DATE_CREATED, 'date_created', 0, \formatTimestamp($this->targetObject->getVar('date_created'), 's') |
||
142 | ) |
||
143 | ); |
||
144 | // Data_update |
||
145 | $this->addElement( |
||
146 | new XoopsFormTextDateSelect( |
||
147 | \_AM_COUNTDOWN_EVENTS_DATE_UPDATED, 'date_updated', 0, \formatTimestamp($this->targetObject->getVar('date_updated'), 's') |
||
148 | ) |
||
149 | ); |
||
150 | |||
151 | $this->addElement(new \XoopsFormHidden('op', 'save')); |
||
152 | $this->addElement(new \XoopsFormButton('', 'submit', _SUBMIT, 'submit')); |
||
153 | } |
||
155 |