Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] Feature/articletree widget #912

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/Resources/contao/classes/Ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ public function executePostActions(DataContainer $dc)
// Reload the page/file picker
case 'reloadPagetree':
case 'reloadFiletree':
case 'reloadArticletree':
$intId = \Input::get('id');
$strField = $dc->inputName = \Input::post('name');

Expand Down Expand Up @@ -332,7 +333,20 @@ public function executePostActions(DataContainer $dc)

// Set the new value
$varValue = \Input::post('value', true);
$strKey = ($this->strAction == 'reloadPagetree') ? 'pageTree' : 'fileTree';

switch($this->strAction)
{
case 'reloadPagetree':
$strKey = 'pageTree';

break;
case 'reloadFiletree':
$strKey = 'fileTree';

break;
case 'reloadArticletree':
$strKey = 'articleTree';
}

// Convert the selected values
if ($varValue != '')
Expand Down
1 change: 1 addition & 0 deletions src/Resources/contao/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@
'inputUnit' => 'InputUnit',
'trbl' => 'TrblField',
'chmod' => 'ChmodTable',
'articleTree' => 'ArticleTree',
'pageTree' => 'PageTree',
'pageSelector' => 'PageSelector',
'fileTree' => 'FileTree',
Expand Down
168 changes: 4 additions & 164 deletions src/Resources/contao/dca/tl_content.php
Original file line number Diff line number Diff line change
Expand Up @@ -716,26 +716,16 @@
(
'label' => &$GLOBALS['TL_LANG']['tl_content']['articleAlias'],
'exclude' => true,
'inputType' => 'select',
'options_callback' => array('tl_content', 'getArticleAlias'),
'eval' => array('mandatory'=>true, 'chosen'=>true, 'submitOnChange'=>true, 'tl_class'=>'w50 wizard'),
'wizard' => array
(
array('tl_content', 'editArticleAlias')
),
'inputType' => 'articleTree',
'eval' => array('mandatory'=>true, 'fieldType'=>'radio'),
'sql' => "int(10) unsigned NOT NULL default '0'"
),
'article' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_content']['article'],
'exclude' => true,
'inputType' => 'select',
'options_callback' => array('tl_content', 'getArticles'),
'eval' => array('mandatory'=>true, 'chosen'=>true, 'submitOnChange'=>true, 'tl_class'=>'w50 wizard'),
'wizard' => array
(
array('tl_content', 'editArticle')
),
'inputType' => 'articleTree',
'eval' => array('mandatory'=>true, 'fieldType'=>'radio'),
'sql' => "int(10) unsigned NOT NULL default '0'"
),
'form' => array
Expand Down Expand Up @@ -1195,68 +1185,6 @@ public function addCteType($arrRow)
}


/**
* Return the edit article alias wizard
*
* @param DataContainer $dc
*
* @return string
*/
public function editArticleAlias(DataContainer $dc)
{
return ($dc->value < 1) ? '' : ' <a href="contao/main.php?do=article&amp;table=tl_content&amp;id=' . $dc->value . '&amp;popup=1&amp;nb=1&amp;rt=' . REQUEST_TOKEN . '" title="' . sprintf(StringUtil::specialchars($GLOBALS['TL_LANG']['tl_content']['editalias'][1]), $dc->value) . '" onclick="Backend.openModalIframe({\'title\':\'' . StringUtil::specialchars(str_replace("'", "\\'", sprintf($GLOBALS['TL_LANG']['tl_content']['editalias'][1], $dc->value))) . '\',\'url\':this.href});return false">' . Image::getHtml('alias.svg', $GLOBALS['TL_LANG']['tl_content']['editalias'][0]) . '</a>';
}


/**
* Get all articles and return them as array (article alias)
*
* @param DataContainer $dc
*
* @return array
*/
public function getArticleAlias(DataContainer $dc)
{
$arrPids = array();
$arrAlias = array();

if (!$this->User->isAdmin)
{
foreach ($this->User->pagemounts as $id)
{
$arrPids[] = $id;
$arrPids = array_merge($arrPids, $this->Database->getChildRecords($id, 'tl_page'));
}

if (empty($arrPids))
{
return $arrAlias;
}

$objAlias = $this->Database->prepare("SELECT a.id, a.pid, a.title, a.inColumn, p.title AS parent FROM tl_article a LEFT JOIN tl_page p ON p.id=a.pid WHERE a.pid IN(". implode(',', array_map('intval', array_unique($arrPids))) .") AND a.id!=(SELECT pid FROM tl_content WHERE id=?) ORDER BY parent, a.sorting")
->execute($dc->id);
}
else
{
$objAlias = $this->Database->prepare("SELECT a.id, a.pid, a.title, a.inColumn, p.title AS parent FROM tl_article a LEFT JOIN tl_page p ON p.id=a.pid WHERE a.id!=(SELECT pid FROM tl_content WHERE id=?) ORDER BY parent, a.sorting")
->execute($dc->id);
}

if ($objAlias->numRows)
{
System::loadLanguageFile('tl_article');

while ($objAlias->next())
{
$key = $objAlias->parent . ' (ID ' . $objAlias->pid . ')';
$arrAlias[$key][$objAlias->id] = $objAlias->title . ' (' . ($GLOBALS['TL_LANG']['COLS'][$objAlias->inColumn] ?: $objAlias->inColumn) . ', ID ' . $objAlias->id . ')';
}
}

return $arrAlias;
}


/**
* Return the edit alias wizard
*
Expand Down Expand Up @@ -1431,94 +1359,6 @@ public function getElementTemplates(DataContainer $dc)
}


/**
* Return the edit article teaser wizard
*
* @param DataContainer $dc
*
* @return string
*/
public function editArticle(DataContainer $dc)
{
return ($dc->value < 1) ? '' : ' <a href="contao/main.php?do=article&amp;table=tl_content&amp;id=' . $dc->value . '&amp;popup=1&amp;nb=1&amp;rt=' . REQUEST_TOKEN . '" title="' . sprintf(StringUtil::specialchars($GLOBALS['TL_LANG']['tl_content']['editarticle'][1]), $dc->value) . '" onclick="Backend.openModalIframe({\'title\':\'' . StringUtil::specialchars(str_replace("'", "\\'", sprintf($GLOBALS['TL_LANG']['tl_content']['editarticle'][1], $dc->value))) . '\',\'url\':this.href});return false">' . Image::getHtml('alias.svg', $GLOBALS['TL_LANG']['tl_content']['editarticle'][0]) . '</a>';
}


/**
* Get all articles and return them as array (article teaser)
*
* @param DataContainer $dc
*
* @return array
*/
public function getArticles(DataContainer $dc)
{
$arrPids = array();
$arrArticle = array();
$arrRoot = array();
$intPid = $dc->activeRecord->pid;

if (Input::get('act') == 'overrideAll')
{
$intPid = Input::get('id');
}

// Limit pages to the website root
$objArticle = $this->Database->prepare("SELECT pid FROM tl_article WHERE id=?")
->limit(1)
->execute($intPid);

if ($objArticle->numRows)
{
$objPage = PageModel::findWithDetails($objArticle->pid);
$arrRoot = $this->Database->getChildRecords($objPage->rootId, 'tl_page');
array_unshift($arrRoot, $objPage->rootId);
}

unset($objArticle);

// Limit pages to the user's pagemounts
if ($this->User->isAdmin)
{
$objArticle = $this->Database->execute("SELECT a.id, a.pid, a.title, a.inColumn, p.title AS parent FROM tl_article a LEFT JOIN tl_page p ON p.id=a.pid" . (!empty($arrRoot) ? " WHERE a.pid IN(". implode(',', array_map('intval', array_unique($arrRoot))) .")" : "") . " ORDER BY parent, a.sorting");
}
else
{
foreach ($this->User->pagemounts as $id)
{
if (!in_array($id, $arrRoot))
{
continue;
}

$arrPids[] = $id;
$arrPids = array_merge($arrPids, $this->Database->getChildRecords($id, 'tl_page'));
}

if (empty($arrPids))
{
return $arrArticle;
}

$objArticle = $this->Database->execute("SELECT a.id, a.pid, a.title, a.inColumn, p.title AS parent FROM tl_article a LEFT JOIN tl_page p ON p.id=a.pid WHERE a.pid IN(". implode(',', array_map('intval', array_unique($arrPids))) .") ORDER BY parent, a.sorting");
}

// Edit the result
if ($objArticle->numRows)
{
System::loadLanguageFile('tl_article');

while ($objArticle->next())
{
$key = $objArticle->parent . ' (ID ' . $objArticle->pid . ')';
$arrArticle[$key][$objArticle->id] = $objArticle->title . ' (' . ($GLOBALS['TL_LANG']['COLS'][$objArticle->inColumn] ?: $objArticle->inColumn) . ', ID ' . $objArticle->id . ')';
}
}

return $arrArticle;
}


/**
* Dynamically set the ace syntax
*
Expand Down
Loading