<?php
use App\Classes\DcaHelper;
use App\Classes\FieldHelper;
use App\Classes\Commons;
$table = 'tl_quad_realisation';
$GLOBALS['TL_DCA'][$table] = [
// Config
'config' => [
'label' => &$GLOBALS['TL_LANG'][$table]['label'],
'dataContainer' => 'Table',
'enableVersioning' => true,
'sql' => [
'keys' => [
'id' => 'primary',
]
],
],
'list' => [
'sorting' => [
'mode' => 1,
'fields' => ['name'],
'flag' => 1,
],
'label' => [
'fields' => ['name'],
'label_callback' => [$table, 'addTaxonomies']
],
'global_operations' => [
'all' => DcaHelper::getAll()
],
'operations' => [
'edit' => DcaHelper::getEdit(),
'copy' => DcaHelper::getCopy(),
'delete' => DcaHelper::getDelete(),
'toggle' => DcaHelper::getToggle($table),
'show' => DcaHelper::getShow(),
]
],
'palettes' => [
'default' => '
{params_legend},name,alias,type;
{content_legend},taxonomy,title,description,multiSRC;
{published_legend},published;
'
],
'fields' => [
'id' => FieldHelper::getId(),
'tstamp' => FieldHelper::getTstamp(),
'alias' => FieldHelper::getAlias(),
'name' => FieldHelper::getTextField($GLOBALS['TL_LANG'][$table]['name']),
'title' => FieldHelper::getTextField($GLOBALS['TL_LANG'][$table]['title'], ['eval' => ['mandatory' => false]]),
'description' => FieldHelper::getTextareaField($GLOBALS['TL_LANG'][$table]['description']),
'multiSRC' => FieldHelper::getMultiSRC($GLOBALS['TL_LANG'][$table]['multiSRC']),
'orderSRC' => FieldHelper::getOrderSRC(),
'type' => FieldHelper::getSelectByCallback(
['App\Classes\CallbackHelper', 'getRootPages'],
$GLOBALS['TL_LANG'][$table]['type']
),
'taxonomy' => FieldHelper::getChosenByCallBack($GLOBALS['TL_LANG'][$table]['taxonomy'],
['App\Classes\CallbackHelper', 'getTaxonomies']),
'published' => FieldHelper::getPublished()
]
];
class tl_quad_realisation extends Commons
{
public const TABLE = 'tl_quad_realisation';
public function addTaxonomies($row, $label, DataContainer $dc = null, $imageAttribute='')
{
$objRealisation = \App\Models\QuadRealisationModel::findOneBy('id', $row['id']);
if(!$objRealisation->taxonomy) return "<span>$objRealisation->name</span>";
$arrTaxonomies = unserialize($objRealisation->taxonomy);
$strTaxonomiesName = [];
foreach($arrTaxonomies as $taxonomyId){
$objTaxonomy = \App\Models\QuadTaxonomyModel::findOneBy('id', $taxonomyId);
$arrTaxonomiesName[] = '<span>'.$objTaxonomy->name.'</span>';
}
$strTaxonomies = implode('', $arrTaxonomiesName);
$strWildcard = "<span>$objRealisation->name</span> ";
$strWildcard .= ($objRealisation->title)? "<span class='be-grey'> $objRealisation->title</span> " : '';
$strWildcard .= (strlen($strTaxonomies))? "<span class='taxonomy-terms'>$strTaxonomies</span>" : '';
return $strWildcard;
}
/**
* Return the "toggle visibility" button
* @param array
* @param string
* @param string
* @param string
* @param string
* @param string
* @return string
*/
public function toggleIcon($row, $href, $label, $title, $icon, $attributes)
{
if (strlen(Input::get('tid'))) {
$this->toggleVisibility(Input::get('tid'), (Input::get('state') == 1));
$this->redirect($this->getReferer());
}
// Check permissions AFTER checking the tid, so hacking attempts are logged
if (!$this->User->isAdmin && !$this->User->hasAccess( static::TABLE . '::published', 'alexf')) {
return '';
}
$href .= '&tid=' . $row['id'] . '&state=' . ($row['published'] ? '' : 1);
if (!$row['published']) {
$icon = 'invisible.gif';
}
return '<a href="' . $this->addToUrl($href) . '" title="' . specialchars($title) . '"' . $attributes . '>' . Image::getHtml($icon, $label, 'data-state="' . ($row['published'] ? 1 : 0) . '"') . '</a> ';
}
/**
* Disable/enable item
* @param integer
* @param boolean
*/
public function toggleVisibility($intId, $blnVisible)
{
// Check permissions to edit
Input::setGet('id', $intId);
Input::setGet('act', 'toggle');
// Check permissions to publish
if (!$this->User->isAdmin && !$this->User->hasAccess(static::TABLE.'::published', 'alexf'))
{
$logger = static::getContainer()->get('monolog.logger.contao');
$logger->error(
'Not enough permissions to publish/unpublish item ID "'.$intId.'"',
['contao' => new ContaoContext(__METHOD__, ContaoContext::ERROR)]
);
$this->redirect('contao/main.php?act=error');
}
$objVersions = new Versions(static::TABLE, $intId);
$objVersions->initialize();
// Update the database
$this->Database->prepare("UPDATE " . static::TABLE . " SET tstamp=" . time() . ", published='" . ($blnVisible ? 1 : '') . "' WHERE id=?")
->execute($intId);
$objVersions->create();
}
}