public function set($section, $path = '.', $searchQuery = null, $value = null, $decodeValue = true) { $dataAll = $this->read(); $storeData = json_encode($dataAll); $store = new Xapp_Util_Json_Query($storeData); $value = is_string($value) ? json_decode($value) : $value; $stdQuery = null; $success = false; if ($searchQuery) { //1. convert string query into an query map $stdQuery = $this->toStdQuery(is_string($searchQuery) ? json_decode($searchQuery, true) : $searchQuery); //2. prepare sanity test $queryResult = $store->query($path, $stdQuery)->get(); //3. did find something ? if ($queryResult != null && count($queryResult) == 1) { //4. now construct the real store $store = Xapp_Util_Json_Store::create($storeData); //5. re-run the query $a = $store->query($path, $stdQuery); //merge new value into query result $newValue = $this->_merge($queryResult[0], $value); //update store $a->set(null, $newValue); $success = true; } else { return false; } } if ($success) { $result = $store->object(); $this->write(json_encode($result)); return $result; } return null; }
public function get($section, $path, $query = null) { $dataAll = $this->read(); $userData = null; if ($dataAll) { $primKey = xapp_get_option(self::PRIMARY_KEY, $this); if (!property_exists($dataAll, $primKey)) { $dataAll->{$primKey} = new stdClass(); } $userData = $dataAll->{$primKey}; } $store = new Xapp_Util_Json_Store($userData); $qRes = $store->query($path, $query)->getResult(); return $qRes; }