/**
  * Function to build the form
  *
  * @return None
  * @access public
  */
 public function buildQuickForm()
 {
     parent::buildQuickForm();
     if ($this->_action & CRM_Core_Action::DELETE) {
         return;
     }
     $this->applyFilter('__ALL__', 'trim');
     $attributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_Batch');
     $this->add('text', 'title', ts('Batch Name'), $attributes['name'], TRUE);
     $type = $this->add('select', 'type_id', ts('Type'), CRM_Core_PseudoConstant::getBatchType());
     if ($this->_action & CRM_Core_Action::UPDATE) {
         $type->freeze();
     }
     $this->add('textarea', 'description', ts('Description'), $attributes['description']);
     $this->add('text', 'item_count', ts('Number of items'), $attributes['item_count'], TRUE);
     $this->add('text', 'total', ts('Total Amount'), $attributes['total'], TRUE);
     $this->add('select', 'status_id', ts('Status'), CRM_Core_PseudoConstant::getBatchStatus());
 }
 /**
  * This function to get list of batches
  *
  * @param  array   $params associated array for params
  * @access public
  */
 static function getBatchList(&$params)
 {
     $config = CRM_Core_Config::singleton();
     $whereClause = self::whereClause($params, FALSE);
     if (!empty($params['rowCount']) && $params['rowCount'] > 0) {
         $limit = " LIMIT {$params['offset']}, {$params['rowCount']} ";
     }
     $orderBy = ' ORDER BY batch.id desc';
     if (CRM_Utils_Array::value('sort', $params)) {
         $orderBy = ' ORDER BY ' . CRM_Utils_Array::value('sort', $params);
     }
     $query = "\n      SELECT batch.*, c.sort_name created_by \n      FROM  civicrm_batch batch \n      INNER JOIN civicrm_contact c ON batch.created_id = c.id\n    WHERE {$whereClause}\n    {$orderBy}\n    {$limit}";
     $object = CRM_Core_DAO::executeQuery($query, $params, TRUE, 'CRM_Core_DAO_Batch');
     $links = self::links();
     $batchTypes = CRM_Core_PseudoConstant::getBatchType();
     $batchStatus = CRM_Core_PseudoConstant::getBatchStatus();
     $values = array();
     $creatorIds = array();
     while ($object->fetch()) {
         $newLinks = $links;
         $values[$object->id] = array();
         CRM_Core_DAO::storeValues($object, $values[$object->id]);
         $action = array_sum(array_keys($newLinks));
         if ($values[$object->id]['status_id'] == 2) {
             $newLinks = array();
         }
         $values[$object->id]['batch_type'] = $batchTypes[$values[$object->id]['type_id']];
         $values[$object->id]['batch_status'] = $batchStatus[$values[$object->id]['status_id']];
         $values[$object->id]['created_by'] = $object->created_by;
         $values[$object->id]['action'] = CRM_Core_Action::formLink($newLinks, $action, array('id' => $object->id));
     }
     return $values;
 }