示例#1
0
 /**
  * XLS file type
  * @param array \Jazzee\Entity\Applicant $applicants
  */
 protected function makeXls(array $applicants, \Jazzee\Interfaces\Display $display)
 {
     $pageAnswerCount = $this->_em->getRepository('Jazzee\\Entity\\Application')->getPageAnswerCounts($this->_application);
     $rows = array();
     $header = array();
     foreach ($display->listElements() as $displayElement) {
         if ($displayElement->getType() == 'applicant') {
             $header[] = $displayElement->getTitle();
         } else {
             $applicationPage = $this->_application->getApplicationPageByChildPageId($displayElement->getPageId());
             for ($i = 1; $i <= $pageAnswerCount[$applicationPage->getPage()->getId()]; $i++) {
                 $header[] = $applicationPage->getTitle() . ' ' . $i . ' ' . $displayElement->getTitle();
             }
         }
     }
     $fileName = tempnam($this->_config->getVarPath() . '/tmp/', 'applicants_download');
     $handle = fopen($fileName, 'w+');
     $this->writeXlsFile($header, $handle);
     foreach ($applicants as $id) {
         $applicant = $this->_application->formatApplicantDisplayArray($this->_em->getRepository('Jazzee\\Entity\\Applicant')->findArray($id, $display));
         $arr = array();
         foreach ($display->listElements() as $displayElement) {
             if ($displayElement->getType() == 'applicant') {
                 if (is_numeric($displayElement->getName())) {
                     $arr[$displayElement->getName()] = 'no';
                     foreach ($applicant['tags'] as $tag) {
                         if ($tag['id'] == $displayElement->getName()) {
                             $arr[$displayElement->getName()] = 'yes';
                             break;
                         }
                     }
                 } else {
                     switch ($displayElement->getName()) {
                         case 'isLocked':
                             $arr['isLocked'] = $applicant['isLocked'] ? 'yes' : 'no';
                             break;
                         case 'lockedAt':
                             $arr[$displayElement->getName()] = $applicant['decision'] ? is_null($applicant['decision']['lockedAt']) ? '' : $applicant['decision']['lockedAt']->format('c') : '';
                             break;
                         case 'hasPaid':
                             $arr['hasPaid'] = $applicant['hasPaid'] ? 'yes' : 'no';
                             break;
                         case 'lastLogin':
                             $arr['lastLogin'] = !is_null($applicant['lastLogin']) ? $applicant['lastLogin']->format('c') : 'never';
                             break;
                         case 'updatedAt':
                         case 'createdAt':
                             $arr[$displayElement->getName()] = $applicant['updatedAt']->format('c');
                             break;
                         case 'decision':
                             $arr['decision'] = $applicant['decision'] ? $applicant['decision']['status'] : 'none';
                             break;
                         case 'percentComplete':
                             $arr['percentComplete'] = $applicant['percentComplete'] * 100 . '%';
                             break;
                         case 'attachments':
                             $values = array();
                             foreach ($applicant['attachments'] as $attachment) {
                                 $values[] = $attachment['displayValue'];
                             }
                             $arr[$displayElement->getName()] = implode(',', $values);
                             break;
                         case 'status_declined':
                             $arr[$displayElement->getName()] = $applicant['decision'] ? is_null($applicant['decision']['declineOffer']) ? 'no' : 'yes' : 'no';
                             break;
                         case 'status_admitted':
                             $arr[$displayElement->getName()] = $applicant['decision'] ? is_null($applicant['decision']['finalAdmit']) ? 'no' : 'yes' : 'no';
                             break;
                         case 'status_denied':
                             $arr[$displayElement->getName()] = $applicant['decision'] ? is_null($applicant['decision']['finalDeny']) ? 'no' : 'yes' : 'no';
                             break;
                         case 'status_accepted':
                             $arr[$displayElement->getName()] = $applicant['decision'] ? is_null($applicant['decision']['acceptOffer']) ? 'no' : 'yes' : 'no';
                             break;
                         case 'status_nominate_admit':
                             $arr[$displayElement->getName()] = $applicant['decision'] ? is_null($applicant['decision']['nominateAdmit']) ? 'no' : 'yes' : 'no';
                             break;
                         case 'status_nominate_deny':
                             $arr[$displayElement->getName()] = $applicant['decision'] ? is_null($applicant['decision']['nominateDeny']) ? 'no' : 'yes' : 'no';
                             break;
                         default:
                             if (array_key_exists($displayElement->getName(), $applicant)) {
                                 $arr[$displayElement->getName()] = $applicant[$displayElement->getName()];
                             }
                     }
                 }
             } else {
                 $applicationPage = $this->_application->getApplicationPageByChildPageId($displayElement->getPageId());
                 $pageArr = array();
                 foreach ($applicant['pages'] as $page) {
                     if ($page['id'] == $applicationPage->getPage()->getId()) {
                         $pageArr = $page;
                     }
                 }
                 for ($i = 0; $i < $pageAnswerCount[$applicationPage->getPage()->getId()]; $i++) {
                     $value = '';
                     if (isset($pageArr['answers']) and array_key_exists($i, $pageArr['answers'])) {
                         $value = $applicationPage->getJazzeePage()->getDisplayElementValueFromArray($pageArr['answers'][$i], $displayElement);
                     }
                     $arr[$displayElement->getType() . $displayElement->getName() . $displayElement->getPageId() . $i] = $value;
                 }
             }
         }
         $this->writeXlsFile($arr, $handle);
     }
     rewind($handle);
     fclose($handle);
     $this->setVar('outputType', 'file');
     $this->setVar('type', 'text/xls');
     $this->setVar('filename', $this->_application->getProgram()->getShortName() . '-' . $this->_application->getCycle()->getName() . date('-mdy') . '.xls');
     $this->setVar('filePath', $fileName);
 }