| 1 |
lars |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* TScaffoldInputBase class file.
|
|
|
4 |
*
|
|
|
5 |
* @link http://www.pradosoft.com/
|
|
|
6 |
* @copyright Copyright © 2005-2008 PradoSoft
|
|
|
7 |
* @license http://www.pradosoft.com/license/
|
|
|
8 |
* @package System.Data.ActiveReecord.Scaffold.InputBuilder
|
|
|
9 |
*/
|
|
|
10 |
class TScaffoldInputBase
|
|
|
11 |
{
|
|
|
12 |
const DEFAULT_ID = 'scaffold_input';
|
|
|
13 |
private $_parent;
|
|
|
14 |
|
|
|
15 |
protected function getParent()
|
|
|
16 |
{
|
|
|
17 |
return $this->_parent;
|
|
|
18 |
}
|
|
|
19 |
|
|
|
20 |
public static function createInputBuilder($record)
|
|
|
21 |
{
|
|
|
22 |
$record->getDbConnection()->setActive(true); //must be connected before retrieving driver name!
|
|
|
23 |
$driver = $record->getDbConnection()->getDriverName();
|
|
|
24 |
switch(strtolower($driver))
|
|
|
25 |
{
|
|
|
26 |
case 'sqlite': //sqlite 3
|
|
|
27 |
case 'sqlite2': //sqlite 2
|
|
|
28 |
require_once(dirname(__FILE__).'/TSqliteScaffoldInput.php');
|
|
|
29 |
return new TSqliteScaffoldInput($conn);
|
|
|
30 |
case 'mysqli':
|
|
|
31 |
case 'mysql':
|
|
|
32 |
require_once(dirname(__FILE__).'/TMysqlScaffoldInput.php');
|
|
|
33 |
return new TMysqlScaffoldInput($conn);
|
|
|
34 |
case 'pgsql':
|
|
|
35 |
require_once(dirname(__FILE__).'/TPgsqlScaffoldInput.php');
|
|
|
36 |
return new TPgsqlScaffoldInput($conn);
|
|
|
37 |
case 'mssql':
|
|
|
38 |
require_once(dirname(__FILE__).'/TMssqlScaffoldInput.php');
|
|
|
39 |
return new TMssqlScaffoldInput($conn);
|
|
|
40 |
case 'ibm':
|
|
|
41 |
require_once(dirname(__FILE__).'/TIbmScaffoldInput.php');
|
|
|
42 |
return new TIbmScaffoldInput($conn);
|
|
|
43 |
default:
|
|
|
44 |
throw new TConfigurationException(
|
|
|
45 |
'scaffold_invalid_database_driver',$driver);
|
|
|
46 |
}
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
public function createScaffoldInput($parent, $item, $column, $record)
|
|
|
50 |
{
|
|
|
51 |
$this->_parent=$parent;
|
|
|
52 |
$item->setCustomData($column->getColumnId());
|
|
|
53 |
$this->createControl($item->_input, $column, $record);
|
|
|
54 |
if($item->_input->findControl(self::DEFAULT_ID))
|
|
|
55 |
$this->createControlLabel($item->_label, $column, $record);
|
|
|
56 |
}
|
|
|
57 |
|
|
|
58 |
protected function createControlLabel($label, $column, $record)
|
|
|
59 |
{
|
|
|
60 |
$fieldname = ucwords(str_replace('_', ' ', $column->getColumnId())).':';
|
|
|
61 |
$label->setText($fieldname);
|
|
|
62 |
$label->setForControl(self::DEFAULT_ID);
|
|
|
63 |
}
|
|
|
64 |
|
|
|
65 |
public function loadScaffoldInput($parent, $item, $column, $record)
|
|
|
66 |
{
|
|
|
67 |
$this->_parent=$parent;
|
|
|
68 |
if($this->getIsEnabled($column, $record))
|
|
|
69 |
{
|
|
|
70 |
$prop = $column->getColumnId();
|
|
|
71 |
$record->setColumnValue($prop, $this->getControlValue($item->_input, $column, $record));
|
|
|
72 |
}
|
|
|
73 |
}
|
|
|
74 |
|
|
|
75 |
protected function getIsEnabled($column, $record)
|
|
|
76 |
{
|
|
|
77 |
return !($this->getParent()->getRecordPk() !== null
|
|
|
78 |
&& $column->getIsPrimaryKey() || $column->hasSequence());
|
|
|
79 |
}
|
|
|
80 |
|
|
|
81 |
protected function getRecordPropertyValue($column, $record)
|
|
|
82 |
{
|
|
|
83 |
$value = $record->getColumnValue($column->getColumnId());
|
|
|
84 |
if($column->getDefaultValue()!==TDbTableColumn::UNDEFINED_VALUE && $value===null)
|
|
|
85 |
return $column->getDefaultValue();
|
|
|
86 |
else
|
|
|
87 |
return $value;
|
|
|
88 |
}
|
|
|
89 |
|
|
|
90 |
protected function setRecordPropertyValue($item, $record, $input)
|
|
|
91 |
{
|
|
|
92 |
$record->setColumnValue($item->getCustomData(), $input->getText());
|
|
|
93 |
}
|
|
|
94 |
|
|
|
95 |
protected function createControl($container, $column, $record)
|
|
|
96 |
{
|
|
|
97 |
}
|
|
|
98 |
|
|
|
99 |
protected function getControlValue($container, $column, $record)
|
|
|
100 |
{
|
|
|
101 |
}
|
|
|
102 |
}
|
|
|
103 |
|