Skip to content

Commit

Permalink
storing client IP addresses with votes (as strings for now) issue #18
Browse files Browse the repository at this point in the history
  • Loading branch information
teo-sk committed Jul 18, 2012
1 parent d23e3d7 commit 17a5b76
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Entity/Vote.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ abstract class Vote extends VoteModel
*/
protected $answer;

/**
* @ORM\Column(name="client_ip", type="string", length="39")
*/
protected $clientIp;

/**
* @ORM\Column(name="created_at", type="datetime")
*/
Expand Down
12 changes: 12 additions & 0 deletions Entity/VoteManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,18 @@ public function findBy($criteria)
return $this->repository->findBy($criteria);
}

/**
* {@inheritDoc}
*/
public function create(FieldInterface $field, $answer)
{
$vote = parent::create($field, $answer);
$vote->setClientIp($this->request->getClientIp());

return $vote;
}


/**
* Doctrine 2 ORM specific save.
*
Expand Down
23 changes: 23 additions & 0 deletions Model/Vote.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ abstract class Vote implements VoteInterface
*/
protected $answer;

/**
* @var string
*/
protected $clientIp;

/**
* @var \DateTime
*/
Expand Down Expand Up @@ -95,6 +100,23 @@ public function getAnswer()
return $this->answer;
}


/**
* @param string $clientIp
*/
public function setClientIp($clientIp)
{
$this->clientIp = $clientIp;
}

/**
* @return string
*/
public function getClientIp()
{
return $this->clientIp;
}

/**
* Sets time this vote was created at.
*
Expand Down Expand Up @@ -128,4 +150,5 @@ public function getAuthorName()
{
return "anonymous";
}

}
10 changes: 10 additions & 0 deletions Model/VoteInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,14 @@ public function getField();
* @return VoteInterface
*/
public function setAnswer($answer);


/**
* Sets client's IP address
*
* @param $ip
*
* @return mixed
*/
public function setClientIp($ip);
}

0 comments on commit 17a5b76

Please sign in to comment.