Skip to content
This repository was archived by the owner on Feb 9, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 9 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_associations
*
* @copyright Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Associations\Administrator\Controller;

defined('_JEXEC') or die;

use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\Controller\FormController;
use Joomla\CMS\Session\Session;

/**
* Automatically associations controller class.
*
* @since __DEPLOY_VERSION__
*/
class AutoassocController extends FormController
{
/**
* The URL view list variable.
*
* @var string
*
* @since 3.7.0
*/
protected $view_list = 'autoassoc';

/**
* Proxy for getModel.
*
* @param string $name The model name. Optional.
* @param string $prefix The class prefix. Optional.
* @param array $config The array of possible config values. Optional.
*
* @return \Joomla\CMS\MVC\Model\BaseDatabaseModel|bool
*
* @since 3.7.0
*/
public function getModel($name = 'Autoassoc', $prefix = 'Administrator', $config = array('ignore_request' => true))
{
return parent::getModel($name, $prefix, $config);
}

/**
* Automatically create associations.
*
* @return boolean
*
* @since __DEPLOY_VERSION__
*/
public function autoCreate()
{
// Check for request forgeries.
Session::checkToken() or jexit(Text::_('JINVALID_TOKEN'));

$model = $this->getModel();
$assocLanguages = $this->input->post->get('assocLanguages', '', 'string');
$langIds = explode(':', $assocLanguages);
$recordId = $this->input->getInt('id');

// Attempt to create associations.
if (!$model->autoCreate($langIds))
{
// Redirect back to the list screen.
$this->setMessage(Text::sprintf('JLIB_APPLICATION_ERROR_SAVE_FAILED', $model->getError()), 'error');

// Save failed, so go back to the list screen and display a notice.
$this->setRedirect(
\JRoute::_(
'index.php?option=' . $this->option . '&view=' . $this->view_list
. $this->getRedirectToItemAppend($recordId), false
)
);

return false;
}

$this->setMessage(Text::_('COM_ASSOCIATIONS_ASSOCIATIONS_SUCCESSFULLY_CREATED'));

// Redirect back to the list screen.
$this->setRedirect(
\JRoute::_(
'index.php?option=' . $this->option . '&view=' . $this->view_list
. $this->getRedirectToItemAppend($recordId), false
)
);

return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -210,13 +210,12 @@ private static function getExtensionRealName($extensionName)
* @param integer $itemId Item id.
* @param string $itemLanguage Item language code.
* @param boolean $addLink True for adding edit links. False for just text.
* @param boolean $assocLanguages True for showing non associated content languages. False only languages with associations.
*
* @return string The language HTML
*
* @since 3.7.0
*/
public static function getAssociationHtmlList($extensionName, $typeName, $itemId, $itemLanguage, $addLink = true, $assocLanguages = true)
public static function getAssociationHtmlList($extensionName, $typeName, $itemId, $itemLanguage, $addLink = true)
{
// Get the associations list for this item.
$items = self::getAssociationList($extensionName, $typeName, $itemId);
Expand All @@ -238,19 +237,6 @@ public static function getAssociationHtmlList($extensionName, $typeName, $itemId
continue;
}

// Don't show languages with associations, if we don't want to show them.
if ($assocLanguages && isset($items[$langCode]))
{
unset($items[$langCode]);
continue;
}

// Don't show languages without associations, if we don't want to show them.
if (!$assocLanguages && !isset($items[$langCode]))
{
continue;
}

// Get html parameters.
if (isset($items[$langCode]))
{
Expand Down Expand Up @@ -288,11 +274,11 @@ public static function getAssociationHtmlList($extensionName, $typeName, $itemId
$additional = '<strong>' . Text::sprintf('COM_MENUS_MENU_SPRINTF', $menutype_title) . '</strong><br>';
}

$labelClass = 'badge-secondary';
$labelClass = 'badge-success';
$target = $langCode . ':' . $items[$langCode]['id'] . ':edit';
$allow = $canEditReference
&& self::allowEdit($extensionName, $typeName, $items[$langCode]['id'])
&& self::canCheckinItem($extensionName, $typeName, $items[$langCode]['id']);
&& self::allowEdit($extensionName, $typeName, $items[$langCode]['id'])
&& self::canCheckinItem($extensionName, $typeName, $items[$langCode]['id']);

$additional .= $addLink && $allow ? Text::_('COM_ASSOCIATIONS_EDIT_ASSOCIATION') : '';
}
Expand All @@ -302,7 +288,7 @@ public static function getAssociationHtmlList($extensionName, $typeName, $itemId

$title = Text::_('COM_ASSOCIATIONS_NO_ASSOCIATION');
$additional = $addLink ? Text::_('COM_ASSOCIATIONS_ADD_NEW_ASSOCIATION') : '';
$labelClass = 'badge-warning';
$labelClass = 'badge-secondary';
$target = $langCode . ':0:add';
$allow = $canCreate;
}
Expand All @@ -326,15 +312,14 @@ public static function getAssociationHtmlList($extensionName, $typeName, $itemId
$classes = 'hasPopover badge ' . $labelClass;

$items[$langCode]['link'] = '<a href="' . $url . '" title="' . $language->title . '" class="' . $classes
. '" data-content="' . $tooltip . '" data-placement="top">'
. $text . '</a>';
. '" data-content="' . $tooltip . '" data-placement="top">'
. $text . '</a>';
}

HTMLHelper::_('bootstrap.popover');

return LayoutHelper::render('joomla.content.associations', $items);
}

/**
* Get all extensions with associations support.
*
Expand Down Expand Up @@ -418,10 +403,12 @@ public static function getSupportedExtension($extensionName)

foreach ($types as $typeName)
{
$details = $helper->getType($typeName);
$context = 'component';
$title = $helper->getTypeTitle($typeName);
$languageKey = $typeName;
$details = $helper->getType($typeName);
$context = 'component';
$title = $helper->getTypeTitle($typeName);
$languageKey = $typeName;
$table = $helper->getTable($typeName);
$associationContext = $helper->getContext($typeName);

$typeNameExploded = explode('.', $typeName);
if (array_pop($typeNameExploded) === 'category')
Expand All @@ -443,6 +430,8 @@ public static function getSupportedExtension($extensionName)
$rType->def('details', $details);
$rType->def('title', $title);
$rType->def('context', $context);
$rType->def('table', $table);
$rType->def('associationContext', $associationContext);

$rTypes[$typeName] = $rType;
}
Expand Down
Loading