function get_select_from_sort($sort_sql) { $sort_clauses = preg_split('/\\s?,\\s?/', $sort_sql); if (count($sort_clauses) === 1) { return str_replace(AMP_SORT_DESC, '', $sort_sql); } $previous_sort_segment = false; $delimiter = "''"; foreach ($sort_clauses as $sort_segment) { if ($previous_sort_segment) { $delimiter = 'if ( isnull( ' . $previous_sort_segment . '), \'\', \', \')'; } $index_segment = str_replace(AMP_SORT_DESC, '', $sort_segment); $local_method = 'make_readable_select_for_' . AMP_from_camelcase($index_segment); if (method_exists($this, $local_method)) { $index_segment = $this->{$local_method}(); } $index_sort[] = '( if( isnull( ' . $index_segment . '), \'\', Concat( ' . $delimiter . ',' . $index_segment . ')))'; //after first time through loop all segments need leading punctuation $previous_sort_segment = $index_segment; } return "Concat( " . join(',', $index_sort) . " ) as index_field"; }
function AMP_underscore($value) { $start = AMP_from_camelcase($value); return strtolower(preg_replace('/_+/', '_', preg_replace('/[^A-z0-9]/', '_', $value))); }
function cache_key($type, $instance_var = null) { $lookup_cache_key = AMP_CACHE_TOKEN_LOOKUP . AMP_from_camelcase($type); if (defined('AMP_SYSTEM_USER_ID')) { $lookup_cache_key = AMP_System_Cache::identify($lookup_cache_key, AMP_SYSTEM_USER_ID); } if (!isset($instance_var)) { return $lookup_cache_key; } //instanced lookup return AMP_System_Cache::identify($lookup_cache_key . 'K', $instance_var); }