Commit 82f73f7e authored by generalredneck's avatar generalredneck

Fixing the majority of coding standards violations.

parent 321de921
...@@ -2,15 +2,16 @@ ...@@ -2,15 +2,16 @@
/** /**
* @file * @file
* Constains the views natural sort sorting handler.
*/ */
/** /**
* * Sort handler for sorting records naturally.
*/ */
class views_natural_sort_handler_sort extends views_handler_sort { class views_natural_sort_handler_sort extends views_handler_sort {
/** /**
* * {@inheritdoc}
*/ */
public function init(&$view, &$options) { public function init(&$view, &$options) {
parent::init($view, $options); parent::init($view, $options);
...@@ -18,8 +19,7 @@ class views_natural_sort_handler_sort extends views_handler_sort { ...@@ -18,8 +19,7 @@ class views_natural_sort_handler_sort extends views_handler_sort {
} }
/** /**
* Provide a list of options for the default sort form. * {@inheritdoc}
* Should be overridden by classes that don't override sort_form.
*/ */
public function sort_options() { public function sort_options() {
return array( return array(
...@@ -31,7 +31,7 @@ class views_natural_sort_handler_sort extends views_handler_sort { ...@@ -31,7 +31,7 @@ class views_natural_sort_handler_sort extends views_handler_sort {
} }
/** /**
* * {@inheritdoc}
*/ */
public function query() { public function query() {
// If this field isn't being used as a Natural Sort Field, move along // 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 { ...@@ -56,13 +56,14 @@ class views_natural_sort_handler_sort extends views_handler_sort {
$this->ensure_my_table(); $this->ensure_my_table();
$vns_alias = $this->query->add_relationship('vns_' . $this->table_alias, $this->natural_sort_join(), $this->table, $this->relationship); $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; $order = substr($temporder, 0, 1) == 'N' ? substr($temporder, 1) : $temporder;
$this->query->add_orderby($vns_alias, 'content', $order); $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() { public function natural_sort_join() {
$join = new views_join(); $join = new views_join();
...@@ -89,7 +90,7 @@ class views_natural_sort_handler_sort extends views_handler_sort { ...@@ -89,7 +90,7 @@ class views_natural_sort_handler_sort extends views_handler_sort {
} }
/** /**
* * {@inheritdoc}
*/ */
public function admin_summary() { public function admin_summary() {
if (!empty($this->options['exposed'])) { if (!empty($this->options['exposed'])) {
...@@ -101,20 +102,15 @@ class views_natural_sort_handler_sort extends views_handler_sort { ...@@ -101,20 +102,15 @@ class views_natural_sort_handler_sort extends views_handler_sort {
default: default:
return t('asc'); return t('asc');
break;
case 'DESC': case 'DESC':
case 'desc': case 'desc':
return t('desc'); return t('desc');
break;
case 'NASC': case 'NASC':
return t('natural asc'); return t('natural asc');
break;
case 'NDESC': case 'NDESC':
return t('natural asc'); return t('natural asc');
break;
} }
} }
......
...@@ -2,22 +2,24 @@ ...@@ -2,22 +2,24 @@
/** /**
* @file * @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 { class views_natural_sort_handler_sort_text_field extends views_natural_sort_handler_sort {
/** /**
* * {@inheritdoc}
*/ */
public function natural_sort_join() { public function natural_sort_join() {
$join = new views_join(); $join = new views_join();
$other_join = $this->get_join(); $other_join = $this->get_join();
$table_data = views_fetch_data($other_join->definition['left_table']); $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; $vns_alias = 'vns_' . $this->table_alias;
// Make the join. Can't use extra as an array because I have to join on two // 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 ...@@ -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 ' . 'extra' => $vns_alias . '.delta = ' . $this->table_alias . '.delta AND ' .
$vns_alias . ".entity_type = '" . $table_data['table']['entity type'] . "' AND " . $vns_alias . ".entity_type = '" . $table_data['table']['entity type'] . "' AND " .
$vns_alias . ".field = '" . preg_replace('/_value$/', '', $this->field) . "'", $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->construct();
$join->adjusted = TRUE; $join->adjusted = TRUE;
......
...@@ -2,15 +2,12 @@ ...@@ -2,15 +2,12 @@
/** /**
* @file * @file
* Install file for the testing module for Views Natural Sort.
*/ */
/** /**
* Implements hook_install(). * Implements hook_install().
*/ */
/**
*
*/
function views_natural_sort_test_install() { function views_natural_sort_test_install() {
node_types_rebuild(); node_types_rebuild();
$types = node_type_get_types(); $types = node_type_get_types();
......
...@@ -2,14 +2,11 @@ ...@@ -2,14 +2,11 @@
/** /**
* @file * @file
* Testing module for Views Natural Sort.
*/ */
/** /**
* Implement hook_form() * Implements hook_form().
*/
/**
*
*/ */
function views_natural_sort_test_form($node, $form_state) { function views_natural_sort_test_form($node, $form_state) {
return node_content_form($node, $form_state); return node_content_form($node, $form_state);
...@@ -30,7 +27,7 @@ function views_natural_sort_test_node_info() { ...@@ -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() { function views_natural_sort_test_views_api() {
return array( return array(
...@@ -88,7 +85,7 @@ function views_natural_sort_test_views_default_views() { ...@@ -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() { function views_natural_sort_test_views_create_test_content() {
$titles = array( $titles = array(
......
...@@ -30,8 +30,9 @@ function hook_views_natural_sort_get_entry_types() { ...@@ -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 * Used for a custom module to queue data that needs to be re-indexed.
* module is installed or settings are changed. *
* This is typicall used when the module is installed or settings are changed.
* *
* @param array $entry_type * @param array $entry_type
* Array representing an entry type with an entity_type field pair. * Array representing an entry type with an entity_type field pair.
...@@ -39,7 +40,7 @@ function hook_views_natural_sort_get_entry_types() { ...@@ -39,7 +40,7 @@ function hook_views_natural_sort_get_entry_types() {
* data that needs to be re-indexed from * data that needs to be re-indexed from
* $field - The field that needs to be re-indexed. * $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') { if ($entry_type['entity_type'] != 'user' || $entry_type['field'] != 'book_favorites') {
return array(); return array();
} }
...@@ -64,7 +65,6 @@ function hook_views_natural_sort_queue_rebuild_data($entry_type) { ...@@ -64,7 +65,6 @@ function hook_views_natural_sort_queue_rebuild_data($entry_type) {
* *
* @param array &$transformations * @param array &$transformations
* An array of transformations already defined. * An array of transformations already defined.
*
* @param array $index_entry * @param array $index_entry
* A representation of the original entry that is would have been put in the * A representation of the original entry that is would have been put in the
* database before the transformation * database before the transformation
...@@ -75,7 +75,7 @@ function hook_views_natural_sort_queue_rebuild_data($entry_type) { ...@@ -75,7 +75,7 @@ function hook_views_natural_sort_queue_rebuild_data($entry_type) {
* $content - The original string before * $content - The original string before
* transformations. * 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 // 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 transformed. The transformation helps the database sort the entry
// to be more like a human would expect it to. // to be more like a human would expect it to.
...@@ -98,7 +98,8 @@ function hook_views_natural_sort_transformations_alter(&$transformations, $index ...@@ -98,7 +98,8 @@ function hook_views_natural_sort_transformations_alter(&$transformations, $index
* @param string $string * @param string $string
* The string to be transformed. * 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) { function _my_special_transformation_function($string) {
return str_replace('a', '', $string); return str_replace('a', '', $string);
......
...@@ -2,10 +2,17 @@ ...@@ -2,10 +2,17 @@
/** /**
* @file * @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) { function views_natural_sort_remove_beginning_words($string) {
$beginning_words = variable_get('views_natural_sort_beginning_words_remove', array()); $beginning_words = variable_get('views_natural_sort_beginning_words_remove', array());
...@@ -22,7 +29,13 @@ function views_natural_sort_remove_beginning_words($string) { ...@@ -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) { function views_natural_sort_remove_words($string) {
$words = variable_get('views_natural_sort_words_remove', array()); $words = variable_get('views_natural_sort_words_remove', array());
...@@ -45,7 +58,13 @@ function views_natural_sort_remove_words($string) { ...@@ -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) { function views_natural_sort_remove_symbols($string) {
$symbols = variable_get('views_natural_sort_symbols_remove', ''); $symbols = variable_get('views_natural_sort_symbols_remove', '');
...@@ -72,13 +91,16 @@ function views_natural_sort_remove_symbols($string) { ...@@ -72,13 +91,16 @@ function views_natural_sort_remove_symbols($string) {
* - Thousands separates are ignored, using the comma as the thous. 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 * - Numbers may be up to 99 digits before the decimal, up to the precision
* of the processor. * of the processor.
*
* @param string $string
* The string we wish to transform.
*/ */
function views_natural_sort_numbers($string) { function views_natural_sort_numbers($string) {
// Find an optional leading dash (either preceded by whitespace or the first // Find an optional leading dash (either preceded by whitespace or the first
// character) followed by either: // character) followed by either:
// - an optional series of digits (with optional embedded commas), then a // - an optional series of digits (with optional embedded commas), then a
// period, then an optional series of digits // period, then an optional series of digits
// - a series of digits (with optional embedded commas) // - a series of digits (with optional embedded commas)
return preg_replace_callback( return preg_replace_callback(
'/(\s-|^-)?(?:(\d[\d,]*)?\.(\d+)|(\d[\d,]*))/', '/(\s-|^-)?(?:(\d[\d,]*)?\.(\d+)|(\d[\d,]*))/',
'_views_natural_sort_number_transform_match_callback', '_views_natural_sort_number_transform_match_callback',
...@@ -87,32 +109,37 @@ function views_natural_sort_numbers($string) { ...@@ -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 * @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[0] is the entire matching string
* $match[1] if present, is the optional dash, preceded by optional whitespace * $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[2] if present, is whole number portion of the decimal number
* $match[3] if present, is the fractional 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 * @return string
* String representing a numerical value that will sort numerically in an * String representing a numerical value that will sort numerically in an
* alphanumeric search. * 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. // 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 traililng 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])) {
// Negative number. Make 10's complement. Put back any leading white space and the dash // Negative number. Make 10's complement. Put back any leading white space
// Requires intermediate to avoid double-replacing the same digit. str_replace seems to // and the dash requires intermediate to avoid double-replacing the same
// work by copying the source to the result, then successively replacing within it, // digit. str_replace() seems to work by copying the source to the result,
// rather than replacing from 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'); $digits = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9');
$intermediate = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'); $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'); $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) { ...@@ -125,6 +152,12 @@ function _views_natural_sort_number_transform_match_callback($match) {
* Simply convert days of the week over to numbers. * Simply convert days of the week over to numbers.
* *
* This "should" be multilingual safe. * 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) { 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) { ...@@ -142,7 +175,7 @@ function views_natural_sort_days_of_the_week_sort_days($string) {
for ($i = 0; $i < 7; $i++) { for ($i = 0; $i < 7; $i++) {
$current_day = ($i + $start) % 7; $current_day = ($i + $start) % 7;
$abbreviations = views_natural_sort_days_of_the_week_get_acceptable_day_abbreviations($day_list[$current_day], $used_language); $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( $string = preg_replace(
array( array(
'/\b' . $translated_day . '\b/i', '/\b' . $translated_day . '\b/i',
...@@ -156,7 +189,7 @@ function views_natural_sort_days_of_the_week_sort_days($string) { ...@@ -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() { function views_natural_sort_days_of_the_week_get_default_days() {
return array( return array(
...@@ -171,7 +204,15 @@ function views_natural_sort_days_of_the_week_get_default_days() { ...@@ -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') { 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(); $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 ...@@ -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() { function views_natural_sort_days_of_the_week_get_default_day_abbreviations() {
return array( return array(
......
...@@ -2,46 +2,47 @@ ...@@ -2,46 +2,47 @@
/** /**
* @file * @file
* The Views Natural Sort install file.
*/ */
/** /**
* Implementation of hook_schema(). * Implements hook_schema().
*/ */
function views_natural_sort_schema() { function views_natural_sort_schema() {
// Contains relations between two users. // Contains relations between two users.
$schema['views_natural_sort'] = array( $schema['views_natural_sort'] = array(
'description' => t('Compressed titles for natural sorting.'), 'description' => 'Compressed titles for natural sorting.',
'fields' => array( 'fields' => array(
'eid' => array( 'eid' => array(
'description' => t('Entity id'), 'description' => 'Entity id',
'type' => 'int', 'type' => 'int',
'unsigned' => TRUE, 'unsigned' => TRUE,
'not null' => TRUE, 'not null' => TRUE,
), ),
'entity_type' => array( 'entity_type' => array(
'description' => t('Entity Type'), 'description' => 'Entity Type',
'type' => 'varchar', 'type' => 'varchar',
'length' => 128, 'length' => 128,
'not null' => TRUE, 'not null' => TRUE,
'default' => 'node', 'default' => 'node',
), ),
'field' => array( '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', 'type' => 'varchar',
'length' => 32, 'length' => 32,
'not null' => TRUE, 'not null' => TRUE,
'default' => '', 'default' => '',
), ),
'delta' => array( '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', 'type' => 'int',
'unsigned' => TRUE, 'unsigned' => TRUE,
'not null' => TRUE, 'not null' => TRUE,
'default' => 0, 'default' => 0,