public function execute($request)
 {
     parent::execute($request);
     if ($request->hasParameter('csvimport')) {
         $this->form->bind($request->getParameterHolder()->getAll());
         if ($this->form->isValid()) {
             $this->processForm();
             $type = $request->getParameter('type');
             if (!empty($type)) {
                 $this->resource->setTypeByName($type);
             }
             $this->resource->save();
             if ($this->request->contact_type || $this->request->contactPerson || $this->request->streetAddress || $this->request->city || $this->request->region || $this->request->countryCode || $this->request->postalCode || $this->request->telephone || $this->request->fax || $this->request->email || $this->request->website) {
                 $contactInformation = new QubitContactInformation();
                 $contactInformation->actor = $this->resource;
                 $contactInformation->contactType = $this->request->contactType;
                 $contactInformation->contactPerson = $this->request->contactPerson;
                 $contactInformation->streetAddress = $this->request->streetAddress;
                 $contactInformation->city = $this->request->city;
                 $contactInformation->region = $this->request->region;
                 $contactInformation->countryCode = $this->request->countryCode;
                 $contactInformation->postalCode = $this->request->postalCode;
                 $contactInformation->telephone = $this->request->telephone;
                 $contactInformation->fax = $this->request->fax;
                 $contactInformation->email = $this->request->email;
                 $contactInformation->website = $this->request->website;
                 $contactInformation->note = $this->request->contactInformationNote;
                 $contactInformation->save();
                 if ($this->request->primaryContact) {
                     $contactInformation->makePrimaryContact();
                 }
             }
         }
     } elseif ($request->isMethod('post')) {
         $this->form->bind($request->getPostParameters());
         if ($this->form->isValid()) {
             $this->contactInformationEditComponent->processForm();
             $this->processForm();
             $this->resource->save();
             $this->redirect(array($this->resource, 'module' => 'repository'));
         }
     }
     QubitDescription::addAssets($this->response);
 }
 public function setIdentifierWithCodes($identifier, $options)
 {
     $this->setIdentifier($identifier);
     if ($repository = QubitRepository::getById($this->getRepositoryId())) {
         // if the repository doesn't already have a code, set it using the <unitid repositorycode=""> value
         if (isset($options['repositorycode'])) {
             if (!$repository->getIdentifier()) {
                 $repository->setIdentifier($options['repositorycode']);
                 $repository->save();
             }
         }
         // if the repository doesn't already have an country code, set it using the <unitid countrycode=""> value
         if (isset($options['countrycode'])) {
             if (!$repository->getCountryCode()) {
                 if ($primaryContact = $repository->getPrimaryContact()) {
                     $primaryContact->setCountryCode(strtoupper($options['countrycode']));
                     $primaryContact->save();
                 } else {
                     if (count($contacts = $repository->getContactInformation()) > 0) {
                         $contacts[0]->setCountryCode(strtoupper($options['countrycode']));
                         $contacts[0]->save();
                     } else {
                         $contactInformation = new QubitContactInformation();
                         $contactInformation->setCountryCode(strtoupper($options['countrycode']));
                         $contactInformation->setActorId($repository->id);
                         $contactInformation->save();
                     }
                 }
             }
         }
     }
 }