Skip to content

Commit d34bd95

Browse files
authored
Merge pull request #43 from Hackwar/views
Cleaning up views
2 parents a1d03fa + 80faa10 commit d34bd95

File tree

38 files changed

+407
-689
lines changed

38 files changed

+407
-689
lines changed

src/administrator/components/com_jed/src/View/Copyjed3data/HtmlView.php

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,12 @@
1414
\defined('_JEXEC') or die;
1515
// phpcs:enable PSR1.Files.SideEffects
1616

17-
use Exception;
1817
use Jed\Component\Jed\Administrator\Helper\JedHelper;
18+
use Jed\Component\Jed\Administrator\Model\Copyjed3dataModel;
1919
use Joomla\CMS\Component\ComponentHelper;
2020
use Joomla\CMS\Factory;
2121
use Joomla\CMS\Language\Text;
2222
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
23-
use Joomla\CMS\Toolbar\Toolbar;
24-
use Joomla\CMS\Toolbar\ToolbarFactoryInterface;
2523
use Joomla\CMS\Toolbar\ToolbarHelper;
2624
use Joomla\Registry\Registry;
2725
use SimpleXMLElement;
@@ -78,27 +76,21 @@ class HtmlView extends BaseHtmlView
7876
* Add the page title and toolbar.
7977
*
8078
* @since 4.0.0
81-
* @throws Exception
79+
* @throws \Exception
8280
*/
8381
private function addToolbar(): void
8482
{
8583
ToolBarHelper::title(Text::_('COM_JED_TITLE_COPY_JED3_DATA'));
8684

87-
$user = Factory::getApplication()->getIdentity();
85+
$user = $this->getCurrentUser();
8886

8987
if (
9088
$user->authorise('core.admin', 'com_jed')
91-
|| $user->authorise(
92-
'core.options',
93-
'com_jed'
94-
)
89+
|| $user->authorise('core.options', 'com_jed')
9590
) {
96-
$toolbar = Factory::getContainer()->get(ToolbarFactoryInterface::class)->createToolbar();
97-
91+
$toolbar = $this->getDocument()->getToolbar();
9892

9993
JedHelper::addConfigToolbar($toolbar);
100-
101-
10294
ToolbarHelper::preferences('com_jed');
10395
}
10496
}
@@ -111,12 +103,14 @@ private function addToolbar(): void
111103
* @return void
112104
*
113105
* @since 4.0.0
114-
* @throws Exception
106+
* @throws \Exception
115107
*/
116108
public function display($tpl = null): void
117109
{
118-
$this->state = $this->get('State');
119-
$this->item = $this->get('Item');
110+
/** @var Copyjed3dataModel $model */
111+
$model = $this->getModel();
112+
$this->state = $model->getState();
113+
$this->item = $model->getItem();
120114
$this->params = ComponentHelper::getParams('com_jed');
121115
$this->migrate_xml = $this->getMigrateXML();
122116
$app = Factory::getApplication();
@@ -125,7 +119,6 @@ public function display($tpl = null): void
125119

126120
$this->addToolbar();
127121

128-
129122
parent::display($tpl);
130123
}
131124

src/administrator/components/com_jed/src/View/Extension/HtmlView.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ protected function addToolbar(): void
100100
{
101101
Factory::getApplication()->input->set('hidemainmenu', true);
102102

103-
$user = Factory::getApplication()->getIdentity();
103+
$user = $this->getCurrentUser();
104104
$isNew = ($this->extension->id == 0);
105105

106106
if (isset($this->item->checked_out)) {

src/administrator/components/com_jed/src/View/Extensionimage/HtmlView.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
\defined('_JEXEC') or die;
1515
// phpcs:enable PSR1.Files.SideEffects
1616

17-
use Exception;
1817
use Jed\Component\Jed\Administrator\Helper\JedHelper;
18+
use Jed\Component\Jed\Administrator\Model\ExtensionimageModel;
1919
use Joomla\CMS\Factory;
2020
use Joomla\CMS\Language\Text;
2121
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
@@ -42,19 +42,21 @@ class HtmlView extends BaseHtmlView
4242
*
4343
* @return void
4444
*
45-
* @throws Exception
45+
* @throws \Exception
4646
*
4747
* @since 4.0.0
4848
*/
4949
public function display($tpl = null): void
5050
{
51-
$this->state = $this->get('State');
52-
$this->item = $this->get('Item');
53-
$this->form = $this->get('Form');
51+
/** @var ExtensionimageModel $model */
52+
$model = $this->getModel();
53+
$this->state = $model->getState();
54+
$this->item = $model->getItem();
55+
$this->form = $model->getForm();
5456

5557
// Check for errors.
56-
if (count($errors = $this->get('Errors'))) {
57-
throw new Exception(implode("\n", $errors));
58+
if (count($errors = $model->getErrors())) {
59+
throw new \Exception(implode("\n", $errors));
5860
}
5961

6062
$this->addToolbar();
@@ -66,13 +68,13 @@ public function display($tpl = null): void
6668
*
6769
* @return void
6870
*
69-
* @throws Exception
71+
* @throws \Exception
7072
*/
7173
protected function addToolbar(): void
7274
{
7375
Factory::getApplication()->input->set('hidemainmenu', true);
7476

75-
$user = Factory::getApplication()->getIdentity();
77+
$user = $this->getCurrentUser();
7678
$isNew = ($this->item->id == 0);
7779

7880
if (isset($this->item->checked_out)) {
@@ -100,8 +102,6 @@ protected function addToolbar(): void
100102
ToolbarHelper::custom('extensionimage.save2copy', 'save-copy.png', 'save-copy_f2.png', 'JTOOLBAR_SAVE_AS_COPY', false);
101103
}
102104

103-
104-
105105
if (empty($this->item->id)) {
106106
ToolbarHelper::cancel('extensionimage.cancel', 'JTOOLBAR_CANCEL');
107107
} else {

src/administrator/components/com_jed/src/View/Extensionimages/HtmlView.php

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,13 @@
1212
// No direct access
1313
// phpcs:disable PSR1.Files.SideEffects
1414
\defined('_JEXEC') or die;
15-
1615
// phpcs:enable PSR1.Files.SideEffects
1716

18-
use Exception;
1917
use Jed\Component\Jed\Administrator\Helper\JedHelper;
20-
use Joomla\CMS\Factory;
2118
use Joomla\CMS\Form\Form;
2219
use Joomla\CMS\HTML\Helpers\Sidebar;
2320
use Joomla\CMS\Language\Text;
2421
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
25-
use Joomla\CMS\Toolbar\Toolbar;
2622
use Joomla\Registry\Registry;
2723
use Joomla\CMS\Pagination\Pagination;
2824
use Joomla\CMS\Toolbar\ToolbarHelper;
@@ -47,23 +43,21 @@ class HtmlView extends BaseHtmlView
4743
* @return void
4844
*
4945
* @since 4.0.0
50-
* @throws Exception
51-
* @throws Exception
46+
* @throws \Exception
5247
*/
5348
protected function addToolbar(): void
5449
{
5550
$canDo = JedHelper::getActions();
5651

5752
ToolbarHelper::title(Text::_('COM_JED_EXTENSIONIMAGES'), "generic");
5853

59-
$toolbar = Toolbar::getInstance(); //$toolbar = Factory::getContainer()->get(ToolbarFactoryInterface::class)->createToolbar('toolbar');
54+
$toolbar = $this->getDocument()->getToolbar();
6055

6156

6257
if ($canDo->get('core.create')) {
6358
$toolbar->addNew('extensionimage.add');
6459
}
6560

66-
6761
if ($canDo->get('core.edit.state')) {
6862
$dropdown = $toolbar->dropdownButton('status-group')
6963
->text('JTOOLBAR_CHANGE_STATUS')
@@ -134,18 +128,4 @@ protected function getSortFields(): array
134128
'a.`ordering`' => Text::_('JGRID_HEADING_ORDERING'),
135129
];
136130
}
137-
138-
/**
139-
* Check if state is set
140-
*
141-
* @param mixed $state State
142-
*
143-
* @return bool
144-
*
145-
* @since 4.0.0
146-
*/
147-
public function getState(mixed $state): bool
148-
{
149-
return $this->state->{$state} ?? false;
150-
}
151131
}

src/administrator/components/com_jed/src/View/Extensions/HtmlView.php

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
use Exception;
1818
use Jed\Component\Jed\Administrator\Helper\JedHelper;
19-
use Joomla\CMS\Factory;
19+
use Jed\Component\Jed\Administrator\Model\ExtensionsModel;
2020
use Joomla\CMS\Form\Form;
2121
use Joomla\CMS\HTML\Helpers\Sidebar;
2222
use Joomla\CMS\Language\Text;
@@ -60,14 +60,16 @@ class HtmlView extends BaseHtmlView
6060
*/
6161
public function display($tpl = null): void
6262
{
63-
$this->state = $this->get('State');
64-
$this->items = $this->get('Items');
65-
$this->pagination = $this->get('Pagination');
66-
$this->filterForm = $this->get('FilterForm');
67-
$this->activeFilters = $this->get('ActiveFilters');
63+
/** @var ExtensionsModel $model */
64+
$model = $this->getModel();
65+
$this->state = $model->getState();
66+
$this->items = $model->getItems();
67+
$this->pagination = $model->getPagination();
68+
$this->filterForm = $model->getFilterForm();
69+
$this->activeFilters = $model->getActiveFilters();
6870

6971
// Check for errors.
70-
if (count($errors = $this->get('Errors'))) {
72+
if (count($errors = $model->getErrors())) {
7173
throw new Exception(implode("\n", $errors));
7274
}
7375

@@ -87,7 +89,6 @@ public function display($tpl = null): void
8789
*/
8890
protected function addToolbar(): void
8991
{
90-
$this->state = $this->get('State');
9192
$canDo = JedHelper::getActions();
9293

9394
ToolbarHelper::title(Text::_('COM_JED_EXTENSIONS'), "generic");
@@ -177,18 +178,4 @@ protected function getSortFields(): array
177178
'a.`state`' => Text::_('JSTATUS'),
178179
];
179180
}
180-
181-
/**
182-
* Check if state is set
183-
*
184-
* @param mixed $state State
185-
*
186-
* @return bool
187-
*
188-
* @since 4.0.0
189-
*/
190-
public function getState(mixed $state): bool
191-
{
192-
return $this->state->{$state} ?? false;
193-
}
194181
}

src/administrator/components/com_jed/src/View/Extensionscore/HtmlView.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
\defined('_JEXEC') or die;
1515
// phpcs:enable PSR1.Files.SideEffects
1616

17-
use Exception;
1817
use Jed\Component\Jed\Administrator\Helper\JedHelper;
18+
use Jed\Component\Jed\Administrator\Model\ExtensionscoreModel;
1919
use Joomla\CMS\Factory;
2020
use Joomla\CMS\Language\Text;
2121
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
@@ -42,19 +42,21 @@ class HtmlView extends BaseHtmlView
4242
*
4343
* @return void
4444
*
45-
* @throws Exception
45+
* @throws \Exception
4646
*
4747
* @since 4.0.0
4848
*/
4949
public function display($tpl = null): void
5050
{
51-
$this->state = $this->get('State');
52-
$this->item = $this->get('Item');
53-
$this->form = $this->get('Form');
51+
/** @var ExtensionscoreModel $model */
52+
$model = $this->getModel();
53+
$this->state = $model->getState();
54+
$this->item = $model->getItem();
55+
$this->form = $model->getForm();
5456

5557
// Check for errors.
56-
if (count($errors = $this->get('Errors'))) {
57-
throw new Exception(implode("\n", $errors));
58+
if (count($errors = $model->getErrors())) {
59+
throw new \Exception(implode("\n", $errors));
5860
}
5961

6062
$this->addToolbar();
@@ -66,15 +68,15 @@ public function display($tpl = null): void
6668
*
6769
* @return void
6870
*
69-
* @throws Exception
71+
* @throws \Exception
7072
*
7173
* @since 4.0.0
7274
*/
7375
protected function addToolbar(): void
7476
{
7577
Factory::getApplication()->input->set('hidemainmenu', true);
7678

77-
$user = Factory::getApplication()->getIdentity();
79+
$user = $this->getCurrentUser();
7880
$isNew = ($this->item->id == 0);
7981

8082
if (isset($this->item->checked_out)) {

src/administrator/components/com_jed/src/View/Extensionscores/HtmlView.php

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,11 @@
1414
\defined('_JEXEC') or die;
1515
// phpcs:enable PSR1.Files.SideEffects
1616

17-
use Exception;
1817
use Jed\Component\Jed\Administrator\Helper\JedHelper;
19-
use Joomla\CMS\Factory;
2018
use Joomla\CMS\Form\Form;
2119
use Joomla\CMS\HTML\Helpers\Sidebar;
2220
use Joomla\CMS\Language\Text;
2321
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
24-
use Joomla\CMS\Toolbar\Toolbar;
2522
use Joomla\Registry\Registry;
2623
use Joomla\CMS\Pagination\Pagination;
2724
use Joomla\CMS\Toolbar\ToolbarHelper;
@@ -46,17 +43,15 @@ class HtmlView extends BaseHtmlView
4643
* @return void
4744
*
4845
* @since 4.0.0
49-
* @throws Exception
50-
* @throws Exception
46+
* @throws \Exception
5147
*/
5248
protected function addToolbar(): void
5349
{
5450
$canDo = JedHelper::getActions();
5551

5652
ToolbarHelper::title(Text::_('COM_JED_EXTENSIONSCORES'), "generic");
5753

58-
$toolbar = Toolbar::getInstance(); //$toolbar = Factory::getContainer()->get(ToolbarFactoryInterface::class)->createToolbar('toolbar');
59-
54+
$toolbar = $this->getDocument()->getToolbar();
6055

6156
$toolbar->addNew('extensionscore.add');
6257

@@ -141,18 +136,4 @@ protected function getSortFields(): array
141136
'a.`number_of_reviews`' => Text::_('COM_JED_EXTENSION_NUMBER_OF_REVIEWS_LABEL'),
142137
];
143138
}
144-
145-
/**
146-
* Check if state is set
147-
*
148-
* @param mixed $state State
149-
*
150-
* @return bool
151-
*
152-
* @since 4.0.0
153-
*/
154-
public function getState(mixed $state): bool
155-
{
156-
return $this->state->{$state} ?? false;
157-
}
158139
}

0 commit comments

Comments
 (0)