Track what data is changed and only send that on post/put requests.
This commit is contained in:
parent
052f0537ba
commit
5731b93845
@ -25,11 +25,13 @@ class Gallery3 {
|
|||||||
var $url;
|
var $url;
|
||||||
var $token;
|
var $token;
|
||||||
var $data;
|
var $data;
|
||||||
|
var $changed_data;
|
||||||
var $file;
|
var $file;
|
||||||
var $parent;
|
var $parent;
|
||||||
|
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
$this->data = new stdClass();
|
$this->data = new stdClass();
|
||||||
|
$this->changed_data = new stdClass();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -90,7 +92,7 @@ class Gallery3 {
|
|||||||
* @return object Gallery3
|
* @return object Gallery3
|
||||||
*/
|
*/
|
||||||
public function set_value($key, $value) {
|
public function set_value($key, $value) {
|
||||||
$this->data->$key = $value;
|
$this->changed_data->$key = $value;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,6 +103,9 @@ class Gallery3 {
|
|||||||
* @return string value
|
* @return string value
|
||||||
*/
|
*/
|
||||||
public function __get($key) {
|
public function __get($key) {
|
||||||
|
if (property_exists($this->changed_data, $key)) {
|
||||||
|
return $this->changed_data->$key;
|
||||||
|
}
|
||||||
return $this->data->$key;
|
return $this->data->$key;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,10 +146,10 @@ class Gallery3 {
|
|||||||
*/
|
*/
|
||||||
public function save() {
|
public function save() {
|
||||||
if ($this->url) {
|
if ($this->url) {
|
||||||
$response = Gallery3_Helper::request("put", $this->url, $this->token, $this->data);
|
$response = Gallery3_Helper::request("put", $this->url, $this->token, $this->changed_data);
|
||||||
} else {
|
} else {
|
||||||
$response = Gallery3_Helper::request(
|
$response = Gallery3_Helper::request(
|
||||||
"post", $this->parent->url, $this->token, $this->data, $this->file);
|
"post", $this->parent->url, $this->token, $this->changed_data, $this->file);
|
||||||
$this->parent->load();
|
$this->parent->load();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -184,8 +189,9 @@ class Gallery3 {
|
|||||||
}
|
}
|
||||||
$response = Gallery3_Helper::request("get", $this->url, $this->token);
|
$response = Gallery3_Helper::request("get", $this->url, $this->token);
|
||||||
|
|
||||||
$this->data = isset($response->resource) ? $response->resource : array();
|
$this->data = isset($response->resource) ? $response->resource : new stdClass();
|
||||||
$this->members = isset($response->members) ? $response->members : array();
|
$this->members = isset($response->members) ? $response->members : array();
|
||||||
|
$chis->changed_data = new stdClass();
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -196,6 +202,7 @@ class Gallery3 {
|
|||||||
*/
|
*/
|
||||||
protected function reset() {
|
protected function reset() {
|
||||||
$this->data = array();
|
$this->data = array();
|
||||||
|
$this->changed_data = array();
|
||||||
$this->url = null;
|
$this->url = null;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user