/** * AJAX Get value of a mycelium node */ public function get(Request $request) { $path = $request->input("path"); if (!$this->mycelium->has($path)) { return ["success" => false]; } return ["success" => true, "node" => $this->mycelium->get($path)]; }
/** * Saves all changes made to pointers * @return Returns instances of newly created pointers */ protected function updatePointers($pointers) { if (!is_array($pointers)) { throw new MyceliumException("Invalid data passed into 'pointers' property."); } $newPointers = []; for ($i = 0; $i < count($pointers); $i++) { // get a pointer reference $pointer =& $pointers[$i]; // remove pointers that say they are located somewhere, where they aren't if ($this->mycelium->get($this->mycelium->pathToString($pointer["location"]) . ".id") != $pointer["id"]) { array_splice($pointers, $i, 1); $i--; continue; } // destroy pointers // they have already been removed from the tree and database so remove them just from the pointer array if (array_key_exists("removed", $pointer) && $pointer["removed"]) { array_splice($pointers, $i, 1); $i--; continue; } // create new pointers // pointers created an immediately destroyed are already removed, because removing happens first if (array_key_exists("new", $pointer) && $pointer["new"]) { $newPointers[$pointer["id"]] = $this->mycelium->createPointer($pointer["location"], $pointer["target"]); // remove the "new" key unset($pointer["new"]); continue; } // update pointers if (array_key_exists("changed", $pointer) && $pointer["changed"]) { $pointer = $this->mycelium->get($pointer["location"]); $pointer->target = $pointer["target"]; // remove the "changed" key unset($pointer["changed"]); } } return $newPointers; }