/**
  * Returns the element or attribute form type
  * that should be used with the named attribute
  * of the given model, (the name minus the Element
  * or AttributeForm suffix).
  */
 public static function getDesignerType(ModelForm $model, $attributeName)
 {
     assert('$model !== null');
     assert('is_string($attributeName) && $attributeName != ""');
     $metadata = $model->getMetadata();
     foreach ($metadata as $className => $perClassMetadata) {
         if (isset($perClassMetadata['elements'][$attributeName])) {
             return $perClassMetadata['elements'][$attributeName];
         }
     }
     $validators = $model->getValidators($attributeName);
     foreach ($validators as $validator) {
         switch (get_class($validator)) {
             case 'CBooleanValidator':
                 return 'CheckBox';
             case 'CEmailValidator':
                 return 'Email';
             case 'RedBeanModelTypeValidator':
             case 'TypeValidator':
                 switch ($validator->type) {
                     case 'date':
                         return 'Date';
                     case 'datetime':
                         return 'DateTime';
                     case 'integer':
                         return 'Integer';
                     case 'float':
                         return 'Decimal';
                     case 'time':
                         return 'Time';
                     case 'array':
                         throw new NotSupportedException();
                 }
                 break;
             case 'CUrlValidator':
                 return 'Url';
         }
     }
     return 'Text';
 }
예제 #2
0
 /**
  * (non-PHPdoc)
  * @see ModelForm::getMetadata()
  */
 public function getMetadata()
 {
     $metadata = parent::getMetadata();
     $dynamicAttributeToElementTypes = static::getDynamicAttributeToElementTypes();
     foreach ($this->dynamicAttributeNames as $attributeName) {
         $delimiter = FormModelUtil::DELIMITER;
         list($realAttributeName, $type) = explode($delimiter, $attributeName);
         assert('$dynamicAttributeToElementTypes[$type] != null');
         $metadata[get_called_class()]['elements'][$attributeName] = $dynamicAttributeToElementTypes[$type];
     }
     foreach ($this->attributeNamesThatCanBeSplitUsingDelimiter as $attributeName) {
         $delimiter = FormModelUtil::DELIMITER;
         list($realAttributeName, $type) = explode($delimiter, $attributeName);
         assert('$dynamicAttributeToElementTypes[$type] != null');
         $metadata[get_called_class()]['elements'][$attributeName] = $dynamicAttributeToElementTypes[$type];
     }
     //add something to resolve for global search....
     $this->resolveMixedSearchAttributeElementForMetadata($metadata[get_called_class()]['elements']);
     return $metadata;
 }