192 lines
4.8 KiB
PHP
192 lines
4.8 KiB
PHP
<?php
|
|
|
|
namespace OCA\Gestion\Controller;
|
|
|
|
use Exception;
|
|
use OCP\IConfig;
|
|
use OCP\IRequest;
|
|
use OCP\IUserSession;
|
|
use OCP\Mail\IMailer;
|
|
use OCP\IGroupManager;
|
|
|
|
defined("TAB1") or define("TAB1", "\t");
|
|
|
|
use OCP\IURLGenerator;
|
|
use OCA\Gestion\Db\Bdd;
|
|
use OC\Files\Filesystem;
|
|
use OCP\Files\IRootFolder;
|
|
use Psr\Log\LoggerInterface;
|
|
use OCP\AppFramework\Controller;
|
|
use OCA\Gestion\Service\GestionService;
|
|
use OCP\AppFramework\Http\DataResponse;
|
|
use OCA\Gestion\Service\NavigationService;
|
|
use OCP\AppFramework\Http\TemplateResponse;
|
|
use OCA\Gestion\Service\ConfigurationService;
|
|
use OCA\Gestion\Service\Provider\ProviderService;
|
|
use OCA\Gestion\Service\Provider\Statistic\ProviderStatisticService;
|
|
|
|
date_default_timezone_set('Europe/Paris');
|
|
|
|
class ProviderController extends Controller
|
|
{
|
|
private $idNextcloud;
|
|
private $urlGenerator;
|
|
private $mailer;
|
|
private $config;
|
|
|
|
/** @var IRootStorage */
|
|
private $storage;
|
|
|
|
private $user;
|
|
private $groups = [];
|
|
|
|
/** @var \OCA\Gestion\Service\NavigationService */
|
|
private $navigationService;
|
|
|
|
private $providerService;
|
|
|
|
private $providerStatisticService;
|
|
|
|
private $logger;
|
|
//Gestion service
|
|
private $gestionService;
|
|
|
|
|
|
/**
|
|
* Constructor
|
|
*/
|
|
public function __construct(
|
|
$AppName,
|
|
IRequest $request,
|
|
$UserId,
|
|
Bdd $myDb,
|
|
IRootFolder $rootFolder,
|
|
IURLGenerator $urlGenerator,
|
|
IMailer $mailer,
|
|
Iconfig $config,
|
|
IUserSession $userSession,
|
|
IGroupManager $groupManager,
|
|
NavigationService $navigationService,
|
|
ConfigurationService $configurationService,
|
|
LoggerInterface $logger,
|
|
ProviderService $providerService,
|
|
ProviderStatisticService $providerStatisticService,
|
|
GestionService $gestionService
|
|
) {
|
|
|
|
parent::__construct($AppName, $request);
|
|
|
|
$this->idNextcloud = $UserId;
|
|
$this->myDb = $myDb;
|
|
$this->urlGenerator = $urlGenerator;
|
|
$this->mailer = $mailer;
|
|
$this->config = $config;
|
|
$this->navigationService = $navigationService;
|
|
$this->configurationService = $configurationService;
|
|
$this->logger = $logger;
|
|
$this->providerService = $providerService;
|
|
$this->providerStatisticService = $providerStatisticService;
|
|
$this->gestionService = $gestionService;
|
|
|
|
if ($userSession->isLoggedIn()) {
|
|
$this->user = $userSession->getUser();
|
|
}
|
|
|
|
if ($this->user != null) {
|
|
$groups = $groupManager->getUserGroups($this->user);
|
|
$this->groups = [];
|
|
foreach ($groups as $group) {
|
|
$this->groups[] = $group->getGID();
|
|
}
|
|
}
|
|
|
|
try {
|
|
$this->storage = $rootFolder->getUserFolder($this->idNextcloud);
|
|
} catch (\OC\User\NoUserException $e) {
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
*/
|
|
public function provider()
|
|
{
|
|
return new TemplateResponse('gestion', 'provider', array('groups' => $this->groups, 'user' => $this->user, 'path' => $this->idNextcloud, 'url' => $this->navigationService->getNavigationLink()));
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
*/
|
|
public function getProviders()
|
|
{
|
|
$providers = $this->providerService->getProvidersAsArray();
|
|
return json_encode($providers);
|
|
}
|
|
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
*/
|
|
public function getProvidersTest() {
|
|
|
|
$client = \OC::$server->getHTTPClientService()->newClient();
|
|
$token = file_get_contents('http://127.0.0.1/ocs/v2.php/core/getcsrftoken', false, stream_context_create([
|
|
'http' => [
|
|
'header' => "OCS-APIRequest: true\r\n"
|
|
]
|
|
]));
|
|
$response = $client->post('http://127.0.0.1/ocs/v2.php/apps/files_sharing/api/v1/shares', [
|
|
'body' => [
|
|
"path" => "//Talk/narindra-dev.png",
|
|
"referenceId" => "dkzcesdsdhae",
|
|
"shareWith" => "dkzcehae",
|
|
"shareType" => 10,
|
|
'talkMetaData' => "{\"messageType\":\"\"}"
|
|
],
|
|
'headers' => [
|
|
'Cookie' =>"_ga=GA1.1.259457270.1732194936; _ga_699NE13B0K=GS1.1.1732203040.2.0.1732203040.0.0.0; nc_sameSiteCookielax=true; nc_sameSiteCookiestrict=true; nc_username=Tiavina; oc_sessionPassphrase=v7ncJ0h%2BYxrmzJViNygGkErBa9cSDs1m3mpgW4M6wZ%2BqphceZK2S7PMELp%2BlHgxQxcZuGPrpzZSwzp2SQCXADxDehB7OkwdBEr3DtG8ZzlnXZWzB%2Fbfl7xsuQYTnvmLU; oczp8j7d6k88=1b54a2ea877ffca7154bea254f70886c; nc_token=OEez5vu%2FWTz7FsafIbVDbAXA7lSdkG9U; nc_session_id=1b54a2ea877ffca7154bea254f70886c",
|
|
'OCS-APIRequest' => 'true',
|
|
'requesttoken' => $token
|
|
]
|
|
]);
|
|
|
|
var_dump($response);die;
|
|
return json_encode($providers);
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
*/
|
|
public function createDefaultProvider()
|
|
{
|
|
try {
|
|
$this->providerService->createDefaultProvider($this->idNextcloud);
|
|
return true;
|
|
} catch (Exception $e) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
*/
|
|
public function exportProvidersStatistic(array $providerIds, $year)
|
|
{
|
|
try {
|
|
$filenames = $this->providerStatisticService->exportProvidersStatisticByYear($providerIds, $year, $this->idNextcloud);
|
|
return $filenames;
|
|
} catch (Exception $e) {
|
|
return [];
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|