| Conditions | 4 |
| Paths | 6 |
| Total Lines | 95 |
| Code Lines | 58 |
| 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', $this->targetObject->getVar( |
||
| 76 | 'audio_id' |
||
| 77 | ) |
||
| 78 | ); |
||
| 79 | $this->addElement($hidden); |
||
| 80 | unset($hidden); |
||
| 81 | |||
| 82 | // Audio_id |
||
| 83 | $this->addElement( |
||
| 84 | new XoopsFormLabel(\AM_YOGURT_AUDIO_AUDIO_ID, $this->targetObject->getVar('audio_id'), 'audio_id') |
||
| 85 | ); |
||
| 86 | |||
| 87 | // Uid_owner |
||
| 88 | $this->addElement( |
||
| 89 | new XoopsFormSelectUser( |
||
| 90 | \AM_YOGURT_AUDIO_UID_OWNER, 'uid_owner', false, $this->targetObject->getVar( |
||
| 91 | 'uid_owner' |
||
| 92 | ), 1, false |
||
| 93 | ), |
||
| 94 | false |
||
| 95 | ); |
||
| 96 | // Title |
||
| 97 | $this->addElement( |
||
| 98 | new XoopsFormText(\AM_YOGURT_AUDIO_TITLE, 'title', 50, 255, $this->targetObject->getVar('title')), |
||
| 99 | false |
||
| 100 | ); |
||
| 101 | // Author |
||
| 102 | $this->addElement( |
||
| 103 | new XoopsFormText(\AM_YOGURT_AUDIO_AUTHOR, 'author', 50, 255, $this->targetObject->getVar('author')), |
||
| 104 | false |
||
| 105 | ); |
||
| 106 | |||
| 107 | // Description |
||
| 108 | if (\class_exists('XoopsFormEditor')) { |
||
| 109 | $editorOptions = []; |
||
| 110 | $editorOptions['name'] = 'description'; |
||
| 111 | $editorOptions['value'] = $this->targetObject->getVar('description', 'e'); |
||
| 112 | $editorOptions['rows'] = 5; |
||
| 113 | $editorOptions['cols'] = 40; |
||
| 114 | $editorOptions['width'] = '100%'; |
||
| 115 | $editorOptions['height'] = '400px'; |
||
| 116 | //$editorOptions['editor'] = xoops_getModuleOption('yogurt_editor', 'yogurt'); |
||
| 117 | //$this->addElement( new \XoopsFormEditor(AM_YOGURT_AUDIO_DESCRIPTION, 'description', $editorOptions), false ); |
||
| 118 | if ($this->helper->isUserAdmin()) { |
||
| 119 | $descEditor = new XoopsFormEditor( |
||
| 120 | \AM_YOGURT_AUDIO_DESCRIPTION, $this->helper->getConfig( |
||
| 121 | 'yogurtEditorAdmin' |
||
| 122 | ), $editorOptions, $nohtml = false, $onfailure = 'textarea' |
||
| 123 | ); |
||
| 124 | } else { |
||
| 125 | $descEditor = new XoopsFormEditor( |
||
| 126 | \AM_YOGURT_AUDIO_DESCRIPTION, $this->helper->getConfig( |
||
| 127 | 'yogurtEditorUser' |
||
| 128 | ), $editorOptions, $nohtml = false, $onfailure = 'textarea' |
||
| 129 | ); |
||
| 130 | } |
||
| 131 | } else { |
||
| 132 | $descEditor = new XoopsFormDhtmlTextArea( |
||
|
|
|||
| 133 | \AM_YOGURT_AUDIO_DESCRIPTION, 'description', $this->targetObject->getVar( |
||
| 134 | 'description', |
||
| 135 | 'e' |
||
| 136 | ), 5, 50 |
||
| 137 | ); |
||
| 138 | } |
||
| 139 | $this->addElement($descEditor); |
||
| 140 | // Url |
||
| 141 | $this->addElement(new \XoopsFormFile(\AM_YOGURT_AUDIO_URL, 'filename', $this->helper->getConfig('maxsize')), false); |
||
| 142 | |||
| 143 | // Data_creation |
||
| 144 | $this->addElement( |
||
| 145 | new XoopsFormTextDateSelect( |
||
| 146 | \AM_YOGURT_AUDIO_DATE_CREATED, 'date_created', 0, formatTimestamp($this->targetObject->getVar('date_created'), 's') |
||
| 147 | ) |
||
| 148 | ); |
||
| 149 | |||
| 150 | $this->addElement( |
||
| 151 | new XoopsFormTextDateSelect( |
||
| 152 | \AM_YOGURT_AUDIO_DATE_UPDATED, 'date_updated', 0, formatTimestamp($this->targetObject->getVar('date_updated'), 's') |
||
| 153 | ) |
||
| 154 | ); |
||
| 155 | |||
| 156 | $this->addElement(new XoopsFormHidden('op', 'save')); |
||
| 157 | $this->addElement(new XoopsFormButton('', 'submit', \_SUBMIT, 'submit')); |
||
| 158 | } |
||
| 160 |