Conditions | 4 |
Paths | 8 |
Total Lines | 334 |
Code Lines | 210 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 1 | 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 |
||
281 | protected function setupCreateOperation() |
||
282 | { |
||
283 | if (config('app.currency_position') === 'before') { |
||
284 | $currency = ['prefix' => config('app.currency_symbol')]; |
||
285 | } else { |
||
286 | $currency = ['suffix' => config('app.currency_symbol')]; |
||
287 | } |
||
288 | |||
289 | CRUD::addFields([ |
||
290 | [ |
||
291 | // RYTHM |
||
292 | 'label' => __('Rhythm'), |
||
293 | 'type' => 'select', |
||
294 | 'name' => 'rhythm_id', |
||
295 | 'entity' => 'rhythm', |
||
296 | 'attribute' => 'name', |
||
297 | 'model' => Rhythm::class, |
||
298 | 'tab' => __('Course info'), |
||
299 | ], |
||
300 | |||
301 | [ |
||
302 | // LEVEL |
||
303 | 'label' => __('Level'), |
||
304 | 'type' => 'select', |
||
305 | 'name' => 'level_id', |
||
306 | 'entity' => 'level', |
||
307 | 'attribute' => 'name', |
||
308 | 'model' => Level::class, |
||
309 | 'tab' => __('Course info'), |
||
310 | ], |
||
311 | |||
312 | [ |
||
313 | 'name' => 'name', |
||
314 | 'label' => __('Name'), |
||
315 | 'tab' => __('Course info'), |
||
316 | ], |
||
317 | |||
318 | array_merge([ |
||
319 | 'name' => 'price', |
||
320 | 'label' => __('Price'), |
||
321 | 'tab' => __('Course info'), |
||
322 | 'type' => 'number', |
||
323 | ], $currency), |
||
324 | ]); |
||
325 | |||
326 | if (config('invoicing.price_categories_enabled')) { |
||
327 | CRUD::addFields([ |
||
328 | array_merge([ |
||
329 | 'name' => 'price_b', |
||
330 | 'label' => __('Price B'), |
||
331 | 'tab' => __('Course info'), |
||
332 | 'type' => 'number', |
||
333 | ], $currency), |
||
334 | |||
335 | array_merge([ |
||
336 | 'name' => 'price_c', |
||
337 | 'label' => __('PriceC'), |
||
338 | 'tab' => __('Course info'), |
||
339 | 'type' => 'number', |
||
340 | ], $currency), |
||
341 | ]); |
||
342 | } |
||
343 | |||
344 | CRUD::addFields([ |
||
345 | [ |
||
346 | 'name' => 'volume', |
||
347 | 'label' => __('Presential volume'), |
||
348 | 'suffix' => 'h', |
||
349 | 'tab' => __('Course info'), |
||
350 | ], |
||
351 | |||
352 | [ |
||
353 | 'name' => 'remote_volume', |
||
354 | 'label' => __('Remote volume'), |
||
355 | 'suffix' => 'h', |
||
356 | 'tab' => __('Course info'), |
||
357 | ], |
||
358 | |||
359 | [ |
||
360 | 'name' => 'spots', |
||
361 | 'label' => __('Spots'), |
||
362 | 'tab' => __('Course info'), |
||
363 | ], |
||
364 | |||
365 | [ |
||
366 | 'name' => 'exempt_attendance', |
||
367 | 'label' => __('Exempt Attendance'), |
||
368 | 'type' => 'checkbox', |
||
369 | 'tab' => __('Course info'), |
||
370 | ], |
||
371 | |||
372 | [ // repeatable |
||
373 | 'name' => 'sublevels', |
||
374 | 'label' => __('Course sublevels'), |
||
375 | 'type' => 'repeatable', |
||
376 | 'fields' => [ |
||
377 | [ |
||
378 | 'name' => 'name', |
||
379 | // The db column name |
||
380 | 'label' => __('Name'), |
||
381 | ], |
||
382 | [ |
||
383 | 'name' => 'level_id', |
||
384 | 'label' => __('Level'), |
||
385 | 'type' => 'select', |
||
386 | 'entity' => 'level', |
||
387 | 'attribute' => 'name', |
||
388 | 'model' => Level::class, |
||
389 | 'allows_null' => true, |
||
390 | 'wrapper' => ['class' => 'form-group col-md-4'], |
||
391 | ], |
||
392 | |||
393 | array_merge([ |
||
394 | 'name' => 'price', |
||
395 | // The db column name |
||
396 | 'label' => __('Price'), |
||
397 | 'type' => 'number', |
||
398 | ], $currency), |
||
399 | |||
400 | [ |
||
401 | 'name' => 'volume', |
||
402 | // The db column name |
||
403 | 'label' => __('Presential volume'), |
||
404 | 'suffix' => 'h', |
||
405 | ], |
||
406 | |||
407 | [ |
||
408 | 'name' => 'remote_volume', |
||
409 | // The db column name |
||
410 | 'label' => __('Remote volume'), |
||
411 | 'suffix' => 'h', |
||
412 | ], |
||
413 | |||
414 | [ |
||
415 | 'name' => 'start_date', |
||
416 | 'type' => 'date', |
||
417 | 'label' => __('Start Date'), |
||
418 | 'wrapper' => ['class' => 'form-group col-md-4'], |
||
419 | ], |
||
420 | [ |
||
421 | 'name' => 'end_date', |
||
422 | 'type' => 'date', |
||
423 | 'label' => __('End Date'), |
||
424 | 'wrapper' => ['class' => 'form-group col-md-4'], |
||
425 | ], |
||
426 | ], |
||
427 | 'tab' => __('Course sublevels'), |
||
428 | 'init_rows' => 0, |
||
429 | |||
430 | ], |
||
431 | ]); |
||
432 | |||
433 | if (config('lms.sync_to') == 'apolearn') { |
||
434 | CRUD::addField([ |
||
435 | 'name' => 'sync_to_lms', |
||
436 | 'label' => __('Sync to LMS'), |
||
437 | 'type' => 'checkbox', |
||
438 | 'tab' => __('Course info'), |
||
439 | ]); |
||
440 | } |
||
441 | |||
442 | CRUD::addFields([ |
||
443 | [ |
||
444 | 'name' => 'color', |
||
445 | 'label' => __('Color'), |
||
446 | 'tab' => __('Course info'), |
||
447 | 'type' => 'color_picker', |
||
448 | ], |
||
449 | |||
450 | [ |
||
451 | // TEACHER |
||
452 | 'label' => __('Teacher'), |
||
453 | 'type' => 'select', |
||
454 | 'name' => 'teacher_id', |
||
455 | 'entity' => 'teacher', |
||
456 | 'attribute' => 'name', |
||
457 | 'model' => Teacher::class, |
||
458 | 'tab' => __('Resources'), |
||
459 | ], |
||
460 | |||
461 | [ |
||
462 | // ROOM |
||
463 | 'label' => __('Room'), |
||
464 | 'type' => 'select', |
||
465 | 'name' => 'room_id', |
||
466 | 'entity' => 'room', |
||
467 | 'attribute' => 'name', |
||
468 | 'model' => Room::class, |
||
469 | 'tab' => __('Resources'), |
||
470 | ], |
||
471 | |||
472 | [ |
||
473 | // RYTHM |
||
474 | 'label' => __('Campus'), |
||
475 | 'type' => 'hidden', |
||
476 | 'name' => 'campus_id', |
||
477 | 'value' => 1, |
||
478 | ], |
||
479 | |||
480 | [ |
||
481 | // n-n relationship (with pivot table) |
||
482 | 'label' => __('Books'), |
||
483 | 'type' => 'select_multiple', |
||
484 | 'name' => 'books', |
||
485 | 'entity' => 'books', |
||
486 | 'attribute' => 'name', |
||
487 | 'model' => Book::class, |
||
488 | 'pivot' => true, |
||
489 | // on create&update, do you need to add/delete pivot table entries? |
||
490 | 'tab' => __('Pedagogy'), |
||
491 | ], |
||
492 | |||
493 | [ |
||
494 | 'label' => __('Evaluation method'), |
||
495 | 'type' => 'select2', |
||
496 | 'name' => 'evaluationType', |
||
497 | 'entity' => 'evaluationType', |
||
498 | 'attribute' => 'name', |
||
499 | 'model' => EvaluationType::class, |
||
500 | 'tab' => __('Pedagogy'), |
||
501 | ], |
||
502 | |||
503 | [ |
||
504 | // PERIOD |
||
505 | 'label' => __('Period'), |
||
506 | 'type' => 'select', |
||
507 | 'name' => 'period_id', |
||
508 | 'entity' => 'period', |
||
509 | 'attribute' => 'name', |
||
510 | 'model' => Period::class, |
||
511 | 'tab' => __('Schedule'), |
||
512 | 'default' => Period::get_enrollments_period()->id, |
||
513 | ], |
||
514 | |||
515 | [ |
||
516 | 'name' => 'start_date', |
||
517 | 'label' => __('Start Date'), |
||
518 | 'type' => 'date', |
||
519 | 'tab' => __('Schedule'), |
||
520 | 'default' => Period::get_enrollments_period()->start, |
||
521 | |||
522 | ], |
||
523 | |||
524 | [ |
||
525 | 'name' => 'end_date', |
||
526 | 'label' => __('End Date'), |
||
527 | 'type' => 'date', |
||
528 | 'tab' => __('Schedule'), |
||
529 | 'default' => Period::get_enrollments_period()->end, |
||
530 | ], |
||
531 | |||
532 | [ // repeatable |
||
533 | 'name' => 'times', |
||
534 | 'label' => __('Course Schedule'), |
||
535 | 'type' => 'repeatable', |
||
536 | 'fields' => [ |
||
537 | [ |
||
538 | 'name' => 'day', |
||
539 | 'label' => __('Day'), |
||
540 | 'type' => 'select_from_array', |
||
541 | 'options' => [ |
||
542 | 0 => __('Sunday'), |
||
543 | 1 => __('Monday'), |
||
544 | 2 => __('Tuesday'), |
||
545 | 3 => __('Wednesday'), |
||
546 | 4 => __('Thursday'), |
||
547 | 5 => __('Friday'), |
||
548 | 6 => __('Saturday'), |
||
549 | ], |
||
550 | 'allows_null' => false, |
||
551 | 'default' => 1, |
||
552 | 'wrapper' => ['class' => 'form-group col-md-4'], |
||
553 | ], |
||
554 | [ |
||
555 | 'name' => 'start', |
||
556 | 'type' => 'time', |
||
557 | 'label' => __('Start'), |
||
558 | 'wrapper' => ['class' => 'form-group col-md-4'], |
||
559 | ], |
||
560 | [ |
||
561 | 'name' => 'end', |
||
562 | 'type' => 'time', |
||
563 | 'label' => __('End'), |
||
564 | 'wrapper' => ['class' => 'form-group col-md-4'], |
||
565 | ], |
||
566 | ], |
||
567 | 'init_rows' => 0, |
||
568 | 'tab' => __('Schedule'), |
||
569 | ], |
||
570 | |||
571 | [ |
||
572 | 'name' => 'remoteevents', |
||
573 | 'label' => __('Remote events'), |
||
574 | 'type' => 'repeatable', |
||
575 | 'fields' => [ |
||
576 | [ |
||
577 | 'name' => 'name', |
||
578 | 'type' => 'text', |
||
579 | 'label' => __('Name'), |
||
580 | 'wrapper' => ['class' => 'form-group col-md-6'], |
||
581 | ], |
||
582 | [ |
||
583 | 'name' => 'worked_hours', |
||
584 | 'type' => 'number', |
||
585 | 'attributes' => ['step' => '0.25'], |
||
586 | 'suffix' => 'h', |
||
587 | 'label' => __('Weekly Volume'), |
||
588 | 'wrapper' => ['class' => 'form-group col-md-6'], |
||
589 | ], |
||
590 | ], |
||
591 | 'tab' => __('Schedule'), |
||
592 | 'init_rows' => 0, |
||
593 | ], |
||
594 | |||
595 | [ // view |
||
596 | 'name' => 'custom-ajax-button', |
||
597 | 'type' => 'view', |
||
598 | 'view' => 'courses/schedule-preset-alert', |
||
599 | 'tab' => __('Schedule'), |
||
600 | ], |
||
601 | |||
602 | [ // select_from_array |
||
603 | 'name' => 'schedulepreset', |
||
604 | 'label' => __('Schedule Preset'), |
||
605 | 'type' => 'select_from_array', |
||
606 | 'options' => array_column(SchedulePreset::all()->toArray(), 'name', 'presets'), |
||
607 | 'allows_null' => true, |
||
608 | 'tab' => __('Schedule'), |
||
609 | ], |
||
610 | |||
611 | ]); |
||
612 | |||
613 | // add asterisk for fields that are required in CourseRequest |
||
614 | CRUD::setValidation(CourseRequest::class); |
||
615 | } |
||
986 |