From 72860964ff86f9a532acd24529352f4e727a6a76 Mon Sep 17 00:00:00 2001 From: Peter Rotich <peter@enhancesoft.com> Date: Sat, 19 Oct 2013 18:20:20 +0000 Subject: [PATCH] Make help topic form optional --- include/api.tickets.php | 13 +++++++------ include/class.topic.php | 14 +++++++++++++- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/include/api.tickets.php b/include/api.tickets.php index 81dac7a92..25cc9c4d1 100644 --- a/include/api.tickets.php +++ b/include/api.tickets.php @@ -18,15 +18,16 @@ class TicketApiController extends ApiController { ); # Fetch dynamic form field names for the given help topic and add # the names to the supported request structure - if (isset($data['topicId'])) { - $topic=Topic::lookup($data['topicId']); - $form=DynamicForm::lookup($topic->ht['form_id']); + if (isset($data['topicId']) + && ($topic = Topic::lookup($data['topicId'])) + && ($form = $topic->getForm())) { foreach ($form->getDynamicFields() as $field) $supported[] = $field->get('name'); } - $form = TicketForm::lookup()->instanciate(); - foreach ($form->getDynamicFields() as $field) - $supported[] = $field->get('name'); + + if(($form = TicketForm::lookup()->instanciate())) + foreach ($form->getDynamicFields() as $field) + $supported[] = $field->get('name'); if(!strcasecmp($format, 'email')) { $supported = array_merge($supported, array('header', 'mid', diff --git a/include/class.topic.php b/include/class.topic.php index 688cb7aaa..140e44e6b 100644 --- a/include/class.topic.php +++ b/include/class.topic.php @@ -21,6 +21,7 @@ class Topic { var $parent; var $page; + var $form; function Topic($id) { $this->id=0; @@ -44,7 +45,7 @@ class Topic { $this->ht = db_fetch_array($res); $this->id = $this->ht['topic_id']; - $this->page = null; + $this->page = $this->form = null; return true; @@ -108,6 +109,17 @@ class Topic { return $this->page; } + function getFormId() { + return $this->ht['form_id']; + } + + function getForm() { + if(!$this->form && $this->getFormId()) + $this->form = DynamicForm::lookup($this->getFormId()); + + return $this->form; + } + function autoRespond() { return (!$this->ht['noautoresp']); } -- GitLab