<?php

namespace Subroutes;

require_once("links/Fahrzeuge_Einweisungen.php");

trait Fahrzeuge_Personal
{
	protected function answer_Fahrzeuge_Personal($pid, $fid) {return $this->fahrzeuge_personal_answer($pid, $fid);} // called from Fahrzeuge
	protected function answer_Personal_Fahrzeuge($fid, $pid) {return $this->fahrzeuge_personal_answer($pid, $fid);} // called from Personal
	
	protected function fahrzeuge_personal_answer($leftid, $rightid) {
		switch (\Request::Method()) {
			case "POST":
				if ($this->fahrzeuge_personal_can("set", $leftid, $rightid) && \Links\Fahrzeuge_Einweisungen::Get()->Set($leftid, $rightid)) {
					\Response::Get()->SubInserted();
					return true;
				}
				break;
			case "DELETE":
				if ($this->fahrzeuge_personal_can("unset", $leftid, $rightid) && \Links\Fahrzeuge_Einweisungen::Get()->Unset($leftid, $rightid)) {
					\Response::Get()->SubDeleted();
					return true;
				}
				break;
			default:
    		\Response::Get()->NotImplemented();
		}
		return false;
	}
	
	protected function fahrzeuge_personal_can($action, $leftid, $rightid) {
		return !is_null($leftid) && !is_null($rightid);
	}
}
