From fefbe772087a91360316a94d924c180f4e851003 Mon Sep 17 00:00:00 2001 From: DarkAngelBGE Date: Tue, 21 Jul 2009 20:57:39 +0000 Subject: [PATCH] Minor refactorings for DboMysql, DboSource and TextHelper git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8241 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/model/datasources/dbo/dbo_mysql.php | 6 ++++-- cake/libs/model/datasources/dbo_source.php | 11 +++++++---- cake/libs/view/helpers/text.php | 5 ++++- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/cake/libs/model/datasources/dbo/dbo_mysql.php b/cake/libs/model/datasources/dbo/dbo_mysql.php index 2dee3f504..2d97e141c 100644 --- a/cake/libs/model/datasources/dbo/dbo_mysql.php +++ b/cake/libs/model/datasources/dbo/dbo_mysql.php @@ -481,9 +481,11 @@ class DboMysql extends DboMysqlBase { if ($parent != null) { return $parent; - } elseif ($data === null || (is_array($data) && empty($data))) { + } + if ($data === null || (is_array($data) && empty($data))) { return 'NULL'; - } elseif ($data === '' && $column !== 'integer' && $column !== 'float' && $column !== 'boolean') { + } + if ($data === '' && $column !== 'integer' && $column !== 'float' && $column !== 'boolean') { return "''"; } if (empty($column)) { diff --git a/cake/libs/model/datasources/dbo_source.php b/cake/libs/model/datasources/dbo_source.php index 1ad21c115..ff5097145 100644 --- a/cake/libs/model/datasources/dbo_source.php +++ b/cake/libs/model/datasources/dbo_source.php @@ -200,9 +200,8 @@ class DboSource extends DataSource { if ($this->error) { $this->showQuery($sql); return false; - } else { - return $this->_result; } + return $this->_result; } /** * DataSource Query abstraction @@ -1515,12 +1514,12 @@ class DboSource extends DataSource { return $join; } /** - * Returns the an SQL calculation, i.e. COUNT() or MAX() + * Returns an SQL calculation, i.e. COUNT() or MAX() * * @param model $model * @param string $func Lowercase name of SQL function, i.e. 'count' or 'max' * @param array $params Function parameters (any values must be quoted manually) - * @return string An SQL calculation function + * @return string An SQL calculation function * @access public */ function calculate(&$model, $func, $params = array()) { @@ -1908,7 +1907,9 @@ class DboSource extends DataSource { } } + $type = (is_object($model) ? $model->getColumnType($key) : null); + $null = ($value === null || (is_array($value) && empty($value))); if (strtolower($operator) === 'not') { @@ -1917,6 +1918,7 @@ class DboSource extends DataSource { ); return $data[0]; } + $value = $this->value($value, $type); if ($key !== '?') { @@ -1957,6 +1959,7 @@ class DboSource extends DataSource { break; } } + return "{$key} {$operator} {$value}"; } /** diff --git a/cake/libs/view/helpers/text.php b/cake/libs/view/helpers/text.php index d12a0396b..a3ae2bee4 100644 --- a/cake/libs/view/helpers/text.php +++ b/cake/libs/view/helpers/text.php @@ -277,17 +277,20 @@ class TextHelper extends AppHelper { } $pos = strpos(strtolower($text), strtolower($phrase)); + $startPos = 0; if ($pos > $radius) { $startPos = $pos - $radius; } + $textLen = strlen($text); + $endPos = $pos + $phraseLen + $radius; if ($endPos >= $textLen) { $endPos = $textLen; } - $excerpt = substr($text, $startPos, $endPos - $startPos); + $excerpt = substr($text, $startPos, $endPos - $startPos); if ($startPos != 0) { $excerpt = substr_replace($excerpt, $ending, 0, $phraseLen); }