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


/**
 * opCsvExportTask
 *
 * @package    opCsvExport
 * @author     <NAME> <<EMAIL>>
 */
class opCsvExportTask extends sfDoctrineBaseTask
{
  protected function configure()
  {
    parent::configure();
    $this->addOptions(array(
      new sfCommandOption('application', null, sfCommandOption::PARAMETER_OPTIONAL, 'The application name', true),
      new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environment', 'prod'),

      new sfCommandOption('from', null, sfCommandOption::PARAMETER_REQUIRED, 'member id which start from (inclusive)', 1),
      new sfCommandOption('to', null, sfCommandOption::PARAMETER_REQUIRED, 'member id which end to (exclusive)', null),

      new sfCommandOption('header', null, sfCommandOption::PARAMETER_OPTIONAL, 'need to output csv param header', true),
    ));

    $this->namespace        = 'opCsvExport';
    $this->name             = 'export';
  }

  protected function execute($arguments = array(), $options = array())
  {
    new sfDatabaseManager($this->configuration);

    if ('true' == $options['header'])
    {
      echo $this->getHeader()."\n";
    }

    $from = $options['from'];
    $to = $options['to'];

    $table = Doctrine::getTable('Member');

    $query = $table->createQuery()->select('id')->where('? <= id', $from);
    if (!is_null($to))
    {
      $query = $query->andWhere('id < ?', $to);
    }
    $memberIds = $query->execute(array(), Doctrine::HYDRATE_NONE);

    foreach($memberIds as $memberId)
    {
      $member = $table->find($memberId[0]);
      $line = array();
      $line[] = $this->getString($member->getId());
      $line[] = $this->getString($member->getName());
      $line[] = $this->getString($member->getCreatedAt());
      $line[] = $this->getString($member->getInviteMemberId());
      $line[] = $this->getString($member->getConfig('lastLogin'));
      $line[] = $this->getString($member->getConfig('pc_address'));
      $line[] = $this->getString($member->getConfig('mobile_address'));
      $memberImages = $member->getMemberImage();
      for ($i = 0; $i < 3; ++$i)
      {
        $line[] = $this->getString($memberImages[$i]->getFile());
      }
      foreach (Doctrine::getTable('Profile')->retrievesAll() as $profile)
      {
        $line[] = $this->getString($member->getProfile($profile->getName()));
      }
      echo '"'.implode('","', $line)."\"\n";
    }
  }

  private function getString($str)
  {
    return is_null($str) || false === $str ? '' : $str;
  }

  private function getHeader()
  {
    $result = array('id','name','created_at','invite_member_id','lastLogin','pc_address','mobile_address');

    for ($i = 1; $i <= 3; ++$i)
    {
      $result[] = 'memberImage'.$i;
    }

    foreach (Doctrine::getTable('Profile')->retrievesAll() as $profile)
    {
      $result[] = $profile->getName();
    }

    return '"'.implode('","', $result).'"';
  }
}<commit_msg>fixed for coding standard<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.
 */


/**
 * opCsvExportTask
 *
 * @package    opCsvExport
 * @author     <NAME> <<EMAIL>>
 */
class opCsvExportTask extends sfDoctrineBaseTask
{
  protected function configure()
  {
    parent::configure();
    $this->addOptions(array(
      new sfCommandOption('application', null, sfCommandOption::PARAMETER_OPTIONAL, 'The application name', true),
      new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environment', 'prod'),

      new sfCommandOption('from', null, sfCommandOption::PARAMETER_REQUIRED, 'member id which start from (inclusive)', 1),
      new sfCommandOption('to', null, sfCommandOption::PARAMETER_REQUIRED, 'member id which end to (exclusive)', null),

      new sfCommandOption('header', null, sfCommandOption::PARAMETER_OPTIONAL, 'need to output csv param header', true),
    ));

    $this->namespace        = 'opCsvExport';
    $this->name             = 'export';
  }

  protected function execute($arguments = array(), $options = array())
  {
    new sfDatabaseManager($this->configuration);

    if ('true' == $options['header'])
    {
      echo $this->getHeader()."\n";
    }

    $from = $options['from'];
    $to = $options['to'];

    $table = Doctrine::getTable('Member');

    $query = $table->createQuery()->select('id')->where('? <= id', $from);
    if (!is_null($to))
    {
      $query = $query->andWhere('id < ?', $to);
    }
    $memberIds = $query->execute(array(), Doctrine::HYDRATE_NONE);

    foreach($memberIds as $memberId)
    {
      $member = $table->find($memberId[0]);
      $line = array();
      $line[] = $this->getString($member->getId());
      $line[] = $this->getString($member->getName());
      $line[] = $this->getString($member->getCreatedAt());
      $line[] = $this->getString($member->getInviteMemberId());
      $line[] = $this->getString($member->getConfig('lastLogin'));
      $line[] = $this->getString($member->getConfig('pc_address'));
      $line[] = $this->getString($member->getConfig('mobile_address'));
      $memberImages = $member->getMemberImage();
      for ($i = 0; $i < 3; ++$i)
      {
        $line[] = $this->getString($memberImages[$i]->getFile());
      }
      foreach (Doctrine::getTable('Profile')->retrievesAll() as $profile)
      {
        $line[] = $this->getString($member->getProfile($profile->getName()));
      }
      echo '"'.implode('","', $line)."\"\n";
    }
  }

  private function getString($str)
  {
    return is_null($str) || false === $str ? '' : $str;
  }

  private function getHeader()
  {
    $result = array('id', 'name', 'created_at', 'invite_member_id', 'lastLogin', 'pc_address', 'mobile_address');

    for ($i = 1; $i <= 3; ++$i)
    {
      $result[] = 'memberImage'.$i;
    }

    foreach (Doctrine::getTable('Profile')->retrievesAll() as $profile)
    {
      $result[] = $profile->getName();
    }

    return '"'.implode('","', $result).'"';
  }
}
{'fraction_non_alphanumeric': 0.1941564561734213, 'fraction_numerical': 0.001885014137606032, 'mean_word_length': 3.5220170454545454, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 77, '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': '6182041', 'n_tokens_mistral': 1980, 'n_tokens_neox': 1968, 'n_words': 417}