/** * @param Context $context * @param Request $request */ public function _execute($context, $request) { $form = $this->getDocumentInstanceFromRequest($request); $request->setAttribute('form', $form); // determine output type if ($request->hasParameter('output')) { $output = ucfirst(strtolower($request->getParameter('output'))); } if (empty($output)) { $output = ucfirst(K::HTML); } if ($request->getParameter('all') == 'all') { $request->setAttribute('all', 'all'); } $className = 'form_Export' . $output . 'View'; if (!f_util_ClassUtils::classExists($className)) { throw new Exception('Unable to format output as "' . $output . '".'); } $request->setAttribute('form', $form); return $output; }
/** * @param block_BlockContext $context * @param block_BlockRequest $request * @return String the view name */ public function execute($context, $request) { $id = $this->getFormId(); if (empty($id)) { return block_BlockView::NONE; } $form = DocumentHelper::getDocumentInstance($id); if (!$form->isPublished()) { return block_BlockView::NONE; } $form->getDocumentNode()->getDescendents(); $this->setParameter('form', $form); if ($context->inBackofficeMode()) { return block_BlockView::DUMMY; } if ($request->hasParameter("receiverIds")) { $receiverIds = explode(",", $request->getParameter("receiverIds")); $receiverLabels = array(); foreach ($receiverIds as $receiverId) { if (is_numeric($receiverId)) { try { $receiver = DocumentHelper::getDocumentInstance($receiverId); $receiverLabels[] = $receiver->getLabel(); } catch (Exception $e) { Framework::exception($e); $receiverLabels[] = $receiverId; } } elseif (f_util_StringUtils::isNotEmpty($receiverId)) { $receiverLabels[] = $receiverId; } } $this->setParameter("receiverLabels", $receiverLabels); } if ($this->isSuccess($context, $request)) { $view = block_BlockView::SUCCESS; } else { if ($this->isFormPosted($request)) { $fs = form_FormService::getInstance(); try { $fs->saveFormData($form, $request); $user = $context->getGlobalContext()->getUser(); $user->setAttribute('form_success_parameters_' . $form->getId(), $request->getParameters()); $view = block_BlockView::SUCCESS; } catch (form_FormValidationException $e) { $this->setParameter('errors', $e->getErrorCollection()); $view = block_BlockView::INPUT; } } else { $view = block_BlockView::INPUT; } } // Calls the BlockFormDecorator if present. $formId = $form->getFormid(); $matches = null; if (preg_match('#^modules_([a-z]+)/([a-z]+)$#', $formId, $matches)) { $extendClassName = $matches[1] . '_BlockForm' . ucfirst($matches[2]) . 'Decorator'; if (f_util_ClassUtils::classExists($extendClassName)) { $instance = new $extendClassName($this); if ($instance instanceof form_BlockFormDecorator) { $instance->execute($context, $request); } else { Framework::warn("\"{$extendClassName}\" is not an instance of \"block_BlockDecorator\": form \"{$formId}\" won't be decorated."); } } } return $view; }