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