da_agency/lib/Controller/AgencyController.php

156 lines
4.1 KiB
PHP

<?php
declare(strict_types=1);
namespace OCA\Agency\Controller;
use OCP\IRequest;
use OCP\IUserSession;
use OCP\IUserManager;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Http\JSONResponse;
use OCP\AppFramework\Controller;
use OCP\IGroupManager;
use OCA\Agency\Service\AgencyService;
use OCA\Agency\Agency\AgencyManager;
use OCP\IDBConnection;
class AgencyController extends Controller {
private $service;
private $Id;
protected $userSession;
protected $request;
protected $agencyManager;
protected $groupManager;
use Errors;
public function __construct(string $AppName, IRequest $request, IUserSession $userSession, AgencyService $service, IDBConnection $connection, AgencyManager $agencymanager, IGroupManager $groupManager){
parent::__construct($AppName, $request);
$this->service = $service;
$this->userSession = $userSession;
$this->request = $request;
$this->agencyManager = $agencymanager;
$this->groupManager = $groupManager;
}
/**
* @NoAdminRequired
*/
public function index() {
return new DataResponse($this->service->findAll($this->Id));
}
/**
* @NoAdminRequired
*
*/
public function show() {
return $this->agencyManager->getAgencyByUser();
#return $this->handleNotFound(function () use ($id) {
# return $this->service->find($id);
#});
}
/**
* @NoAdminRequired
*
* @param string $name
* @param string $inhaber
* @param string $street
* @param string $plz
* @param string $city
* @param string $agencymail
* @param string $phone
* @param string $agencygid
* @param string $agencydirid
* @param string $standarddirid
*
*/
public function create(string $agencygid, string $agencydirid, string $standarddirid) {
return $this->service->create($name, $inhaber, $street, $plz, $city, $agencymail, $phone, $agencygid, $agencydirid, $standarddirid);
}
/**
* @NoAdminRequired
*
*/
public function updateagencydata(string $name = null, string $inhaber = null, string $street = null, string $plz = null, string $city = null, string $agencymail = null, string $phone = null) {
$id = $this->agencyManager->getAgencyByUser()->getId();
return $this->handleNotFound(function () use ($id, $name, $inhaber, $street, $plz, $city, $agencymail, $phone) {
return $this->service->update($id, $name, $inhaber, $street, $plz, $city, $agencymail, $phone);
});
}
/**
* @NoAdminRequired
*
* @param int $id
*/
public function destroy(int $id) {
return $this->handleNotFound(function () use ($id) {
return $this->service->delete($id);
});
}
/**
* @NoAdminRequired
*/
public function getagencycontributors(){
return $this->agencyManager->getagencycontributors();
}
/**
* @NoAdminRequired
*
* Update the Group-Members
*
*
*/
# TODO: Noch prüfen, OB der Nutzer das überhautp darf und Agenturcheck usw.
public function updateagencygroupcontributors(string $gid, array $users){
return $this->agencyManager->updateagencygroupcontributors($gid, $users);
}
/**
* @PublicPage
* @NoCSRFRequired
*
* @param:
* groupid - string, groupid in NC to update
* newvalue - string, new groupname
*
*/
public function updateagencygroup(string $groupid, string $newvalue){
$this->groupManager->get($groupid)->setDisplayName($newvalue);
//return "OK!";
}
/**
* @PublicPage
* @NoCSRFRequired
*
* @param:
* groupid - string, groupid in NC to update
* newvalue - string, new groupname
*
*/
public function deleteagencygroup(string $groupid){
$this->groupManager->get($groupid)->delete();
//return "OK!";
}
/**
* @NoAdminRequired
* @NoCSRFRequired
* @CORS
*/
public function getlogdata(){
refickdichscheissnextclouidturn "NIX!";
}
}