function run()
 {
     $countries = CRM_Bic_Parser_Parser::getParserList();
     $stats = civicrm_api3('Bic', 'stats');
     $total_count = 0;
     foreach ($countries as $country) {
         if (isset($stats['values'][$country])) {
             $total_count += $stats['values'][$country];
         } else {
             $stats['values'][$country] = 0;
         }
     }
     // gather the names
     $country_names = array();
     $config = CRM_Core_Config::singleton();
     $id2code = CRM_Core_PseudoConstant::countryIsoCode();
     $default_country = $id2code[$config->defaultContactCountry];
     $code2id = array_flip($id2code);
     $id2country = CRM_Core_PseudoConstant::country(FALSE, FALSE);
     foreach ($countries as $code) {
         $country_id = $code2id[$code];
         $country_name = $id2country[$country_id];
         $country_names[$code] = $country_name;
     }
     $this->assign('countries', $countries);
     $this->assign('country_names', $country_names);
     $this->assign('default_country', $default_country);
     $this->assign('stats', $stats['values']);
     $this->assign('total_count', $total_count);
     parent::run();
 }
Example #2
0
/**
 * API call to update the stored bank data
 *
 * @param 'country'   country code to update or 'all'
 */
function civicrm_api3_bic_update($params)
{
    if (empty($params['country'])) {
        return civicrm_api3_create_error("No country given");
    }
    $countries = array();
    if ($params['country'] == 'all') {
        $countries = CRM_Bic_Parser_Parser::getParserList();
    } else {
        $countries[] = $params['country'];
    }
    // now, loop through the given countries
    $result = array();
    $total_count = 0;
    foreach ($countries as $country) {
        $parser = CRM_Bic_Parser_Parser::getParser($country);
        if (empty($parser)) {
            return civicrm_api3_create_error("Parser for '{$country}' not found!");
        }
        // and execute update for each
        // TODO: process errors
        $result[$country] = $parser->update();
        $total_count += $result[$country]['count'];
    }
    $null = NULL;
    return civicrm_api3_create_success($result, $params, $null, $null, $null, array('total_count' => $total_count));
}