PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.4.7
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.4.7
4.4.7 4.4.6 4.4.5 4.4.4 4.4.3 4.4.2 4.4.1 4.4.0 4.3.9.1 4.3.9 4.3.8 4.3.7 4.1.6.9 4.1.6.9.1 4.1.6.9.2 4.1.6.9.3 4.1.6.9.4 4.1.7 4.1.7.1 4.1.7.2 4.1.7.3 4.1.7.3.1 4.1.7.3.2 4.2.0 4.2.1 All 138 releases
← All changes | inc/Models/CourseModel.php +30 -12 4.4.34.4.7 View file →
@@ -507,29 +507,46 @@
507 507
508 508 /**
509 509 * Get section id of item
510 510 *
511 - * @param int $item_id
511 + * A curriculum item's identity is the (item_id, item_type) pair, not the numeric
512 + * ID alone: once items live in per-type tables a lesson and a quiz can share the
513 + * same ID. Pass $item_type to match the composite identity.
512 514 *
515 + * @param int $item_id
516 + * @param string $item_type Optional. Curriculum item type to match as well. Empty
517 + * keeps the legacy ID-only match for callers not yet migrated.
518 + *
513 519 * @return int
514 520 * @since 4.2.8
515 - * @version 1.0.0
521 + * @version 1.1.0
516 522 */
517 - public function get_section_of_item( int $item_id ): int {
518 - $section_id = 0;
523 + public function get_section_of_item( int $item_id, string $item_type = '' ): int {
524 + $section_items = $this->get_section_items();
519 525
520 - $section_items = $this->get_section_items();
521 526 foreach ( $section_items as $section ) {
527 + if ( empty( $section->items ) ) {
528 + continue;
529 + }
530 +
522 531 foreach ( $section->items as $item ) {
523 532 $item_id_check = (int) ( $item->item_id ?? $item->id ?? 0 );
524 - if ( $item_id_check === $item_id ) {
525 - $section_id = $section->section_id ?? $section->id ?? 0;
526 - break;
533 + if ( $item_id_check !== $item_id ) {
534 + continue;
527 535 }
536 +
537 + if ( '' !== $item_type ) {
538 + $item_type_check = (string) ( $item->item_type ?? $item->type ?? '' );
539 + if ( $item_type_check !== $item_type ) {
540 + continue;
541 + }
542 + }
543 +
544 + return (int) ( $section->section_id ?? $section->id ?? 0 );
528 545 }
529 546 }
530 547
531 - return (int) $section_id;
548 + return 0;
532 549 }
533 550
534 551 /**
535 552 * Get course Evaluation type.
@@ -1265,16 +1282,17 @@
1265 1282 * @param bool $check_assign | default true check assign item to course
1266 1283 *
1267 1284 * @return mixed|false|null|WP_Post|PostModel
1268 1285 * @since v4.2.7.6
1269 - * @version 1.0.2
1286 + * @version 1.0.3
1270 1287 */
1271 1288 public function get_item_model( int $item_id, string $item_type, bool $check_assign = true ) {
1272 1289 try {
1273 1290 $item = false;
1274 1291
1275 - // Find item has in section
1276 - $section_id = $this->get_section_of_item( $item_id );
1292 + // Find item has in section. Match the composite (item_id, item_type) identity,
1293 + // so a quiz ID can never resolve through a lesson request and vice versa.
1294 + $section_id = $this->get_section_of_item( $item_id, $item_type );
1277 1295 if ( $check_assign && ! $section_id ) {
1278 1296 return $item;
1279 1297 }
1280 1298