| Conditions | 14 |
| Paths | 252 |
| Total Lines | 130 |
| Code Lines | 84 |
| 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 |
||
| 195 | public function exportCompleteReportXLS( |
||
| 196 | $document_path = '', |
||
| 197 | $user_id = null, |
||
| 198 | $export_user_fields = false, |
||
| 199 | $export_filter = 0, |
||
| 200 | $exercise_id = 0, |
||
| 201 | $hotpotato_name = null |
||
| 202 | ) { |
||
| 203 | global $charset; |
||
| 204 | $this->getExercisesReporting( |
||
| 205 | $document_path, |
||
| 206 | $user_id, |
||
| 207 | $export_filter, |
||
| 208 | $exercise_id, |
||
| 209 | $hotpotato_name |
||
| 210 | ); |
||
| 211 | $filename = 'exercise_results_'.api_get_local_time(); |
||
| 212 | if (!empty($user_id)) { |
||
| 213 | $filename = 'exercise_results_user_'.$user_id.'_'.api_get_local_time(); |
||
| 214 | } |
||
| 215 | |||
| 216 | // check if exists column 'user' |
||
| 217 | $withColumnUser = false; |
||
| 218 | foreach ($this->results as $result) { |
||
| 219 | if (!empty($result['last_name']) && !empty($result['first_name'])) { |
||
| 220 | $withColumnUser = true; |
||
| 221 | break; |
||
| 222 | } |
||
| 223 | } |
||
| 224 | $list = []; |
||
| 225 | if ($withColumnUser) { |
||
| 226 | $list[0][] = get_lang('Email'); |
||
| 227 | if (api_is_western_name_order()) { |
||
| 228 | $list[0][] = get_lang('FirstName'); |
||
| 229 | $list[0][] = get_lang('LastName'); |
||
| 230 | } else { |
||
| 231 | $list[0][] = get_lang('LastName'); |
||
| 232 | $list[0][] = get_lang('FirstName'); |
||
| 233 | } |
||
| 234 | } |
||
| 235 | |||
| 236 | if ($export_user_fields) { |
||
| 237 | //show user fields section with a big th colspan that spans over all fields |
||
| 238 | $extra_user_fields = UserManager::get_extra_fields( |
||
| 239 | 0, |
||
| 240 | 1000, |
||
| 241 | 5, |
||
| 242 | 'ASC', |
||
| 243 | false, |
||
| 244 | 1 |
||
| 245 | ); |
||
| 246 | |||
| 247 | //show the fields names for user fields |
||
| 248 | foreach ($extra_user_fields as $field) { |
||
| 249 | $list[0][] = api_html_entity_decode( |
||
| 250 | strip_tags($field[3]), |
||
| 251 | ENT_QUOTES, |
||
| 252 | $charset |
||
| 253 | ); |
||
| 254 | } |
||
| 255 | } |
||
| 256 | |||
| 257 | $list[0][] = get_lang('Title'); |
||
| 258 | $list[0][] = get_lang('StartDate'); |
||
| 259 | $list[0][] = get_lang('EndDate'); |
||
| 260 | $list[0][] = get_lang('Duration').' ('.get_lang('MinMinutes').')'; |
||
| 261 | $list[0][] = get_lang('Score'); |
||
| 262 | $list[0][] = get_lang('Total'); |
||
| 263 | $list[0][] = get_lang('Status'); |
||
| 264 | |||
| 265 | $column = 1; |
||
| 266 | foreach ($this->results as $row) { |
||
| 267 | if ($withColumnUser) { |
||
| 268 | $list[$column][] = api_html_entity_decode( |
||
| 269 | strip_tags($row['email']), |
||
| 270 | ENT_QUOTES, |
||
| 271 | $charset |
||
| 272 | ); |
||
| 273 | |||
| 274 | if (api_is_western_name_order()) { |
||
| 275 | $list[$column][] = api_html_entity_decode( |
||
| 276 | strip_tags($row['first_name']), |
||
| 277 | ENT_QUOTES, |
||
| 278 | $charset |
||
| 279 | ); |
||
| 280 | $list[$column][] = api_html_entity_decode( |
||
| 281 | strip_tags($row['last_name']), |
||
| 282 | ENT_QUOTES, |
||
| 283 | $charset |
||
| 284 | ); |
||
| 285 | } else { |
||
| 286 | $list[$column][] = api_html_entity_decode( |
||
| 287 | strip_tags($row['last_name']), |
||
| 288 | ENT_QUOTES, |
||
| 289 | $charset |
||
| 290 | ); |
||
| 291 | $list[$column][] = api_html_entity_decode( |
||
| 292 | strip_tags($row['first_name']), |
||
| 293 | ENT_QUOTES, |
||
| 294 | $charset |
||
| 295 | ); |
||
| 296 | } |
||
| 297 | } |
||
| 298 | |||
| 299 | if ($export_user_fields) { |
||
| 300 | //show user fields data, if any, for this user |
||
| 301 | $values = UserManager::get_extra_user_data( |
||
| 302 | $row['user_id'], |
||
| 303 | false, |
||
| 304 | false, |
||
| 305 | false, |
||
| 306 | true |
||
| 307 | ); |
||
| 308 | foreach ($values as $value) { |
||
| 309 | $list[$column][] = api_html_entity_decode(strip_tags($value), ENT_QUOTES, $charset); |
||
| 310 | } |
||
| 311 | } |
||
| 312 | |||
| 313 | $list[$column][] = api_html_entity_decode(strip_tags($row['title']), ENT_QUOTES, $charset); |
||
| 314 | $list[$column][] = $row['start_date']; |
||
| 315 | $list[$column][] = $row['end_date']; |
||
| 316 | $list[$column][] = $row['duration']; |
||
| 317 | $list[$column][] = $row['result']; |
||
| 318 | $list[$column][] = $row['max']; |
||
| 319 | $list[$column][] = $row['status']; |
||
| 320 | } |
||
| 321 | |||
| 322 | Export::arrayToXls($list, $filename); |
||
| 323 | |||
| 324 | return true; |
||
| 325 | } |
||
| 327 |