* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision: 6903 $
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
/**
* @author Lucas Cherifi - Nans Pellicari - Anatole Korczak - PrestaShop Team
*/
class WebserviceOutputXMLCore implements WebserviceOutputInterface
{
public $docUrl = '';
public $languages = array();
protected $wsUrl;
protected $schemaToDisplay;
public function setSchemaToDisplay($schema)
{
if (is_string($schema))
$this->schemaToDisplay = $schema;
return $this;
}
public function getSchemaToDisplay()
{
return $this->schemaToDisplay;
}
public function setWsUrl($url)
{
$this->wsUrl = $url;
return $this;
}
public function getWsUrl()
{
return $this->wsUrl;
}
public function getContentType()
{
return 'text/xml';
}
public function __construct($languages = array())
{
$this->languages = $languages;
}
public function setLanguages($languages)
{
$this->languages = $languages;
return $this;
}
public function renderErrorsHeader()
{
return ''."\n";
}
public function renderErrorsFooter()
{
return ''."\n";
}
public function renderErrors($message, $code = null)
{
$str_output = ''."\n";
if ($code !== null)
$str_output .= '
'."\n";
$str_output .= ''."\n";
$str_output .= ''."\n";
return $str_output;
}
public function renderField($field)
{
$ret = '';
$node_content = '';
$ret .= '<'.$field['sqlId'];
// display i18n fields
if (isset($field['i18n']) && $field['i18n'])
{
foreach ($this->languages as $language)
{
$more_attr = '';
if (isset($field['synopsis_details']) || (isset($field['value']) AND is_array($field['value'])))
{
$more_attr .= ' xlink:href="'.$this->getWsUrl().'languages/'.$language.'"';
if (isset($field['synopsis_details']) && $this->schemaToDisplay != 'blank')
$more_attr .= ' format="isUnsignedId" ';
}
$node_content .= '';
if (isset($field['value']) AND is_array($field['value']) AND isset($field['value'][$language]))
$node_content .= '';
$node_content .= ''."";
}
}
// display not i18n fields value
else
{
if (array_key_exists('xlink_resource', $field) && $this->schemaToDisplay != 'blank')
{
if (!is_array($field['xlink_resource']))
$ret .= ' xlink:href="'.$this->getWsUrl().$field['xlink_resource'].'/'. $field['value'] .'"';
else
$ret .= ' xlink:href="'.$this->getWsUrl().$field['xlink_resource']['resourceName'].'/'.
(isset($field['xlink_resource']['subResourceName']) ? $field['xlink_resource']['subResourceName'].'/'.$field['object_id'].'/' : '').$field['value'].'"';
}
if (isset($field['getter']) && $this->schemaToDisplay != 'blank')
$ret .= ' not_filterable="true"';
if ($field['value'] != '')
$node_content .= '';
}
if (isset($field['synopsis_details']) && !empty($field['synopsis_details']) && $this->schemaToDisplay !== 'blank')
{
foreach ($field['synopsis_details'] as $name => $detail)
{
$ret .= ' '.$name.'="'.(is_array($detail) ? implode(' ', $detail) : $detail).'"';
}
}
$ret .= '>';
$ret .= $node_content;
$ret .= ''.$field['sqlId'].'>'."\n";
return $ret;
}
public function renderNodeHeader($node_name, $params, $more_attr = null, $has_child = true)
{
$string_attr = '';
if (is_array($more_attr))
{
foreach($more_attr as $key=>$attr)
{
if ($key === 'xlink_resource')
$string_attr .= ' xlink:href="'.$attr.'"';
else
$string_attr .= ' '.$key.'="'.$attr.'"';
}
}
$end_tag = (!$has_child) ? '/>' : '>';
return '<'.$node_name.$string_attr.$end_tag."\n";
}
public function getNodeName($params)
{
$node_name = '';
if (isset($params['objectNodeName']))
$node_name = $params['objectNodeName'];
return $node_name;
}
public function renderNodeFooter($node_name, $params)
{
return ''.$node_name.'>'."\n";
}
public function overrideContent($content)
{
$xml = ''."\n";
$xml .= ''."\n";
$xml .= $content;
$xml .= ''."\n";
return $xml;
}
public function renderAssociationWrapperHeader()
{
return ''."\n";
}
public function renderAssociationWrapperFooter()
{
return ''."\n";
}
public function renderAssociationHeader($obj, $params, $assoc_name, $closed_tags = false)
{
$end_tag = ($closed_tags) ? '/>' : '>';
$more = '';
if ($this->schemaToDisplay != 'blank')
{
$more .= (isset($params['associations'][$assoc_name]['virtual_entity']) && $params['associations'][$assoc_name]['virtual_entity'] ? ' virtual_entity="true"' : '');
$more .= ' node_type="'.$params['associations'][$assoc_name]['resource'].'"';
}
return '<'.$assoc_name.$more.$end_tag."\n";
}
public function renderAssociationFooter($obj, $params, $assoc_name)
{
return ''.$assoc_name.'>'."\n";
}
}