/** * Add a contract. */ public function addAction() { // Wrap the whole thing in a try/catch. try { // Create an array of the fields that represent the contract. $data = array('contract_num' => $this->getStr('contract_num'), 'description' => $this->getStr('description'), 'job_code' => $this->getStr('job_code'), 'admin' => $this->getBool('admin'), 'active' => $this->getBool('active')); // Get the DAO. $contractDao = new ContractDao(); // Add the contract. $id = $contractDao->add($data); // Retrieve the new contract. $contract = $contractDao->get($id); // Make sure the contract was returned. if (isset($contract)) { // Create the JSON object to return. $json = new stdClass(); $json->success = true; $json->msg = 'The contract was created successfully.'; $json->contract = $contract; } else { // Create the error JSON object to return. $json = new stdClass(); $json->success = false; $json->msg = 'Failed to create the contract.'; } } catch (Zend_Exception $ex) { // Create the error JSON object to return. $json = new stdClass(); $json->success = false; $json->msg = $ex->getMessage(); } // Return the JSON. $this->_helper->json($json); }