Im new to objects and im still trying to get my head around it.
Here is the situation i have:
I have info coming from an API formatted as an object with a bunch of variables like this:
public 'id' => int 64
public 'taskId' => int 6
public 'projectId' => int 2
public 'type' => string 'progress' (length=8)
public 'text' => string 'bug5279 main branch fix confirmed beta still an issue with bounties' (length=111)
public 'ownerId' => int 3
public 'progress' => int 0
public 'hoursDone' => float 0.25
public 'createdAt' => string '2012-08-28T09:33:51' (length=19)
public 'notifyProjectTeam' => boolean false
public 'notifyTaskTeam' => boolean false
public 'notifyClient' => boolean false
public 'date' => string '2012-08-28T09:33:51' (length=19)
This is the code i use to produce the above and it returns a bunch of objects
activity List
$activityList = $activityClient->getList( $filter, $offset, $count );
This is the users list
$usersList = $usersClient->getAll();
Now what i want to do is only display the username IF the user hoursDone value is >0
I googled and i can find how to loop through an object but cant seem to find the right keywords to show where conditions and since im new to objects im a bit lost. Here is my code for a simple loop through
// get the usernames
foreach($usersList->items as $user_details) {
$users[$user_details->id]=$user_details->firstName.' '.$user_details->lastName;
}
// get projects
foreach($tasksList->items as $task_details)
{
$tasks[$task_details->id]=$task_details->name;
}
And here is how i loop through the activities
foreach($activityList->items as $workdetails)
{
echo "<br><h2>$username</h2><br>";
}
foreach($tasks as $taskid=>$taskname)
{
if($userid==$workdetails->ownerId && $taskid==$workdetails->taskId)
{
echo "<br>$workdetails->hoursDone<br>";
echo "<br>$workdetails->text<br>";
}
}
Now the problem is i end up with something like this:
John
1
worked on emails
James
Jerry
Pat
Harry
2.50
worked on emails
Mary
Sarah
But i don’t want people to show up unless they have > 0 for hoursDone.
this is the point im really lost on, i dont know where to start to be honest. Any links to answers or examples would be great. This is a mixture of inherited code and my own code.
You’re almost there, just do
I added a check to see if the hoursDone value is > 0