/** * @param SurveyPurpose $purpose * @param SurveyRequestStep1 $formModel * @return string */ function showPurpose(SurveyPurpose $purpose, SurveyRequestStep1 $formModel) { $name = 'SurveyRequestStep1[purposes][]'; $id = "ytSurveyRequestStep1_purposes_" . $purpose->id; $value = $purpose->id; $isChecked = in_array($purpose->id, $formModel->purposes); $hasInnerBlock = !empty($purpose->children); $elem = '<div class="checkbox">'; // $elem .= '<input id="'.$id.'" type="hidden" value="'.$value.'" name="'.$name.'">'; $elem .= '<label class="control-label">'; $elem .= '<input class="' . ($hasInnerBlock ? 'has-inner-block' : '') . '" name="' . $name . '" id="' . $id . '" value="' . $value . '" ' . ($isChecked ? 'checked="checked"' : '') . ' type="checkbox" disabled="disabled">'; $elem .= $purpose->title; $elem .= '</label>'; $elem .= '</div>'; if ($hasInnerBlock) { $elem .= '<div class="margin-left-30" data-id="' . $id . '" style="' . ($isChecked ? '' : 'display: none;') . '">'; foreach ($purpose->children as $child) { $elem .= showPurpose($child, $formModel); } $elem .= '</div>'; } return $elem; }
/** * @param SurveyPurpose $purpose * @param SurveyRequestStep1 $formModel * @return string */ function showPurpose(SurveyPurpose $purpose, SurveyRequestStep1 $formModel) { $isChecked = in_array($purpose->id, $formModel->purposes); $hasInnerBlock = !empty($purpose->children); $res = ''; if (!$isChecked) { return $res; } $res .= $purpose->title; if ($hasInnerBlock) { $childBlock = ''; foreach ($purpose->children as $child) { $purposeContent = showPurpose($child, $formModel); if (strlen($purposeContent) > 0) { $childBlock .= '<li>' . $purposeContent . '</li>'; } } if (strlen($res) > 0) { $res .= '<ul>' . $childBlock . '</ul>'; } } return $res; }