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 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(); } } } }