Exemplo n.º 1
0
 /**
  * Create a new CustomValue record
  *
  * @param array $params  The values for the new record
  *
  * @return object  The new BAO
  * @access public
  * @static
  */
 function create(&$params)
 {
     $customValue =& new CRM_Core_BAO_CustomValue();
     $customValue->copyValues($params);
     switch ($params['type']) {
         case 'StateProvince':
             //$states =& CRM_Core_PseudoConstant::stateProvince();
             //$customValue->int_data = CRM_Utils_Array::key($params['value'], $states);
             //$customValue->char_data = $params['value'];
             if (!is_numeric($params['value'])) {
                 $states = array();
                 $states['state_province'] = $params['value'];
                 CRM_Contact_BAO_Contact::lookupValue($states, 'state_province', CRM_Core_PseudoConstant::stateProvince(), true);
                 if (!$states['state_province_id']) {
                     CRM_Contact_BAO_Contact::lookupValue($states, 'state_province', CRM_Core_PseudoConstant::stateProvinceAbbreviation(), true);
                 }
                 $customValue->int_data = $states['state_province_id'];
             } else {
                 $customValue->int_data = $params['value'];
             }
             break;
         case 'Country':
             //$countries =& CRM_Core_PseudoConstant::country();
             //$customValue->int_data = CRM_Utils_Array::key($params['value'], $countries);
             //$customValue->char_data = $params['value'];
             if (!is_numeric($params['value'])) {
                 $countries = array();
                 $countries['country'] = $params['value'];
                 CRM_Contact_BAO_Contact::lookupValue($countries, 'country', CRM_Core_PseudoConstant::country(), true);
                 if (!$countries['country_id']) {
                     CRM_Contact_BAO_Contact::lookupValue($countries, 'country', CRM_Core_PseudoConstant::countryIsoCode(), true);
                 }
                 $customValue->int_data = $countries['country_id'];
             } else {
                 $customValue->int_data = $params['value'];
             }
             break;
         case 'String':
             $customValue->char_data = $params['value'];
             break;
         case 'Boolean':
             $customValue->int_data = CRM_Utils_String::strtobool($params['value']);
             break;
         case 'Int':
             $customValue->int_data = $params['value'];
             break;
         case 'Float':
             $customValue->float_data = $params['value'];
             break;
         case 'Money':
             $customValue->decimal_data = number_format($params['value'], 2, '.', '');
             break;
         case 'Memo':
             $customValue->memo_data = $params['value'];
             break;
         case 'Date':
             $customValue->date_data = $params['value'];
             break;
     }
     $customValue->save();
     return $customValue;
 }
Exemplo n.º 2
0
 /**
  *
  * Get the values for pseudoconstants for name->value and reverse.
  *
  * @param array   $defaults (reference) the default values, some of which need to be resolved.
  * @param boolean $reverse  true if we want to resolve the values in the reverse direction (value -> name)
  *
  * @return none
  * @access public
  * @static
  */
 function resolveDefaults(&$defaults, $reverse = false)
 {
     // hack for birth_date
     if (CRM_Utils_Array::value('birth_date', $defaults)) {
         if (is_array($defaults['birth_date'])) {
             $defaults['birth_date'] = CRM_Utils_Date::format($defaults['birth_date'], '-');
         }
     }
     if (CRM_Utils_Array::value('prefix', $defaults)) {
         CRM_Contact_BAO_Contact::lookupValue($defaults, 'prefix', CRM_Core_PseudoConstant::individualPrefix(), $reverse);
     }
     if (CRM_Utils_Array::value('suffix', $defaults)) {
         CRM_Contact_BAO_Contact::lookupValue($defaults, 'suffix', CRM_Core_PseudoConstant::individualSuffix(), $reverse);
     }
     if (CRM_Utils_Array::value('gender', $defaults)) {
         CRM_Contact_BAO_Contact::lookupValue($defaults, 'gender', CRM_Core_PseudoConstant::gender(), $reverse);
     }
     if (array_key_exists('location', $defaults)) {
         $locations =& $defaults['location'];
         foreach ($locations as $index => $location) {
             $location =& $locations[$index];
             CRM_Contact_BAO_Contact::lookupValue($location, 'location_type', CRM_Core_PseudoConstant::locationType(), $reverse);
             // FIXME: lookupValue doesn't work for vcard_name
             $vcardNames =& CRM_Core_PseudoConstant::locationVcardName();
             $location['vcard_name'] = $vcardNames[$location['location_type_id']];
             if (array_key_exists('address', $location)) {
                 if (!CRM_Contact_BAO_Contact::lookupValue($location['address'], 'state_province', CRM_Core_PseudoConstant::stateProvince(), $reverse) && $reverse) {
                     CRM_Contact_BAO_Contact::lookupValue($location['address'], 'state_province', CRM_Core_PseudoConstant::stateProvinceAbbreviation(), $reverse);
                 }
                 if (!CRM_Contact_BAO_Contact::lookupValue($location['address'], 'country', CRM_Core_PseudoConstant::country(), $reverse) && $reverse) {
                     CRM_Contact_BAO_Contact::lookupValue($location['address'], 'country', CRM_Core_PseudoConstant::countryIsoCode(), $reverse);
                 }
                 CRM_Contact_BAO_Contact::lookupValue($location['address'], 'county', CRM_Core_SelectValues::county(), $reverse);
             }
             if (array_key_exists('im', $location)) {
                 $ims =& $location['im'];
                 foreach ($ims as $innerIndex => $im) {
                     $im =& $ims[$innerIndex];
                     CRM_Contact_BAO_Contact::lookupValue($im, 'provider', CRM_Core_PseudoConstant::IMProvider(), $reverse);
                     unset($im);
                 }
             }
             unset($location);
         }
     }
 }