aAttributes[$sAttributeCode] = $aOptions; return $this; } /** * Get attribute data. * * @throws \CoreException * @throws \ArchivedObjectException */ protected 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 = []; $sLabel = $oAttributeDefinition->GetLabel(); if(!$this->bGroup){ $sLabel = $this->GetLabel() . ' ••• ' . $sLabel; } 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 { $oAttributeDefinition = MetaModel::GetAttributeDef(get_class($this->oDBObject), $sAttributeCode); 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->GetIdentifier() . '_' . $sAttributeCode; } public function GetLayoutDescription() { return [ 'row__1' => [ 'column__1' => [ 'fieldset__1' => [ 'name'], ], 'column__2' => [ 'fieldset__2' => ['mobile_phone'], ], ], ]; } /** @inheritdoc */ public function GetFieldsData() : array { $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); } } if($this->bGroup){ return [ $this->GetIdentifier() => $aData ]; } else{ return $aData; } } /** @inheritdoc */ 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->GetIdentifier(), FormFieldTypeEnumeration::DB_OBJECT, [ 'fields' => $aFieldsDescriptions, 'label' => $this->GetLabel() ]); return [$this->GetIdentifier() => $oGroupDescriptions]; } else{ return $aFieldsDescriptions; } } public function GetLabel(): string { return get_class($this->oDBObject) . ' ' . $this->oDBObject->GetKey(); } /** @inheritdoc */ public function GetIdentifier(): string { return get_class($this->oDBObject) . '_' . $this->oDBObject->GetKey(); } /** @inheritdoc */ public function UpdateFieldsData(array $aFormData) : bool { if($this->bGroup){ $aFormData = $aFormData[$this->GetIdentifier()]; } foreach ($this->aAttributes as $sAttCode => $aValue){ $this->oDBObject->Set($sAttCode, $aFormData[$this->GetAttributeName($sAttCode)]); } $this->oDBObject->DBUpdate(); return true; } }