Skip to content

Commit 8858684

Browse files
committed
More use of new Credential Types
1 parent 595724c commit 8858684

10 files changed

Lines changed: 154 additions & 131 deletions

composer.lock

Lines changed: 92 additions & 92 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/MultiFlexi/Application.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ public function deleteFromSQL($data = null)
482482
*/
483483
public function getAppEnvironmentFields()
484484
{
485-
return Conffield::getAppConfigs($this->getMyKey());
485+
return Conffield::getAppConfigs($this);
486486
}
487487

488488
/**

src/MultiFlexi/Conffield.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,13 @@ public function addAppConfig($appId, $envName, $envProperties)
8787
return $this->dbsync();
8888
}
8989

90-
public static function getAppConfigs(int $appId): ConfigFields
90+
public static function getAppConfigs(Application $app): ConfigFields
9191
{
9292
$appConfiguration = new ConfigFields(_('Application Config Fields'));
9393

94-
foreach ((new self())->appConfigs($appId) as $appConfig) {
94+
foreach ((new self())->appConfigs($app->getMyKey()) as $appConfig) {
9595
$field = new ConfigField($appConfig['keyname'], $appConfig['type'], $appConfig['keyname'], $appConfig['description']);
96-
$field->setRequired($appConfig['required'] === 1)->setDefaultValue($appConfig['defval']);
96+
$field->setRequired($appConfig['required'] === 1)->setDefaultValue($appConfig['defval'])->setSource(serialize($app));
9797
$appConfiguration->addField($field);
9898
}
9999

src/MultiFlexi/Credential.php

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,27 @@
1717

1818
class Credential extends DBEngine
1919
{
20+
/**
21+
* @var string Name Column
22+
*/
23+
public string $nameColumn = 'name';
2024
private Credata $credator;
2125
private ?CredentialType $credentialType = null;
2226

2327
public function __construct($identifier = null, $options = [])
2428
{
2529
$this->myTable = 'credentials';
2630
$this->keyColumn = 'id';
27-
$this->nameColumn = 'name';
2831
$this->credator = new Credata();
2932

3033
parent::__construct($identifier, $options);
3134
}
3235

36+
public function __unserialize(array $data): void
37+
{
38+
$this->takeData($data['data']);
39+
}
40+
3341
/**
3442
* Set assigned CredentialType object.
3543
*/
@@ -62,6 +70,10 @@ public function takeData(array $data): int
6270
unset($data['id']);
6371
}
6472

73+
if (\array_key_exists('credential_type_id', $data)) {
74+
$this->setCredentialType(new CredentialType($data['credential_type_id']));
75+
}
76+
6577
return parent::takeData($data);
6678
}
6779

@@ -154,17 +166,18 @@ public function loadFromSQL($itemID = null)
154166
$itemID = $this->getMyKey();
155167
}
156168

157-
$data = parent::loadFromSQL($itemID);
169+
$dataCount = parent::loadFromSQL($itemID);
158170

159171
foreach ($this->credator->listingQuery()->where('credential_id', $this->getMyKey()) as $credential) {
160172
$this->setDataValue($credential['name'], $credential['value']);
173+
++$dataCount;
161174
}
162175

163176
if ($this->getDataValue('credential_type_id')) {
164177
$this->setCredentialType(new CredentialType($this->getDataValue('credential_type_id')));
165178
}
166179

167-
return $data;
180+
return $dataCount;
168181
}
169182

170183
public function deleteFromSQL($data = null)
@@ -244,9 +257,10 @@ public function query(): CredentialConfigFields
244257

245258
if (\is_object($fieldProvidedByCredType)) {
246259
$fieldProvidedByCredType->setValue((string) $credential['value']);
260+
$fieldProvidedByCredType->setSource(serialize($this));
247261
} else {
248262
$field = new ConfigField($credential['name'], $credential['type'], $credential['name'], '', '', $credential['value']);
249-
$field->setSource(sprintf(_('Credential #%d'), $credential['credential_id']));
263+
$field->setSource(serialize($this));
250264
$credentialEnv->addField($field);
251265
}
252266

src/MultiFlexi/CredentialType.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public function getFields(): ConfigFields
165165
$field->setRequired($fieldHelper->isRequired());
166166
$field->setSecret($fieldHelper->isSecret());
167167
} else {
168-
$this->addStatusMessage(sprintf(_('Unexistent field helper %s ?!?'), $fieldData['helper']), 'info');
168+
$this->addStatusMessage(sprintf(_('Unexistent field helper %s ?!?'), $fieldData['helper']), 'info'); // TODO:
169169
}
170170
}
171171

@@ -198,9 +198,9 @@ public function query(): ConfigFields
198198

199199
return $crtypeFields;
200200
}
201-
202-
public function getLogo(): string {
203-
return (string)$this->getDataValue('logo');
201+
202+
public function getLogo(): string
203+
{
204+
return (string) $this->getDataValue('logo');
204205
}
205-
206206
}

src/MultiFlexi/DBEngine.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ public function __construct($init = null, $filter = [])
8686
if (null === $this->detailPage) {
8787
$this->setDetailPage();
8888
}
89+
90+
$this->setObjectName();
8991
}
9092

9193
/**

src/MultiFlexi/RunTemplate.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -541,11 +541,11 @@ public function completeDataRow(array $dataRowRaw): array
541541
return $dataRowRaw;
542542
}
543543

544-
public function getAssignedCredentials()
544+
public function getAssignedCredentials(): array
545545
{
546546
$crdHlpr = new \MultiFlexi\RunTplCreds();
547547

548-
return $crdHlpr->getCredentialsForRuntemplate($this->getMyKey())->fetchAll('formType');
548+
return $crdHlpr->getCredentialsForRuntemplate($this->getMyKey())->fetchAll();
549549
}
550550

551551
/**

src/MultiFlexi/Ui/CredentialForm.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function __construct(Credential $kredenc)
5050
$credentialTypeSelect = null; // Ensure variable is always defined
5151

5252
if ($kredenc->getDataValue('company_id')) {
53-
$credentialTypeSelect = new CredentialTypeSelect('credential_type_id', (int) $kredenc->getDataValue('company_id'), (int) $kredenc->getDataValue('credential_type_id'));
53+
$credentialTypeSelect = new CredentialTypeSelect('credential_type_id', (int) $kredenc->getDataValue('company_id'), $kredenc->getCredentialType() ? $kredenc->getCredentialType()->getMyKey() : 0);
5454
$credentialTypeSelect->finalize();
5555

5656
if ($credentialTypeSelect->getItemsCount()) {

src/MultiFlexi/Ui/RuntemplateConfigForm.php

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
*/
2323
class RuntemplateConfigForm extends EngineForm
2424
{
25-
private array $modulesEnv;
26-
2725
public function __construct(\MultiFlexi\RunTemplate $engine)
2826
{
2927
parent::__construct($engine, null, ['method' => 'post', 'action' => 'runtemplate.php', 'enctype' => 'multipart/form-data']);
@@ -45,7 +43,7 @@ public function __construct(\MultiFlexi\RunTemplate $engine)
4543

4644
$this->addItem(new RuntemplateRequirementsChoser($engine));
4745

48-
$appFields = \MultiFlexi\Conffield::getAppConfigs($engine->getDataValue('app_id'));
46+
$appFields = \MultiFlexi\Conffield::getAppConfigs($engine->getApplication());
4947
$runTemplateFields = $engine->getEnvironment();
5048

5149
$appFields->addFields($customized);
@@ -59,32 +57,41 @@ public function __construct(\MultiFlexi\RunTemplate $engine)
5957

6058
$runTemplateField = $runTemplateFields->getFieldByCode($fieldName);
6159

62-
if ($runTemplateField) {
63-
if (\array_key_exists($fieldName, $credData)) {
64-
$input->setTagProperty('disabled', '1');
65-
$input->setValue($credData[$fieldName]);
66-
}
60+
if ($runTemplateField) { // Filed by Credential
61+
$input->setTagProperty('disabled', '1');
62+
63+
$runTemplateFieldSource = $runTemplateField->getSource();
64+
65+
if (\Ease\Functions::isSerialized($runTemplateFieldSource)) {
66+
$credential = unserialize($runTemplateFieldSource);
67+
68+
if ($credential) {
69+
$credentialType = $credential->getCredentialType();
70+
71+
$credentialLink = new \Ease\Html\ATag('credential.php?id='.$credential->getMyKey(), new \Ease\Html\SmallTag($credential->getRecordName()));
6772

68-
$formIcon = new \Ease\Html\ImgTag($runTemplateField->getLogo(), $runTemplateField->getSource(), ['height' => 20, 'title' => $runTemplateField->getSource()]);
73+
$formIcon = new \Ease\Html\ImgTag('images/'.$runTemplateField->getLogo(), $credentialType->getRecordName(), ['height' => 20, 'title' => $credentialType->getRecordName()]);
6974

70-
if (\array_key_exists($fieldName, $credSource)) {
71-
$fieldLink = new \Ease\Html\ATag('credential.php?id='.$credSource[$fieldName], $formIcon.' '.$fieldName);
75+
$credentialTypeLink = new \Ease\Html\ATag('credentialtype.php?id='.$credentialType->getMyKey(), $formIcon);
76+
77+
$inputCaption = new \Ease\Html\SpanTag([$credentialTypeLink, new \Ease\Html\StrongTag($fieldName), ' ', $credentialLink]);
78+
}
7279
} else {
73-
$fieldLink = $formIcon.' '.$fieldName;
80+
$inputCaption = new \Ease\Html\StrongTag($fieldName);
7481
}
7582

76-
$formGroup = $this->addInput($input, $fieldLink, $field->getDefaultValue(), $field->getDescription());
77-
} else {
78-
$formGroup = $this->addInput($input, $fieldName.' ('.$field->getSource().')', $field->getDefaultValue(), $field->getDescription());
83+
$formGroup = $this->addInput($input, $inputCaption, $runTemplateField->getValue(), $field->getDescription());
84+
} else { // Simple Fields
85+
$formGroup = $this->addInput($input, $fieldName, $field->getDefaultValue(), $field->getDescription());
7986
}
8087

81-
if ($field->isRequired()) {
82-
$formGroup->addTagClass('bg-danger');
83-
}
84-
85-
if ($field->getSource()) {
86-
$formGroup->addTagClass('bg-info');
87-
}
88+
// if ($field->isRequired()) {
89+
// $formGroup->addTagClass('bg-danger');
90+
// }
91+
//
92+
// if ($field->getSource()) {
93+
// $formGroup->addTagClass('bg-info');
94+
// }
8895
}
8996

9097
// $this->addItem( new RuntemplateTopicsChooser('topics', $engine)); //TODO

src/css/bootstrap.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)