Conditions | 4 |
Paths | 6 |
Total Lines | 108 |
Code Lines | 67 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
63 | public function __construct($target) |
||
64 | { |
||
65 | $this->helper = $target->helper; |
||
66 | $this->targetObject = $target; |
||
67 | |||
68 | $title = $this->targetObject->isNew() ? \sprintf(\AM_YOGURT_AUDIO_ADD) : \sprintf(\AM_YOGURT_AUDIO_EDIT); |
||
69 | parent::__construct($title, 'form', \xoops_getenv('SCRIPT_NAME'), 'post', true); |
||
70 | $this->setExtra('enctype="multipart/form-data"'); |
||
71 | |||
72 | //include ID field, it's needed so the module knows if it is a new form or an edited form |
||
73 | |||
74 | $hidden = new XoopsFormHidden( |
||
75 | 'audio_id', |
||
76 | $this->targetObject->getVar( |
||
77 | 'audio_id' |
||
78 | ) |
||
79 | ); |
||
80 | $this->addElement($hidden); |
||
81 | unset($hidden); |
||
82 | |||
83 | // Audio_id |
||
84 | $this->addElement( |
||
85 | new XoopsFormLabel(\AM_YOGURT_AUDIO_AUDIO_ID, $this->targetObject->getVar('audio_id'), 'audio_id') |
||
86 | ); |
||
87 | |||
88 | // Uid_owner |
||
89 | $this->addElement( |
||
90 | new XoopsFormSelectUser( |
||
91 | \AM_YOGURT_AUDIO_UID_OWNER, 'uid_owner', false, $this->targetObject->getVar( |
||
92 | 'uid_owner' |
||
93 | ), 1, false |
||
94 | ), |
||
95 | false |
||
96 | ); |
||
97 | // Title |
||
98 | $this->addElement( |
||
99 | new XoopsFormText(\AM_YOGURT_AUDIO_TITLE, 'title', 50, 255, $this->targetObject->getVar('title')), |
||
100 | false |
||
101 | ); |
||
102 | // Author |
||
103 | $this->addElement( |
||
104 | new XoopsFormText(\AM_YOGURT_AUDIO_AUTHOR, 'author', 50, 255, $this->targetObject->getVar('author')), |
||
105 | false |
||
106 | ); |
||
107 | |||
108 | // Description |
||
109 | if (\class_exists('XoopsFormEditor')) { |
||
110 | $editorOptions = []; |
||
111 | $editorOptions['name'] = 'description'; |
||
112 | $editorOptions['value'] = $this->targetObject->getVar('description', 'e'); |
||
113 | $editorOptions['rows'] = 5; |
||
114 | $editorOptions['cols'] = 40; |
||
115 | $editorOptions['width'] = '100%'; |
||
116 | $editorOptions['height'] = '400px'; |
||
117 | //$editorOptions['editor'] = xoops_getModuleOption('yogurt_editor', 'yogurt'); |
||
118 | //$this->addElement( new \XoopsFormEditor(AM_YOGURT_AUDIO_DESCRIPTION, 'description', $editorOptions), false ); |
||
119 | if ($this->helper->isUserAdmin()) { |
||
120 | $descEditor = new XoopsFormEditor( |
||
121 | \AM_YOGURT_AUDIO_DESCRIPTION, |
||
122 | $this->helper->getConfig( |
||
123 | 'yogurtEditorAdmin' |
||
124 | ), |
||
125 | $editorOptions, |
||
126 | $nohtml = false, |
||
127 | $onfailure = 'textarea' |
||
128 | ); |
||
129 | } else { |
||
130 | $descEditor = new XoopsFormEditor( |
||
131 | \AM_YOGURT_AUDIO_DESCRIPTION, |
||
132 | $this->helper->getConfig( |
||
133 | 'yogurtEditorUser' |
||
134 | ), |
||
135 | $editorOptions, |
||
136 | $nohtml = false, |
||
137 | $onfailure = 'textarea' |
||
138 | ); |
||
139 | } |
||
140 | } else { |
||
141 | $descEditor = new XoopsFormDhtmlTextArea( |
||
|
|||
142 | \AM_YOGURT_AUDIO_DESCRIPTION, |
||
143 | 'description', |
||
144 | $this->targetObject->getVar( |
||
145 | 'description', |
||
146 | 'e' |
||
147 | ), |
||
148 | 5, |
||
149 | 50 |
||
150 | ); |
||
151 | } |
||
152 | $this->addElement($descEditor); |
||
153 | // Url |
||
154 | $this->addElement(new \XoopsFormFile(\AM_YOGURT_AUDIO_URL, 'filename', $this->helper->getConfig('maxsize')), false); |
||
155 | |||
156 | // Data_creation |
||
157 | $this->addElement( |
||
158 | new XoopsFormTextDateSelect( |
||
159 | \AM_YOGURT_AUDIO_DATE_CREATED, 'date_created', 0, formatTimestamp($this->targetObject->getVar('date_created'), 's') |
||
160 | ) |
||
161 | ); |
||
162 | |||
163 | $this->addElement( |
||
164 | new XoopsFormTextDateSelect( |
||
165 | \AM_YOGURT_AUDIO_DATE_UPDATED, 'date_updated', 0, formatTimestamp($this->targetObject->getVar('date_updated'), 's') |
||
166 | ) |
||
167 | ); |
||
168 | |||
169 | $this->addElement(new XoopsFormHidden('op', 'save')); |
||
170 | $this->addElement(new XoopsFormButton('', 'submit', \_SUBMIT, 'submit')); |
||
171 | } |
||
173 |