PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.4.9
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.4.9
4.4.9 4.4.8 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 All 140 releases
← All changes | inc/curds/class-lp-section-curd.php +28 -201 4.1.7.3.2 → 4.4.9 View file →
@@ -57,9 +57,10 @@
57 57 $wpdb->learnpress_sections,
58 58 $insert_data,
59 59 array( '%d', '%s', '%d', '%s' )
60 60 );
61 - $section['section_id'] = $wpdb->insert_id;
61 + $section['section_id'] = $wpdb->insert_id;
62 + $section['section_order'] = $section_order_new;
62 63
63 64 do_action( 'lp/section/created', $section );
64 65 } catch ( Throwable $e ) {
65 66 error_log( $e->getMessage() );
@@ -134,45 +135,8 @@
134 135 // TODO: Implement duplicate() method.
135 136 }
136 137
137 138 /**
138 - * Remove all items from each section and delete course's sections.
139 - *
140 - * @return bool
141 - * @since 3.0.0
142 - * @editor tungnx
143 - * @modify 4.1.4.1 - comment - not use
144 - */
145 - /*public function clear() {
146 -
147 - $sections_ids = LP_Object_Cache::get( 'course-' . $this->course_id, 'learn-press/course-sections-ids' );
148 -
149 - if ( ! $sections_ids ) {
150 - return false;
151 - }
152 -
153 - global $wpdb;
154 -
155 - do_action( 'learn-press/before-clear-section', $this->course_id );
156 -
157 - // Remove all items in course's sections
158 - $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}learnpress_section_items WHERE %d AND section_id IN(" . join( ',', $sections_ids ) . ')', 1 ) );
159 - learn_press_reset_auto_increment( 'learnpress_section_items' );
160 - // delete sections ids cache
161 - // wp_cache_delete( 'course-' . $this->course_id, 'learn-press/course-sections-ids' );
162 -
163 - // delete sections in course
164 - $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}learnpress_sections WHERE section_course_id = %d", $this->course_id ) );
165 - learn_press_reset_auto_increment( 'learnpress_sections' );
166 - // delete sections cache
167 - // wp_cache_delete( 'course-' . $this->course_id, 'learn-press/course-sections' );
168 -
169 - LP_Course_Utils::set_cache_db_sections( $this->course_id, false );
170 -
171 - return true;
172 - }*/
173 -
174 - /**
175 139 * Load data from database.
176 140 *
177 141 * @param object $object
178 142 *
@@ -206,60 +170,8 @@
206 170 return $data;
207 171 }
208 172
209 173 /**
210 - * Get course sections ids and set data to cache.
211 - *
212 - * @return array
213 - * @since 3.0.0
214 - * @deprecated 4.1.6.3
215 - */
216 - /*public function read_sections_ids() {
217 -
218 - // Get course's sections id data from cache
219 - $ids = LP_Object_Cache::get( 'course-' . $this->course_id, 'learn-press/course-sections-ids' );
220 -
221 - if ( ! $ids ) {
222 - global $wpdb;
223 - // get sections id
224 - $ids = $wpdb->get_col( $wpdb->prepare( "SELECT section_id FROM {$wpdb->prefix}learnpress_sections WHERE section_course_id = %d", $this->course_id ) );
225 - // Set cache
226 - LP_Object_Cache::set( 'course-' . $this->course_id, $ids, 'learn-press/course-sections-ids' );
227 - }
228 -
229 - return $ids;
230 - }*/
231 -
232 - /**
233 - * Read all items from DB
234 - *
235 - * @param int $section_id
236 - *
237 - * @return array
238 - * @deprecated 4.1.6.9 Remove when release Addon Frontend Editor 4.0.1
239 - */
240 - public function read_items( $section_id ) {
241 - global $wpdb;
242 -
243 - $query = $wpdb->prepare(
244 - "
245 - SELECT item_id id
246 - FROM {$wpdb->learnpress_section_items} si
247 - INNER JOIN {$wpdb->learnpress_sections} s ON si.section_id = s.section_id
248 - INNER JOIN {$wpdb->posts} c ON c.ID = s.section_course_id
249 - INNER JOIN {$wpdb->posts} it ON it.ID = si.item_id
250 - WHERE s.section_id = %d
251 - AND it.post_status = %s
252 - ORDER BY si.item_order, si.section_item_id ASC
253 - ",
254 - $section_id,
255 - 'publish'
256 - );
257 -
258 - return $wpdb->get_col( $query );
259 - }
260 -
261 - /**
262 174 * Update sort sections.
263 175 *
264 176 * @param string[] $sections_new_order
265 177 *
@@ -268,13 +180,8 @@
268 180 */
269 181 public function update_sections_order( $sections_new_order ) {
270 182 global $wpdb;
271 183
272 - //$current_sections = LP_Course_Utils::get_cached_db_sections( $this->course_id );
273 - //$new_sections = array();
274 - //$course = learn_press_get_course( $this->course_id );
275 - //$sections_items = $course->get_full_sections_and_items_course();
276 -
277 184 $orders = array();
278 185
279 186 foreach ( $sections_new_order as $order_new => $section_id ) {
280 187 $order_new = $order_new + 1;
@@ -283,34 +190,10 @@
283 190 $wpdb->learnpress_sections,
284 191 array( 'section_order' => $order_new ),
285 192 array( 'section_id' => $section_id )
286 193 );
287 -
288 - // $this->get_section_items( $section_id );
289 194 }
290 195
291 - /*foreach ( $sections as $index => $section_id ) {
292 - $order = $index + 1;
293 -
294 - $orders[ $section_id ] = $order;
295 -
296 - $wpdb->update(
297 - $wpdb->learnpress_sections,
298 - array( 'section_order' => $order ),
299 - array( 'section_id' => $section_id )
300 - );
301 -
302 - foreach ( $current_sections as $current_section ) {
303 - if ( $current_section->section_id == $section_id ) {
304 - $new_sections[ $index ] = $current_section;
305 - }
306 - }
307 -
308 - $this->get_section_items( $section_id );
309 - }*/
310 -
311 - //LP_Course_Utils::set_cache_db_sections( $this->course_id, $new_sections );
312 -
313 196 return $orders;
314 197 }
315 198
316 199 /**
@@ -337,10 +220,8 @@
337 220 }
338 221 }
339 222 }
340 223
341 - // LP_Object_Cache::set( 'course-' . $this->course_id . '-' . $section_id, $return, 'learn-press/course-section-items' );
342 -
343 224 return $return;
344 225 }
345 226
346 227 /**
@@ -345,9 +226,9 @@
345 226
346 227 /**
347 228 * Create new section item and add to course.
348 229 *
349 - * @param int $section_id
230 + * @param int $section_id
350 231 * @param array $item
351 232 *
352 233 * @return array | bool
353 234 * @since 3.0.0
@@ -362,17 +243,21 @@
362 243
363 244 // $item = wp_parse_args( $item, array( 'title' => '', 'type' => '' ) );
364 245 $item = array_merge(
365 246 array(
366 - 'title' => '',
367 - 'type' => '',
247 + 'title' => '',
248 + 'type' => '',
249 + 'content' => '',
250 + 'status' => 'publish',
368 251 ),
369 252 $item
370 253 );
371 254
372 255 $args = array(
373 - 'title' => $item['title'],
374 - 'author' => $author_id,
256 + 'title' => $item['title'],
257 + 'author' => $author_id,
258 + 'content' => $item['content'],
259 + 'status' => $item['status'],
375 260 );
376 261
377 262 if ( ! empty( $item['id'] ) ) {
378 263 $item['old_id'] = $item ['id'];
@@ -403,9 +288,9 @@
403 288 /**
404 289 * Add list new items to section.
405 290 *
406 291 * @param $section_id
407 - * @param array $items
292 + * @param array $items
408 293 *
409 294 * @return array
410 295 */
411 296 public function add_items_section( $section_id, $items = array() ) {
@@ -418,8 +303,9 @@
418 303
419 304 $all_items = array_merge( $current_items, $items );
420 305 $result = array();
421 306 foreach ( $all_items as $key => $item ) {
307 + $key = $key + 1;
422 308 if ( ! isset( $item['id'] ) || ! isset( $item['type'] ) ) {
423 309 continue;
424 310 }
425 311
@@ -556,59 +442,8 @@
556 442 return $section;
557 443 }
558 444
559 445 /**
560 - * Update course final item.
561 - *
562 - * @return bool
563 - * @version 4.0.0
564 - * @deprecated 4.1.6.9
565 - */
566 - public function update_final_item() {
567 - _deprecated_function( __FUNCTION__, '4.1.6.9' );
568 - /*$sections = LP_Course_Utils::get_cached_db_sections( $this->course_id );
569 -
570 - if ( ! $sections ) {
571 - return false;
572 - }
573 -
574 - $last_section = end( $sections );
575 - $section_id = $last_section->section_id;
576 -
577 - // get last section items
578 - $section_items = LP_Object_Cache::get( 'course-' . $this->course_id . '-' . $section_id, 'learn-press/course-section-items' );
579 -
580 - $types = apply_filters( 'learn-press/post-types-support-assessment-by-final-item', array( LP_QUIZ_CPT ) );
581 -
582 - if ( $section_items ) {
583 - // last item in last section
584 - $final = end( $section_items );
585 -
586 - if ( is_array( $types ) && in_array( $final['type'], $types ) ) {
587 - update_post_meta( $this->course_id, '_' . substr_replace( $final['type'], '_final_', 2, 1 ), $final['id'] );
588 - $diff = array_diff( $types, array( $final['type'] ) );
589 - foreach ( $diff as $type ) {
590 - // delete all other final meta
591 - delete_post_meta( $this->course_id, '_' . substr_replace( $type, '_final_', 2, 1 ) );
592 - }
593 - } else {
594 - // for last item is not post type need check final item
595 - foreach ( $types as $type ) {
596 - delete_post_meta( $this->course_id, '_' . substr_replace( $type, '_final_', 2, 1 ) );
597 - }
598 - }
599 - } else {
600 - // for last section does not has any item
601 - foreach ( $types as $type ) {
602 - delete_post_meta( $this->course_id, '_' . substr_replace( $type, '_final_', 2, 1 ) );
603 - }
604 - }
605 -
606 - return true;*/
607 -
608 - }
609 -
610 - /**
611 446 * Remove section item.
612 447 *
613 448 * @param $section_id
614 449 * @param $item_id
@@ -640,17 +475,26 @@
640 475 * @param $section_id
641 476 * @param $items array
642 477 *
643 478 * @return array
644 - * @since 3.0.0
479 + * @since 3.0.1
645 480 */
646 481 public function update_section_items( $section_id, $items ) {
647 482 global $wpdb;
648 - $current_items = $this->get_section_items( $section_id );
649 483
650 484 foreach ( $items as $index => $item ) {
485 + $item_id = 0;
486 + $item_type = '';
487 + if ( is_object( $item ) ) {
488 + $item_id = $item->id ?? 0;
489 + $item_type = $item->post_type ?? '';
490 + } elseif ( is_array( $item ) ) {
491 + $item_id = $item['id'] ?? 0;
492 + $item_type = $item['type'] ?? '';
493 + }
494 +
651 495 $order = $index + 1;
652 - $exist = $this->item_section_exist( $section_id, $item['id'] );
496 + $exist = $this->item_section_exist( $section_id, $item_id );
653 497
654 498 if ( $exist ) {
655 499 $wpdb->update(
656 500 $wpdb->learnpress_section_items,
@@ -656,9 +500,9 @@
656 500 $wpdb->learnpress_section_items,
657 501 array( 'item_order' => $order ),
658 502 array(
659 503 'section_id' => $section_id,
660 - 'item_id' => $item['id'],
504 + 'item_id' => $item_id,
661 505 )
662 506 );
663 507 } else {
664 508 $wpdb->insert(
@@ -664,32 +508,15 @@
664 508 $wpdb->insert(
665 509 $wpdb->learnpress_section_items,
666 510 array(
667 511 'section_id' => $section_id,
668 - 'item_id' => $item['id'],
512 + 'item_id' => $item_id,
669 513 'item_order' => $order,
670 - 'item_type' => $item['type'],
514 + 'item_type' => $item_type,
671 515 )
672 516 );
673 517 }
674 518 }
675 -
676 - /**
677 - * Remove non-existent items.
678 - */
679 - /*foreach ( $current_items as $item ) {
680 - $find = $this->check_item_exist( $items, $item['id'] );
681 -
682 - if ( ! $find ) {
683 - $wpdb->delete(
684 - $wpdb->learnpress_section_items,
685 - array(
686 - 'section_id' => $section_id,
687 - 'item_id' => $item['id'],
688 - )
689 - );
690 - }
691 - }*/
692 519
693 520 return $items;
694 521 }
695 522