Skip to content

Instantly share code, notes, and snippets.

@clemblanco
Created May 30, 2013 10:58
Show Gist options
  • Save clemblanco/5677103 to your computer and use it in GitHub Desktop.
Save clemblanco/5677103 to your computer and use it in GitHub Desktop.
Tests if a Picture entity has already been voted by a specific User.
<?php
/**
* Tests if a Picture entity has already been voted by a specific User.
*
* @param Innteger $userId The User ID.
* @return boolean TRUE if the predicate is TRUE for at least one element, FALSE otherwise.
*/
public function hasBeenVotedBy($userId)
{
$predicate = function($key, $element) use ($userId){
return $element->getUser()->getId() === intval($userId);
};
return $this->votes->exists($predicate);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment