Add \Entities\UsrList::has method

This commit is contained in:
Romain Neutron
2012-01-31 11:29:59 +01:00
parent 6b9f667b0d
commit f1a817098a

View File

@@ -45,7 +45,7 @@ class UsrList
private $owners; private $owners;
/** /**
* @var Entities\UsrListEntry * @var \Doctrine\Common\Collections\Collection
*/ */
private $entries; private $entries;
@@ -150,9 +150,10 @@ class UsrList
foreach ($this->getOwners() as $owner) foreach ($this->getOwners() as $owner)
{ {
if ($owner->getUser()->get_id() == $user->get_id()) if ($owner->getUser()->get_id() == $user->get_id())
{
return true; return true;
} }
}
return false; return false;
} }
@@ -167,9 +168,10 @@ class UsrList
foreach ($this->getOwners() as $owner) foreach ($this->getOwners() as $owner)
{ {
if ($owner->getUser()->get_id() == $user->get_id()) if ($owner->getUser()->get_id() == $user->get_id())
{
return $owner; return $owner;
} }
}
throw new \Exception('This user is not an owner of the list'); throw new \Exception('This user is not an owner of the list');
} }
@@ -187,11 +189,27 @@ class UsrList
/** /**
* Get entries * Get entries
* *
* @return Doctrine\Common\Collections\Collection * @return \Doctrine\Common\Collections\Collection
*/ */
public function getEntries() public function getEntries()
{ {
return $this->entries; return $this->entries;
} }
/**
* Return true if one of the entry is related to the given user
*
* @param \User_Adapter $user
* @return boolean
*/
public function has(\User_Adapter $user)
{
return $this->entries->exists(
function($key, $entry) use ($user)
{
return $entry->getUser()->get_id() === $user->get_id();
}
);
}
} }