Hey lindesbs,
Habe in meiner DCA nun oben unter operations folgendes hinzugefügt:
PHP-Code:
'toggle' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_mymodule']['toggle'],
'icon' => 'visible.gif',
'attributes' => 'onclick="Backend.getScrollOffset(); return AjaxRequest.toggleVisibility(this, %s);"',
'button_callback' => array('tl_mymodule', 'toggleIcon')
),
Un gaaaanz unten ans Ende dies hier:
PHP-Code:
class tl_mymodule extends Backend
{
public function toggleIcon($row, $href, $label, $title, $icon, $attributes)
{
if (strlen($this->Input->get('tid')))
{
$this->toggleVisibility($this->Input->get('tid'), ($this->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('tl_mymodule::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.'>'.$this->generateImage($icon, $label).'</a> ';
}
/**
* Disable/enable a user group
* @param integer
* @param boolean
*/
public function toggleVisibility($intId, $blnVisible)
{
// Check permissions to edit
$this->Input->setGet('id', $intId);
$this->Input->setGet('act', 'toggle');
$this->checkPermission();
// Check permissions to publish
// if (!$this->User->isAdmin && !$this->User->hasAccess('tl_mymodule::published', 'alexf'))
// {
// $this->log('Not enough permissions to publish/unpublish news item ID "'.$intId.'"', 'tl_mymodule toggleVisibility', TL_ERROR);
// $this->redirect('contao/main.php?act=error');
// }
// Trigger the save_callback
if (is_array($GLOBALS['TL_DCA']['tl_news']['fields']['published']['save_callback']))
{
foreach ($GLOBALS['TL_DCA']['tl_news']['fields']['published']['save_callback'] as $callback)
{
$this->import($callback[0]);
$blnVisible = $this->$callback[0]->$callback[1]($blnVisible, $this);
}
}
// Update the database
$this->Database->prepare("UPDATE tl_mymodule SET tstamp=". time() .", published='" . ($blnVisible ? 1 : '') . "' WHERE id=?")
->execute($intId);
$this->createNewVersion('tl_mymodule', $intId);
}
}
Da ich ich die Prüfung über "hasAccess" und "alexf" nicht ganz verstehe (weiß auch nicht ob das bei mir Sinn macht), habe ich dieses wie du siehst erstmal auskommentiert.
Nun kann ich im Firebug sehen, dass der Ajax Request einen Fehler liefert, er kennt die Funktion checkpermission() nicht.
Jetzt habe ich diese noch hinzugefügt (Habe mir die von tl_news aus dem Code besorgt):
PHP-Code:
public function checkPermission()
{
// HOOK: comments extension required
if (!in_array('comments', $this->Config->getActiveModules()))
{
$key = array_search('allowComments', $GLOBALS['TL_DCA']['tl_news']['list']['sorting']['headerFields']);
unset($GLOBALS['TL_DCA']['tl_news']['list']['sorting']['headerFields'][$key]);
}
if ($this->User->isAdmin)
{
return;
}
// Set root IDs
if (!is_array($this->User->news) || count($this->User->news) < 1)
{
$root = array(0);
}
else
{
$root = $this->User->news;
}
$id = strlen($this->Input->get('id')) ? $this->Input->get('id') : CURRENT_ID;
// Check current action
switch ($this->Input->get('act'))
{
case 'paste':
// Allow
break;
case 'create':
if (!strlen($this->Input->get('pid')) || !in_array($this->Input->get('pid'), $root))
{
$this->log('Not enough permissions to create news items in news archive ID "'.$this->Input->get('pid').'"', 'tl_news checkPermission', TL_ERROR);
$this->redirect('contao/main.php?act=error');
}
break;
case 'cut':
case 'copy':
if (!in_array($this->Input->get('pid'), $root))
{
$this->log('Not enough permissions to '.$this->Input->get('act').' news item ID "'.$id.'" to news archive ID "'.$this->Input->get('pid').'"', 'tl_news checkPermission', TL_ERROR);
$this->redirect('contao/main.php?act=error');
}
// NO BREAK STATEMENT HERE
case 'edit':
case 'show':
case 'delete':
case 'toggle':
$objArchive = $this->Database->prepare("SELECT pid FROM tl_news WHERE id=?")
->limit(1)
->execute($id);
if ($objArchive->numRows < 1)
{
$this->log('Invalid news item ID "'.$id.'"', 'tl_news checkPermission', TL_ERROR);
$this->redirect('contao/main.php?act=error');
}
if (!in_array($objArchive->pid, $root))
{
$this->log('Not enough permissions to '.$this->Input->get('act').' news item ID "'.$id.'" of news archive ID "'.$objArchive->pid.'"', 'tl_news checkPermission', TL_ERROR);
$this->redirect('contao/main.php?act=error');
}
break;
case 'select':
case 'editAll':
case 'deleteAll':
case 'overrideAll':
case 'cutAll':
case 'copyAll':
if (!in_array($id, $root))
{
$this->log('Not enough permissions to access news archive ID "'.$id.'"', 'tl_news checkPermission', TL_ERROR);
$this->redirect('contao/main.php?act=error');
}
$objArchive = $this->Database->prepare("SELECT id FROM tl_news WHERE pid=?")
->execute($id);
if ($objArchive->numRows < 1)
{
$this->log('Invalid news archive ID "'.$id.'"', 'tl_news checkPermission', TL_ERROR);
$this->redirect('contao/main.php?act=error');
}
$session = $this->Session->getData();
$session['CURRENT']['IDS'] = array_intersect($session['CURRENT']['IDS'], $objArchive->fetchEach('id'));
$this->Session->setData($session);
break;
default:
if (strlen($this->Input->get('act')))
{
$this->log('Invalid command "'.$this->Input->get('act').'"', 'tl_news checkPermission', TL_ERROR);
$this->redirect('contao/main.php?act=error');
}
elseif (!in_array($id, $root))
{
$this->log('Not enough permissions to access news archive ID "'.$id.'"', 'tl_news checkPermission', TL_ERROR);
$this->redirect('contao/main.php?act=error');
}
break;
}
}
Und genau da ist mein Problem, steige hier echt null durch den Code durch und weiß jetzt auch nicht ob ich so eine Prüfung für meine relative einfache Extension brauche.
Schreibe ich statt der langen Funktion zum Testen einfach mal:
PHP-Code:
public function checkPermission()
{
return;
}
Dann scheint alles zu gehen und auch die Spalte "published" wird in 0 oder 1 geupdated. Das ist ja genau das was ich wollte Aber kannst du mir die checkpermission() function erklären?^^ Danke
Lesezeichen