Replace @see tags with @inheritDoc tags
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / acp / form / TemplateEditForm.class.php
CommitLineData
12aa6f89
MW
1<?php
2namespace wcf\acp\form;
12aa6f89
MW
3use wcf\data\template\Template;
4use wcf\data\template\TemplateAction;
5use wcf\form\AbstractForm;
6use wcf\system\exception\IllegalLinkException;
12aa6f89 7use wcf\system\WCF;
12aa6f89
MW
8
9/**
10 * Shows the form for adding new templates.
e3369fd2 11 *
12aa6f89 12 * @author Marcel Werk
7d739af0 13 * @copyright 2001-2016 WoltLab GmbH
12aa6f89
MW
14 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
15 * @package com.woltlab.wcf
16 * @subpackage acp.form
17 * @category Community Framework
18 */
19class TemplateEditForm extends TemplateAddForm {
20 /**
0fcfe5f6 21 * @inheritDoc
12aa6f89
MW
22 */
23 public $activeMenuItem = 'wcf.acp.menu.link.template';
24
25 /**
26 * template id
06355ec3 27 * @var integer
12aa6f89
MW
28 */
29 public $templateID = 0;
30
31 /**
32 * template object
0ad90fc3 33 * @var \wcf\data\template\Template
12aa6f89
MW
34 */
35 public $template = null;
36
37 /**
0fcfe5f6 38 * @inheritDoc
12aa6f89
MW
39 */
40 public function readParameters() {
41 parent::readParameters();
e3369fd2 42
12aa6f89
MW
43 if (isset($_REQUEST['id'])) $this->templateID = intval($_REQUEST['id']);
44 $this->template = new Template($this->templateID);
45 if (!$this->template->templateID || !$this->template->templateGroupID) {
46 throw new IllegalLinkException();
47 }
48 $this->packageID = $this->template->packageID;
49 }
50
51 /**
0fcfe5f6 52 * @inheritDoc
12aa6f89
MW
53 */
54 protected function validateName() {
55 if ($this->tplName != $this->template->templateName) {
56 parent::validateName();
57 }
58 }
59
60 /**
0fcfe5f6 61 * @inheritDoc
12aa6f89
MW
62 */
63 protected function validateGroup() {
64 if ($this->templateGroupID != $this->template->templateGroupID) {
65 parent::validateName();
66 }
67 }
68
69 /**
0fcfe5f6 70 * @inheritDoc
12aa6f89
MW
71 */
72 public function save() {
73 AbstractForm::save();
74
058cbd6a 75 $this->objectAction = new TemplateAction([$this->template], 'update', ['data' => array_merge($this->additionalFields, [
12aa6f89
MW
76 'templateName' => $this->tplName,
77 'templateGroupID' => $this->templateGroupID,
78 'lastModificationTime' => TIME_NOW
058cbd6a 79 ]), 'source' => $this->templateSource]);
12aa6f89
MW
80 $this->objectAction->executeAction();
81 $this->saved();
82
83 // show success
058cbd6a 84 WCF::getTPL()->assign([
12aa6f89 85 'success' => true
058cbd6a 86 ]);
12aa6f89
MW
87 }
88
89 /**
0fcfe5f6 90 * @inheritDoc
12aa6f89
MW
91 */
92 public function readData() {
93 parent::readData();
e3369fd2 94
12aa6f89
MW
95 if (!count($_POST)) {
96 $this->tplName = $this->template->templateName;
97 $this->templateSource = $this->template->getSource();
98 $this->templateGroupID = $this->template->templateGroupID;
99 }
100 }
101
102 /**
0fcfe5f6 103 * @inheritDoc
12aa6f89
MW
104 */
105 public function assignVariables() {
106 parent::assignVariables();
107
058cbd6a 108 WCF::getTPL()->assign([
12aa6f89
MW
109 'action' => 'edit',
110 'templateID' => $this->templateID,
111 'template' => $this->template
058cbd6a 112 ]);
12aa6f89
MW
113 }
114}