Browse Source

cleanup.

tags/2.0.0-beta
Qiang Xue 12 years ago
parent
commit
0e8e94bcb9
  1. 2
      build/controllers/LocaleController.php
  2. 20
      framework/i18n/data/plurals.php
  3. 38
      framework/widgets/ActiveForm.php

2
build/controllers/LocaleController.php

@ -62,7 +62,7 @@ class LocaleController extends Controller
}
$expr = preg_replace('/\\bn\\b/', '$n', implode('||', $expr_or));
$rules[] = preg_replace_callback('/range\((\d+),(\d+)\)/', function ($matches) {
if ($matches[2] - $matches[1] <= 2) {
if ($matches[2] - $matches[1] <= 5) {
return 'array(' . implode(',', range($matches[1], $matches[2])) . ')';
} else {
return $matches[0];

20
framework/i18n/data/plurals.php

@ -494,8 +494,8 @@ return array (
array (
0 => '$n==1',
1 => '$n==2',
2 => 'in_array($n,range(3,6))',
3 => 'in_array($n,range(7,10))',
2 => 'in_array($n,array(3,4,5,6))',
3 => 'in_array($n,array(7,8,9,10))',
),
'ro' =>
array (
@ -516,43 +516,43 @@ return array (
array (
0 => 'fmod($n,10)==1&&fmod($n,100)!=11',
1 => 'in_array(fmod($n,10),array(2,3,4))&&!in_array(fmod($n,100),array(12,13,14))',
2 => 'fmod($n,10)==0||in_array(fmod($n,10),range(5,9))||in_array(fmod($n,100),range(11,14))',
2 => 'fmod($n,10)==0||in_array(fmod($n,10),array(5,6,7,8,9))||in_array(fmod($n,100),array(11,12,13,14))',
),
'bs' =>
array (
0 => 'fmod($n,10)==1&&fmod($n,100)!=11',
1 => 'in_array(fmod($n,10),array(2,3,4))&&!in_array(fmod($n,100),array(12,13,14))',
2 => 'fmod($n,10)==0||in_array(fmod($n,10),range(5,9))||in_array(fmod($n,100),range(11,14))',
2 => 'fmod($n,10)==0||in_array(fmod($n,10),array(5,6,7,8,9))||in_array(fmod($n,100),array(11,12,13,14))',
),
'hr' =>
array (
0 => 'fmod($n,10)==1&&fmod($n,100)!=11',
1 => 'in_array(fmod($n,10),array(2,3,4))&&!in_array(fmod($n,100),array(12,13,14))',
2 => 'fmod($n,10)==0||in_array(fmod($n,10),range(5,9))||in_array(fmod($n,100),range(11,14))',
2 => 'fmod($n,10)==0||in_array(fmod($n,10),array(5,6,7,8,9))||in_array(fmod($n,100),array(11,12,13,14))',
),
'ru' =>
array (
0 => 'fmod($n,10)==1&&fmod($n,100)!=11',
1 => 'in_array(fmod($n,10),array(2,3,4))&&!in_array(fmod($n,100),array(12,13,14))',
2 => 'fmod($n,10)==0||in_array(fmod($n,10),range(5,9))||in_array(fmod($n,100),range(11,14))',
2 => 'fmod($n,10)==0||in_array(fmod($n,10),array(5,6,7,8,9))||in_array(fmod($n,100),array(11,12,13,14))',
),
'sh' =>
array (
0 => 'fmod($n,10)==1&&fmod($n,100)!=11',
1 => 'in_array(fmod($n,10),array(2,3,4))&&!in_array(fmod($n,100),array(12,13,14))',
2 => 'fmod($n,10)==0||in_array(fmod($n,10),range(5,9))||in_array(fmod($n,100),range(11,14))',
2 => 'fmod($n,10)==0||in_array(fmod($n,10),array(5,6,7,8,9))||in_array(fmod($n,100),array(11,12,13,14))',
),
'sr' =>
array (
0 => 'fmod($n,10)==1&&fmod($n,100)!=11',
1 => 'in_array(fmod($n,10),array(2,3,4))&&!in_array(fmod($n,100),array(12,13,14))',
2 => 'fmod($n,10)==0||in_array(fmod($n,10),range(5,9))||in_array(fmod($n,100),range(11,14))',
2 => 'fmod($n,10)==0||in_array(fmod($n,10),array(5,6,7,8,9))||in_array(fmod($n,100),array(11,12,13,14))',
),
'uk' =>
array (
0 => 'fmod($n,10)==1&&fmod($n,100)!=11',
1 => 'in_array(fmod($n,10),array(2,3,4))&&!in_array(fmod($n,100),array(12,13,14))',
2 => 'fmod($n,10)==0||in_array(fmod($n,10),range(5,9))||in_array(fmod($n,100),range(11,14))',
2 => 'fmod($n,10)==0||in_array(fmod($n,10),array(5,6,7,8,9))||in_array(fmod($n,100),array(11,12,13,14))',
),
'cs' =>
array (
@ -568,7 +568,7 @@ return array (
array (
0 => '$n==1',
1 => 'in_array(fmod($n,10),array(2,3,4))&&!in_array(fmod($n,100),array(12,13,14))',
2 => '$n!=1&&in_array(fmod($n,10),array(0,1))||in_array(fmod($n,10),range(5,9))||in_array(fmod($n,100),array(12,13,14))',
2 => '$n!=1&&in_array(fmod($n,10),array(0,1))||in_array(fmod($n,10),array(5,6,7,8,9))||in_array(fmod($n,100),array(12,13,14))',
),
'sl' =>
array (

38
framework/widgets/ActiveForm.php

@ -110,8 +110,7 @@ class ActiveForm extends Widget
*/
public function error($model, $attribute, $options = array())
{
$attribute = $this->normalizeAttributeName($attribute);
$this->getInputName($model, $attribute);
$attribute = $this->getAttributeName($attribute);
$tag = isset($options['tag']) ? $options['tag'] : 'div';
unset($options['tag']);
$error = $model->getFirstError($attribute);
@ -126,15 +125,19 @@ class ActiveForm extends Widget
*/
public function label($model, $attribute, $options = array())
{
$attribute = $this->normalizeAttributeName($attribute);
$label = $model->getAttributeLabel($attribute);
return Html::label(Html::encode($label), isset($options['for']) ? $options['for'] : null, $options);
$attribute = $this->getAttributeName($attribute);
$label = isset($options['label']) ? $options['label'] : Html::encode($model->getAttributeLabel($attribute));
$for = array_key_exists('for', $options) ? $options['for'] : $this->getInputId($model, $attribute);
return Html::label($label, $for, $options);
}
public function input($type, $model, $attribute, $options = array())
{
$value = $this->getAttributeValue($model, $attribute);
$name = $this->getInputName($model, $attribute);
if (!array_key_exists('id', $options)) {
$options['id'] = $this->getInputId($model, $attribute);
}
return Html::input($type, $name, $value, $options);
}
@ -162,6 +165,9 @@ class ActiveForm extends Widget
{
$value = $this->getAttributeValue($model, $attribute);
$name = $this->getInputName($model, $attribute);
if (!array_key_exists('id', $options)) {
$options['id'] = $this->getInputId($model, $attribute);
}
return Html::textarea($name, $value, $options);
}
@ -172,6 +178,9 @@ class ActiveForm extends Widget
if (!array_key_exists('uncheck', $options)) {
$options['unchecked'] = '0';
}
if (!array_key_exists('id', $options)) {
$options['id'] = $this->getInputId($model, $attribute);
}
return Html::radio($name, $checked, $value, $options);
}
@ -182,6 +191,9 @@ class ActiveForm extends Widget
if (!array_key_exists('uncheck', $options)) {
$options['unchecked'] = '0';
}
if (!array_key_exists('id', $options)) {
$options['id'] = $this->getInputId($model, $attribute);
}
return Html::checkbox($name, $checked, $value, $options);
}
@ -189,6 +201,9 @@ class ActiveForm extends Widget
{
$checked = $this->getAttributeValue($model, $attribute);
$name = $this->getInputName($model, $attribute);
if (!array_key_exists('id', $options)) {
$options['id'] = $this->getInputId($model, $attribute);
}
return Html::dropDownList($name, $checked, $items, $options);
}
@ -199,6 +214,9 @@ class ActiveForm extends Widget
if (!array_key_exists('unselect', $options)) {
$options['unselect'] = '0';
}
if (!array_key_exists('id', $options)) {
$options['id'] = $this->getInputId($model, $attribute);
}
return Html::listBox($name, $checked, $items, $options);
}
@ -228,7 +246,7 @@ class ActiveForm extends Widget
if (isset($this->modelMap[$class])) {
$class = $this->modelMap[$class];
} elseif (($pos = strrpos($class, '\\')) !== false) {
$class = substr($class, $pos);
$class = substr($class, $pos + 1);
}
if (!preg_match('/(^|.*\])(\w+)(\[.*|$)/', $attribute, $matches)) {
throw new InvalidParamException('Attribute name must contain word characters only.');
@ -245,6 +263,12 @@ class ActiveForm extends Widget
}
}
public function getInputId($model, $attribute)
{
$name = $this->getInputName($model, $attribute);
return str_replace(array('[]', '][', '[', ']', ' '), array('', '-', '-', '', '-'), $name);
}
public function getAttributeValue($model, $attribute)
{
if (!preg_match('/(^|.*\])(\w+)(\[.*|$)/', $attribute, $matches)) {
@ -267,7 +291,7 @@ class ActiveForm extends Widget
}
}
public function normalizeAttributeName($attribute)
public function getAttributeName($attribute)
{
if (preg_match('/(^|.*\])(\w+)(\[.*|$)/', $attribute, $matches)) {
return $matches[2];

Loading…
Cancel
Save