<?php

/**
 * @package CRM
 * @copyright CiviCRM LLC https://civicrm.org/licensing
 *
 * Generated from xml/schema/CRM/Batch/Batch.xml
 * DO NOT EDIT.  Generated by CRM_Core_CodeGen
 * (GenCodeChecksum:d7bcbc183569fc9cc52260eef81e84ad)
 */

/**
 * Database access object for the Batch entity.
 */
class CRM_Batch_DAO_Batch extends CRM_Core_DAO {
  const EXT = 'civicrm';
  const TABLE_ADDED = '3.3';

  /**
   * Static instance to hold the table name.
   *
   * @var string
   */
  public static $_tableName = 'civicrm_batch';

  /**
   * Should CiviCRM log any modifications to this table in the civicrm_log table.
   *
   * @var bool
   */
  public static $_log = FALSE;

  /**
   * Unique Address ID
   *
   * @var int|string|null
   *   (SQL type: int unsigned)
   *   Note that values will be retrieved from the database as a string.
   */
  public $id;

  /**
   * Variable name/programmatic handle for this batch.
   *
   * @var string|null
   *   (SQL type: varchar(64))
   *   Note that values will be retrieved from the database as a string.
   */
  public $name;

  /**
   * Friendly Name.
   *
   * @var string|null
   *   (SQL type: varchar(255))
   *   Note that values will be retrieved from the database as a string.
   */
  public $title;

  /**
   * Description of this batch set.
   *
   * @var string|null
   *   (SQL type: text)
   *   Note that values will be retrieved from the database as a string.
   */
  public $description;

  /**
   * FK to Contact ID
   *
   * @var int|string|null
   *   (SQL type: int unsigned)
   *   Note that values will be retrieved from the database as a string.
   */
  public $created_id;

  /**
   * When was this item created
   *
   * @var string|null
   *   (SQL type: datetime)
   *   Note that values will be retrieved from the database as a string.
   */
  public $created_date;

  /**
   * FK to Contact ID
   *
   * @var int|string|null
   *   (SQL type: int unsigned)
   *   Note that values will be retrieved from the database as a string.
   */
  public $modified_id;

  /**
   * When was this item modified
   *
   * @var string|null
   *   (SQL type: datetime)
   *   Note that values will be retrieved from the database as a string.
   */
  public $modified_date;

  /**
   * FK to Saved Search ID
   *
   * @var int|string|null
   *   (SQL type: int unsigned)
   *   Note that values will be retrieved from the database as a string.
   */
  public $saved_search_id;

  /**
   * fk to Batch Status options in civicrm_option_values
   *
   * @var int|string
   *   (SQL type: int unsigned)
   *   Note that values will be retrieved from the database as a string.
   */
  public $status_id;

  /**
   * fk to Batch Type options in civicrm_option_values
   *
   * @var int|string|null
   *   (SQL type: int unsigned)
   *   Note that values will be retrieved from the database as a string.
   */
  public $type_id;

  /**
   * fk to Batch mode options in civicrm_option_values
   *
   * @var int|string|null
   *   (SQL type: int unsigned)
   *   Note that values will be retrieved from the database as a string.
   */
  public $mode_id;

  /**
   * Total amount for this batch.
   *
   * @var float|string|null
   *   (SQL type: decimal(20,2))
   *   Note that values will be retrieved from the database as a string.
   */
  public $total;

  /**
   * Number of items in a batch.
   *
   * @var int|string|null
   *   (SQL type: int unsigned)
   *   Note that values will be retrieved from the database as a string.
   */
  public $item_count;

  /**
   * fk to Payment Instrument options in civicrm_option_values
   *
   * @var int|string|null
   *   (SQL type: int unsigned)
   *   Note that values will be retrieved from the database as a string.
   */
  public $payment_instrument_id;

  /**
   * @var string|null
   *   (SQL type: datetime)
   *   Note that values will be retrieved from the database as a string.
   */
  public $exported_date;

  /**
   * cache entered data
   *
   * @var string|null
   *   (SQL type: longtext)
   *   Note that values will be retrieved from the database as a string.
   */
  public $data;

  /**
   * Class constructor.
   */
  public function __construct() {
    $this->__table = 'civicrm_batch';
    parent::__construct();
  }

  /**
   * Returns localized title of this entity.
   *
   * @param bool $plural
   *   Whether to return the plural version of the title.
   */
  public static function getEntityTitle($plural = FALSE) {
    return $plural ? ts('Batches') : ts('Batch');
  }

  /**
   * Returns foreign keys and entity references.
   *
   * @return array
   *   [CRM_Core_Reference_Interface]
   */
  public static function getReferenceColumns() {
    if (!isset(Civi::$statics[__CLASS__]['links'])) {
      Civi::$statics[__CLASS__]['links'] = static::createReferenceColumns(__CLASS__);
      Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'created_id', 'civicrm_contact', 'id');
      Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'modified_id', 'civicrm_contact', 'id');
      Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'saved_search_id', 'civicrm_saved_search', 'id');
      CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'links_callback', Civi::$statics[__CLASS__]['links']);
    }
    return Civi::$statics[__CLASS__]['links'];
  }

  /**
   * Returns all the column names of this table
   *
   * @return array
   */
  public static function &fields() {
    if (!isset(Civi::$statics[__CLASS__]['fields'])) {
      Civi::$statics[__CLASS__]['fields'] = [
        'id' => [
          'name' => 'id',
          'type' => CRM_Utils_Type::T_INT,
          'title' => ts('Batch ID'),
          'description' => ts('Unique Address ID'),
          'required' => TRUE,
          'where' => 'civicrm_batch.id',
          'table_name' => 'civicrm_batch',
          'entity' => 'Batch',
          'bao' => 'CRM_Batch_BAO_Batch',
          'localizable' => 0,
          'html' => [
            'type' => 'Number',
          ],
          'readonly' => TRUE,
          'add' => '3.3',
        ],
        'name' => [
          'name' => 'name',
          'type' => CRM_Utils_Type::T_STRING,
          'title' => ts('Batch Name'),
          'description' => ts('Variable name/programmatic handle for this batch.'),
          'maxlength' => 64,
          'size' => CRM_Utils_Type::BIG,
          'where' => 'civicrm_batch.name',
          'table_name' => 'civicrm_batch',
          'entity' => 'Batch',
          'bao' => 'CRM_Batch_BAO_Batch',
          'localizable' => 0,
          'html' => [
            'type' => 'Text',
          ],
          'add' => '3.3',
        ],
        'title' => [
          'name' => 'title',
          'type' => CRM_Utils_Type::T_STRING,
          'title' => ts('Batch Title'),
          'description' => ts('Friendly Name.'),
          'maxlength' => 255,
          'size' => CRM_Utils_Type::HUGE,
          'where' => 'civicrm_batch.title',
          'table_name' => 'civicrm_batch',
          'entity' => 'Batch',
          'bao' => 'CRM_Batch_BAO_Batch',
          'localizable' => 1,
          'html' => [
            'type' => 'Text',
          ],
          'add' => '4.2',
        ],
        'description' => [
          'name' => 'description',
          'type' => CRM_Utils_Type::T_TEXT,
          'title' => ts('Batch Description'),
          'description' => ts('Description of this batch set.'),
          'rows' => 4,
          'cols' => 80,
          'where' => 'civicrm_batch.description',
          'table_name' => 'civicrm_batch',
          'entity' => 'Batch',
          'bao' => 'CRM_Batch_BAO_Batch',
          'localizable' => 1,
          'html' => [
            'type' => 'TextArea',
          ],
          'add' => '3.3',
        ],
        'created_id' => [
          'name' => 'created_id',
          'type' => CRM_Utils_Type::T_INT,
          'title' => ts('Created By Contact ID'),
          'description' => ts('FK to Contact ID'),
          'where' => 'civicrm_batch.created_id',
          'table_name' => 'civicrm_batch',
          'entity' => 'Batch',
          'bao' => 'CRM_Batch_BAO_Batch',
          'localizable' => 0,
          'FKClassName' => 'CRM_Contact_DAO_Contact',
          'html' => [
            'label' => ts("Created By"),
          ],
          'add' => '3.3',
        ],
        'created_date' => [
          'name' => 'created_date',
          'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME,
          'title' => ts('Batch Created Date'),
          'description' => ts('When was this item created'),
          'where' => 'civicrm_batch.created_date',
          'table_name' => 'civicrm_batch',
          'entity' => 'Batch',
          'bao' => 'CRM_Batch_BAO_Batch',
          'localizable' => 0,
          'html' => [
            'type' => 'Select Date',
            'formatType' => 'activityDateTime',
          ],
          'add' => '3.3',
        ],
        'modified_id' => [
          'name' => 'modified_id',
          'type' => CRM_Utils_Type::T_INT,
          'title' => ts('Modified By Contact ID'),
          'description' => ts('FK to Contact ID'),
          'where' => 'civicrm_batch.modified_id',
          'table_name' => 'civicrm_batch',
          'entity' => 'Batch',
          'bao' => 'CRM_Batch_BAO_Batch',
          'localizable' => 0,
          'FKClassName' => 'CRM_Contact_DAO_Contact',
          'html' => [
            'label' => ts("Modified By"),
          ],
          'add' => '3.3',
        ],
        'modified_date' => [
          'name' => 'modified_date',
          'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME,
          'title' => ts('Batch Modified Date'),
          'description' => ts('When was this item modified'),
          'where' => 'civicrm_batch.modified_date',
          'table_name' => 'civicrm_batch',
          'entity' => 'Batch',
          'bao' => 'CRM_Batch_BAO_Batch',
          'localizable' => 0,
          'readonly' => TRUE,
          'add' => '3.3',
        ],
        'saved_search_id' => [
          'name' => 'saved_search_id',
          'type' => CRM_Utils_Type::T_INT,
          'title' => ts('Smart Group ID'),
          'description' => ts('FK to Saved Search ID'),
          'where' => 'civicrm_batch.saved_search_id',
          'table_name' => 'civicrm_batch',
          'entity' => 'Batch',
          'bao' => 'CRM_Batch_BAO_Batch',
          'localizable' => 0,
          'FKClassName' => 'CRM_Contact_DAO_SavedSearch',
          'html' => [
            'type' => 'EntityRef',
            'label' => ts("Smart Group"),
          ],
          'add' => '4.1',
        ],
        'status_id' => [
          'name' => 'status_id',
          'type' => CRM_Utils_Type::T_INT,
          'title' => ts('Batch Status'),
          'description' => ts('fk to Batch Status options in civicrm_option_values'),
          'required' => TRUE,
          'where' => 'civicrm_batch.status_id',
          'table_name' => 'civicrm_batch',
          'entity' => 'Batch',
          'bao' => 'CRM_Batch_BAO_Batch',
          'localizable' => 0,
          'html' => [
            'type' => 'Select',
          ],
          'pseudoconstant' => [
            'optionGroupName' => 'batch_status',
            'optionEditPath' => 'civicrm/admin/options/batch_status',
          ],
          'add' => '4.2',
        ],
        'type_id' => [
          'name' => 'type_id',
          'type' => CRM_Utils_Type::T_INT,
          'title' => ts('Batch Type'),
          'description' => ts('fk to Batch Type options in civicrm_option_values'),
          'where' => 'civicrm_batch.type_id',
          'table_name' => 'civicrm_batch',
          'entity' => 'Batch',
          'bao' => 'CRM_Batch_BAO_Batch',
          'localizable' => 0,
          'html' => [
            'type' => 'Select',
          ],
          'pseudoconstant' => [
            'optionGroupName' => 'batch_type',
            'optionEditPath' => 'civicrm/admin/options/batch_type',
          ],
          'add' => '4.2',
        ],
        'mode_id' => [
          'name' => 'mode_id',
          'type' => CRM_Utils_Type::T_INT,
          'title' => ts('Batch Mode'),
          'description' => ts('fk to Batch mode options in civicrm_option_values'),
          'where' => 'civicrm_batch.mode_id',
          'table_name' => 'civicrm_batch',
          'entity' => 'Batch',
          'bao' => 'CRM_Batch_BAO_Batch',
          'localizable' => 0,
          'html' => [
            'type' => 'Select',
          ],
          'pseudoconstant' => [
            'optionGroupName' => 'batch_mode',
            'optionEditPath' => 'civicrm/admin/options/batch_mode',
          ],
          'add' => '4.2',
        ],
        'total' => [
          'name' => 'total',
          'type' => CRM_Utils_Type::T_MONEY,
          'title' => ts('Batch Total'),
          'description' => ts('Total amount for this batch.'),
          'precision' => [
            20,
            2,
          ],
          'where' => 'civicrm_batch.total',
          'table_name' => 'civicrm_batch',
          'entity' => 'Batch',
          'bao' => 'CRM_Batch_BAO_Batch',
          'localizable' => 0,
          'html' => [
            'type' => 'Text',
          ],
          'add' => '4.2',
        ],
        'item_count' => [
          'name' => 'item_count',
          'type' => CRM_Utils_Type::T_INT,
          'title' => ts('Batch Number of Items'),
          'description' => ts('Number of items in a batch.'),
          'where' => 'civicrm_batch.item_count',
          'table_name' => 'civicrm_batch',
          'entity' => 'Batch',
          'bao' => 'CRM_Batch_BAO_Batch',
          'localizable' => 0,
          'html' => [
            'type' => 'Text',
          ],
          'add' => '4.2',
        ],
        'payment_instrument_id' => [
          'name' => 'payment_instrument_id',
          'type' => CRM_Utils_Type::T_INT,
          'title' => ts('Batch Payment Method'),
          'description' => ts('fk to Payment Instrument options in civicrm_option_values'),
          'where' => 'civicrm_batch.payment_instrument_id',
          'table_name' => 'civicrm_batch',
          'entity' => 'Batch',
          'bao' => 'CRM_Batch_BAO_Batch',
          'localizable' => 0,
          'html' => [
            'type' => 'Select',
          ],
          'pseudoconstant' => [
            'optionGroupName' => 'payment_instrument',
            'optionEditPath' => 'civicrm/admin/options/payment_instrument',
          ],
          'add' => '4.3',
        ],
        'exported_date' => [
          'name' => 'exported_date',
          'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME,
          'title' => ts('Batch Exported Date'),
          'where' => 'civicrm_batch.exported_date',
          'table_name' => 'civicrm_batch',
          'entity' => 'Batch',
          'bao' => 'CRM_Batch_BAO_Batch',
          'localizable' => 0,
          'add' => '4.3',
        ],
        'data' => [
          'name' => 'data',
          'type' => CRM_Utils_Type::T_LONGTEXT,
          'title' => ts('Batch Data'),
          'description' => ts('cache entered data'),
          'where' => 'civicrm_batch.data',
          'table_name' => 'civicrm_batch',
          'entity' => 'Batch',
          'bao' => 'CRM_Batch_BAO_Batch',
          'localizable' => 0,
          'add' => '4.4',
        ],
      ];
      CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
    }
    return Civi::$statics[__CLASS__]['fields'];
  }

  /**
   * Return a mapping from field-name to the corresponding key (as used in fields()).
   *
   * @return array
   *   Array(string $name => string $uniqueName).
   */
  public static function &fieldKeys() {
    if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {
      Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields()));
    }
    return Civi::$statics[__CLASS__]['fieldKeys'];
  }

  /**
   * Returns the names of this table
   *
   * @return string
   */
  public static function getTableName() {
    return CRM_Core_DAO::getLocaleTableName(self::$_tableName);
  }

  /**
   * Returns if this table needs to be logged
   *
   * @return bool
   */
  public function getLog() {
    return self::$_log;
  }

  /**
   * Returns the list of fields that can be imported
   *
   * @param bool $prefix
   *
   * @return array
   */
  public static function &import($prefix = FALSE) {
    $r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, 'batch', $prefix, []);
    return $r;
  }

  /**
   * Returns the list of fields that can be exported
   *
   * @param bool $prefix
   *
   * @return array
   */
  public static function &export($prefix = FALSE) {
    $r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'batch', $prefix, []);
    return $r;
  }

  /**
   * Returns the list of indices
   *
   * @param bool $localize
   *
   * @return array
   */
  public static function indices($localize = TRUE) {
    $indices = [
      'UI_name' => [
        'name' => 'UI_name',
        'field' => [
          0 => 'name',
        ],
        'localizable' => FALSE,
        'unique' => TRUE,
        'sig' => 'civicrm_batch::1::name',
      ],
    ];
    return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;
  }

}
