Advertisement:

Author Topic: (Fixed) Problem for count numbers of items  (Read 847 times)

Ipobra

  • Newbie
  • *
  • Posts: 3
(Fixed) Problem for count numbers of items
« on: August 11, 2015, 12:30:21 pm »
Hello,

I'm trying to get the numbers of items for an user.

This is my code:

Code: [Select]
<?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;
?>

Someone know why that don't work?
(sorry for my bad english)

Thank's.
Ipobra.
« Last Edit: August 11, 2015, 01:12:14 pm by Ipobra »

frosticek

  • Hero Member
  • *****
  • Posts: 3948
Re: Problem for count numbers of items
« Reply #1 on: August 11, 2015, 01:06:45 pm »
@Ipobra

You miss one $ sign in.

Code: [Select]
<?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;
?>


SmaRTeY

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 2519
Re: Problem for count numbers of items
« Reply #2 on: August 11, 2015, 01:07:36 pm »
Why don't you try helper function in hUsers.php?

Similar to your function there is this one you could try:
Code: [Select]
/**
     * Gets number of items validated of current user
     *
     * @return int
     */
    function osc_user_items_validated() {
        return (int) osc_user_field("i_items");
    }

Regards,
Eric

Ipobra

  • Newbie
  • *
  • Posts: 3
Re: Problem for count numbers of items
« Reply #3 on: August 11, 2015, 01:11:31 pm »
Really a noob problem...

Thank's you for your help.

Ipobra.

Ipobra

  • Newbie
  • *
  • Posts: 3
Re: (Fixed) Problem for count numbers of items
« Reply #4 on: August 11, 2015, 01:14:51 pm »
@SmaRTeY

I do not know the proper functioning of osclass .

I will try to watch helpers fonctions now.

SmaRTeY

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 2519
Re: (Fixed) Problem for count numbers of items
« Reply #5 on: August 11, 2015, 01:51:17 pm »
Yes you should, there's is not 100% coverage I guess but for example your function does not take item statusses into account ie. ALL ads from an user are counted. If that is what you want cool but if you want to skip the ones that are expired or something you need your code to be a bit different.

Regards,
Eric

frosticek

  • Hero Member
  • *****
  • Posts: 3948
Re: (Fixed) Problem for count numbers of items
« Reply #6 on: August 11, 2015, 02:56:47 pm »
@Ipobra
Anyway is good if you can construct some functions by yourself ;)