PHP code example of nattreid / gallery

1. Go to this page and download the library: Download nattreid/gallery 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/ */

    

nattreid / gallery example snippets


/** @var \NAttreid\Gallery\Control\IGalleryFactory @inject */
public $galleryFactory;

function createComponentGalleryDB() {
    $model = $this->db->table('example');

    $gallery = $this->galleryFactory->create();
    $gallery->setStorage($model);
    $gallery->setNamespace('example/class');
    $gallery->setForeignKey('foreignKey', 5);
    return $gallery;
}

function createComponentGallerySession() {
    $session = $this->getSession('example/class');

    $gallery = $this->galleryFactory->create();
    $gallery->setStorage($session, 'nameOfVariableInSession');
    $gallery->setNamespace('example/class');
    return $gallery;
}

/** @var \NAttreid\Cms\Configurator\Configurator @inject */
public $configurator;

function createComponentGalleryConfigurator() {
    $gallery = $this->galleryFactory->create();
    $gallery->setStorage($this->configurator, 'nameOfVariableInSession');
    $gallery->setNamespace('example/class');
    return $gallery;
}

protected function createComponentGallery() {
    $session = $this->getSession('example/class');
    $session->setExpiration('1 hour');

    $gallery = $this->galleryFactory->create();
    $gallery->setStorage($session, 'example');
    return $gallery;
}

function onSuccessForm(Form $form, $values) {
    $createGallery = empty($values->id);
    $id = $this->model->save($values->id, $values)->getPrimary();  

    if ($createGallery) {
        /* @var $gallery \NAttreid\Gallery\Gallery */
        $gallery=$this['gallery'];

        $gallery->changeNamespace('item/' . $values->url);
        $this->imageModel->add($id, $gallery->getImages());
        $gallery->clearTemp();
    }
}