Commit 2d73714a authored by generalredneck's avatar generalredneck

Start of translation of d7 code to get something "Working" Erroring still.

PHPUnit_Framework_Error_Notice: Array to string conversion
C:\Users\Allan\workspace\drupal-core\drupal\modules\custom\views_natural_sort\views_natural_sort.inc:25
C:\Users\Allan\workspace\drupal-core\drupal\modules\custom\views_natural_sort\views_natural_sort.module:231
C:\Users\Allan\workspace\drupal-core\drupal\modules\custom\views_natural_sort\views_natural_sort.module:157
C:\Users\Allan\workspace\drupal-core\drupal\modules\custom\views_natural_sort\views_natural_sort.module:100
parent d099975b
<?php
/**
* @STUBBED
*/
function views_natural_sort_remove_beginning_words($string) {
$beginning_words = [
t('The'),
t('A'),
t('An'),
t('La'),
t('Le'),
t('Il')
];
if (empty($beginning_words)) {
return $string;
}
array_walk($beginning_words, 'preg_quote');
return preg_replace(
'/^(' . implode('|', $beginning_words) . ')\s+/i',
'',
$string
);
}
function views_natural_sort_remove_words($string) {
$words = [
t('and'),
t('or'),
t('of'),
];
if (empty($words)) {
return $string;
}
array_walk($words, 'preg_quote');
return preg_replace(
array(
'/\s(' . implode('|', $words) . ')\s+/i',
'/^(' . implode('|', $words) . ')\s+/i',
),
array(
' ',
''
),
$string
);
}
function views_natural_sort_remove_symbols($string) {
$symbols = "#\"'\\()[]";
if (strlen($symbols) == 0) {
return $string;
}
return preg_replace(
'/[' . preg_quote($symbols) . ']/',
'',
$string
);
}
/**
* Transform numbers in a string into a natural sortable string.
*
* Rules are as follows:
* - Embeded numbers will sort in numerical order. The following possibilities
* are supported
* - A leading dash indicates a negative number, unless it is preceded by a
* non-whitespace character, which case it is considered just a dash.
* - Leading zeros are properly ignored so as to not influence sort order
* - Decimal numbers are supported using a period as the decimal character
* - Thousands separates are ignored, using the comma as the thous. character
* - Numbers may be up to 99 digits before the decimal, up to the precision
* of the processor.
*/
function views_natural_sort_numbers($string) {
// Find an optional leading dash (either preceded by whitespace or the first
// character) followed by either:
// - an optional series of digits (with optional embedded commas), then a
// period, then an optional series of digits
// - a series of digits (with optional embedded commas)
return preg_replace_callback(
'/(\s-|^-)?(?:(\d[\d,]*)?\.(\d+)|(\d[\d,]*))/',
'_views_natural_sort_number_transform_match_callback',
$string
);
}
/**
* Encodes a string representing numbers into a special format that can be sorted alphanumerically.
*
* @param array $match
* array of matches passed from preg_replace_callback
* $match[0] is the entire matching string
* $match[1] if present, is the optional dash, preceded by optional whitespace
* $match[2] if present, is whole number portion of the decimal number
* $match[3] if present, is the fractional portion of the decimal number
* $match[4] if present, is the integer (when no fraction is matched)
*
* @return string
* String representing a numerical value that will sort numerically in an
* alphanumeric search.
*/
function _views_natural_sort_number_transform_match_callback($match) {
// Remove commas and leading zeros from whole number
$whole = (string)(int)str_replace(',', '', (isset($match[4]) && strlen($match[4]) > 0) ? $match[4] : $match[2]);
// Remove traililng 0's from fraction, then add the decimal and one trailing 0
$fraction = trim('.' . $match[3], '0') . '0';
$encode = sprintf('%02u', strlen($whole)) . $whole . $fraction;
if (strlen($match[1])) {
// Negative number. Make 10's complement. Put back any leading white space and the dash
// Requires intermediate to avoid double-replacing the same digit. str_replace seems to
// work by copying the source to the result, then successively replacing within it,
// rather than replacing from the source to the result.
$digits = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9');
$intermediate = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j');
$rev_digits = array('9', '8', '7', '6', '5', '4', '3', '2', '1', '0');
$encode = $match[1] . str_replace($intermediate, $rev_digits, str_replace($digits, $intermediate, $encode));
}
return $encode;
}
......@@ -11,16 +11,22 @@
*/
function views_natural_sort_schema() {
// Contains relations between two users.
$schema['views_natural_sort'] = array(
'description' => t('Compressed titles for natural sorting.'),
'fields' => array(
'nid' => array(
'description' => t('Node id'),
'eid' => array(
'description' => t('Entity id'),
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'entity_type' => array(
'description' => t('Entity Type'),
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => 'node',
),
'field' => array(
'description' => t('The field name. This will be title or some cck text field, etc.'),
'type' => 'varchar',
......@@ -28,6 +34,13 @@ function views_natural_sort_schema() {
'not null' => TRUE,
'default' => '',
),
'delta' => array(
'description' => t('The sequence number for this data item, used for multi-value fields'),
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'content' => array(
'description' => t('Filtered content used for sorting.'),
'type' => 'varchar',
......@@ -36,8 +49,7 @@ function views_natural_sort_schema() {
'default' => '',
),
),
'key' => array('nid', 'field', 'content'),
'primary key' => array('nid', 'field'),
'primary key' => array('eid', 'entity_type', 'field', 'delta'),
);
return $schema;
......@@ -47,12 +59,10 @@ function views_natural_sort_schema() {
* Implementation of hook_install().
*/
function views_natural_sort_install() {
drupal_install_schema('views_natural_sort');
}
/**
* Implementation of hook_uninstall().
*/
function views_natural_sort_uninstall() {
drupal_uninstall_schema('views_natural_sort');
}
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment