<commit_before><?php
/**
 * Created by PhpStorm.
 * User: tom.kay
 * Date: 18/10/13
 * Time: 09:49
 */

namespace Qubes\Defero\Components\DataSource;

use Cubex\Form\FormElement;

class DataSourceCondition
{
  protected $_name;
  protected $_comparisons;
  protected $_values;
  protected $_input;
  protected $_callback;

  public function getComparison($key)
  {
    $keys = array_keys($this->_comparisons);
    return $keys[$key];
  }

  public function __construct(
    $name, $callback, $comparisons = null, $input = FormElement::TEXT,
    $values = null
  )
  {
    if($comparisons === null)
    {
      $comparisons = [
        '%~' => 'Contains',
        '%>' => 'Begins With',
        '%<' => 'Ends With'
      ];
    }

    $this->_name        = $name;
    $this->_callback    = $callback;
    $this->_comparisons = $comparisons;
    $this->_input       = $input;
    $this->_values      = $values;
  }

  public function getCompareElement($key, $comparison)
  {
    $ele = new FormElement('conditionCompare[' . $key . ']');
    $ele->setLabel($this->_name . ' Compare Type');
    $ele->setType(FormElement::SELECT);
    $ele->setOptions(array_values($this->_comparisons));
    $ele->setData($comparison);
    return $ele;
  }

  public function getValueElement($key, $value)
  {
    $ele = new FormElement('conditionValue[' . $key . ']');
    $ele->setLabel($this->_name . ' Value');
    if($this->_input == FormElement::NONE)
    {
      $this->_input = FormElement::HIDDEN;<commit_msg>empty option defaulted in compare elements<commit_after><?php
/**
 * Created by PhpStorm.
 * User: tom.kay
 * Date: 18/10/13
 * Time: 09:49
 */

namespace Qubes\Defero\Components\DataSource;

use Cubex\Form\FormElement;

class DataSourceCondition
{
  protected $_name;
  protected $_comparisons;
  protected $_values;
  protected $_input;
  protected $_callback;

  public function getComparison($key)
  {
    $keys = array_keys($this->_comparisons);
    return $keys[$key];
  }

  public function __construct(
    $name, $callback, $comparisons = null, $input = FormElement::TEXT,
    $values = null
  )
  {
    if($comparisons === null)
    {
      $comparisons = [
        '%~' => 'Contains',
        '%>' => 'Begins With',
        '%<' => 'Ends With'
      ];
    }

    $this->_name        = $name;
    $this->_callback    = $callback;
    $this->_comparisons = $comparisons;
    $this->_input       = $input;
    $this->_values      = $values;
  }

  public function getCompareElement($key, $comparison)
  {
    $ele = new FormElement('conditionCompare[' . $key . ']');
    $ele->setLabel($this->_name . ' Compare Type');
    $ele->setType(FormElement::SELECT);
    $opts = array_merge([''], array_values($this->_comparisons));
    $ele->setOptions($opts);
    $ele->setData($comparison);
    return $ele;
  }

  public function getValueElement($key, $value)
  {
    $ele = new FormElement('conditionValue[' . $key . ']');
    $ele->setLabel($this->_name . ' Value');
    if($this->_input == FormElement::NONE)
    {
      $this->_input = FormElement::HIDDEN;
{'fraction_non_alphanumeric': 0.17009467841984982, 'fraction_numerical': 0.00652954619653934, 'mean_word_length': 3.031578947368421, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '1217241', 'n_tokens_mistral': 1017, 'n_tokens_neox': 1003, 'n_words': 191}