62 lines
2.2 KiB
PHP
62 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace Komponent\Component\Testquestions\Administrator\View\Set;
|
|
|
|
defined('_JEXEC') or die;
|
|
|
|
use Joomla\CMS\Factory;
|
|
use Joomla\CMS\Language\Text;
|
|
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
|
|
use Joomla\CMS\Toolbar\ToolbarHelper;
|
|
|
|
class HtmlView extends BaseHtmlView
|
|
{
|
|
protected $form;
|
|
protected $item;
|
|
protected $questions;
|
|
protected $categories;
|
|
protected $variants;
|
|
protected $isVariant;
|
|
protected $parentTitle = '';
|
|
|
|
public function display($tpl = null)
|
|
{
|
|
$this->form = $this->get('Form');
|
|
$this->item = $this->get('Item');
|
|
$this->questions = $this->get('Questions');
|
|
$this->categories = $this->get('Categories');
|
|
$this->variants = $this->item && (int) $this->item->id > 0 ? $this->get('Variants') : [];
|
|
$parentId = Factory::getApplication()->getInput()->getInt('parent_id');
|
|
$this->isVariant = (int) ($this->item->parent_id ?? 0) > 0 || $parentId > 0;
|
|
$this->parentTitle = (string) ($this->item->parent_title ?? '');
|
|
|
|
if ($this->isVariant && $this->parentTitle === '' && $parentId > 0) {
|
|
$parent = $this->getModel()->getItem($parentId);
|
|
$this->parentTitle = (string) ($parent->title ?? '');
|
|
}
|
|
|
|
if (count($errors = $this->get('Errors'))) {
|
|
throw new \RuntimeException(implode("\n", $errors));
|
|
}
|
|
|
|
$this->addToolbar();
|
|
|
|
return parent::display($tpl);
|
|
}
|
|
|
|
protected function addToolbar()
|
|
{
|
|
ToolbarHelper::title($this->item->id ? Text::_('COM_TESTQUESTIONS_EDIT_SET') : Text::_('COM_TESTQUESTIONS_NEW_SET'));
|
|
if (!empty($this->item->id) && ((string) $this->item->set_type !== 'multi' || $this->isVariant)) {
|
|
ToolbarHelper::link(
|
|
'index.php?option=com_testquestions&view=preview&set_id=' . (int) $this->item->id,
|
|
'COM_TESTQUESTIONS_PREVIEW_SET',
|
|
'eye'
|
|
);
|
|
}
|
|
ToolbarHelper::custom('set.save', 'save', 'save', 'COM_TESTQUESTIONS_SET_SAVE', false);
|
|
ToolbarHelper::custom('set.saveandclose', 'save', 'save', 'COM_TESTQUESTIONS_SET_SAVE_AND_CLOSE', false);
|
|
ToolbarHelper::cancel('set.cancel', 'JTOOLBAR_CANCEL');
|
|
}
|
|
}
|