update
This commit is contained in:
@@ -965,6 +965,10 @@ class Products
|
||||
|
||||
$db_results = \factory\Products::get_products( $client_id, $search, $limit, $start, $order_name, $order_dir, $campaign_id, $ad_group_id, $filter_cl4, $filter_cl1 );
|
||||
$recordsTotal = \factory\Products::get_records_total_products( $client_id, $search, $campaign_id, $ad_group_id, $filter_cl4, $filter_cl1 );
|
||||
$product_ids = array_values( array_unique( array_filter( array_map( function( $row ) {
|
||||
return (int) ( $row['product_id'] ?? 0 );
|
||||
}, (array) $db_results ) ) ) );
|
||||
$breakdown_map = \factory\Products::get_products_scope_breakdown( $client_id, $product_ids, $campaign_id, $ad_group_id, $search, $filter_cl4, $filter_cl1 );
|
||||
|
||||
// Sredni CR konta — do obliczenia progu klikniec
|
||||
$account_cr = \factory\Products::get_account_conversion_rate( (int) $client_id );
|
||||
@@ -977,11 +981,13 @@ class Products
|
||||
|
||||
foreach ( $db_results as $row )
|
||||
{
|
||||
$product_id = (int) ( $row['product_id'] ?? 0 );
|
||||
$breakdown_rows = (array) ( $breakdown_map[ $product_id ] ?? [] );
|
||||
$custom_class = '';
|
||||
$custom_label_4 = \factory\Products::get_product_data( $row['product_id'], 'custom_label_4' );
|
||||
$custom_label_1 = \factory\Products::get_product_data( $row['product_id'], 'custom_label_1' );
|
||||
$custom_name = \factory\Products::get_product_data( $row['product_id'], 'title' );
|
||||
$product_url = trim( (string) \factory\Products::get_product_data( $row['product_id'], 'product_url' ) );
|
||||
$custom_label_4 = \factory\Products::get_product_data( $product_id, 'custom_label_4' );
|
||||
$custom_label_1 = \factory\Products::get_product_data( $product_id, 'custom_label_1' );
|
||||
$custom_name = \factory\Products::get_product_data( $product_id, 'title' );
|
||||
$product_url = trim( (string) \factory\Products::get_product_data( $product_id, 'product_url' ) );
|
||||
|
||||
if ( $custom_name )
|
||||
{
|
||||
@@ -1074,29 +1080,56 @@ class Products
|
||||
|
||||
$history_campaign_id = (int) ( $row['history_campaign_id'] ?? 0 );
|
||||
$history_ad_group_id = (int) ( $row['history_ad_group_id'] ?? 0 );
|
||||
$breakdown_for_view = [];
|
||||
|
||||
if ( $history_campaign_id <= 0 )
|
||||
if ( $history_campaign_id <= 0 && !empty( $breakdown_rows ) )
|
||||
{
|
||||
$history_campaign_id = (int) ( $row['campaign_id'] ?? 0 );
|
||||
$history_campaign_id = (int) ( $breakdown_rows[0]['campaign_id'] ?? 0 );
|
||||
}
|
||||
|
||||
if ( $history_ad_group_id <= 0 )
|
||||
if ( $history_ad_group_id <= 0 && !empty( $breakdown_rows ) )
|
||||
{
|
||||
$history_ad_group_id = (int) ( $row['ad_group_id'] ?? 0 );
|
||||
$history_ad_group_id = (int) ( $breakdown_rows[0]['ad_group_id'] ?? 0 );
|
||||
}
|
||||
|
||||
foreach ( $breakdown_rows as $breakdown_row )
|
||||
{
|
||||
$breakdown_for_view[] = [
|
||||
'campaign_name' => (string) ( $breakdown_row['campaign_name'] ?? '' ),
|
||||
'ad_group_name' => (string) ( $breakdown_row['ad_group_name'] ?? '' ),
|
||||
'impressions' => (int) ( $breakdown_row['impressions'] ?? 0 ),
|
||||
'impressions_30' => (int) ( $breakdown_row['impressions_30'] ?? 0 ),
|
||||
'clicks' => (int) ( $breakdown_row['clicks'] ?? 0 ),
|
||||
'clicks_30' => (int) ( $breakdown_row['clicks_30'] ?? 0 ),
|
||||
'ctr' => (float) ( $breakdown_row['ctr'] ?? 0 ),
|
||||
'cost' => (float) ( $breakdown_row['cost'] ?? 0 ),
|
||||
'cpc' => (float) ( $breakdown_row['cpc'] ?? 0 ),
|
||||
'conversions' => (float) ( $breakdown_row['conversions'] ?? 0 ),
|
||||
'conversions_value' => (float) ( $breakdown_row['conversions_value'] ?? 0 ),
|
||||
'roas' => (float) ( $breakdown_row['roas'] ?? 0 ),
|
||||
'min_roas' => (float) ( $row['min_roas'] ?? 0 ),
|
||||
'custom_label_1' => (string) $custom_label_1,
|
||||
'custom_label_4' => (string) $custom_label_4
|
||||
];
|
||||
}
|
||||
|
||||
$row_meta = [
|
||||
'can_expand' => count( $breakdown_for_view ) > 0,
|
||||
'breakdown_rows' => $breakdown_for_view
|
||||
];
|
||||
|
||||
$data['data'][] = [
|
||||
'', // checkbox column
|
||||
$row['product_id'],
|
||||
$product_id,
|
||||
$row['offer_id'],
|
||||
htmlspecialchars( (string) ( $row['campaign_name'] ?? '' ) ),
|
||||
htmlspecialchars( (string) ( $row['ad_group_name'] ?? '' ) ),
|
||||
$product_url_html,
|
||||
'<div class="table-product-title" product_id="' . $row['product_id'] . '">
|
||||
<a href="/products/product_history/client_id=' . $client_id . '&product_id=' . $row['product_id'] . '&campaign_id=' . $history_campaign_id . '&ad_group_id=' . $history_ad_group_id . '" target="_blank" class="' . $custom_class . '">
|
||||
'<div class="table-product-title" product_id="' . $product_id . '">
|
||||
<a href="/products/product_history/client_id=' . $client_id . '&product_id=' . $product_id . '&campaign_id=' . $history_campaign_id . '&ad_group_id=' . $history_ad_group_id . '" target="_blank" class="' . $custom_class . '">
|
||||
' . $row['name'] . '
|
||||
</a>
|
||||
<span class="edit-product-title" product_id="' . $row['product_id'] . '">
|
||||
<span class="edit-product-title" product_id="' . $product_id . '">
|
||||
<i class="fa fa-pencil"></i>
|
||||
</span>
|
||||
</div>',
|
||||
@@ -1111,14 +1144,15 @@ class Products
|
||||
round( $row['conversions'], 2 ),
|
||||
\S::number_display( $row['conversions_value'] ),
|
||||
$roasCellHtml,
|
||||
'<input type="text" class="form-control min_roas" product_id="' . $row['product_id'] . '" value="' . $row['min_roas'] . '" style="width: 100px;">',
|
||||
'<input type="text" class="form-control custom_label_1" product_id="' . $row['product_id'] . '" value="' . $custom_label_1 . '" style="' . $custom_label_1_color . '">',
|
||||
'<input type="text" class="form-control custom_label_4" product_id="' . $row['product_id'] . '" value="' . $custom_label_4 . '" style="' . $custom_label_4_color . '">',
|
||||
'<input type="text" class="form-control min_roas" product_id="' . $product_id . '" value="' . $row['min_roas'] . '" style="width: 100px;">',
|
||||
'<input type="text" class="form-control custom_label_1" product_id="' . $product_id . '" value="' . $custom_label_1 . '" style="' . $custom_label_1_color . '">',
|
||||
'<input type="text" class="form-control custom_label_4" product_id="' . $product_id . '" value="' . $custom_label_4 . '" style="' . $custom_label_4_color . '">',
|
||||
'<div class="btn-group btn-group-sm products-row-actions" role="group">'
|
||||
. '<button type="button" class="btn btn-primary assign-product-scope" product_id="' . $row['product_id'] . '" title="Dodaj produkt do kampanii/grupy"><i class="fa-solid fa-diagram-project"></i></button>'
|
||||
. '<button type="button" class="btn btn-secondary view-merchant-logs" product_id="' . $row['product_id'] . '" title="Pokaż logi synchronizacji Merchant"><i class="fa-solid fa-clock-rotate-left"></i></button>'
|
||||
. '<button type="button" class="btn btn-danger delete-product" product_id="' . $row['product_id'] . '" title="Usuń produkt"><i class="fa-solid fa-trash"></i></button>'
|
||||
. '</div>'
|
||||
. '<button type="button" class="btn btn-primary assign-product-scope" product_id="' . $product_id . '" title="Dodaj produkt do kampanii/grupy"><i class="fa-solid fa-diagram-project"></i></button>'
|
||||
. '<button type="button" class="btn btn-secondary view-merchant-logs" product_id="' . $product_id . '" title="Pokaż logi synchronizacji Merchant"><i class="fa-solid fa-clock-rotate-left"></i></button>'
|
||||
. '<button type="button" class="btn btn-danger delete-product" product_id="' . $product_id . '" title="Usuń produkt"><i class="fa-solid fa-trash"></i></button>'
|
||||
. '</div>',
|
||||
$row_meta
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -487,6 +487,39 @@ class Products
|
||||
$sql .= ' AND ag.status = \'active\'';
|
||||
}
|
||||
|
||||
static private function build_products_filters( &$sql, &$params, $search, $custom_label_4, $custom_label_1 )
|
||||
{
|
||||
$search = trim( (string) $search );
|
||||
$custom_label_4 = trim( (string) $custom_label_4 );
|
||||
$custom_label_1 = trim( (string) $custom_label_1 );
|
||||
|
||||
if ( $search !== '' )
|
||||
{
|
||||
$sql .= ' AND (
|
||||
p.name LIKE :search
|
||||
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
|
||||
)';
|
||||
$params[':search'] = '%' . $search . '%';
|
||||
}
|
||||
|
||||
if ( $custom_label_4 !== '' )
|
||||
{
|
||||
$sql .= ' AND p.custom_label_4 LIKE :custom_label_4';
|
||||
$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 . '%';
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
@@ -522,15 +555,17 @@ class Products
|
||||
p.offer_id,
|
||||
p.min_roas,
|
||||
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
|
||||
WHEN pa.ad_group_id = 0 THEN \'PMax (bez grup reklam)\'
|
||||
ELSE COALESCE( NULLIF( TRIM( ag.ad_group_name ), \'\' ), \'--- brak grupy reklam ---\' )
|
||||
WHEN COUNT( DISTINCT pa.campaign_id ) > 1 THEN CONCAT( \'Wiele kampanii (\', COUNT( DISTINCT pa.campaign_id ), \')\' )
|
||||
ELSE COALESCE( NULLIF( TRIM( MAX( c.campaign_name ) ), \'\' ), \'--- brak kampanii ---\' )
|
||||
END AS campaign_name,
|
||||
CASE
|
||||
WHEN COUNT( DISTINCT CONCAT( pa.campaign_id, \':\', pa.ad_group_id ) ) > 1 THEN CONCAT( \'Wiele grup (\', COUNT( DISTINCT CONCAT( pa.campaign_id, \':\', pa.ad_group_id ) ), \')\' )
|
||||
WHEN MIN( pa.ad_group_id ) = 0 THEN \'PMax (bez grup reklam)\'
|
||||
ELSE COALESCE( NULLIF( TRIM( MAX( ag.ad_group_name ) ), \'\' ), \'--- brak grupy reklam ---\' )
|
||||
END AS ad_group_name,
|
||||
pa.ad_group_id AS ad_group_id,
|
||||
pa.campaign_id AS history_campaign_id,
|
||||
pa.ad_group_id AS history_ad_group_id,
|
||||
MIN( pa.campaign_id ) AS history_campaign_id,
|
||||
MIN( pa.ad_group_id ) AS history_ad_group_id,
|
||||
COALESCE( NULLIF( TRIM( p.title ), \'\' ), NULLIF( TRIM( p.name ), \'\' ), p.offer_id ) AS name,
|
||||
SUM( pa.impressions_all_time ) AS impressions,
|
||||
SUM( pa.impressions_30 ) AS impressions_30,
|
||||
@@ -558,34 +593,9 @@ class Products
|
||||
WHERE p.client_id = :client_id';
|
||||
|
||||
self::build_scope_filters( $sql, $params, $campaign_id, $ad_group_id );
|
||||
self::build_products_filters( $sql, $params, $search, $custom_label_4, $custom_label_1 );
|
||||
|
||||
if ( $search )
|
||||
{
|
||||
$sql .= ' AND (
|
||||
p.name LIKE :search
|
||||
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
|
||||
)';
|
||||
$params[':search'] = '%' . $search . '%';
|
||||
}
|
||||
|
||||
if ( $custom_label_4 !== '' )
|
||||
{
|
||||
$sql .= ' AND p.custom_label_4 LIKE :custom_label_4';
|
||||
$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, 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 .= ' GROUP BY p.id, p.offer_id, p.min_roas, p.custom_label_1, p.name, p.title';
|
||||
$sql .= ' ORDER BY ' . $order_sql . ' ' . $order_dir . ', product_id DESC LIMIT ' . $start . ', ' . $limit;
|
||||
|
||||
return $mdb -> query( $sql, $params ) -> fetchAll( \PDO::FETCH_ASSOC );
|
||||
@@ -597,47 +607,30 @@ class Products
|
||||
|
||||
$params = [ ':client_id' => $client_id ];
|
||||
|
||||
$sql = 'SELECT MIN( p.min_roas ) AS min_roas,
|
||||
MAX(
|
||||
CASE
|
||||
WHEN COALESCE( pa.cost_all_time, 0 ) > 0 THEN ROUND( COALESCE( pa.conversion_value_all_time, 0 ) / pa.cost_all_time * 100, 2 )
|
||||
ELSE 0
|
||||
END
|
||||
) AS max_roas
|
||||
FROM products_aggregate AS pa
|
||||
INNER JOIN products AS p ON p.id = pa.product_id
|
||||
LEFT JOIN campaigns AS c ON c.id = pa.campaign_id
|
||||
LEFT JOIN campaign_ad_groups AS ag ON ag.id = pa.ad_group_id
|
||||
WHERE p.client_id = :client_id
|
||||
AND pa.conversions_all_time > 10';
|
||||
$sql = 'SELECT
|
||||
MIN( t.min_roas ) AS min_roas,
|
||||
MAX( t.roas ) AS max_roas
|
||||
FROM (
|
||||
SELECT
|
||||
p.id AS product_id,
|
||||
p.min_roas AS min_roas,
|
||||
CASE
|
||||
WHEN SUM( pa.cost_all_time ) > 0 THEN ROUND( SUM( pa.conversion_value_all_time ) / SUM( pa.cost_all_time ) * 100, 2 )
|
||||
ELSE 0
|
||||
END AS roas,
|
||||
SUM( pa.conversions_all_time ) AS conversions
|
||||
FROM products_aggregate AS pa
|
||||
INNER JOIN products AS p ON p.id = pa.product_id
|
||||
LEFT JOIN campaigns AS c ON c.id = pa.campaign_id
|
||||
LEFT JOIN campaign_ad_groups AS ag ON ag.id = pa.ad_group_id
|
||||
WHERE p.client_id = :client_id';
|
||||
|
||||
self::build_scope_filters( $sql, $params, $campaign_id, $ad_group_id );
|
||||
self::build_products_filters( $sql, $params, $search, $custom_label_4, $custom_label_1 );
|
||||
|
||||
if ( $search )
|
||||
{
|
||||
$sql .= ' AND (
|
||||
p.name LIKE :search
|
||||
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
|
||||
)';
|
||||
$params[':search'] = '%' . $search . '%';
|
||||
}
|
||||
|
||||
if ( $custom_label_4 !== '' )
|
||||
{
|
||||
$sql .= ' AND p.custom_label_4 LIKE :custom_label_4';
|
||||
$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, p.min_roas
|
||||
HAVING SUM( pa.conversions_all_time ) > 10
|
||||
) AS t';
|
||||
|
||||
$row = $mdb -> query( $sql, $params ) -> fetch( \PDO::FETCH_ASSOC );
|
||||
|
||||
@@ -676,49 +669,103 @@ class Products
|
||||
global $mdb;
|
||||
|
||||
$params = [ ':client_id' => (int) $client_id ];
|
||||
$sql = 'SELECT COUNT(0)
|
||||
FROM (
|
||||
SELECT p.id
|
||||
FROM products_aggregate AS pa
|
||||
INNER JOIN products AS p ON p.id = pa.product_id
|
||||
LEFT JOIN campaigns AS c ON c.id = pa.campaign_id
|
||||
LEFT JOIN campaign_ad_groups AS ag ON ag.id = pa.ad_group_id
|
||||
WHERE p.client_id = :client_id';
|
||||
$sql = 'SELECT COUNT( DISTINCT p.id )
|
||||
FROM products_aggregate AS pa
|
||||
INNER JOIN products AS p ON p.id = pa.product_id
|
||||
LEFT JOIN campaigns AS c ON c.id = pa.campaign_id
|
||||
LEFT JOIN campaign_ad_groups AS ag ON ag.id = pa.ad_group_id
|
||||
WHERE p.client_id = :client_id';
|
||||
|
||||
self::build_scope_filters( $sql, $params, $campaign_id, $ad_group_id );
|
||||
|
||||
if ( $search )
|
||||
{
|
||||
$sql .= ' AND (
|
||||
p.name LIKE :search
|
||||
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
|
||||
)';
|
||||
$params[':search'] = '%' . $search . '%';
|
||||
}
|
||||
|
||||
if ( $custom_label_4 !== '' )
|
||||
{
|
||||
$sql .= ' AND p.custom_label_4 LIKE :custom_label_4';
|
||||
$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';
|
||||
self::build_products_filters( $sql, $params, $search, $custom_label_4, $custom_label_1 );
|
||||
|
||||
return $mdb -> query( $sql, $params ) -> fetchColumn();
|
||||
}
|
||||
|
||||
static public function get_products_scope_breakdown( $client_id, $product_ids, $campaign_id = 0, $ad_group_id = 0, $search = '', $custom_label_4 = '', $custom_label_1 = '' )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$product_ids = array_values( array_filter( array_map( 'intval', (array) $product_ids ) ) );
|
||||
|
||||
if ( empty( $product_ids ) )
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
$params = [ ':client_id' => (int) $client_id ];
|
||||
$in_placeholders = [];
|
||||
|
||||
foreach ( $product_ids as $idx => $product_id )
|
||||
{
|
||||
$key = ':product_id_' . $idx;
|
||||
$in_placeholders[] = $key;
|
||||
$params[ $key ] = $product_id;
|
||||
}
|
||||
|
||||
$sql = 'SELECT
|
||||
pa.product_id,
|
||||
pa.campaign_id,
|
||||
pa.ad_group_id,
|
||||
COALESCE( NULLIF( TRIM( c.campaign_name ), \'\' ), \'--- brak kampanii ---\' ) AS campaign_name,
|
||||
CASE
|
||||
WHEN pa.ad_group_id = 0 THEN \'PMax (bez grup reklam)\'
|
||||
ELSE COALESCE( NULLIF( TRIM( ag.ad_group_name ), \'\' ), \'--- brak grupy reklam ---\' )
|
||||
END AS ad_group_name,
|
||||
SUM( pa.impressions_all_time ) AS impressions,
|
||||
SUM( pa.impressions_30 ) AS impressions_30,
|
||||
SUM( pa.clicks_all_time ) AS clicks,
|
||||
SUM( pa.clicks_30 ) AS clicks_30,
|
||||
CASE
|
||||
WHEN SUM( pa.impressions_all_time ) > 0 THEN ROUND( SUM( pa.clicks_all_time ) / SUM( pa.impressions_all_time ) * 100, 2 )
|
||||
ELSE 0
|
||||
END AS ctr,
|
||||
SUM( pa.cost_all_time ) AS cost,
|
||||
CASE
|
||||
WHEN SUM( pa.clicks_all_time ) > 0 THEN ROUND( SUM( pa.cost_all_time ) / SUM( pa.clicks_all_time ), 6 )
|
||||
ELSE 0
|
||||
END AS cpc,
|
||||
SUM( pa.conversions_all_time ) AS conversions,
|
||||
SUM( pa.conversion_value_all_time ) AS conversions_value,
|
||||
CASE
|
||||
WHEN SUM( pa.cost_all_time ) > 0 THEN ROUND( SUM( pa.conversion_value_all_time ) / SUM( pa.cost_all_time ) * 100, 2 )
|
||||
ELSE 0
|
||||
END AS roas
|
||||
FROM products_aggregate AS pa
|
||||
INNER JOIN products AS p ON p.id = pa.product_id
|
||||
LEFT JOIN campaigns AS c ON c.id = pa.campaign_id
|
||||
LEFT JOIN campaign_ad_groups AS ag ON ag.id = pa.ad_group_id
|
||||
WHERE p.client_id = :client_id
|
||||
AND pa.product_id IN (' . implode( ', ', $in_placeholders ) . ')';
|
||||
|
||||
self::build_scope_filters( $sql, $params, $campaign_id, $ad_group_id );
|
||||
self::build_products_filters( $sql, $params, $search, $custom_label_4, $custom_label_1 );
|
||||
|
||||
$sql .= ' GROUP BY pa.product_id, pa.campaign_id, pa.ad_group_id, c.campaign_name, ag.ad_group_name
|
||||
ORDER BY campaign_name ASC, ad_group_name ASC';
|
||||
|
||||
$rows = $mdb -> query( $sql, $params ) -> fetchAll( \PDO::FETCH_ASSOC );
|
||||
$map = [];
|
||||
|
||||
foreach ( $rows as $row )
|
||||
{
|
||||
$product_id = (int) ( $row['product_id'] ?? 0 );
|
||||
if ( $product_id <= 0 )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( !isset( $map[ $product_id ] ) )
|
||||
{
|
||||
$map[ $product_id ] = [];
|
||||
}
|
||||
|
||||
$map[ $product_id ][] = $row;
|
||||
}
|
||||
|
||||
return $map;
|
||||
}
|
||||
|
||||
static public function get_product_full_context( $product_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
Reference in New Issue
Block a user