app/Resources/contao/dca/tl_quad_realisation.php line 56

Open in your IDE?
  1. <?php
  2. use App\Classes\DcaHelper;
  3. use App\Classes\FieldHelper;
  4. use App\Classes\Commons;
  5. $table 'tl_quad_realisation';
  6. $GLOBALS['TL_DCA'][$table] = [
  7.     // Config
  8.     'config' => [
  9.         'label' => &$GLOBALS['TL_LANG'][$table]['label'],
  10.         'dataContainer' => 'Table',
  11.         'enableVersioning' => true,
  12.         'sql' => [
  13.             'keys' => [
  14.                 'id' => 'primary',
  15.             ]
  16.         ],
  17.     ],
  18.     'list' => [
  19.         'sorting' => [
  20.             'mode' => 1,
  21.             'fields' => ['name'],
  22.             'flag' => 1,
  23.         ],
  24.         'label' => [
  25.             'fields' => ['name'],
  26.             'label_callback' => [$table'addTaxonomies']
  27.         ],
  28.         'global_operations' => [
  29.             'all' => DcaHelper::getAll()
  30.         ],
  31.         'operations' => [
  32.             'edit' => DcaHelper::getEdit(),
  33.             'copy' => DcaHelper::getCopy(),
  34.             'delete' => DcaHelper::getDelete(),
  35.             'toggle' => DcaHelper::getToggle($table),
  36.             'show' => DcaHelper::getShow(),
  37.         ]
  38.     ],
  39.     'palettes' => [
  40.         'default' => '
  41.             {params_legend},name,alias,type;
  42.             {content_legend},taxonomy,title,description,multiSRC;
  43.             {published_legend},published;
  44.             '
  45.     ],
  46.     'fields' => [
  47.         'id' => FieldHelper::getId(),
  48.         'tstamp' => FieldHelper::getTstamp(),
  49.         'alias' => FieldHelper::getAlias(),
  50.         'name' => FieldHelper::getTextField($GLOBALS['TL_LANG'][$table]['name']),
  51.         'title' => FieldHelper::getTextField($GLOBALS['TL_LANG'][$table]['title'], ['eval' => ['mandatory' => false]]),
  52.         'description' => FieldHelper::getTextareaField($GLOBALS['TL_LANG'][$table]['description']),
  53.         'multiSRC' => FieldHelper::getMultiSRC($GLOBALS['TL_LANG'][$table]['multiSRC']),
  54.         'orderSRC' => FieldHelper::getOrderSRC(),
  55.         'type' => FieldHelper::getSelectByCallback(
  56.             ['App\Classes\CallbackHelper''getRootPages'],
  57.             $GLOBALS['TL_LANG'][$table]['type']
  58.         ),
  59.         'taxonomy' => FieldHelper::getChosenByCallBack($GLOBALS['TL_LANG'][$table]['taxonomy'],
  60.             ['App\Classes\CallbackHelper''getTaxonomies']),
  61.         'published' => FieldHelper::getPublished()
  62.     ]
  63. ];
  64. class tl_quad_realisation extends Commons
  65. {
  66.     public const TABLE 'tl_quad_realisation';
  67.     public function addTaxonomies($row$labelDataContainer $dc null$imageAttribute='')
  68.     {
  69.         $objRealisation = \App\Models\QuadRealisationModel::findOneBy('id'$row['id']);
  70.         if(!$objRealisation->taxonomy) return "<span>$objRealisation->name</span>";
  71.         $arrTaxonomies unserialize($objRealisation->taxonomy);
  72.         $strTaxonomiesName = [];
  73.         foreach($arrTaxonomies as $taxonomyId){
  74.             $objTaxonomy = \App\Models\QuadTaxonomyModel::findOneBy('id'$taxonomyId);
  75.             $arrTaxonomiesName[] = '<span>'.$objTaxonomy->name.'</span>';
  76.         }
  77.         $strTaxonomies implode(''$arrTaxonomiesName);
  78.         $strWildcard "<span>$objRealisation->name</span> ";
  79.         $strWildcard .= ($objRealisation->title)? "<span class='be-grey'> $objRealisation->title</span> " '';
  80.         $strWildcard .= (strlen($strTaxonomies))? "<span class='taxonomy-terms'>$strTaxonomies</span>" '';
  81.         return $strWildcard;
  82.     }
  83.     /**
  84.      * Return the "toggle visibility" button
  85.      * @param array
  86.      * @param string
  87.      * @param string
  88.      * @param string
  89.      * @param string
  90.      * @param string
  91.      * @return string
  92.      */
  93.     public function toggleIcon($row$href$label$title$icon$attributes)
  94.     {
  95.         if (strlen(Input::get('tid'))) {
  96.             $this->toggleVisibility(Input::get('tid'), (Input::get('state') == 1));
  97.             $this->redirect($this->getReferer());
  98.         }
  99.         // Check permissions AFTER checking the tid, so hacking attempts are logged
  100.         if (!$this->User->isAdmin && !$this->User->hasAccess( static::TABLE '::published''alexf')) {
  101.             return '';
  102.         }
  103.         $href .= '&amp;tid=' $row['id'] . '&amp;state=' . ($row['published'] ? '' 1);
  104.         if (!$row['published']) {
  105.             $icon 'invisible.gif';
  106.         }
  107.         return '<a href="' $this->addToUrl($href) . '" title="' specialchars($title) . '"' $attributes '>' Image::getHtml($icon$label'data-state="' . ($row['published'] ? 0) . '"') . '</a> ';
  108.     }
  109.     /**
  110.      * Disable/enable item
  111.      * @param integer
  112.      * @param boolean
  113.      */
  114.     public function toggleVisibility($intId$blnVisible)
  115.     {
  116.         // Check permissions to edit
  117.         Input::setGet('id'$intId);
  118.         Input::setGet('act''toggle');
  119.         // Check permissions to publish
  120.         if (!$this->User->isAdmin && !$this->User->hasAccess(static::TABLE.'::published''alexf'))
  121.         {
  122.             $logger = static::getContainer()->get('monolog.logger.contao');
  123.             $logger->error(
  124.                 'Not enough permissions to publish/unpublish item ID "'.$intId.'"',
  125.                 ['contao' => new ContaoContext(__METHOD__ContaoContext::ERROR)]
  126.             );
  127.             $this->redirect('contao/main.php?act=error');
  128.         }
  129.         $objVersions = new Versions(static::TABLE$intId);
  130.         $objVersions->initialize();
  131.         // Update the database
  132.         $this->Database->prepare("UPDATE " . static::TABLE " SET tstamp=" time() . ", published='" . ($blnVisible '') . "' WHERE id=?")
  133.             ->execute($intId);
  134.         $objVersions->create();
  135.     }
  136. }