Skip to content
57 changes: 51 additions & 6 deletions src/app/Http/Controllers/CytoscapeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,77 @@ public function index()
$lists = Field::whereCrewId(Auth::user()->crew_id)->whereRelation('dataType','name', 'List')->get();
$lists_name = $lists->pluck('title', 'id');
$field_list = json_encode($lists->pluck('linked_list','id'));
$relations = Link::whereRelation('RefugeeFrom.crew', 'crews.id', Auth::user()->crew->id)
$refugee_to_event_relations = Link::whereRelation('RefugeeFrom.crew', 'crews.id', Auth::user()->crew->id)
->whereRelation('EventTo.crew', 'crews.id', Auth::user()->crew->id)
->get();
$refugee_to_place_relations = Link::whereRelation('RefugeeFrom.crew', 'crews.id', Auth::user()->crew->id)
->whereRelation('PlaceTo.crew', 'crews.id', Auth::user()->crew->id)
->get();
$refugee_to_refugee_relations = Link::whereRelation('RefugeeFrom.crew', 'crews.id', Auth::user()->crew->id)
->whereRelation('RefugeeTo.crew', 'crews.id', Auth::user()->crew->id)
->get();
$event_to_event_relations = Link::whereRelation('EventFrom.crew', 'crews.id', Auth::user()->crew->id)
->whereRelation('EventTo.crew', 'crews.id', Auth::user()->crew->id)
->get();
$event_to_place_relations = Link::whereRelation('EventFrom.crew', 'crews.id', Auth::user()->crew->id)
->whereRelation('PlaceTo.crew', 'crews.id', Auth::user()->crew->id)
->get();
$event_to_refugee_relations = Link::whereRelation('EventFrom.crew', 'crews.id', Auth::user()->crew->id)
->whereRelation('RefugeeTo.crew', 'crews.id', Auth::user()->crew->id)
->get();
$place_to_place_relations = Link::whereRelation('PlaceFrom.crew', 'crews.id', Auth::user()->crew->id)
->whereRelation('PlaceTo.crew', 'crews.id', Auth::user()->crew->id)
->get();
$place_to_refugee_relations = Link::whereRelation('PlaceFrom.crew', 'crews.id', Auth::user()->crew->id)
->whereRelation('RefugeeTo.crew', 'crews.id', Auth::user()->crew->id)
->get();
$place_to_event_relations = Link::whereRelation('PlaceFrom.crew', 'crews.id', Auth::user()->crew->id)
->whereRelation('EventTo.crew', 'crews.id', Auth::user()->crew->id)
->get();
$relations = $refugee_to_event_relations
->merge($refugee_to_place_relations)
->merge($refugee_to_refugee_relations)
->merge($event_to_event_relations)
->merge($event_to_place_relations)
->merge($event_to_refugee_relations)
->merge($place_to_place_relations)
->merge($place_to_refugee_relations)
->merge($place_to_event_relations);

//get the role field

$links = array();
$nodes = array();
$refugees = array();
$events = array();
$places = array();
$used_relations = array();
foreach ($relations as $relation) {

$node["data"] = array();
$node["data"]["id"] = $relation->getFromId();
$node["data"]["name"] = $relation->refugeeFrom->best_descriptive_value;
$node["data"]["name"] = $relation->refugeeFrom?->best_descriptive_value
?? $relation->eventFrom?->name
?? $relation->placeFrom?->name
?? "Ø";

array_push($nodes, $node);

$node["data"] = array();
$node["data"]["id"] = $relation->getToId();
$node["data"]["name"] = $relation->refugeeTo->best_descriptive_value;
$node["data"]["name"] = $relation->refugeeTo?->best_descriptive_value
?? $relation->eventTo?->name
?? $relation->placeTo?->name
?? "Ø";

array_push($nodes, $node);

$refugees[$relation->getToId()] = $relation->refugeeTo->best_descriptive_value;
$refugees[$relation->getFromId()] = $relation->refugeeFrom->best_descriptive_value;
$refugees[$relation->getToId()] = $relation->refugeeTo->best_descriptive_value ?? "Ø";
$refugees[$relation->getFromId()] = $relation->refugeeFrom->best_descriptive_value ?? "Ø";
$events[$relation->getToId()] = $relation->eventTo->name ?? "Ø";
$events[$relation->getFromId()] = $relation->eventFrom->name ?? "Ø";
$places[$relation->getToId()] = $relation->placeTo->name ?? "Ø";
$places[$relation->getFromId()] = $relation->placeFrom->name ?? "Ø";

$link["data"] = array();
$link["data"]["id"] = $relation->id;
Expand Down Expand Up @@ -103,6 +148,6 @@ public function index()

// file_put_contents("js/cytoscape/content.json",json_encode(array_merge($nodes, $links)));
Storage::disk('public')->put('content.json', $cytoscape_data);
return view("cytoscape.index", compact("relations", "refugees", "lists_name", "field_list", "persons", "used_relations"));
return view("cytoscape.index", compact("relations", "refugees", "events", "places","lists_name", "field_list", "persons", "used_relations"));
}
}
2 changes: 2 additions & 0 deletions src/app/Http/Controllers/EventController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
use App\Models\Language;
use App\Models\ListControl;
use App\Models\Translation;
use App\Models\Link;
use App\Models\Crew;
use Illuminate\View\View;

class EventController extends Controller
Expand Down
45 changes: 35 additions & 10 deletions src/app/Http/Controllers/LinkController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
use App\Models\ListRelation;
use App\Models\ListRelationType;
use App\Models\Refugee;
use App\Models\Event;
use App\Models\Place;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Auth;
Expand Down Expand Up @@ -54,7 +56,7 @@ public static function handleApiRequest(StoreLinkApiRequest $request) {
$link = Link::firstOrCreate($link, ["api_log" => $log->id]);

}
array_push($responseArray, $link->id);
array_push ($responseArray, $link->id);
}
return response(json_encode($responseArray),
201,
Expand Down Expand Up @@ -88,14 +90,32 @@ public function update(UpdateLinkRequest $request,Link $link) {
*
* @return Response
*/

public function index() {
$links = Link::whereRelation('RefugeeFrom.crew',
'crews.id',
Auth::user()->crew->id)->whereRelation('RefugeeTo.crew',
'crews.id',
Auth::user()->crew->id)->get();
return view("links.index",
compact('links'));

$links_refugee_to_refugee = Link::createLinks('RefugeeFrom', 'RefugeeTo');
$links_refugee_to_event = Link::createLinks('RefugeeFrom', 'EventTo');
$links_refugee_to_place = Link::createLinks('RefugeeFrom', 'PlaceTo');
$links_event_to_refugee = Link::createLinks('EventFrom', 'RefugeeTo');
$links_event_to_event = Link::createLinks('EventFrom', 'EventTo');
$links_event_to_place = Link::createLinks('EventFrom', 'PlaceTo');
$links_place_to_place = Link::createLinks('PlaceFrom', 'PlaceTo');
$links_place_to_refugee = Link::createLinks('PlaceFrom', 'RefugeeTo');
$links_place_to_event = Link::createLinks('PlaceFrom', 'EventTo');


// merge all links
$links = $links_refugee_to_refugee
->merge($links_refugee_to_event)
->merge($links_refugee_to_place)
->merge($links_event_to_refugee)
->merge($links_event_to_event)
->merge($links_event_to_place)
->merge($links_place_to_place)
->merge($links_place_to_refugee)
->merge($links_place_to_event);

return view("links.index", compact('links'));
}

/**
Expand Down Expand Up @@ -172,16 +192,21 @@ public function store(StoreLinkRequest $request) {
* @return Response
*/
public function create($origin = null,
Refugee $refugee = null) {
Refugee $refugee = null, Event $event = null, Place $place = null) {
$lists["refugees"] = Refugee::getAllBestDescriptiveValues();
$lists["events"] = Event::getAllEventsNames();
$lists["places"] = Place::getAllPlacesNames();
$lists["all"] = $lists["refugees"] + $lists["events"] + $lists["places"];
$lists["relations"] = array_column(ListRelation::all()->toArray(),
ListControl::where('name',
"ListRelation")->first()->displayed_value,
"id");
return view("links.create",
compact("lists",
'origin',
'refugee'));
'refugee',
'event',
'place'));
}

/**
Expand Down
3 changes: 3 additions & 0 deletions src/app/Http/Controllers/PlaceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Models\Place;
use \App\Http\Livewire\Forms\Coordinates;
use \App\Http\Livewire\Forms\Area;
use App\Models\ApiLog;

class PlaceController extends Controller
{
Expand Down Expand Up @@ -37,7 +38,9 @@ public function create()

public function store(StorePlaceRequest $request)
{
$log = ApiLog::createFromRequest($request, 'Place');
$place = $request->validated();
$place['api_log'] = $log->id;
$place['coordinates'] = Coordinates::encode($place['coordinates']);
$place['area'] = Area::encode($place['area']);
$place = Place::create($place);
Expand Down
39 changes: 39 additions & 0 deletions src/app/Models/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,43 @@ public function persons()
}
return $persons_in_event;
}

public static function getAllEventsNames(){
$events = Event::all();
$events_name = [];
foreach ($events as $event){
$events_name[$event->id] = $event->name;
}
return $events_name;
}
public function crew() {
return $this->hasOneThrough(Crew::class,
ApiLog::class,
"id", "id",
"api_log",
"crew_id");
}
public function user() {
return $this->hasOneThrough(User::class,
ApiLog::class,
"id", "id",
"api_log",
"user_id");
}
public function getRelationsAttribute() {
return [
$this->fromRelation,
$this->toRelation,
];
}
public function toRelation() {
return $this->belongsToMany(ListRelation::class,
"links", "to",
"relation_id")->using(Link::class)->wherePivotNull("deleted_at")->withPivot("from")->withPivot("id");
}
public function fromRelation() {
return $this->belongsToMany(ListRelation::class,
"links", "from",
"relation_id")->using(Link::class)->wherePivotNull("deleted_at")->withPivot("to")->withPivot("id");
}
}
Loading