['positionTitle', 'name']]; protected $_fileFields = ['documents']; protected function _addDependenciesFromDb(array &$data) { $this->getModel()->injectDependencies($data); $this->getModel()->injectStaticDependencies($data); return $this; } public function insert(array $data = []) { $data = empty($data) ? $this->_data : $data; $this->_primaryKey = $this->getModel()->insert($data); $this->_handleFiles(); return $this->_primaryKey; } public function update(array $data = []) { $data = empty($data) ? $this->_data : $data; $result = $this->getModel()->update($data, $this->_primaryKey); $this->_handleFiles(); return $result; } public function getList4ExportStatement() { $select = clone $this->getListSelect(); return $select->query(); } public function prepareExportRow(array &$row) { $this->getModel()->injectDependencies($row); $this->_prepareExportAddresses($row); $this->getModel()->injectStaticDependencies($row); $this->prepareExportRowQuestions($row); $this->prepareExportRowEducation($row); $this->prepareExportRowFormerEmployments($row); $this->prepareExportRowReferences($row); $this->prepareExportRowRelationships($row); $row['documents'] = Qs_FileFs::getUrl($row['documents']); return $this; } protected function _prepareExportAddresses(&$row) { foreach([AddressEntity::TYPE_MAILING] as $type) { $address = $row[$type]; foreach ((array) $address as $field => $value) { $row[$type . ucfirst($field)] = $value; } unset($row[$type]); } return $this; } private function prepareExportRowQuestions(array &$row) { $questions = $this->getModel()->getFullQuestionnaire(['employeeId' => $row['id']]); $options = $this->getConfigArray('yesNoOptions'); foreach ($questions as $question) { $row['question' . $question['id'] . 'answer'] = Qs_Array::get($options, $question['answer']); $row['question' . $question['id'] . 'explanation'] = $question['explanation']; } unset($row['questionnaire']); return $this; } private function prepareExportRowEducation(array &$row) { $educationList = Qs_Array::group($row['education'], 'type'); $institutionTypes = $this->getConfigArray('educationInstitutionTypes'); foreach ($institutionTypes as $type) { foreach ($type['labels'] as $labelIndex => $labelTitle) { $row['education' . ucfirst($type['type']) . ucfirst($labelIndex)] = $educationList[$type['type']][$labelIndex]; } } unset($row['education']); return $this; } private function prepareExportRowFormerEmployments(array &$row) { $this->prepareCsvListedData($row, 'formerEmployments', 'employment', 'formerEmployments'); return $this; } private function prepareExportRowReferences(array &$row) { $this->prepareCsvListedData($row, 'references', 'reference', 'references'); return $this; } private function prepareExportRowRelationships(array &$row) { $this->prepareCsvListedData($row, 'relationshipWithEmployers', 'relationship', 'relationshipWithEmployers'); return $this; } /** * @param array $row * @param $rowKey * @param $newRowIndexPrefix * @param $configCsvExportColumnsKey * @return $this */ private function prepareCsvListedData(array &$row, $rowKey, $newRowIndexPrefix, $configCsvExportColumnsKey) { $list = $row[$rowKey]; $number = 1; foreach ($list as $listItem) { foreach (array_keys($this->getConfigArray('csvExportColumns')[$configCsvExportColumnsKey]) as $field) { $row[$newRowIndexPrefix . $number . ucfirst($field)] = $listItem[$field]; } $number++; } unset($row[$rowKey]); return $this; } public function getExportCsvColumns() { $columns = $this->getConfigArray('csvExportColumns'); $this->injectCsvQuestionnaireColumns($columns); $this->injectCsvEducationColumns($columns); $this->injectCsvFormerEmploymentsColumns($columns); $this->injectCsvReferencesColumns($columns); $this->injectCsvRelationshipsColumns($columns); return $columns; } protected function injectCsvQuestionnaireColumns(array &$columns) { $newColumns = []; $questions = $this->getModel()->getUsedQuestions(); foreach ($questions as $question) { $newColumns['question' . $question['id'] . 'answer'] = $question['question']; $newColumns['question' . $question['id'] . 'explanation'] = 'Explanation'; } Qs_Array::mergeAssocAfter($columns, $newColumns, 'questionnaire'); unset($columns['questionnaire']); return $this; } protected function injectCsvEducationColumns(array &$columns) { $newColumns = []; $institutionTypes = $this->getConfigArray('educationInstitutionTypes'); foreach ($institutionTypes as $type) { foreach ($type['labels'] as $labelIndex => $labelTitle) { $newColumns['education' . ucfirst($type['type']) . ucfirst($labelIndex)] = $labelTitle; } } Qs_Array::mergeAssocAfter($columns, $newColumns, 'education'); unset($columns['education']); return $this; } protected function injectCsvFormerEmploymentsColumns(array &$columns) { $this->injectCsvListedDataColumns($columns, 'EmployeeFormerEmployment', 'formerEmployments', 'employment'); return $this; } protected function injectCsvReferencesColumns(array &$columns) { $this->injectCsvListedDataColumns($columns, 'EmployeeReference', 'references', 'reference'); return $this; } protected function injectCsvRelationshipsColumns(array &$columns) { $this->injectCsvListedDataColumns( $columns, 'EmployeeRelationshipWithEmployer', 'relationshipWithEmployers', 'relationship'); return $this; } /** * @param array $columns * @param $dataTableAlias * @param $configCsvExportColumnsKey * @param $newColumnPrefix * @return $this */ protected function injectCsvListedDataColumns( array &$columns, $dataTableAlias, $configCsvExportColumnsKey, $newColumnPrefix ) { $newColumns = []; $maxDataColumns = $this->getCsvExportMaxRelations($dataTableAlias); for ($number = 1; $number <= $maxDataColumns; $number++) { foreach ($columns[$configCsvExportColumnsKey] as $field => $title) { $newColumns[$newColumnPrefix . $number . ucfirst($field)] = str_replace('#', '#' . $number, $title); } } Qs_Array::mergeAssocAfter($columns, $newColumns, $configCsvExportColumnsKey); unset($columns[$configCsvExportColumnsKey]); return $this; } protected function getCsvExportMaxRelations($tableAlias) { $select = clone $this->getListSelect(); $select->join($this->_getPair($tableAlias, 'er'), '`er`.`employeeId` = `e`.`id`'); $select->reset(Zend_Db_Select::COLUMNS)->columns(['e.id', 'cnt' => 'COUNT(*)']); $select->reset(Zend_Db_Select::ORDER); $select->group('e.id'); $select->order('cnt DESC'); $select->limit(1); if (($row = $this->_db->fetchRow($select))) { return $row['cnt']; } return 0; } }