コード例 #1
0
 /**
  * Update a contract.
  */
 public function updateAction()
 {
     // 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 id of the contract to modify.
         $id = $this->getInt('id');
         // Make sure the id is set.
         if (isset($id)) {
             // Update the contract.
             $contractDao = new ContractDao();
             // Save the new values.
             $contractDao->save($id, $data);
             // Retrieve the updated 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 updated successfully.';
                 $json->contract = $contract;
             } else {
                 // Create the error JSON object to return.
                 $json = new stdClass();
                 $json->success = false;
                 $json->msg = 'Failed to update the contract.';
             }
         } else {
             // Create the error JSON object to return.
             $json = new stdClass();
             $json->success = false;
             $json->msg = 'The id of the contract to modify must ' . 'be specified.';
         }
     } 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);
 }