/**
  * @return form_ResponseService
  */
 public static function getInstance()
 {
     if (self::$instance === null) {
         self::$instance = self::getServiceClassInstance(get_class());
     }
     return self::$instance;
 }
 public function _execute($context, $request)
 {
     $this->setTemplateName('Form-Responses', K::HTML);
     $form = $request->getAttribute('form');
     $this->setAttribute('form', $form);
     $query = form_ResponseService::getInstance()->createQuery()->add(Restrictions::eq('parentForm', $form))->addOrder(Order::desc('document_creationdate'));
     if ($request->getAttribute('all') != 'all') {
         $query->add(Restrictions::published());
     }
     $responses = $query->find();
     $this->setAttribute('responsesCount', count($responses));
     $responsesInfos = array();
     foreach ($responses as $response) {
         $responsesInfos[] = $response->getResponseInfos();
     }
     $this->setAttribute('responses', $responsesInfos);
 }
 /**
  * @param form_persistentdocument_baseform $form
  * @param block_BlockRequest $request
  * @return void
  */
 public function saveFormData($form, $request)
 {
     $errors = new validation_Errors();
     $this->validate($form, $request, $errors);
     if (!$errors->isEmpty()) {
         throw new form_FormValidationException("Form does not validate", $errors);
     }
     $domDoc = new DOMDocument('1.0', 'utf-8');
     $domDoc->formatOutput = true;
     $rootElm = $domDoc->createElement('response');
     $rootElm->setAttribute('lang', RequestContext::getInstance()->getLang());
     $rootElm->setAttribute('date', date('Y-m-d H:i:s'));
     $domDoc->appendChild($rootElm);
     $fields = $this->getSortedFields($form);
     $replyTo = null;
     $acknowledgmentReceiver = null;
     $this->doMakeXmlResponse($domDoc, $rootElm, $request, $replyTo, $acknowledgmentReceiver, $form);
     $response = form_ResponseService::getInstance()->getNewDocumentInstance();
     $response->setContents($domDoc->saveXML());
     $response->setLabel(f_Locale::translate("&modules.form.bo.general.Form-response-title;", array('form' => $form->getLabel())));
     // Handle specific treatments.
     $result = $this->handleData($form, $fields, $response, $request, $replyTo);
     // Acknowledgment.
     if ($result['success'] && $form->getAcknowledgment() && $acknowledgmentReceiver !== null) {
         if (!$this->sendAcknowledgement($form, $response, $request, $result, $acknowledgmentReceiver, $replyTo)) {
             Framework::info(__METHOD__ . " An error occured during acknowledgment sending to " . $acknowledgmentReceiver);
         }
     }
     return $result;
 }
 /**
  * @param form_persistentdocument_baseform $document
  * @return Integer
  */
 public function fileResponses($document)
 {
     try {
         $this->tm->beginTransaction();
         $count = form_ResponseService::getInstance()->fileForForm($document);
         if ($count > 0) {
             $document->setArchivedResponseCount($document->getArchivedResponseCount() + $count);
             if ($document->isModified()) {
                 $this->pp->updateDocument($document);
             }
         }
         $this->tm->commit();
         return $count;
     } catch (Exception $e) {
         $this->tm->rollBack($e);
     }
     return 0;
 }
 /**
  * @return form_persistentdocument_response
  */
 protected function initPersistentDocument()
 {
     return form_ResponseService::getInstance()->getNewDocumentInstance();
 }