%PDF-
%PDF-
Mini Shell
Mini Shell
<?php
/**
* @package CSVI
* @subpackage Plugin.Replace
*
* @author Roland Dalmulder <contact@csvimproved.com>
* @copyright Copyright (C) 2006 - 2015 RolandD Cyber Produksi. All rights reserved.
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
* @link http://www.csvimproved.com
*/
defined('_JEXEC') or die;
/**
* Replaces values.
*
* @package CSVI
* @subpackage Plugin.Customfieldsforall
* @since 6.0
*/
class PlgCsviextCustomfieldsforall extends RantaiPluginDispatcher
{
/**
* The unique ID of the plugin
*
* @var string
* @since 6.0
*/
private $id = 'customfieldsforall';
/**
* JDatabase handler
*
* @var JDatabase
* @since 6.0
*/
protected $db = null;
/**
* Construct the class.
*
* @since 6.0
*/
public function __construct()
{
// Set the dependencies
$this->db = JFactory::getDbo();
}
/**
* Method to get the field options.
*
* @param string $plugin The ID of the plugin.
* @param array $params An array of settings.
* @param int $virtuemart_product_id The product ID.
* @param int $virtuemart_custom_id The custom ID.
* @param CsviHelperLog $log The CSVI logger.
*
* @return void
*
* @since 6.0
*/
public function clearCustomValues($plugin, $params, $virtuemart_product_id, $virtuemart_custom_id, $log)
{
if ($plugin == $this->id)
{
// Get all the values
$param_entries = explode('#', $params);
foreach ($param_entries as $pkey => $pvalue)
{
$param_entries[$pkey] = $this->db->quote($pvalue);
}
// Load the CF4All value IDs
$query = $this->db->getQuery(true)
->select($this->db->quoteName('customsforall_value_id'))
->from($this->db->quoteName('#__virtuemart_custom_plg_customsforall_values'))
->where($this->db->quoteName('virtuemart_custom_id') . ' = ' . (int) $virtuemart_custom_id);
$this->db->setQuery($query);
$valueIds = $this->db->loadColumn();
$log->add('Load cf4all values for custom ID ' . $virtuemart_custom_id);
// Remove existing values for this parameter and only if the product ID has already been handled
if (is_array($valueIds) && !empty($valueIds))
{
$query = $this->db->getQuery(true)
->delete($this->db->quoteName('#__virtuemart_product_custom_plg_customsforall'))
->where($this->db->quoteName('virtuemart_product_id') . ' = ' . (int) $virtuemart_product_id)
->where($this->db->quoteName('customsforall_value_id') . ' IN (' . implode(',', $valueIds) . ')');
$this->db->setQuery($query)->execute();
$log->add('Delete existing cf4all values for product ID ' . $virtuemart_product_id);
}
}
}
/**
* Method to get the field options.
*
* @param string $plugin The ID of the plugin.
* @param array $params An array of settings.
* @param int $virtuemart_product_id The product ID.
* @param int $virtuemart_custom_id The custom ID.
* @param CsviHelperLog $log The CSVI logger.
*
* @return mixed String if plugin needs to handle request | False if plugin does not handle request.
*
* @since 6.0
*/
public function getCustomParam($plugin, $params, $virtuemart_product_id, $virtuemart_custom_id, $log)
{
if ($plugin == $this->id)
{
// There are no params
return '';
}
else
{
return false;
}
}
/**
* Method to get the field options.
*
* @param string $plugin The ID of the plugin.
* @param array $params An array of settings.
* @param int $virtuemart_product_id The product ID.
* @param int $virtuemart_custom_id The custom ID.
* @param int $virtuemart_customfield_id The custom field ID.
* @param CsviHelperLog $log The CSVI logger.
*
* @return mixed Void if plugin needs to handle request | False if plugin does not handle request.
*
* @since 6.0
*/
public function onAfterStoreCustomfield($plugin, $params, $virtuemart_product_id, $virtuemart_custom_id, $virtuemart_customfield_id, $log)
{
if ($plugin == $this->id)
{
// Get all the values
$param_entries = explode('#', $params);
foreach ($param_entries as $pkey => $pvalue)
{
$param_entries[$pkey] = $this->db->quote($pvalue);
}
// Load the CF4All value IDs
$query = $this->db->getQuery(true)
->select($this->db->quoteName('customsforall_value_id'))
->from($this->db->quoteName('#__virtuemart_custom_plg_customsforall_values'))
->where($this->db->quoteName('customsforall_value_name') . ' IN (' . implode(',', $param_entries) . ')');
$this->db->setQuery($query);
$valueIds = $this->db->loadColumn();
$log->add('COM_CSVI_DEBUG_CUSTOMFIELD_VALUE_QUERY');
// Create the value
if (empty($valueIds))
{
foreach ($param_entries as $entry_order => $entry)
{
$query->clear()
->insert($this->db->qn('#__virtuemart_custom_plg_customsforall_values'))
->columns(array('customsforall_value_name', 'virtuemart_custom_id', 'ordering'))
->values($entry . ',' . (int) $virtuemart_custom_id . ',' . ($entry_order + 1));
$this->db->setQuery($query)->execute();
$valueIds[] = $this->db->insertid();
}
}
if (is_array($valueIds) && !empty($valueIds))
{
// Store the values
$query = $this->db->getQuery(true)
->insert($this->db->quoteName('#__virtuemart_product_custom_plg_customsforall'))
->columns($this->db->quoteName(array('customsforall_value_id', 'virtuemart_product_id', 'customfield_id')));
foreach ($valueIds as $valueId)
{
$query->values(
(int) $valueId . ',' .
(int) $virtuemart_product_id . ',' .
(int) $virtuemart_customfield_id
);
}
$this->db->setQuery($query)->execute();
$log->add('COM_CSVI_DEBUG_CUSTOMFIELD_PARAM_QUERY');
}
}
else
{
return false;
}
}
/**
* Export the values.
*
* @param string $plugin The ID of the plugin.
* @param string $custom_param The custom parameter values.
* @param int $virtuemart_product_id The product ID.
* @param int $virtuemart_custom_id The custom ID.
* @param int $virtuemart_customfield_id The custom field ID.
* @param CsviHelperLog $log The CSVI logger.
*
* @return array List of values to export.
*
* @since 6.0
*/
public function exportCustomValues($plugin, $custom_param, $virtuemart_product_id, $virtuemart_custom_id, $virtuemart_customfield_id, $log)
{
if ($plugin == $this->id)
{
// Get the values for this custom field
$query = $this->db->getQuery(true)
->select(
$this->db->quoteName('v.customsforall_value_name', 'value') . ',' .
$this->db->quoteName('c.virtuemart_custom_id')
)
->from($this->db->quoteName('#__virtuemart_product_custom_plg_customsforall', 'r'))
->leftJoin(
$this->db->quoteName('#__virtuemart_custom_plg_customsforall_values', 'v')
. ' ON ' . $this->db->quoteName('r.customsforall_value_id') . ' = ' . $this->db->quoteName('v.customsforall_value_id')
)
->leftJoin(
$this->db->quoteName('#__virtuemart_customs', 'c')
. ' ON ' . $this->db->quoteName('v.virtuemart_custom_id') . ' = ' . $this->db->quoteName('c.virtuemart_custom_id')
)
->leftJoin(
$this->db->quoteName('#__virtuemart_product_customfields', 'f')
. ' ON ' . $this->db->quoteName('c.virtuemart_custom_id') . ' = ' . $this->db->quoteName('f.virtuemart_custom_id')
. ' AND ' . $this->db->quoteName('r.virtuemart_product_id') . ' = ' . $this->db->quoteName('f.virtuemart_product_id')
)
->where($this->db->quoteName('r.virtuemart_product_id') . ' = ' . (int) $virtuemart_product_id)
->where($this->db->quoteName('v.virtuemart_custom_id') . ' = ' . (int) $virtuemart_custom_id)
->where($this->db->quoteName('r.customfield_id') . ' = ' . (int) $virtuemart_customfield_id)
->group($this->db->quoteName('value'));
$this->db->setQuery($query);
$options = $this->db->loadObjectList();
$log->add('Get CF4All values');
// Group the data correctly
$newoptions = array();
foreach ($options as $option)
{
$newoptions[$option->virtuemart_custom_id][] = $option->value;
}
$values = array();
// Create the CSVI format
// option1[value1#value2;option2[value1#value2
foreach ($newoptions as $option)
{
$values[] = implode('#', $option);
}
return $values;
}
else
{
return null;
}
}
}
Zerion Mini Shell 1.0