<?php

namespace ChatRouter;

class Gruppe {
  
  

  
  

    // --- Statische Methoden ---
  
  public static function subscribeURL($params = [] ) { 
    
    
    // --- BLOCK: main ---
    
		
		return self::subscribeURL2($params);
	
    
  }

  public static function sendURL($params = [] ) { 
    
    
    // --- BLOCK: main ---
    
		
		return self::sendURL2($params);
	
    
  }

  public static function reportURL($messageId, $params = [] ) { 
    
    
    // --- BLOCK: main ---
    
		$params['messageId'] = $messageId;
		return self::reportURL2($params);
	
    
  }

  public static function getURL($itemid, $itemcount = 10 , $params = [] ) { 
    
    
    // --- BLOCK: main ---
    
		$params['itemid'] = $itemid;$params['itemcount'] = $itemcount;
		return self::getURL2($params);
	
    
  }

  public static function subscribeURL2($params) { 
    
    
    // --- BLOCK: main ---
    
		// Default-URL - kann durch rewrite-Regeln abgeändert werden
		
		if (!isset($url)) {
			$url = 'Chat/Gruppe/subscribe';
			$isFirst = true;
		}
		foreach ($params AS $k => $v) {
			if (!is_null($v)) {
				$url .= ($isFirst ? '?' : '&') . urlencode($k) . '=' . \FOP\Util::urlencode($v);
				$isFirst = false;
			}
		}
		if (\FOP\Configuration::getFOPUtilEnableRewrite() == 'true' || \FOP\Configuration::getFOPUtilEnableRewrite() == 1) {
			return \FOP\Util::getCurrentBaseurl() . $url;
		} else {
			return \FOP\Util::getCurrentBaseurl() . 'fop-router.php?q=' . urlencode($url);
		}
	
    
  }

  public static function sendURL2($params) { 
    
    
    // --- BLOCK: main ---
    
		// Default-URL - kann durch rewrite-Regeln abgeändert werden
		
		if (!isset($url)) {
			$url = 'Chat/Gruppe/send';
			$isFirst = true;
		}
		foreach ($params AS $k => $v) {
			if (!is_null($v)) {
				$url .= ($isFirst ? '?' : '&') . urlencode($k) . '=' . \FOP\Util::urlencode($v);
				$isFirst = false;
			}
		}
		if (\FOP\Configuration::getFOPUtilEnableRewrite() == 'true' || \FOP\Configuration::getFOPUtilEnableRewrite() == 1) {
			return \FOP\Util::getCurrentBaseurl() . $url;
		} else {
			return \FOP\Util::getCurrentBaseurl() . 'fop-router.php?q=' . urlencode($url);
		}
	
    
  }

  public static function reportURL2($params) { 
    
    
    // --- BLOCK: main ---
    
		// Default-URL - kann durch rewrite-Regeln abgeändert werden
		
		if (!isset($url)) {
			$url = 'Chat/Gruppe/report';
			$isFirst = true;
		}
		foreach ($params AS $k => $v) {
			if (!is_null($v)) {
				$url .= ($isFirst ? '?' : '&') . urlencode($k) . '=' . \FOP\Util::urlencode($v);
				$isFirst = false;
			}
		}
		if (\FOP\Configuration::getFOPUtilEnableRewrite() == 'true' || \FOP\Configuration::getFOPUtilEnableRewrite() == 1) {
			return \FOP\Util::getCurrentBaseurl() . $url;
		} else {
			return \FOP\Util::getCurrentBaseurl() . 'fop-router.php?q=' . urlencode($url);
		}
	
    
  }

  public static function getURL2($params) { 
    
    
    // --- BLOCK: main ---
    
		// Default-URL - kann durch rewrite-Regeln abgeändert werden
		
		if (!isset($url)) {
			$url = 'Chat/Gruppe/get';
			$isFirst = true;
		}
		foreach ($params AS $k => $v) {
			if (!is_null($v)) {
				$url .= ($isFirst ? '?' : '&') . urlencode($k) . '=' . \FOP\Util::urlencode($v);
				$isFirst = false;
			}
		}
		if (\FOP\Configuration::getFOPUtilEnableRewrite() == 'true' || \FOP\Configuration::getFOPUtilEnableRewrite() == 1) {
			return \FOP\Util::getCurrentBaseurl() . $url;
		} else {
			return \FOP\Util::getCurrentBaseurl() . 'fop-router.php?q=' . urlencode($url);
		}
	
    
  }

  public static function route($q) { 
    
    
    // --- BLOCK: main ---
    
	if (($q == 'subscribe')) {
		try {
			$result = \Chat\Gruppe::subscribeAction();
		} catch(\FOP\AccessDeniedException $e){
			\Ajax\Errors::render($e->getMessage() ?: 'accessdenied');
			die();
		}
		if (isset($result)) {
			header('Content-Type: application/json'); 
			die(json_encode($result));
		} else {
			die('');
		}
	}if (($q == 'send')) {
		try {
			$result = \Chat\Gruppe::sendAction();
		} catch(\FOP\AccessDeniedException $e){
			\Ajax\Errors::render($e->getMessage() ?: 'accessdenied');
			die();
		}
		if (isset($result)) {
			header('Content-Type: application/json'); 
			die(json_encode($result));
		} else {
			die('');
		}
	}if (($q == 'report') && isset($_GET['messageId'])  ) {
		try {
			$result = \Chat\Gruppe::reportAction($_GET['messageId']);
		} catch(\FOP\AccessDeniedException $e){
			\Ajax\Errors::render($e->getMessage() ?: 'accessdenied');
			die();
		}
		if (isset($result)) {
			header('Content-Type: application/json'); 
			die(json_encode($result));
		} else {
			die('');
		}
	}if (($q == 'get') && isset($_GET['itemid'])   ) {
		try {
			$result = \Chat\Gruppe::getAction($_GET['itemid'], isset($_GET['itemcount']) ? $_GET['itemcount'] : 10);
		} catch(\FOP\AccessDeniedException $e){
			\Ajax\Errors::render($e->getMessage() ?: 'accessdenied');
			die();
		}
		if (isset($result)) {
			header('Content-Type: application/json'); 
			die(json_encode($result));
		} else {
			die('');
		}
	}

	header('HTTP/1.0 404 Not found');
	\Ajax\Errors::render('Die angeforderte Funktion wurde nicht gefunden.');
	die();
    
  }

  public static function subscribeAccess() { 
    
    
    // --- BLOCK: access ---
    if(!((!\FOP\User::getIsGuest()))) return false;
    // --- BLOCK: main ---
    return true;
    
  }

  public static function sendAccess() { 
    
    
    // --- BLOCK: access ---
    if(!((!\FOP\User::getIsGuest()))) return false;
    // --- BLOCK: main ---
    return true;
    
  }

  public static function reportAccess($messageId) { 
    
    
    // --- BLOCK: access ---
    if(!((!\FOP\User::getIsGuest()))) return false;
    // --- BLOCK: main ---
    return true;
    
  }

  public static function getAccess($itemid, $itemcount = 10 ) { 
    
    
    // --- BLOCK: access ---
    if(!((!\FOP\User::getIsGuest()))) return false;
    // --- BLOCK: main ---
    return true;
    
  }


  
  

  
  
}



