<commit_before><?php
/*
 * This file is part of the reditype package.
 * (c) 2006-2008 digital Wranglers <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

/**
 * rtShopCreateBirthdayVoucherTask
 *
 * @package    rtShopPlugin
 * @author     <NAME> <<EMAIL>>
 * @author     <NAME> <<EMAIL>>
 */

class rtShopCreateBirthdayVouchersTask extends sfDoctrineBaseTask
{
  private $_debug_verbose = true;
  private $_batch_reference = '';

  /**
   * Configure
   *
   */
  protected function configure()
  {
    $this->addArguments(array(
      new sfCommandArgument('day', sfCommandArgument::OPTIONAL, 'Startdate of birthday range for which vouchers have to be generated'),
      new sfCommandArgument('month', sfCommandArgument::OPTIONAL, 'Enddate of birthday range for which vouchers have to be generated'),
    ));

    $this->addOptions(array(
      new sfCommandOption('application', null, sfCommandOption::PARAMETER_REQUIRED, 'The application name', 'frontend'),
      new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environment', 'dev'),
      new sfCommandOption('connection', null, sfCommandOption::PARAMETER_REQUIRED, 'The connection name', 'doctrine'),
    ));

    $this->namespace        = 'rt';
    $this->name             = 'shop-create-birthday-vouchers';
    $this->briefDescription = 'Create birthdays vouchers and send email to users with voucher code';
    $this->detailedDescription = <<<EOF
The [rt:shop-create-birthday-vouchers] task creates vouchers based on birthdays of registered users.

Configure in app.yml:

all:
  rt:
    shop_birthday_voucher:
      reduction_type:                  dollarOff               # Either 'percentageOff' or 'dollarOff'
      reduction_value:                 10                      # Voucher reduction value (e.g 10 = $10)

To generate vouchers for a specific birthday use:

[./symfony rt:shop-create-birthday-vouchers day month]

Note: If [day] and [month] is not specified than the current date is used!

Vouchers are then generated and an email sent to the users with the birthdays specified.
Another email is sent to the shop administrator with the details of the created vouchers.
EOF;
  }

  /**
   * Execute function
   *
   * @param array $arguments Arguments
   * @param array $options  Options
   */
  protected function execute($arguments = array(), $options = array())
  {
    $configuration = ProjectConfiguration::getApplicationConfiguration ('frontend', 'dev', false);
    sfContext::createInstance($configuration);
    $configuration->loadHelpers('Partial');
    $this->configuration->loadHelpers('Number','I18N','Partial');

    // If no day/month set use current date
    $day = is_null($arguments['day']) ? date("j",strtotime(date("Y-m-d H:i:s"))) : $arguments['day'];
    $month = is_null($arguments['month']) ? date("n",strtotime(date("Y-m-d H:i:s"))) : $arguments['month'];

    if (!sfConfig::has('app_rt_shop_birthday_voucher'))
    {
      throw new sfCommandException('app_rt_shop_birthday_voucher has to be set');
    }
    
    $config = sfConfig::get('app_rt_shop_birthday_voucher');

    $config['title'] = isset($config['title']) ? $config['title'] : 'Birthday Voucher';
    $config['reduction_type'] = isset($config['reduction_type']) ? $config['reduction_type'] : 'percentageOff';
    $config['reduction_value'] = isset($config['reduction_value']) ? $config['reduction_value'] : '0';

    // Database actions
    $databaseManager = new sfDatabaseManager($this->configuration);

    $q = Doctrine_Query::create()->from('rtGuardUser u')
          ->andWhere('DAY(u.date_of_birth) = ?', $day)
          ->andWhere('MONTH(u.date_of_birth) = ?', $month);
    $users = $q->fetchArray();
    
    $this->_batch_reference = rtShopVoucherToolkit::generateVoucherCode();
    $voucher_details = array('date_from' => NULL,
                    'date_to' => isset($config['date_to']) ? $config['date_to'] : NULL,
                    'reduction_type' =>  $config['reduction_type'],
                    'reduction_value' =>  $config['reduction_value'],
                    'title' =>  $config['title'],
                    'type' => 'rtShopVoucher',
                    'batch_reference' => $this->_batch_reference,
                    'count' => 1,
                    'mode' => 'Single',
                    'total_from' =>  isset($config['total_from']) ? $config['total_from'] : NULL,
                    'total_to' =>  isset($config['total_to']) ? $config['total_to'] : NULL,
                    'created_at' => date("Y-m-d H:i:s"),
                    'updated_at' => date("Y-m-d H:i:s"),
                    'code' => '');

    $this->createBatchVouchers($voucher_details, count($users));<commit_msg>Added expires_in variable for voucher expiry date<commit_after><?php
/*
 * This file is part of the reditype package.
 * (c) 2006-2008 digital Wranglers <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

/**
 * rtShopCreateBirthdayVoucherTask
 *
 * @package    rtShopPlugin
 * @author     <NAME> <<EMAIL>>
 * @author     <NAME> <<EMAIL>>
 */

class rtShopCreateBirthdayVouchersTask extends sfDoctrineBaseTask
{
  private $_debug_verbose = true;
  private $_batch_reference = '';

  /**
   * Configure
   *
   */
  protected function configure()
  {
    $this->addArguments(array(
      new sfCommandArgument('day', sfCommandArgument::OPTIONAL, 'Startdate of birthday range for which vouchers have to be generated'),
      new sfCommandArgument('month', sfCommandArgument::OPTIONAL, 'Enddate of birthday range for which vouchers have to be generated'),
    ));

    $this->addOptions(array(
      new sfCommandOption('application', null, sfCommandOption::PARAMETER_REQUIRED, 'The application name', 'frontend'),
      new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environment', 'dev'),
      new sfCommandOption('connection', null, sfCommandOption::PARAMETER_REQUIRED, 'The connection name', 'doctrine'),
    ));

    $this->namespace        = 'rt';
    $this->name             = 'shop-create-birthday-vouchers';
    $this->briefDescription = 'Create birthdays vouchers and send email to users with voucher code';
    $this->detailedDescription = <<<EOF
The [rt:shop-create-birthday-vouchers] task creates vouchers based on birthdays of registered users.

Configure in app.yml:

all:
  rt:
    shop_birthday_voucher:
      reduction_type:                  dollarOff               # Either 'percentageOff' or 'dollarOff'
      reduction_value:                 10                      # Voucher reduction value (e.g 10 = $10)

To generate vouchers for a specific birthday use:

[./symfony rt:shop-create-birthday-vouchers day month]

Note: If [day] and [month] is not specified than the current date is used!

Vouchers are then generated and an email sent to the users with the birthdays specified.
Another email is sent to the shop administrator with the details of the created vouchers.
EOF;
  }

  /**
   * Execute function
   *
   * @param array $arguments Arguments
   * @param array $options  Options
   */
  protected function execute($arguments = array(), $options = array())
  {
    $configuration = ProjectConfiguration::getApplicationConfiguration ('frontend', 'dev', false);
    sfContext::createInstance($configuration);
    $configuration->loadHelpers('Partial');
    $this->configuration->loadHelpers('Number','I18N','Partial');

    // If no day/month set use current date
    $day = is_null($arguments['day']) ? date("j",strtotime(date("Y-m-d H:i:s"))) : $arguments['day'];
    $month = is_null($arguments['month']) ? date("n",strtotime(date("Y-m-d H:i:s"))) : $arguments['month'];

    if (!sfConfig::has('app_rt_shop_birthday_voucher'))
    {
      throw new sfCommandException('app_rt_shop_birthday_voucher has to be set');
    }
    
    $config = sfConfig::get('app_rt_shop_birthday_voucher');

    $config['title'] = isset($config['title']) ? $config['title'] : 'Birthday Voucher';
    $config['reduction_type'] = isset($config['reduction_type']) ? $config['reduction_type'] : 'percentageOff';
    $config['reduction_value'] = isset($config['reduction_value']) ? $config['reduction_value'] : '0';

    // Database actions
    $databaseManager = new sfDatabaseManager($this->configuration);

    $q = Doctrine_Query::create()->from('rtGuardUser u')
          ->andWhere('DAY(u.date_of_birth) = ?', $day)
          ->andWhere('MONTH(u.date_of_birth) = ?', $month);
    $users = $q->fetchArray();

    // Set expiry date for vouchers
    if(isset($config['expires_in']))
    {
      $expiry_date = date('Y-m-d H:i:s',strtotime(sprintf("+%s days",$config['expires_in'])));
    }
    else
    {
      $expiry_date = isset($config['date_to']) ? $config['date_to'] : NULL;
    }

    $this->_batch_reference = rtShopVoucherToolkit::generateVoucherCode();
    $voucher_details = array('date_from' => NULL,
                    'date_to' => $expiry_date,
                    'reduction_type' =>  $config['reduction_type'],
                    'reduction_value' =>  $config['reduction_value'],
                    'title' =>  $config['title'],
                    'type' => 'rtShopVoucher',
                    'batch_reference' => $this->_batch_reference,
                    'count' => 1,
                    'mode' => 'Single',
                    'total_from' =>  isset($config['total_from']) ? $config['total_from'] : NULL,
                    'total_to' =>  isset($config['total_to']) ? $config['total_to'] : NULL,
                    'created_at' => date("Y-m-d H:i:s"),
                    'updated_at' => date("Y-m-d H:i:s"),
                    'code' => '');

    $this->createBatchVouchers($voucher_details, count($users));
{'fraction_non_alphanumeric': 0.14404460212873796, 'fraction_numerical': 0.003649265078560568, 'mean_word_length': 3.2746967071057194, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 81, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6535311', 'n_tokens_mistral': 3014, 'n_tokens_neox': 2904, 'n_words': 684}