PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.1.7.1
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.1.7.1
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 4.2.0 All 139 releases
learnpress / inc / databases / class-lp-section-items-db.php

class-lp-section-items-db.php in LearnPress – WordPress LMS Plugin for Create and Sell Online Courses 4.1.7.1, at inc/databases/class-lp-section-items-db.php

106 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit; // Exit if accessed directly
5 }
6
7 /**
8 * Class LP_Section_Items_DB
9 */
10
11 class LP_Section_Items_DB extends LP_Database {
12 public static $_instance;
13
14 public function __construct() {
15 parent::__construct();
16 }
17
18 public static function getInstance() {
19 if ( is_null( self::$_instance ) ) {
20 self::$_instance = new self();
21 }
22
23 return self::$_instance;
24 }
25
26 /**
27 * Get section items
28 *
29 * @throws Exception
30 * @since 4.1.6
31 * @version 1.0.0
32 * @return array|null|int|string
33 */
34 public function get_section_items( LP_Section_Items_Filter $filter ) {
35 $default_fields = $this->get_cols_of_table( $this->tb_lp_section_items );
36 $filter->fields = array_merge( $default_fields, $filter->fields );
37
38 if ( empty( $filter->collection ) ) {
39 $filter->collection = $this->tb_lp_section_items;
40 }
41
42 if ( empty( $filter->collection_alias ) ) {
43 $filter->collection_alias = 'si';
44 }
45
46 return $this->execute( $filter );
47 }
48
49 /**
50 * Update table
51 *
52 * @throws Exception
53 */
54 public function update( LP_Section_Items_Filter $filter ) {
55 $filter->collection = $this->tb_lp_section_items;
56 $this->update_execute( $filter );
57 }
58
59 /**
60 * Delete items on section
61 *
62 * @param LP_Section_Items_Filter $filter
63 *
64 * @return bool|int|mysqli_result|resource|null
65 * @throws Exception
66 */
67 public function delete_items( LP_Section_Items_Filter $filter ) {
68 if ( empty( $filter->item_ids ) ) {
69 return 1;
70 }
71
72 $where = 'WHERE 1=1 ';
73
74 $where .= $this->wpdb->prepare(
75 'AND item_id IN(' . LP_Helper::db_format_array( $filter->item_ids, '%d' ) . ')',
76 $filter->item_ids
77 );
78
79 $result = $this->wpdb->query(
80 "DELETE FROM $this->tb_lp_section_items
81 $where
82 "
83 );
84
85 $this->check_execute_has_error();
86
87 return $result;
88 }
89
90 public function get_last_number_order( int $section_id = 0 ): int {
91 $query = $this->wpdb->prepare(
92 "SELECT MAX(item_order)
93 FROM $this->tb_lp_section_items
94 WHERE section_id = %d",
95 $section_id
96 );
97
98 $number_order = intval( $this->wpdb->get_var( $query ) );
99
100 $this->check_execute_has_error();
101
102 return $number_order;
103 }
104 }
105
106