update
This commit is contained in:
@@ -7,6 +7,7 @@ class Products
|
||||
return in_array( (string) $field, [
|
||||
'custom_label_4',
|
||||
'custom_label_3',
|
||||
'custom_label_1',
|
||||
'title',
|
||||
'description',
|
||||
'google_product_category',
|
||||
@@ -486,7 +487,7 @@ class Products
|
||||
$sql .= ' AND ag.status = \'active\'';
|
||||
}
|
||||
|
||||
static public function get_products( $client_id, $search, $limit, $start, $order_name, $order_dir, $campaign_id = 0, $ad_group_id = 0, $custom_label_4 = '' )
|
||||
static public function get_products( $client_id, $search, $limit, $start, $order_name, $order_dir, $campaign_id = 0, $ad_group_id = 0, $custom_label_4 = '', $custom_label_1 = '' )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
@@ -499,7 +500,7 @@ class Products
|
||||
'campaign_name' => 'campaign_name',
|
||||
'ad_group_name' => 'ad_group_name',
|
||||
'name' => 'name',
|
||||
'custom_label_3' => 'custom_label_3',
|
||||
'custom_label_1' => 'custom_label_1',
|
||||
'impressions' => 'impressions',
|
||||
'impressions_30' => 'impressions_30',
|
||||
'clicks' => 'clicks',
|
||||
@@ -520,7 +521,7 @@ class Products
|
||||
p.id AS product_id,
|
||||
p.offer_id,
|
||||
p.min_roas,
|
||||
COALESCE( NULLIF( TRIM( p.custom_label_3 ), \'\' ), \'\' ) AS custom_label_3,
|
||||
COALESCE( NULLIF( TRIM( p.custom_label_1 ), \'\' ), \'\' ) AS custom_label_1,
|
||||
pa.campaign_id AS campaign_id,
|
||||
COALESCE( NULLIF( TRIM( c.campaign_name ), \'\' ), \'--- brak kampanii ---\' ) AS campaign_name,
|
||||
CASE
|
||||
@@ -565,6 +566,7 @@ class Products
|
||||
OR p.title LIKE :search
|
||||
OR p.offer_id LIKE :search
|
||||
OR p.custom_label_4 LIKE :search
|
||||
OR p.custom_label_1 LIKE :search
|
||||
OR c.campaign_name LIKE :search
|
||||
OR ag.ad_group_name LIKE :search
|
||||
)';
|
||||
@@ -577,13 +579,19 @@ class Products
|
||||
$params[':custom_label_4'] = '%' . $custom_label_4 . '%';
|
||||
}
|
||||
|
||||
$sql .= ' GROUP BY p.id, p.offer_id, p.min_roas, p.custom_label_3, p.name, p.title, pa.campaign_id, c.campaign_name, pa.ad_group_id, ag.ad_group_name';
|
||||
if ( $custom_label_1 !== '' )
|
||||
{
|
||||
$sql .= ' AND p.custom_label_1 LIKE :custom_label_1';
|
||||
$params[':custom_label_1'] = '%' . $custom_label_1 . '%';
|
||||
}
|
||||
|
||||
$sql .= ' GROUP BY p.id, p.offer_id, p.min_roas, p.custom_label_1, p.name, p.title, pa.campaign_id, c.campaign_name, pa.ad_group_id, ag.ad_group_name';
|
||||
$sql .= ' ORDER BY ' . $order_sql . ' ' . $order_dir . ', product_id DESC LIMIT ' . $start . ', ' . $limit;
|
||||
|
||||
return $mdb -> query( $sql, $params ) -> fetchAll( \PDO::FETCH_ASSOC );
|
||||
}
|
||||
|
||||
public static function get_roas_bounds( int $client_id, ?string $search = null, int $campaign_id = 0, int $ad_group_id = 0, string $custom_label_4 = '' ): array
|
||||
public static function get_roas_bounds( int $client_id, ?string $search = null, int $campaign_id = 0, int $ad_group_id = 0, string $custom_label_4 = '', string $custom_label_1 = '' ): array
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
@@ -612,6 +620,7 @@ class Products
|
||||
OR p.title LIKE :search
|
||||
OR p.offer_id LIKE :search
|
||||
OR p.custom_label_4 LIKE :search
|
||||
OR p.custom_label_1 LIKE :search
|
||||
OR c.campaign_name LIKE :search
|
||||
OR ag.ad_group_name LIKE :search
|
||||
)';
|
||||
@@ -624,6 +633,12 @@ class Products
|
||||
$params[':custom_label_4'] = '%' . $custom_label_4 . '%';
|
||||
}
|
||||
|
||||
if ( $custom_label_1 !== '' )
|
||||
{
|
||||
$sql .= ' AND p.custom_label_1 LIKE :custom_label_1';
|
||||
$params[':custom_label_1'] = '%' . $custom_label_1 . '%';
|
||||
}
|
||||
|
||||
$row = $mdb -> query( $sql, $params ) -> fetch( \PDO::FETCH_ASSOC );
|
||||
|
||||
return [
|
||||
@@ -656,7 +671,7 @@ class Products
|
||||
return $total_conversions / $total_clicks;
|
||||
}
|
||||
|
||||
static public function get_records_total_products( $client_id, $search, $campaign_id = 0, $ad_group_id = 0, $custom_label_4 = '' )
|
||||
static public function get_records_total_products( $client_id, $search, $campaign_id = 0, $ad_group_id = 0, $custom_label_4 = '', $custom_label_1 = '' )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
@@ -679,6 +694,7 @@ class Products
|
||||
OR p.title LIKE :search
|
||||
OR p.offer_id LIKE :search
|
||||
OR p.custom_label_4 LIKE :search
|
||||
OR p.custom_label_1 LIKE :search
|
||||
OR c.campaign_name LIKE :search
|
||||
OR ag.ad_group_name LIKE :search
|
||||
)';
|
||||
@@ -691,6 +707,12 @@ class Products
|
||||
$params[':custom_label_4'] = '%' . $custom_label_4 . '%';
|
||||
}
|
||||
|
||||
if ( $custom_label_1 !== '' )
|
||||
{
|
||||
$sql .= ' AND p.custom_label_1 LIKE :custom_label_1';
|
||||
$params[':custom_label_1'] = '%' . $custom_label_1 . '%';
|
||||
}
|
||||
|
||||
$sql .= ' GROUP BY p.id, pa.campaign_id, pa.ad_group_id
|
||||
) AS grouped_rows';
|
||||
|
||||
@@ -760,6 +782,30 @@ class Products
|
||||
return $rows ?: [];
|
||||
}
|
||||
|
||||
static public function get_distinct_custom_label_1( $client_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$client_id = (int) $client_id;
|
||||
|
||||
if ( $client_id <= 0 )
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
$rows = $mdb -> query(
|
||||
"SELECT DISTINCT p.custom_label_1
|
||||
FROM products p
|
||||
WHERE p.client_id = :client_id
|
||||
AND p.custom_label_1 IS NOT NULL
|
||||
AND p.custom_label_1 != ''
|
||||
ORDER BY p.custom_label_1 ASC",
|
||||
[ ':client_id' => $client_id ]
|
||||
) -> fetchAll( \PDO::FETCH_COLUMN );
|
||||
|
||||
return $rows ?: [];
|
||||
}
|
||||
|
||||
static public function get_product_data( $product_id, $field )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
Reference in New Issue
Block a user