<?php

/**
 * Cat filter form base class.
 *
 * @package    sf
 * @subpackage filter
 * @author     Atma
 * @version    SVN: $Id: sfDoctrineFormFilterGeneratedTemplate.php 24171 2009-11-19 16:37:50Z Kris.Wallsmith $
 */
abstract class BaseCatFormFilter extends BaseFormFilterDoctrine
{
  public function setup()
  {
    $this->setWidgets(array(
      'inner_id'      => new sfWidgetFormFilterInput(),
      'alias'         => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'photo'         => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'parent_id'     => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Parent'), 'add_empty' => true)),
      'order_id'      => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'view_type'     => new sfWidgetFormChoice(array('choices' => array('' => '', 'Simple' => 'Simple', 'Standart' => 'Standart', 'BigStandart' => 'BigStandart'))),
      'is_filter'     => new sfWidgetFormChoice(array('choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no'))),
      'is_main'       => new sfWidgetFormChoice(array('choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no'))),
      'sort'          => new sfWidgetFormFilterInput(),
      'created_at'    => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
      'updated_at'    => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
      'products_list' => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'Product')),
    ));

    $this->setValidators(array(
      'inner_id'      => new sfValidatorPass(array('required' => false)),
      'alias'         => new sfValidatorPass(array('required' => false)),
      'photo'         => new sfValidatorPass(array('required' => false)),
      'parent_id'     => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('Parent'), 'column' => 'id')),
      'order_id'      => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'view_type'     => new sfValidatorChoice(array('required' => false, 'choices' => array('Simple' => 'Simple', 'Standart' => 'Standart', 'BigStandart' => 'BigStandart'))),
      'is_filter'     => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))),
      'is_main'       => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))),
      'sort'          => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'created_at'    => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
      'updated_at'    => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
      'products_list' => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'Product', 'required' => false)),
    ));

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

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

    $this->setupInheritance();

    parent::setup();
  }

  public function addProductsListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query->leftJoin('r.CatProduct CatProduct')
          ->andWhereIn('CatProduct.product_id', $values);
  }

  public function getModelName()
  {
    return 'Cat';
  }

  public function getFields()
  {
    return array(
      'id'            => 'Number',
      'inner_id'      => 'Text',
      'alias'         => 'Text',
      'photo'         => 'Text',
      'parent_id'     => 'ForeignKey',
      'order_id'      => 'Number',
      'view_type'     => 'Enum',
      'is_filter'     => 'Boolean',
      'is_main'       => 'Boolean',
      'sort'          => 'Number',
      'created_at'    => 'Date',
      'updated_at'    => 'Date',
      'products_list' => 'ManyKey',
    );
  }
}
