/** * Список соискателей (главная страница) * @return void */ public function indexAction() { if ($this->_authorize('applicants', 'view')) { $objFilterForm = new Form_Applicant_Filter(); $objVacancies = new Vacancies(); $objFilterForm->setVacancies($objVacancies->fetchAll()->toArray()); if ($this->getRequest()->isPost()) { $arrParams = $this->_request->getPost(); $vacancyId = (int) $arrParams['vacancyId']; $status = $arrParams['status']; $objFilterForm->populate($arrParams); } else { $vacancyId = -1; $status = -1; } $objApplicants = new Applicants(); $arrApplicants = $objApplicants->getApplicants($vacancyId, $status, $this->getRequest()->getParam('orderBy')); $objVT = new VacanciesTest(); $this->view->orderBy = $this->getRequest()->getParam('orderBy'); $this->view->arrApplicants = $arrApplicants; $this->view->arrTests = $objVT->getTestsA(); $this->view->objFilterForm = $objFilterForm; $this->view->can_edit = $this->isAllowed('applicants', 'edit'); $this->view->can_remove = $this->isAllowed('applicants', 'remove'); $this->view->can_change_status = $this->isAllowed('applicants', 'change_status'); } }
/** * Добавление/обновление вакансии * @return void */ public function editAction() { if ($this->_authorize('vacancies', 'edit')) { $form = new Form_Vacancy_Edit(); // выбираем из базы данные о редактируемой вакансии $objTest = new Tests(); $tests = $objTest->fetchAll()->toArray(); $objVT = new VacanciesTest(); //Добавляет тесты на форму $form->addElementsForm($tests); if ($this->getRequest()->isPost()) { if ($form->isValid($_POST)) { // Выполняем update (insert/update данных о вакансии) $objVacancies = new Vacancies(); $vacancyId = $form->vacancyId->getValue(); $objVacancy = $objVacancies->getObjectById($vacancyId); if (!$objVacancy instanceof Vacancy) { $objVacancy = $objVacancies->createRow(); } $objVacancy->name = $form->Name->getValue(); $objVacancy->num = $form->Num->getValue(); $objVacancy->duties = $form->Duties->getValue(); $objVacancy->requirements = $form->Requirements->getValue(); $idSaveVacancy = $objVacancy->save(); $test = $this->keyReplace($form->getValues(), 'test_'); $objVT->delete('vacancy_id = ' . $idSaveVacancy); foreach ($test as $testId => $val) { if ($val) { $newRow = $objVT->createRow(array('vacancy_id' => $idSaveVacancy, 'test_id' => $testId)); $newRow->save(); } } $this->_helper->redirector('index', 'vacancy'); } } else { $vacancyId = (int) $this->getRequest()->getParam('vacancyId'); if ($vacancyId != '') { // выбираем из базы данные о редактируемой вакансии $vacancies = new Vacancies(); $objVacancy = $vacancies->getObjectById($vacancyId); if ($objVacancy instanceof Vacancy) { $this->view->objVacancy = $objVacancy; $form->populate(array('Name' => $objVacancy->name, 'Num' => $objVacancy->num, 'Duties' => $objVacancy->duties, 'Requirements' => $objVacancy->requirements, 'vacancyId' => $objVacancy->id)); } $testIds = $objVT->getTestIds($vacancyId); // отмечаем выбранные тесты foreach ($testIds as $id) { $form->populate(array('test_' . $id => 1)); } } } $this->view->objVacancyEditForm = $form; } }