Skip to content

Commit

Permalink
Dev add group level to expression builder.
Browse files Browse the repository at this point in the history
  • Loading branch information
SamMousa committed Sep 16, 2015
1 parent 71992fb commit f7b1c83
Showing 1 changed file with 50 additions and 45 deletions.
95 changes: 50 additions & 45 deletions application/views/expressions/build.php
@@ -1,61 +1,66 @@
<?php
$tree = [];
/** @var Survey $survey */
foreach($survey->questions as $question) {
// Check subquestions.
if ($question->hasSubQuestions) {
$subQuestions = [];
/** @var \ls\interfaces\iSubQuestion $subQuestion */
foreach($question->getSubQuestions() as $subQuestion) {
if ($question->hasAnswers) {
$children = array_values(array_map(function (\ls\interfaces\iAnswer $answer) use ($subQuestion) {
return [
'text' => $answer->getLabel(),
'icon' => 'asterisk',
'tags' => ["{$subQuestion->getCode()} == \"{$answer->getCode()}\""]
];

}, $question->getAnswers()));
}
foreach($survey->groups as $group) {
$groupTree = [];
foreach ($group->questions as $question) {
// Check subquestions.
if ($question->hasSubQuestions) {
$subQuestions = [];
/** @var \ls\interfaces\iSubQuestion $subQuestion */
foreach ($question->getSubQuestions() as $subQuestion) {
if ($question->hasAnswers) {
$children = array_values(array_map(function (\ls\interfaces\iAnswer $answer) use ($subQuestion) {
return [
'text' => $answer->getLabel(),
'icon' => 'asterisk',
'tags' => ["{$subQuestion->getCode()} == \"{$answer->getCode()}\""]
];

$node = [
'text' => $subQuestion->getLabel(),
'children' => $question->hasAnswers ? $children : null,
'icon' => !$question->hasAnswers ? 'pencil' : 'th-list'
];
}, $question->getAnswers()));
}

$subQuestions[] = $node;
}
$tree[] = [
'text' => $question->displayLabel,
'children' => $subQuestions
];
} elseif ($question->hasAnswers) {
$children = array_values(array_map(function (\ls\interfaces\iAnswer $answer) use ($question) {
return [
'text' => $answer->getLabel(),
'icon' => 'asterisk',
'tags' => ["{$question->title} == \"{$answer->getCode()}\""]
];
$node = [
'text' => $subQuestion->getLabel(),
'children' => $question->hasAnswers ? $children : null,
'icon' => !$question->hasAnswers ? 'pencil' : 'th-list'
];

}, $question->getAnswers()));
$tree[] = [
'text' => $question->getDisplayLabel(),
'children' => $children,
$subQuestions[] = $node;
}
$groupTree[] = [
'text' => $question->displayLabel,
'children' => $subQuestions
];
} elseif ($question->hasAnswers) {
$children = array_values(array_map(function (\ls\interfaces\iAnswer $answer) use ($question) {
return [
'text' => $answer->getLabel(),
'icon' => 'asterisk',
'tags' => ["{$question->title} == \"{$answer->getCode()}\""]
];

];
}, $question->getAnswers()));
$groupTree[] = [
'text' => $question->getDisplayLabel(),
'children' => $children,

}
];

else {
$tree[] = [
'text' => $question->getDisplayLabel(),
'icon' => 'pencil'
];
} else {
$groupTree[] = [
'text' => $question->getDisplayLabel(),
'icon' => 'pencil'
];

}
}
$tree[] = [
'children' => $groupTree,
'text' => $group->title
];
}

//vdd($tree);
//
$this->widget(\SamIT\Yii1\Widgets\BootstrapTreeView::class, [
Expand Down

0 comments on commit f7b1c83

Please sign in to comment.