76 lines
3.5 KiB
PHP
76 lines
3.5 KiB
PHP
<?
|
|
namespace factory;
|
|
class Products
|
|
{
|
|
static public function get_products( $client_id, $search, $limit, $start, $order_name, $order_dir )
|
|
{
|
|
global $mdb;
|
|
|
|
if ( $search )
|
|
return $mdb -> query( 'SELECT pt.*, p.offer_id FROM products_temp AS pt INNER JOIN products AS p ON p.id = pt.product_id WHERE client_id = \'' . $client_id . '\' AND pt.name LIKE \'%' . $search . '%\' ORDER BY ' . $order_name . ' ' . $order_dir . ' LIMIT ' . $start . ', ' . $limit ) -> fetchAll();
|
|
else
|
|
return $mdb -> query( 'SELECT pt.*, p.offer_id FROM products_temp AS pt INNER JOIN products AS p ON p.id = pt.product_id WHERE client_id = \'' . $client_id . '\' ORDER BY ' . $order_name . ' ' . $order_dir . ' LIMIT ' . $start . ', ' . $limit ) -> fetchAll();
|
|
}
|
|
|
|
static public function get_records_total_products( $client_id, $search )
|
|
{
|
|
global $mdb;
|
|
|
|
if ( $search )
|
|
return $mdb -> query( 'SELECT COUNT(0) FROM products_temp AS pt INNER JOIN products AS p ON p.id = pt.product_id WHERE client_id = \'' . $client_id . '\' AND pt.name LIKE \'%' . $search . '%\'' ) -> fetchColumn();
|
|
else
|
|
return $mdb -> query( 'SELECT COUNT(0) FROM products_temp AS pt INNER JOIN products AS p ON p.id = pt.product_id WHERE client_id = \'' . $client_id . '\'' ) -> fetchColumn();
|
|
}
|
|
|
|
static public function get_product_data( $product_id, $field )
|
|
{
|
|
global $mdb;
|
|
return $mdb -> get( 'products_data', $field, [ 'product_id' => $product_id ] );
|
|
}
|
|
|
|
static public function set_product_data( $product_id, $field, $value )
|
|
{
|
|
global $mdb;
|
|
return $mdb -> update( 'products_data', [ $field => $value ], [ 'product_id' => $product_id ] );
|
|
}
|
|
|
|
static public function get_product_history( $client_id, $product_id, $start, $limit )
|
|
{
|
|
global $mdb;
|
|
return $mdb -> query( 'SELECT * FROM products_history AS ph WHERE ph.product_id = \'' . $product_id . '\' ORDER BY ph.date_add DESC LIMIT ' . $start . ', ' . $limit ) -> fetchAll( \PDO::FETCH_ASSOC );
|
|
}
|
|
|
|
static public function get_records_total_product_history( $client_id, $product_id )
|
|
{
|
|
global $mdb;
|
|
return $mdb -> query( 'SELECT COUNT(0) FROM products_history AS ph WHERE ph.product_id = \'' . $product_id . '\'' ) -> fetchColumn();
|
|
}
|
|
|
|
static public function get_product_history_30( $client_id, $product_id, $start, $limit )
|
|
{
|
|
global $mdb;
|
|
return $mdb -> query( 'SELECT * FROM products_history_30 AS ph3 WHERE ph3.product_id = \'' . $product_id . '\' ORDER BY ph3.date_add DESC LIMIT ' . $start . ', ' . $limit ) -> fetchAll( \PDO::FETCH_ASSOC );
|
|
}
|
|
|
|
static public function get_impressions_30( $product_id )
|
|
{
|
|
global $mdb;
|
|
return $mdb -> query( 'SELECT SUM(impressions) FROM products_history WHERE product_id = \'' . $product_id . '\'' ) -> fetchColumn();
|
|
}
|
|
|
|
static public function get_clicks_30( $product_id )
|
|
{
|
|
global $mdb;
|
|
return $mdb -> query( 'SELECT SUM(clicks) FROM products_history WHERE product_id = \'' . $product_id . '\'' ) -> fetchColumn();
|
|
}
|
|
|
|
static public function add_product_comment( $product_id, $type, $comment )
|
|
{
|
|
global $mdb;
|
|
|
|
if ( $mdb -> count( 'products_comments', [ 'AND' => [ 'product_id' => $product_id, 'type' => $type, 'comment' => $comment, 'date_add' => date( 'Y-m-d' ) ] ] ) )
|
|
$mdb -> update( 'products_comments', [ 'date_add' => date( 'Y-m-d H:i:s' ) ], [ 'AND' => [ 'product_id' => $product_id, 'type' => $type, 'comment' => $comment, 'date_add' => date( 'Y-m-d' ) ] ] );
|
|
else
|
|
$mdb -> insert( 'products_comments', [ 'product_id' => $product_id, 'type' => $type, 'comment' => $comment, 'date_add' => date( 'Y-m-d' ) ] );
|
|
}
|
|
} |