summaryrefslogtreecommitdiff
path: root/framework/Data/ActiveRecord/Scaffold/InputBuilder/TMysqlScaffoldInput.php
blob: 74eddbd80c9ad2b1a120a9b76ce5f4c984bdee9d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
/**
 * TMysqlScaffoldInput class file.
 *
 * @link http://www.pradosoft.com/
 * @copyright Copyright &copy; 2005-2013 PradoSoft
 * @license http://www.pradosoft.com/license/
 * @package System.Data.ActiveRecord.Scaffold.InputBuilder
 */
Prado::using('System.Data.ActiveRecord.Scaffold.InputBuilder.TScaffoldInputCommon');

class TMysqlScaffoldInput extends TScaffoldInputCommon
{
	protected function createControl($container, $column, $record)
	{
		$dbtype = trim(str_replace(array('unsigned', 'zerofill'),array('','',),strtolower($column->getDbType())));
		switch($dbtype)
		{
			case 'date':
				return $this->createDateControl($container, $column, $record);
			case 'blob': case 'tinyblob': case 'mediumblob': case 'longblob':
			case 'text': case 'tinytext': case 'mediumtext': case 'longtext':
				return $this->createMultiLineControl($container, $column, $record);
			case 'year':
				return $this->createYearControl($container, $column, $record);
			case 'int': case 'integer': case 'tinyint': case 'smallint': case 'mediumint': case 'bigint':
				return $this->createIntegerControl($container, $column, $record);
			case 'decimal': case 'double': case 'float':
				return $this->createFloatControl($container, $column, $record);
			case 'time' :
				return $this->createTimeControl($container, $column, $record);
			case 'datetime': case 'timestamp':
				return $this->createDateTimeControl($container, $column, $record);
			case 'set':
				return $this->createSetControl($container, $column, $record);
			case 'enum':
				return $this->createEnumControl($container, $column, $record);
			default:
				return $this->createDefaultControl($container, $column, $record);
		}
	}

	protected function getControlValue($container, $column, $record)
	{
		$dbtype = trim(str_replace(array('unsigned', 'zerofill'),array('','',),strtolower($column->getDbType())));
		switch($dbtype)
		{
			case 'date':
				return $container->findControl(self::DEFAULT_ID)->getDate();
			case 'year':
				return $container->findControl(self::DEFAULT_ID)->getSelectedValue();
			case 'time':
				return $this->getTimeValue($container, $column, $record);
			case 'datetime': case 'timestamp':
				return $this->getDateTimeValue($container,$column, $record);
			case 'tinyint':
				return $this->getIntBooleanValue($container,$column, $record);
			case 'set':
				return $this->getSetValue($container, $column, $record);
			case 'enum':
				return $this->getEnumValue($container, $column, $record);
			default:
				return $this->getDefaultControlValue($container,$column, $record);
		}
	}

	protected function createIntegerControl($container, $column, $record)
	{
		if($column->getColumnSize()==1)
			return $this->createBooleanControl($container, $column, $record);
		else
			parent::createIntegerControl($container, $column, $record);
	}

	protected function getIntBooleanValue($container,$column, $record)
	{
		if($column->getColumnSize()==1)
			return (int)$container->findControl(self::DEFAULT_ID)->getChecked();
		else
			return $this->getDefaultControlValue($container,$column, $record);
	}
}