Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // write class Event that implements interface ParticipableInterface
- // Event represents real life event like - concert, meetup, or some other gathering of people
- // for storing participants - use array,
- // consider edge cases scenarios
- // It is allowed to use google for searching documentation.
- interface ParticipableInterface
- {
- public function getStartDate(); // Trivial - Do not implement
- public function getParticipants(); // Trivial - Do not implement
- public function setStartDate(DateTime $date);
- public function getDuration(); // Trivial -- Do not implement
- /**
- * $duration -- integer, amount of minutes
- */
- public function setDuration($duration);
- // should return instance of DateTime or rise exception if duration has not been set yet
- public function getEndDate();
- // when user joins event
- public function join(ParticipantInterface $participant);
- // when user leaves
- public function part(ParticipantInterface $participant);
- }
- // FOR YOUR INFORMATION -- Do not implement this interface
- interface ParticipantInterface
- {
- public function getId();
- public function getName();
- public function getEmail();
- }
- class User implements ParticipantInterface
- {
- public $id;
- public $name;
- public $email;
- public function getId()
- {
- return $this->id;
- }
- public function getName()
- {
- return $this->name;
- }
- public function getEmail()
- {
- return $this->email;
- }
- /**
- * Constructor.
- */
- public function __construct($id, $name, $email)
- {
- $this->id = $id;
- $this->email = $email;
- $this->name = $name;
- }
- }
- class Event implements ParticipableInterface
- {
- /** @var $nameEvent string */
- public $nameEvent;
- /**
- * @var array
- */
- public $participants = [];
- /** @var $startDate DateTime */
- public $startDate;
- /** @var integer */
- public $duration;
- /** @var $endDate DateTime */
- public $endDate;
- public function getStartDate() {
- return $this->startDate;
- }
- public function getParticipants() {
- return $this->participants;
- }
- public function setStartDate(DateTime $date) {
- $this->startDate = $date;
- return $this;
- }
- public function getDuration() {
- return $this->duration;
- }
- /**
- * $duration integer
- */
- public function setDuration($duration) {
- $this->duration = $duration;
- return $this;
- }
- // should return instance of DateTime or rise exception if duration has not been set yet
- public function getEndDate() {
- if ($this->startDate->modify('+'.$this->duration.' minutes') >= new DateTime('now')) {
- return new Exception('has not been set yet');
- }
- return $this->startDate->modify('+'.$this->duration.' minutes')->format('Y-m-d H:i:s');
- }
- // when user joins event
- public function join(ParticipantInterface $participant) {
- $this->addParticipant($participant);
- }
- /**
- * @param array $participant
- * @return $this
- */
- public function setParticipant(array $participant)
- {
- $this->participants = $participant;
- return $this;
- }
- public function addParticipant(ParticipantInterface $participant)
- {
- $participant = strtoupper($participant->getEmail());
- if (!in_array($participant, $this->participants, true)) {
- $this->participants[] = $participant;
- }
- return $this;
- }
- public function unsetParticipant(ParticipantInterface $participant)
- {
- $usersArrayEmail = $this->getParticipants();
- $key = array_search((strtoupper($participant->getEmail())), $usersArrayEmail);
- if ($key !== false) {
- unset($usersArrayEmail[$key]);
- $this->setParticipant($usersArrayEmail);
- }
- return $this;
- }
- // when user leaves
- public function part(ParticipantInterface $participant) {
- $this->unsetParticipant($participant);
- }
- /**
- * Constructor.
- */
- public function __construct($nameEvent)
- {
- $this->nameEvent = $nameEvent;
- }
- }
- $event = new Event('concert');
- $event
- ->setStartDate(new DateTime('now'))
- ->setDuration(10)
- ;
- $event->join($user);
- var_dump($event);
- $event->part($user);
- var_dump($event);
- // YOUR CODE HERE
- // Palindrome is word that can be read backwards and it is the same word as read forwards example: kayak, dad
- // write function that will check if given word is palindrome
- // Simplest solution is most desired
- /**
- * @param string $word
- * @return bool
- */
- function is_palindrome($word) {
- return strrev((string) $word) === $word ? true : false;
- }
Advertisement
Add Comment
Please, Sign In to add comment