Commit 51879a6c authored by malcomio's avatar malcomio Committed by generalredneck

Issue #2832865 by malcomio: Tidy up code

parent bcbf2ae0
...@@ -65,7 +65,7 @@ function views_natural_sort_remove_symbols($string) { ...@@ -65,7 +65,7 @@ function views_natural_sort_remove_symbols($string) {
* Transform numbers in a string into a natural sortable string. * Transform numbers in a string into a natural sortable string.
* *
* Rules are as follows: * Rules are as follows:
* - Embeded numbers will sort in numerical order. The following possibilities * - Embedded numbers will sort in numerical order. The following possibilities
* are supported * are supported
* - A leading dash indicates a negative number, unless it is preceded by a * - A leading dash indicates a negative number, unless it is preceded by a
* non-whitespace character, which case it is considered just a dash. * non-whitespace character, which case it is considered just a dash.
...@@ -107,7 +107,7 @@ function _views_natural_sort_number_transform_match_callback($match) { ...@@ -107,7 +107,7 @@ function _views_natural_sort_number_transform_match_callback($match) {
// Remove commas and leading zeros from whole number // Remove commas and leading zeros from whole number
$whole = (string)(int)str_replace(',', '', (isset($match[4]) && strlen($match[4]) > 0) ? $match[4] : $match[2]); $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 // Remove trailing 0's from fraction, then add the decimal and one trailing 0
$fraction = trim('.' . $match[3], '0') . '0'; $fraction = trim('.' . $match[3], '0') . '0';
$encode = sprintf('%02u', strlen($whole)) . $whole . $fraction; $encode = sprintf('%02u', strlen($whole)) . $whole . $fraction;
if (strlen($match[1])) { if (strlen($match[1])) {
......
; $Id$
name = Views Natural Sort
description = Sort results naturaly on a text field skipping articles like "the" and "a."
dependencies[] = views
package = Views
core = 6.x
...@@ -15,15 +15,17 @@ function views_natural_sort_help($route_name, RouteMatchInterface $route_match) ...@@ -15,15 +15,17 @@ function views_natural_sort_help($route_name, RouteMatchInterface $route_match)
switch ($route_name) { switch ($route_name) {
// Main module help for the views_natural_sort module. // Main module help for the views_natural_sort module.
case 'help.page.views_natural_sort': case 'help.page.views_natural_sort':
$output = ''; $output = '<h3>' . t('About') . '</h3>';
$output .= '<h3>' . t('About') . '</h3>'; $output .= '<p>' . t('Sort results naturally on a node&#039;s title skipping articles like &quot;the&quot; and &quot;a.&quot;') . '</p>';
$output .= '<p>' . t('Sort results naturaly on a node&#039;s title skipping articles like &quot;the&quot; and &quot;a.&quot;') . '</p>';
return $output; return $output;
default: default:
} }
} }
/**
* Implements hook_module_implements_alter().
*/
function views_natural_sort_module_implements_alter(&$implements, $hook) { function views_natural_sort_module_implements_alter(&$implements, $hook) {
if ($hook == 'views_data_alter') { if ($hook == 'views_data_alter') {
// Make views natural sort always last so we get all the up to date info. // Make views natural sort always last so we get all the up to date info.
...@@ -114,7 +116,7 @@ function views_natural_sort_entity_update(EntityInterface $entity) { ...@@ -114,7 +116,7 @@ function views_natural_sort_entity_update(EntityInterface $entity) {
/** /**
* Implementation of hook_entity_delete(). * Implementation of hook_entity_delete().
* *
* This keep sour natural sort index clean. * This keeps our natural sort index clean.
*/ */
function views_natural_sort_entity_delete(EntityInterface $entity) { function views_natural_sort_entity_delete(EntityInterface $entity) {
views_natural_sort_remove($entry = array( views_natural_sort_remove($entry = array(
...@@ -151,13 +153,12 @@ function views_natural_sort_store_multiple(array $index_entries) { ...@@ -151,13 +153,12 @@ function views_natural_sort_store_multiple(array $index_entries) {
* be sorted by. * be sorted by.
* @Not-Rewritten * @Not-Rewritten
*/ */
function views_natural_sort_store(array $index_entry) { function views_natural_sort_store(array $index_entry) {
// This should take a formatted object and store it into the views_natural_sort table. // This should take a formatted object and store it into the views_natural_sort table.
$string = views_natural_sort_transform($index_entry); $string = views_natural_sort_transform($index_entry);
// The size limit on the content field for views_natual_sort is sometimes not // The size limit on the content field for views_natural_sort is sometimes not
// enough. Lets truncate all data down to that size. I personally feel the // enough. Let's truncate all data down to that size. I personally feel the
// inaccuracy is an acceptable loss, as the bigger the string gets, the less // inaccuracy is an acceptable loss, as the bigger the string gets, the less
// permanent the sort. // permanent the sort.
// //
...@@ -189,7 +190,7 @@ function views_natural_sort_store(array $index_entry) { ...@@ -189,7 +190,7 @@ function views_natural_sort_store(array $index_entry) {
* $entity_type - The Entity Type. Ex. node * $entity_type - The Entity Type. Ex. node
* $field - (optional) reference to the property or field name * $field - (optional) reference to the property or field name
* $delta - (optional)the item number in that field or property * $delta - (optional)the item number in that field or property
* If an optional parameter doesn't exist, this is treated as a wild care * If an optional parameter doesn't exist, this is treated as a wild card
* delete * delete
* @Not-Rewritten * @Not-Rewritten
*/ */
...@@ -208,7 +209,7 @@ function views_natural_sort_remove($index_entry) { ...@@ -208,7 +209,7 @@ function views_natural_sort_remove($index_entry) {
/** /**
* Encodes a string into an ascii-sortable string such as: * Encodes a string into an ascii-sortable string such as:
* - Leading articles in common languages are ingored: The A An El La Le Il * - Leading articles in common languages are ignored: The A An El La Le Il
* - Unimportant punctuation is ignored: # ' " ( ) * - Unimportant punctuation is ignored: # ' " ( )
* - Unimportant words are ignored: and of or * - Unimportant words are ignored: and of or
* *
......
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