<?php
class Poll {
private array $points;
private RatingCost $cost;
private array $votes = [];
private array $votedUsers = [];
public function __construct(array $points, RatingCost $cost, array $votes = [], array $votedUsers = []) {
$this->points = $points;
$this->cost = $cost;
$this->votes = $votes;
$this->votedUsers = $votedUsers;
}
public function vote(Vote $vote) {
$this->votes[] = $vote;
$votedUser = $vote->getUser();
$this->votedUsers[] = $votedUser;
$votedUser->increaseRating($this->cost);
}
}
class Vote {
private User $user;
private PollingPoint $point;
public function __construct(User $user, PollingPoint $point) {
$this->user = $user;
$this->point = $point;
}
public function getUser() : User {
return $this->user;
}
}
class PollingPoint {
private string $id;
private string $value;
public function __construct(string $id, string $value) {
$this->id = $id;
$this->value = $value;
}
}
class User {
private string $id;
private Rating $rating;
public function __construct(string $id, Rating $rating) {
$this->id = $id;
$this->rating = $rating;
}
public function increaseRating(RatingCost $cost) {
$this->rating->increase($cost);
}
}
class Rating {
private int $value;
public function __construct(int $value) {
$this->value = $value;
}
public function increase(RatingCost $cost) {
$this->value += $cost->getValue();
}
}
class RatingCost {
private $value;
public function __construct(int $value) {
$this->value = $value;
}
public function getValue() : int {
return $this->value;
}
}
class VotePoll {
public function __invoke(string $pollId, string $userId, string $pointId) {
//$poll = $em->getPoll($pollId);
$cost = new RatingCost(30);
$firstPoint = new PollingPoint('firstPoint', 'Подписыюсь');
$secondPoint = new PollingPoint('secondPoint', 'За русь ем закусь');
$poll = new Poll([$firstPoint, $secondPoint], $cost);
//$user = $em->getUser($userId);
$rating = new Rating(1488);
$user = new User('firstUser', $rating);
$vote = new Vote($user, $firstPoint);
$poll->vote($vote);
//$em->flush();
return $user;
}
}
print_r((new VotePoll)('pollId', 'userId', 'pointId'));
preferences:
24.98 ms | 404 KiB | 5 Q