Commit 82f73f7e authored by generalredneck's avatar generalredneck

Fixing the majority of coding standards violations.

parent 321de921
......@@ -2,15 +2,16 @@
/**
* @file
* Constains the views natural sort sorting handler.
*/
/**
*
* Sort handler for sorting records naturally.
*/
class views_natural_sort_handler_sort extends views_handler_sort {
/**
*
* {@inheritdoc}
*/
public function init(&$view, &$options) {
parent::init($view, $options);
......@@ -18,8 +19,7 @@ class views_natural_sort_handler_sort extends views_handler_sort {
}
/**
* Provide a list of options for the default sort form.
* Should be overridden by classes that don't override sort_form.
* {@inheritdoc}
*/
public function sort_options() {
return array(
......@@ -31,7 +31,7 @@ class views_natural_sort_handler_sort extends views_handler_sort {
}
/**
*
* {@inheritdoc}
*/
public function query() {
// If this field isn't being used as a Natural Sort Field, move along
......@@ -56,13 +56,14 @@ class views_natural_sort_handler_sort extends views_handler_sort {
$this->ensure_my_table();
$vns_alias = $this->query->add_relationship('vns_' . $this->table_alias, $this->natural_sort_join(), $this->table, $this->relationship);
}
// Sometimes we get the appended N from the sort options. Filter it out here.
// Sometimes we get the appended N from the sort options. Filter it out
// here.
$order = substr($temporder, 0, 1) == 'N' ? substr($temporder, 1) : $temporder;
$this->query->add_orderby($vns_alias, 'content', $order);
}
/**
*
* Helper function that creates a join to the views natural sort table.
*/
public function natural_sort_join() {
$join = new views_join();
......@@ -89,7 +90,7 @@ class views_natural_sort_handler_sort extends views_handler_sort {
}
/**
*
* {@inheritdoc}
*/
public function admin_summary() {
if (!empty($this->options['exposed'])) {
......@@ -101,20 +102,15 @@ class views_natural_sort_handler_sort extends views_handler_sort {
default:
return t('asc');
break;
case 'DESC':
case 'desc':
return t('desc');
break;
case 'NASC':
return t('natural asc');
break;
case 'NDESC':
return t('natural asc');
break;
}
}
......
......@@ -2,22 +2,24 @@
/**
* @file
* Constains the views natural sort text field sorting handler.
*/
/**
*
* The text field sort handler for views.
*/
class views_natural_sort_handler_sort_text_field extends views_natural_sort_handler_sort {
/**
*
* {@inheritdoc}
*/
public function natural_sort_join() {
$join = new views_join();
$other_join = $this->get_join();
$table_data = views_fetch_data($other_join->definition['left_table']);
// If you look at where natural_sort_join is called, this alias will be used.
// If you look at where natural_sort_join is called, this alias will be
// used.
$vns_alias = 'vns_' . $this->table_alias;
// Make the join. Can't use extra as an array because I have to join on two
......@@ -32,17 +34,6 @@ class views_natural_sort_handler_sort_text_field extends views_natural_sort_hand
'extra' => $vns_alias . '.delta = ' . $this->table_alias . '.delta AND ' .
$vns_alias . ".entity_type = '" . $table_data['table']['entity type'] . "' AND " .
$vns_alias . ".field = '" . preg_replace('/_value$/', '', $this->field) . "'",
/*'extra' => array(
"views_natural_sort.delta = $this->table_alias.delta",
array(
'field' => 'entity_type',
'value' => $table_data['table']['entity type'],
),
array(
'field' => 'field',
'value' => preg_replace('/_value$/', '', $this->field),
),
)*/
);
$join->construct();
$join->adjusted = TRUE;
......
......@@ -2,15 +2,12 @@
/**
* @file
* Install file for the testing module for Views Natural Sort.
*/
/**
* Implements hook_install().
*/
/**
*
*/
function views_natural_sort_test_install() {
node_types_rebuild();
$types = node_type_get_types();
......
......@@ -2,14 +2,11 @@
/**
* @file
* Testing module for Views Natural Sort.
*/
/**
* Implement hook_form()
*/
/**
*
* Implements hook_form().
*/
function views_natural_sort_test_form($node, $form_state) {
return node_content_form($node, $form_state);
......@@ -30,7 +27,7 @@ function views_natural_sort_test_node_info() {
}
/**
* Implementation of hook_views_api().
* Implements hook_views_api().
*/
function views_natural_sort_test_views_api() {
return array(
......@@ -88,7 +85,7 @@ function views_natural_sort_test_views_default_views() {
}
/**
*
* A convieance function that will create content used for testing.
*/
function views_natural_sort_test_views_create_test_content() {
$titles = array(
......
......@@ -30,8 +30,9 @@ function hook_views_natural_sort_get_entry_types() {
}
/**
* Used for a custom module to queue data that needs to be re-indexed when the
* module is installed or settings are changed.
* Used for a custom module to queue data that needs to be re-indexed.
*
* This is typicall used when the module is installed or settings are changed.
*
* @param array $entry_type
* Array representing an entry type with an entity_type field pair.
......@@ -39,7 +40,7 @@ function hook_views_natural_sort_get_entry_types() {
* data that needs to be re-indexed from
* $field - The field that needs to be re-indexed.
*/
function hook_views_natural_sort_queue_rebuild_data($entry_type) {
function hook_views_natural_sort_queue_rebuild_data(array $entry_type) {
if ($entry_type['entity_type'] != 'user' || $entry_type['field'] != 'book_favorites') {
return array();
}
......@@ -64,7 +65,6 @@ function hook_views_natural_sort_queue_rebuild_data($entry_type) {
*
* @param array &$transformations
* An array of transformations already defined.
*
* @param array $index_entry
* A representation of the original entry that is would have been put in the
* database before the transformation
......@@ -75,7 +75,7 @@ function hook_views_natural_sort_queue_rebuild_data($entry_type) {
* $content - The original string before
* transformations.
*/
function hook_views_natural_sort_transformations_alter(&$transformations, $index_entry) {
function hook_views_natural_sort_transformations_alter(array &$transformations, array $index_entry) {
// This function will receive a single argument that is the string that needs
// to be transformed. The transformation helps the database sort the entry
// to be more like a human would expect it to.
......@@ -98,7 +98,8 @@ function hook_views_natural_sort_transformations_alter(&$transformations, $index
* @param string $string
* The string to be transformed.
*
* @return string A transformed string used for sorting "Naturally".
* @return string
* A transformed string used for sorting "Naturally".
*/
function _my_special_transformation_function($string) {
return str_replace('a', '', $string);
......
......@@ -2,10 +2,17 @@
/**
* @file
* The Views Natural Sort module include file.
*/
/**
* Remove all the configured words from the beginning of the string only.
*
* @param string $string
* The string we wish to transform.
*
* @return string
* The transformed string.
*/
function views_natural_sort_remove_beginning_words($string) {
$beginning_words = variable_get('views_natural_sort_beginning_words_remove', array());
......@@ -22,7 +29,13 @@ function views_natural_sort_remove_beginning_words($string) {
}
/**
* Remove all the configured words from the string.
*
* @param string $string
* The string we wish to transform.
*
* @return string
* The transformed string.
*/
function views_natural_sort_remove_words($string) {
$words = variable_get('views_natural_sort_words_remove', array());
......@@ -45,7 +58,13 @@ function views_natural_sort_remove_words($string) {
}
/**
* Remove all the configured symbols from the string.
*
* @param string $string
* The string we wish to transform.
*
* @return string
* The transformed string.
*/
function views_natural_sort_remove_symbols($string) {
$symbols = variable_get('views_natural_sort_symbols_remove', '');
......@@ -72,13 +91,16 @@ function views_natural_sort_remove_symbols($string) {
* - 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.
*
* @param string $string
* The string we wish to transform.
*/
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)
// - 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',
......@@ -87,32 +109,37 @@ function views_natural_sort_numbers($string) {
}
/**
* Encodes a string representing numbers into a special format that can be sorted alphanumerically.
* Transforms a string representing numbers into a special format.
*
* This special format can be sorted as if it was a number but in reality is
* being sorted alphanumerically.
*
* @param array $match
* array of matches passed from preg_replace_callback
* 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)
* $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) {
function _views_natural_sort_number_transform_match_callback(array $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.
// 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.
// 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');
......@@ -125,6 +152,12 @@ function _views_natural_sort_number_transform_match_callback($match) {
* Simply convert days of the week over to numbers.
*
* This "should" be multilingual safe.
*
* @param string $string
* The string we are transforming days to numbers in.
*
* @return string
* The transformed string.
*/
function views_natural_sort_days_of_the_week_sort_days($string) {
......@@ -142,7 +175,7 @@ function views_natural_sort_days_of_the_week_sort_days($string) {
for ($i = 0; $i < 7; $i++) {
$current_day = ($i + $start) % 7;
$abbreviations = views_natural_sort_days_of_the_week_get_acceptable_day_abbreviations($day_list[$current_day], $used_language);
$translated_day = t($day_list[$current_day]);
$translated_day = t('@day', array('@day' => $day_list[$current_day]);
$string = preg_replace(
array(
'/\b' . $translated_day . '\b/i',
......@@ -156,7 +189,7 @@ function views_natural_sort_days_of_the_week_sort_days($string) {
}
/**
*
* The default days of the week.
*/
function views_natural_sort_days_of_the_week_get_default_days() {
return array(
......@@ -171,7 +204,15 @@ function views_natural_sort_days_of_the_week_get_default_days() {
}
/**
* Gets all the configured abbreviations for a certain day of the week.
*
* @param string $day
* The day of the week we want to get abbreviations for.
* @param string $lang
* Determines which configuration to search for as they are keyed by language.
*
* @return array
* The abbreviations for the day of the week and language passed in.
*/
function views_natural_sort_days_of_the_week_get_acceptable_day_abbreviations($day, $lang = 'en') {
$default_days = views_natural_sort_days_of_the_week_get_default_days();
......@@ -184,7 +225,7 @@ function views_natural_sort_days_of_the_week_get_acceptable_day_abbreviations($d
}
/**
*
* Default mappings of days of the week abbreviationas.
*/
function views_natural_sort_days_of_the_week_get_default_day_abbreviations() {
return array(
......
......@@ -2,46 +2,47 @@
/**
* @file
* The Views Natural Sort install file.
*/
/**
* Implementation of hook_schema().
* Implements hook_schema().
*/
function views_natural_sort_schema() {
// Contains relations between two users.
$schema['views_natural_sort'] = array(
'description' => t('Compressed titles for natural sorting.'),
'description' => 'Compressed titles for natural sorting.',
'fields' => array(
'eid' => array(
'description' => t('Entity id'),
'description' => 'Entity id',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'entity_type' => array(
'description' => t('Entity Type'),
'description' => '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.'),
'description' => 'The field name. This will be title or some cck text field, etc.',
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
'default' => '',
),
'delta' => array(
'description' => t('The sequence number for this data item, used for multi-value fields'),
'description' => '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.'),
'description' => 'Filtered content used for sorting.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
......@@ -55,7 +56,7 @@ function views_natural_sort_schema() {
}
/**
* Implementation of hook_install().
* Implements hook_install().
*/
function views_natural_sort_install() {
variable_set(
......@@ -83,7 +84,7 @@ function views_natural_sort_install() {
}
/**
* Implementation of hook_enable().
* Implements hook_enable().
*/
function views_natural_sort_enable() {
module_load_include('inc', 'views_natural_sort', 'views_natural_sort.admin');
......@@ -91,7 +92,7 @@ function views_natural_sort_enable() {
}
/**
* Implementation of hook_uninstall().
* Implements hook_uninstall().
*/
function views_natural_sort_uninstall() {
variable_del('views_natural_sort_beginning_words_remove');
......@@ -102,8 +103,6 @@ function views_natural_sort_uninstall() {
}
/**
* Impliments hook_update_N().
*
* Rebuild the sorting index after changes made for numerical data.
*/
function views_natural_sort_update_7001() {
......@@ -112,8 +111,6 @@ function views_natural_sort_update_7001() {
}
/**
* Impliments hook_update_N().
*
* Upgrade the 7.x-1.x table structure to the 7.x-2.x table structure.
*/
function views_natural_sort_update_7200() {
......
......@@ -2,6 +2,10 @@
/**
* @file
* Views Natural Sort module.
*/
/*
* Provides a views filter that sorts titles by a more natural manner by
* ignoring articles like "The" and "A.".
*
......@@ -21,7 +25,7 @@
*/
/**
* Implementation of hook_menu().
* Implements hook_menu().
*/
function views_natural_sort_menu() {
$items = array();
......@@ -38,7 +42,7 @@ function views_natural_sort_menu() {
}
/**
* Implementation of hook_views_api().
* Implements hook_views_api().
*/
function views_natural_sort_views_api() {
return array(
......@@ -47,7 +51,7 @@ function views_natural_sort_views_api() {
}
/**
*
* Implements hook_implements_alter().
*/
function views_natural_sort_module_implements_alter(&$implements, $hook) {
if ($hook == 'views_data_alter') {
......@@ -76,7 +80,7 @@ function views_natural_sort_views_natural_sort_get_entry_types() {
}
/**
* Implements hook_views_natural_sort_queue_rebuild_data();.
* Implements hook_views_natural_sort_queue_rebuild_data().
*/
function views_natural_sort_views_natural_sort_queue_rebuild_data($entry_type) {
$supported_entity_properties = views_natural_sort_get_views_configurable_properties();
......@@ -127,7 +131,7 @@ function views_natural_sort_entity_insert($entity, $type) {
}
/**
* Implementation of hook_entity_update().
* Implements hook_entity_update().
*
* This keeps our natural sort index up to date.
*/
......@@ -136,7 +140,7 @@ function views_natural_sort_entity_update($entity, $type) {
}
/**
* Implementation of hook_entity_delete().
* Implements hook_entity_delete().
*
* This keep sour natural sort index clean.
*/
......@@ -176,7 +180,8 @@ function views_natural_sort_store_multiple(array $index_entries) {
* be sorted by.
*/
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);
// The size limit on the content field for views_natual_sort is sometimes not
......@@ -215,7 +220,7 @@ function views_natural_sort_store(array $index_entry) {
* If an optional parameter doesn't exist, this is treated as a wild care
* delete.
*/
function views_natural_sort_remove($index_entry) {
function views_natural_sort_remove(array $index_entry) {
$query = db_delete('views_natural_sort')
->condition('eid', $index_entry['eid'])
->condition('entity_type', $index_entry['entity_type']);
......@@ -229,7 +234,10 @@ 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.
*
* Encoding rquires a set of transformations. Those transformations perform
* functionality such as:
* - Leading articles in common languages are ingored: The A An El La Le Il
* - Unimportant punctuation is ignored: # ' " ( )
* - Unimportant words are ignored: and of or.
......@@ -244,7 +252,7 @@ function views_natural_sort_remove($index_entry) {
* @return string
* The transformed string
*/
function views_natural_sort_transform($index_entry) {
function views_natural_sort_transform(array $index_entry) {
// Get copy the original string.
$string = $index_entry['content'];
module_load_include('inc', 'views_natural_sort', 'views_natural_sort');
......@@ -269,7 +277,7 @@ function views_natural_sort_transform($index_entry) {
* @return array
* The final list of transformations.
*/
function views_natural_sort_get_transformations($index_entry) {
function views_natural_sort_get_transformations(array $index_entry) {
$transformations = array(
'views_natural_sort_remove_beginning_words',
'views_natural_sort_remove_words',
......@@ -371,8 +379,9 @@ function views_natural_sort_get_supported_entity_properties() {
* affected by VNS.
*
* @return mixed
* Returns an array formatted as views_natural_sort_get_supported_entity_properties
* or FALSE when views hasn't initianalized yet.
* Returns an array formatted as
* views_natural_sort_get_supported_entity_properties or FALSE when views
* hasn't initianalized yet.
*
* @see views_natural_sort_get_supported_entity_properties
*/
......@@ -402,8 +411,11 @@ function views_natural_sort_get_views_configurable_properties() {
* A helper function for creating a VNS record for storage.
*
* @param object $entity
* An object representing an entity.
* @param string $entity_type
* The machine name for an entity type.
* @param string $field
* The machine name for the field the data belongs to.
*
* @return array
* An array that represents the VNS table row to be inserted.
......@@ -426,7 +438,7 @@ function views_natural_sort_entity_to_vns($entity, $entity_type, $field) {
}
/**
*
* Get the queue used to store natural sort index jobs.
*/
function views_natural_sort_get_queue() {
return DrupalQueue::get('views_natural_sort_index_queue');
......
......@@ -2,16 +2,18 @@
/**
* @file
* Tests for the Views Natural Sort module.
*/
module_load_include('test', 'views', 'tests/views_query');
/**
*
* Basic tests for the Views Natural Sort Module.
*/
class ViewsNaturalSortBasicTest extends ViewsTestCase {
/**
*
* {@inheritdoc}
*/
public static function getInfo() {
return array(
......@@ -22,14 +24,14 @@ class ViewsNaturalSortBasicTest extends ViewsTestCase {
}
/**
*
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp('views', 'views_natural_sort', 'views_natural_sort_test');
}
/**
*
* Test the default settings for stripping out the words A, An, and The.
*/
public function testNaturalSortDefaultBeginningWords() {
$titles = array(
......@@ -58,7 +60,7 @@ class ViewsNaturalSortBasicTest extends ViewsTestCase {
}
/**
*
* Test the default settings for symbol removal in sorting.
*/
public function testNaturalSortDefaultSymbols() {
$titles = array(
......@@ -86,7 +88,7 @@ class ViewsNaturalSortBasicTest extends ViewsTestCase {
}
/**
*
* Test sorting strings that contain numbers in them.
*/
public function testNaturalSortNumbers() {
$titles = array(
......@@ -129,12 +131,12 @@ class ViewsNaturalSortBasicTest extends ViewsTestCase {
}
/**
*
* Tests all the "Days of the week" natural sort functionality.
*/
class ViewsNaturalSortDaysOfTheWeekTest extends DrupalWebTestCase {
/**
*
* {@inheritdoc}
*/
public static function getInfo() {
return array(
......@@ -145,7 +147,7 @@ class ViewsNaturalSortDaysOfTheWeekTest extends DrupalWebTestCase {
}
/**
*
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp('views', 'views_natural_sort');
......@@ -153,7 +155,7 @@ class ViewsNaturalSortDaysOfTheWeekTest extends DrupalWebTestCase {
}
/**
*
* Test tranformation functionality of the days of the week transformation.
*/
public function testDefaultDayReplace() {
foreach (views_natural_sort_days_of_the_week_get_default_days() as $replaced => $day) {
......@@ -162,7 +164,7 @@ class ViewsNaturalSortDaysOfTheWeekTest extends DrupalWebTestCase {
}
/**
*
* Test changing the first day of the week.
*/
public function testFirstDayMonday() {
variable_set("views_natural_sort_days_of_the_week_first_day_en", "Monday");
......@@ -181,7 +183,7 @@ class ViewsNaturalSortDaysOfTheWeekTest extends DrupalWebTestCase {
}
/**
*
* Test sorting day abbreviations.
*/
public function testAbbreviations() {
$expected = array(
......
......@@ -2,14 +2,11 @@
/**
* @file
* Views related hooks.
*
* Automatically included by views. Because of the nature of this module this
* is most of the code.
* Views related hooks for the Views Natural Sort module.
*/
/**
*
* Implements hook_views_data_alter().
*/
function views_natural_sort_views_data_alter(&$views_data) {
$supported_entity_properties = views_natural_sort_get_supported_entity_properties();
......
......@@ -2,10 +2,11 @@
/**
* @file
* The install file for the Views Natural Sort Text Field module.
*/
/**
*
* Implements hook_enable().
*/
function views_natural_sort_text_field_enable() {
module_load_include('inc', 'views_natural_sort', 'views_natural_sort.admin');
......