Skip to content
Snippets Groups Projects
Utils.php 1.52 KiB
Newer Older
  • Learn to ignore specific revisions
  • mattwire's avatar
    mattwire committed
    <?php
    
    mattwire's avatar
    mattwire committed
    /*
     +--------------------------------------------------------------------+
     | Copyright CiviCRM LLC. All rights reserved.                        |
     |                                                                    |
     | This work is published under the GNU AGPLv3 license with some      |
     | permitted exceptions and without any warranty. For full license    |
     | and copyright information, see https://civicrm.org/licensing       |
     +--------------------------------------------------------------------+
    
    mattwire's avatar
    mattwire committed
     */
    
    /**
     * Class CRM_Mjwshared_Utils
     */
    class CRM_Mjwshared_Utils {
    
      /**
       * Return the field ID for $fieldName custom field
       *
    
    mattwire's avatar
    mattwire committed
       * @param string $fieldName
       * @param string $fieldGroup
       * @param bool $fullString If TRUE return "custom_25", If FALSE return "25"
    
    mattwire's avatar
    mattwire committed
       *
    
    mattwire's avatar
    mattwire committed
       * @return int|string
    
       * @throws \CRM_Core_Exception
    
    mattwire's avatar
    mattwire committed
       */
      public static function getCustomByName($fieldName, $fieldGroup, $fullString = TRUE) {
        if (!isset(Civi::$statics[__CLASS__][$fieldGroup][$fieldName])) {
          $field = civicrm_api3('CustomField', 'get', array(
            'custom_group_id' => $fieldGroup,
            'name' => $fieldName,
          ));
    
          if (!empty($field['id'])) {
            Civi::$statics[__CLASS__][$fieldGroup][$fieldName]['id'] = $field['id'];
            Civi::$statics[__CLASS__][$fieldGroup][$fieldName]['string'] = 'custom_' . $field['id'];
          }
        }
    
        if ($fullString) {
          return Civi::$statics[__CLASS__][$fieldGroup][$fieldName]['string'];
        }
        return Civi::$statics[__CLASS__][$fieldGroup][$fieldName]['id'];
      }
    
    }