<commit_before><?php

require_once 'nycgeoclientgeocoder.civix.php';

function nycgeoclientgeocoder_civicrm_post($op, $objectName, $objectId, &$objectRef) {
  //If the state is NY (state_provice_id of 1031), then use the NYC API.
  if ($objectRef->state_province_id == 1031) {
    $bbl = CRM_Nycgeoclient::getBbl($objectRef);
    if ($bbl) {
      // FIXME: You don't need to use "custom_x", you can use BBL:BBL, but I don't 100%
      // know the syntax.  The Electoral API does this though.
      // Get the BBL custom field ID.
      $bbl_field = "custom_" . CRM_Nycgeoclient::getBblFieldId();
      // Store the BBL.
      $params['entity_id'] = $objectId;
      $params[$bbl_field] = $bbl;
      $result = civicrm_api3('CustomValue', 'create', $params);
    }
  }
}

function nycgeoclientgeocoder_civicrm_check(&$messages) {
  nycgeoclientgeocoder_addressParsingIsEnabled($messages);
}

function nycgeoclientgeocoder_addressParsingIsEnabled(&$messages) {
  // Get the value of "Street Address Parsing" from the option values table.
  $id = civicrm_api3('OptionValue', 'getsingle', array(
    'return' => array("value"),
    'option_group_id' => "address_options",
    'name' => "street_address_parsing",
  ));
  // Get the address_options.
  $result = civicrm_api3('Setting', 'get', array(
    'sequential' => 1,
    'return' => array("address_options"),
  ));
  // Is "Street Address Parsing" set in address_options?
  $parsingEnabled = in_array($id['value'], $result['values'][0]['address_options']);
  if (!$parsingEnabled) {
    $messages[] = new CRM_Utils_Check_Message(
      'nycgeoclientgeocoder_parsingEnabled',
      ts('You have enabled the NYC Geo Client Geocoder extension, but you have not enabled "Street Address Parsing" field in Administer menu » Localization » Address Settings.'),<commit_msg>Only fire on address objects; refactor code to set BBL into the appropriate class<commit_after><?php

require_once 'nycgeoclientgeocoder.civix.php';

function nycgeoclientgeocoder_civicrm_post($op, $objectName, $objectId, &$objectRef) {
  //If the state is NY (state_provice_id of 1031), then use the NYC API.
  if ($objectName == 'Address' && $objectRef->state_province_id == 1031) {
    if ($op != 'create' && $op != 'edit') {
      return;
    }
    $bbl = CRM_Nycgeoclient::getBbl($objectRef);
    if ($bbl) {
      CRM_Nycgeoclient::setBbl($objectId, $bbl);
    }
  }
}

function nycgeoclientgeocoder_civicrm_check(&$messages) {
  nycgeoclientgeocoder_addressParsingIsEnabled($messages);
}

function nycgeoclientgeocoder_addressParsingIsEnabled(&$messages) {
  // Get the value of "Street Address Parsing" from the option values table.
  $id = civicrm_api3('OptionValue', 'getsingle', array(
    'return' => array("value"),
    'option_group_id' => "address_options",
    'name' => "street_address_parsing",
  ));
  // Get the address_options.
  $result = civicrm_api3('Setting', 'get', array(
    'sequential' => 1,
    'return' => array("address_options"),
  ));
  // Is "Street Address Parsing" set in address_options?
  $parsingEnabled = in_array($id['value'], $result['values'][0]['address_options']);
  if (!$parsingEnabled) {
    $messages[] = new CRM_Utils_Check_Message(
      'nycgeoclientgeocoder_parsingEnabled',
      ts('You have enabled the NYC Geo Client Geocoder extension, but you have not enabled "Street Address Parsing" field in Administer menu » Localization » Address Settings.'),
{'fraction_non_alphanumeric': 0.13580607476635514, 'fraction_numerical': 0.008177570093457943, 'mean_word_length': 4.542071197411003, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2193441', 'n_tokens_mistral': 1209, 'n_tokens_neox': 1146, 'n_words': 282}