Advertisement:

Author Topic: Function to get nr. of Items per user dynamically  (Read 1316 times)

SmaRTeY

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 2519
Function to get nr. of Items per user dynamically
« on: November 09, 2015, 05:06:16 pm »
Hi all,

since there is not an easy way (yet) to get the total nr. of user items for display or other use I decided to create a simple function that gets the "Active/Enabled/Not Spam/Not Expired" user item count given a user id.

Code: [Select]
function GetTotalActiveUserItemsCount($userId) {
$useritems = new DAO();
$useritems->dao->select();
$useritems->dao->from(DB_TABLE_PREFIX.'t_item');
$useritems->dao->where('b_enabled', 1);
$useritems->dao->where('b_active', 1);
$useritems->dao->where('b_spam', 0);
$useritems->dao->where("dt_expiration = '9999-12-31 23:59:59' or 'dt_expiration < now()' ");
$useritems->dao->where(sprintf("fk_i_user_id = '%s'", $userId));
$result = $useritems->dao->get();
$count = $result->result();
$count = count($count);
return $count;
}

Put the code inside your functions.php and it should be ready for use.
Feel free to modify for your own use, virtually all kinds of counts can be made depending on your modifications.
Performance should not be an issue since most single users do not have that many ads.

Use phpMyAdmin to view the table oc_t_item and it's fields which will help you in making your own modifications if needed.

P.s. also check out the plugin made by dev101 that does some fixing of item & user stats:
http://forums.osclass.org/development/number-of-items/


Regards,
Eric

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: Function to get nr. of Items per user dynamically
« Reply #1 on: July 02, 2017, 10:41:31 pm »
Hi,
Sorry to dig this up, but I'm interested in a non-plugin solution for the wrong number of items shown in osclass admin area.


If I put this function in functions.php of my theme, and call the function in the user loop that populates the users table in users admin area, it should work?
I'm using 3.7.1 bender theme.

Thank you.

SmaRTeY

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 2519
Re: Function to get nr. of Items per user dynamically
« Reply #2 on: July 03, 2017, 04:00:03 am »
Hi,

I think you should really want to use the plugin dev101 created to refresh/update counter statistics.
In my Admin Dashboard user statistics look fine now, no need to use my function to show the nr. of ads.

The function itself works and it could also be used in Admin as long as you pass the user's pk you'll get the actual item count.
Using it in a loop would also work but again, I recommend the plugin for this.

The function, but with more parameters, could be a additional helper function in hUsers.


Regards,
Eric

Hi,
Sorry to dig this up, but I'm interested in a non-plugin solution for the wrong number of items shown in osclass admin area.


If I put this function in functions.php of my theme, and call the function in the user loop that populates the users table in users admin area, it should work?
I'm using 3.7.1 bender theme.

Thank you.