| Conditions | 22 |
| Paths | 768 |
| Total Lines | 256 |
| Code Lines | 204 |
| 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 |
||
| 62 | public static function display_form( |
||
| 63 | $course, |
||
| 64 | $hidden_fields = null, |
||
| 65 | $avoidSerialize = false, |
||
| 66 | $avoidCourseInForm = false |
||
| 67 | ) { |
||
| 68 | global $charset; ?> |
||
| 69 | <script> |
||
| 70 | function exp(item) { |
||
| 71 | el = document.getElementById('div_'+item); |
||
| 72 | if (el.style.display == 'none') { |
||
| 73 | el.style.display = ''; |
||
| 74 | $('#img_'+item).removeClass(); |
||
| 75 | $('#img_'+item).addClass('fa fa-minus-square-o fa-lg'); |
||
| 76 | |||
| 77 | } else { |
||
| 78 | el.style.display = 'none'; |
||
| 79 | $('#img_'+item).removeClass(); |
||
| 80 | $('#img_'+item).addClass('fa fa-plus-square-o fa-lg'); |
||
| 81 | } |
||
| 82 | } |
||
| 83 | |||
| 84 | function setCheckboxForum(type, value, item_id) { |
||
| 85 | d = document.course_select_form; |
||
| 86 | for (i = 0; i < d.elements.length; i++) { |
||
| 87 | if (d.elements[i].type == "checkbox") { |
||
| 88 | var name = d.elements[i].attributes.getNamedItem('name').nodeValue; |
||
| 89 | if (name.indexOf(type) > 0 || type == 'all') { |
||
| 90 | if ($(d.elements[i]).attr('rel') == item_id) { |
||
| 91 | d.elements[i].checked = value; |
||
| 92 | } |
||
| 93 | } |
||
| 94 | } |
||
| 95 | } |
||
| 96 | } |
||
| 97 | |||
| 98 | function setCheckbox(type,value) { |
||
| 99 | d = document.course_select_form; |
||
| 100 | for (i = 0; i < d.elements.length; i++) { |
||
| 101 | if (d.elements[i].type == "checkbox") { |
||
| 102 | var name = d.elements[i].attributes.getNamedItem('name').nodeValue; |
||
| 103 | if( name.indexOf(type) > 0 || type == 'all' ){ |
||
| 104 | d.elements[i].checked = value; |
||
| 105 | } |
||
| 106 | } |
||
| 107 | } |
||
| 108 | } |
||
| 109 | |||
| 110 | function checkLearnPath(message){ |
||
| 111 | d = document.course_select_form; |
||
| 112 | for (i = 0; i < d.elements.length; i++) { |
||
| 113 | if (d.elements[i].type == "checkbox") { |
||
| 114 | var name = d.elements[i].attributes.getNamedItem('name').nodeValue; |
||
| 115 | if( name.indexOf('learnpath') > 0){ |
||
| 116 | if(d.elements[i].checked){ |
||
| 117 | setCheckbox('document',true); |
||
| 118 | alert(message); |
||
| 119 | break; |
||
| 120 | } |
||
| 121 | } |
||
| 122 | } |
||
| 123 | } |
||
| 124 | } |
||
| 125 | |||
| 126 | function check_forum(obj) { |
||
| 127 | var id = $(obj).attr('rel'); |
||
| 128 | var my_id = $(obj).attr('my_rel'); |
||
| 129 | var checked = false; |
||
| 130 | if ($('#resource_forum_'+my_id).attr('checked')) { |
||
| 131 | checked = true; |
||
| 132 | } |
||
| 133 | setCheckboxForum('thread', checked, my_id); |
||
| 134 | $('#resource_Forum_Category_'+id).attr('checked','checked'); |
||
| 135 | } |
||
| 136 | |||
| 137 | function check_category(obj) { |
||
| 138 | var my_id = $(obj).attr('my_rel'); |
||
| 139 | var checked = false; |
||
| 140 | if ($('#resource_Forum_Category_'+my_id).attr('checked')) { |
||
| 141 | checked = true; |
||
| 142 | } |
||
| 143 | $('.resource_forum').each(function(index, value) { |
||
| 144 | if ($(value).attr('rel') == my_id) { |
||
| 145 | $(value).attr('checked', checked); |
||
| 146 | } |
||
| 147 | }); |
||
| 148 | |||
| 149 | $('.resource_topic').each(function(index, value) { |
||
| 150 | if ($(value).attr('cat_id') == my_id) { |
||
| 151 | $(value).attr('checked', checked); |
||
| 152 | } |
||
| 153 | }); |
||
| 154 | } |
||
| 155 | |||
| 156 | function check_topic(obj) { |
||
| 157 | var my_id = $(obj).attr('cat_id'); |
||
| 158 | var forum_id = $(obj).attr('forum_id'); |
||
| 159 | $('#resource_Forum_Category_'+my_id).attr('checked','checked'); |
||
| 160 | $('#resource_forum_'+forum_id).attr('checked','checked'); |
||
| 161 | } |
||
| 162 | </script> |
||
| 163 | <?php |
||
| 164 | // get destination course title |
||
| 165 | if (!empty($hidden_fields['destination_course'])) { |
||
| 166 | $sessionTitle = !empty($hidden_fields['destination_session']) ? ' ('.api_get_session_name($hidden_fields['destination_session']).')' : null; |
||
| 167 | $courseInfo = api_get_course_info($hidden_fields['destination_course']); |
||
| 168 | echo '<h3>'; |
||
| 169 | echo get_lang('DestinationCourse').' : '.$courseInfo['title'].' ('.$courseInfo['code'].') '.$sessionTitle; |
||
| 170 | echo '</h3>'; |
||
| 171 | } |
||
| 172 | |||
| 173 | echo '<script src="'.api_get_path(WEB_CODE_PATH).'inc/lib/javascript/upload.js" type="text/javascript"></script>'; |
||
| 174 | echo '<div class="tool-backups-options">'; |
||
| 175 | echo '<form method="post" id="upload_form" name="course_select_form">'; |
||
| 176 | echo '<input type="hidden" name="action" value="course_select_form"/>'; |
||
| 177 | |||
| 178 | if (!empty($hidden_fields['destination_course']) && |
||
| 179 | !empty($hidden_fields['origin_course']) && |
||
| 180 | !empty($hidden_fields['destination_session']) && |
||
| 181 | !empty($hidden_fields['origin_session']) |
||
| 182 | ) { |
||
| 183 | echo '<input type="hidden" name="destination_course" value="'.$hidden_fields['destination_course'].'"/>'; |
||
| 184 | echo '<input type="hidden" name="origin_course" value="'.$hidden_fields['origin_course'].'"/>'; |
||
| 185 | echo '<input type="hidden" name="destination_session" value="'.$hidden_fields['destination_session'].'"/>'; |
||
| 186 | echo '<input type="hidden" name="origin_session" value="'.$hidden_fields['origin_session'].'"/>'; |
||
| 187 | } |
||
| 188 | |||
| 189 | $forum_categories = []; |
||
| 190 | $forums = []; |
||
| 191 | $forum_topics = []; |
||
| 192 | |||
| 193 | echo '<p>'; |
||
| 194 | echo get_lang('SelectResources'); |
||
| 195 | echo '</p>'; |
||
| 196 | echo Display::return_message(get_lang('DontForgetToSelectTheMediaFilesIfYourResourceNeedIt')); |
||
| 197 | |||
| 198 | $resource_titles = self::getResourceTitleList(); |
||
| 199 | $element_count = self::parseResources($resource_titles, $course->resources, true, true); |
||
| 200 | |||
| 201 | // Fixes forum order |
||
| 202 | if (!empty($forum_categories)) { |
||
| 203 | $type = RESOURCE_FORUMCATEGORY; |
||
| 204 | echo '<div class="item-backup" onclick="javascript:exp('."'$type'".');">'; |
||
| 205 | echo '<em id="img_'.$type.'" class="fa fa-minus-square-o fa-lg"></em>'; |
||
| 206 | echo '<span class="title">'.$resource_titles[RESOURCE_FORUM].'</span></div>'; |
||
| 207 | echo '<div class="item-content" id="div_'.$type.'">'; |
||
| 208 | echo '<ul class="list-backups-options">'; |
||
| 209 | foreach ($forum_categories as $forum_category_id => $forum_category) { |
||
| 210 | echo '<li>'; |
||
| 211 | echo '<label class="checkbox">'; |
||
| 212 | echo '<input type="checkbox" |
||
| 213 | id="resource_'.RESOURCE_FORUMCATEGORY.'_'.$forum_category_id.'" |
||
| 214 | my_rel="'.$forum_category_id.'" |
||
| 215 | onclick="javascript:check_category(this);" |
||
| 216 | name="resource['.RESOURCE_FORUMCATEGORY.']['.$forum_category_id.']" /> '; |
||
| 217 | $forum_category->show(); |
||
| 218 | echo '</label>'; |
||
| 219 | echo '</li>'; |
||
| 220 | |||
| 221 | if (isset($forums[$forum_category_id])) { |
||
| 222 | $my_forums = $forums[$forum_category_id]; |
||
| 223 | echo '<ul>'; |
||
| 224 | foreach ($my_forums as $forum_id => $forum) { |
||
| 225 | echo '<li>'; |
||
| 226 | echo '<label class="checkbox">'; |
||
| 227 | echo '<input type="checkbox" |
||
| 228 | class="resource_forum" |
||
| 229 | id="resource_'.RESOURCE_FORUM.'_'.$forum_id.'" |
||
| 230 | onclick="javascript:check_forum(this);" |
||
| 231 | my_rel="'.$forum_id.'" |
||
| 232 | rel="'.$forum_category_id.'" |
||
| 233 | name="resource['.RESOURCE_FORUM.']['.$forum_id.']" />'; |
||
| 234 | $forum->show(); |
||
| 235 | echo '</label>'; |
||
| 236 | echo '</li>'; |
||
| 237 | if (isset($forum_topics[$forum_id])) { |
||
| 238 | $my_forum_topics = $forum_topics[$forum_id]; |
||
| 239 | if (!empty($my_forum_topics)) { |
||
| 240 | echo '<ul>'; |
||
| 241 | foreach ($my_forum_topics as $topic_id => $topic) { |
||
| 242 | echo '<li>'; |
||
| 243 | echo '<label class="checkbox">'; |
||
| 244 | echo '<input |
||
| 245 | type="checkbox" |
||
| 246 | id="resource_'.RESOURCE_FORUMTOPIC.'_'.$topic_id.'" |
||
| 247 | onclick="javascript:check_topic(this);" class="resource_topic" |
||
| 248 | forum_id="'.$forum_id.'" |
||
| 249 | rel="'.$forum_id.'" |
||
| 250 | cat_id="'.$forum_category_id.'" |
||
| 251 | name="resource['.RESOURCE_FORUMTOPIC.']['.$topic_id.']" />'; |
||
| 252 | $topic->show(); |
||
| 253 | echo '</label>'; |
||
| 254 | echo '</li>'; |
||
| 255 | } |
||
| 256 | echo '</ul>'; |
||
| 257 | } |
||
| 258 | } |
||
| 259 | } |
||
| 260 | echo '</ul>'; |
||
| 261 | } |
||
| 262 | echo '<hr/>'; |
||
| 263 | } |
||
| 264 | echo '</ul>'; |
||
| 265 | echo '</div>'; |
||
| 266 | echo '<script language="javascript">exp('."'$type'".')</script>'; |
||
| 267 | } |
||
| 268 | |||
| 269 | if ($avoidSerialize) { |
||
| 270 | /*Documents are avoided due the huge amount of memory that the serialize php function "eats" |
||
| 271 | (when there are directories with hundred/thousand of files) */ |
||
| 272 | // this is a known issue of serialize |
||
| 273 | $course->resources['document'] = null; |
||
| 274 | } |
||
| 275 | |||
| 276 | if ($avoidCourseInForm === false) { |
||
| 277 | /** @var Course $course */ |
||
| 278 | $courseSerialized = base64_encode(Course::serialize($course)); |
||
| 279 | echo '<input type="hidden" name="course" value="'.$courseSerialized.'"/>'; |
||
| 280 | } |
||
| 281 | |||
| 282 | if (is_array($hidden_fields)) { |
||
| 283 | foreach ($hidden_fields as $key => $value) { |
||
| 284 | echo '<input type="hidden" name="'.$key.'" value="'.$value.'"/>'; |
||
| 285 | } |
||
| 286 | } |
||
| 287 | |||
| 288 | $recycleOption = isset($_POST['recycle_option']) ? true : false; |
||
| 289 | if (empty($element_count)) { |
||
| 290 | echo Display::return_message(get_lang('NoDataAvailable'), 'warning'); |
||
| 291 | } else { |
||
| 292 | if (!empty($hidden_fields['destination_session'])) { |
||
| 293 | echo '<br /> |
||
| 294 | <button |
||
| 295 | class="save" |
||
| 296 | type="submit" |
||
| 297 | onclick="javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"), ENT_QUOTES, $charset))."'".')) return false;" >'. |
||
| 298 | get_lang('Ok').'</button>'; |
||
| 299 | } else { |
||
| 300 | if ($recycleOption) { |
||
| 301 | echo '<br /><button class="save" type="submit">'.get_lang('Ok').'</button>'; |
||
| 302 | } else { |
||
| 303 | echo '<br /> |
||
| 304 | <button |
||
| 305 | class="save btn btn-primary" |
||
| 306 | type="submit" |
||
| 307 | onclick="checkLearnPath(\''.addslashes(get_lang('DocumentsWillBeAddedToo')).'\')">'. |
||
| 308 | get_lang('Ok').'</button>'; |
||
| 309 | } |
||
| 310 | } |
||
| 311 | } |
||
| 312 | |||
| 313 | self::display_hidden_quiz_questions($course); |
||
| 314 | self::display_hidden_scorm_directories($course); |
||
| 315 | echo '</form>'; |
||
| 316 | echo '</div>'; |
||
| 317 | echo '<div id="dynamic_div" style="display:block;margin-left:40%;margin-top:10px;height:50px;"></div>'; |
||
| 318 | } |
||
| 819 |