diff --git a/includes/handlers.inc b/includes/handlers.inc deleted file mode 100644 index 85c5c748308e8573f21f728cac228d7b3fbdbf26..0000000000000000000000000000000000000000 --- a/includes/handlers.inc +++ /dev/null @@ -1,407 +0,0 @@ -<?php - -/** - * @file - * Defines the various handler objects to help build and display views. - */ - -use Drupal\Core\Database\Database; - -/** - * Fetch a handler to join one table to a primary table from the data cache - */ -function views_get_table_join($table, $base_table) { - $data = views_fetch_data($table); - if (isset($data['table']['join'][$base_table])) { - $h = $data['table']['join'][$base_table]; - if (!empty($h['join_id']) && class_exists($h['handler'])) { - $id = $h['join_id']; - } - else { - $id = 'standard'; - } - $handler = views_get_plugin('join', $id); - - // Fill in some easy defaults - $handler->definition = $h; - if (empty($handler->definition['table'])) { - $handler->definition['table'] = $table; - } - // If this is empty, it's a direct link. - if (empty($handler->definition['left_table'])) { - $handler->definition['left_table'] = $base_table; - } - - if (isset($h['arguments'])) { - call_user_func_array(array(&$handler, 'construct'), $h['arguments']); - } - else { - $handler->construct(); - } - - return $handler; - } -} - -/** - * Break x,y,z and x+y+z into an array. Works for strings. - * - * @param $str - * The string to parse. - * @param $object - * The object to use as a base. If not specified one will - * be created. - * - * @return $object - * An object containing - * - operator: Either 'and' or 'or' - * - value: An array of numeric values. - */ -function views_break_phrase_string($str, &$handler = NULL) { - if (!$handler) { - $handler = new stdClass(); - } - - // Set up defaults: - if (!isset($handler->value)) { - $handler->value = array(); - } - - if (!isset($handler->operator)) { - $handler->operator = 'or'; - } - - if ($str == '') { - return $handler; - } - - // Determine if the string has 'or' operators (plus signs) or 'and' operators - // (commas) and split the string accordingly. If we have an 'and' operator, - // spaces are treated as part of the word being split, but otherwise they are - // treated the same as a plus sign. - $or_wildcard = '[^\s+,]'; - $and_wildcard = '[^+,]'; - if (preg_match("/^({$or_wildcard}+[+ ])+{$or_wildcard}+$/", $str)) { - $handler->operator = 'or'; - $handler->value = preg_split('/[+ ]/', $str); - } - elseif (preg_match("/^({$and_wildcard}+,)*{$and_wildcard}+$/", $str)) { - $handler->operator = 'and'; - $handler->value = explode(',', $str); - } - - // Keep an 'error' value if invalid strings were given. - if (!empty($str) && (empty($handler->value) || !is_array($handler->value))) { - $handler->value = array(-1); - return $handler; - } - - // Doubly ensure that all values are strings only. - foreach ($handler->value as $id => $value) { - $handler->value[$id] = (string) $value; - } - - return $handler; -} - -/** - * Break x,y,z and x+y+z into an array. Numeric only. - * - * @param $str - * The string to parse. - * @param $handler - * The handler object to use as a base. If not specified one will - * be created. - * - * @return $handler - * The new handler object. - */ -function views_break_phrase($str, &$handler = NULL) { - if (!$handler) { - $handler = new stdClass(); - } - - // Set up defaults: - - if (!isset($handler->value)) { - $handler->value = array(); - } - - if (!isset($handler->operator)) { - $handler->operator = 'or'; - } - - if (empty($str)) { - return $handler; - } - - if (preg_match('/^([0-9]+[+ ])+[0-9]+$/', $str)) { - // The '+' character in a query string may be parsed as ' '. - $handler->operator = 'or'; - $handler->value = preg_split('/[+ ]/', $str); - } - elseif (preg_match('/^([0-9]+,)*[0-9]+$/', $str)) { - $handler->operator = 'and'; - $handler->value = explode(',', $str); - } - - // Keep an 'error' value if invalid strings were given. - if (!empty($str) && (empty($handler->value) || !is_array($handler->value))) { - $handler->value = array(-1); - return $handler; - } - - // Doubly ensure that all values are numeric only. - foreach ($handler->value as $id => $value) { - $handler->value[$id] = intval($value); - } - - return $handler; -} - -// -------------------------------------------------------------------------- -// Date helper functions - -/** - * Figure out what timezone we're in; needed for some date manipulations. - */ -function views_get_timezone() { - global $user; - if (variable_get('configurable_timezones', 1) && $user->uid && strlen($user->timezone)) { - $timezone = $user->timezone; - } - else { - $timezone = variable_get('date_default_timezone', 0); - } - - // set up the database timezone - $db_type = Database::getConnection()->databaseType(); - if (in_array($db_type, array('mysql', 'pgsql'))) { - $offset = '+00:00'; - static $already_set = FALSE; - if (!$already_set) { - if ($db_type == 'pgsql') { - db_query("SET TIME ZONE INTERVAL '$offset' HOUR TO MINUTE"); - } - elseif ($db_type == 'mysql') { - db_query("SET @@session.time_zone = '$offset'"); - } - - $already_set = TRUE; - } - } - - return $timezone; -} - -/** - * Helper function to create cross-database SQL dates. - * - * @param $field - * The real table and field name, like 'tablename.fieldname'. - * @param $field_type - * The type of date field, 'int' or 'datetime'. - * @param $set_offset - * The name of a field that holds the timezone offset or a fixed timezone - * offset value. If not provided, the normal Drupal timezone handling - * will be used, i.e. $set_offset = 0 will make no timezone adjustment. - * @return - * An appropriate SQL string for the db type and field type. - */ -function views_date_sql_field($field, $field_type = 'int', $set_offset = NULL) { - $db_type = Database::getConnection()->databaseType(); - $offset = $set_offset !== NULL ? $set_offset : views_get_timezone(); - if (isset($offset) && !is_numeric($offset)) { - $dtz = new DateTimeZone($offset); - $dt = new DateTime("now", $dtz); - $offset_seconds = $dtz->getOffset($dt); - } - - switch ($db_type) { - case 'mysql': - switch ($field_type) { - case 'int': - $field = "DATE_ADD('19700101', INTERVAL $field SECOND)"; - break; - case 'datetime': - break; - } - if (!empty($offset)) { - $field = "($field + INTERVAL $offset_seconds SECOND)"; - } - return $field; - case 'pgsql': - switch ($field_type) { - case 'int': - $field = "TO_TIMESTAMP($field)"; - break; - case 'datetime': - break; - } - if (!empty($offset)) { - $field = "($field + INTERVAL '$offset_seconds SECONDS')"; - } - return $field; - case 'sqlite': - if (!empty($offset)) { - $field = "($field + '$offset_seconds')"; - } - return $field; - } -} - -/** - * Helper function to create cross-database SQL date formatting. - * - * @param $format - * A format string for the result, like 'Y-m-d H:i:s'. - * @param $field - * The real table and field name, like 'tablename.fieldname'. - * @param $field_type - * The type of date field, 'int' or 'datetime'. - * @param $set_offset - * The name of a field that holds the timezone offset or a fixed timezone - * offset value. If not provided, the normal Drupal timezone handling - * will be used, i.e. $set_offset = 0 will make no timezone adjustment. - * @return - * An appropriate SQL string for the db type and field type. - */ -function views_date_sql_format($format, $field, $field_type = 'int', $set_offset = NULL) { - $db_type = Database::getConnection()->databaseType(); - $field = views_date_sql_field($field, $field_type, $set_offset); - switch ($db_type) { - case 'mysql': - $replace = array( - 'Y' => '%Y', - 'y' => '%y', - 'M' => '%b', - 'm' => '%m', - 'n' => '%c', - 'F' => '%M', - 'D' => '%a', - 'd' => '%d', - 'l' => '%W', - 'j' => '%e', - 'W' => '%v', - 'H' => '%H', - 'h' => '%h', - 'i' => '%i', - 's' => '%s', - 'A' => '%p', - ); - $format = strtr($format, $replace); - return "DATE_FORMAT($field, '$format')"; - case 'pgsql': - $replace = array( - 'Y' => 'YYYY', - 'y' => 'YY', - 'M' => 'Mon', - 'm' => 'MM', - 'n' => 'MM', // no format for Numeric representation of a month, without leading zeros - 'F' => 'Month', - 'D' => 'Dy', - 'd' => 'DD', - 'l' => 'Day', - 'j' => 'DD', // no format for Day of the month without leading zeros - 'W' => 'WW', - 'H' => 'HH24', - 'h' => 'HH12', - 'i' => 'MI', - 's' => 'SS', - 'A' => 'AM', - ); - $format = strtr($format, $replace); - return "TO_CHAR($field, '$format')"; - case 'sqlite': - $replace = array( - 'Y' => '%Y', // 4 digit year number - 'y' => '%Y', // no format for 2 digit year number - 'M' => '%m', // no format for 3 letter month name - 'm' => '%m', // month number with leading zeros - 'n' => '%m', // no format for month number without leading zeros - 'F' => '%m', // no format for full month name - 'D' => '%d', // no format for 3 letter day name - 'd' => '%d', // day of month number with leading zeros - 'l' => '%d', // no format for full day name - 'j' => '%d', // no format for day of month number without leading zeros - 'W' => '%W', // ISO week number - 'H' => '%H', // 24 hour hour with leading zeros - 'h' => '%H', // no format for 12 hour hour with leading zeros - 'i' => '%M', // minutes with leading zeros - 's' => '%S', // seconds with leading zeros - 'A' => '', // no format for AM/PM - ); - $format = strtr($format, $replace); - return "strftime('$format', $field, 'unixepoch')"; - } -} - -/** - * Helper function to create cross-database SQL date extraction. - * - * @param $extract_type - * The type of value to extract from the date, like 'MONTH'. - * @param $field - * The real table and field name, like 'tablename.fieldname'. - * @param $field_type - * The type of date field, 'int' or 'datetime'. - * @param $set_offset - * The name of a field that holds the timezone offset or a fixed timezone - * offset value. If not provided, the normal Drupal timezone handling - * will be used, i.e. $set_offset = 0 will make no timezone adjustment. - * @return - * An appropriate SQL string for the db type and field type. - */ -function views_date_sql_extract($extract_type, $field, $field_type = 'int', $set_offset = NULL) { - $db_type = Database::getConnection()->databaseType(); - $field = views_date_sql_field($field, $field_type, $set_offset); - - // Note there is no space after FROM to avoid db_rewrite problems - // see http://drupal.org/node/79904. - switch ($extract_type) { - case 'DATE': - return $field; - case 'YEAR': - return "EXTRACT(YEAR FROM($field))"; - case 'MONTH': - return "EXTRACT(MONTH FROM($field))"; - case 'DAY': - return "EXTRACT(DAY FROM($field))"; - case 'HOUR': - return "EXTRACT(HOUR FROM($field))"; - case 'MINUTE': - return "EXTRACT(MINUTE FROM($field))"; - case 'SECOND': - return "EXTRACT(SECOND FROM($field))"; - // ISO week number for date - case 'WEEK': - switch ($db_type) { - case 'mysql': - // WEEK using arg 3 in mysql should return the same value as postgres - // EXTRACT. - return "WEEK($field, 3)"; - case 'pgsql': - return "EXTRACT(WEEK FROM($field))"; - } - case 'DOW': - switch ($db_type) { - case 'mysql': - // mysql returns 1 for Sunday through 7 for Saturday php date - // functions and postgres use 0 for Sunday and 6 for Saturday. - return "INTEGER(DAYOFWEEK($field) - 1)"; - case 'pgsql': - return "EXTRACT(DOW FROM($field))"; - } - case 'DOY': - switch ($db_type) { - case 'mysql': - return "DAYOFYEAR($field)"; - case 'pgsql': - return "EXTRACT(DOY FROM($field))"; - } - } -} - -/** - * @} - */ diff --git a/lib/Drupal/views/ManyToOneHelper.php b/lib/Drupal/views/ManyToOneHelper.php index 069e04ea861703fadc52c5da50ac458b4a164efa..3cadfeaa0a39aae2845d50beeb7c8fdabf4f7def 100644 --- a/lib/Drupal/views/ManyToOneHelper.php +++ b/lib/Drupal/views/ManyToOneHelper.php @@ -7,6 +7,8 @@ namespace Drupal\views; +use Drupal\views\Plugin\views\HandlerBase; + /** * This many to one helper object is used on both arguments and filters. * @@ -87,7 +89,7 @@ function add_table($join = NULL, $alias = NULL) { // ensure_path logic. Perhaps it should be. $r_join = clone $join; while ($r_join->left_table != $base_table) { - $r_join = views_get_table_join($r_join->left_table, $base_table); + $r_join = HandlerBase::getTableJoin($r_join->left_table, $base_table); } // If we found that there are tables in between, add the relationship. if ($r_join->table != $join->table) { diff --git a/lib/Drupal/views/Plugin/views/HandlerBase.php b/lib/Drupal/views/Plugin/views/HandlerBase.php index b61de0627b672a1949d19c8c4855fe6448b347be..77fd106c3376de5392f3ae95f612ee7905efb891 100644 --- a/lib/Drupal/views/Plugin/views/HandlerBase.php +++ b/lib/Drupal/views/Plugin/views/HandlerBase.php @@ -10,6 +10,9 @@ use Drupal\Component\Plugin\Discovery\DiscoveryInterface; use Drupal\views\Plugin\views\PluginBase; use Drupal\views\ViewExecutable; +use Drupal\Core\Database\Database; +use DateTimeZone; +use DateTime; abstract class HandlerBase extends PluginBase { @@ -593,7 +596,7 @@ public function getJoin() { $base_table = $this->query->relationships[$this->relationship]['base']; } - $join = views_get_table_join($this->table, $base_table); + $join = $this->getTableJoin($this->table, $base_table); if ($join) { return clone $join; } @@ -618,4 +621,309 @@ public function validate() { return array(); } */ public function broken() { } + /** + * Creates cross-database SQL date formatting. + * + * @param string $format + * A format string for the result, like 'Y-m-d H:i:s'. + * + * @return string + * An appropriate SQL string for the DB type and field type. + */ + public function getSQLFormat($format) { + $db_type = Database::getConnection()->databaseType(); + $field = $this->getSQLDateField(); + switch ($db_type) { + case 'mysql': + $replace = array( + 'Y' => '%Y', + 'y' => '%y', + 'M' => '%b', + 'm' => '%m', + 'n' => '%c', + 'F' => '%M', + 'D' => '%a', + 'd' => '%d', + 'l' => '%W', + 'j' => '%e', + 'W' => '%v', + 'H' => '%H', + 'h' => '%h', + 'i' => '%i', + 's' => '%s', + 'A' => '%p', + ); + $format = strtr($format, $replace); + return "DATE_FORMAT($field, '$format')"; + case 'pgsql': + $replace = array( + 'Y' => 'YYYY', + 'y' => 'YY', + 'M' => 'Mon', + 'm' => 'MM', + 'n' => 'MM', // no format for Numeric representation of a month, without leading zeros + 'F' => 'Month', + 'D' => 'Dy', + 'd' => 'DD', + 'l' => 'Day', + 'j' => 'DD', // no format for Day of the month without leading zeros + 'W' => 'WW', + 'H' => 'HH24', + 'h' => 'HH12', + 'i' => 'MI', + 's' => 'SS', + 'A' => 'AM', + ); + $format = strtr($format, $replace); + return "TO_CHAR($field, '$format')"; + case 'sqlite': + $replace = array( + 'Y' => '%Y', // 4 digit year number + 'y' => '%Y', // no format for 2 digit year number + 'M' => '%m', // no format for 3 letter month name + 'm' => '%m', // month number with leading zeros + 'n' => '%m', // no format for month number without leading zeros + 'F' => '%m', // no format for full month name + 'D' => '%d', // no format for 3 letter day name + 'd' => '%d', // day of month number with leading zeros + 'l' => '%d', // no format for full day name + 'j' => '%d', // no format for day of month number without leading zeros + 'W' => '%W', // ISO week number + 'H' => '%H', // 24 hour hour with leading zeros + 'h' => '%H', // no format for 12 hour hour with leading zeros + 'i' => '%M', // minutes with leading zeros + 's' => '%S', // seconds with leading zeros + 'A' => '', // no format for AM/PM + ); + $format = strtr($format, $replace); + return "strftime('$format', $field, 'unixepoch')"; + } + } + + /** + * Creates cross-database SQL dates. + * + * @return string + * An appropriate SQL string for the db type and field type. + */ + public function getSQLDateField() { + $field = "$this->tableAlias.$this->realField"; + $db_type = Database::getConnection()->databaseType(); + $offset = $this->getTimezone(); + if (isset($offset) && !is_numeric($offset)) { + $dtz = new DateTimeZone($offset); + $dt = new DateTime('now', $dtz); + $offset_seconds = $dtz->getOffset($dt); + } + + switch ($db_type) { + case 'mysql': + $field = "DATE_ADD('19700101', INTERVAL $field SECOND)"; + if (!empty($offset)) { + $field = "($field + INTERVAL $offset_seconds SECOND)"; + } + return $field; + case 'pgsql': + $field = "TO_TIMESTAMP($field)"; + if (!empty($offset)) { + $field = "($field + INTERVAL '$offset_seconds SECONDS')"; + } + return $field; + case 'sqlite': + if (!empty($offset)) { + $field = "($field + '$offset_seconds')"; + } + return $field; + } + } + + /** + * Figure out what timezone we're in; needed for some date manipulations. + */ + public static function getTimezone() { + global $user; + if (variable_get('configurable_timezones', 1) && $user->uid && strlen($user->timezone)) { + $timezone = $user->timezone; + } + else { + $timezone = variable_get('date_default_timezone', 0); + } + + // set up the database timezone + $db_type = Database::getConnection()->databaseType(); + if (in_array($db_type, array('mysql', 'pgsql'))) { + $offset = '+00:00'; + static $already_set = FALSE; + if (!$already_set) { + if ($db_type == 'pgsql') { + db_query("SET TIME ZONE INTERVAL '$offset' HOUR TO MINUTE"); + } + elseif ($db_type == 'mysql') { + db_query("SET @@session.time_zone = '$offset'"); + } + + $already_set = TRUE; + } + } + + return $timezone; + } + + /** + * Fetches a handler to join one table to a primary table from the data cache. + * + * @param string $table + * The table to join from. + * @param string $base_table + * The table to join to. + * + * @return Drupal\views\Plugin\views\join\JoinPluginBase + */ + public static function getTableJoin($table, $base_table) { + $data = views_fetch_data($table); + if (isset($data['table']['join'][$base_table])) { + $h = $data['table']['join'][$base_table]; + if (!empty($h['join_id']) && class_exists($h['handler'])) { + $id = $h['join_id']; + } + else { + $id = 'standard'; + } + $handler = views_get_plugin('join', $id); + + // Fill in some easy defaults + $handler->definition = $h; + if (empty($handler->definition['table'])) { + $handler->definition['table'] = $table; + } + // If this is empty, it's a direct link. + if (empty($handler->definition['left_table'])) { + $handler->definition['left_table'] = $base_table; + } + + if (isset($h['arguments'])) { + call_user_func_array(array(&$handler, 'construct'), $h['arguments']); + } + else { + $handler->construct(); + } + + return $handler; + } + } + + /** + * Breaks x,y,z and x+y+z into an array. Numeric only. + * + * @param string $str + * The string to parse. + * @param Drupal\views\Plugin\views\HandlerBase|null $handler + * The handler object to use as a base. If not specified one will + * be created. + * + * @return Drupal\views\Plugin\views\HandlerBase|stdClass $handler + * The new handler object. + */ + public static function breakPhrase($str, &$handler = NULL) { + if (!$handler) { + $handler = new \stdClass(); + } + + // Set up defaults: + + if (!isset($handler->value)) { + $handler->value = array(); + } + + if (!isset($handler->operator)) { + $handler->operator = 'or'; + } + + if (empty($str)) { + return $handler; + } + + if (preg_match('/^([0-9]+[+ ])+[0-9]+$/', $str)) { + // The '+' character in a query string may be parsed as ' '. + $handler->operator = 'or'; + $handler->value = preg_split('/[+ ]/', $str); + } + elseif (preg_match('/^([0-9]+,)*[0-9]+$/', $str)) { + $handler->operator = 'and'; + $handler->value = explode(',', $str); + } + + // Keep an 'error' value if invalid strings were given. + if (!empty($str) && (empty($handler->value) || !is_array($handler->value))) { + $handler->value = array(-1); + return $handler; + } + + // Doubly ensure that all values are numeric only. + foreach ($handler->value as $id => $value) { + $handler->value[$id] = intval($value); + } + + return $handler; + } + + /** + * Breaks x,y,z and x+y+z into an array. Works for strings. + * + * @param string $str + * The string to parse. + * @param Drupal\views\Plugin\views\HandlerBase|null $handler + * The object to use as a base. If not specified one will + * be created. + * + * @return Drupal\views\Plugin\views\HandlerBase|stdClass $handler + * The new handler object. + */ + public static function breakPhraseString($str, &$handler = NULL) { + if (!$handler) { + $handler = new \stdClass(); + } + + // Set up defaults: + if (!isset($handler->value)) { + $handler->value = array(); + } + + if (!isset($handler->operator)) { + $handler->operator = 'or'; + } + + if ($str == '') { + return $handler; + } + + // Determine if the string has 'or' operators (plus signs) or 'and' operators + // (commas) and split the string accordingly. If we have an 'and' operator, + // spaces are treated as part of the word being split, but otherwise they are + // treated the same as a plus sign. + $or_wildcard = '[^\s+,]'; + $and_wildcard = '[^+,]'; + if (preg_match("/^({$or_wildcard}+[+ ])+{$or_wildcard}+$/", $str)) { + $handler->operator = 'or'; + $handler->value = preg_split('/[+ ]/', $str); + } + elseif (preg_match("/^({$and_wildcard}+,)*{$and_wildcard}+$/", $str)) { + $handler->operator = 'and'; + $handler->value = explode(',', $str); + } + + // Keep an 'error' value if invalid strings were given. + if (!empty($str) && (empty($handler->value) || !is_array($handler->value))) { + $handler->value = array(-1); + return $handler; + } + + // Doubly ensure that all values are strings only. + foreach ($handler->value as $id => $value) { + $handler->value[$id] = (string) $value; + } + + return $handler; + } + } diff --git a/lib/Drupal/views/Plugin/views/argument/ArgumentPluginBase.php b/lib/Drupal/views/Plugin/views/argument/ArgumentPluginBase.php index 4676b72c3f2d11b5fe043d57f0e59697a4ee2817..1efbfda9a2702baf9f48dd406ef7bfe9d04f165f 100644 --- a/lib/Drupal/views/Plugin/views/argument/ArgumentPluginBase.php +++ b/lib/Drupal/views/Plugin/views/argument/ArgumentPluginBase.php @@ -820,7 +820,7 @@ function summary_name_field() { // if the alias is different then we're probably added, not ensured, // so look up the join and add it instead. if ($this->tableAlias != $this->name_table) { - $j = views_get_table_join($this->name_table, $this->table); + $j = HandlerBase::getTableJoin($this->name_table, $this->table); if ($j) { $join = clone $j; $join->left_table = $this->tableAlias; diff --git a/lib/Drupal/views/Plugin/views/argument/Date.php b/lib/Drupal/views/Plugin/views/argument/Date.php index 183011a656d3822ac1a6b85a6013d3ceecff2fdb..ce3f52f72389ac20612fafad0416c650a83cd8b7 100644 --- a/lib/Drupal/views/Plugin/views/argument/Date.php +++ b/lib/Drupal/views/Plugin/views/argument/Date.php @@ -83,4 +83,63 @@ function get_sort_name() { return t('Date', array(), array('context' => 'Sort order')); } + /** + * Creates cross-database SQL date extraction. + * + * @param string $extract_type + * The type of value to extract from the date, like 'MONTH'. + * + * @return string + * An appropriate SQL string for the DB type and field type. + */ + public function extractSQL($extract_type) { + $db_type = Database::getConnection()->databaseType(); + $field = $this->getSQLDateField(); + + // Note there is no space after FROM to avoid db_rewrite problems + // see http://drupal.org/node/79904. + switch ($extract_type) { + case 'DATE': + return $field; + case 'YEAR': + return "EXTRACT(YEAR FROM($field))"; + case 'MONTH': + return "EXTRACT(MONTH FROM($field))"; + case 'DAY': + return "EXTRACT(DAY FROM($field))"; + case 'HOUR': + return "EXTRACT(HOUR FROM($field))"; + case 'MINUTE': + return "EXTRACT(MINUTE FROM($field))"; + case 'SECOND': + return "EXTRACT(SECOND FROM($field))"; + // ISO week number for date + case 'WEEK': + switch ($db_type) { + case 'mysql': + // WEEK using arg 3 in mysql should return the same value as postgres + // EXTRACT. + return "WEEK($field, 3)"; + case 'pgsql': + return "EXTRACT(WEEK FROM($field))"; + } + case 'DOW': + switch ($db_type) { + case 'mysql': + // mysql returns 1 for Sunday through 7 for Saturday php date + // functions and postgres use 0 for Sunday and 6 for Saturday. + return "INTEGER(DAYOFWEEK($field) - 1)"; + case 'pgsql': + return "EXTRACT(DOW FROM($field))"; + } + case 'DOY': + switch ($db_type) { + case 'mysql': + return "DAYOFYEAR($field)"; + case 'pgsql': + return "EXTRACT(DOY FROM($field))"; + } + } + } + } diff --git a/lib/Drupal/views/Plugin/views/argument/ManyToOne.php b/lib/Drupal/views/Plugin/views/argument/ManyToOne.php index 9ca51001731ec9a861e60aa0a810a58bd8670f0f..b0807ad46ffb1303a61054e0d9bff35a2b98e0a7 100644 --- a/lib/Drupal/views/Plugin/views/argument/ManyToOne.php +++ b/lib/Drupal/views/Plugin/views/argument/ManyToOne.php @@ -117,11 +117,11 @@ public function query($group_by = FALSE) { } if (!empty($this->options['break_phrase'])) { - if (!empty($this->definition['nummeric'])) { - views_break_phrase($this->argument, $this); + if (!empty($this->definition['numeric'])) { + $this->breakPhrase($this->argument, $this); } else { - views_break_phrase_string($this->argument, $this); + $this->breakPhraseString($this->argument, $this); } } else { @@ -138,7 +138,7 @@ function title() { } if (!empty($this->options['break_phrase'])) { - views_break_phrase($this->argument, $this); + $this->breakPhrase($this->argument, $this); } else { $this->value = array($this->argument); diff --git a/lib/Drupal/views/Plugin/views/argument/Numeric.php b/lib/Drupal/views/Plugin/views/argument/Numeric.php index 9f74bfc07ec9147dc667cf1314cfa0cd8e6b5b57..3972b4da378cb9ab08703ba9b314727fb6d35a4f 100644 --- a/lib/Drupal/views/Plugin/views/argument/Numeric.php +++ b/lib/Drupal/views/Plugin/views/argument/Numeric.php @@ -69,7 +69,7 @@ function title() { } if (!empty($this->options['break_phrase'])) { - views_break_phrase($this->argument, $this); + $this->breakPhrase($this->argument, $this); } else { $this->value = array($this->argument); @@ -100,7 +100,7 @@ public function query($group_by = FALSE) { $this->ensureMyTable(); if (!empty($this->options['break_phrase'])) { - views_break_phrase($this->argument, $this); + $this->breakPhrase($this->argument, $this); } else { $this->value = array($this->argument); diff --git a/lib/Drupal/views/Plugin/views/argument/String.php b/lib/Drupal/views/Plugin/views/argument/String.php index 2f3646a5bf1342b102617042f98c2fa7634868e0..59148deccb39916524969ccb675c03b11e496b1d 100644 --- a/lib/Drupal/views/Plugin/views/argument/String.php +++ b/lib/Drupal/views/Plugin/views/argument/String.php @@ -186,7 +186,7 @@ public function query($group_by = FALSE) { } if (!empty($this->options['break_phrase'])) { - views_break_phrase_string($argument, $this); + $this->breakPhraseString($argument, $this); } else { $this->value = array($argument); @@ -257,7 +257,7 @@ function title() { } if (!empty($this->options['break_phrase'])) { - views_break_phrase_string($this->argument, $this); + $this->breakPhraseString($this->argument, $this); } else { $this->value = array($this->argument); diff --git a/lib/Drupal/views/Plugin/views/query/Sql.php b/lib/Drupal/views/Plugin/views/query/Sql.php index b94074c7094ee3df6a02ed4f093cfedc623811c3..8d42b8fca8674fb32819ad709be998a924629011 100644 --- a/lib/Drupal/views/Plugin/views/query/Sql.php +++ b/lib/Drupal/views/Plugin/views/query/Sql.php @@ -10,6 +10,7 @@ use Drupal\Core\Database\Database; use Drupal\Core\Database\DatabaseExceptionWrapper; use Drupal\views\Plugin\views\join\JoinPluginBase; +use Drupal\views\Plugin\views\HandlerBase; use Drupal\Core\Annotation\Plugin; use Drupal\Core\Annotation\Translation; use Drupal\views\ViewExecutable; @@ -700,7 +701,7 @@ function get_join_data($table, $base_table) { if (!empty($this->table_queue[$table])) { $table = $this->table_queue[$table]['table']; } - return views_get_table_join($table, $base_table); + return HandlerBase::getTableJoin($table, $base_table); } /** diff --git a/lib/Drupal/views/Plugin/views/sort/Date.php b/lib/Drupal/views/Plugin/views/sort/Date.php index 0eb5158a02479fef27ade94a9a7f02c5d1b763a3..a00e3d8dd1b2bc92b4d30642506e38f5cce39853 100644 --- a/lib/Drupal/views/Plugin/views/sort/Date.php +++ b/lib/Drupal/views/Plugin/views/sort/Date.php @@ -59,19 +59,19 @@ public function query() { $this->query->add_orderby($this->tableAlias, $this->realField, $this->options['order']); return; case 'minute': - $formula = views_date_sql_format('YmdHi', "$this->tableAlias.$this->realField"); + $formula = $this->getSQLFormat('YmdHi'); break; case 'hour': - $formula = views_date_sql_format('YmdH', "$this->tableAlias.$this->realField"); + $formula = $this->getSQLFormat('YmdH'); break; case 'day': - $formula = views_date_sql_format('Ymd', "$this->tableAlias.$this->realField"); + $formula = $this->getSQLFormat('Ymd'); break; case 'month': - $formula = views_date_sql_format('Ym', "$this->tableAlias.$this->realField"); + $formula = $this->getSQLFormat('Ym'); break; case 'year': - $formula = views_date_sql_format('Y', "$this->tableAlias.$this->realField"); + $formula = $this->getSQLFormat('Y'); break; } diff --git a/lib/Drupal/views/Tests/Handler/HandlerTest.php b/lib/Drupal/views/Tests/Handler/HandlerTest.php index fa49a461a9723549979afb2b10e64daab6097729..b98b9563c51ecba35344ec1bfdf341a232680665 100644 --- a/lib/Drupal/views/Tests/Handler/HandlerTest.php +++ b/lib/Drupal/views/Tests/Handler/HandlerTest.php @@ -9,6 +9,7 @@ use stdClass; use Drupal\views\Tests\ViewTestBase; +use Drupal\views\Plugin\views\HandlerBase; /** * Tests abstract handlers of views. @@ -54,58 +55,56 @@ function testFilterInOperatorUi() { } /** - * Tests views_break_phrase_string function. + * Tests the breakPhraseString() method. */ - function test_views_break_phrase_string() { + function testBreakPhraseString() { $empty_stdclass = new StdClass(); $empty_stdclass->operator = 'or'; $empty_stdclass->value = array(); - views_include('handlers'); - $null = NULL; - // check defaults - $this->assertEqual($empty_stdclass, views_break_phrase_string('', $null)); + $null = NULL; + $this->assertEqual($empty_stdclass, HandlerBase::breakPhraseString('', $null)); $handler = views_get_handler('node', 'title', 'argument'); - $this->assertEqual($handler, views_break_phrase_string('', $handler), 'The views_break_phrase_string() works correctly.'); + $this->assertEqual($handler, HandlerBase::breakPhraseString('', $handler), 'The breakPhraseString() method works correctly.'); // test ors - $handler = views_break_phrase_string('word1 word2+word'); + $handler = HandlerBase::breakPhraseString('word1 word2+word'); $this->assertEqualValue(array('word1', 'word2', 'word'), $handler); $this->assertEqual('or', $handler->operator); - $handler = views_break_phrase_string('word1+word2+word'); + $handler = HandlerBase::breakPhraseString('word1+word2+word'); $this->assertEqualValue(array('word1', 'word2', 'word'), $handler); $this->assertEqual('or', $handler->operator); - $handler = views_break_phrase_string('word1 word2 word'); + $handler = HandlerBase::breakPhraseString('word1 word2 word'); $this->assertEqualValue(array('word1', 'word2', 'word'), $handler); $this->assertEqual('or', $handler->operator); - $handler = views_break_phrase_string('word-1+word-2+word'); + $handler = HandlerBase::breakPhraseString('word-1+word-2+word'); $this->assertEqualValue(array('word-1', 'word-2', 'word'), $handler); $this->assertEqual('or', $handler->operator); - $handler = views_break_phrase_string('wõrd1+wõrd2+wõrd'); + $handler = HandlerBase::breakPhraseString('wõrd1+wõrd2+wõrd'); $this->assertEqualValue(array('wõrd1', 'wõrd2', 'wõrd'), $handler); $this->assertEqual('or', $handler->operator); // test ands. - $handler = views_break_phrase_string('word1,word2,word'); + $handler = HandlerBase::breakPhraseString('word1,word2,word'); $this->assertEqualValue(array('word1', 'word2', 'word'), $handler); $this->assertEqual('and', $handler->operator); - $handler = views_break_phrase_string('word1 word2,word'); + $handler = HandlerBase::breakPhraseString('word1 word2,word'); $this->assertEqualValue(array('word1 word2', 'word'), $handler); $this->assertEqual('and', $handler->operator); - $handler = views_break_phrase_string('word1,word2 word'); + $handler = HandlerBase::breakPhraseString('word1,word2 word'); $this->assertEqualValue(array('word1', 'word2 word'), $handler); $this->assertEqual('and', $handler->operator); - $handler = views_break_phrase_string('word-1,word-2,word'); + $handler = HandlerBase::breakPhraseString('word-1,word-2,word'); $this->assertEqualValue(array('word-1', 'word-2', 'word'), $handler); $this->assertEqual('and', $handler->operator); - $handler = views_break_phrase_string('wõrd1,wõrd2,wõrd'); + $handler = HandlerBase::breakPhraseString('wõrd1,wõrd2,wõrd'); $this->assertEqualValue(array('wõrd1', 'wõrd2', 'wõrd'), $handler); $this->assertEqual('and', $handler->operator); // test a single word - $handler = views_break_phrase_string('word'); + $handler = HandlerBase::breakPhraseString('word'); $this->assertEqualValue(array('word'), $handler); $this->assertEqual('and', $handler->operator); } @@ -113,36 +112,36 @@ function test_views_break_phrase_string() { /** * Tests views_break_phrase function. */ - function test_views_break_phrase() { + function testBreakPhrase() { $empty_stdclass = new StdClass(); $empty_stdclass->operator = 'or'; $empty_stdclass->value = array(); $null = NULL; // check defaults - $this->assertEqual($empty_stdclass, views_break_phrase('', $null)); + $this->assertEqual($empty_stdclass, HandlerBase::breakPhrase('', $null)); $handler = views_get_handler('node', 'title', 'argument'); - $this->assertEqual($handler, views_break_phrase('', $handler), 'The views_break_phrase() function works correctly.'); + $this->assertEqual($handler, HandlerBase::breakPhrase('', $handler), 'The breakPhrase() method works correctly.'); // Generate three random numbers which can be used below; $n1 = rand(0, 100); $n2 = rand(0, 100); $n3 = rand(0, 100); // test ors - $this->assertEqualValue(array($n1, $n2, $n3), views_break_phrase("$n1 $n2+$n3", $handler)); + $this->assertEqualValue(array($n1, $n2, $n3), HandlerBase::breakPhrase("$n1 $n2+$n3", $handler)); $this->assertEqual('or', $handler->operator); - $this->assertEqualValue(array($n1, $n2, $n3), views_break_phrase("$n1+$n2+$n3", $handler)); + $this->assertEqualValue(array($n1, $n2, $n3), HandlerBase::breakPhrase("$n1+$n2+$n3", $handler)); $this->assertEqual('or', $handler->operator); - $this->assertEqualValue(array($n1, $n2, $n3), views_break_phrase("$n1 $n2 $n3", $handler)); + $this->assertEqualValue(array($n1, $n2, $n3), HandlerBase::breakPhrase("$n1 $n2 $n3", $handler)); $this->assertEqual('or', $handler->operator); - $this->assertEqualValue(array($n1, $n2, $n3), views_break_phrase("$n1 $n2++$n3", $handler)); + $this->assertEqualValue(array($n1, $n2, $n3), HandlerBase::breakPhrase("$n1 $n2++$n3", $handler)); $this->assertEqual('or', $handler->operator); // test ands. - $this->assertEqualValue(array($n1, $n2, $n3), views_break_phrase("$n1,$n2,$n3", $handler)); + $this->assertEqualValue(array($n1, $n2, $n3), HandlerBase::breakPhrase("$n1,$n2,$n3", $handler)); $this->assertEqual('and', $handler->operator); - $this->assertEqualValue(array($n1, $n2, $n3), views_break_phrase("$n1,,$n2,$n3", $handler)); + $this->assertEqualValue(array($n1, $n2, $n3), HandlerBase::breakPhrase("$n1,,$n2,$n3", $handler)); $this->assertEqual('and', $handler->operator); } diff --git a/lib/Drupal/views/Tests/PluginInstanceTest.php b/lib/Drupal/views/Tests/PluginInstanceTest.php index 1afd0faf64109ecd125d41e8a2db57b5895acea8..b9187727c946f5fe3c5a13447a9ffa06b151d33d 100644 --- a/lib/Drupal/views/Tests/PluginInstanceTest.php +++ b/lib/Drupal/views/Tests/PluginInstanceTest.php @@ -59,7 +59,6 @@ public static function getInfo() { protected function setUp() { parent::setUp(); - views_include('handlers'); $this->definitions = views_get_plugin_definitions(); } diff --git a/lib/Views/node/Plugin/views/argument/CreatedDay.php b/lib/Views/node/Plugin/views/argument/CreatedDay.php index f354d7db087c50d576a49d54c8009ef27f9ace9a..0d6b4240feb82842773c6207584f302fd72dcfea 100644 --- a/lib/Views/node/Plugin/views/argument/CreatedDay.php +++ b/lib/Views/node/Plugin/views/argument/CreatedDay.php @@ -26,7 +26,7 @@ class CreatedDay extends Date { * Overrides Drupal\views\Plugin\views\argument\Formula::get_formula(). */ function get_formula() { - $this->formula = views_date_sql_extract('DAY', "***table***.$this->realField"); + $this->formula = $this->extractSQL('DAY'); return parent::get_formula(); } diff --git a/lib/Views/node/Plugin/views/argument/CreatedFullDate.php b/lib/Views/node/Plugin/views/argument/CreatedFullDate.php index ebb5ff69224d301724a99b5b568280e5f2bfa75a..ac3e1d9f5f06e8cbeff4889accd169bea1ee26a7 100644 --- a/lib/Views/node/Plugin/views/argument/CreatedFullDate.php +++ b/lib/Views/node/Plugin/views/argument/CreatedFullDate.php @@ -26,7 +26,7 @@ class CreatedFullDate extends Date { * Overrides Drupal\views\Plugin\views\argument\Formula::get_formula(). */ function get_formula() { - $this->formula = views_date_sql_format($this->definition['arg_format'], "***table***.$this->realField"); + $this->formula = $this->getSQLFormat($this->definition['arg_format']); return parent::get_formula(); } diff --git a/lib/Views/node/Plugin/views/argument/CreatedMonth.php b/lib/Views/node/Plugin/views/argument/CreatedMonth.php index 2278f40b532ee48e68411c498fc26f709a15df9a..22fb87fc36ca8158b0b7da3c43b0d608e4d7ffaa 100644 --- a/lib/Views/node/Plugin/views/argument/CreatedMonth.php +++ b/lib/Views/node/Plugin/views/argument/CreatedMonth.php @@ -26,7 +26,7 @@ class CreatedMonth extends Date { * Overrides Drupal\views\Plugin\views\argument\Formula::get_formula(). */ function get_formula() { - $this->formula = views_date_sql_extract('MONTH', "***table***.$this->realField"); + $this->formula = $this->extractSQL('MONTH'); return parent::get_formula(); } diff --git a/lib/Views/node/Plugin/views/argument/CreatedWeek.php b/lib/Views/node/Plugin/views/argument/CreatedWeek.php index 10723ff2edf58583783686798c4d50634d55fdc6..e68c4681aaacf04048b5119a1a4a81b77e7ba1bc 100644 --- a/lib/Views/node/Plugin/views/argument/CreatedWeek.php +++ b/lib/Views/node/Plugin/views/argument/CreatedWeek.php @@ -25,7 +25,7 @@ class CreatedWeek extends Date { * Overrides Drupal\views\Plugin\views\argument\Formula::get_formula(). */ function get_formula() { - $this->formula = views_date_sql_extract('WEEK', "***table***.$this->realField"); + $this->formula = $this->extractSQL('WEEK'); return parent::get_formula(); } diff --git a/lib/Views/node/Plugin/views/argument/CreatedYear.php b/lib/Views/node/Plugin/views/argument/CreatedYear.php index 6250b612dd2bb6e1560f992ee7c6a6f56fb45d76..fd92735bdaea3646ae36f792a5241f69df1a05e3 100644 --- a/lib/Views/node/Plugin/views/argument/CreatedYear.php +++ b/lib/Views/node/Plugin/views/argument/CreatedYear.php @@ -25,7 +25,7 @@ class CreatedYear extends Date { * Overrides Drupal\views\Plugin\views\argument\Formula::get_formula(). */ function get_formula() { - $this->formula = views_date_sql_extract('YEAR', "***table***.$this->realField"); + $this->formula = $this->extractSQL('YEAR'); return parent::get_formula(); } diff --git a/lib/Views/node/Plugin/views/argument/CreatedYearMonth.php b/lib/Views/node/Plugin/views/argument/CreatedYearMonth.php index 090ed8b6ca4e99ec6053d913687c792143592839..5e0b8927254abc91b4ce6e77ab3bbb221abed45b 100644 --- a/lib/Views/node/Plugin/views/argument/CreatedYearMonth.php +++ b/lib/Views/node/Plugin/views/argument/CreatedYearMonth.php @@ -26,7 +26,7 @@ class CreatedYearMonth extends Date { * Overrides Drupal\views\Plugin\views\argument\Formula::get_formula(). */ function get_formula() { - $this->formula = views_date_sql_format($this->definition['arg_format'], "***table***.$this->realField"); + $this->formula = $this->getSQLFormat($this->definition['arg_format']); return parent::get_formula(); } diff --git a/lib/Views/node/Plugin/views/argument_validator/Node.php b/lib/Views/node/Plugin/views/argument_validator/Node.php index f85ffb25b257a08ad30d1400784dd78a932b9ff4..5066977410b8e50f8dd3aec75fd16c585a46a6f5 100644 --- a/lib/Views/node/Plugin/views/argument_validator/Node.php +++ b/lib/Views/node/Plugin/views/argument_validator/Node.php @@ -111,7 +111,7 @@ function validate_argument($argument) { case 'nids': $nids = new stdClass(); $nids->value = array($argument); - $nids = views_break_phrase($argument, $nids); + $nids = $this->breakPhrase($argument, $nids); if ($nids->value == array(-1)) { return FALSE; } diff --git a/lib/Views/taxonomy/Plugin/views/argument/IndexTidDepth.php b/lib/Views/taxonomy/Plugin/views/argument/IndexTidDepth.php index 2eaf98423d486bedfa458099c309694c4f1e8d86..8616a1b8d831471142724d4552b59032fa25022a 100644 --- a/lib/Views/taxonomy/Plugin/views/argument/IndexTidDepth.php +++ b/lib/Views/taxonomy/Plugin/views/argument/IndexTidDepth.php @@ -104,7 +104,7 @@ public function query($group_by = FALSE) { if (!empty($this->options['break_phrase'])) { $tids = new stdClass(); $tids->value = $this->argument; - $tids = views_break_phrase($this->argument, $tids); + $tids = $this->breakPhrase($this->argument, $tids); if ($tids->value == array(-1)) { return FALSE; } diff --git a/lib/Views/taxonomy/Plugin/views/argument_validator/Term.php b/lib/Views/taxonomy/Plugin/views/argument_validator/Term.php index 73f567f3678c661ebae8cdeef8ed0c17dd0a8fc1..a4e250cf162ca97a447f1d644297fd335a22b048 100644 --- a/lib/Views/taxonomy/Plugin/views/argument_validator/Term.php +++ b/lib/Views/taxonomy/Plugin/views/argument_validator/Term.php @@ -115,7 +115,7 @@ function validate_argument($argument) { $tids = new stdClass(); $tids->value = $argument; - $tids = views_break_phrase($argument, $tids); + $tids = $this->breakPhrase($argument, $tids); if ($tids->value == array(-1)) { return FALSE; } diff --git a/views.module b/views.module index bbe7d81bc90bd27f3bff6e8e81408d81e4500178..737ab4e70fb3ede3de1094075538b3892e327bd0 100644 --- a/views.module +++ b/views.module @@ -1247,7 +1247,6 @@ function views_include_handlers($reset = FALSE) { return; } - views_include('handlers'); views_include('cache'); views_module_include(); $finished = TRUE; @@ -1278,9 +1277,6 @@ function views_get_handler($table, $field, $type, $override = NULL) { $data = views_fetch_data($table, FALSE); $handler = NULL; - views_include('handlers'); - - // Support old views_data entries conversion. // Support conversion on table level. if (isset($data['moved to'])) {