public function exportAction()
 {
     $sl = $this->getServiceLocator();
     $request = $this->getRequest();
     $filters = $sl->get('FormElementManager')->get('\\Application\\Form\\LeadFilterForm');
     $results = array();
     $leadForm = new LeadForm();
     $labels = array();
     $headings = array();
     $lead = new LeadEntity();
     $form = new FormEntity();
     $detail = new DetailEntity();
     $data = $request->getQuery();
     $fdata = array();
     $order = 'desc';
     $sort = 'lead.id';
     if ($data) {
         $filters->setData($data);
         if ($filters->isValid()) {
             $fdata = $filters->getData();
         }
     }
     $collection = array('lead' => $lead, 'form' => $form, 'detail' => $detail);
     foreach (array_keys($collection) as $fieldsetName) {
         $fieldset = $leadForm->get($fieldsetName);
         foreach ($fieldset as $name => $element) {
             $labels["{$fieldsetName}[{$name}]"] = $element->getLabel();
         }
     }
     foreach ($collection as $name => $entity) {
         $data = $entity->getArrayCopy();
         unset($data['array_copy']);
         foreach (array_keys($data) as $heading) {
             $headings[] = isset($labels["{$name}[{$heading}]"]) ? $labels["{$name}[{$heading}]"] : "{$name}[{$heading}]";
         }
     }
     // grab the paginator from the LeadTable
     $submissions = $this->getSubmissionMapper()->fetchAll(false, $sort, $order, $fdata);
     return $this->csvExport('Lead Report (' . date('Y-m-d') . ').csv', $headings, $submissions, array($this, 'extractSubmission'));
 }
 public function update($id, $data)
 {
     $result = null;
     $data['id'] = $id;
     $submission = $this->getSubmissionMapper()->getSubmission($id);
     $form = new LeadForm();
     $form->bind($submission);
     $form->setData($data);
     if ($form->isValid()) {
         $id = $this->getSubmissionMapper()->saveSubmission($submission);
     } else {
         return $this->errorResponse->errorHandler(400, "Invalid Submission.");
     }
     if ($id) {
         $result = $this->get($id);
     }
     return $result;
 }