public function executePrevschoolPost() { $this->getEnquirer(); if (!$this->filterUser(true)) { $this->jsonwrapper->print_json(array('success' => false, 'code' => 'security', 'message' => 'You must login to access this url.')); } $applicant = $this->pmbTools->getApplicant($this->user); if (!$applicant) { $this->jsonwrapper->show_json_error('Permission', 'You dont have permission to access this page'); } if ($applicant->getStatus() != StudentDetail::GRADUATE) { $this->jsonwrapper->show_json_error('Permission', 'You dont have permission to access this page'); } $param = $this->getAllRequestParameter(); $valid = true; $error_message = array(); /* School Name */ if (empty($param['schoolname'])) { $error_message[] = array('field' => 'schoolname', 'message' => 'Please enter School Name'); $valid = false; } /* Academic Year */ if (empty($param['acyear'])) { $error_message[] = array('field' => 'acyear', 'message' => 'Please enter Academic Year'); $valid = false; } /* Grade */ if (empty($param['grade'])) { $error_message[] = array('field' => 'grade', 'message' => 'Please enter Grade'); $valid = false; } /* Language of Instruction */ if (empty($param['lang'])) { $error_message[] = array('field' => 'lang', 'message' => 'Please enter Language of Instruction'); $valid = false; } if (!$valid) { $this->jsonwrapper->print_json(array('success' => false, 'code' => 'notvalid', 'message' => 'data anda belum lengkap', 'error' => $error_message)); } if (empty($param['id'])) { $education = new TestApplicantEducations(); } else { $c = new Criteria(); $c->add(TestApplicantEducationsPeer::ID, $param['id'], Criteria::EQUAL); $c->add(TestApplicantEducationsPeer::TEST_APPLICANT_ID, $applicant->getId(), Criteria::EQUAL); $education = TestApplicantEducationsPeer::doSelectOne($c); if (!$education) { $this->jsonwrapper->show_json_error('notfound', 'Education not found'); } } $connection = Propel::getConnection('propel'); $connection->begin(); $education->setTestApplicantId($applicant->getId()); $education->setSchoolOfOrigin($param['schoolname']); $education->setClassOfOrigin($param['grade']); $education->setLanguageInstruction($param['lang']); $education->setAcademicYear($param['acyear']); try { $education->save(); } catch (Exception $e) { $connection->rollback(); $this->jsonwrapper->print_json(array('success' => false, 'code' => 'fail', 'message' => 'Error while save the data, please try again later.', 'message2' => 'Error save education history - education history')); } $connection->commit(); $education->save(); $data = $education->toArray(); /* Hehehe */ $this->jsonwrapper->print_json(array('success' => true, 'code' => 'success', 'message' => 'Data successfully saved', 'data' => $data, 'href' => $this->pmbTools->pmbUrl('data/educationhistory'))); /* ---- */ }