summaryrefslogtreecommitdiff
path: root/framework/Web
diff options
context:
space:
mode:
authorDaniel <darthdaniel85@gmail.com>2015-01-28 15:59:45 -0500
committerDaniel <darthdaniel85@gmail.com>2015-01-28 15:59:45 -0500
commit68c81d74a593d8e0225078d6982f9b5fe4986d2a (patch)
treed4dd5be2319ec46d14d9eccbe51504fcc56e047e /framework/Web
parent7f22a44867fdf10d2383595e6467923fd11e2b89 (diff)
raising update views-ar functions to TTemplateControl
Diffstat (limited to 'framework/Web')
-rw-r--r--framework/Web/UI/TPage.php84
-rw-r--r--framework/Web/UI/TTemplateControl.php86
2 files changed, 86 insertions, 84 deletions
diff --git a/framework/Web/UI/TPage.php b/framework/Web/UI/TPage.php
index 903711e4..41fd4454 100644
--- a/framework/Web/UI/TPage.php
+++ b/framework/Web/UI/TPage.php
@@ -1212,90 +1212,6 @@ class TPage extends TTemplateControl
if ($this->_writer)
$this->Response->write($this->_writer->flush());
}
-
- /**
- * Function to update view controls with data in a given AR object.
- * View controls and AR object need to have the same name in IDs and Attrs respectively.
- * @param TActiveRecord $arObj
- * @param Boolean $throwExceptions Wheter or not to throw exceptions
- * @author Daniel Sampedro <darthdaniel85@gmail.com>
- */
- 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};
- if ($control instanceof TTextBox)
- $control->Text = $arObj->{$key};
- elseif ($control instanceof TCheckBox)
- $control->Checked = (boolean) $arObj->{$key};
- elseif ($control instanceof TDatePicker)
- $control->Date = $arObj->{$key};
- }
- 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 TActiveRecord $arObj
- * @param Boolean $throwExceptions Wheter or not to throw exceptions
- * @author Daniel Sampedro <darthdaniel85@gmail.com>
- */
- public function tryToUpdateAR($arObj, $throwExceptions = false)
- {
- $objAttrs = get_class_vars(get_class($arObj));
- foreach (array_keys($objAttrs) as $key)
- {
- try
- {
- if ($key == "RELATIONS")
- break;
- $control = $this->{$key};
- if ($control instanceof TTextBox)
- $arObj->{$key} = $control->Text;
- elseif ($control instanceof TCheckBox)
- $arObj->{$key} = $control->Checked;
- elseif ($control instanceof TDatePicker)
- $arObj->{$key} = $control->Date;
- } catch (Exception $ex)
- {
- if ($throwExceptions)
- throw $ex;
- }
- }
- }
}
diff --git a/framework/Web/UI/TTemplateControl.php b/framework/Web/UI/TTemplateControl.php
index df6482c6..3040571e 100644
--- a/framework/Web/UI/TTemplateControl.php
+++ b/framework/Web/UI/TTemplateControl.php
@@ -237,5 +237,91 @@ class TTemplateControl extends TCompositeControl
throw new TConfigurationException('templatecontrol_mastercontrol_required',get_class($this));
parent::initRecursive($namingContainer);
}
+
+ /**
+ * Function to update view controls with data in a given AR object.
+ * View controls and AR object need to have the same name in IDs and Attrs respectively.
+ * @param TActiveRecord $arObj
+ * @param Boolean $throwExceptions Wheter or not to throw exceptions
+ * @author Daniel Sampedro <darthdaniel85@gmail.com>
+ */
+ 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};
+ if ($control instanceof TTextBox)
+ $control->Text = $arObj->{$key};
+ elseif ($control instanceof TCheckBox)
+ $control->Checked = (boolean) $arObj->{$key};
+ elseif ($control instanceof TDatePicker)
+ $control->Date = $arObj->{$key};
+ }
+ 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 TActiveRecord $arObj
+ * @param Boolean $throwExceptions Wheter or not to throw exceptions
+ * @author Daniel Sampedro <darthdaniel85@gmail.com>
+ */
+ public function tryToUpdateAR($arObj, $throwExceptions = false)
+ {
+ $objAttrs = get_class_vars(get_class($arObj));
+ foreach (array_keys($objAttrs) as $key)
+ {
+ try
+ {
+ if ($key == "RELATIONS")
+ break;
+ $control = $this->{$key};
+ if ($control instanceof TTextBox)
+ $arObj->{$key} = $control->Text;
+ elseif ($control instanceof TCheckBox)
+ $arObj->{$key} = $control->Checked;
+ elseif ($control instanceof TDatePicker)
+ $arObj->{$key} = $control->Date;
+ }
+ catch (Exception $ex)
+ {
+ if ($throwExceptions)
+ throw $ex;
+ }
+ }
+ }
}