<commit_before><?php

/**
 * This file is part of the OpenPNE package.
 * (c) OpenPNE Project (http://www.openpne.jp/)
 *
 * For the full copyright and license information, please view the LICENSE
 * file and the NOTICE file that were distributed with this source code.
 */

/**
 * opMemberProfileSearchForm
 *
 * @package    OpenPNE
 * @subpackage form
 * @author     <NAME> <<EMAIL>>
 */
class opMemberProfileSearchForm extends sfForm
{
  protected static $profileFieldPrefix = 'profile_';
 
  protected function getProfiles()
  {
    return Doctrine::getTable('Profile')->retrievesAll();
  }
  
  public function configure()
  {
    $this->disableCSRFProtection();

    $widgets = array();
    $validators = array();

    if ($this->getOption('use_id'))
    {
      $widgets += array('id' => new sfWidgetFormInput());
      $validators += array('id' => new sfValidatorPass());
    }

    $widgets += array('name' => new sfWidgetFormInput());
    $validators += array('name' => new opValidatorSearchQueryString(array('required' => false)));

    foreach ($this->getProfiles() as $profile)
    {
      $widgets[self::$profileFieldPrefix.$profile->getName()] = opFormItemGenerator::generateSearchWidget($profile->toArray(), $profile->getOptionsArray());
      $validators[self::$profileFieldPrefix.$profile->getName()] = new sfValidatorPass();
    }

    $this->setWidgets($widgets);
    $this->setValidators($validators);

    $this->widgetSchema->setLabel('name', 'Nickname');

    $this->widgetSchema->setNameFormat('member[%s]');
  }

  protected function addIdColumnQuery(Doctrine_Query $query, $value)
  {
    if (!empty($value))
    {
      $query->andWhere('id = ?', $value);
    }
  }

  protected function addNameColumnQuery(Doctrine_Query $query, $value)
  {
    if (!empty($value))
    {
      if (is_array($value))
      {
        foreach ($value as $v)
        {
          $query->addWhere('name LIKE ?', '%'.$v.'%');
        }
      }
      else
      {
        if (!empty($value))
        {
          $query->addWhere('name LIKE ?', '%'.$values.'%');
        }
      }
    }
  }

  public function getQuery()
  {
    $isWhere = false;
    $ids = null;
    $q = Doctrine::getTable('Member')->createQuery();

    if ($this->getOption('use_id'))
    {
      $this->addIdColumnQuery($q, $this->getValue('id'));
    }

    $this->addNameColumnQuery($q, $this->getValue('name'));

    $profileValues = array();
    foreach ($this->getProfiles() as $profile)
    {
      $key = $profile->getName();
      $value = $this->getValue(self::$profileFieldPrefix.$key);

      if (is_array($value))
      {
        $isEmpty = true;
        foreach ($value as $v)
        {
          if(!empty($v))
          {
            $isEmpty = false;
          }
        }
        if ($isEmpty)
        {
          $value = null;
        }
      }
      if (!empty($value))
      {
        $profileValues[$key] = $value;
        $isWhere = true;
      }
    }

    $ids = Doctrine::getTable('MemberProfile')->searchMemberIds($profileValues, $ids);

    if ($isWhere)
    {
      if (!count($ids))
      {
        $ids[] = 0;
      }
      $q->whereIn('id', $ids);
    }

    return $q;
 }
}

<commit_msg>#4010:fixed opMemberProfileSearchForm doesn't internationalize correctly<commit_after><?php

/**
 * This file is part of the OpenPNE package.
 * (c) OpenPNE Project (http://www.openpne.jp/)
 *
 * For the full copyright and license information, please view the LICENSE
 * file and the NOTICE file that were distributed with this source code.
 */

/**
 * opMemberProfileSearchForm
 *
 * @package    OpenPNE
 * @subpackage form
 * @author     <NAME> <<EMAIL>>
 */
class opMemberProfileSearchForm extends sfForm
{
  protected static $profileFieldPrefix = 'profile_';
 
  protected function getProfiles()
  {
    return Doctrine::getTable('Profile')->retrievesAll();
  }
  
  public function configure()
  {
    $this->disableCSRFProtection();

    $widgets = array();
    $validators = array();

    if ($this->getOption('use_id'))
    {
      $widgets += array('id' => new sfWidgetFormInput());
      $validators += array('id' => new sfValidatorPass());
    }

    $widgets += array('name' => new sfWidgetFormInput());
    $validators += array('name' => new opValidatorSearchQueryString(array('required' => false)));

    foreach ($this->getProfiles() as $profile)
    {
      $profileI18n = $profile->Translation[sfContext::getInstance()->getUser()->getCulture()]->toArray();
      $profileWithI18n = $profile->toArray() + $profileI18n;

      $widgets[self::$profileFieldPrefix.$profile->getName()] = opFormItemGenerator::generateSearchWidget($profileWithI18n, $profile->getOptionsArray());
      $validators[self::$profileFieldPrefix.$profile->getName()] = new sfValidatorPass();
    }

    $this->setWidgets($widgets);
    $this->setValidators($validators);

    $this->widgetSchema->setLabel('name', 'Nickname');

    $this->widgetSchema->setNameFormat('member[%s]');
  }

  protected function addIdColumnQuery(Doctrine_Query $query, $value)
  {
    if (!empty($value))
    {
      $query->andWhere('id = ?', $value);
    }
  }

  protected function addNameColumnQuery(Doctrine_Query $query, $value)
  {
    if (!empty($value))
    {
      if (is_array($value))
      {
        foreach ($value as $v)
        {
          $query->addWhere('name LIKE ?', '%'.$v.'%');
        }
      }
      else
      {
        if (!empty($value))
        {
          $query->addWhere('name LIKE ?', '%'.$values.'%');
        }
      }
    }
  }

  public function getQuery()
  {
    $isWhere = false;
    $ids = null;
    $q = Doctrine::getTable('Member')->createQuery();

    if ($this->getOption('use_id'))
    {
      $this->addIdColumnQuery($q, $this->getValue('id'));
    }

    $this->addNameColumnQuery($q, $this->getValue('name'));

    $profileValues = array();
    foreach ($this->getProfiles() as $profile)
    {
      $key = $profile->getName();
      $value = $this->getValue(self::$profileFieldPrefix.$key);

      if (is_array($value))
      {
        $isEmpty = true;
        foreach ($value as $v)
        {
          if(!empty($v))
          {
            $isEmpty = false;
          }
        }
        if ($isEmpty)
        {
          $value = null;
        }
      }
      if (!empty($value))
      {
        $profileValues[$key] = $value;
        $isWhere = true;
      }
    }

    $ids = Doctrine::getTable('MemberProfile')->searchMemberIds($profileValues, $ids);

    if ($isWhere)
    {
      if (!count($ids))
      {
        $ids[] = 0;
      }
      $q->whereIn('id', $ids);
    }

    return $q;
 }
}


{'fraction_non_alphanumeric': 0.17160568491079528, 'fraction_numerical': 0.0021167221046265497, 'mean_word_length': 2.6266447368421053, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 79, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1787537', 'n_tokens_mistral': 2082, 'n_tokens_neox': 2030, 'n_words': 387}