OneBot: Leantime 改造版源码(BOM/Univer 表格/AI 接管/品牌替换等)
This commit is contained in:
52
app/Domain/Projects/Controllers/ChangeCurrentProject.php
Normal file
52
app/Domain/Projects/Controllers/ChangeCurrentProject.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace Leantime\Domain\Projects\Controllers;
|
||||
|
||||
use Leantime\Core\Controller\Controller;
|
||||
use Leantime\Core\Controller\Frontcontroller;
|
||||
use Leantime\Domain\Projects\Services\Projects as ProjectService;
|
||||
|
||||
class ChangeCurrentProject extends Controller
|
||||
{
|
||||
private ProjectService $projectService;
|
||||
|
||||
public function init(ProjectService $projectService): void
|
||||
{
|
||||
$this->projectService = $projectService;
|
||||
}
|
||||
|
||||
/**
|
||||
* get - handle get requests
|
||||
*/
|
||||
public function get($params)
|
||||
{
|
||||
$id = (int) ($params['id'] ?? 0);
|
||||
|
||||
if (
|
||||
! isset($params['id']) ||
|
||||
! $this->projectService->isUserAssignedToProject(session('userdata.id'), $id) ||
|
||||
! $project = $this->projectService->getProject($id)
|
||||
) {
|
||||
return Frontcontroller::redirect(BASE_URL.'/errors/error404');
|
||||
}
|
||||
|
||||
$this->projectService->changeCurrentSessionProject($id);
|
||||
|
||||
$defaultURL = '/dashboard/show';
|
||||
$redirectFilter = self::dispatch_filter('defaultProjectUrl', $defaultURL, $project);
|
||||
|
||||
return Frontcontroller::redirect(BASE_URL.$redirectFilter);
|
||||
}
|
||||
|
||||
/**
|
||||
* post - handle post requests (via login for example) and redirects to get
|
||||
*/
|
||||
public function post($params)
|
||||
{
|
||||
if (isset($_GET['id'])) {
|
||||
$id = filter_var($_GET['id'], FILTER_SANITIZE_NUMBER_INT);
|
||||
|
||||
return Frontcontroller::redirect(BASE_URL.'/projects/changeCurrentProject/'.$id);
|
||||
}
|
||||
}
|
||||
}
|
||||
64
app/Domain/Projects/Controllers/Createnew.php
Normal file
64
app/Domain/Projects/Controllers/Createnew.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace Leantime\Domain\Projects\Controllers;
|
||||
|
||||
use Leantime\Core\Controller\Controller;
|
||||
use Leantime\Domain\Auth\Models\Roles;
|
||||
use Leantime\Domain\Auth\Services\Auth;
|
||||
use Leantime\Domain\Modulemanager\Services\Modulemanager;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class Createnew extends Controller
|
||||
{
|
||||
private Modulemanager $modulemanager;
|
||||
|
||||
/**
|
||||
* Initializes dependencies.
|
||||
*/
|
||||
public function init(
|
||||
Modulemanager $modulemanager
|
||||
): void {
|
||||
$this->modulemanager = $modulemanager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays the create new project type selection.
|
||||
*
|
||||
* @param array $params Request parameters
|
||||
*/
|
||||
public function get(array $params): Response
|
||||
{
|
||||
Auth::authOrRedirect([Roles::$owner, Roles::$admin, Roles::$manager], true);
|
||||
|
||||
$projectTypes = [
|
||||
'strategy' => [
|
||||
'label' => 'label.set_direction',
|
||||
'btnLabel' => 'label.create_strategy',
|
||||
'description' => 'description.strategy',
|
||||
'url' => 'strategyPro/newStrategy',
|
||||
'image' => 'undraw_thought_process_re_om58.svg',
|
||||
'active' => $this->modulemanager->isModuleAvailable('strategyPro'),
|
||||
],
|
||||
'plan' => [
|
||||
'label' => 'label.map_steps',
|
||||
'btnLabel' => 'label.create_plan',
|
||||
'description' => 'description.plan',
|
||||
'url' => 'pgmPro/newProgram',
|
||||
'image' => 'undraw_join_re_w1lh.svg',
|
||||
'active' => $this->modulemanager->isModuleAvailable('pgmPro'),
|
||||
],
|
||||
'project' => [
|
||||
'label' => 'label.launch_endeavour',
|
||||
'btnLabel' => 'label.create_project',
|
||||
'description' => 'description.project',
|
||||
'url' => 'projects/newProject',
|
||||
'image' => 'undraw_complete_task_u2c3.svg',
|
||||
'active' => true,
|
||||
],
|
||||
];
|
||||
|
||||
$this->tpl->assign('projectTypes', $projectTypes);
|
||||
|
||||
return $this->tpl->displayPartial('projects.createnew');
|
||||
}
|
||||
}
|
||||
91
app/Domain/Projects/Controllers/DelProject.php
Normal file
91
app/Domain/Projects/Controllers/DelProject.php
Normal file
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
namespace Leantime\Domain\Projects\Controllers;
|
||||
|
||||
use Leantime\Core\Controller\Controller;
|
||||
use Leantime\Core\Controller\Frontcontroller;
|
||||
use Leantime\Domain\Auth\Models\Roles;
|
||||
use Leantime\Domain\Auth\Services\Auth;
|
||||
use Leantime\Domain\Projects\Services\Projects as ProjectService;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class DelProject extends Controller
|
||||
{
|
||||
private ProjectService $projectService;
|
||||
|
||||
/**
|
||||
* Initializes dependencies.
|
||||
*/
|
||||
public function init(ProjectService $projectService): void
|
||||
{
|
||||
$this->projectService = $projectService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays the delete project confirmation page.
|
||||
*
|
||||
* @param array $params Request parameters
|
||||
*/
|
||||
public function get(array $params): Response
|
||||
{
|
||||
Auth::authOrRedirect([Roles::$owner, Roles::$admin, Roles::$manager], true);
|
||||
|
||||
if (! Auth::userIsAtLeast(Roles::$manager)) {
|
||||
return $this->tpl->display('errors.error403', responseCode: 403);
|
||||
}
|
||||
|
||||
if (! isset($params['id'])) {
|
||||
return $this->tpl->display('errors.error403', responseCode: 403);
|
||||
}
|
||||
|
||||
$id = (int) $params['id'];
|
||||
|
||||
$project = $this->projectService->getProject($id);
|
||||
if ($project === false) {
|
||||
return Frontcontroller::redirect(BASE_URL.'/errors/error404');
|
||||
}
|
||||
|
||||
if ($this->projectService->hasTickets($id)) {
|
||||
$this->tpl->setNotification($this->language->__('notification.project_has_tasks'), 'info');
|
||||
}
|
||||
|
||||
$this->tpl->assign('project', $project);
|
||||
|
||||
return $this->tpl->display('projects.delProject');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles project deletion.
|
||||
*
|
||||
* @param array $params Request parameters
|
||||
*/
|
||||
public function post(array $params): Response
|
||||
{
|
||||
Auth::authOrRedirect([Roles::$owner, Roles::$admin, Roles::$manager], true);
|
||||
|
||||
if (! Auth::userIsAtLeast(Roles::$manager)) {
|
||||
return $this->tpl->display('errors.error403', responseCode: 403);
|
||||
}
|
||||
|
||||
if (! isset($params['id'])) {
|
||||
return $this->tpl->display('errors.error403', responseCode: 403);
|
||||
}
|
||||
|
||||
$id = (int) $params['id'];
|
||||
|
||||
$result = $this->projectService->deleteProject($id);
|
||||
|
||||
if ($result === false) {
|
||||
$this->tpl->setNotification($this->language->__('notification.no_permission'), 'error');
|
||||
|
||||
return Frontcontroller::redirect(BASE_URL.'/projects/showAll');
|
||||
}
|
||||
|
||||
$this->projectService->resetCurrentProject();
|
||||
$this->projectService->setCurrentProject();
|
||||
|
||||
$this->tpl->setNotification($this->language->__('notification.project_deleted'), 'success');
|
||||
|
||||
return Frontcontroller::redirect(BASE_URL.'/projects/showAll');
|
||||
}
|
||||
}
|
||||
87
app/Domain/Projects/Controllers/DuplicateProject.php
Normal file
87
app/Domain/Projects/Controllers/DuplicateProject.php
Normal file
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
namespace Leantime\Domain\Projects\Controllers;
|
||||
|
||||
use Illuminate\Contracts\Container\BindingResolutionException;
|
||||
use Leantime\Core\Controller\Controller;
|
||||
use Leantime\Core\Controller\Frontcontroller;
|
||||
use Leantime\Domain\Auth\Models\Roles;
|
||||
use Leantime\Domain\Auth\Services\Auth;
|
||||
use Leantime\Domain\Clients\Services\Clients as ClientService;
|
||||
use Leantime\Domain\Projects\Services\Projects as ProjectService;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class DuplicateProject extends Controller
|
||||
{
|
||||
private ProjectService $projectService;
|
||||
|
||||
private ClientService $clientService;
|
||||
|
||||
/**
|
||||
* Initializes dependencies.
|
||||
*/
|
||||
public function init(
|
||||
ProjectService $projectService,
|
||||
ClientService $clientService
|
||||
): void {
|
||||
$this->projectService = $projectService;
|
||||
$this->clientService = $clientService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays the duplicate-project form.
|
||||
*
|
||||
* @param array $params Request parameters
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function get(array $params): Response
|
||||
{
|
||||
Auth::authOrRedirect([Roles::$owner, Roles::$admin, Roles::$manager], true);
|
||||
|
||||
$id = (int) ($params['id'] ?? $_GET['id'] ?? 0);
|
||||
|
||||
if (! Auth::userIsAtLeast(Roles::$manager) || $id <= 0) {
|
||||
return $this->tpl->displayPartial('errors.error403', responseCode: 403);
|
||||
}
|
||||
|
||||
$this->tpl->assign('allClients', $this->clientService->getAll());
|
||||
$this->tpl->assign('project', $this->projectService->getProject($id));
|
||||
|
||||
return $this->tpl->displayPartial('projects.duplicateProject');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the project duplication request.
|
||||
*
|
||||
* @param array $params Request parameters
|
||||
*
|
||||
* @throws BindingResolutionException
|
||||
*/
|
||||
public function post(array $params): Response
|
||||
{
|
||||
Auth::authOrRedirect([Roles::$owner, Roles::$admin, Roles::$manager], true);
|
||||
|
||||
if (! Auth::userIsAtLeast(Roles::$manager)) {
|
||||
return $this->tpl->displayPartial('errors.error403', responseCode: 403);
|
||||
}
|
||||
|
||||
$id = (int) ($params['id'] ?? $_GET['id'] ?? 0);
|
||||
$assignSameUsers = isset($params['assignSameUsers']);
|
||||
|
||||
$result = $this->projectService->duplicateProject(
|
||||
$id,
|
||||
(int) $params['clientId'],
|
||||
$params['projectName'],
|
||||
$params['startDate'] ?? '',
|
||||
$assignSameUsers
|
||||
);
|
||||
|
||||
$this->tpl->setNotification(
|
||||
sprintf($this->language->__('notifications.project_copied_successfully'), BASE_URL.'/projects/changeCurrentProject/'.$result),
|
||||
'success'
|
||||
);
|
||||
|
||||
return Frontcontroller::redirect(BASE_URL.'/projects/duplicateProject/'.$id);
|
||||
}
|
||||
}
|
||||
0
app/Domain/Projects/Controllers/EditProject.php
Normal file
0
app/Domain/Projects/Controllers/EditProject.php
Normal file
156
app/Domain/Projects/Controllers/NewProject.php
Normal file
156
app/Domain/Projects/Controllers/NewProject.php
Normal file
@@ -0,0 +1,156 @@
|
||||
<?php
|
||||
|
||||
namespace Leantime\Domain\Projects\Controllers;
|
||||
|
||||
use Leantime\Core\Controller\Controller;
|
||||
use Leantime\Core\Controller\Frontcontroller;
|
||||
use Leantime\Core\Support\FromFormat;
|
||||
use Leantime\Domain\Auth\Models\Roles;
|
||||
use Leantime\Domain\Auth\Services\Auth;
|
||||
use Leantime\Domain\Clients\Services\Clients as ClientService;
|
||||
use Leantime\Domain\Projects\Services\Projects as ProjectService;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class NewProject extends Controller
|
||||
{
|
||||
private ClientService $clientService;
|
||||
|
||||
private ProjectService $projectService;
|
||||
|
||||
/**
|
||||
* Initializes dependencies.
|
||||
*/
|
||||
public function init(
|
||||
ClientService $clientService,
|
||||
ProjectService $projectService
|
||||
): void {
|
||||
$this->clientService = $clientService;
|
||||
$this->projectService = $projectService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays the new project form.
|
||||
*
|
||||
* @param array $params Request parameters
|
||||
*/
|
||||
public function get(array $params): Response
|
||||
{
|
||||
Auth::authOrRedirect([Roles::$owner, Roles::$admin, Roles::$manager], true);
|
||||
|
||||
if (! session()->exists('lastPage')) {
|
||||
session(['lastPage' => BASE_URL.'/projects/showAll']);
|
||||
}
|
||||
|
||||
$defaultParent = $_GET['parent'] ?? '';
|
||||
if ($defaultParent === '') {
|
||||
// When creating a project from within a container project (e.g. a program or a
|
||||
// strategy), nest the new project under it by default so it's immediately
|
||||
// associated. The parent picker still lets the user change or clear it.
|
||||
$contextProject = $this->projectService->getProject(session('currentProject'));
|
||||
if (is_array($contextProject) && in_array($contextProject['type'] ?? '', ['program', 'strategy'], true)) {
|
||||
$defaultParent = (string) session('currentProject');
|
||||
}
|
||||
}
|
||||
|
||||
$values = $this->projectService->getNewProjectDefaults($defaultParent);
|
||||
|
||||
$this->tpl->assign('menuTypes', $this->projectService->getMenuTypes());
|
||||
$this->tpl->assign('project', $values);
|
||||
$this->tpl->assign('availableUsers', $this->projectService->getAllUsers());
|
||||
$this->tpl->assign('clients', $this->clientService->getAll());
|
||||
$this->tpl->assign('projectTypes', $this->projectService->getProjectTypes());
|
||||
$this->tpl->assign('info', '');
|
||||
|
||||
return $this->tpl->display('projects.newProject');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles new project form submission.
|
||||
*
|
||||
* @param array $params Request parameters
|
||||
*/
|
||||
public function post(array $params): Response
|
||||
{
|
||||
Auth::authOrRedirect([Roles::$owner, Roles::$admin, Roles::$manager], true);
|
||||
|
||||
if (! session()->exists('lastPage')) {
|
||||
session(['lastPage' => BASE_URL.'/projects/showAll']);
|
||||
}
|
||||
|
||||
$hourBudget = (! isset($_POST['hourBudget']) || $_POST['hourBudget'] == '' || $_POST['hourBudget'] == null)
|
||||
? '0'
|
||||
: $_POST['hourBudget'];
|
||||
|
||||
$assignedUsers = (isset($_POST['editorId']) && count($_POST['editorId']))
|
||||
? $_POST['editorId']
|
||||
: [];
|
||||
|
||||
// A project may only be nested under a CONTAINER (a program or a strategy) — never under
|
||||
// another regular project. Only keep the parent if the candidate is actually a
|
||||
// program/strategy; anything else (incl. a regular project) leaves it un-nested. (The
|
||||
// service validates this too, since addProject is JSON-RPC reachable.)
|
||||
//
|
||||
// If the parent field was on the form, respect the user's explicit choice — including an
|
||||
// intentional "none" (empty) selection, so they can clear the parent. Only when the field
|
||||
// was NOT submitted do we infer the container from the URL ("Add Project" button) or the
|
||||
// current project.
|
||||
if (isset($_POST['parent'])) {
|
||||
$parentCandidate = $_POST['parent'];
|
||||
} else {
|
||||
$parentCandidate = $_GET['parent'] ?? (string) session('currentProject');
|
||||
}
|
||||
|
||||
$parent = '';
|
||||
if ($parentCandidate !== '' && $parentCandidate !== '0') {
|
||||
$parentProject = $this->projectService->getProject((int) $parentCandidate);
|
||||
if (is_array($parentProject) && in_array($parentProject['type'] ?? '', ['program', 'strategy'], true)) {
|
||||
$parent = (string) $parentCandidate;
|
||||
}
|
||||
}
|
||||
|
||||
$values = [
|
||||
'name' => $_POST['name'] ?? '',
|
||||
'details' => $_POST['details'] ?? '',
|
||||
'clientId' => $_POST['clientId'] ?? 0,
|
||||
'hourBudget' => $hourBudget,
|
||||
'assignedUsers' => $assignedUsers,
|
||||
'dollarBudget' => $_POST['dollarBudget'] ?? 0,
|
||||
'state' => $_POST['projectState'],
|
||||
'psettings' => $_POST['globalProjectUserAccess'],
|
||||
'menuType' => $_POST['menuType'] ?? 'default',
|
||||
'type' => $_POST['type'] ?? 'project',
|
||||
'parent' => $parent,
|
||||
'start' => format(value: $_POST['start'], fromFormat: FromFormat::UserDateStartOfDay)->isoDateTime(),
|
||||
'end' => $_POST['end'] ? format(value: $_POST['end'], fromFormat: FromFormat::UserDateEndOfDay)->isoDateTime() : '',
|
||||
];
|
||||
|
||||
if ($values['name'] === '') {
|
||||
$this->tpl->setNotification($this->language->__('notification.no_project_name'), 'error');
|
||||
} elseif ($values['clientId'] === '') {
|
||||
$this->tpl->setNotification($this->language->__('notification.no_client'), 'error');
|
||||
} else {
|
||||
$id = $this->projectService->addProject($values);
|
||||
$this->projectService->changeCurrentSessionProject($id);
|
||||
|
||||
$this->projectService->notifyProjectCreated($id, $values['name'], session('userdata.name'));
|
||||
|
||||
$this->tpl->sendConfetti();
|
||||
$this->tpl->setNotification(
|
||||
sprintf($this->language->__('notifications.project_created_successfully'), BASE_URL.'/leancanvas/simpleCanvas/'),
|
||||
'success',
|
||||
'project_created'
|
||||
);
|
||||
|
||||
return Frontcontroller::redirect(BASE_URL.'/projects/showProject/'.$id);
|
||||
}
|
||||
|
||||
$this->tpl->assign('menuTypes', $this->projectService->getMenuTypes());
|
||||
$this->tpl->assign('project', $values);
|
||||
$this->tpl->assign('availableUsers', $this->projectService->getAllUsers());
|
||||
$this->tpl->assign('clients', $this->clientService->getAll());
|
||||
$this->tpl->assign('projectTypes', $this->projectService->getProjectTypes());
|
||||
$this->tpl->assign('info', '');
|
||||
|
||||
return $this->tpl->display('projects.newProject');
|
||||
}
|
||||
}
|
||||
68
app/Domain/Projects/Controllers/ProjectImage.php
Normal file
68
app/Domain/Projects/Controllers/ProjectImage.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace Leantime\Domain\Projects\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Leantime\Core\Http\Responses\ImageResponse;
|
||||
use Leantime\Domain\Projects\Services\Projects as ProjectService;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
/**
|
||||
* Serves and updates project avatars.
|
||||
*
|
||||
* A native Laravel controller (constructor DI, route-bound actions). Relocated from the
|
||||
* retired Api\Controllers\Projects. Bound in Projects/routes.php at the canonical
|
||||
* /projects/projectImage/{id} plus the backward-compatible /api/projects alias used by
|
||||
* core templates and the plugin submodule. The JSON sort/status operations the old
|
||||
* controller also multiplexed onto /api/projects now go through JSON-RPC.
|
||||
*/
|
||||
class ProjectImage
|
||||
{
|
||||
public function __construct(private ProjectService $projectService) {}
|
||||
|
||||
/**
|
||||
* GET — returns the project avatar as a binary/SVG response.
|
||||
*
|
||||
* The id comes from the canonical path segment ({id}) or the legacy ?projectAvatar=
|
||||
* query param. Avatars are low-sensitivity images rendered across the app (including
|
||||
* arbitrary project rows on admin screens), so the read stays open to any authenticated user.
|
||||
*/
|
||||
public function show(Request $request, ?string $id = null): ImageResponse|Response
|
||||
{
|
||||
$id = $request->query('projectAvatar', $id);
|
||||
|
||||
if (empty($id)) {
|
||||
return response()->json(['status' => 'failure'], 400);
|
||||
}
|
||||
|
||||
return new ImageResponse($this->projectService->getProjectAvatar($id));
|
||||
}
|
||||
|
||||
/**
|
||||
* POST — uploads a new avatar for the active project.
|
||||
*
|
||||
* The avatar always targets session('currentProject'); the upload requires manage
|
||||
* rights on that project (the legacy endpoint had no role check at all).
|
||||
*/
|
||||
public function upload(): Response
|
||||
{
|
||||
if (! isset($_FILES['file'])) {
|
||||
return response()->json(['error' => 'File not included'], 400);
|
||||
}
|
||||
|
||||
$projectId = (int) session('currentProject');
|
||||
|
||||
if (! $this->projectService->userCanManageProject($projectId)) {
|
||||
return response()->json(['status' => 'unauthorized'], 403);
|
||||
}
|
||||
|
||||
$_FILES['file']['name'] = 'profileImage-'.$projectId.'.png';
|
||||
|
||||
$this->projectService->setProjectAvatar($_FILES, $projectId);
|
||||
|
||||
session(['msg' => 'PICTURE_CHANGED']);
|
||||
session(['msgT' => 'success']);
|
||||
|
||||
return response()->json(['status' => 'ok']);
|
||||
}
|
||||
}
|
||||
113
app/Domain/Projects/Controllers/ShowAll.php
Normal file
113
app/Domain/Projects/Controllers/ShowAll.php
Normal file
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
namespace Leantime\Domain\Projects\Controllers;
|
||||
|
||||
use Leantime\Core\Controller\Controller;
|
||||
use Leantime\Domain\Auth\Models\Roles;
|
||||
use Leantime\Domain\Auth\Services\Auth;
|
||||
use Leantime\Domain\Bom\Services\Bom as BomService;
|
||||
use Leantime\Domain\Bom\Services\MasterRef as MasterRefService;
|
||||
use Leantime\Domain\Menu\Repositories\Menu as MenuRepository;
|
||||
use Leantime\Domain\Projects\Services\Projects as ProjectService;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class ShowAll extends Controller
|
||||
{
|
||||
private ProjectService $projectService;
|
||||
|
||||
private MenuRepository $menuRepo;
|
||||
|
||||
private BomService $bomService;
|
||||
|
||||
private MasterRefService $masterRefService;
|
||||
|
||||
/**
|
||||
* Initializes dependencies.
|
||||
*/
|
||||
public function init(
|
||||
ProjectService $projectService,
|
||||
MenuRepository $menuRepo,
|
||||
BomService $bomService,
|
||||
MasterRefService $masterRefService
|
||||
): void {
|
||||
$this->projectService = $projectService;
|
||||
$this->menuRepo = $menuRepo;
|
||||
$this->bomService = $bomService;
|
||||
$this->masterRefService = $masterRefService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays the list of all projects.
|
||||
*
|
||||
* @param array $params Request parameters
|
||||
*/
|
||||
public function get(array $params): Response
|
||||
{
|
||||
Auth::authOrRedirect([Roles::$owner, Roles::$admin, Roles::$manager], true);
|
||||
|
||||
if (! Auth::userIsAtLeast(Roles::$manager)) {
|
||||
return $this->tpl->display('errors.error403', responseCode: 403);
|
||||
}
|
||||
|
||||
if (! session()->exists('showClosedProjects')) {
|
||||
session(['showClosedProjects' => false]);
|
||||
}
|
||||
|
||||
$this->tpl->assign('role', session('userdata.role'));
|
||||
|
||||
if (Auth::userIsAtLeast(Roles::$admin)) {
|
||||
$allProjects = $this->projectService->getAll(session('showClosedProjects'));
|
||||
} else {
|
||||
$allProjects = $this->projectService->getClientManagerProjects(session('userdata.id'), session('userdata.clientId'));
|
||||
}
|
||||
|
||||
// 为每个项目附加其关联的全局主数据(BOM/工艺文件/工具清单),供概览页展开显示
|
||||
$typeNames = ['bom' => 'BOM', 'process' => '工艺文件', 'tooling' => '工具清单'];
|
||||
foreach ($allProjects as &$project) {
|
||||
$projectId = (int) $project['id'];
|
||||
$linkedMasters = [];
|
||||
foreach ($this->masterRefService->getRefs($projectId) as $ref) {
|
||||
$master = $this->bomService->getBom((int) $ref['masterId']);
|
||||
if ($master === false) {
|
||||
continue;
|
||||
}
|
||||
$master['refId'] = (int) $ref['id'];
|
||||
$master['typeName'] = $typeNames[$master['type'] ?? 'bom'] ?? 'BOM';
|
||||
$linkedMasters[] = $master;
|
||||
}
|
||||
$project['linkedMasters'] = $linkedMasters;
|
||||
}
|
||||
unset($project);
|
||||
|
||||
$this->tpl->assign('allProjects', $allProjects);
|
||||
|
||||
// 项目概览甘特图数据(frappe-gantt 兼容 tasks)
|
||||
$gantt = $this->projectService->getProjectGanttData($allProjects);
|
||||
$this->tpl->assign('ganttTasks', $gantt['tasks'] ?? []);
|
||||
|
||||
$this->tpl->assign('menuTypes', $this->menuRepo->getMenuTypes());
|
||||
$this->tpl->assign('showClosedProjects', session('showClosedProjects'));
|
||||
|
||||
return $this->tpl->display('projects.showAll');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles filter changes (show/hide closed projects).
|
||||
*
|
||||
* @param array $params Request parameters
|
||||
*/
|
||||
public function post(array $params): Response
|
||||
{
|
||||
Auth::authOrRedirect([Roles::$owner, Roles::$admin, Roles::$manager], true);
|
||||
|
||||
if (isset($_POST['hideClosedProjects'])) {
|
||||
session(['showClosedProjects' => false]);
|
||||
}
|
||||
|
||||
if (isset($_POST['showClosedProjects'])) {
|
||||
session(['showClosedProjects' => true]);
|
||||
}
|
||||
|
||||
return $this->get($params);
|
||||
}
|
||||
}
|
||||
41
app/Domain/Projects/Controllers/ShowMy.php
Normal file
41
app/Domain/Projects/Controllers/ShowMy.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace Leantime\Domain\Projects\Controllers;
|
||||
|
||||
use Leantime\Core\Controller\Controller;
|
||||
use Leantime\Domain\Menu\Services\Menu;
|
||||
use Leantime\Domain\Projects\Services\Projects as ProjectService;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class ShowMy extends Controller
|
||||
{
|
||||
private ProjectService $projectService;
|
||||
|
||||
private Menu $menuService;
|
||||
|
||||
public function init(
|
||||
ProjectService $projectService,
|
||||
Menu $menuService
|
||||
): void {
|
||||
$this->projectService = $projectService;
|
||||
$this->menuService = $menuService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays the project hub for the current user.
|
||||
*/
|
||||
public function get(): Response
|
||||
{
|
||||
$clientId = (isset($_GET['client']) === true && $_GET['client'] != '') ? (int) $_GET['client'] : null;
|
||||
|
||||
$hubData = $this->projectService->getProjectHubData(session('userdata.id'), $clientId);
|
||||
|
||||
$this->tpl->assign('projectTypeAvatars', $this->menuService->getProjectTypeAvatars());
|
||||
$this->tpl->assign('currentClientName', $hubData['currentClientName']);
|
||||
$this->tpl->assign('currentClient', $hubData['currentClient']);
|
||||
$this->tpl->assign('clients', $hubData['clients']);
|
||||
$this->tpl->assign('allProjects', $hubData['allProjects']);
|
||||
|
||||
return $this->tpl->display('projects.projectHub');
|
||||
}
|
||||
}
|
||||
310
app/Domain/Projects/Controllers/ShowProject.php
Normal file
310
app/Domain/Projects/Controllers/ShowProject.php
Normal file
@@ -0,0 +1,310 @@
|
||||
<?php
|
||||
|
||||
namespace Leantime\Domain\Projects\Controllers;
|
||||
|
||||
use Leantime\Core\Controller\Controller;
|
||||
use Leantime\Core\Controller\Frontcontroller;
|
||||
use Leantime\Domain\Auth\Models\Roles;
|
||||
use Leantime\Domain\Auth\Services\Auth;
|
||||
use Leantime\Domain\Bom\Services\Bom as BomService;
|
||||
use Leantime\Domain\Bom\Services\MasterRef as MasterRefService;
|
||||
use Leantime\Domain\Clients\Services\Clients as ClientService;
|
||||
use Leantime\Domain\Projects\Services\Projects as ProjectService;
|
||||
use Leantime\Domain\Tickets\Services\Tickets as TicketService;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class ShowProject extends Controller
|
||||
{
|
||||
private ProjectService $projectService;
|
||||
|
||||
private TicketService $ticketService;
|
||||
|
||||
private ClientService $clientService;
|
||||
|
||||
private BomService $bomService;
|
||||
|
||||
private MasterRefService $masterRefService;
|
||||
|
||||
/**
|
||||
* Initializes dependencies.
|
||||
*/
|
||||
public function init(
|
||||
ProjectService $projectService,
|
||||
TicketService $ticketService,
|
||||
ClientService $clientService,
|
||||
BomService $bomService,
|
||||
MasterRefService $masterRefService
|
||||
): void {
|
||||
Auth::authOrRedirect([Roles::$owner, Roles::$admin, Roles::$manager]);
|
||||
|
||||
$this->projectService = $projectService;
|
||||
$this->ticketService = $ticketService;
|
||||
$this->clientService = $clientService;
|
||||
$this->bomService = $bomService;
|
||||
$this->masterRefService = $masterRefService;
|
||||
|
||||
if (! session()->exists('lastPage')) {
|
||||
session(['lastPage' => CURRENT_URL]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays the project settings page.
|
||||
*
|
||||
* @param array $params Request parameters
|
||||
*/
|
||||
public function get(array $params): Response
|
||||
{
|
||||
if (! isset($params['id'])) {
|
||||
return $this->tpl->display('errors.error404', responseCode: 404);
|
||||
}
|
||||
|
||||
$id = (int) $params['id'];
|
||||
|
||||
if (Auth::userHasRole(Roles::$manager)) {
|
||||
if ($this->projectService->isUserAssignedToProject(session('userdata.id'), $id) === false) {
|
||||
return Frontcontroller::redirect(BASE_URL.'/errors/error403');
|
||||
}
|
||||
}
|
||||
|
||||
$project = $this->projectService->getProject($id);
|
||||
|
||||
if (! isset($project['id'])) {
|
||||
return Frontcontroller::redirect(BASE_URL.'/errors/error404');
|
||||
}
|
||||
|
||||
if (session('currentProject') != $project['id']) {
|
||||
$this->projectService->changeCurrentSessionProject($project['id']);
|
||||
}
|
||||
|
||||
session(['lastPage' => BASE_URL.'/projects/showProject/'.$id]);
|
||||
|
||||
$project['assignedUsers'] = $this->projectService->getUsersAssignedToProject($id, true);
|
||||
|
||||
$this->assignIntegrationSettings($id);
|
||||
$this->assignTemplateVars($id, $project);
|
||||
$this->assignMasterData($id);
|
||||
|
||||
return $this->tpl->display('projects.showProject');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles project settings form submissions.
|
||||
*
|
||||
* @param array $params Request parameters
|
||||
*/
|
||||
public function post(array $params): Response
|
||||
{
|
||||
if (! isset($params['id'])) {
|
||||
return $this->tpl->display('errors.error404', responseCode: 404);
|
||||
}
|
||||
|
||||
$id = (int) $params['id'];
|
||||
|
||||
if (Auth::userHasRole(Roles::$manager)) {
|
||||
if ($this->projectService->isUserAssignedToProject(session('userdata.id'), $id) === false) {
|
||||
return Frontcontroller::redirect(BASE_URL.'/errors/error403');
|
||||
}
|
||||
}
|
||||
|
||||
$project = $this->projectService->getProject($id);
|
||||
|
||||
if (! isset($project['id'])) {
|
||||
return Frontcontroller::redirect(BASE_URL.'/errors/error404');
|
||||
}
|
||||
|
||||
if (session('currentProject') != $project['id']) {
|
||||
$this->projectService->changeCurrentSessionProject($project['id']);
|
||||
}
|
||||
|
||||
// Handle Mattermost integration
|
||||
if (isset($_POST['mattermostSave'])) {
|
||||
$this->projectService->saveMattermostWebhook($id, $_POST['mattermostWebhookURL']);
|
||||
$this->tpl->setNotification($this->language->__('notification.saved_mattermost_webhook'), 'success');
|
||||
}
|
||||
|
||||
// Handle Slack integration
|
||||
if (isset($_POST['slackSave'])) {
|
||||
$this->projectService->saveSlackWebhook($id, $_POST['slackWebhookURL']);
|
||||
$this->tpl->setNotification($this->language->__('notification.saved_slack_webhook'), 'success');
|
||||
}
|
||||
|
||||
// Handle Zulip integration
|
||||
if (isset($_POST['zulipSave'])) {
|
||||
$zulipResult = $this->projectService->saveZulipWebhook($id, $_POST);
|
||||
|
||||
if ($zulipResult['saved']) {
|
||||
$this->tpl->setNotification($this->language->__('notification.saved_zulip_webhook'), 'success');
|
||||
} else {
|
||||
$this->tpl->setNotification($this->language->__('notification.error_zulip_webhook_fill_out_fields'), 'error');
|
||||
}
|
||||
|
||||
$this->tpl->assign('zulipHook', $zulipResult['hook']);
|
||||
}
|
||||
|
||||
// Handle Telegram integration
|
||||
if (isset($_POST['telegramSave'])) {
|
||||
$telegramResult = $this->projectService->saveTelegramWebhook($id, $_POST);
|
||||
|
||||
if ($telegramResult['saved']) {
|
||||
$this->tpl->setNotification($this->language->__('notification.saved_telegram_webhook'), 'success');
|
||||
} else {
|
||||
$errorKey = $telegramResult['error'] === 'missing_token'
|
||||
? 'notification.error_telegram_missing_token'
|
||||
: 'notification.error_telegram_chat_not_found';
|
||||
$this->tpl->setNotification($this->language->__($errorKey), 'error');
|
||||
}
|
||||
|
||||
$this->tpl->assign('telegramHook', $telegramResult['hook']);
|
||||
}
|
||||
|
||||
// Handle Discord integration
|
||||
if (isset($_POST['discordSave'])) {
|
||||
$this->projectService->saveDiscordWebhooks($id, $_POST);
|
||||
$this->tpl->setNotification($this->language->__('notification.saved_discord_webhook'), 'success');
|
||||
}
|
||||
|
||||
// Handle status label settings
|
||||
if (isset($_POST['submitSettings'])) {
|
||||
if (isset($_POST['labelKeys']) && is_array($_POST['labelKeys']) && count($_POST['labelKeys']) > 0) {
|
||||
if ($this->ticketService->saveStatusLabels($_POST)) {
|
||||
$this->tpl->setNotification($this->language->__('notification.new_status_saved'), 'success');
|
||||
} else {
|
||||
$this->tpl->setNotification($this->language->__('notification.error_saving_status'), 'error');
|
||||
}
|
||||
} else {
|
||||
$this->tpl->setNotification($this->language->__('notification.at_least_one_status'), 'error');
|
||||
}
|
||||
}
|
||||
|
||||
// Handle user assignment
|
||||
if (isset($_POST['saveUsers'])) {
|
||||
$assignedUsers = (isset($_POST['editorId']) && count($_POST['editorId']))
|
||||
? $_POST['editorId']
|
||||
: [];
|
||||
|
||||
$this->projectService->updateProjectUsers($id, $assignedUsers, $_POST);
|
||||
$this->tpl->setNotification($this->language->__('notifications.user_was_added_to_project'), 'success');
|
||||
}
|
||||
|
||||
// Handle project save
|
||||
if (isset($_POST['save'])) {
|
||||
$values = [
|
||||
'name' => $_POST['name'],
|
||||
'details' => $_POST['details'],
|
||||
'clientId' => $_POST['clientId'],
|
||||
'state' => $_POST['projectState'],
|
||||
'hourBudget' => $_POST['hourBudget'],
|
||||
'dollarBudget' => $_POST['dollarBudget'],
|
||||
'psettings' => $_POST['globalProjectUserAccess'],
|
||||
'menuType' => $_POST['menuType'],
|
||||
'type' => $_POST['type'] ?? $project['type'],
|
||||
'parent' => $_POST['parent'] ?? '',
|
||||
'start' => isset($_POST['start']) && dtHelper()->isValidDateString($_POST['start']) ? dtHelper()->parseUserDateTime($_POST['start'])->formatDateTimeForDb() : '',
|
||||
'end' => isset($_POST['end']) && dtHelper()->isValidDateString($_POST['end']) ? dtHelper()->parseUserDateTime($_POST['end'])->formatDateTimeForDb() : '',
|
||||
];
|
||||
|
||||
if ($values['name'] !== '') {
|
||||
if ($this->projectService->hasTickets($id) && $values['state'] == 1) {
|
||||
$this->tpl->setNotification($this->language->__('notification.project_has_tickets'), 'error');
|
||||
} else {
|
||||
$this->projectService->editProjectAndNotify(
|
||||
$values,
|
||||
$id,
|
||||
$project,
|
||||
CURRENT_URL,
|
||||
session('userdata.id'),
|
||||
session('userdata.name')
|
||||
);
|
||||
$this->tpl->setNotification($this->language->__('notification.project_saved'), 'success');
|
||||
|
||||
return Frontcontroller::redirect(BASE_URL.'/projects/showProject/'.$id);
|
||||
}
|
||||
} else {
|
||||
$this->tpl->setNotification($this->language->__('notification.no_project_name'), 'error');
|
||||
}
|
||||
}
|
||||
|
||||
// Handle master data linking (关联全局主数据到项目)
|
||||
if (isset($_POST['linkMaster']) && ! empty($_POST['masterId'])) {
|
||||
$masterId = (int) $_POST['masterId'];
|
||||
if ($this->masterRefService->link($id, $masterId) > 0) {
|
||||
$this->tpl->setNotification($this->language->__('notification.master_linked', '主数据已关联到项目'), 'success');
|
||||
} else {
|
||||
$this->tpl->setNotification($this->language->__('notification.master_link_failed', '关联失败'), 'error');
|
||||
}
|
||||
}
|
||||
|
||||
session(['lastPage' => BASE_URL.'/projects/showProject/'.$id]);
|
||||
|
||||
$project['assignedUsers'] = $this->projectService->getUsersAssignedToProject($id, true);
|
||||
|
||||
$this->assignIntegrationSettings($id);
|
||||
$this->assignTemplateVars($id, $project);
|
||||
$this->assignMasterData($id);
|
||||
|
||||
return $this->tpl->display('projects.showProject');
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads and assigns integration settings to the template.
|
||||
*/
|
||||
private function assignIntegrationSettings(int $projectId): void
|
||||
{
|
||||
$settings = $this->projectService->getProjectIntegrationSettings($projectId);
|
||||
|
||||
array_map([$this->tpl, 'assign'], array_keys($settings), array_values($settings));
|
||||
}
|
||||
|
||||
/**
|
||||
* Assigns common template variables.
|
||||
*/
|
||||
private function assignTemplateVars(int $projectId, array $project): void
|
||||
{
|
||||
$this->tpl->assign('availableUsers', $this->projectService->getAllUsers());
|
||||
$this->tpl->assign('clients', $this->clientService->getAll());
|
||||
$this->tpl->assign('todoStatus', $this->ticketService->getStatusLabels());
|
||||
$this->tpl->assign('employees', $this->projectService->getEmployees());
|
||||
$this->tpl->assign('project', $project);
|
||||
$this->tpl->assign('menuTypes', $this->projectService->getMenuTypes());
|
||||
$this->tpl->assign('projectTypes', $this->projectService->getProjectTypes());
|
||||
$this->tpl->assign('state', ['open', 'closed']);
|
||||
$this->tpl->assign('role', session('userdata.role'));
|
||||
$this->tpl->assign('projectMuteCount', $this->projectService->getMuteCountForProject($projectId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载项目已引用的主数据 + 可关联的全局主数据列表,供「主数据」tab 使用。
|
||||
*/
|
||||
private function assignMasterData(int $projectId): void
|
||||
{
|
||||
$typeNames = ['bom' => 'BOM', 'process' => '工艺文件', 'tooling' => '工具清单'];
|
||||
|
||||
// 已引用
|
||||
$refs = $this->masterRefService->getRefs($projectId);
|
||||
$linked = [];
|
||||
foreach ($refs as $ref) {
|
||||
$master = $this->bomService->getBom((int) $ref['masterId']);
|
||||
if ($master !== false) {
|
||||
$ref['master'] = $master;
|
||||
$linked[] = $ref;
|
||||
}
|
||||
}
|
||||
|
||||
// 可关联的全局主数据(排除已关联)
|
||||
$linkedMasterIds = array_map(fn ($r) => (int) $r['masterId'], $refs);
|
||||
$available = [];
|
||||
foreach (['bom', 'process', 'tooling'] as $type) {
|
||||
foreach ($this->bomService->getMasters($type, 0) as $m) {
|
||||
if (in_array((int) $m['id'], $linkedMasterIds, true)) {
|
||||
continue;
|
||||
}
|
||||
$m['typeName'] = $typeNames[$m['type'] ?? 'bom'] ?? 'BOM';
|
||||
$available[] = $m;
|
||||
}
|
||||
}
|
||||
|
||||
$this->tpl->assign('linkedMasters', $linked);
|
||||
$this->tpl->assign('availableMasters', $available);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user