summaryrefslogtreecommitdiff
path: root/framework/Web
diff options
context:
space:
mode:
authorDaniel Sampedro B <darthdaniel85@gmail.com>2014-10-21 09:17:02 -0500
committerDaniel Sampedro B <darthdaniel85@gmail.com>2014-10-21 09:17:02 -0500
commitf3268c5b71fd3bc2732f3a796aabb3b4de5ce1e6 (patch)
treec23c7290763edb921720e2707dbd10205452495c /framework/Web
parent7aced38af5ea73b605fc21f9c84b7430ae53e39a (diff)
parent231ef50435090bfb1dec4093365e01a118d2b0ff (diff)
Merge remote-tracking branch 'origin/wsat'
Diffstat (limited to 'framework/Web')
-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;
+ }
+ }
+ }
+ }
}
/**