You are here

private function wf_crm_admin_form::buildGrantTab in Webform CiviCRM Integration 7.4

Same name and namespace in other branches
  1. 7.5 includes/wf_crm_admin_form.inc \wf_crm_admin_form::buildGrantTab()

Grant settings FIXME: This is nearly the same code as buildCaseTab. More utilities and less boilerplate needed.

1 call to wf_crm_admin_form::buildGrantTab()
wf_crm_admin_form::buildForm in includes/wf_crm_admin_form.inc
Build admin form for civicrm tab of a webform

File

includes/wf_crm_admin_form.inc, line 1063
Webform CiviCRM module's admin form.

Class

wf_crm_admin_form
@file Webform CiviCRM module's admin form.

Code

private function buildGrantTab() {
  $types = wf_crm_apivalues('grant', 'getoptions', array(
    'field' => 'grant_type_id',
  ));
  if (!$types) {
    return;
  }
  $this->form['grantTab'] = array(
    '#type' => 'fieldset',
    '#title' => t('Grants'),
    '#group' => 'webform_civicrm',
    '#attributes' => array(
      'class' => array(
        'civi-icon-grant',
      ),
    ),
  );
  $this->form['grantTab']["grant_number_of_grant"] = array(
    '#type' => 'select',
    '#title' => t('Number of Grants'),
    '#default_value' => $num = wf_crm_aval($this->data, "grant:number_of_grant", 0),
    '#options' => range(0, $this->sets['grant']['max_instances']),
    '#prefix' => '<div class="number-of">',
    '#suffix' => '</div>',
  );
  $this
    ->addAjaxItem("grantTab", "grant_number_of_grant", "grant");
  for ($n = 1; $n <= $num; ++$n) {
    $fs = "grant_grant_{$n}_fieldset";
    $this->form['grantTab']['grant'][$fs] = array(
      '#type' => 'fieldset',
      '#title' => t('Grant !num', array(
        '!num' => $n,
      )),
      'wrap' => array(
        '#weight' => 9,
      ),
    );
    $this->form['grantTab']['grant'][$fs]["grant_{$n}_settings_existing_grant_status"] = array(
      '#type' => 'select',
      '#title' => t('Update Existing Grant'),
      '#options' => array(
        '' => '- ' . t('None') . ' -',
      ) + wf_crm_apivalues('grant', 'getoptions', array(
        'field' => 'status_id',
      )),
      '#default_value' => wf_crm_aval($this->data, "grant:{$n}:existing_grant_status", array()),
      '#multiple' => TRUE,
    );
    $this
      ->help($this->form['grantTab']['grant'][$fs]["grant_{$n}_settings_existing_grant_status"], 'existing_grant_status');
    $grant_type = wf_crm_aval($this->data, "grant:{$n}:grant:1:grant_type_id");
    foreach ($this->sets as $sid => $set) {
      if ($set['entity_type'] == 'grant' && (!$grant_type || empty($set['sub_types']) || in_array($grant_type, $set['sub_types']))) {
        $fs1 = "grant_grant_{$n}_fieldset_{$sid}";
        if ($sid == 'grant') {
          $pos =& $this->form['grantTab']['grant'][$fs];
        }
        else {
          $pos =& $this->form['grantTab']['grant'][$fs]['wrap'];
        }
        $pos[$fs1] = array(
          '#type' => 'fieldset',
          '#title' => $set['label'],
          '#attributes' => array(
            'id' => $fs1,
            'class' => array(
              'web-civi-checkbox-set',
            ),
          ),
          'js_select' => $this
            ->addToggle($fs1),
        );
        $this
          ->addDynamicCustomSetting($pos[$fs1], $sid, 'grant', $n);
        if (isset($set['fields'])) {
          foreach ($set['fields'] as $fid => $field) {
            $fid = "civicrm_{$n}_grant_1_{$fid}";
            $pos[$fs1][$fid] = $this
              ->addItem($fid, $field);
          }
        }
      }
    }
    $this
      ->addAjaxItem("grantTab:grant:{$fs}:grant_grant_{$n}_fieldset_grant", "civicrm_{$n}_grant_1_grant_grant_type_id", "..:wrap");
  }
}