private function removeAllFinds() { $count = 0; $findNodes = $this->finds->getAll(); $bar = $this->output->createProgressBar(count($findNodes)); foreach ($findNodes as $findNode) { $find = new FindEvent(); $find->setNode($findNode); $find->delete(); $bar->advance(); $count++; } $this->info(""); $this->info("Removed {$count} FindEvent nodes."); }
/** * Get all of the finds for a person * * @param Person $person The Person object * @param integer $limit * @param integer $offset * * @return array */ public function getForPerson($person, $limit = 20, $offset = 0) { // Get all of the related finds $personNode = $person->getNode(); $relationships = $personNode->getRelationships(['P29'], Relationship::DirectionOut); // Apply paging by taking a slice of the relationships array $relationships = array_slice($relationships, $offset, $limit); $finds = []; foreach ($relationships as $relation) { $find_node = $relation->getEndNode(); $findEvent = new FindEvent(); $findEvent->setNode($find_node); // Get the entire data that's behind the find $find = $findEvent->getValues(); $finds[] = $find; } return ['data' => $finds, 'count' => count($relationships)]; }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $findId * @return \Illuminate\Http\Response */ public function update(Request $request, $findId) { $find_node = $this->finds->getById($findId); if (!empty($find_node)) { $input = $request->json()->all(); $user = $request->user(); if (empty($user)) { // Test code in order to test with PostMan requests /*$users = new UserRepository(); $user_node = $users->getUser('*****@*****.**'); $user = new \App\Models\Person(); $user->setNode($user_node);*/ abort('401'); } $images = []; // Check for images, they need special processing before the Neo4j writing is initiated if (!empty($input['object']['photograph'])) { foreach ($input['object']['photograph'] as $image) { if (empty($image['identifier'])) { list($name, $name_small, $width, $height) = $this->processImage($image); $images[] = ['src' => $request->root() . '/uploads/' . $name, 'resized' => $request->root() . '/uploads/' . $name_small, 'width' => $width, 'height' => $height]; } else { $images[] = $image; } } } $input['object']['photograph'] = $images; $input['person'] = ['id' => $user->id]; $find = new FindEvent(); $find->setNode($find_node); try { $find->update($input); return response()->json(['url' => '/finds/' . $findId, 'id' => $findId]); } catch (\Exception $ex) { return response()->json(['error' => $ex->getMessage()], 400); } } else { abort('404'); } }