PMA\libraries\Index::set PHP Method

set() public method

Sets index details
public set ( array $params ) : void
$params array index details
return void
    public function set($params)
    {
        if (isset($params['columns'])) {
            $this->addColumns($params['columns']);
        }
        if (isset($params['Schema'])) {
            $this->_schema = $params['Schema'];
        }
        if (isset($params['Table'])) {
            $this->_table = $params['Table'];
        }
        if (isset($params['Key_name'])) {
            $this->_name = $params['Key_name'];
        }
        if (isset($params['Index_type'])) {
            $this->_type = $params['Index_type'];
        }
        if (isset($params['Comment'])) {
            $this->_remarks = $params['Comment'];
        }
        if (isset($params['Index_comment'])) {
            $this->_comment = $params['Index_comment'];
        }
        if (isset($params['Non_unique'])) {
            $this->_non_unique = $params['Non_unique'];
        }
        if (isset($params['Packed'])) {
            $this->_packed = $params['Packed'];
        }
        if (isset($params['Index_choice'])) {
            $this->_choice = $params['Index_choice'];
        } else {
            if ('PRIMARY' == $this->_name) {
                $this->_choice = 'PRIMARY';
            } elseif ('FULLTEXT' == $this->_type) {
                $this->_choice = 'FULLTEXT';
                $this->_type = '';
            } elseif ('SPATIAL' == $this->_type) {
                $this->_choice = 'SPATIAL';
                $this->_type = '';
            } elseif ('0' == $this->_non_unique) {
                $this->_choice = 'UNIQUE';
            } else {
                $this->_choice = 'INDEX';
            }
        }
        if (isset($params['Key_block_size'])) {
            $this->_key_block_size = $params['Key_block_size'];
        }
        if (isset($params['Parser'])) {
            $this->_parser = $params['Parser'];
        }
    }

Usage Example

 /**
  * Display the form to edit/create an index
  *
  * @return void
  */
 public function displayFormAction()
 {
     include_once 'libraries/tbl_info.inc.php';
     $add_fields = 0;
     if (isset($_REQUEST['index']) && is_array($_REQUEST['index'])) {
         // coming already from form
         if (isset($_REQUEST['index']['columns']['names'])) {
             $add_fields = count($_REQUEST['index']['columns']['names']) - $this->index->getColumnCount();
         }
         if (isset($_REQUEST['add_fields'])) {
             $add_fields += $_REQUEST['added_fields'];
         }
     } elseif (isset($_REQUEST['create_index'])) {
         $add_fields = $_REQUEST['added_fields'];
     }
     // end preparing form values
     // Get fields and stores their name/type
     if (isset($_REQUEST['create_edit_table'])) {
         $fields = json_decode($_REQUEST['columns'], true);
         $index_params = array('Non_unique' => $_REQUEST['index']['Index_choice'] == 'UNIQUE' ? '0' : '1');
         $this->index->set($index_params);
         $add_fields = count($fields);
     } else {
         $fields = $this->dbi->getTable($this->db, $this->table)->getNameAndTypeOfTheColumns();
     }
     $form_params = array('db' => $this->db, 'table' => $this->table);
     if (isset($_REQUEST['create_index'])) {
         $form_params['create_index'] = 1;
     } elseif (isset($_REQUEST['old_index'])) {
         $form_params['old_index'] = $_REQUEST['old_index'];
     } elseif (isset($_REQUEST['index'])) {
         $form_params['old_index'] = $_REQUEST['index'];
     }
     $this->response->getHeader()->getScripts()->addFile('indexes.js');
     $this->response->addHTML(Template::get('table/index_form')->render(array('fields' => $fields, 'index' => $this->index, 'form_params' => $form_params, 'add_fields' => $add_fields)));
 }