-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathAttributeMappingRulesQuery.php
58 lines (49 loc) · 1.44 KB
/
AttributeMappingRulesQuery.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
declare( strict_types=1 );
namespace Automattic\WooCommerce\GoogleListingsAndAds\DB\Query;
use Automattic\WooCommerce\GoogleListingsAndAds\DB\Query;
use Automattic\WooCommerce\GoogleListingsAndAds\DB\Table\AttributeMappingRulesTable;
use wpdb;
defined( 'ABSPATH' ) || exit;
/**
* Class defining the queries for the Attribute Mapping Rules Table
*
* @package Automattic\WooCommerce\GoogleListingsAndAds\DB\Query
*/
class AttributeMappingRulesQuery extends Query {
/**
* Query constructor.
*
* @param wpdb $wpdb
* @param AttributeMappingRulesTable $table
*/
public function __construct( wpdb $wpdb, AttributeMappingRulesTable $table ) {
parent::__construct( $wpdb, $table );
}
/**
* Sanitize a value for a given column before inserting it into the DB.
*
* @param string $column The column name.
* @param mixed $value The value to sanitize.
*
* @return mixed The sanitized value.
*/
protected function sanitize_value( string $column, $value ) {
if ( $column === 'attribute' || $column === 'source' ) {
return sanitize_text_field( $value );
}
if ( $column === 'categories' && is_null( $value ) ) {
return '';
}
return $value;
}
/**
* Gets a specific rule from Database
*
* @param int $rule_id The rule ID to get from Database
* @return array The rule from database
*/
public function get_rule( int $rule_id ): array {
return $this->where( 'id', $rule_id )->get_row();
}
}