<?php

namespace Subroutes;

require_once("links/Personal_Verwalter.php");

trait Personal_Verwalter
{
	protected function answer_Personal_Verwalter($pid, $vid) {return $this->personal_verwalter_answer($pid, $vid);} // called from Personal
	protected function answer_Verwalter_Personal($vid, $pid) {return $this->personal_verwalter_answer($pid, $vid);} // called from Verwalter
	
	protected function personal_verwalter_answer($leftid, $rightid) {
		switch (\Request::Method()) {
			case "POST":
				if ($this->personal_verwalter_can("set", $leftid, $rightid) && \Links\Personal_Verwalter::Get()->Set($leftid, $rightid)) {
					\Response::Get()->SubInserted();
					return true;
				}
				break;
			case "DELETE":
				if ($this->personal_verwalter_can("unset", $leftid, $rightid) && \Links\Personal_Verwalter::Get()->Unset($leftid, $rightid)) {
					\Response::Get()->SubDeleted();
					return true;
				}
				break;
			default:
    		\Response::Get()->NotImplemented();
		}
		return false;
	}
	
	protected function personal_verwalter_can($action, $leftid, $rightid) {
		return !is_null($leftid) && !is_null($rightid);
	}
}
