diff options
author | Daniel <darthdaniel85@gmail.com> | 2014-10-19 16:24:04 -0500 |
---|---|---|
committer | Daniel <darthdaniel85@gmail.com> | 2014-10-19 16:24:04 -0500 |
commit | 290ccc3735eaee72819a2ad6d6a2f77a60a74dd8 (patch) | |
tree | 9391725edd99a75b83c9038d2c698bbf13431ff1 /framework | |
parent | 2cb8ef91c8c2436ed5bdfd40ed7ea3015f76010d (diff) |
function tryToUpdateView 1st version completed.
Diffstat (limited to 'framework')
-rw-r--r-- | framework/Web/UI/TPage.php | 62 |
1 files changed, 56 insertions, 6 deletions
diff --git a/framework/Web/UI/TPage.php b/framework/Web/UI/TPage.php index e9fd8141..82e1f0ae 100644 --- a/framework/Web/UI/TPage.php +++ b/framework/Web/UI/TPage.php @@ -1215,19 +1215,69 @@ class TPage extends TTemplateControl /**
* Function to update view controls with those data in a given AR object.
- * @param type $arObj
- * TODO
+ * @param TActiveRecord $arObj
+ * @author Daniel Sampedro <darthdaniel85@gmail.com>
*/
- public function tryUpdateView($arObj)
+ public function tryToUpdateView($arObj, $throwExceptions = false)
{
-
+ $objAttrs = get_class_vars(get_class($arObj));
+ foreach (array_keys($objAttrs) as $key)
+ {
+ try
+ {
+ if ($key != "RELATIONS")
+ {
+ $control = $this->{$key};
+ switch (get_class($control))
+ {
+ default:
+ case "TTextBox":
+ $control->Text = $arObj->{$key};
+ break;
+ case "TCheckBox":
+ $control->Checked = (boolean) $arObj->{$key};
+ break;
+ case "TDatePicker":
+ $control->Date = $arObj->{$key};
+ break;
+ }
+ } else
+ {
+ foreach ($objAttrs["RELATIONS"] as $relKey => $relValues)
+ {
+ $relControl = $this->{$relKey};
+ switch ($relValues[0])
+ {
+ case TActiveRecord::BELONGS_TO:
+ case TActiveRecord::HAS_ONE:
+ $relControl->Text = $arObj->{$relKey};
+ break;
+ case TActiveRecord::HAS_MANY:
+ if($relControl instanceof TListControl){
+ $relControl->DataSource = $arObj->{$relKey};
+ $relControl->dataBind();
+ }
+ break;
+ }
+ }
+ break;
+ }
+ } catch (Exception $ex)
+ {
+ if ($throwExceptions)
+ {
+ throw $ex;
+ }
+ }
+ }
}
/**
* Function to try to update an AR object with data in view controls.
- * @param type $arObj
+ * @param TActiveRecord $arObj
+ * @author Daniel Sampedro <darthdaniel85@gmail.com>
*/
- public function tryUpdateAR($arObj)
+ public function tryToUpdateAR($arObj)
{
}
|