forked from VonRosenchild/ubirimi
/
AddController.php
79 lines (63 loc) · 3.18 KB
/
AddController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
/*
* Copyright (C) 2012-2014 SC Ubirimi SRL <info-copyright@ubirimi.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
namespace Ubirimi\Yongo\Controller\Administration\Workflow;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Ubirimi\Repository\General\UbirimiLog;
use Ubirimi\SystemProduct;
use Ubirimi\UbirimiController;
use Ubirimi\Util;
use Ubirimi\Yongo\Repository\Issue\IssueTypeScheme;
use Ubirimi\Yongo\Repository\Workflow\Workflow;
class AddController extends UbirimiController
{
public function indexAction(Request $request, SessionInterface $session)
{
Util::checkUserIsLoggedInAndRedirect();
$emptyName = false;
$workflowExists = false;
$workflowIssueTypeSchemes = $this->getRepository(IssueTypeScheme::class)->getByClientId($session->get('client/id'), 'workflow');
if ($request->request->has('new_workflow')) {
$name = Util::cleanRegularInputField($request->request->get('name'));
$description = Util::cleanRegularInputField($request->request->get('description'));
if (empty($name))
$emptyName = true;
$duplicateWorkflow = $this->getRepository(Workflow::class)->getByClientIdAndName($session->get('client/id'), mb_strtolower($name));
if ($duplicateWorkflow)
$workflowExists = true;
if (!$emptyName && !$workflowExists) {
$workflowIssueTypeSchemeId = $request->request->get('workflow_issue_type_scheme');
$currentDate = $date = Util::getServerCurrentDateTime();
$workflowId = $this->getRepository(Workflow::class)->createNewMetaData(
$session->get('client/id'),
$workflowIssueTypeSchemeId,
$name,
$description,
$currentDate
);
$this->getRepository(Workflow::class)->createInitialData($session->get('client/id'), $workflowId);
$this->getLogger()->addInfo('ADD Yongo Workflow ' . $name, $this->getLoggerContext());
return new RedirectResponse('/yongo/administration/workflows');
}
}
$menuSelectedCategory = 'issue';
$sectionPageTitle = $session->get('client/settings/title_name') . ' / ' . SystemProduct::SYS_PRODUCT_YONGO_NAME . ' / Create Workflow';
return $this->render(__DIR__ . '/../../../Resources/views/administration/workflow/Add.php', get_defined_vars());
}
}