Skip to content

Commit

Permalink
merge from 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
qiang.xue committed May 6, 2009
1 parent b124980 commit c7a9962
Show file tree
Hide file tree
Showing 27 changed files with 634 additions and 571 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,27 @@ Version 1.0.5 to be released
- Bug #234: Multi-line Yii::t() not found by 'yiic message' (Qiang)
- Bug #239: Syntax error in translated Portuguese error view file (Qiang)
- Bug #246: Undefined variable in CMaskedTextField (Qiang)
- Bug #252: mimeTypes.php contains clashing types (Qiang)
- Bug #262: Setting 'charset' of CDbConnection causes exception when working with SQLite (Qiang)
- Bug #263: Exception is thrown when column names contain "=" symbol (Qiang)
- Bug #270: CComponent::detachBehavior() uses undefined index (Qiang)
- Bug: Lazy loading HAS_MANY or MANY_MANY properties will get NULL instead of empty array when the result set is empty (Qiang)
- Bug: CDateFormatter::formatYear() only returns one digit when the year pattern is 'yy' (Qiang)
- New #210: Added support for named scope of AR (Qiang)
- New #211: Enhanced AR by supporting lazy relational query with on-the-fly query parameters (Qiang)
- New #247: Added support to allow using Web services in PHP versions lower than 5.2.0 (Qiang)
- New #254: Added support to allow input widgets to be used with tabular inputs (Qiang)
- New #265: Added support to validate time and datetime inputs (Qiang)
- New: Deprecated CHtml::getActiveId() (Qiang)
- New: Added CDbCriteria::mergeWith() (Qiang)
- New: Added Oracle support for Active Record (Ricardo)
- New: Modified CClientScript so that it can be used without the presence of a controller (Qiang)
- New: Enhanced CWebUser::checkAccess() to allow caching the access check results (Qiang)
- New: Enhanced the performance of CDbAuthManager::checkAccess() (Qiang)
- New: Added CAccessControlFilter::accessDenied() (Qiang)
- New: Added CWebUser::identityCookie property (Qiang)
- New: Added new message placeholder to CCompareValidator (Qiang)
- New: Added trace statements to auth components (Qiang)

Version 1.0.4 April 5, 2009
---------------------------
Expand Down
2 changes: 2 additions & 0 deletions UPGRADE
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ modify your method declaration accordingly. Because the new parameter will
enable caching the access check results by default, please double check
your code containing this method call to make sure the behavior is as expected.

- CDateParser has been renamed to CDateTimeParser


Upgrading from v1.0.3
---------------------
Expand Down
2 changes: 1 addition & 1 deletion docs/guide/database.ar.txt
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ Named Scopes

A *named scope* represents a *named* query criteria that can be combined with other named scopes and applied to an active record query.

Named scopes are mainly declared in the [CActiveRecord::scopes()] method as name-criteria pairs. The following code declares three named scopes, `published` and `recently`, in the `Post` model class:
Named scopes are mainly declared in the [CActiveRecord::scopes()] method as name-criteria pairs. The following code declares two named scopes, `published` and `recently`, in the `Post` model class:

~~~
[php]
Expand Down
5 changes: 4 additions & 1 deletion docs/guide/database.arr.txt
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ $author=$post->author;
corresponding property could be either null or an empty array. For
`BELONGS_TO` and `HAS_ONE` relationships, the result is null; for
`HAS_MANY` and `MANY_MANY`, it is an empty array.
Note that the `HAS_MANY` and `MANY_MANY` relationships return arrays of objects,
you will need to loop through the results before trying to access any properties.
Otherwise, you may receive "Trying to get property of non-object" errors.

The lazy loading approach is very convenient to use, but it is not
efficient in some scenarios. For example, if we want to access the author
Expand Down Expand Up @@ -318,7 +321,7 @@ class User extends CActiveRecord
public function relations()
{
return array(
'posts'=>array(self::HAS_MANY, 'Post', 'authorID'
'posts'=>array(self::HAS_MANY, 'Post', 'authorID',
'order'=>'??.createTime DESC',
'with'=>'categories'),
'profile'=>array(self::HAS_ONE, 'Profile', 'ownerID'),
Expand Down
2 changes: 1 addition & 1 deletion docs/guide/database.dao.txt
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ try
//.... other SQL executions
$transaction->commit();
}
catch(Exception $e) // an exception is raised if a query fails will be raised
catch(Exception $e) // an exception is raised if a query fails
{
$transaction->rollBack();
}
Expand Down
4 changes: 2 additions & 2 deletions docs/guide/quickstart.first-app.txt
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ If you have a 'db' database connection, you can test it now with:
>> crud User
generate UserController.php
generate create.php
mkdir D:/wwwroot/testdrive/protected/views/user
mkdir D:/wwwroot/testdrive/protected/views/user
generate update.php
generate list.php
generate show.php
Expand All @@ -190,7 +190,7 @@ http://hostname/path/to/index.php?r=user
In the above, we use the `yiic shell` command to interact with our
skeleton application. At the prompt, we execute two sub-commands: `model User`
and `crud User`. The former generates a model class for the `User` table,
while the latter reads the `User` model and generates the code needed
while the latter reads the `User` model and generates the code implementing
the CRUD operations.

> Note: You may encounter errors like "...could not find driver", even
Expand Down
2 changes: 1 addition & 1 deletion framework/YiiBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ public static function t($category,$message,$params=array(),$source=null,$langua
'CLogger' => '/logging/CLogger.php',
'CProfileLogRoute' => '/logging/CProfileLogRoute.php',
'CWebLogRoute' => '/logging/CWebLogRoute.php',
'CDateParser' => '/utils/CDateParser.php',
'CDateTimeParser' => '/utils/CDateTimeParser.php',
'CFileHelper' => '/utils/CFileHelper.php',
'CMarkdownParser' => '/utils/CMarkdownParser.php',
'CPropertyValue' => '/utils/CPropertyValue.php',
Expand Down
3 changes: 2 additions & 1 deletion framework/base/CComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,9 @@ public function detachBehavior($name)
if(isset($this->_m[$name]))
{
$this->_m[$name]->detach($this);
$behavior=$this->_m[$name];
unset($this->_m[$name]);
return $this->_m[$name];
return $behavior;
}
}

Expand Down
11 changes: 10 additions & 1 deletion framework/db/ar/CActiveRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -1987,12 +1987,21 @@ class CActiveRelation extends CBaseActiveRelation
*/
public function mergeWith($criteria)
{
if(isset($criteria['condition']) && $this->on!==$criteria['condition'])
{
if($this->on==='')
$this->on=$criteria['condition'];
else if($criteria['condition']!=='')
$this->on="({$this->on}) AND ({$criteria['condition']})";
}
unset($criteria['condition']);

parent::mergeWith($criteria);

if(isset($criteria['joinType']))
$this->joinType=$criteria['joinType'];

if(isset($criteria['on']) && $this->defaultValue!==$criteria['on'])
if(isset($criteria['on']) && $this->on!==$criteria['on'])
{
if($this->on==='')
$this->on=$criteria['on'];
Expand Down
18 changes: 12 additions & 6 deletions framework/db/schema/CDbCommandBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ public function createInsertCommand($table,$data)
$fields=array();
$values=array();
$placeholders=array();
$i=0;
foreach($data as $name=>$value)
{
if(($column=$table->getColumn($name))!==null && ($value!==null || $column->allowNull))
Expand All @@ -137,8 +138,9 @@ public function createInsertCommand($table,$data)
$placeholders[]=(string)$value;
else
{
$placeholders[]=':'.$name;
$values[':'.$name]=$column->typecast($value);
$placeholders[]=':_p'.$i;
$values[':_p'.$i]=$column->typecast($value);
$i++;
}
}
}
Expand All @@ -164,6 +166,7 @@ public function createUpdateCommand($table,$data,$criteria)
$fields=array();
$values=array();
$bindByPosition=isset($criteria->params[0]);
$i=0;
foreach($data as $name=>$value)
{
if(($column=$table->getColumn($name))!==null)
Expand All @@ -177,8 +180,9 @@ public function createUpdateCommand($table,$data,$criteria)
}
else
{
$fields[]=$column->rawName.'=:'.$name;
$values[':'.$name]=$column->typecast($value);
$fields[]=$column->rawName.'=:_p'.$i;
$values[':_p'.$i]=$column->typecast($value);
$i++;
}
}
}
Expand Down Expand Up @@ -453,6 +457,7 @@ public function createColumnCriteria($table,$columns,$condition='',$params=array
$bindByPosition=isset($criteria->params[0]);
$conditions=array();
$values=array();
$i=0;
foreach($columns as $name=>$value)
{
if(($column=$table->getColumn($name))!==null)
Expand All @@ -466,8 +471,9 @@ public function createColumnCriteria($table,$columns,$condition='',$params=array
}
else
{
$conditions[]=$table->rawName.'.'.$column->rawName.'=:'.$name;
$values[':'.$name]=$value;
$conditions[]=$table->rawName.'.'.$column->rawName.'=:_p'.$i;
$values[':_p'.$i]=$value;
$i++;
}
}
else
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
<?php
/**
* CDateParser class file
* CDateTimeParser class file
*
* @author Wei Zhuo <weizhuo[at]gamil[dot]com>
* @author Qiang Xue <qiang.xue@gmail.com>
* @author Tomasz Suchanek <tomasz[dot]suchanek[at]gmail[dot]com>
* @link http://www.yiiframework.com/
* @copyright Copyright &copy; 2008-2009 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/

/**
* CDateParser converts a date string to a UNIX timestamp according to the specified pattern.
* CDateTimeParser converts a date/time string to a UNIX timestamp according to the specified pattern.
*
* The following pattern characters are recognized:
* <pre>
Expand All @@ -22,13 +23,19 @@
* MM | Month digit 01 to 12, zero leading
* yy | 2 year digit, e.g., 96, 05
* yyyy | 4 year digit, e.g., 2005
* h | Hour in 0 to 23, no padding (since version 1.0.5)
* hh | Hour in 00 to 23, zero leading (since version 1.0.5)
* m | Minutes in 0 to 59, no padding (since version 1.0.5)
* mm | Minutes in 00 to 59, zero leading (since version 1.0.5)
* s | Seconds in 0 to 59, no padding (since version 1.0.5)
* ss | Seconds in 00 to 59, zero leading (since version 1.0.5)
* ----------------------------------------------------
* </pre>
* All other characters must appear in the date string at the corresponding positions.
*
* For example, to parse a date string '21/10/2008', use the following:
* <pre>
* $timestamp=CDateParser::parse('21/10/2008','dd/MM/yyyy');
* $timestamp=CDateTimeParser::parse('21/10/2008','dd/MM/yyyy');
* </pre>
*
* To format a timestamp to a date string, please use {@link CDateFormatter}.
Expand All @@ -39,7 +46,7 @@
* @package system.utils
* @since 1.0
*/
class CDateParser
class CDateTimeParser
{
/**
* Converts a date string to a timestamp.
Expand Down Expand Up @@ -98,6 +105,48 @@ public static function parse($value,$pattern='MM/dd/yyyy')
$i+=strlen($day);
break;
}
case 'h':
{
if(($hour=self::parseInteger($value,$i,1,2))===false)
return false;
$i+=strlen($hour);
break;
}
case 'hh':
{
if(($hour=self::parseInteger($value,$i,2,2))===false)
return false;
$i+=2;
break;
}
case 'm':
{
if(($minute=self::parseInteger($value,$i,1,2))===false)
return false;
$i+=strlen($minute);
break;
}
case 'mm':
{
if(($minute=self::parseInteger($value,$i,2,2))===false)
return false;
$i+=2;
break;
}
case 's':
{
if(($second=self::parseInteger($value,$i,1,2))===false)
return false;
$i+=strlen($seconds);
break;
}
case 'ss':
{
if(($second=self::parseInteger($value,$i,2,2))===false)
return false;
$i+=2;
break;
}
default:
{
$tn=strlen($token);
Expand Down Expand Up @@ -129,8 +178,23 @@ public static function parse($value,$pattern='MM/dd/yyyy')
$month=(int)$month;
$day=(int)$day;

if(CTimestamp::isValidDate($year,$month,$day))
return CTimestamp::getTimestamp(0,0,0,$month,$day,$year);
if(!isset($hour) && !isset($minute) && !isset($second))
$hour=$minute=$second=0;
else
{
if(!isset($hour))
$hour=date('H');
if(!isset($minute))
$minute=date('i');
if(!isset($second))
$second=date('s');
$hour=(int)$hour;
$minute=(int)$minute;
$second=(int)$second;
}

if(CTimestamp::isValidDate($year,$month,$day) && CTimestamp::isValidTime($hour,$minute,$second))
return CTimestamp::getTimestamp($hour,$minute,$second,$month,$day,$year);
else
return false;
}
Expand Down
17 changes: 17 additions & 0 deletions framework/utils/CTimestamp.php
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,23 @@ public static function isValidDate($y,$m,$d)
return true;
}

/**
* Checks to see if the hour, minute and second are valid.
* @param integer hour
* @param integer minute
* @param integer second
* @param boolean whether the hours should be 0 through 23 (default) or 1 through 12.
* @return boolean true if valid date, semantic check only.
* @since 1.0.5
*/
public static function isValidTime($h,$m,$s,$hs24=true)
{
if($hs24 && ($h < 0 || $h > 23) || !$hs24 && ($h < 1 || $h > 12)) return false;
if($m > 59 || $m < 0) return false;
if($s > 59 || $s < 0) return false;
return true;
}

/**
* Formats a timestamp to a date string.
* @param string format pattern
Expand Down
Loading

0 comments on commit c7a9962

Please sign in to comment.