|
@@ 406-464 (lines=59) @@
|
| 403 |
|
return $arrayPosts; |
| 404 |
|
} |
| 405 |
|
|
| 406 |
|
public function toggleVote($user, $ipAddress, $post, $comment = null) |
| 407 |
|
{ |
| 408 |
|
$postvoteVoteMapper = $this->getPostVoteVoteMapper(); |
| 409 |
|
$postId = $post->getId(); |
| 410 |
|
$commentId = ($comment !== null) ? $comment->getId() : null; |
| 411 |
|
$vote = null; |
| 412 |
|
$game = $post->getPostvote(); |
| 413 |
|
|
| 414 |
|
if ($user) { |
| 415 |
|
if ($comment == null) { |
| 416 |
|
$entryUser = count($postvoteVoteMapper->findBy(array('user' => $user, 'post' => $postId))); |
| 417 |
|
$vote = $postvoteVoteMapper->findOneBy(array('user' => $user, 'post' => $postId)); |
| 418 |
|
} else { |
| 419 |
|
$entryUser = count($postvoteVoteMapper->findBy(array('user' => $user, 'post' => $postId, 'postComment' => $commentId))); |
| 420 |
|
$vote = $postvoteVoteMapper->findOneBy(array('user' => $user, 'post' => $postId, 'postComment' => $commentId)); |
| 421 |
|
} |
| 422 |
|
} else { |
| 423 |
|
if ($comment == null) { |
| 424 |
|
$entryUser = count($postvoteVoteMapper->findBy(array('ip' => $ipAddress, 'post' => $postId))); |
| 425 |
|
$vote = $postvoteVoteMapper->findOneBy(array('ip' => $ipAddress, 'post' => $postId)); |
| 426 |
|
} else { |
| 427 |
|
$entryUser = count($postvoteVoteMapper->findBy(array('ip' => $ipAddress, 'post' => $postId, 'postComment' => $commentId))); |
| 428 |
|
$vote = $postvoteVoteMapper->findOneBy(array('ip' => $ipAddress, 'post' => $postId, 'postComment' => $commentId)); |
| 429 |
|
} |
| 430 |
|
} |
| 431 |
|
|
| 432 |
|
if ($entryUser && $entryUser > 0) { |
| 433 |
|
$postvoteVoteMapper->remove($vote); |
| 434 |
|
|
| 435 |
|
return 0; |
| 436 |
|
} else { |
| 437 |
|
$vote = new \PlaygroundGame\Entity\PostVoteVote(); |
| 438 |
|
$vote->setPost($post); |
| 439 |
|
$vote->setIp($ipAddress); |
| 440 |
|
$vote->setNote(1); |
| 441 |
|
// If the vote is for a comment |
| 442 |
|
if ($comment != null) { |
| 443 |
|
$vote->setPostComment($comment); |
| 444 |
|
$vote->setPostvote($post->getPostvote()); |
| 445 |
|
// else if the vote is for the post itself |
| 446 |
|
} else { |
| 447 |
|
$vote->setPostvote($post->getPostvote(), true); |
| 448 |
|
} |
| 449 |
|
|
| 450 |
|
if ($user) { |
| 451 |
|
$vote->setUser($user); |
| 452 |
|
} |
| 453 |
|
|
| 454 |
|
$postvoteVoteMapper->insert($vote); |
| 455 |
|
} |
| 456 |
|
|
| 457 |
|
$this->getEventManager()->trigger( |
| 458 |
|
__FUNCTION__ .'.post', |
| 459 |
|
$this, |
| 460 |
|
array('user' => $user, 'game' => $game, 'post' => $post, 'vote' => $vote) |
| 461 |
|
); |
| 462 |
|
|
| 463 |
|
return 1; |
| 464 |
|
} |
| 465 |
|
|
| 466 |
|
public function removeVote($user, $ipAddress, $post) |
| 467 |
|
{ |
|
@@ 501-556 (lines=56) @@
|
| 498 |
|
return true; |
| 499 |
|
} |
| 500 |
|
|
| 501 |
|
public function addVote($user, $ipAddress, $post) |
| 502 |
|
{ |
| 503 |
|
$postvoteVoteMapper = $this->getPostVoteVoteMapper(); |
| 504 |
|
$postId = $post->getId(); |
| 505 |
|
$commentId = ($comment !== null) ? $comment->getId() : null; |
| 506 |
|
$vote = null; |
| 507 |
|
$game = $post->getPostvote(); |
| 508 |
|
|
| 509 |
|
if ($user) { |
| 510 |
|
if ($comment == null) { |
| 511 |
|
$entryUser = count($postvoteVoteMapper->findBy(array('user' => $user, 'post' => $postId))); |
| 512 |
|
$vote = $postvoteVoteMapper->findOneBy(array('user' => $user, 'post' => $postId)); |
| 513 |
|
} else { |
| 514 |
|
$entryUser = count($postvoteVoteMapper->findBy(array('user' => $user, 'post' => $postId, 'postComment' => $commentId))); |
| 515 |
|
$vote = $postvoteVoteMapper->findOneBy(array('user' => $user, 'post' => $postId, 'postComment' => $commentId)); |
| 516 |
|
} |
| 517 |
|
} else { |
| 518 |
|
if ($comment == null) { |
| 519 |
|
$entryUser = count($postvoteVoteMapper->findBy(array('ip' => $ipAddress, 'post' => $postId))); |
| 520 |
|
$vote = $postvoteVoteMapper->findOneBy(array('ip' => $ipAddress, 'post' => $postId)); |
| 521 |
|
} else { |
| 522 |
|
$entryUser = count($postvoteVoteMapper->findBy(array('ip' => $ipAddress, 'post' => $postId, 'postComment' => $commentId))); |
| 523 |
|
$vote = $postvoteVoteMapper->findOneBy(array('ip' => $ipAddress, 'post' => $postId, 'postComment' => $commentId)); |
| 524 |
|
} |
| 525 |
|
} |
| 526 |
|
|
| 527 |
|
if ($entryUser && $entryUser > 0) { |
| 528 |
|
return false; |
| 529 |
|
} else { |
| 530 |
|
$vote = new \PlaygroundGame\Entity\PostVoteVote(); |
| 531 |
|
$vote->setPost($post); |
| 532 |
|
$vote->setIp($ipAddress); |
| 533 |
|
$vote->setNote(1); |
| 534 |
|
// If the vote is for a comment |
| 535 |
|
if ($comment != null) { |
| 536 |
|
$vote->setPostComment($comment); |
| 537 |
|
$vote->setPostvote($post->getPostvote()); |
| 538 |
|
// else if the vote is for the post itself |
| 539 |
|
} else { |
| 540 |
|
$vote->setPostvote($post->getPostvote(), true); |
| 541 |
|
} |
| 542 |
|
if ($user) { |
| 543 |
|
$vote->setUser($user); |
| 544 |
|
} |
| 545 |
|
|
| 546 |
|
$postvoteVoteMapper->insert($vote); |
| 547 |
|
$game = $post->getPostvote(); |
| 548 |
|
$this->getEventManager()->trigger( |
| 549 |
|
__FUNCTION__ .'.post', |
| 550 |
|
$this, |
| 551 |
|
array('user' => $user, 'game' => $game, 'post' => $post, 'vote' => $vote) |
| 552 |
|
); |
| 553 |
|
|
| 554 |
|
return true; |
| 555 |
|
} |
| 556 |
|
} |
| 557 |
|
|
| 558 |
|
public function addComment($user, $ipAddress, $post, $message = '', $category = null) |
| 559 |
|
{ |