/**
  * Handles client editing
  *
  * Choosing a person involves going through a whole person finding process
  * at a different url.  Once the user has chosen a new person, they will
  * return here, passing in the person_id they have chosen
  *
  * @param REQUEST client_id   Existing issues are edited by passing in an Issue
  * @param REQUEST person_id  The new contactPerson
  */
 public function update()
 {
     // Load the $client for editing
     if (isset($_REQUEST['client_id']) && $_REQUEST['client_id']) {
         try {
             $client = new Client($_REQUEST['client_id']);
         } catch (\Exception $e) {
             $_SESSION['errorMessages'][] = $e;
             header('Location: ' . BASE_URL . '/clients');
             exit;
         }
     } else {
         $client = new Client();
     }
     if (isset($_REQUEST['person_id'])) {
         $client->setContactPerson_id($_REQUEST['person_id']);
     }
     // Handle stuff the user POSTS
     if (isset($_POST['name'])) {
         $client->handleUpdate($_POST);
         try {
             $client->save();
             header('Location: ' . BASE_URL . '/clients');
             exit;
         } catch (\Exception $e) {
             $_SESSION['errorMessages'][] = $e;
         }
     }
     $this->template->blocks[] = new Block('clients/updateClientForm.inc', array('client' => $client));
 }
예제 #2
0
 public function testSaveAndLoad()
 {
     $name = 'Test Client';
     $client = new Client();
     $client->setName($name);
     $client->setContactPerson_id($this->testPersonId);
     $client->save();
     $id = $client->getId();
     $api_key = $client->getApi_key();
     $this->assertNotEmpty($id);
     $this->assertNotEmpty($api_key);
     $client = new Client($id);
     $this->assertEquals($api_key, $client->getApi_key());
     $client = Client::loadByApiKey($api_key);
     $this->assertEquals($id, $client->getId());
 }