56 lines
1.7 KiB
PHP
56 lines
1.7 KiB
PHP
<?php
|
|
namespace OCA\Agency\Agency;
|
|
|
|
use OCP\IRequest;
|
|
use OCP\IUserSession;
|
|
use OCP\IDBConnection;
|
|
use OCA\Agency\Db\AgencyMapper;
|
|
use OCA\Agency\Service\AgencyService;
|
|
|
|
use OCP\IGroupManager;
|
|
|
|
class AgencyManager {
|
|
|
|
protected $agencyMapper;
|
|
protected $groupManager;
|
|
protected $db;
|
|
|
|
public function __construct($AppName, IDBConnection $db, IRequest $request, AgencyMapper $agencyMapper, IGroupManager $groupManager) {
|
|
$this->agencyMapper = $agencyMapper;
|
|
$this->groupManager = $groupManager;
|
|
}
|
|
/**
|
|
* Creates a new Agency and save it to the database.
|
|
*
|
|
* @param:
|
|
* agencygid - GrouopID of the Agency
|
|
* agencydirid - ID for the Grouopfolder for AgencyData
|
|
* standarddirid - ID for the Groupfolder for all Uploaded Standardfiles
|
|
*/
|
|
public function createAgencyOnReg(string $agencygid, int $agencydirid, int $standarddirid){
|
|
$agencyService = new AgencyService($this->agencyMapper);
|
|
return $agencyService->create(null, null, null, null, null, null, null, $agencygid, $agencydirid, $standarddirid);
|
|
}
|
|
|
|
/**
|
|
* getAgencyIdByUser
|
|
*
|
|
* @param:
|
|
* - $request
|
|
* - $userSession
|
|
*
|
|
* Return the Agency-ID by filtering the id from default agency-group, ex: agency_1 -> 1 (int)
|
|
*
|
|
*/
|
|
public function getAgencyIdByUser(IUserSession $userSession){
|
|
$groups = $this->groupManager->getUserGroups($userSession->getUser());
|
|
$agency_group_id = "";
|
|
foreach($groups as $group){
|
|
if(str_contains($group->getGId(), 'agency')){
|
|
$agency_group_id = explode("_", strval($group->getGId()))[1];
|
|
}
|
|
}
|
|
return intval($agency_group_id);
|
|
}
|
|
|
|
} |