Skip to content

Commit

Permalink
Initial CredentialTypes overview
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitexus committed Feb 11, 2025
1 parent 1b7ae1a commit ee801e2
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/DOCtor-RST.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# .github/workflows/lint.yaml
name: Lint
name: DOCtor-RST

on:
push:
Expand Down
40 changes: 40 additions & 0 deletions db/migrations/20250211160329_credential_type_uuid.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

declare(strict_types=1);

/**
* This file is part of the MultiFlexi package
*
* https://multiflexi.eu/
*
* (c) Vítězslav Dvořák <http://vitexsoftware.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

use Phinx\Migration\AbstractMigration;

final class CredentialTypeUuid extends AbstractMigration
{
/**
* Change Method.
*
* Write your reversible migrations using this method.
*
* More information on writing migrations is available here:
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
*
* Remember to call "create()" or "update()" and NOT "save()" when working
* with the Table class.
*/
public function change(): void
{
$table = $this->table('credential_type');
$table->addColumn('uuid', 'string', ['length' => 40])->update();

if ($this->adapter->getAdapterType() === 'mysql') {
$this->execute('ALTER TABLE `credential_type` CHANGE `uuid` `uuid` VARCHAR(40) NULL DEFAULT uuid(); ');
}
}
}
50 changes: 50 additions & 0 deletions db/migrations/20250211165705_credential_type_i_d.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

declare(strict_types=1);

/**
* This file is part of the MultiFlexi package
*
* https://multiflexi.eu/
*
* (c) Vítězslav Dvořák <http://vitexsoftware.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

use Phinx\Migration\AbstractMigration;

final class CredentialTypeID extends AbstractMigration
{
/**
* Change Method.
*
* Write your reversible migrations using this method.
*
* More information on writing migrations is available here:
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
*
* Remember to call "create()" or "update()" and NOT "save()" when working
* with the Table class.
*/
public function change(): void
{
$databaseType = $this->getAdapter()->getOption('adapter');
$unsigned = ($databaseType === 'mysql') ? ['signed' => false] : [];

// Adding 'credential_type_id' column to 'credentials' table
$table = $this->table('credentials');
$table->addColumn('credential_type_id', 'integer', array_merge(['null' => false], $unsigned))
->update();

// Check if the 'credentials' table is empty
$rowCount = $this->fetchRow('SELECT COUNT(*) as count FROM credentials')['count'];

if ($rowCount === 0) {
// Add foreign key constraint only if the table is empty
$table->addForeignKey('credential_type_id', 'credential_type', ['id'], ['constraint' => 'ct2c_credential_type_must_exist'])
->update();
}
}
}
38 changes: 27 additions & 11 deletions src/MultiFlexi/CredentialType.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,15 @@
*/
class CredentialType extends DBEngine
{
/**
* @var string Name Column
*/
public string $nameColumn = 'name';

public function __construct($init = null, $filter = [])
{
$this->myTable = 'credential_type';

parent::__construct(false /* TODO $init */, $filter);
}

Expand All @@ -36,20 +42,30 @@ public function takeData(array $data): int
{
unset($data['class']);

if (!\array_key_exists('logo', $data) && \array_key_exists('imageraw', $_FILES) && !empty($_FILES['imageraw']['name'])) {
$uploadfile = sys_get_temp_dir().'/'.basename($_FILES['imageraw']['name']);

if (move_uploaded_file($_FILES['imageraw']['tmp_name'], $uploadfile)) {
$data['logo'] = 'data:'.mime_content_type($uploadfile).';base64,'.base64_encode(file_get_contents($uploadfile));
unlink($uploadfile);
unset($data['imageraw']);
}
if (\array_key_exists('id', $data) && !is_numeric($data['id'])) {
unset($data['id']);
}

// if (empty($this->getDataValue('logo'))) {
// $data['logo'] = 'data:image/svg+xml;base64,' . base64_encode(Ui\CredentialTypeLogo::$none);
// }
if (\array_key_exists('uuid', $data) === false) {
$data['uuid'] = \Ease\Functions::guidv4();
}

return parent::takeData($data);
}

/**
* @param array $columns
*
* @return array
*/
public function columns($columns = [])
{
return parent::columns([
['name' => 'id', 'type' => 'text', 'label' => _('ID'),
'detailPage' => 'credentialtype.php', 'valueColumn' => 'credential_type.id', 'idColumn' => 'credential_type.id', ],
['name' => 'logo', 'type' => 'text', 'label' => _('Logo'), 'searchable' => false],
['name' => 'name', 'type' => 'text', 'label' => _('Name')],
['name' => 'uuid', 'type' => 'text', 'label' => _('UUID')],
]);
}
}
1 change: 0 additions & 1 deletion src/MultiFlexi/Ui/CredentialTypeForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public function __construct(\MultiFlexi\CredentialType $credtype, $formPropertie
parent::__construct(['action' => 'credentialtype.php'], ['method' => 'POST'], $formContents);
$this->setTagProperty('enctype', 'multipart/form-data');

$this->addInput(new \Ease\Html\InputFileTag('imageraw'), _('Credential Logo'));
$this->addItem(new CredentialTypeLogo($credtype, ['style' => 'height: 200px']));

$this->addItem(new SubmitButton(_('Save'), 'success btn-lg btn-block'));
Expand Down
8 changes: 4 additions & 4 deletions src/MultiFlexi/Ui/PageBottom.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ public function finalize(): void

$footrow->addColumn(2, [$github, '&nbsp;', $linkedIn]);

$lnks = $footrow->addColumn(4, new \Ease\Html\ATag('https://multiflexi.readthedocs.io', _('Docs')));

if ($this->apiLink) {
$footrow->addColumn(4, $this->apiLinks());
$lnks->addItem($this->apiLinks());
}

$footrow->addColumn(2,new \Ease\Html\ATag('https://multiflexi.readthedocs.io', _('Docs')));

$this->addItem(new \Ease\TWB4\Container($footrow));
parent::finalize();
}
Expand All @@ -68,6 +68,6 @@ public function apiLinks()
$links[] = new \Ease\Html\ATag('api/VitexSoftware/MultiFlexi/1.0.0/'.$this->apiLink.'.'.$format, $format);
}

return 'API ['.implode(',', $links).']';
return '&nbsp;API ['.implode(',', $links).']';
}
}

0 comments on commit ee801e2

Please sign in to comment.