getRouteParam('id'); $link = $request->getRouteParam('link'); $searchParams = $this->fetchSearchParamsFromRequest($request); $result = $this->getRecordService()->findLinked($id, $link, $searchParams); if ($result instanceof RecordCollection) { return (object) [ 'total' => $result->getTotal(), 'list' => $result->getValueMapList(), ]; } if (is_array($result)) { return [ 'total' => $result['total'], 'list' => isset($result['collection']) ? $result['collection']->getValueMapList() : $result['list'] ]; } return (object) [ 'total' => $result->total, 'list' => isset($result->collection) ? $result->collection->getValueMapList() : $result->list ]; } /** * Relate records. */ public function postActionCreateLink(Request $request): bool { $id = $request->getRouteParam('id'); $link = $request->getRouteParam('link'); $data = $request->getParsedBody(); if (!$id || !$link) { throw new BadRequest(); } if (!empty($data->massRelate)) { if (!is_array($data->where)) { throw new BadRequest(); } $where = json_decode(json_encode($data->where), true); $selectData = null; if (isset($data->selectData) && is_array($data->selectData)) { $selectData = json_decode(json_encode($data->selectData), true); } return $this->getRecordService()->massLink($id, $link, $where, $selectData); } $foreignIdList = []; if (isset($data->id)) { $foreignIdList[] = $data->id; } if (isset($data->ids) && is_array($data->ids)) { foreach ($data->ids as $foreignId) { $foreignIdList[] = $foreignId; } } $result = false; foreach ($foreignIdList as $foreignId) { $this->getRecordService()->link($id, $link, $foreignId); $result = true; } return $result; } /** * Unrelate records. */ public function deleteActionRemoveLink(Request $request): bool { $id = $request->getRouteParam('id'); $link = $request->getRouteParam('link'); $data = $request->getParsedBody(); if (!$id || !$link) { throw new BadRequest(); } $foreignIdList = []; if (isset($data->id)) { $foreignIdList[] = $data->id; } if (isset($data->ids) && is_array($data->ids)) { foreach ($data->ids as $foreignId) { $foreignIdList[] = $foreignId; } } $result = false; foreach ($foreignIdList as $foreignId) { $this->getRecordService()->unlink($id, $link, $foreignId); $result = true; } return $result; } /** * Follow a record. */ public function putActionFollow(Request $request): bool { $id = $request->getRouteParam('id'); return $this->getRecordService()->follow($id); } /** * Unfollow a record. */ public function deleteActionUnfollow(Request $request): bool { $id = $request->getRouteParam('id'); return $this->getRecordService()->unfollow($id); } }