Skip to content
Snippets Groups Projects
Commit ef8acc8e authored by Peter Rotich's avatar Peter Rotich
Browse files

Merge pull request #5 from greezybacon/issue/hide-empty-forms

topic: forms: Hide forms with no visible fields
parents 51abf377 42b66993
Branches
Tags
No related merge requests found
......@@ -25,6 +25,8 @@ class DynamicFormsAjaxAPI extends AjaxController {
}
foreach ($topic->getForms() as $form) {
if (!$form->hasAnyVisibleFields())
continue;
ob_start();
$form->getForm($_SESSION[':form-data'])->render(!$client);
$html .= ob_get_clean();
......
......@@ -125,6 +125,23 @@ class DynamicForm extends VerySimpleModel {
}
}
function hasAnyVisibleFields($user=false) {
global $thisstaff, $thisclient;
$user = $user ?: $thisstaff ?: $thisclient;
$visible = 0;
$isstaff = $user instanceof Staff;
foreach ($this->getFields() as $F) {
if ($isstaff) {
if ($F->isVisibleToStaff())
$visible++;
}
elseif ($F->isVisibleToUsers()) {
$visible++;
}
}
return $visible > 0;
}
function instanciate($sort=1) {
return DynamicFormEntry::create(array(
'form_id'=>$this->get('id'), 'sort'=>$sort));
......
......@@ -82,14 +82,7 @@ if ($info['topicId'] && ($topic=Topic::lookup($info['topicId']))) {
</tbody>
<tbody id="dynamic-form">
<?php foreach ($forms as $form) {
$hasFields = false;
foreach ($form->getFields() as $f) {
if ($f->isVisibleToUsers()) {
$hasFields = true;
break;
}
}
if (!$hasFields)
if (!$form->hasAnyVisibleFields())
continue;
include(CLIENTINC_DIR . 'templates/dynamic-form.tmpl.php');
} ?>
......
......@@ -263,14 +263,7 @@ if ($_POST)
<tbody id="dynamic-form">
<?php
foreach ($forms as $form) {
$hasFields = false;
foreach ($form->getFields() as $f) {
if ($f->isVisibleToStaff()) {
$hasFields = true;
break;
}
}
if (!$hasFields)
if (!$form->hasAnyVisibleFields())
continue;
print $form->getForm()->getMedia();
include(STAFFINC_DIR . 'templates/dynamic-form.tmpl.php');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment