nattreid/gallery

Gallery for Nette Framework

Installs: 429

Dependents: 1

Suggesters: 0

Security: 0

Stars: 1

Watchers: 2

Forks: 0

Open Issues: 0

Language:JavaScript

2.4.10 2022-06-22 06:59 UTC

README

Nastavení v config.neon

extensions:
    gallery: NAttreid\Gallery\DI\GalleryExtension

gallery:
    maxFileSize: 5 #MB
    maxFiles: 50

Načtení továrny

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

Použítí s databází

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

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

Použití se session

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

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

Použití s cms konfigurátorem

/** @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;
}

Použití ve formuláři

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();
    }
}