<?php

namespace Subroutes;

require_once("links/Personal_Abteilungen.php");

trait Personal_Abteilungen
{
	protected function answer_Personal_Abteilungen($pid, $aid) {return $this->personal_abteilungen_answer($pid, $aid);} // called from Personal
	protected function answer_Abteilungen_Personal($aid, $pid) {return $this->personal_abteilungen_answer($pid, $aid);} // called from Abteilungen
	
	protected function personal_abteilungen_answer($leftid, $rightid) {
		switch (\Request::Method()) {
			case "POST":
				if ($this->personal_abteilungen_can("set", $leftid, $rightid) && \Links\Personal_Abteilungen::Get()->Set($leftid, $rightid)) {
					\Response::Get()->SubInserted();
					return true;
				}
				break;
			case "DELETE":
				if ($this->personal_abteilungen_can("unset", $leftid, $rightid) && \Links\Personal_Abteilungen::Get()->Unset($leftid, $rightid)) {
					\Response::Get()->SubDeleted();
					return true;
				}
				break;
			default:
    		\Response::Get()->NotImplemented();
		}
		return false;
	}
	
	protected function personal_abteilungen_can($action, $leftid, $rightid) {
		return !is_null($leftid) && !is_null($rightid);
	}
}
