[eluser]Jeroen Brussich[/eluser]
I found a imho dirty solution, but I still would like somebody to have a look, point his finger and laugh at me
and then provide me with the right code. :p
Code:
public function remove_doubles($candidates, $loaners)
{
// build an array with the user_ids
$haystack = array();
foreach($loaners->result() as $loaner)
{
$haystack[] = $loaner->id;
}
//look if the user_id from the candidate is in the already_loaned_haystack
//iterate i
$i = 0;
foreach($candidates->result() as $candidate)
{
$needle = $candidate->id;
if(in_array($needle, $haystack))
{
// DIRTY!!!
// hack into the object and force unset.
// manually reset num_rows
// do not user ->num_rows() after this, because it would return the number of rows of the initial object, not the hacked object.
unset($candidates->result_object[0]);
$candidates->num_rows = $candidates->num_rows -1;
}
$i++;
}
// return hacked object or FALSE
if($candidates->num_rows != 0) // do not use ->num_rows() but ->num_rows
{
sort($candidates->result_object);
return $candidates;
}
return FALSE;
}