| @@ -212,9 +212,9 @@ | ||
| 212 | 212 | * |
| 213 | 213 | * JS file edit-section-item.js: function addItemToSection call this method. |
| 214 | 214 | * |
| 215 | 215 | * @since 4.2.8.6 |
| 216 | - * @version 1.0.1 | |
| 216 | + * @version 1.0.2 | |
| 217 | 217 | */ |
| 218 | 218 | public static function create_item_add_to_section() { |
| 219 | 219 | $response = new LP_REST_Response(); |
| 220 | 220 | |
| @@ -234,8 +234,11 @@ | ||
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | $courseSectionItemModel = $courseSectionModel->create_item_and_add( $data ); |
| 237 | 237 | |
| 238 | + // Reload course model to get updated sections | |
| 239 | + $courseModel = CourseModel::find( $course_id, true ); | |
| 240 | + | |
| 238 | 241 | $response->data->section_item = $courseSectionItemModel; |
| 239 | 242 | |
| 240 | 243 | /** |
| 241 | 244 | * @var $itemModel PostModel |
| @@ -264,9 +267,9 @@ | ||
| 264 | 267 | * |
| 265 | 268 | * JS file edit-section-item.js: function addItemsSelectedToSection call this method. |
| 266 | 269 | * |
| 267 | 270 | * @since 4.2.8.6 |
| 268 | - * @version 1.0.1 | |
| 271 | + * @version 1.0.2 | |
| 269 | 272 | */ |
| 270 | 273 | public static function add_items_to_section() { |
| 271 | 274 | $response = new LP_REST_Response(); |
| 272 | 275 | |
| @@ -289,8 +292,11 @@ | ||
| 289 | 292 | if ( empty( $courseSectionItems ) ) { |
| 290 | 293 | throw new Exception( __( 'No items were added to the section', 'learnpress' ) ); |
| 291 | 294 | } |
| 292 | 295 | |
| 296 | + // Reload course model to get updated sections | |
| 297 | + $courseModel = CourseModel::find( $course_id, true ); | |
| 298 | + | |
| 293 | 299 | // Set context_data for Course Builder context |
| 294 | 300 | $is_course_builder = ! empty( $data['is_course_builder'] ); |
| 295 | 301 | AdminEditCurriculumTemplate::instance()->context_data = [ |
| 296 | 302 | 'is_course_builder' => $is_course_builder, |
| @@ -479,9 +485,9 @@ | ||
| 479 | 485 | * |
| 480 | 486 | * JS file edit-section-item.js: function updatePreviewItem call this method. |
| 481 | 487 | * |
| 482 | 488 | * @since 4.2.8.6 |
| 483 | - * @version 1.0.2 | |
| 489 | + * @version 1.0.3 | |
| 484 | 490 | */ |
| 485 | 491 | public static function update_item_preview() { |
| 486 | 492 | $response = new LP_REST_Response(); |
| 487 | 493 | |
| @@ -486,12 +492,12 @@ | ||
| 486 | 492 | $response = new LP_REST_Response(); |
| 487 | 493 | |
| 488 | 494 | try { |
| 489 | 495 | $data = self::check_valid(); |
| 490 | - $course_id = $data['course_id'] ?? 0; | |
| 491 | - $item_id = $data['item_id'] ?? 0; | |
| 492 | - $item_type = $data['item_type'] ?? ''; | |
| 493 | - $enable_preview = $data['enable_preview'] ?? 0; | |
| 496 | + $course_id = absint( $data['course_id'] ?? 0 ); | |
| 497 | + $item_id = absint( $data['item_id'] ?? 0 ); | |
| 498 | + $item_type = LP_Helper::sanitize_params_submitted( $data['item_type'] ?? '' ); | |
| 499 | + $enable_preview = absint( $data['enable_preview'] ?? 0 ); | |
| 494 | 500 | |
| 495 | 501 | $courseModel = CourseModel::find( $course_id, true ); |
| 496 | 502 | if ( ! $courseModel ) { |
| 497 | 503 | throw new Exception( __( 'Course not found', 'learnpress' ) ); |
| @@ -509,8 +515,9 @@ | ||
| 509 | 515 | throw new Exception( __( 'Item not found', 'learnpress' ) ); |
| 510 | 516 | } |
| 511 | 517 | |
| 512 | 518 | $itemModel->set_preview( $enable_preview == 1 ); |
| 519 | + $itemModel->save(); | |
| 513 | 520 | |
| 514 | 521 | // Save course to update preview data of item in the curriculum. |
| 515 | 522 | $coursePostModel = new CoursePostModel( $courseModel ); |
| 516 | 523 | $coursePostModel->save(); |