function buildQuickForm() { $custom = sumfields_get_custom_field_definitions(); $options = array(); $field_options = array(); while (list($k, $v) = each($custom['fields'])) { $display = $v['display']; $field_options[$display][$k] = $v['label']; } if (count($field_options) == 0) { // This means neither CiviEvent or CiviContribute are enabled. $session = CRM_Core_Session::singleton(); $session->setStatus(ts("Summary Fields is not particularly useful if CiviContribute and CiviEvent are both disabled. Try enabling at least one.", array('domain' => 'net.ourpowerbase.sumfields'))); return; } // Evaluate the status of form changes and report to the user $apply_settings_status = sumfields_get_setting('generate_schema_and_data', FALSE); if (empty($apply_settings_status)) { $display_status = ts('The settings have never been saved (newly enabled)', array('domain' => 'net.ourpowerbase.sumfields')); } elseif (!preg_match('/^(scheduled|running|success|failed):([0-9 :\\-]+)$/', $apply_settings_status, $matches)) { $display_status = ts("Unable to determine status (%1).", array(1 => $apply_settings_status, 'domain' => 'net.ourpowerbase.sumfields')); } else { $display_status = NULL; $status = $matches[1]; $date = $matches[2]; switch ($status) { case 'scheduled': $display_status = ts("Setting changes were saved on %1, but not yet applied; they should be applied shortly.", array(1 => $date, 'domain' => 'net.ourpowerbase.sumfields')); break; case 'running': $display_status = ts("Setting changes are in the process of being applied; the process started on %1.", array(1 => $date, 'domain' => 'net.ourpowerbase.sumfields')); break; case 'success': $display_status = ts("Setting changes were successfully applied on %1.", array(1 => $date, 'domain' => 'net.ourpowerbase.sumfields')); break; case 'failed': $display_status = ts("Setting changes failed to apply; the failed attempt happend on %1.", array(1 => $date, 'domain' => 'net.ourpowerbase.sumfields')); break; } } $this->Assign('display_status', $display_status); // Evaluate status of the triggers and report to the user. if (sumfields_get_update_trigger('civicrm_contribution')) { $contribution_table_trigger_status = 'Enabled'; } else { $contribution_table_trigger_status = 'Not Enabled'; } $this->Assign('contribution_table_trigger_status', $contribution_table_trigger_status); if (sumfields_get_update_trigger('civicrm_participant')) { $participant_table_trigger_status = 'Enabled'; } else { $participant_table_trigger_status = 'Not Enabled'; } $this->Assign('participant_table_trigger_status', $participant_table_trigger_status); // Add active fields if (array_key_exists('fundraising', $field_options)) { $this->Assign('sumfields_active_fundraising', TRUE); $name = 'active_fundraising_fields'; $label = ts('Fundraising Fields', array('domain' => 'net.ourpowerbase.sumfields')); $this->addCheckBox($name, $label, array_flip($field_options['fundraising'])); } if (sumfields_component_enabled('CiviMember') && array_key_exists('membership', $field_options)) { $this->Assign('sumfields_active_membership', TRUE); $name = 'active_membership_fields'; $label = ts('Membership Fields', array('domain' => 'net.ourpowerbase.sumfields')); $this->addCheckBox($name, $label, array_flip($field_options['membership'])); } if (array_key_exists('event_standard', $field_options)) { $this->Assign('sumfields_active_event_standard', TRUE); $name = 'active_event_standard_fields'; $label = ts('Standard Event Fields', array('domain' => 'net.ourpowerbase.sumfields')); $this->addCheckBox($name, $label, array_flip($field_options['event_standard'])); } if (array_key_exists('event_turnout', $field_options)) { $this->Assign('sumfields_active_event_turnout', TRUE); $name = 'active_event_turnout_fields'; $label = ts('Turnout Event Fields', array('domain' => 'net.ourpowerbase.sumfields')); $this->addCheckBox($name, $label, array_flip($field_options['event_turnout'])); } if (sumfields_component_enabled('CiviMember')) { $this->assign('sumfields_member', TRUE); $name = 'membership_financial_type_ids'; $label = ts('Membership Financial Types', array('domain' => 'net.ourpowerbase.sumfields')); $this->addCheckBox($name, $label, array_flip(sumfields_get_all_financial_types())); $this->addRule($name, ts('%1 is a required field.', array(1 => $label, 'domain' => 'net.ourpowerbase.sumfields')), 'required'); } if (sumfields_component_enabled('CiviContribute')) { $this->assign('sumfields_contribute', TRUE); $name = 'financial_type_ids'; $label = ts('Financial Types', array('domain' => 'net.ourpowerbase.sumfields')); $this->addCheckBox($name, $label, array_flip(sumfields_get_all_financial_types())); $this->addRule($name, ts('%1 is a required field.', array(1 => $label, 'domain' => 'net.ourpowerbase.sumfields')), 'required'); } if (sumfields_component_enabled('CiviEvent')) { $this->assign('sumfields_event', TRUE); $name = 'event_type_ids'; $label = ts('Event Types', array('domain' => 'net.ourpowerbase.sumfields')); $this->addCheckBox($name, $label, array_flip(sumfields_get_all_event_types())); $this->addRule($name, ts('%1 is a required field.', array(1 => $label, 'domain' => 'net.ourpowerbase.sumfields')), 'required'); $label = ts('Participant Status (attended)', array('domain' => 'net.ourpowerbase.sumfields')); $name = 'participant_status_ids'; $this->addCheckBox($name, $label, array_flip(sumfields_get_all_participant_status_types())); $this->addRule($name, ts('%1 is a required field.', array(1 => $label, 'domain' => 'net.ourpowerbase.sumfields')), 'required'); $label = ts('Participant Status (did not attend)', array('domain' => 'net.ourpowerbase.sumfields')); $name = 'participant_noshow_status_ids'; $this->addCheckBox($name, $label, array_flip(sumfields_get_all_participant_status_types())); $this->addRule($name, ts('%1 is a required field.', array(1 => $label, 'domain' => 'net.ourpowerbase.sumfields')), 'required'); } $name = 'when_to_apply_change'; $label = ts('When should these changes be applied?', array('domain' => 'net.ourpowerbase.sumfields')); $options = array('via_cron' => ts("On the next scheduled job (cron)", array('domain' => 'net.ourpowerbase.sumfields')), 'on_submit' => ts("When I submit this form", array('domain' => 'net.ourpowerbase.sumfields'))); $this->addRadio($name, $label, $options); $this->addButtons(array(array('type' => 'next', 'name' => ts('Save'), 'spacing' => ' ', 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel')))); }
/** * Return the $custom array with all the custom field * definitions. **/ function sumfields_get_custom_field_definitions() { static $custom = NULL; if (is_null($custom)) { // The custom.php file defines the $custom array of field // definitions. Only require if necessary. require 'custom.php'; } // Not all custom field definitions will be relevant to this // installation, so we have filter out any fields that come // from tables that are not installed. while (list($k, $v) = each($custom['fields'])) { if ($v['trigger_table'] == 'civicrm_contribution') { if (!sumfields_component_enabled('CiviContribute')) { unset($custom['fields'][$k]); } } elseif ($v['trigger_table'] == 'civicrm_participant') { if (!sumfields_component_enabled('CiviEvent')) { unset($custom['fields'][$k]); } } // Some of the custom fields depend on installed components if ($k == 'contribution_amount_last_membership_payment' || $k == 'contribution_date_last_membership_payment') { if (!sumfields_component_enabled('CiviMember')) { unset($custom['fields'][$k]); } } if ($k == 'event_turnout_attempts') { // event_turnout_attempts is triggered on the civicrm_participant table, // but it counts records in the civicrm custom table civirm_participant_info_NN. // We have to look up the name of that table for this particular instance as a // way to see if the table is installed. $actual_table_name = sumfields_get_participant_info_table(); if (!$actual_table_name) { // Perhaps not enabled. unset($custom['fields'][$k]); } } } reset($custom); return $custom; }