public function saveRelativesInfo($data_array) { foreach ($data_array as $key => $value) { if (empty($value)) { unset($data_array[$key]); } } if (!empty($data_array)) { $member_id = $this->getMember_id(); $relation_id = $data_array['relation_id']; $info = $this->fetchRelativeInfo($relation_id); $data_array['member_id'] = $member_id; if ($info == false) { $relatives_object = new Core_Model_MemberRelatives(); $relatives_object->initSave(); $preparedData = $relatives_object->prepareDataForSaveProcess($data_array); return $relatives_object->getMapper()->save($preparedData); } else { $relatives_object = new Core_Model_MemberRelatives(); $relatives_object->initSave(); unset($data_array['member_id']); $prepared_data = $relatives_object->prepareDataForSaveProcess($data_array); return $relatives_object->getMapper()->update($prepared_data, $member_id, $relation_id); } } }
public function searchAction() { $this->_helper->viewRenderer->setNoRender(true); $this->_helper->layout()->disableLayout(); $request = $this->getRequest(); $param_view = array_diff($request->getParams(), $request->getUserParams()); $format = $this->_getParam('format', 'log'); $params = $param_view['myarray']; $member_ids = array(); $member_ids = $this->fetchAllStudents(); if (empty($member_ids)) { return $this->returnResult($format, false); } $member_ids = $this->combineResult($member_ids, $member_ids); $batch_member_ids = array(); $department_member_ids = array(); $programme_member_ids = array(); $personal_matches = array(); $rel_matches = array(); $student = new Core_Model_Member_Student(); $critical_fields = array(); $rel_fields = array(); if (!empty($params)) { if (!empty($params['programme_id'])) { $p_search = $this->programmeSearch($params['programme_id']); if (empty($p_search)) { return $this->returnResult($format, false); } } $member_ids = $this->combineResult($member_ids, $programme_member_ids); Zend_Registry::get('logger')->debug($member_ids); if (!empty($params['discipline_id'])) { $d_search = $this->disciplineSearch($params['discipline_id']); Zend_Registry::get('logger')->debug($d_search); if (empty($p_search)) { return $this->returnResult($format, false); } } if (!empty($d_search)) { $member_ids = array_intersect($member_ids, $d_search); } if (!empty($params['batch_start'])) { $b_search = $this->batchStartSearch($params['batch_start']); if (empty($b_search)) { return $this->returnResult($format, false); } } $member_ids = $this->combineResult($member_ids, $batch_member_ids); foreach ($params as $key => $value) { switch (substr($key, 0, 1)) { case '0': $critical_key = substr($key, 1); $critical_fields[$critical_key] = $params[$key]; break; case '1': $rel_key = substr($key, 1); $rel_fields[$rel_key] = $params[$key]; break; default: //throw new Exception('invalid params'); break; } } if (!empty($critical_fields)) { $critical_range_fields = array('dob' => ''); $critical_range_params = array_intersect_key($critical_fields, $critical_range_fields); $critical_exact_params = array_diff_key($critical_fields, $critical_range_params); $student = new Core_Model_Member_Student(); $personal_matches = $student->search($critical_exact_params, $critical_range_params); if (empty($personal_matches)) { return $this->returnResult($format, false); } } $member_ids = $this->combineResult($member_ids, $personal_matches); if (!empty($rel_fields)) { $rel_range_fields = array('annual_income' => ''); $rel_range_params = array_intersect_key($rel_fields, $rel_range_fields); $rel_exact_params = array_diff_key($rel_fields, $rel_range_params); $relatives = new Core_Model_MemberRelatives(); $rel_matches = $relatives->search($rel_exact_params, $rel_range_params); if (empty($rel_matches)) { return $this->returnResult($format, false); } } $member_ids = $this->combineResult($member_ids, $rel_matches); } $this->returnResult($format, $member_ids); }