<?php
namespace Main\StrategyPattern;

require_once 'IMarker.php';

class Multichoice implements IMarker
{
	// Attributes
	private $_correctAnswers;
	
	// Constructor
	
	public function __construct(array $correctAnswers)
	{
		$this->_correctAnswers = $correctAnswers;
	}
	
	// Methods for properties
	// Getters and Setters
	
	// Methods
	public function Mark($answers)
	{
		$correctAnswers = array_slice($this->_correctAnswers, 0);		// Copy the array
		$count = count($correctAnswers);
		
		if(count($answers) == $count)
		{
			foreach($answers as $answer)
			{
				if(($key = $this->CheckAnswer($correctAnswers, $answer)) !== false)
				{
					$count--;
					if($count == 0)
						return true;
						
					// Remove the matched answer
					array_splice($correctAnswers, $key, 1);
				}
			}
		}
		return false;
	}
	
	private function CheckAnswer($correctAnswers, $answer)
	{
		foreach($correctAnswers as $key => $correctAnswer)
		{
			if($answer == $correctAnswer)
			{
				return $key;
			}
		}
		return false;
	}
}
?>