Example #1
0
 function __construct()
 {
     $this->_columns = array('civicrm_entity_batch' => array('dao' => 'CRM_Core_DAO_EntityBatch', 'filters' => array('batch_id' => array('title' => 'Batch', 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => GiftAid_Utils_Contribution::getBatchIdTitle('id desc')))), 'civicrm_contribution' => array('dao' => 'CRM_Contribute_DAO_Contribution', 'fields' => array('contribution_id' => array('name' => 'id', 'no_display' => true, 'required' => true))));
     parent::__construct();
     // set defaults
     if (is_array($this->_columns['civicrm_value_gift_aid_submission'])) {
         foreach ($this->_columns['civicrm_value_gift_aid_submission']['fields'] as $field => $values) {
             $this->_columns['civicrm_value_gift_aid_submission']['fields'][$field]['default'] = true;
         }
     }
 }
 /**
  * process the form after the input has been submitted and validated
  *
  * @access public
  * @return None
  */
 public function postProcess()
 {
     $params = $this->controller->exportValues();
     $batchParams = array();
     $batchParams['label'] = $params['title'];
     $batchParams['name'] = CRM_Utils_String::titleToVar($params['title'], 63);
     $batchParams['description'] = $params['description'];
     $batchParams['batch_type'] = "Gift Aid";
     $session =& CRM_Core_Session::singleton();
     $batchParams['created_id'] = $session->get('userID');
     $batchParams['created_date'] = date("YmdHis");
     require_once 'CRM/Core/Transaction.php';
     $transaction = new CRM_Core_Transaction();
     require_once 'CRM/Core/BAO/Batch.php';
     $createdBatch =& CRM_Core_BAO_Batch::create($batchParams);
     $batchID = $createdBatch->id;
     $batchLabel = $batchParams['label'];
     require_once 'GiftAid/Utils/Contribution.php';
     list($total, $added, $notAdded) = GiftAid_Utils_Contribution::addContributionToBatch($this->_contributionIds, $batchID);
     if ($added <= 0) {
         // rollback since there were no contributions added, and we might not want to keep an empty batch
         $transaction->rollback();
         $status = ts('Could not create batch "%1", as there were no valid contribution(s) to be added.', array(1 => $batchLabel));
     } else {
         $status = array(ts('Added Contribution(s) to %1', array(1 => $batchLabel)), ts('Total Selected Contribution(s): %1', array(1 => $total)));
         if ($added) {
             $status[] = ts('Total Contribution(s) added to batch: %1', array(1 => $added));
         }
         if ($notAdded) {
             $status[] = ts('Total Contribution(s) already in batch or not valid: %1', array(1 => $notAdded));
         }
         $status = implode('<br/>', $status);
     }
     $transaction->commit();
     CRM_Core_Session::setStatus($status);
 }