summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorLuke Shumaker <LukeShu@sbcglobal.net>2011-10-04 22:19:45 -0400
committerLuke Shumaker <LukeShu@sbcglobal.net>2011-10-04 22:19:45 -0400
commitf72b9a7658cea71ee1edf4ae678a2c8043d9e5bf (patch)
treead815ede91026d8ed0df23785d4ff3b6170b3de4 /src/lib
parent2f1d74bdd48e3beaf6b52cad126de0271875e7ac (diff)
Begin work on safely allowing concurrent edits on data, giving better form interface.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/Form.class.php57
1 files changed, 57 insertions, 0 deletions
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 @@
+<?php
+
+require_once('Auth.class.php');
+
+class Form {
+ public $getter = null;
+ public $setter = null;
+ public function __constructor($get, $set) {
+ $this->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;
+ }
+ }
+}