protected function findCardOrError($cardId) { $card = $this->cm->findById($cardId); if ($card == null) { $this->addError("Card with id {$cardId} doesn't exist"); $this->redirect(); $this->stop(); } return $card; }
public function loadSaveChanges($mindMapId, $changesAsJson) { $errors = array(); //used to map the temporary id of nodes to the new database ids $newNodes = array(); $changes = json_decode($changesAsJson); foreach ($changes as $c) { if ($c->state == "new") { $parent = $this->mnm->findById($mindMapId); if ($c->type == "card") { $card = $this->cm->findById($c->cardId); $nc = $this->mnm->addCardToMindMap($parent, $card, $c->x, $c->y, $c->z, $c->width, $c->height, $c->collapsed); $newNodes["node" . $c->id] = $nc; } else { if ($c->type == "map") { $m = $this->mnm->createMindMap($c->name, $c->x, $c->y, $c->z, $c->width, $c->height, $c->collapsed, $parent); $newNodes["node" . $c->id] = $m; } else { if ($c->type == "link") { $left = null; $right = null; $lid = substr($c->leftId, 4); if (substr($c->leftId, 4, 1) == "-") { //the link refers to a new created node $left = $newNodes[$c->leftId]; } else { $left = $this->mnm->findById($lid); } $rid = substr($c->rightId, 4); if (substr($c->rightId, 4, 1) == "-") { //the link refers to a new created node $right = $newNodes[$c->rightId]; } else { $right = $this->mnm->findById($rid); } $this->lm->createLink($left, $right, $c->text, $c->leftArrow, $c->rightArrow); } } } } else { if ($c->state == "updated") { if ($c->type == "card" || $c->type == "map") { $node = $this->mnm->findById($c->id); $this->mnm->updateNode($node, $c->x, $c->y, $c->z, $c->width, $c->height, $c->collapsed); } else { if ($c->type == "link") { $link = $this->lm->findById($c->id); $this->lm->updateLink($link, null, null, $c->text, $c->leftArrow, $c->rightArrow); } } } else { if ($c->state == "deleted") { if ($c->type == "card" || $c->type == "map") { $this->mnm->deleteById($c->id); } else { if ($c->type == "link") { $this->lm->deleteById($c->id); } } } } } } echo json_encode($errors); $this->dontRender(); }