2017-04-01 13:59:54 +00:00
|
|
|
<?php
|
2021-03-05 03:08:47 +00:00
|
|
|
/**
|
|
|
|
* @package Joomla.Component.Builder
|
|
|
|
*
|
|
|
|
* @created 30th April, 2015
|
2022-07-09 15:45:08 +00:00
|
|
|
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
|
|
|
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
2021-03-05 03:08:47 +00:00
|
|
|
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
|
|
|
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
// No direct access to this file
|
|
|
|
defined('_JEXEC') or die('Restricted access');
|
|
|
|
|
2024-03-02 20:10:30 +00:00
|
|
|
use Joomla\CMS\Factory;
|
|
|
|
use Joomla\CMS\Language\Text;
|
|
|
|
use Joomla\CMS\HTML\HTMLHelper as Html;
|
|
|
|
|
2021-03-05 03:08:47 +00:00
|
|
|
// import the list field type
|
|
|
|
jimport('joomla.form.helper');
|
|
|
|
JFormHelper::loadFieldClass('list');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Dynamicget Form Field class for the Componentbuilder component
|
|
|
|
*/
|
|
|
|
class JFormFieldDynamicget extends JFormFieldList
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The dynamicget field type.
|
|
|
|
*
|
2024-03-02 20:10:30 +00:00
|
|
|
* @var string
|
2021-03-05 03:08:47 +00:00
|
|
|
*/
|
2018-03-30 04:41:33 +00:00
|
|
|
public $type = 'dynamicget';
|
|
|
|
|
2017-04-01 13:59:54 +00:00
|
|
|
/**
|
|
|
|
* Override to add new button
|
|
|
|
*
|
|
|
|
* @return string The field input markup.
|
|
|
|
*
|
|
|
|
* @since 3.2
|
|
|
|
*/
|
|
|
|
protected function getInput()
|
|
|
|
{
|
|
|
|
// see if we should add buttons
|
2019-06-13 21:12:16 +00:00
|
|
|
$set_button = $this->getAttribute('button');
|
2017-04-01 13:59:54 +00:00
|
|
|
// get html
|
|
|
|
$html = parent::getInput();
|
|
|
|
// if true set button
|
2019-06-13 21:12:16 +00:00
|
|
|
if ($set_button === 'true')
|
2017-04-01 13:59:54 +00:00
|
|
|
{
|
|
|
|
$button = array();
|
|
|
|
$script = array();
|
2019-06-13 21:12:16 +00:00
|
|
|
$button_code_name = $this->getAttribute('name');
|
2017-04-01 13:59:54 +00:00
|
|
|
// get the input from url
|
2024-03-02 20:10:30 +00:00
|
|
|
$app = Factory::getApplication();
|
2017-04-01 13:59:54 +00:00
|
|
|
$jinput = $app->input;
|
|
|
|
// get the view name & id
|
|
|
|
$values = $jinput->getArray(array(
|
|
|
|
'id' => 'int',
|
2018-08-19 20:15:43 +00:00
|
|
|
'view' => 'word'
|
2017-04-01 13:59:54 +00:00
|
|
|
));
|
|
|
|
// check if new item
|
|
|
|
$ref = '';
|
|
|
|
$refJ = '';
|
|
|
|
if (!is_null($values['id']) && strlen($values['view']))
|
|
|
|
{
|
2018-08-19 20:15:43 +00:00
|
|
|
// only load referral if not new item.
|
2017-04-01 13:59:54 +00:00
|
|
|
$ref = '&ref=' . $values['view'] . '&refid=' . $values['id'];
|
|
|
|
$refJ = '&ref=' . $values['view'] . '&refid=' . $values['id'];
|
2018-08-18 12:09:17 +00:00
|
|
|
// get the return value.
|
2024-03-02 20:10:30 +00:00
|
|
|
$_uri = (string) \Joomla\CMS\Uri\Uri::getInstance();
|
2018-08-18 12:09:17 +00:00
|
|
|
$_return = urlencode(base64_encode($_uri));
|
|
|
|
// load return value.
|
|
|
|
$ref .= '&return=' . $_return;
|
|
|
|
$refJ .= '&return=' . $_return;
|
2017-04-01 13:59:54 +00:00
|
|
|
}
|
2019-06-13 21:12:16 +00:00
|
|
|
// get button label
|
|
|
|
$button_label = trim($button_code_name);
|
|
|
|
$button_label = preg_replace('/_+/', ' ', $button_label);
|
|
|
|
$button_label = preg_replace('/\s+/', ' ', $button_label);
|
|
|
|
$button_label = preg_replace("/[^A-Za-z ]/", '', $button_label);
|
|
|
|
$button_label = ucfirst(strtolower($button_label));
|
|
|
|
// get user object
|
2024-03-02 20:10:30 +00:00
|
|
|
$user = Factory::getUser();
|
2017-04-01 13:59:54 +00:00
|
|
|
// only add if user allowed to create dynamic_get
|
2024-03-02 20:10:30 +00:00
|
|
|
if ($user->authorise('dynamic_get.create', 'com_componentbuilder') && $app->isClient('administrator')) // TODO for now only in admin area.
|
2017-04-01 13:59:54 +00:00
|
|
|
{
|
|
|
|
// build Create button
|
2024-03-02 20:10:30 +00:00
|
|
|
$button[] = '<a id="'.$button_code_name.'Create" class="btn btn-small btn-success hasTooltip" title="'.Text::sprintf('COM_COMPONENTBUILDER_CREATE_NEW_S', $button_label).'" style="border-radius: 0px 4px 4px 0px; padding: 4px 4px 4px 7px;"
|
2017-04-01 13:59:54 +00:00
|
|
|
href="index.php?option=com_componentbuilder&view=dynamic_get&layout=edit'.$ref.'" >
|
|
|
|
<span class="icon-new icon-white"></span></a>';
|
|
|
|
}
|
|
|
|
// only add if user allowed to edit dynamic_get
|
2024-03-02 20:10:30 +00:00
|
|
|
if ($user->authorise('dynamic_get.edit', 'com_componentbuilder') && $app->isClient('administrator')) // TODO for now only in admin area.
|
2017-04-01 13:59:54 +00:00
|
|
|
{
|
|
|
|
// build edit button
|
2024-03-26 20:30:10 +00:00
|
|
|
$button[] = '<a id="'.$button_code_name.'Edit" class="btn btn-small hasTooltip" title="'.Text::sprintf('COM_COMPONENTBUILDER_EDIT_S', $button_label).'" style="display: none; padding: 3px 4px 4px 7px;" href="#" >
|
2017-04-01 13:59:54 +00:00
|
|
|
<span class="icon-edit"></span></a>';
|
|
|
|
// build script
|
|
|
|
$script[] = "
|
|
|
|
jQuery(document).ready(function() {
|
2019-06-13 21:12:16 +00:00
|
|
|
jQuery('#adminForm').on('change', '#jform_".$button_code_name."',function (e) {
|
2017-04-01 13:59:54 +00:00
|
|
|
e.preventDefault();
|
2019-06-13 21:12:16 +00:00
|
|
|
var ".$button_code_name."Value = jQuery('#jform_".$button_code_name."').val();
|
|
|
|
".$button_code_name."Button(".$button_code_name."Value);
|
2017-04-01 13:59:54 +00:00
|
|
|
});
|
2019-06-13 21:12:16 +00:00
|
|
|
var ".$button_code_name."Value = jQuery('#jform_".$button_code_name."').val();
|
|
|
|
".$button_code_name."Button(".$button_code_name."Value);
|
2017-04-01 13:59:54 +00:00
|
|
|
});
|
2019-06-13 21:12:16 +00:00
|
|
|
function ".$button_code_name."Button(value) {
|
2017-04-01 13:59:54 +00:00
|
|
|
if (value > 0) {
|
|
|
|
// hide the create button
|
2019-06-13 21:12:16 +00:00
|
|
|
jQuery('#".$button_code_name."Create').hide();
|
2017-04-01 13:59:54 +00:00
|
|
|
// show edit button
|
2019-06-13 21:12:16 +00:00
|
|
|
jQuery('#".$button_code_name."Edit').show();
|
2017-04-01 13:59:54 +00:00
|
|
|
var url = 'index.php?option=com_componentbuilder&view=dynamic_gets&task=dynamic_get.edit&id='+value+'".$refJ."';
|
2019-06-13 21:12:16 +00:00
|
|
|
jQuery('#".$button_code_name."Edit').attr('href', url);
|
2017-04-01 13:59:54 +00:00
|
|
|
} else {
|
|
|
|
// show the create button
|
2019-06-13 21:12:16 +00:00
|
|
|
jQuery('#".$button_code_name."Create').show();
|
2017-04-01 13:59:54 +00:00
|
|
|
// hide edit button
|
2019-06-13 21:12:16 +00:00
|
|
|
jQuery('#".$button_code_name."Edit').hide();
|
2017-04-01 13:59:54 +00:00
|
|
|
}
|
|
|
|
}";
|
|
|
|
}
|
|
|
|
// check if button was created for dynamic_get field.
|
|
|
|
if (is_array($button) && count($button) > 0)
|
|
|
|
{
|
|
|
|
// Load the needed script.
|
2024-03-02 20:10:30 +00:00
|
|
|
$document = Factory::getDocument();
|
2017-04-01 13:59:54 +00:00
|
|
|
$document->addScriptDeclaration(implode(' ',$script));
|
|
|
|
// return the button attached to input field.
|
|
|
|
return '<div class="input-append">' .$html . implode('',$button).'</div>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $html;
|
2021-03-05 03:08:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Method to get a list of options for a list input.
|
|
|
|
*
|
2024-03-02 20:10:30 +00:00
|
|
|
* @return array An array of Html options.
|
2021-03-05 03:08:47 +00:00
|
|
|
*/
|
|
|
|
protected function getOptions()
|
|
|
|
{
|
2017-04-01 13:59:54 +00:00
|
|
|
$db = JFactory::getDBO();
|
|
|
|
$query = $db->getQuery(true);
|
|
|
|
$query->select($db->quoteName(array('a.id','a.name','a.gettype'),array('id','dynamic_get_name','type')));
|
|
|
|
$query->from($db->quoteName('#__componentbuilder_dynamic_get', 'a'));
|
|
|
|
$query->where($db->quoteName('a.published') . ' = 1');
|
|
|
|
$query->order('a.name ASC');
|
|
|
|
$db->setQuery((string)$query);
|
|
|
|
$items = $db->loadObjectList();
|
|
|
|
$options = array();
|
|
|
|
if ($items)
|
|
|
|
{
|
|
|
|
$options[] = JHtml::_('select.option', '', 'Select an option');
|
|
|
|
$model = ComponentbuilderHelper::getModel('dynamic_gets');
|
|
|
|
foreach($items as $item)
|
|
|
|
{
|
|
|
|
$type = $model->selectionTranslation($item->type,'gettype');
|
|
|
|
$options[] = JHtml::_('select.option', $item->id, $item->dynamic_get_name . ' (' . JText::_($type) . ')' );
|
|
|
|
}
|
|
|
|
}
|
2021-03-05 03:08:47 +00:00
|
|
|
return $options;
|
|
|
|
}
|
|
|
|
}
|