Jump to content

Sortowanie w module


Recommended Posts

Witam, tworze moduł do tz. realizacji. w module znajduje sie lista realizacji oraz pole do dodawania realizacji, każda realizacja ma pole do zdjęcia, problem polega na tym ze nie wiem w jaki sposób zaimplementować sortowanie takie jak jest ja innych listach. W tych listach jest kolumna position i przycisk drag drop. W moim module też dodałem tą kolumne za pomocą $HELPERLIST, aczkolwiek po przesunięciu nie zmienia się pozycja. Czy ktoś mógłby spojrzeć na moduł , podpowiedzieć mi co robię źle , czy brakuje mi jakiegoś pliku (jakiegoś kontrolera) ? Z góry dziękuje za pomoc a poniżej załączam mój plik module.php 

 

<?php
if (!defined('_PS_VERSION_')) exit;

class BlockRealization extends Module {

protected $_html = '';

public function __construct() {

$this->name = 'blockrealization';
$this->tab = 'front_office_features';
$this->version = '1.0.0';
$this->author = 'XXX';
$this->need_instance = 0;
$this->ps_versions_compliancy = array('min' => '1.6', 'max' => _PS_VERSION_); 
$this->bootstrap = true;

parent::__construct();

$this->displayName = $this->l('Module realization');
$this->description = $this->l('Display realization on homepage.');
$this->confirmUninstall = $this->l('Are you sure you want to uninstall?'); 
}

public function install() {
if (!parent::install() ||
    !$this->registerHook('displayHeader') ||
    !$this->registerHook('home') ||
    !$this->createTables()
)
    return false;
return true;
}

public function uninstall() {
if (!parent::uninstall() ||
    !$this->removeTable())
    return false;
return true;
}

protected function createTables() {

/* Realization */
$res = (bool)Db::getInstance()->execute('
    CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'realization` (
        `id_realization_slides` int(10) unsigned NOT NULL AUTO_INCREMENT,
        `image_realization` varchar(255) NOT NULL,
        `position` int(10) unsigned NOT NULL,
        PRIMARY KEY (`id_realization_slides`, `image_realization`)
    ) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=UTF8;
');

return $res;
}

protected function removeTable() {
if (!Db::getInstance()->Execute('DROP TABLE `'. _DB_PREFIX_ . 'realization`'))
    return false;
return true;
}

public function getContent() {

$output = null;

if (Tools::isSubmit('submit'.$this->name)) {
    $errors = '';

    if ($_FILES) {

        $helper = new HelperImageUploader('realization_img');
        $files = $helper->process();

        if ($files) {

            foreach ($files as $file) {

                if (isset($file['save_path'])) {
                    if (!ImageManager::checkImageMemoryLimit($file['save_path']))
                    $errors = Tools::displayError('Limit');

                    if (!$errors) {
                        if (!ImageManager::resize($file['save_path'], dirname(__FILE__) . '/img/' . $file['name']))
                            $errors = Tools::displayError('error');
                        else {

                            $previous_file = Configuration::get('realization_img');
                            $file_path = dirname(__FILE__) . '/img/' . $previous_file;

                            if (file_exists($file_path))
                                unlink($file_path);


                            $realization['image_realization'] = $file['name'];
                            $realization['position'] = count($this->getAll());
                            if (!Db::getInstance()->insert('realization', $realization))
                                $errors = Tools::displayError('error');
                        }
                    }

                    unlink($file['save_path']);
                }
            }
        }
    }

    if ($errors) 
        $output .= $this->displayError($errors);
    else 

        $output .= $this->displayConfirmation($this->l('Settings updated'));
}

$output .= $this->generateList();
$output .= $this->displayForm();

return $output;
}

public function displayForm() {

 // Init Fields form array
 $fields_form[0]['form'] = array(
    'legend' => array(
        'title' => $this->l('Add the realization'),
    ),
    'input' => array(
        array(
            'type' => 'file',                              
            'label' => $this->l('Image:'),
            'name' => 'realization_img',
            'hint' => $this->l('Upload image for contact:'),
        )
    ),
    'submit' => array(
        'title' => $this->l('Save'),
        'class' => 'btn btn-default pull-right'
    )
);

$helper = new HelperForm();

// Module, token and currentIndex
$helper->module = $this;
$helper->name_controller = $this->name;
$helper->token = Tools::getAdminTokenLite('AdminModules');
$helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->name;

// Title and toolbar
$helper->title = $this->displayName;
$helper->show_toolbar = true;        // false -> remove toolbar
$helper->toolbar_scroll = true;      // yes - > Toolbar is always visible on the top of the screen.
$helper->submit_action = 'submit'.$this->name;
$helper->toolbar_btn = array(
    'save' =>
    array(
        'desc' => $this->l('Save'),
        'href' => AdminController::$currentIndex.'&configure='.$this->name.'&save'.$this->name.
        '&token='.Tools::getAdminTokenLite('AdminModules'),
    ),
    'back' => array(
        'href' => AdminController::$currentIndex.'&token='.Tools::getAdminTokenLite('AdminModules'),
        'desc' => $this->l('Back to list')
    )
);

// Load current value
$helper->tpl_vars = array(
    'fields_value' => array(
        'realization_img' => Configuration::get('realization_img')
    )
);

return $helper->generateForm($fields_form);
}

public function generateList() {
$content = $this->getAll();

$fields_list = array(
    'id_realization_slides' => array(
        'title' => 'ID',
        'align' => 'center',
        'class' => 'fixed-width-xs',
    ),
    'image_realization' => array(
        'title' => $this->l('Image'),
        'orderby' => false,
        'search' => false
    ),
    'position' => array(
        'title' => $this->l('Position'),
        'position' => 'position' ,
        'orderby' => false,
        'search' => false
    ),
);

$helper = new HelperList();
$helper->shopLinkType = '';
$helper->actions = array('edit', 'delete');
$helper->module = $this;
$helper->listTotal = count($content);
$helper->identifier = 'id_realization_slides';
$helper->title = $this->l('Realizations');
$helper->table = $this->name;
$helper->imageType = 'jpg';
$helper->orderBy = 'position';
$helper->orderWay = 'asc';
$helper->position_identifier = 'id_realization_slides';
$helper->token = Tools::getAdminTokenLite('AdminModules');
$helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->name;

return $helper->generateList($content, $fields_list);
}

public function getAll() {
return Db::getInstance()->ExecuteS('
    SELECT *
    FROM '._DB_PREFIX_.'realization
');
}

 public function hookHome($params) {

return $this->display(__FILE__, "views/templates/hook/realization.tpl");
}

 

Link to comment
Share on other sites

  • 2 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...