Exemplo n.º 1
0
 /**
  * Handle Confirm (Stage 4)
  *
  * @param array $post        	
  * @param Form $form        	
  * @param boolean $reload        	
  *
  * @return mixed
  */
 protected function handleConfirm($post, $form, $reload = false)
 {
     $outcome = false;
     $valid = false;
     $request = $this->getRequest();
     $invalid = false;
     $form->setData($post);
     if ($form->isValid()) {
         if ($post && isset($post['match'], $post['leadTmpFile'])) {
             $match = $post['match'];
             if (Helper::is_json($match)) {
                 $match = json_decode($match, true);
             }
             $company = $post['Company'];
             $tmp_file = $this->getUploadPath() . '/' . $post['leadTmpFile'];
             $duplicates = isset($post['duplicate']) ? $post['duplicate'] : false;
             $importFieldset = $form->getImportFieldset();
             $form->addConfirmField();
             $csv = $this->parseFile($tmp_file);
             if ($csv['count']) {
                 $data = $this->mapImportedValues($csv['body'], $match, false);
                 $valid = $this->validateImportData($data, $duplicates);
                 if ($valid) {
                     $outcome = true;
                     $headings = $this->getHeadings();
                     $invalid = array_filter($valid);
                     $form = $this->addImportFields($form, $data, $valid);
                     $form->get('submit')->setValue('Confirm');
                     $form->addCancelField();
                     $form->addHiddenField('Company', $company);
                     $this->stage = 4;
                     $this->results['stage'] = $this->stage;
                     $this->results['fields'] = $form->getLeadAttributes();
                     $this->results['data'] = $data;
                     $this->results['valid'] = $valid;
                     $this->results['form'] = $form;
                     $this->results['headings'] = $headings;
                     $this->setImportCache($this->stage, $post);
                 }
             }
             if (!$valid || $valid === $invalid) {
                 $outcome = false;
                 $message = "No valid records could be imported.";
                 $this->flashMessenger()->addErrorMessage($message);
             }
         }
     } else {
         $message = "You have invalid Form Entries.";
         $this->flashMessenger()->addErrorMessage($message);
         $messages = $form->getMessages();
         if ($messages) {
             $this->flashMessenger()->addErrorMessage($this->formatFormMessages($form));
         }
     }
     return $outcome;
 }