Esempio n. 1
0
 /**
  * Return default input field type based on column schema for attribute
  * @param string $attributeName
  * @param \yii\db\ColumnSchema $columnSchema
  * @param array|null $config attributeConfig (active element)
  * @return string
  */
 public static function getDefaultInputFieldType($attributeName, $columnSchema, $config = null)
 {
     if (is_array($config) && $config) {
         $type = ArrayHelper::getValue($config, 'type', '');
         if ($type != '') {
             return $type;
         }
     }
     switch ($attributeName) {
         case 'id':
             $type = self::INPUT_STATIC;
             break;
         case 'created_at':
         case 'createdAt':
         case 'modified_at':
         case 'modifiedAt':
             $type = self::INPUT_STATIC;
             break;
         default:
             switch ($columnSchema->type) {
                 case 'string':
                     // case 'char':
                     // case 'varchar':
                     if (is_array($columnSchema->enumValues) && $columnSchema->enumValues) {
                         $type = self::INPUT_DROPDOWN_LIST;
                     } else {
                         $type = self::INPUT_TEXT;
                     }
                     break;
                 case 'text':
                     //case 'tinytext':
                     //case 'mediumtext':
                     //case 'longtext':
                 //case 'tinytext':
                 //case 'mediumtext':
                 //case 'longtext':
                 case 'binary':
                     //case 'varbinary':
                     //case 'blob':
                     //case 'tinyblob':
                     //case 'mediumblob':
                     //case 'longblob':
                     $type = self::INPUT_TEXTAREA;
                     break;
                 case 'int':
                 case 'integer':
                 case 'tinyint':
                 case 'smallint':
                 case 'mediumint':
                 case 'bigint':
                     if ($columnSchema->size == 1) {
                         //$type = self::INPUT_CHECKBOX_SWITCH;
                         $type = self::INPUT_CHECKBOX_ICHECK;
                         //$type = self::INPUT_CHECKBOX;
                     } else {
                         $type = self::INPUT_INTEGER;
                     }
                     break;
                 case 'float':
                 case 'real':
                 case 'double':
                 case 'decimal':
                 case 'numeric':
                     $type = self::INPUT_DECIMAL;
                     break;
                 case 'date':
                     if ($columnSchema->size == 4) {
                         $type = self::INPUT_YEAR;
                     } else {
                         $type = self::INPUT_DATE;
                     }
                     break;
                 case 'datetime':
                     $type = self::INPUT_DATETIME;
                     break;
                 case 'time':
                     $type = self::INPUT_TIME;
                     break;
                 default:
                     \fangface\Tools::debug($columnSchema, __CLASS__);
                     $type = self::INPUT_TEXT;
                     break;
             }
             break;
     }
     return $type;
 }
Esempio n. 2
0
 /**
  * Test debug method does not fail
  */
 public function testDebugDoesNotFail()
 {
     $var = array('a' => 100, 'b' => 200);
     $debug = Tools::debug($var, 'My Label', false);
     $this->assertInternalType('string', $actual);
 }