PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / trunk
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses vtrunk
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
learnpress / inc / Databases / Order / LPOrderItemsDB.php

LPOrderItemsDB.php in LearnPress – WordPress LMS Plugin for Create and Sell Online Courses trunk, at inc/Databases/Order/LPOrderItemsDB.php

76 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace LearnPress\Databases\Order;
4
5 use Exception;
6 use LearnPress\Databases\DataBase;
7 use LearnPress\Filters\Order\OrderItemsFilter;
8
9 defined( 'ABSPATH' ) || exit();
10
11 /**
12 * Class LPOrderItemsDB
13 *
14 * @author tungnx
15 * @since 4.3.2
16 * @version 1.0.0
17 */
18 class LPOrderItemsDB extends DataBase {
19 private static $_instance;
20
21 protected function __construct() {
22 parent::__construct();
23 }
24
25 public static function getInstance() {
26 if ( is_null( self::$_instance ) ) {
27 self::$_instance = new self();
28 }
29
30 return self::$_instance;
31 }
32
33 /**
34 * Get order items by filter
35 *
36 * @throws Exception
37 * @since 4.3.2
38 * @version 1.0.0
39 */
40 public function get_items( OrderItemsFilter $filter, int &$total_rows = 0 ) {
41 $default_fields = $filter->all_fields;
42 $filter->fields = array_merge( $default_fields, $filter->fields );
43
44 if ( empty( $filter->collection ) ) {
45 $filter->collection = $this->tb_lp_order_items;
46 }
47
48 if ( empty( $filter->collection_alias ) ) {
49 $filter->collection_alias = 'oi';
50 }
51
52 $ca = $filter->collection_alias;
53
54 foreach ( $filter->fields as $k => $field ) {
55 $filter->fields[ $k ] = "$ca.$field";
56 }
57
58 if ( isset( $filter->order_item_id ) ) {
59 $filter->where[] = $this->wpdb->prepare( "AND $ca.order_item_id = %d", $filter->order_item_id );
60 }
61
62 if ( isset( $filter->order_id ) ) {
63 $filter->where[] = $this->wpdb->prepare( "AND $ca.order_id = %d", $filter->order_id );
64 }
65
66 if ( isset( $filter->item_id ) ) {
67 $filter->where[] = $this->wpdb->prepare( "AND $ca.item_id = %d", $filter->item_id );
68 }
69
70 if ( isset( $filter->item_type ) ) {
71 $filter->where[] = $this->wpdb->prepare( "AND $ca.item_type = %s", $filter->item_type );
72 }
73 return $this->execute( $filter, $total_rows );
74 }
75 }
76