OneBot: Leantime 改造版源码(BOM/Univer 表格/AI 接管/品牌替换等)
This commit is contained in:
83
app/Domain/Calendar/Controllers/Export.php
Normal file
83
app/Domain/Calendar/Controllers/Export.php
Normal file
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
namespace Leantime\Domain\Calendar\Controllers;
|
||||
|
||||
use Leantime\Core\Auth\Permissions\RequiresPermission;
|
||||
use Leantime\Core\Controller\Controller;
|
||||
use Leantime\Domain\Calendar\Permissions\CalendarPermissions;
|
||||
use Leantime\Domain\Calendar\Services\Calendar as CalendarService;
|
||||
use Leantime\Domain\Setting\Services\Setting as SettingService;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class Export extends Controller
|
||||
{
|
||||
private SettingService $settingService;
|
||||
|
||||
private CalendarService $calendarService;
|
||||
|
||||
/**
|
||||
* Initializes dependencies.
|
||||
*/
|
||||
public function init(
|
||||
SettingService $settingService,
|
||||
CalendarService $calendarService
|
||||
): void {
|
||||
$this->settingService = $settingService;
|
||||
$this->calendarService = $calendarService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays the calendar export page.
|
||||
*
|
||||
* @param array $params Request parameters
|
||||
*/
|
||||
#[RequiresPermission(CalendarPermissions::VIEW)]
|
||||
public function get(array $params): Response
|
||||
{
|
||||
if (isset($_GET['remove'])) {
|
||||
$this->settingService->deleteSetting('usersettings.'.session('userdata.id').'.icalSecret');
|
||||
$this->tpl->setNotification('notifications.ical_removed_success', 'success');
|
||||
}
|
||||
|
||||
$this->assignUrl();
|
||||
|
||||
return $this->tpl->displayPartial('calendar.export');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles iCal URL generation.
|
||||
*
|
||||
* @param array $params Request parameters
|
||||
*/
|
||||
#[RequiresPermission(CalendarPermissions::VIEW)]
|
||||
public function post(array $params): Response
|
||||
{
|
||||
if (isset($_POST['generateUrl'])) {
|
||||
try {
|
||||
$this->calendarService->generateIcalHash();
|
||||
$this->tpl->setNotification('notifications.ical_success', 'success');
|
||||
} catch (\Exception $e) {
|
||||
$this->tpl->setNotification('There was a problem generating the ical hash', 'error');
|
||||
}
|
||||
}
|
||||
|
||||
$this->assignUrl();
|
||||
|
||||
return $this->tpl->displayPartial('calendar.export');
|
||||
}
|
||||
|
||||
/**
|
||||
* Assigns the iCal URL to the template.
|
||||
*/
|
||||
private function assignUrl(): void
|
||||
{
|
||||
$icalUrl = '';
|
||||
try {
|
||||
$icalUrl = $this->calendarService->getICalUrl();
|
||||
} catch (\Exception $e) {
|
||||
$this->tpl->setNotification('Could not find ical URL', 'error');
|
||||
}
|
||||
|
||||
$this->tpl->assign('url', $icalUrl);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user