PHP code example of esit / datacollections

1. Go to this page and download the library: Download esit/datacollections library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

esit / datacollections example snippets


use Esit\Valueobjects\Classes\Database\Enums\TablenamesInterface;

enum Tablenames implements TablenamesInterface
{
    case tl_content;
    case tl_test_data;
}

use Esit\Valueobjects\Classes\Database\Enums\FieldnamesInterface;

enum TlContent implements FieldnamesInterface
{
    case id;
    case tstamp;
    case headline;
}

enum TlTestData implements FieldnamesInterface
{
    case id;
    case tstamp;
    case specialdata;
}

use Esit\Datacollections\Classes\Services\Factories\CollectionFactory;

class MyClass
{

    public function __construct(private readonly CollectionFactory $factory)
    {
    }


    public function useArray(): void
    {
        $myArrayCollection = $this->factory->createArrayCollection(
            ['t1' =>'test01', 't2' => 'test02']
        );

        // getValue
        echo $myArrayCollection->getValue('t1'); // => test01

        // setValue
        $myArrayCollection->setValue('t3', 'Test03');

        // fetchData
        $data = $myArrayCollection->fetchData(); // => ['t1' =>'test01', 't2' => 'test02', 't3' => 'Test03']

        // Iterator
        foreach ($myArrayCollection as $k => $v) {
            echo "$k: $y";
        }
    }
}

use Esit\Datacollections\Classes\Services\Factories\CollectionFactory;

class MyClass
{

    public function __construct(private readonly CollectionFactory $factory)
    {
    }


    public function useDatabaseRow(): void
    {
        // Eine leere Collection erstellen
        $myDbCollection = $this->factory->createDatabaseRowCollection(
            Tablenames::tl_test_data,
            [] // Hier können Daten als Array oder ArrayCollection übergeben werden.
        );

        // setValue
        $myDbCollection->getValue(TlTestData::specialdata, 'TestValue');

        // getValue
        echo $myDbCollection->getValue(TlTestData::specialdata); // => 'TestValue'

        // fetchData
        $data = $myDbCollection->fetchData(); // Alle Daten der Tabellenzeile als Array

        // ArrayCollection mit mehreren DatabaseRowCollections erstellen.
        $myCollections = $this->factory->createMultiDatabaseRowCollection(
            Tablenames::tl_test_data,
            [] // Hier können Daten als multidemensionales Array übergeben werden.
        );

        // Iterator ($myCollections ist eine ArrayCollection, $oneDbCollection je eine DatabaseRowCollection)
        foreach ($myCollections as $oneDbCollection) {
            var_dump($oneDbCollection); // oder alle anderen Aktionen einer DatabaseRowCollection
        }
    }
}

$table = 'tl_test_data';

$GLOBALS['TL_DCA'][$table]['fields']['author'] = [
    'label'                 => &$GLOBALS['TL_LANG'][$table]['author'],
    'exclude'               => true,
    'inputType'             => 'text',
    'foreignKey'            => 'tl_member.CONCAT(firstname,' ',lastname)',
    'lazyloading'           => ['table'=>'tl_member', 'field'=>'id', 'serialised'=>false],
    'eval'                  => ['mandatory'=>true, 'maxlength'=>255],
    'sql'                   => "varchar(255) NOT NULL default ''"
];