Jump to content

[Module] Where This Field Is It Stored ?


Omaley

Recommended Posts

Hi, I'm making a prestashop module and i'm new in it.

 

There are many many mistakes in this code, see my question below.

 

I've write my module :

 

 



<?php
if (!defined('_PS_VERSION_'))
  exit;
 
class MyModule extends Module
{
    public function __construct()
    {
      $this->name = 'mymodule';
      $this->tab = 'front_office_features';
      $this->version = '1.0';
      $this->author = 'PA';
      $this->need_instance = 0;
      $this->ps_versions_compliancy = array('min' => '1.5', 'max' => '1.6');
   
      parent::__construct();
   
      $this->displayName = $this->l('My module');
      $this->description = $this->l('Description of my module.');
   
      $this->confirmUninstall = $this->l('Are you sure you want to uninstall?');
   
      if (!Configuration::get('MYMODULE_NAME'))      
        $this->warning = $this->l('No name provided');
    } 
 
    public function install()
      {
        if (!parent::install()
          || !$this->registerHook('hookDisplayLeftColumn')
          || !Db::getInstance()->execute('
          CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'sondage`(
          `id` int(6) NOT NULL AUTO_INCREMENT,
          `question` varchar(60) NOT NULL,
          `champ1` int(3) NOT NULL,
          `champ2` int(3) NOT NULL,
          `champ3` int(3) NOT NULL,
          PRIMARY KEY(`id`)) ENGINE='._MYSQL_ENGINE_.' default CHARSET=utf8')
          || !Db::getInstance()->execute('INSERT INTO '._DB_PREFIX_.'sondage (champ1,champ2,champ3) VALUES (0,0,0)')  
        )
        
        return false;
    }
 
    public function uninstall()
    {
      if (!parent::uninstall() ||
        !Configuration::deleteByName('MYMODULE_NAME') ||
        !Db::getInstance()->execute('DROP TABLE '._DB_PREFIX_.'sondage')
      )
       return false;
      return true;
    }
 
    public function hookDisplayLeftColumn($params)
    {
      $this->_prepareHook($params);
      return $this->display(__FILE__, 'mymodule.tpl');
    }
 
 
 
 
    public function trie()
    {
      $var = (string)Tools::getValue('mymodule');
      if ($var == 'champ1') {
        $sql = 'SELECT champ1 FROM '._DB_PREFIX_.'sondage';
        $total = Db::getInstance()->getValue($sql);
        $temp = $total + 1;
        Db::getInstance()->update('sondage', array('champ1' => $temp));
      }
      elseif ($var == 'champ2') {
        $sql = 'SELECT champ2 FROM '._DB_PREFIX_.'sondage';
        $total = Db::getInstance()->getValue($sql);
        $temp = $total + 1;
        Db::getInstance()->update('sondage', array('champ2' => $temp));
      }
      elseif ($var == 'champ3') {
        $sql = 'SELECT champ3 FROM '._DB_PREFIX_.'sondage';
        $total = Db::getInstance()->getValue($sql);
        $temp = $total + 1;
        Db::getInstance()->update('sondage', array('champ3' => $temp));
      }
 
      $question = Configuration::get('question');
 
    }
 
 
 
 
    private function _prepareHook($params)
    {
      if (Tools::isSubmit('submitMyModule'))
        $this->trie();
    }
 
 
 
 
    public function getContent()
    {
        $output = null;
     
        if (Tools::isSubmit('submitB'.$this->name))
        {
 
          $question = strval(Tools::getValue('question'));
          Configuration::updateValue('FOOTERCUSTOM_NAME1', Tools::getValue('FOOTERCUSTOM_NAME1'));
 
            if (!$question
              || empty($question)
              || !Validate::isGenericName($question))
                $output .= $this->displayError( $this->l('Invalid Configuration value') );
            else
            {
                Configuration::updateValue('question', $question);
                Configuration::updateValue('champ1', $champ1);
                Configuration::updateValue('reponse2', $reponse2);
                Configuration::updateValue('question', $question);
                $output .= $this->displayConfirmation($this->l('Settings updated'));
            }
        }
        return $output.$this->displayForm();
    }
 
 
 
 
 
    public function displayForm()
    {
        // Get default Language
        $default_lang = (int)Configuration::get('PS_LANG_DEFAULT');
         
        // Init Fields form array
        $fields_form[0]['form'] = array(
          'legend' => array(
              'title' => $this->l('Question vue'),
          ),
          'input' => array(
              array(
                  'type' => 'text',
                  'label' => $this->l('question :'),
                  'name' => 'question',
                  'size' => 15,
                  'required' => true
              ),
              array(
                  'type' => 'text',
                  'label' => $this->l('reponse1 :'),
                  'name' => 'champ1',
                  'size' => 15,
                  'required' => true
              ),
              array(
                  'type' => 'text',
                  'label' => $this->l('reponse2 :'),
                  'name' => 'reponse2',
                  'size' => 15,
                  'required' => true
              ),
          ),
          'submit' => array(
              'title' => $this->l('Save'),
              'class' => 'button'
          )
      );
       
      $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;
         
        // Language
        $helper->default_form_language = $default_lang;
        $helper->allow_employee_form_lang = $default_lang;
         
        // 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 = 'submitB'.$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->fields_value['question'] = Configuration::get('question');
        $helper->fields_value['champ1'] = Configuration::get('champ1');
        $helper->fields_value['reponse2'] = Configuration::get('reponse2');
         
        return $helper->generateForm($fields_form);
    }
}
?>
 
 
This give me :
 
40a6b20c-271f-4f62-9a8c-9614ba7b8905.jpg
 

 

My database for "question" is empty but I can write word (in this case "vvvvvvvvvv..") in the question field (in the BO) save it and it's save somewhere and I want where it's stored.

I hope i'm clear.

 

Thank you !

Edited by Omaley (see edit history)
Link to comment
Share on other sites

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...