From f72b9a7658cea71ee1edf4ae678a2c8043d9e5bf Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Tue, 4 Oct 2011 22:19:45 -0400 Subject: Begin work on safely allowing concurrent edits on data, giving better form interface. --- src/lib/Form.class.php | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/lib/Form.class.php (limited to 'src/lib/Form.class.php') diff --git a/src/lib/Form.class.php b/src/lib/Form.class.php new file mode 100644 index 0000000..725bac5 --- /dev/null +++ b/src/lib/Form.class.php @@ -0,0 +1,57 @@ +getter = $get; + $this->setter = $set; + } + private function getConf($key) { + call_user_func($getter, $key); + } + public function setConf($key, $value) { + call_user_func($setter, $key, $value); + } + private function getConfString($key) { + $raw = $this->getConf($key); + $value = $raw['value']; + if ($value===false) return 'false'; + if ($value===true) return 'true'; + return $value; + } + + public function updateValue($value, $value_base=null) { + $doit = true; + $forked = false; + $have_old = ($value_base!==null); + if ($have_old) { + @$value_base = $old[$uid]; + $we_changed_it = $value_base != $value; + if ($we_changed_it) { + $value_fork = $this->getConfString($key); + $someone_else_changed_it = + $value_fork != $value_base; + if ($someone_else_changed_it) { + if ($value == $value_fork) { + // we might as well not have + $we_changed_it = false; + } else { + $forked = true; + } + } + } + if (!$we_changed_it) { + $doit = false;// nothing to do + } + } + if ($doit) { + return $this->setConf($key, $value); + } + if ($forked) { + return $value_fork; + } + } +} -- cgit v1.2.3-2-g168b