<?php

/**
 * User 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 BaseUserFormFilter extends BaseFormFilterDoctrine
{
  public function setup()
  {
    $this->setWidgets(array(
      'username'              => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'name'                  => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'email'                 => new sfWidgetFormFilterInput(),
      'address'               => new sfWidgetFormFilterInput(),
      'email_check'           => new sfWidgetFormFilterInput(),
      'email_change'          => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'email_change_check'    => new sfWidgetFormFilterInput(),
      'social'                => new sfWidgetFormChoice(array('choices' => array('' => '', 0 => 'vk', 1 => 'fb', 2 => 'google', 3 => 'apple'))),
      'phone'                 => new sfWidgetFormFilterInput(),
      'phone_check'           => new sfWidgetFormFilterInput(),
      'phone_change'          => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'salt'                  => new sfWidgetFormFilterInput(),
      'password'              => new sfWidgetFormFilterInput(),
      'password_recovery'     => new sfWidgetFormFilterInput(),
      'is_active'             => new sfWidgetFormChoice(array('choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no'))),
      'is_blocked'            => new sfWidgetFormChoice(array('choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no'))),
      'is_super_admin'        => new sfWidgetFormChoice(array('choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no'))),
      'last_login'            => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate())),
      '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)),
      'deleted_at'            => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate())),
      'user_permissions_list' => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'Permission')),
      'user_group_list'       => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'UserGroup')),
    ));

    $this->setValidators(array(
      'username'              => new sfValidatorPass(array('required' => false)),
      'name'                  => new sfValidatorPass(array('required' => false)),
      'email'                 => new sfValidatorPass(array('required' => false)),
      'address'               => new sfValidatorPass(array('required' => false)),
      'email_check'           => new sfValidatorPass(array('required' => false)),
      'email_change'          => new sfValidatorPass(array('required' => false)),
      'email_change_check'    => new sfValidatorPass(array('required' => false)),
      'social'                => new sfValidatorChoice(array('required' => false, 'choices' => array(0 => 'vk', 1 => 'fb', 2 => 'google', 3 => 'apple'))),
      'phone'                 => new sfValidatorPass(array('required' => false)),
      'phone_check'           => new sfValidatorPass(array('required' => false)),
      'phone_change'          => new sfValidatorPass(array('required' => false)),
      'salt'                  => new sfValidatorPass(array('required' => false)),
      'password'              => new sfValidatorPass(array('required' => false)),
      'password_recovery'     => new sfValidatorPass(array('required' => false)),
      'is_active'             => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))),
      'is_blocked'            => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))),
      'is_super_admin'        => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))),
      'last_login'            => 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')))),
      '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')))),
      'deleted_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')))),
      'user_permissions_list' => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'Permission', 'required' => false)),
      'user_group_list'       => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'UserGroup', 'required' => false)),
    ));

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

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

    $this->setupInheritance();

    parent::setup();
  }

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

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

    $query->leftJoin('r.UserPermissions UserPermissions')
          ->andWhereIn('UserPermissions.permission_id', $values);
  }

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

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

    $query->leftJoin('r.UserGroupUsers UserGroupUsers')
          ->andWhereIn('UserGroupUsers.user_group_id', $values);
  }

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

  public function getFields()
  {
    return array(
      'id'                    => 'Number',
      'username'              => 'Text',
      'name'                  => 'Text',
      'email'                 => 'Text',
      'address'               => 'Text',
      'email_check'           => 'Text',
      'email_change'          => 'Text',
      'email_change_check'    => 'Text',
      'social'                => 'Enum',
      'phone'                 => 'Text',
      'phone_check'           => 'Text',
      'phone_change'          => 'Text',
      'salt'                  => 'Text',
      'password'              => 'Text',
      'password_recovery'     => 'Text',
      'is_active'             => 'Boolean',
      'is_blocked'            => 'Boolean',
      'is_super_admin'        => 'Boolean',
      'last_login'            => 'Date',
      'created_at'            => 'Date',
      'updated_at'            => 'Date',
      'deleted_at'            => 'Date',
      'user_permissions_list' => 'ManyKey',
      'user_group_list'       => 'ManyKey',
    );
  }
}
