/**
* function to get batch list
*
- * @return array array of batches
+ * @return array array of all batches
+ * excluding batches with data entry in progress
*/
static function getBatches() {
- $query = 'SELECT id, title
+ $dataEntryStatusId = CRM_Core_OptionGroup::getValue('batch_status','Data Entry');
+ $query = "SELECT id, title
FROM civicrm_batch
- WHERE type_id IN (1,2)
- AND status_id = 2
- ORDER BY id DESC';
+ WHERE item_count >= 1
+ AND status_id != {$dataEntryStatusId}
+ ORDER BY id DESC";
$batches = array();
$dao = CRM_Core_DAO::executeQuery($query);
}
if (array_key_exists('Address', $this->_editOptions)) {
- $this->addFormRule(array('CRM_Contact_Form_Edit_Address', 'formRule'));
+ $this->addFormRule(array('CRM_Contact_Form_Edit_Address', 'formRule'), $this);
}
if (array_key_exists('CommunicationPreferences', $this->_editOptions)) {
static function formRule($fields) {
$errors = array();
// check for state/country mapping
- CRM_Contact_Form_Edit_Address::formRule($fields, $errors);
+ $errors = CRM_Contact_Form_Edit_Address::formRule($fields, CRM_Core_DAO::$_nullArray, CRM_Core_DAO::$_nullObject);
//fix for CRM-3552,
//as we use "fromName"<emailaddresss> format for domain email.
// And we can't set it to 'address_' because we want to set it in a slightly different format.
CRM_Core_BAO_CustomGroup::buildQuickForm($form, $groupTree, FALSE, 'dnc_');
+ // during contact editing : if no address is filled
+ // required custom data must not produce 'required' form rule error
+ // more handling done in formRule func
+ if (!$inlineEdit) {
+ CRM_Contact_Form_Edit_Address::storeRequiredCustomDataInfo($form, $groupTree);
+ }
+
$template = CRM_Core_Smarty::singleton();
$tplGroupTree = $template->get_template_vars('address_groupTree');
$tplGroupTree = empty($tplGroupTree) ? array(
* @access public
* @static
*/
- static function formRule($fields) {
+ static function formRule($fields, $files, $self) {
$errors = array();
+
+ $customDataRequiredFields = array();
+ if (property_exists($self, '_addressRequireOmission')) {
+ $customDataRequiredFields = explode(',', $self->_addressRequireOmission);
+ }
+
// check for state/county match if not report error to user.
if (CRM_Utils_Array::value('address', $fields) && is_array($fields['address'])) {
foreach ($fields['address'] as $instance => $addressValues) {
+
if (CRM_Utils_System::isNull($addressValues)) {
+ // DETACH 'required' form rule error to
+ // custom data only if address data not exists upon submission
+ if (!empty($customDataRequiredFields)) {
+ foreach($customDataRequiredFields as $customElementName) {
+ $elementName = "address[$instance][$customElementName]";
+ if ($self->getElementError($elementName)) {
+ // set element error to none
+ $self->setElementError($elementName, NULL);
+ }
+ }
+ }
continue;
}
+ // DETACH 'required' form rule error to
+ // custom data only if address data not exists upon submission
+ if (!empty($customDataRequiredFields) && !CRM_Core_BAO_Address::dataExists($addressValues)) {
+ foreach($customDataRequiredFields as $customElementName) {
+ $elementName = "address[$instance][$customElementName]";
+ if ($self->getElementError($elementName)) {
+ // set element error to none
+ $self->setElementError($elementName, NULL);
+ }
+ }
+ }
+
$countryId = CRM_Utils_Array::value('country_id', $addressValues);
+
$stateProvinceId = CRM_Utils_Array::value('state_province_id', $addressValues);
//do check for mismatch countries
// end of parse address functionality
}
}
-}
+
+ static function storeRequiredCustomDataInfo(&$form, $groupTree) {
+ if (CRM_Utils_System::getClassName($form) == 'CRM_Contact_Form_Contact') {
+ $requireOmission = NULL;
+ foreach ($groupTree as $csId => $csVal) {
+ // only process Address entity fields
+ if ($csVal['extends'] != 'Address') {
+ continue;
+ }
+
+ foreach ($csVal['fields'] as $cdId => $cdVal) {
+ if ($cdVal['is_required']) {
+ $elementName = $cdVal['element_name'];
+ if (in_array($elementName, $form->_required)) {
+ // store the omitted rule for a element, to be used later on
+ $requireOmission .= $cdVal['element_custom_name'] . ',';
+ }
+ }
+ }
+ }
+
+ $form->_addressRequireOmission = rtrim($requireOmission, ',');
+ }
+ }
+}
\ No newline at end of file
CRM_Utils_Array::value('prefix', $defaults),
CRM_Utils_Array::value('suffix', $defaults)
);
+ $organizationName = CRM_Utils_Array::value('organization_name', $defaults);
+ if ($organizationName !== NULL) {
+ $vcard->addOrganization($organizationName);
+ }
}
elseif ($defaults['contact_type'] == 'Organization') {
$vcard->setName($defaults['organization_name'], '', '', '', '');
}
return CRM_Core_PseudoConstant::get(__CLASS__, $fieldName, $params, $context);
}
-}
+}
\ No newline at end of file
*/
static function formRule($fields) {
// check for state/country mapping
- $errors = CRM_Contact_Form_Edit_Address::formRule($fields);
+ $errors = CRM_Contact_Form_Edit_Address::formRule($fields, CRM_Core_DAO::$_nullArray, CRM_Core_DAO::$_nullObject);
return empty($errors) ? TRUE : $errors;
}
foreach ($this->_columns as $tableName => $table) {
if (array_key_exists('fields', $table)) {
foreach ($table['fields'] as $fieldName => $field) {
- if (!array_key_exists('no_display', $field)) {
+ if (!CRM_Utils_Array::value('no_display', $field)) {
if (isset($field['required'])) {
// set default
$this->_defaults['fields'][$fieldName] = 1;
if (array_key_exists('fields', $table)) {
foreach ($table['fields'] as $fieldName => $field) {
$groupTitle = '';
- if (!array_key_exists('no_display', $field)) {
+ if (!CRM_Utils_Array::value('no_display', $field)) {
foreach ( array('table', 'field') as $var) {
if (!empty(${$var}['grouping'])) {
if (!is_array(${$var}['grouping'])) {
if ($this->_autoIncludeIndexedFieldsAsOrderBys && array_key_exists('extends', $table) && !empty($table['extends'])) {
foreach ($table['fields'] as $fieldName => $field) {
- if (!array_key_exists('no_display', $field)) {
+ if (!CRM_Utils_Array::value('no_display', $field)) {
$options[$fieldName] = $field['title'];
}
}
// unset columns not to be displayed.
foreach ($this->_columnHeaders as $key => $value) {
- if (is_array($value) && isset($value['no_display'])) {
+ if (CRM_Utils_Array::value('no_display', $value)) {
unset($this->_columnHeaders[$key]);
}
}
protected $_nameFieldHonor = FALSE;
protected $_summary = NULL;
+ protected $_allBatches = NULL;
protected $_customGroupExtends = array(
'Contribution');
$this->_tagFilter = TRUE;
// Don't show Batch display column and filter unless batches are being used
- $this->_closedBatches = CRM_Batch_BAO_Batch::getBatches();
- if (!empty($this->_closedBatches)) {
+ $this->_allBatches = CRM_Batch_BAO_Batch::getBatches();
+ if (!empty($this->_allBatches)) {
$this->_columns['civicrm_batch']['dao'] = 'CRM_Batch_DAO_Batch';
$this->_columns['civicrm_batch']['fields']['batch_id'] = array(
'name' => 'id',
'title' => ts('Batch Name'),
'type' => CRM_Utils_Type::T_INT,
'operatorType' => CRM_Report_Form::OP_MULTISELECT,
- 'options' => $this->_closedBatches,
+ 'options' => $this->_allBatches,
);
$this->_columns['civicrm_entity_batch']['dao'] = 'CRM_Batch_DAO_EntityBatch';
$this->_columns['civicrm_entity_batch']['fields']['entity_batch_id'] = array(
{$this->_aliases['civicrm_contribution']}.id = {$this->_aliases['civicrm_note']}.entity_id )";
}
//for contribution batches
- if ($this->_closedBatches && CRM_Utils_Array::value('batch_id', $this->_params['fields'])) {
+ if ($this->_allBatches &&
+ (CRM_Utils_Array::value('batch_id', $this->_params['fields']) || !empty($this->_params['bid_value']))) {
$this->_from .= "
+ LEFT JOIN civicrm_entity_financial_trxn tx ON (tx.entity_id = {$this->_aliases['civicrm_contribution']}.id AND
+ tx.entity_table = 'civicrm_contribution')
LEFT JOIN civicrm_entity_batch {$this->_aliases['civicrm_entity_batch']}
- ON ({$this->_aliases['civicrm_entity_batch']}.entity_id = {$this->_aliases['civicrm_contribution']}.id AND
- {$this->_aliases['civicrm_entity_batch']}.entity_table = 'civicrm_contribution')
+ ON ({$this->_aliases['civicrm_entity_batch']}.entity_id = tx.financial_trxn_id AND
+ {$this->_aliases['civicrm_entity_batch']}.entity_table = 'civicrm_financial_trxn')
LEFT JOIN civicrm_batch {$this->_aliases['civicrm_batch']}
ON {$this->_aliases['civicrm_batch']}.id = {$this->_aliases['civicrm_entity_batch']}.batch_id";
}
protected $_nameFieldHonor = FALSE;
protected $_summary = NULL;
+ protected $_allBatches = NULL;
protected $_customGroupExtends = array(
'Contribution', 'Membership');
$this->_tagFilter = TRUE;
// Don't show Batch display column and filter unless batches are being used
- $this->_closedBatches = CRM_Batch_BAO_Batch::getBatches();
- if (!empty($this->_closedBatches)) {
+ $this->_allBatches = CRM_Batch_BAO_Batch::getBatches();
+ if (!empty($this->_allBatches)) {
$this->_columns['civicrm_batch']['dao'] = 'CRM_Batch_DAO_Batch';
$this->_columns['civicrm_batch']['fields']['batch_id'] = array(
'name' => 'id',
'title' => ts('Batch Name'),
'type' => CRM_Utils_Type::T_INT,
'operatorType' => CRM_Report_Form::OP_MULTISELECT,
- 'options' => $this->_closedBatches,
+ 'options' => $this->_allBatches,
);
$this->_columns['civicrm_entity_batch']['dao'] = 'CRM_Batch_DAO_EntityBatch';
$this->_columns['civicrm_entity_batch']['fields']['entity_batch_id'] = array(
{$this->_aliases['civicrm_phone']}.is_primary = 1)";
}
//for contribution batches
- if ($this->_closedBatches &&
+ if ($this->_allBatches &&
(CRM_Utils_Array::value('batch_id', $this->_params['fields']) || !empty($this->_params['bid_value']))) {
$this->_from .= "
+ LEFT JOIN civicrm_entity_financial_trxn tx ON (tx.entity_id = {$this->_aliases['civicrm_contribution']}.id AND
+ tx.entity_table = 'civicrm_contribution')
LEFT JOIN civicrm_entity_batch {$this->_aliases['civicrm_entity_batch']}
- ON ({$this->_aliases['civicrm_entity_batch']}.entity_id = {$this->_aliases['civicrm_contribution']}.id AND
- {$this->_aliases['civicrm_entity_batch']}.entity_table = 'civicrm_contribution')
+ ON ({$this->_aliases['civicrm_entity_batch']}.entity_id = tx.financial_trxn_id AND
+ {$this->_aliases['civicrm_entity_batch']}.entity_table = 'civicrm_financial_trxn')
LEFT JOIN civicrm_batch {$this->_aliases['civicrm_batch']}
ON {$this->_aliases['civicrm_batch']}.id = {$this->_aliases['civicrm_entity_batch']}.batch_id";
}