/** * Get next available value. * We will take the highest numeric value (or 0 if no numeric values exist) * and add one. The calling function is responsible for any * more complex decision making * @param array $params */ public static function getDefaultValue($params) { $bao = new CRM_Core_BAO_OptionValue(); $bao->option_group_id = $params['option_group_id']; if (isset($params['domain_id'])) { $bao->domain_id = $params['domain_id']; } $bao->selectAdd(); $bao->whereAdd("value REGEXP '^[0-9]+\$'"); $bao->selectAdd('(ROUND(COALESCE(MAX(CONVERT(value, UNSIGNED)),0)) +1) as nextvalue'); $bao->find(TRUE); return $bao->nextvalue; }