<commit_before><?php
/**
 * CakeGanache : (https://github.com/gezeresolutionsweb/cakeganache)
 * Copyright (c) <NAME> (http://www.gezere.com)
 *
 * Licensed under The MIT License
 * For full copyright and license information, please see the LICENSE.txt
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright     Copyright (c) <NAME> (http://www.gezere.com)
 * @link          http://www.gezere.com
 * @package       CakeGanache.View.Helper
 * @since         CakeGanache v 0.0.0
 * @license       http://www.opensource.org/licenses/mit-license.php MIT License
 */

App::import('Helper', 'Form') ;

class GanacheFormHelper extends FormHelper
{
    public $navbar = false;
    public $horizontal = false;
    public $inline = false;
    public $search = false;
    
    public $buttonTypes = [
        GA_PRIMARY,
        GA_INFO,
        GA_SUCCESS,
        GA_WARNING,
        GA_DANGER,
        GA_INVERSE,
        GA_LINK
    ];

    public $buttonSizes = [
        GA_MINI,
        GA_SMALL,
        GA_LARGE
    ];
    
    /**
     * Add classes to options according to values of bootstrap-type and bootstrap-size for button.
     * 
     * @param $options The initial options with bootstrap-type and/or bootstrat-size values
     * @return The new options with class values (btn, and btn-* according to initial options)
     *
     * Extra options:
     *   - bootstrap-type: string Type of the button. GA_PRIMARY|GA_INFO|GA_SUCCESS|GA_WARNING|GA_DANGER|GA_INVERSE|GA_LINK
     *   - bootstrap-size: string Size of the button. GA_MINI|GA_SMALL|GA_LARGE
     */
    public function addButtonClasses($options)
    {
        $options = $this->addClass($options, GA_BTN);
        foreach ($this->buttonTypes as $type) {
            if (isset($options['bootstrap-type']) && $options['bootstrap-type'] === $type) {
                $options = $this->addClass($options, 'btn-'.$type) ;
                break ;
            }
        }
        foreach ($this->buttonSizes as $size) {
            if (isset($options['bootstrap-size']) && $options['bootstrap-size'] === $size) {
                $options = $this->addClass($options, 'btn-'.$size) ;
                break ;
            }
        }
        unset($options['bootstrap-size']) ;
        unset($options['bootstrap-type']) ;
        return $options ;
    }
	
    /**
     * 
     * Create a Twitter Bootstrap like form. 
     * 
     * New options available:
     * 	- navbar: boolean, specify if the form is a navbar form
     * 	- horizontal: boolean, specify if the form is horizontal
     * 	- inline: boolean, specify if the form is inline
     * 	- search: boolean, specify if the form is a search form
     * 
     * @param $model The model corresponding to the form
     * @param $options Options to customize the form
     * 
     * @return The HTML tags corresponding to the openning of the form
     * 
    **/
    public function create($model = null, $options = array()) {
        $this->navbar = $this->_extractOption('navbar', $options, false);
		unset($options['navbar']);
        $this->horizontal = $this->_extractOption('horizontal', $options, false);
		unset($options['horizontal']);
        $this->search = $this->_extractOption('search', $options, false) ;<commit_msg>* Refactorize View/Helper/GanacheFormHelper::addButtonClasses() to improve performance and extra running code.<commit_after><?php
/**
 * CakeGanache : (https://github.com/gezeresolutionsweb/cakeganache)
 * Copyright (c) <NAME> (http://www.gezere.com)
 *
 * Licensed under The MIT License
 * For full copyright and license information, please see the LICENSE.txt
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright     Copyright (c) <NAME> (http://www.gezere.com)
 * @link          http://www.gezere.com
 * @package       CakeGanache.View.Helper
 * @since         CakeGanache v 0.0.0
 * @license       http://www.opensource.org/licenses/mit-license.php MIT License
 */

App::import('Helper', 'Form') ;

class GanacheFormHelper extends FormHelper
{
    public $navbar = false;
    public $horizontal = false;
    public $inline = false;
    public $search = false;
    
    public $buttonTypes = [
        GA_PRIMARY,
        GA_INFO,
        GA_SUCCESS,
        GA_WARNING,
        GA_DANGER,
        GA_INVERSE,
        GA_LINK
    ];

    public $buttonSizes = [
        GA_MINI,
        GA_SMALL,
        GA_LARGE
    ];
    
    /**
     * Add classes to options according to values of bootstrap-type and bootstrap-size for button.
     * 
     * @param $options The initial options with bootstrap-type and/or bootstrat-size values
     * @return The new options with class values (btn, and btn-* according to initial options)
     *
     * Extra options:
     *   - bootstrap-type: string Type of the button. GA_PRIMARY|GA_INFO|GA_SUCCESS|GA_WARNING|GA_DANGER|GA_INVERSE|GA_LINK
     *   - bootstrap-size: string Size of the button. GA_MINI|GA_SMALL|GA_LARGE
     */
    public function addButtonClasses($options)
    {
        $options = $this->addClass($options, GA_BTN);

        if(isset($options['bootstrap-type'])) {
            if(in_array($options['bootstrap-type'], $this->buttonTypes)) {
                $options = $this->addClass($options, GA_BTN . '-' . $options['bootstrap-type']);
            }
            unset($options['bootstrap-type']);
        }

        if(isset($options['bootstrap-size'])) {
            if(in_array($options['bootstrap-size'], $this->buttonSizes)) {
                $options = $this->addClass($options, GA_BTN . '-' . $options['bootstrap-size']);
            }
            unset($options['bootstrap-size']);
        }

        return $options;
    }
	
    /**
     * 
     * Create a Twitter Bootstrap like form. 
     * 
     * New options available:
     * 	- navbar: boolean, specify if the form is a navbar form
     * 	- horizontal: boolean, specify if the form is horizontal
     * 	- inline: boolean, specify if the form is inline
     * 	- search: boolean, specify if the form is a search form
     * 
     * @param $model The model corresponding to the form
     * @param $options Options to customize the form
     * 
     * @return The HTML tags corresponding to the openning of the form
     * 
    **/
    public function create($model = null, $options = array()) {
        $this->navbar = $this->_extractOption('navbar', $options, false);
		unset($options['navbar']);
        $this->horizontal = $this->_extractOption('horizontal', $options, false);
		unset($options['horizontal']);
        $this->search = $this->_extractOption('search', $options, false) ;
{'fraction_non_alphanumeric': 0.12388578335095936, 'fraction_numerical': 0.0009064813415923856, 'mean_word_length': 2.4897206114918293, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 29, 'https://': 2, 'lorem ipsum': 0, 'www.': 8, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '343129', 'n_tokens_mistral': 1964, 'n_tokens_neox': 1904, 'n_words': 515}