PluginProbe
Lasso Lite – Affiliate Link Manager & Product Displays / 112
Lasso Lite – Affiliate Link Manager & Product Displays v112
158 157 155 156 154 153 152 151 150 149 148 trunk 0.9.9 104 105 106 107 108 109 110 111 112 113 114 115 All 57 releases
simple-urls / models / class-url-details.php

class-url-details.php in Lasso Lite – Affiliate Link Manager & Product Displays 112, at models/class-url-details.php

102 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Models
4 *
5 * @package Models
6 */
7
8 namespace LassoLite\Models;
9
10 use LassoLite\Admin\Constant;
11 use LassoLite\Classes\Amazon_Api;
12
13 /**
14 * Model
15 */
16 class Url_Details extends Model {
17
18 const META_KEY_URL_WITHOUT_ARGUMENTS = 'url_without_arguments';
19 /**
20 * Table name
21 *
22 * @var string
23 */
24 protected $table = 'lasso_lite_url_details';
25
26 /**
27 * Columns of the table
28 *
29 * @var array
30 */
31 protected $columns = array(
32 'lasso_id',
33 'redirect_url',
34 'base_domain',
35 'is_opportunity',
36 'product_id',
37
38 'product_type',
39 );
40
41 /**
42 * Primary key of the table
43 *
44 * @var string
45 */
46 protected $primary_key = 'lasso_id';
47
48 /**
49 * Create table
50 */
51 public function create_table() {
52 $columns_sql = '
53 lasso_id bigint UNSIGNED NOT NULL,
54 redirect_url longtext NOT NULL,
55 base_domain varchar(128) NOT NULL,
56 is_opportunity tinyint NOT NULL DEFAULT 1,
57 product_id varchar(150),
58 product_type varchar(20),
59 PRIMARY KEY (lasso_id),
60 KEY ix_base_domain (base_domain)
61 ';
62 $sql = '
63 CREATE TABLE ' . $this->get_table_name() . ' (
64 ' . $columns_sql . '
65 ) ' . $this->get_charset_collate();
66
67 return $this->modify_table( $sql, $this->get_table_name() );
68 }
69
70 /**
71 * Get lasso url detail object by product id and product_type
72 *
73 * @param string $product_id Product id.
74 * @param string $product_type Product type. Default is amazon.
75 */
76 public static function get_by_product_id_and_type( $product_id, $product_type = Amazon_Api::PRODUCT_TYPE ) {
77 if ( ! $product_id ) {
78 return null;
79 }
80
81 $sql = '
82 SELECT lud.*
83 FROM ' . self::get_wp_table_name( 'posts' ) . ' AS wpp
84 LEFT JOIN ' . ( new self() )->get_table_name() . ' AS lud
85 ON wpp.id = lud.lasso_id
86 WHERE wpp.post_type = %s
87 AND lud.product_id = %s
88 AND lud.product_type = %s
89 AND wpp.post_status = "publish"
90 ';
91
92 $prepare = self::prepare( $sql, Constant::LASSO_POST_TYPE, $product_id, $product_type ); // phpcs:ignore
93 $result = self::get_row( $prepare );
94
95 if ( $result ) {
96 return ( new self() )->map_properties( $result );
97 }
98
99 return null;
100 }
101 }
102