Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* CDateTimeBehavior: added scenarios
* CDateTimeBehavior: added getDateTimeAttr * CDateTimeBehavior: refactoring * CDateTimeBehavior: added readme.md and readme_ru.md
- Loading branch information
Showing
6 changed files
with
307 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
protected/extensions/yiicomp/behaviors/DateTimeBehavior/readme.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
CDateTimeBehavior | ||
================= | ||
|
||
`CDateTimeBehavior` - flexible behavior, that automatically converts date attribute values | ||
into specified formats between the client and database. | ||
|
||
Installation | ||
------------ | ||
|
||
1. Copy DateTimeBehavior directory to Yii `components` directory | ||
|
||
2. Add an import path | ||
|
||
~~~php | ||
'import'=>array( | ||
|
||
... | ||
|
||
'application.components.DateTimeBehavior.CDateTimeBehavior', | ||
|
||
... | ||
|
||
) | ||
~~~ | ||
|
||
3. Attach the behavior to your model | ||
|
||
~~~php | ||
public function behaviors() | ||
{ | ||
return array( | ||
'dateTimeBehavior' => array( | ||
'class'=>'CDateTimeBehavior', | ||
'attributes'=>'date_of_birth, passport_expiration', | ||
), | ||
); | ||
} | ||
~~~ | ||
|
||
Date/time format patterns | ||
------------------------- | ||
|
||
Please see http://www.unicode.org/reports/tr35/#Date_Format_Patterns for details | ||
about the recognized pattern characters. | ||
|
||
Properties | ||
---------- | ||
|
||
`dbFormat` - default DB format for each processed attribute. Default value is `yyyy-MM-dd`. | ||
|
||
`clientFormat` - default client format for each processed attribute. Default value is `dd.MM.yyyy`. | ||
|
||
`attributes` - which attributes should be processed, their formats etc. (please see samples below) | ||
|
||
Methods | ||
------- | ||
|
||
~~~php | ||
public function getDateTimeAttr($attribute, $format=false); | ||
~~~ | ||
|
||
Retrieves date/time attribute value in unmodified or in specified in the second parameter format. | ||
If an attribute is not processed by behavior, than model unmodified attribute value is | ||
returned (the second method parameter is ignored). | ||
|
||
`$attribute` - name of an attribute | ||
|
||
`$format` - date/time format, in which attribute value will be returned. Function returns unmodified | ||
attribute value if this attribute is unspecified or equal to `false`. | ||
|
||
|
||
Usage samples | ||
------------- | ||
|
||
Simple usage: | ||
|
||
~~~php | ||
'dateTimeBehavior' => array( | ||
'class'=>'CDateTimeBehavior', | ||
'attributes'=>'date_of_birth, passport_expiration', | ||
), | ||
~~~ | ||
|
||
In the above sample behavior converts attributes with default date formats. | ||
|
||
You can change default formats: | ||
|
||
~~~php | ||
'dateTimeBehavior' => array( | ||
'class'=>'CDateTimeBehavior', | ||
'dbFormat'=>'dd-MM-yyyy', | ||
'clientFormat'=>'MM/dd/yyyy', | ||
'attributes'=>'date_of_birth, passport_expiration', | ||
), | ||
~~~ | ||
|
||
Advanced sample: | ||
|
||
~~~php | ||
'dateTimeBehavior' => array( | ||
'class'=>'CDateTimeBehavior', | ||
'attributes' => array( | ||
'date_start, date_end', //default formats | ||
|
||
//Attribute with formats, that differ from default ones | ||
array( | ||
'date_created', | ||
'dbFormat' => 'yyyy-MM-dd HH:mm:ss', | ||
'clientFormat' => 'dd.MM.yyyy HH:mm:ss' | ||
), | ||
|
||
array( | ||
'date_scenario', | ||
'dbFormat' => 'yyyy-MM-dd', | ||
'clientFormat' => 'dd.MM.yyyy' | ||
'on'=>'scenario1, scenario2', //scenarios can be specified | ||
), | ||
|
||
array( | ||
'date_scenario', | ||
'dbFormat' => 'dd-MM-yyyy', | ||
'clientFormat' => 'MM/dd/yyyy' | ||
'on'=>'scenario3', //scenarios can be specified | ||
), | ||
), | ||
), | ||
~~~ |
127 changes: 127 additions & 0 deletions
127
protected/extensions/yiicomp/behaviors/DateTimeBehavior/readme_ru.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
CDateTimeBehavior | ||
================= | ||
|
||
`CDateTimeBehavior` - гибко настраиваемое поведение, позволяющее конвертировать | ||
форматы дат/времени между базой и клиентом. | ||
|
||
Installation | ||
------------ | ||
|
||
1. Скопируйте директорию DateTimeBehavior в директорию `components` | ||
|
||
2. Добавьте импорт | ||
|
||
~~~php | ||
'import'=>array( | ||
|
||
... | ||
|
||
'application.components.DateTimeBehavior.CDateTimeBehavior', | ||
|
||
... | ||
|
||
) | ||
~~~ | ||
|
||
3. Привяжите поведение к модели | ||
|
||
~~~php | ||
public function behaviors() | ||
{ | ||
return array( | ||
'dateTimeBehavior' => array( | ||
'class'=>'CDateTimeBehavior', | ||
'attributes'=>'date_of_birth, passport_expiration', | ||
), | ||
); | ||
} | ||
~~~ | ||
|
||
Паттерны даты/времени | ||
--------------------- | ||
|
||
Пожалуйста, смотрите по нижеследующей ссылке возможные значения паттернов | ||
http://www.unicode.org/reports/tr35/#Date_Format_Patterns | ||
|
||
Свойства | ||
-------- | ||
|
||
`dbFormat` - формат дат в БД по умолчанию для всех атрибутов. Значение по умолчанию равно `yyyy-MM-dd`. | ||
|
||
`clientFormat` - формат дат клиента по умолчанию для всех атрибутов. Значение по умолчанию равно `dd.MM.yyyy`. | ||
|
||
`attributes` - какие атрибуты должны обрабатываться, их значения и т.п. (см. примеры ниже) | ||
|
||
Методы | ||
------ | ||
|
||
~~~php | ||
public function getDateTimeAttr($attribute, $format=false); | ||
~~~ | ||
|
||
Получает значение даты/времени не модифицированным или в указанном во втором параметре формате. | ||
Если атрибут не обрабатывается поведением, то будет возвращено не модифицированное | ||
значение атрибута модели (второй параметр в таком случае игнорируется). | ||
|
||
`$attribute` - название атрибута | ||
|
||
`$format` - формат, в котором будет возвращена дата/время. Если параметр не указан | ||
или его значение равно `false`, будет возвращено не модифицированное значение. | ||
|
||
|
||
Примеры использования | ||
--------------------- | ||
|
||
Простое использование: | ||
|
||
~~~php | ||
'dateTimeBehavior' => array( | ||
'class'=>'CDateTimeBehavior', | ||
'attributes'=>'date_of_birth, passport_expiration', | ||
), | ||
~~~ | ||
|
||
В примере выше атрибуты будут конвертированы в форматы по умолчанию. | ||
|
||
Можно изменить форматы по умолчанию: | ||
|
||
~~~php | ||
'dateTimeBehavior' => array( | ||
'class'=>'CDateTimeBehavior', | ||
'dbFormat'=>'dd-MM-yyyy', | ||
'clientFormat'=>'MM/dd/yyyy', | ||
'attributes'=>'date_of_birth, passport_expiration', | ||
), | ||
~~~ | ||
|
||
Сложный пример: | ||
|
||
~~~php | ||
'dateTimeBehavior' => array( | ||
'class'=>'CDateTimeBehavior', | ||
'attributes' => array( | ||
'date_start, date_end', //в форматах по умолчанию | ||
|
||
//Атрибут с форматами отличными от форматов по умолчанию | ||
array( | ||
'date_created', | ||
'dbFormat' => 'yyyy-MM-dd HH:mm:ss', | ||
'clientFormat' => 'dd.MM.yyyy HH:mm:ss' | ||
), | ||
|
||
array( | ||
'date_scenario', | ||
'dbFormat' => 'yyyy-MM-dd', | ||
'clientFormat' => 'dd.MM.yyyy' | ||
'on'=>'scenario1, scenario2', //можно указывать сценарии | ||
), | ||
|
||
array( | ||
'date_scenario', | ||
'dbFormat' => 'dd-MM-yyyy', | ||
'clientFormat' => 'MM/dd/yyyy' | ||
'on'=>'scenario3', //можно указывать сценарии | ||
), | ||
), | ||
), | ||
~~~ |
2 changes: 1 addition & 1 deletion
2
protected/extensions/yiicomp/components/ButtonColumnEx/readme.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
protected/extensions/yiicomp/components/ButtonColumnEx/readme_ru.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters