First git commit
This commit is contained in:
commit
a830722f4c
100 changed files with 38622 additions and 0 deletions
116
src/Questionnaire/Model/Question.php
Normal file
116
src/Questionnaire/Model/Question.php
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
<?php
|
||||
|
||||
namespace Questionnaire\Model;
|
||||
|
||||
class Question
|
||||
{
|
||||
protected $id;
|
||||
|
||||
protected $title;
|
||||
|
||||
protected $choices = array();
|
||||
|
||||
protected $required = array();
|
||||
|
||||
public function hydrate(array $data)
|
||||
{
|
||||
foreach ($data as $k => $v) {
|
||||
$setter = 'set'.ucfirst($k);
|
||||
|
||||
if (method_exists($this, $setter)) {
|
||||
$this->$setter($v);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setId($id)
|
||||
{
|
||||
$this->id = $id;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function setTitle($title)
|
||||
{
|
||||
$this->title = $title;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
{
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
public function setChoices(array $choices)
|
||||
{
|
||||
$this->choices = $choices;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getChoices()
|
||||
{
|
||||
return $this->choices;
|
||||
}
|
||||
|
||||
public function setRequired(array $required)
|
||||
{
|
||||
$this->required = $required;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getRequired()
|
||||
{
|
||||
return $this->required;
|
||||
}
|
||||
|
||||
public function getRequirements()
|
||||
{
|
||||
return $this->getRequired();
|
||||
}
|
||||
|
||||
public function hasRequirements()
|
||||
{
|
||||
return count($this->getRequirements()) > 0;
|
||||
}
|
||||
|
||||
public function isCompatibleWithResponses(array $response)
|
||||
{
|
||||
if (!$this->hasRequirements()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach ($response as $questionId => $response) {
|
||||
$question = QuestionPeer::retrieveQuestionById($questionId);
|
||||
|
||||
if (null === $question) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($this->getRequirements() as $requirement) {
|
||||
list($requirementQuestionId, $requirementResponses) = $requirement;
|
||||
|
||||
if ($requirementQuestionId === $questionId) {
|
||||
if (!is_array($requirementResponses)) {
|
||||
$requirementResponses = array($requirementResponses);
|
||||
}
|
||||
|
||||
if (!in_array($response, $requirementResponses)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue