aAttributes[$sAttributeCode] = $aOptions; return $this; } /** * Get attribute data. * * @throws \CoreException * @throws \ArchivedObjectException */ private function GetAttributeData(string $sAttributeCode) : mixed { return $this->oDBObject->Get($sAttributeCode); } /** * Get attribute form type options. * * @param \AttributeDefinition $oAttributeDefinition * * @return array */ private function GetAttributeOptions(AttributeDefinition $oAttributeDefinition) : array { $aOptions = []; // compute label $sLabel = $oAttributeDefinition->GetLabel(); if(!$this->bGroup){ $sLabel = $this->GetAdapterIdentifier() . ' - ' . $sLabel; } // attribute options if($oAttributeDefinition instanceof AttributeString) { $aOptions['required'] = !$oAttributeDefinition->IsNullAllowed(); $aOptions['label'] = $sLabel; } return $aOptions; } /** * Get attribute description. * * @param string $sAttributeCode * * @return \Combodo\iTop\FormSDK\Field\FormFieldDescription|null * @throws \Exception */ private function GetAttributeDescription(string $sAttributeCode) : ?FormFieldDescription { // retrieve attribute definition $oAttributeDefinition = MetaModel::GetAttributeDef(get_class($this->oDBObject), $sAttributeCode); // create field description if($oAttributeDefinition instanceof AttributeString) { return new FormFieldDescription( $this->GetAttributeName($sAttributeCode), FormFieldTypeEnumeration::TEXT, array_merge( $this->GetAttributeOptions($oAttributeDefinition), $this->aAttributes[$sAttributeCode]) ); } return null; } /** * Return attribute name. * * @param string $sAttributeCode * * @return string */ private function GetAttributeName(string $sAttributeCode) : string { return $this->bGroup ? $sAttributeCode : $this->GetAdapterIdentifier() . '_' . $sAttributeCode; } /** * Get adapter label. * * @return string */ public function GetAdapterLabel(): string { return get_class($this->oDBObject) . ' ' . $this->oDBObject->GetKey(); } /** * Get adapter identifier. * * @return string */ public function GetAdapterIdentifier(): string { return get_class($this->oDBObject) . '_' . $this->oDBObject->GetKey(); } /** @inheritdoc */ public function GetFieldsData() : array { // prepare data... $aData = []; foreach ($this->aAttributes as $sAttributeCode => $oValue){ try { $aData[$this->GetAttributeName($sAttributeCode)] = $this->GetAttributeData($sAttributeCode); } catch (Exception $e) { $aData[$this->GetAttributeName($sAttributeCode)] = null; ExceptionLog::LogException($e); } } // group if($this->bGroup){ return [ $this->GetAdapterIdentifier() => $aData ]; } else{ return $aData; } } /** @inheritdoc * @throws \Exception */ public function GetFieldsDescriptions() : array { $aFieldsDescriptions = []; foreach ($this->aAttributes as $sAttCode => $oValue){ try { $aFieldsDescriptions[$this->GetAttributeName($sAttCode)] = $this->GetAttributeDescription($sAttCode); } catch (Exception $e) { ExceptionLog::LogException($e); } } if($this->bGroup){ $oGroupDescriptions = new FormFieldDescription($this->GetAdapterIdentifier(), FormFieldTypeEnumeration::FIELDSET, [ 'fields' => $aFieldsDescriptions, 'layout' => [ ':row_1' => [ ':column_1' => ['name'], ':column_2' => ['mobile_phone'], ], ] ]); return [$this->GetAdapterIdentifier() => $oGroupDescriptions]; } else{ return $aFieldsDescriptions; } } /** @inheritdoc */ public function UpdateFieldsData(array $aFormData) : bool { if($this->bGroup){ $aFormData = $aFormData[$this->GetAdapterIdentifier()]; } foreach ($this->aAttributes as $sAttCode => $aValue){ $this->oDBObject->Set($sAttCode, $aFormData[$this->GetAttributeName($sAttCode)]); } $this->oDBObject->DBUpdate(); return true; } }