summaryrefslogtreecommitdiff
path: root/framework/Web/UI/TPage.php
diff options
context:
space:
mode:
Diffstat (limited to 'framework/Web/UI/TPage.php')
-rw-r--r--framework/Web/UI/TPage.php100
1 files changed, 100 insertions, 0 deletions
diff --git a/framework/Web/UI/TPage.php b/framework/Web/UI/TPage.php
index 2dc1cac3..c633a3be 100644
--- a/framework/Web/UI/TPage.php
+++ b/framework/Web/UI/TPage.php
@@ -1212,6 +1212,106 @@ 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
+ * @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};
+ 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 TActiveRecord $arObj
+ * @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};
+ switch (get_class($control))
+ {
+ default:
+ case "TTextBox":
+ $arObj->{$key} = $control->Text;
+ break;
+ case "TCheckBox":
+ $arObj->{$key} = $control->Checked;
+ break;
+ case "TDatePicker":
+ $arObj->{$key} = $control->Date;
+ break;
+ }
+ } catch (Exception $ex)
+ {
+ if ($throwExceptions)
+ {
+ throw $ex;
+ }
+ }
+ }
+ }
}
/**