*

Ajit Sahane

  • ****
  • 147 posts
  • https://bestclassifiedsusa.com
User My Account Show - Ads Status with count
« on: April 25, 2020, 08:05:58 AM »

 How we can show under User - My Account Section |  Total Ads - Active ( 10) Block ( 2) Spam (1) 

 Below Item title -

 Ad status - Active / Blocked / Spam / Premium Active etc

 Its help to user to know what is current status of this ad. many times if 1 ad not approved then user posting same ad repeated.

 Beta theme want code.

 I am try some but not prefect check JPG  -  How i want ..?

 Anyone can help me ..? 

*

MB Themes

Re: User My Account Show - Ads Status with count
« Reply #1 on: April 26, 2020, 12:07:33 PM »
@Ajit
Such stats are not collected, you will have to use oc_t_item table to calculate this
fk_i_user_id
b_enabled
b_spam
b_active

Are the fields you need... Query would be:
Code: [Select]
select sum(b_enabled) as enabled, sum(b_spam) as spam, sum(b_active), count(pk_i_id) as total as active from oc_t_item where fk_i_user_id = "$user_id"
Hope it helps you, good luck ;)

// you may find many examples of using queries and getting data in theme functions.php
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

Ajit Sahane

  • ****
  • 147 posts
  • https://bestclassifiedsusa.com
Re: User My Account Show - Ads Status with count
« Reply #2 on: April 27, 2020, 06:39:50 AM »
I am trying your suggest code but no any result.

1st i add below code in theme functions.php   & then user-items.php but no luck.

<?php function bet_item_stats( $item_id ) {
  if( $item_id <> '' ) {
    $db_prefix = DB_TABLE_PREFIX;
    //$query = "SELECT sum(coalesce(i_num_phone_clicks, 0)) as phone_clicks FROM {$db_prefix}t_item_stats_beta s WHERE fk_i_item_id = " . $item_id . ";";
    $query = "SELECT sum(b_enabled) as enabled, sum(b_spam) as spam, sum(b_active), count(pk_i_id) as total_ads_active FROM oc_t_item WHERE fk_i_user_id = " . $user_id .";";
    $result = ItemStats::newInstance()->dao->query( $query );
    if( !$result ) {
      $prepare = array();
      return '0';
    } else {
      $prepare = $result->row();
      if($prepare['total_ads_active'] <> '') {
        return $prepare['total_ads_active'];
      } else {
        return '0';
      }
    }
  }
}
?>
<?php echo $total_ads_active; ?>  or  <?php echo bet_item_stats(); ?>

this code not any output. pls have a look in code, might be coding error. 

Also, currently i am used below code & its show only active ads count but not spam, block.

<?php
  if( osc_is_web_user_logged_in() ) {
    $user_id = osc_logged_user_id();
  }

  $user = User::newInstance()->findByPrimaryKey($user_id);
  $num_items_user = $user['i_items'];
  echo $num_items_user;
?>