public function execute($request)
 {
     $this->resource = QubitContactInformation::getById($request->id);
     if (!isset($this->resource)) {
         $this->forward404();
     }
     $value = array();
     $value['primaryContact'] = (bool) $this->resource->primaryContact;
     if (isset($this->resource->contactPerson)) {
         $value['contactPerson'] = $this->resource->contactPerson;
     }
     if (isset($this->resource->streetAddress)) {
         $value['streetAddress'] = $this->resource->streetAddress;
     }
     if (isset($this->resource->website)) {
         $value['website'] = $this->resource->website;
     }
     if (isset($this->resource->email)) {
         $value['email'] = $this->resource->email;
     }
     if (isset($this->resource->telephone)) {
         $value['telephone'] = $this->resource->telephone;
     }
     if (isset($this->resource->fax)) {
         $value['fax'] = $this->resource->fax;
     }
     if (isset($this->resource->postalCode)) {
         $value['postalCode'] = $this->resource->postalCode;
     }
     if (isset($this->resource->countryCode)) {
         $value['countryCode'] = $this->resource->countryCode;
     }
     if (isset($this->resource->latitude)) {
         $value['latitude'] = $this->resource->latitude;
     }
     if (isset($this->resource->longitude)) {
         $value['longitude'] = $this->resource->longitude;
     }
     if (isset($this->resource->city)) {
         $value['city'] = $this->resource->city;
     }
     if (isset($this->resource->region)) {
         $value['region'] = $this->resource->region;
     }
     if (isset($this->resource->note)) {
         $value['note'] = $this->resource->note;
     }
     if (isset($this->resource->contactType)) {
         $value['contactType'] = $this->resource->contactType;
     }
     return $this->renderText(json_encode($value));
 }
 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);
 }
Exemplo n.º 3
0
 public static function getcontactInformationsById($id, array $options = array())
 {
     $criteria = new Criteria();
     self::addcontactInformationsCriteriaById($criteria, $id);
     return QubitContactInformation::get($criteria, $options);
 }
 public function processForm()
 {
     // HACK For now, parameter name and action name are the same. Should
     // really be configurable, ideally by interpreting
     // $form->getWidgetSchema()->getNameFormat()?
     $params = array($this->request[$this->actionName]);
     if (isset($this->request["{$this->actionName}s"])) {
         // If dialog JavaScript did it's work, then use array of parameters
         $params = $this->request["{$this->actionName}s"];
     }
     foreach ($params as $item) {
         // Continue only if user typed something
         foreach ($item as $value) {
             if (0 < strlen($value)) {
                 break;
             }
         }
         if (1 > strlen($value)) {
             continue;
         }
         $this->form->bind($item);
         if ($this->form->isValid()) {
             if (isset($item['id'])) {
                 $this->contactInformation = QubitContactInformation::getById(preg_replace('/^(.*)(\\d+)$/', '$2', $item['id']));
             } else {
                 $this->resource->contactInformations[] = $this->contactInformation = new QubitContactInformation();
             }
             foreach ($this->form as $field) {
                 if (isset($item[$field->getName()])) {
                     $this->processField($field);
                 }
             }
             if (isset($item['id'])) {
                 $this->contactInformation->save();
                 if ($this->contactInformation->primaryContact) {
                     $this->contactInformation->makePrimaryContact();
                 }
             }
         }
     }
     if (isset($this->request->deleteContactInformations)) {
         foreach ($this->request->deleteContactInformations as $item) {
             $contactInformation = QubitContactInformation::getById($item);
             if (isset($contactInformation)) {
                 $contactInformation->delete();
             }
         }
     }
 }
Exemplo n.º 5
0
 public function getPrimaryContact()
 {
     $criteria = new Criteria();
     $criteria->add(QubitContactInformation::ACTOR_ID, $this->id);
     $criteria->add(QubitContactInformation::PRIMARY_CONTACT, true);
     $primaryContact = QubitContactInformation::getOne($criteria);
     if ($primaryContact) {
         return $primaryContact;
     } else {
         $criteria = new Criteria();
         $criteria->add(QubitContactInformation::ACTOR_ID, $this->id);
         return QubitContactInformation::getOne($criteria);
     }
 }
 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();
                     }
                 }
             }
         }
     }
 }