<?php

namespace Subroutes;

require_once("links/Personal_Lehrgaenge.php");

trait Personal_Lehrgänge
{
	protected function answer_Personal_Lehrgänge($pid, $lid) {return $this->personal_lehrgänge_answer($pid, $lid);} // called from Personal
	protected function answer_Lehrgänge_Personal($lid, $pid) {return $this->personal_lehrgänge_answer($pid, $lid);} // called from Lehrgänge
	
	protected function personal_lehrgänge_answer($leftid, $rightid) {
		switch (\Request::Method()) {
			case "POST":
				if ($this->personal_lehrgänge_can("set", $leftid, $rightid) && \Links\Personal_Lehrgänge::Get()->Set($leftid, $rightid)) {
					\Response::Get()->SubInserted();
					return true;
				}
				break;
			case "DELETE":
				if ($this->personal_lehrgänge_can("unset", $leftid, $rightid) && \Links\Personal_Lehrgänge::Get()->Unset($leftid, $rightid)) {
					\Response::Get()->SubDeleted();
					return true;
				}
				break;
			default:
    		\Response::Get()->NotImplemented();
		}
		return false;
	}
	
	protected function personal_lehrgänge_can($action, $leftid, $rightid) {
		return !is_null($leftid) && !is_null($rightid);
  }
}
