Esempio n. 1
0
 /**
  * Create resource wrapping contact
  *
  * @param  Contact  $contact
  * @param  string   $selfRoute  Name of route to generate self link from
  * @param  string[] $selfParams Route params to use when generating self link
  * @return Resource
  */
 public function createContactResource(Contact $contact, $selfRoute = 'contacts.item.read', array $selfParams = [])
 {
     $selfParams = $selfParams ?: ['id' => $contact->getId()];
     $resource = new Resource($this->generator->generate($selfRoute, $selfParams), $this->contactArrayizer->toArray($contact));
     if ($contact->getAccountWrapper()->getAccount()->getBankName() == 'Unknown') {
         $resource->addWarningMessage(sprintf("Kontonumret %s hos kontakterson %s verkar inte vara giltigt. Var god kontrollera numret.", $contact->getAccountWrapper()->getAccount(), $contact->getName()));
     }
     return $resource->addLink('edit', $this->generator->generate('contacts.item.read', ['id' => $contact->getId()]))->addLink('collection', $this->generator->generate('contacts.coll.read'))->addLink('wb:claim-collection', $this->generator->generate('contacts.item.claims', ['id' => $contact->getId()]));
 }
Esempio n. 2
0
 /**
  * Validate that contact data does not exist in db
  *
  * @param  Contact $new
  * @return void
  * @throws \RuntimeException If validation fails
  */
 private function validate(Contact $new)
 {
     foreach ($this->readAll() as $curr) {
         if ($new->getId() == $curr->getId()) {
             continue;
         }
         if ($new->getName() == $curr->getName()) {
             throw new \RuntimeException("Kan ej skapa KP: {$curr->getName()} finns redan");
         }
         if ((string) $new->getAccountWrapper()->getAccount() == (string) $curr->getAccountWrapper()->getAccount()) {
             throw new \RuntimeException("Kan ej skapa KP: kontonumret {$curr->getAccountWrapper()->getAccount()} finns redan");
         }
         if ($new->getMailWrapper()->getValue() == $curr->getMailWrapper()->getValue()) {
             throw new \RuntimeException("Kan ej skapa KP: adressen {$curr->getMailWrapper()->getValue()} finns redan");
         }
         if ($new->getPhoneWrapper()->getValue() == $curr->getPhoneWrapper()->getValue()) {
             throw new \RuntimeException("Kan ej skapa KP: telefonnumret {$curr->getPhoneWrapper()->getValue()} finns redan");
         }
     }
 }