Version Notes
Version 2:
- includes boxalino PHP SDK library
- personalized recommendations
- integration of the layered navigation
Download this release
Release Info
| Developer | Marcel Zenger |
| Extension | boxalino_plugin |
| Version | 2.13.0 |
| Comparing to | |
| See all releases | |
Code changes from version 2.10.0 to 2.13.0
- app/code/community/Boxalino/CemSearch/Block/Abstract.php +0 -36
- app/code/community/Boxalino/CemSearch/Block/Autocomplete.php +0 -245
- app/code/community/Boxalino/CemSearch/Block/Cart/Crosssell.php +0 -88
- app/code/community/Boxalino/CemSearch/Block/Facets.php +0 -323
- app/code/community/Boxalino/CemSearch/Block/Product/List.php +0 -49
- app/code/community/Boxalino/CemSearch/Block/Product/List/Recommendation.php +0 -120
- app/code/community/Boxalino/CemSearch/Block/Product/List/Related.php +0 -60
- app/code/community/Boxalino/CemSearch/Block/Product/List/Upsell.php +0 -67
- app/code/community/Boxalino/CemSearch/CatalogSearch/Helper/Data.php +0 -27
- app/code/community/Boxalino/CemSearch/Helper/Data.php +0 -351
- app/code/community/Boxalino/CemSearch/Helper/P13n/Adapter.php +0 -1043
- app/code/community/Boxalino/CemSearch/Helper/P13n/Config.php +0 -59
- app/code/community/Boxalino/CemSearch/Helper/P13n/Recommendation.php +0 -89
- app/code/community/Boxalino/CemSearch/Helper/P13n/Sort.php +0 -36
- app/code/community/Boxalino/CemSearch/Lib/AbstractThrift.php +0 -28
- app/code/community/Boxalino/CemSearch/Lib/vendor/Thrift/HttpP13n.php +0 -270
- app/code/community/Boxalino/CemSearch/Model/Advanced.php +0 -284
- app/code/community/Boxalino/CemSearch/Model/Category.php +0 -46
- app/code/community/Boxalino/CemSearch/Model/Logger.php +0 -84
- app/code/community/Boxalino/CemSearch/Model/Resource/Advanced.php +0 -12
- app/code/community/Boxalino/CemSearch/Model/Resource/Advanced/Collection.php +0 -30
- app/code/community/Boxalino/CemSearch/Model/Resource/Fulltext.php +0 -258
- app/code/community/Boxalino/CemSearch/controllers/AdvancedController.php +0 -158
- app/code/community/Boxalino/CemSearch/controllers/IndexController.php +0 -27
- app/code/community/Boxalino/CemSearch/controllers/ResultController.php +0 -10
- app/code/community/Boxalino/CemSearch/etc/adminhtml.xml +0 -26
- app/code/community/Boxalino/CemSearch/etc/config.xml +0 -259
- app/code/community/Boxalino/CemSearch/etc/system.xml +0 -775
- app/code/community/Boxalino/Exporter/Helper/Data.php +0 -205
- app/code/community/Boxalino/Exporter/Model/Delta.php +0 -29
- app/code/community/Boxalino/Exporter/Model/Indexer.php +0 -29
- app/code/community/Boxalino/Exporter/Model/Mysql4/Exporter/Delta.php +0 -71
- app/code/community/Boxalino/Exporter/Model/Mysql4/Indexer.php +0 -2029
- app/code/community/Boxalino/Exporter/etc/adminhtml.xml +0 -23
- app/code/community/Boxalino/Exporter/etc/config.xml +0 -62
- app/code/community/Boxalino/Exporter/etc/system.xml +0 -151
- app/code/community/Boxalino/Intelligence/Block/Autocomplete.php +59 -0
- app/code/community/Boxalino/Intelligence/Block/Cart/Crosssell.php +80 -0
- app/code/community/Boxalino/Intelligence/Block/Facets.php +48 -0
- app/code/community/Boxalino/Intelligence/Block/Layer.php +63 -0
- app/code/community/Boxalino/Intelligence/Block/Layer/FIlter/Attribute.php +44 -0
- app/code/community/Boxalino/Intelligence/Block/Layer/State.php +56 -0
- app/code/community/Boxalino/Intelligence/Block/Layer/View.php +69 -0
- app/code/community/Boxalino/Intelligence/Block/Product/List.php +93 -0
- app/code/community/Boxalino/Intelligence/Block/Product/List/Related.php +70 -0
- app/code/community/Boxalino/Intelligence/Block/Product/List/Toolbar.php +15 -0
- app/code/community/Boxalino/Intelligence/Block/Product/List/Upsell.php +71 -0
- app/code/community/Boxalino/Intelligence/Block/Recommendation.php +194 -0
- app/code/community/Boxalino/Intelligence/Block/Result.php +140 -0
- app/code/community/Boxalino/{CemSearch → Intelligence}/Block/Script.php +33 -29
- app/code/community/Boxalino/Intelligence/Block/Slider.php +36 -0
- app/code/community/Boxalino/Intelligence/Helper/Autocomplete.php +25 -0
- app/code/community/Boxalino/Intelligence/Helper/BxFiles.php +226 -0
- app/code/community/Boxalino/Intelligence/Helper/BxGeneral.php +49 -0
- app/code/community/Boxalino/Intelligence/Helper/BxIndexConfig.php +331 -0
- app/code/community/Boxalino/Intelligence/Helper/Data.php +613 -0
- app/code/community/Boxalino/Intelligence/Helper/P13n/Adapter.php +466 -0
- app/code/community/Boxalino/Intelligence/Model/Delta.php +45 -0
- app/code/community/Boxalino/Intelligence/Model/Indexer.php +45 -0
- app/code/community/Boxalino/Intelligence/Model/Layer/Filter/Attribute.php +189 -0
- app/code/community/Boxalino/Intelligence/Model/Mysql4/Exporter/Delta.php +33 -0
- app/code/community/Boxalino/{Exporter → Intelligence}/Model/Mysql4/Exporter/Indexer.php +15 -15
- app/code/community/Boxalino/Intelligence/Model/Mysql4/Indexer.php +1481 -0
- app/code/community/Boxalino/{CemSearch → Intelligence}/Model/Observer.php +109 -111
- app/code/community/Boxalino/Intelligence/Model/Resource/Product/Collection.php +137 -0
- app/code/community/Boxalino/{CemSearch → Intelligence}/Model/Session.php +32 -32
- app/code/community/Boxalino/Intelligence/Model/Template/Filter.php +19 -0
- app/code/community/Boxalino/{CemSearch → Intelligence}/controllers/AjaxController.php +50 -47
- app/code/community/Boxalino/Intelligence/controllers/CategoryController.php +42 -0
- app/code/community/Boxalino/Intelligence/controllers/ResultController.php +30 -0
- app/code/community/Boxalino/Intelligence/etc/adminhtml.xml +31 -0
- app/code/community/Boxalino/Intelligence/etc/config.xml +210 -0
- app/code/community/Boxalino/Intelligence/etc/system.xml +947 -0
- app/code/community/Boxalino/Intelligence/lib/BxAutocompleteRequest.php +122 -0
- app/code/community/Boxalino/Intelligence/lib/BxAutocompleteResponse.php +94 -0
- app/code/community/Boxalino/Intelligence/lib/BxChooseResponse.php +248 -0
- app/code/community/Boxalino/Intelligence/lib/BxClient.php +422 -0
- app/code/community/Boxalino/Intelligence/lib/BxData.php +658 -0
- app/code/community/Boxalino/Intelligence/lib/BxFacets.php +531 -0
- app/code/community/Boxalino/Intelligence/lib/BxFilter.php +85 -0
- app/code/community/Boxalino/Intelligence/lib/BxRecommendationRequest.php +7 -0
- app/code/community/Boxalino/Intelligence/lib/BxRequest.php +255 -0
- app/code/community/Boxalino/Intelligence/lib/BxSearchRequest.php +14 -0
- app/code/community/Boxalino/Intelligence/lib/BxSortFields.php +47 -0
- app/code/community/Boxalino/{CemSearch/Lib → Intelligence/lib}/P13nService.php +1309 -1064
- app/code/community/Boxalino/{CemSearch/Lib/vendor → Intelligence/lib}/Thrift/Base/TBase.php +367 -367
- app/code/community/Boxalino/{CemSearch/Lib/vendor → Intelligence/lib}/Thrift/ClassLoader/ThriftClassLoader.php +223 -223
- app/code/community/Boxalino/{CemSearch/Lib/vendor → Intelligence/lib}/Thrift/Exception/TApplicationException.php +72 -72
- app/code/community/Boxalino/{CemSearch/Lib/vendor → Intelligence/lib}/Thrift/Exception/TException.php +369 -369
- app/code/community/Boxalino/{CemSearch/Lib/vendor → Intelligence/lib}/Thrift/Exception/TProtocolException.php +48 -48
- app/code/community/Boxalino/{CemSearch/Lib/vendor → Intelligence/lib}/Thrift/Exception/TTransportException.php +40 -40
- app/code/community/Boxalino/{CemSearch/Lib/vendor → Intelligence/lib}/Thrift/Factory/TBinaryProtocolFactory.php +42 -42
- app/code/community/Boxalino/{CemSearch/Lib/vendor → Intelligence/lib}/Thrift/Factory/TCompactProtocolFactory.php +38 -38
- app/code/community/Boxalino/{CemSearch/Lib/vendor → Intelligence/lib}/Thrift/Factory/TJSONProtocolFactory.php +41 -41
- app/code/community/Boxalino/Intelligence/lib/Thrift/Factory/TProtocol.php +346 -0
- app/code/community/Boxalino/{CemSearch/Lib/vendor → Intelligence/lib}/Thrift/Factory/TProtocolFactory.php +35 -35
- app/code/community/Boxalino/{CemSearch/Lib/vendor → Intelligence/lib}/Thrift/Factory/TStringFuncFactory.php +62 -62
- app/code/community/Boxalino/{CemSearch/Lib/vendor → Intelligence/lib}/Thrift/Factory/TTransportFactory.php +16 -16
- app/code/community/Boxalino/{CemSearch/Lib/vendor → Intelligence/lib}/Thrift/Protocol/JSON/BaseContext.php +38 -38
- app/code/community/Boxalino/{CemSearch/Lib/vendor → Intelligence/lib}/Thrift/Protocol/JSON/ListContext.php +51 -51
- app/code/community/Boxalino/{CemSearch/Lib/vendor → Intelligence/lib}/Thrift/Protocol/JSON/LookaheadReader.php +53 -53
- app/code/community/Boxalino/{CemSearch/Lib/vendor → Intelligence/lib}/Thrift/Protocol/JSON/PairContext.php +59 -59
- app/code/community/Boxalino/{CemSearch/Lib/vendor → Intelligence/lib}/Thrift/Protocol/TBinaryProtocol.php +396 -396
- app/code/community/Boxalino/{CemSearch/Lib/vendor → Intelligence/lib}/Thrift/Protocol/TBinaryProtocolAccelerated.php +46 -46
- app/code/community/Boxalino/{CemSearch/Lib/vendor → Intelligence/lib}/Thrift/Protocol/TCompactProtocol.php +670 -670
- app/code/community/Boxalino/{CemSearch/Lib/vendor → Intelligence/lib}/Thrift/Protocol/TJSONProtocol.php +694 -694
- app/code/community/Boxalino/{CemSearch/Lib/vendor → Intelligence/lib}/Thrift/Protocol/TProtocol.php +346 -346
- app/code/community/Boxalino/{CemSearch/Lib/vendor → Intelligence/lib}/Thrift/Serializer/TBinarySerializer.php +73 -73
- app/code/community/Boxalino/{CemSearch/Lib/vendor → Intelligence/lib}/Thrift/Server/TForkingServer.php +119 -119
- app/code/community/Boxalino/{CemSearch/Lib/vendor → Intelligence/lib}/Thrift/Server/TServer.php +101 -101
- app/code/community/Boxalino/{CemSearch/Lib/vendor → Intelligence/lib}/Thrift/Server/TServerSocket.php +98 -98
- app/code/community/Boxalino/{CemSearch/Lib/vendor → Intelligence/lib}/Thrift/Server/TServerTransport.php +54 -54
- app/code/community/Boxalino/{CemSearch/Lib/vendor → Intelligence/lib}/Thrift/Server/TSimpleServer.php +57 -57
- app/code/community/Boxalino/{CemSearch/Lib/vendor → Intelligence/lib}/Thrift/StringFunc/Core.php +37 -37
- app/code/community/Boxalino/{CemSearch/Lib/vendor → Intelligence/lib}/Thrift/StringFunc/Mbstring.php +44 -44
- app/code/community/Boxalino/{CemSearch/Lib/vendor → Intelligence/lib}/Thrift/StringFunc/TStringFunc.php +26 -26
- app/code/community/Boxalino/{CemSearch/Lib/vendor → Intelligence/lib}/Thrift/Transport/P13nTCurlClient.php +77 -76
- app/code/community/Boxalino/{CemSearch/Lib/vendor → Intelligence/lib}/Thrift/Transport/P13nTHttpClient.php +51 -51
- app/code/community/Boxalino/{CemSearch/Lib/vendor → Intelligence/lib}/Thrift/Transport/TBufferedTransport.php +165 -165
- app/code/community/Boxalino/{CemSearch/Lib/vendor → Intelligence/lib}/Thrift/Transport/TCurlClient.php +221 -221
- app/code/community/Boxalino/{CemSearch/Lib/vendor → Intelligence/lib}/Thrift/Transport/TFramedTransport.php +183 -183
- app/code/community/Boxalino/{CemSearch/Lib/vendor → Intelligence/lib}/Thrift/Transport/THttpClient.php +206 -206
- app/code/community/Boxalino/{CemSearch/Lib/vendor → Intelligence/lib}/Thrift/Transport/TMemoryBuffer.php +0 -5
app/code/community/Boxalino/CemSearch/Block/Abstract.php
DELETED
|
@@ -1,36 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
|
| 3 |
-
abstract class Boxalino_CemSearch_Block_Abstract extends Mage_Core_Block_Template
|
| 4 |
-
{
|
| 5 |
-
public function isPluginEnabled()
|
| 6 |
-
{
|
| 7 |
-
return Mage::helper('Boxalino_CemSearch')->isEnabled();
|
| 8 |
-
}
|
| 9 |
-
|
| 10 |
-
public function isPageEnabled($uri)
|
| 11 |
-
{
|
| 12 |
-
return Mage::helper('Boxalino_CemSearch')->isPageEnabled($uri);
|
| 13 |
-
}
|
| 14 |
-
|
| 15 |
-
public function getSearchUrl()
|
| 16 |
-
{
|
| 17 |
-
return $this->getUrl('Boxalino_CemSearch/search');
|
| 18 |
-
}
|
| 19 |
-
|
| 20 |
-
public function getLanguage()
|
| 21 |
-
{
|
| 22 |
-
return Mage::helper('Boxalino_CemSearch')->getLanguage();
|
| 23 |
-
}
|
| 24 |
-
|
| 25 |
-
public function getSuggestUrl()
|
| 26 |
-
{
|
| 27 |
-
return Mage::helper('Boxalino_CemSearch')->getSuggestUrl();
|
| 28 |
-
}
|
| 29 |
-
|
| 30 |
-
public function getSuggestParameters()
|
| 31 |
-
{
|
| 32 |
-
return Mage::helper('Boxalino_CemSearch')->getSuggestParameters();
|
| 33 |
-
}
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/code/community/Boxalino/CemSearch/Block/Autocomplete.php
DELETED
|
@@ -1,245 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
/**
|
| 3 |
-
* Magento
|
| 4 |
-
*
|
| 5 |
-
* NOTICE OF LICENSE
|
| 6 |
-
*
|
| 7 |
-
* This source file is subject to the Open Software License (OSL 3.0)
|
| 8 |
-
* that is bundled with this package in the file LICENSE.txt.
|
| 9 |
-
* It is also available through the world-wide-web at this URL:
|
| 10 |
-
* http://opensource.org/licenses/osl-3.0.php
|
| 11 |
-
* If you did not receive a copy of the license and are unable to
|
| 12 |
-
* obtain it through the world-wide-web, please send an email
|
| 13 |
-
* to license@magentocommerce.com so we can send you a copy immediately.
|
| 14 |
-
*
|
| 15 |
-
* DISCLAIMER
|
| 16 |
-
*
|
| 17 |
-
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
| 18 |
-
* versions in the future. If you wish to customize Magento for your
|
| 19 |
-
* needs please refer to http://www.magentocommerce.com for more information.
|
| 20 |
-
*
|
| 21 |
-
* @category Mage
|
| 22 |
-
* @package Mage_CatalogSearch
|
| 23 |
-
* @copyright Copyright (c) 2014 Magento Inc. (http://www.magentocommerce.com)
|
| 24 |
-
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
| 25 |
-
*/
|
| 26 |
-
|
| 27 |
-
/**
|
| 28 |
-
* Autocomplete queries list
|
| 29 |
-
*/
|
| 30 |
-
|
| 31 |
-
require_once "Mage/CatalogSearch/Block/Autocomplete.php";
|
| 32 |
-
|
| 33 |
-
class Boxalino_CemSearch_Block_Autocomplete extends Mage_CatalogSearch_Block_Autocomplete
|
| 34 |
-
{
|
| 35 |
-
protected $_suggestData = array();
|
| 36 |
-
protected $_suggestDataProducts = array();
|
| 37 |
-
protected $_order = array();
|
| 38 |
-
protected $_first = null;
|
| 39 |
-
|
| 40 |
-
protected function _toHtml()
|
| 41 |
-
{
|
| 42 |
-
if (!Mage::getStoreConfig('Boxalino_General/general/enabled')) {
|
| 43 |
-
return null;
|
| 44 |
-
}
|
| 45 |
-
|
| 46 |
-
$html = '';
|
| 47 |
-
|
| 48 |
-
if (!$this->_beforeToHtml()) {
|
| 49 |
-
return $html;
|
| 50 |
-
}
|
| 51 |
-
|
| 52 |
-
$suggestData = $this->getSuggestData();
|
| 53 |
-
if (!($count = count($suggestData))) {
|
| 54 |
-
$html .= '<ul class="queries"><li>' . $this->helper('catalogsearch')->getQueryText() . '</li></ul>';
|
| 55 |
-
if (count($this->_suggestDataProducts)) {
|
| 56 |
-
$html .= $this->prepareDataProducts();
|
| 57 |
-
}
|
| 58 |
-
return $html;
|
| 59 |
-
}
|
| 60 |
-
|
| 61 |
-
$count--;
|
| 62 |
-
$catalogSearchHelper = Mage::helper('catalogsearch');
|
| 63 |
-
$autocompleteConfig = Mage::getStoreConfig('Boxalino_General/autocomplete_extra');
|
| 64 |
-
$resultUrl = $catalogSearchHelper->getResultUrl();
|
| 65 |
-
|
| 66 |
-
$html = '<ul class="queries"><li style="display:none"></li>';
|
| 67 |
-
foreach ($suggestData as $index => $item) {
|
| 68 |
-
if ($index == 0) {
|
| 69 |
-
$item['row_class'] .= ' first';
|
| 70 |
-
if (empty($this->_first)) {
|
| 71 |
-
$this->_first = $item['id'];
|
| 72 |
-
}
|
| 73 |
-
}
|
| 74 |
-
|
| 75 |
-
if ($index == $count) {
|
| 76 |
-
$item['row_class'] .= ' last';
|
| 77 |
-
}
|
| 78 |
-
$all = false;
|
| 79 |
-
if ($autocompleteConfig['enabled_for_all'] == '1') {
|
| 80 |
-
$all = true;
|
| 81 |
-
}
|
| 82 |
-
|
| 83 |
-
if ($autocompleteConfig['enabled'] && count($item['facets']) > 0 && (($all == false && $index == 0) || ($all && $index >= 0))) {
|
| 84 |
-
$html .= '<li data-word="' . $item['id'] . '" title="' . $this->escapeHtml($item['title']) . '" class="' . $item['row_class'] . '">'
|
| 85 |
-
. '<span class="query-title">' . $item['html'] . '</span><span class="amount">(' . $item['num_of_results'] . ')</span></li>';
|
| 86 |
-
|
| 87 |
-
$c = 0;
|
| 88 |
-
foreach ($item['facets'] as $facet) {
|
| 89 |
-
if ($c++ >= $autocompleteConfig['items']) {
|
| 90 |
-
break;
|
| 91 |
-
}
|
| 92 |
-
$dataWord = ($autocompleteConfig['products'] == '1') ? ' data-word="' . $facet['id'] . '"' : '';
|
| 93 |
-
$html .= '<a class="facet"' . $dataWord . ' title="' . $this->escapeHtml($item['title']) . '&bx_categories[0]=' . urlencode($facet['href']) . '" href="' . $resultUrl . '?q=' . $this->escapeHtml($item['title']) . '&bx_categories[0]=' . urlencode($facet['href']) . '"><li' . $dataWord . ' class="facet ' . $item['row_class'] . '" title="' . $this->escapeHtml($facet['title']) . '" ><span class="query-title">' . $this->escapeHtml($facet['title']) . '</span><span class="amount">(' . $facet['hits'] . ')</span></li></a>';
|
| 94 |
-
}
|
| 95 |
-
} else {
|
| 96 |
-
$html .= '<li data-word="' . $item['id'] . '" title="' . $this->escapeHtml($item['title']) . '" class="' . $item['row_class'] . '">'
|
| 97 |
-
. '<span class="query-title">' . $item['html'] . '</span><span class="amount">(' . $item['num_of_results'] . ')</span></li>';
|
| 98 |
-
}
|
| 99 |
-
}
|
| 100 |
-
$html .= '</ul>';
|
| 101 |
-
|
| 102 |
-
$html .= $this->prepareDataProducts();
|
| 103 |
-
|
| 104 |
-
return $html;
|
| 105 |
-
}
|
| 106 |
-
|
| 107 |
-
public function prepareDataProducts()
|
| 108 |
-
{
|
| 109 |
-
$html = '<ul class="products">';
|
| 110 |
-
|
| 111 |
-
foreach ($this->_suggestDataProducts as $prods) {
|
| 112 |
-
|
| 113 |
-
foreach ($prods as $prod) {
|
| 114 |
-
|
| 115 |
-
if (Mage::getStoreConfig('Boxalino_General/autocomplete_html/enabled') == '1') {
|
| 116 |
-
|
| 117 |
-
$product = Mage::getModel('catalog/product')->load($prod['id']);
|
| 118 |
-
if ($prod['hash'] == $this->_first || empty($this->_first)) {
|
| 119 |
-
$html .= '<li data-word="' . $prod['hash'] . '" class="product-autocomplete" title="' . $this->escapeHtml($product->getName()) . '">';
|
| 120 |
-
} else {
|
| 121 |
-
$html .= '<li style="display:none" data-word="' . $prod['hash'] . '" class="product-autocomplete" title="' . $this->escapeHtml($product->getName()) . '">';
|
| 122 |
-
}
|
| 123 |
-
$html .= '<a href="' . $product->getProductUrl() . '" >';
|
| 124 |
-
$html .= '<div class="product-image"><img src="' . $product->getThumbnailUrl() . '" alt="' . $product->getName() . '"></div>';
|
| 125 |
-
$html .= '<div class="product-title"><span>' . $product->getName() . '</span></div>';
|
| 126 |
-
$html .= '</a>';
|
| 127 |
-
$html .= '</li>';
|
| 128 |
-
} else {
|
| 129 |
-
$html .= $this->prepareProductView($prod);
|
| 130 |
-
}
|
| 131 |
-
}
|
| 132 |
-
|
| 133 |
-
}
|
| 134 |
-
|
| 135 |
-
$html .= '</ul>';
|
| 136 |
-
|
| 137 |
-
return $html;
|
| 138 |
-
}
|
| 139 |
-
|
| 140 |
-
protected function prepareProductView($product)
|
| 141 |
-
{
|
| 142 |
-
$html = '';
|
| 143 |
-
|
| 144 |
-
if ($product['hash'] == $this->_first || empty($this->_first)) {
|
| 145 |
-
$html .= '<li style="display:block" data-word="' . $product['hash'] . '" class="product-autocomplete" title="' . $this->escapeHtml($product['title']) . '">';
|
| 146 |
-
} else {
|
| 147 |
-
$html .= '<li style="display:none" data-word="' . $product['hash'] . '" class="product-autocomplete" title="' . $this->escapeHtml($product['title']) . '">';
|
| 148 |
-
}
|
| 149 |
-
|
| 150 |
-
$html .= '<a href="' . $product['url'] . '" >';
|
| 151 |
-
unset($product['url']);
|
| 152 |
-
unset($product['hash']);
|
| 153 |
-
unset($product[Mage::getStoreConfig('Boxalino_General/search/entity_id')]);
|
| 154 |
-
|
| 155 |
-
foreach ($this->_order as $f) {
|
| 156 |
-
if ($f == 'image' && isset($product[$f]) && !empty($product[$f])) {
|
| 157 |
-
$html .= '<div class="product-' . $f . '"><img src="' . $product[$f] . '" alt="' . $product['title'] . '" style="max-height:75px; max-width:75px;"></div>';
|
| 158 |
-
} elseif (isset($product[$f]) && !empty($product[$f])) {
|
| 159 |
-
$html .= '<div class="product-' . $f . '"><span>' . $product[$f] . '</span></div>';
|
| 160 |
-
}
|
| 161 |
-
}
|
| 162 |
-
|
| 163 |
-
$html .= '</a>';
|
| 164 |
-
$html .= '</li>';
|
| 165 |
-
|
| 166 |
-
return $html;
|
| 167 |
-
}
|
| 168 |
-
|
| 169 |
-
public function getSuggestData()
|
| 170 |
-
{
|
| 171 |
-
$storeConfig = Mage::getStoreConfig('Boxalino_General/general');
|
| 172 |
-
if ($storeConfig['enabled'] == '0') {
|
| 173 |
-
return parent::getSuggestData();
|
| 174 |
-
}
|
| 175 |
-
|
| 176 |
-
if (!$this->_suggestData) {
|
| 177 |
-
$query = $this->helper('catalogsearch')->getQueryText();
|
| 178 |
-
|
| 179 |
-
$htmlConfig = Mage::getStoreConfig('Boxalino_General/autocomplete_html');
|
| 180 |
-
$generalConfig = Mage::getStoreConfig('Boxalino_General/search');
|
| 181 |
-
$p13nConfig = new Boxalino_CemSearch_Helper_P13n_Config(
|
| 182 |
-
$storeConfig['host'],
|
| 183 |
-
Mage::helper('Boxalino_CemSearch')->getAccount(),
|
| 184 |
-
$storeConfig['p13n_username'],
|
| 185 |
-
$storeConfig['p13n_password'],
|
| 186 |
-
$storeConfig['domain']
|
| 187 |
-
);
|
| 188 |
-
$p13n = new Boxalino_CemSearch_Helper_P13n_Adapter($p13nConfig);
|
| 189 |
-
|
| 190 |
-
if ($query) {
|
| 191 |
-
if ($htmlConfig['enabled'] == '1') {
|
| 192 |
-
$fields = array($generalConfig['entity_id'], 'title', 'score');
|
| 193 |
-
} else {
|
| 194 |
-
$fields = array($generalConfig['entity_id']);
|
| 195 |
-
$map = array($generalConfig['entity_id'] => $generalConfig['entity_id']);
|
| 196 |
-
$fi = explode(',', $htmlConfig['items']);
|
| 197 |
-
foreach ($fi as $f) {
|
| 198 |
-
list($attribute, $fieldname) = explode(':', $f);
|
| 199 |
-
$fields[] = $fieldname;
|
| 200 |
-
$map[$fieldname] = $attribute;
|
| 201 |
-
$this->_order[] = $attribute;
|
| 202 |
-
}
|
| 203 |
-
}
|
| 204 |
-
|
| 205 |
-
$p13n->autocomplete($query, $generalConfig['autocomplete_limit'], $generalConfig['autocomplete_products_limit'], $fields);
|
| 206 |
-
$collection = $p13n->getAutocompleteEntities();
|
| 207 |
-
$this->_first = $p13n->getPrefixSearchHash();
|
| 208 |
-
} else {
|
| 209 |
-
$collection = array();
|
| 210 |
-
}
|
| 211 |
-
|
| 212 |
-
$counter = 0;
|
| 213 |
-
$data = array();
|
| 214 |
-
foreach ($collection as $item) {
|
| 215 |
-
if ($item['hits'] <= 0) {
|
| 216 |
-
continue;
|
| 217 |
-
}
|
| 218 |
-
|
| 219 |
-
$_data = array(
|
| 220 |
-
'id' => substr(md5($item['text']), 0, 10),
|
| 221 |
-
'title' => $item['text'],
|
| 222 |
-
'html' => $item['html'],
|
| 223 |
-
'row_class' => (++$counter) % 2 ? 'odd' : 'even',
|
| 224 |
-
'num_of_results' => $item['hits'],
|
| 225 |
-
'facets' => $item['facets']
|
| 226 |
-
);
|
| 227 |
-
|
| 228 |
-
if ($item['text'] == $query) {
|
| 229 |
-
array_unshift($data, $_data);
|
| 230 |
-
} else {
|
| 231 |
-
$data[] = $_data;
|
| 232 |
-
}
|
| 233 |
-
}
|
| 234 |
-
|
| 235 |
-
$this->_suggestData = $data;
|
| 236 |
-
$facets = array_key_exists(0, $data) && is_array($data[0]['facets']) ? $data[0]['facets'] : array();
|
| 237 |
-
if ($htmlConfig['enabled'] == '1') {
|
| 238 |
-
$this->_suggestDataProducts = $p13n->getAutocompleteProducts($facets);
|
| 239 |
-
} else {
|
| 240 |
-
$this->_suggestDataProducts = $p13n->getAutocompleteProducts($facets, $map, $fields);
|
| 241 |
-
}
|
| 242 |
-
}
|
| 243 |
-
return $this->_suggestData;
|
| 244 |
-
}
|
| 245 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/code/community/Boxalino/CemSearch/Block/Cart/Crosssell.php
DELETED
|
@@ -1,88 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
|
| 3 |
-
/**
|
| 4 |
-
* Created by: Szymon Nosal <szymon.nosal@codete.com>
|
| 5 |
-
* Created at: 13.06.14 12:25
|
| 6 |
-
*/
|
| 7 |
-
class Boxalino_CemSearch_Block_Cart_Crosssell extends Mage_Checkout_Block_Cart_Crosssell
|
| 8 |
-
{
|
| 9 |
-
|
| 10 |
-
/**
|
| 11 |
-
* Items quantity will be capped to this value
|
| 12 |
-
*
|
| 13 |
-
* @var int
|
| 14 |
-
*/
|
| 15 |
-
protected $_maxItemCount = 4;
|
| 16 |
-
|
| 17 |
-
/**
|
| 18 |
-
* Get crosssell items
|
| 19 |
-
*
|
| 20 |
-
* @return array
|
| 21 |
-
*/
|
| 22 |
-
public function getItems()
|
| 23 |
-
{
|
| 24 |
-
|
| 25 |
-
if (Mage::getStoreConfig('Boxalino_General/general/enabled') == 0) {
|
| 26 |
-
return parent::getItems();
|
| 27 |
-
}
|
| 28 |
-
$name = Mage::getStoreConfig('Boxalino_Recommendation/cart/widget');
|
| 29 |
-
#####################################################################################
|
| 30 |
-
|
| 31 |
-
$cartItems = array();
|
| 32 |
-
foreach ($this->getQuote()->getAllItems() as $item) {
|
| 33 |
-
$productPrice = $item->getProduct()->getPrice();
|
| 34 |
-
$productId = $item->getProductId();
|
| 35 |
-
|
| 36 |
-
if ($item->getProductType() === 'configurable') {
|
| 37 |
-
continue;
|
| 38 |
-
}
|
| 39 |
-
|
| 40 |
-
$cartItems[] = array('id' => $productId, 'price' => $productPrice);
|
| 41 |
-
|
| 42 |
-
}
|
| 43 |
-
|
| 44 |
-
$_REQUEST['basketContent'] = json_encode($cartItems);
|
| 45 |
-
|
| 46 |
-
$p13nRecommendation = Boxalino_CemSearch_Helper_P13n_Recommendation::Instance();
|
| 47 |
-
|
| 48 |
-
$response = $p13nRecommendation->getRecommendation('basket', $name);
|
| 49 |
-
$entityIds = array();
|
| 50 |
-
|
| 51 |
-
if ($response === null) {
|
| 52 |
-
return null;
|
| 53 |
-
}
|
| 54 |
-
|
| 55 |
-
foreach ($response as $item) {
|
| 56 |
-
$entityIds[] = $item[Mage::getStoreConfig('Boxalino_General/search/entity_id')];
|
| 57 |
-
}
|
| 58 |
-
|
| 59 |
-
if (empty($entityIds)) {
|
| 60 |
-
return parent::getItems();
|
| 61 |
-
}
|
| 62 |
-
|
| 63 |
-
#########################################################################################
|
| 64 |
-
|
| 65 |
-
$itemCollection = Mage::getResourceModel('catalog/product_collection')
|
| 66 |
-
->addFieldToFilter('entity_id', $entityIds)
|
| 67 |
-
->addAttributeToSelect('*');
|
| 68 |
-
|
| 69 |
-
if (Mage::helper('catalog')->isModuleEnabled('Mage_Checkout')) {
|
| 70 |
-
Mage::getResourceSingleton('checkout/cart')->addExcludeProductFilter($itemCollection,
|
| 71 |
-
Mage::getSingleton('checkout/session')->getQuoteId()
|
| 72 |
-
);
|
| 73 |
-
$this->_addProductAttributesAndPrices($itemCollection);
|
| 74 |
-
}
|
| 75 |
-
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($itemCollection);
|
| 76 |
-
|
| 77 |
-
$itemCollection->load();
|
| 78 |
-
$items = array();
|
| 79 |
-
foreach ($itemCollection as $product) {
|
| 80 |
-
$product->setDoNotUseCategoryId(true);
|
| 81 |
-
$items[] = $product;
|
| 82 |
-
}
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
return $items;
|
| 86 |
-
}
|
| 87 |
-
|
| 88 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/code/community/Boxalino/CemSearch/Block/Facets.php
DELETED
|
@@ -1,323 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
|
| 3 |
-
class Boxalino_CemSearch_Block_Facets extends Mage_Core_Block_Template
|
| 4 |
-
{
|
| 5 |
-
/** @var array */
|
| 6 |
-
private $_allFilters = array();
|
| 7 |
-
|
| 8 |
-
/** @var array */
|
| 9 |
-
public $maxLevel = array();
|
| 10 |
-
|
| 11 |
-
public function __construct()
|
| 12 |
-
{
|
| 13 |
-
$this->_allFilters = Mage::helper('Boxalino_CemSearch')->getSearchAdapter()->getFacetsData();
|
| 14 |
-
}
|
| 15 |
-
|
| 16 |
-
/**
|
| 17 |
-
* Gets the current URL without filters
|
| 18 |
-
*
|
| 19 |
-
* @return string
|
| 20 |
-
*/
|
| 21 |
-
public function getResetUrl()
|
| 22 |
-
{
|
| 23 |
-
/** @var $helper Mage_Core_Helper_Url */
|
| 24 |
-
$helper = Mage::helper('core/url');
|
| 25 |
-
|
| 26 |
-
// get current url
|
| 27 |
-
$url = $helper->getCurrentUrl();
|
| 28 |
-
|
| 29 |
-
// parse url
|
| 30 |
-
$parsedUrl = parse_url($url);
|
| 31 |
-
|
| 32 |
-
// build url
|
| 33 |
-
$url = $parsedUrl['scheme'] . '://' . $parsedUrl['host'] . $parsedUrl['path'];
|
| 34 |
-
|
| 35 |
-
// get query parameters
|
| 36 |
-
if (isset($parsedUrl['query'])) {
|
| 37 |
-
parse_str($parsedUrl['query'], $q);
|
| 38 |
-
|
| 39 |
-
// remove bx filters
|
| 40 |
-
foreach ($q as $k => $v) {
|
| 41 |
-
if (strpos($k, 'bx_') === 0) {
|
| 42 |
-
unset($q[$k]);
|
| 43 |
-
}
|
| 44 |
-
}
|
| 45 |
-
|
| 46 |
-
// append query string
|
| 47 |
-
if ($q) {
|
| 48 |
-
$url .= '?' . http_build_query($q);
|
| 49 |
-
}
|
| 50 |
-
}
|
| 51 |
-
|
| 52 |
-
// return url
|
| 53 |
-
return $url;
|
| 54 |
-
}
|
| 55 |
-
|
| 56 |
-
public function getTopFilters()
|
| 57 |
-
{
|
| 58 |
-
$filters = array();
|
| 59 |
-
$filterOptions = Mage::getStoreConfig('Boxalino_General/filter');
|
| 60 |
-
$topFilters = explode(',', $filterOptions['top_filters']);
|
| 61 |
-
$titles = explode(',', $filterOptions['top_filters_title']);
|
| 62 |
-
$i = 0;
|
| 63 |
-
$allFilters = $this->_allFilters;
|
| 64 |
-
foreach ($topFilters as $filter) {
|
| 65 |
-
$filter = trim($filter);
|
| 66 |
-
if (isset($allFilters[$filter])) {
|
| 67 |
-
foreach ($allFilters[$filter] as $key => $values) {
|
| 68 |
-
$yes = (strtolower($values['stringValue']) == 'yes');
|
| 69 |
-
if ($values['stringValue'] == 1 || $yes) {
|
| 70 |
-
$filters[$filter] = $allFilters[$filter][$key];
|
| 71 |
-
$filters[$filter]['title'] = $titles[$i];
|
| 72 |
-
$filters[$filter]['url'] = $this->_getTopFilterUrl($filter, $yes?$values['stringValue']:'1', $allFilters[$filter][$key]['selected']);
|
| 73 |
-
$filters[$filter]['selected'] = $allFilters[$filter][$key]['selected'];
|
| 74 |
-
}
|
| 75 |
-
}
|
| 76 |
-
}
|
| 77 |
-
$i++;
|
| 78 |
-
}
|
| 79 |
-
return $filters;
|
| 80 |
-
}
|
| 81 |
-
|
| 82 |
-
public function getLeftFilters()
|
| 83 |
-
{
|
| 84 |
-
$filters = array();
|
| 85 |
-
$leftFilters = explode(',', Mage::getStoreConfig('Boxalino_General/filter/left_filters_normal'));
|
| 86 |
-
$leftFiltersTitles = explode(',', Mage::getStoreConfig('Boxalino_General/filter/left_filters_normal_title'));
|
| 87 |
-
$i = 0;
|
| 88 |
-
$allFilters = $this->_allFilters;
|
| 89 |
-
foreach ($leftFilters as $filterString) {
|
| 90 |
-
$position = 0;
|
| 91 |
-
$filter = explode(':', $filterString);
|
| 92 |
-
$filters[$filter[0]] = array('title' => $leftFiltersTitles[$i], 'values' => array());
|
| 93 |
-
if (isset($allFilters[$filter[0]])) {
|
| 94 |
-
if ($filter[1] == 'hierarchical') {
|
| 95 |
-
$filters[$filter[0]]['values'] = $this->_returnTree($filter[0]);
|
| 96 |
-
} else {
|
| 97 |
-
foreach ($allFilters[$filter[0]] as $key => $values) {
|
| 98 |
-
$filters[$filter[0]]['values'][] = $this->_returnImportantValues($values, $filter[1], $filter[0], $position);
|
| 99 |
-
$position++;
|
| 100 |
-
}
|
| 101 |
-
}
|
| 102 |
-
}
|
| 103 |
-
if (count($filters[$filter[0]]['values']) == 0) {
|
| 104 |
-
unset($filters[$filter[0]]);
|
| 105 |
-
}
|
| 106 |
-
$i++;
|
| 107 |
-
}
|
| 108 |
-
return $filters;
|
| 109 |
-
}
|
| 110 |
-
|
| 111 |
-
public function removeFilterFromUrl($url, $filter, $vals)
|
| 112 |
-
{
|
| 113 |
-
$key = 'bx_' . $filter;
|
| 114 |
-
if (array_key_exists($key, $_REQUEST) && is_array($_REQUEST[$key])) {
|
| 115 |
-
foreach ($vals as $val) {
|
| 116 |
-
$position = array_search($val, $_REQUEST[$key]);
|
| 117 |
-
if ($position !== false) {
|
| 118 |
-
$url = $this->_removeFilterFromUrl($url, $filter, $val, $position);
|
| 119 |
-
}
|
| 120 |
-
}
|
| 121 |
-
}
|
| 122 |
-
return $url;
|
| 123 |
-
}
|
| 124 |
-
|
| 125 |
-
public function getMinMaxValues($values)
|
| 126 |
-
{
|
| 127 |
-
$first = $values[0];
|
| 128 |
-
$last = end($values);
|
| 129 |
-
return array('min' => round(floor($first['stringValue']['min']), -2), 'max' => round(ceil($last['stringValue']['max'])), 1);
|
| 130 |
-
}
|
| 131 |
-
|
| 132 |
-
public function getMaxLevel($filter)
|
| 133 |
-
{
|
| 134 |
-
if (isset($this->maxLevel[$filter])) {
|
| 135 |
-
return $this->maxLevel[$filter];
|
| 136 |
-
}
|
| 137 |
-
|
| 138 |
-
return 0;
|
| 139 |
-
}
|
| 140 |
-
|
| 141 |
-
protected function _addFilterToUrl($url, $filter, $value, $position = 0)
|
| 142 |
-
{
|
| 143 |
-
return $url . (strpos($url, '?') === FALSE ? '?' : '&') .
|
| 144 |
-
'bx_' . $filter . '[' . $position . ']=' . urlencode($value);
|
| 145 |
-
}
|
| 146 |
-
|
| 147 |
-
protected function _getFilterUrl($name, $value, $selected, $ranged = false, $position = 0, $hierarchical = null)
|
| 148 |
-
{
|
| 149 |
-
$multioption = Mage::getStoreConfig('Boxalino_General/filter/left_filters_multioption');
|
| 150 |
-
$currentUrl = Mage::helper('core/url')->getCurrentUrl();
|
| 151 |
-
if (!$ranged) {
|
| 152 |
-
if ($multioption == true && $hierarchical == null) {
|
| 153 |
-
if ($selected === false) {
|
| 154 |
-
$url = $this->_addFilterToUrl($currentUrl, $name, $value, $position);
|
| 155 |
-
} else {
|
| 156 |
-
$url = $this->_removeFilterFromUrl($currentUrl, $name, $value, $position);
|
| 157 |
-
}
|
| 158 |
-
} else {
|
| 159 |
-
$position = 0;
|
| 160 |
-
if ($selected === false) {
|
| 161 |
-
if (array_key_exists('bx_' . $name, $_REQUEST) && is_array($_REQUEST['bx_' . $name])) {
|
| 162 |
-
foreach ($_REQUEST['bx_' . $name] as $val) {
|
| 163 |
-
$currentUrl = $this->_removeFilterFromUrl($currentUrl, $name, $val, $position);
|
| 164 |
-
}
|
| 165 |
-
}
|
| 166 |
-
$url = $this->_addFilterToUrl($currentUrl, $name, $value, $position);
|
| 167 |
-
} else {
|
| 168 |
-
$url = $this->_removeFilterFromUrl($currentUrl, $name, $value, $position);
|
| 169 |
-
}
|
| 170 |
-
}
|
| 171 |
-
} else {
|
| 172 |
-
if ($selected === false) {
|
| 173 |
-
$url = $this->_addFilterToUrl($currentUrl, $name, $value['from'] . '-' . $value['to'], $position);
|
| 174 |
-
} else {
|
| 175 |
-
$url = $this->_removeFilterFromUrl($currentUrl, $name, $value['from'] . '-' . $value['to'], $position);
|
| 176 |
-
}
|
| 177 |
-
}
|
| 178 |
-
return $url;
|
| 179 |
-
}
|
| 180 |
-
|
| 181 |
-
protected function _getTopFilterUrl($name, $value, $selected)
|
| 182 |
-
{
|
| 183 |
-
$filterOptions = Mage::getStoreConfig('Boxalino_General/filter');
|
| 184 |
-
$multioption = $filterOptions['top_filters_multioption'];
|
| 185 |
-
$currentUrl = Mage::helper('core/url')->getCurrentUrl();
|
| 186 |
-
if ($multioption == true) {
|
| 187 |
-
if ($selected === false) {
|
| 188 |
-
$url = $this->_addFilterToUrl($currentUrl, $name, $value);
|
| 189 |
-
} else {
|
| 190 |
-
$url = $this->_removeFilterFromUrl($currentUrl, $name, $value);
|
| 191 |
-
}
|
| 192 |
-
} else {
|
| 193 |
-
if ($selected === false) {
|
| 194 |
-
$topFilters = explode(',', $filterOptions['top_filters']);
|
| 195 |
-
foreach ($topFilters as $filter) {
|
| 196 |
-
$filter = trim($filter);
|
| 197 |
-
$currentUrl = $this->_removeFilterFromUrl($currentUrl, $filter, $value);
|
| 198 |
-
}
|
| 199 |
-
$url = $this->_addFilterToUrl($currentUrl, $name, $value);
|
| 200 |
-
} else {
|
| 201 |
-
$url = $this->_removeFilterFromUrl($currentUrl, $name, $value);
|
| 202 |
-
}
|
| 203 |
-
}
|
| 204 |
-
|
| 205 |
-
return $url;
|
| 206 |
-
}
|
| 207 |
-
|
| 208 |
-
protected function _removeFilterFromUrl($url, $filter, $value, $position = 0)
|
| 209 |
-
{
|
| 210 |
-
$filter = urlencode($filter);
|
| 211 |
-
$value = urlencode($value);
|
| 212 |
-
return str_replace(
|
| 213 |
-
array(
|
| 214 |
-
'&bx_' . $filter . '[' . $position . ']=' . $value,
|
| 215 |
-
'?bx_' . $filter . '[' . $position . ']=' . $value,
|
| 216 |
-
), '', $url
|
| 217 |
-
);
|
| 218 |
-
}
|
| 219 |
-
|
| 220 |
-
protected function _returnImportantValues($values, $option, $filter, $position)
|
| 221 |
-
{
|
| 222 |
-
$data = array();
|
| 223 |
-
if ($option == 'ranged') {
|
| 224 |
-
$data['stringValue'] = array('min' => $values['rangeFromInclusive'], 'max' => $values['rangeToExclusive']);
|
| 225 |
-
$data['url'] = $this->_getFilterUrl($filter, array('from' => $values['rangeFromInclusive'], 'to' => $values['rangeToExclusive']), $values['selected'], true, $position);
|
| 226 |
-
} else {
|
| 227 |
-
$data['url'] = $this->_getFilterUrl($filter, $values['stringValue'], $values['selected'], false, $position);
|
| 228 |
-
$data['stringValue'] = $values['stringValue'];
|
| 229 |
-
}
|
| 230 |
-
$data['hitCount'] = $values['hitCount'];
|
| 231 |
-
$data['selected'] = $values['selected'];
|
| 232 |
-
return $data;
|
| 233 |
-
}
|
| 234 |
-
|
| 235 |
-
protected function _returnHierarchy($filter)
|
| 236 |
-
{
|
| 237 |
-
$whatToDisplay = array('level' => 2, 'parentId' => '');
|
| 238 |
-
$parents = array();
|
| 239 |
-
$values = $this->_allFilters[$filter];
|
| 240 |
-
|
| 241 |
-
$amount = count($values);
|
| 242 |
-
for ($i = 0; $i < $amount; $i++) {
|
| 243 |
-
$parentLevel = count($values[$i]['hierarchy']);
|
| 244 |
-
for ($j = $i + 1; $j < $amount; $j++) {
|
| 245 |
-
if ($parentLevel < count($values[$j]['hierarchy'])) {
|
| 246 |
-
$level = count($values[$j]['hierarchy']);
|
| 247 |
-
$childId = $values[$j]['hierarchyId'];
|
| 248 |
-
$parents[$level][$childId] = array(
|
| 249 |
-
'stringValue' => end($values[$j]['hierarchy']),
|
| 250 |
-
'hitCount' => $values[$j]['hitCount'],
|
| 251 |
-
'parentId' => $values[$i]['hierarchyId'],
|
| 252 |
-
'url' => $this->_getFilterUrl($filter, $values[$j]['stringValue'], $values[$j]['selected'], false, 0),
|
| 253 |
-
'selected' => $values[$j]['selected']
|
| 254 |
-
);
|
| 255 |
-
if ($values[$j]['selected'] === true) {
|
| 256 |
-
$whatToDisplay = array('level' => $level + 1, 'parentId' => $values[$j]['hierarchyId']);
|
| 257 |
-
}
|
| 258 |
-
continue;
|
| 259 |
-
}
|
| 260 |
-
if (count($values[$i]['hierarchy']) == count($values[$j]['hierarchy'])) {
|
| 261 |
-
break;
|
| 262 |
-
}
|
| 263 |
-
}
|
| 264 |
-
}
|
| 265 |
-
return array('values' => $parents, 'display' => $whatToDisplay);
|
| 266 |
-
}
|
| 267 |
-
|
| 268 |
-
protected function _returnTree($filter)
|
| 269 |
-
{
|
| 270 |
-
$results = array();
|
| 271 |
-
$parents = $this->_returnHierarchy($filter);
|
| 272 |
-
$level = 0;
|
| 273 |
-
if ($parents['display']['level'] == 2) {
|
| 274 |
-
$results = $parents['values'][$parents['display']['level']];
|
| 275 |
-
return $results;
|
| 276 |
-
} else {
|
| 277 |
-
$highestChild = array();
|
| 278 |
-
$level = $parents['display']['level'];
|
| 279 |
-
$parentId = 0;
|
| 280 |
-
if (isset($parents['values'][$level])) {
|
| 281 |
-
$highestLevelCount = count($parents['values'][$level]);
|
| 282 |
-
foreach ($parents['values'][$level] as $value) {
|
| 283 |
-
$parentId = $parents['display']['parentId'];
|
| 284 |
-
if ($value['parentId'] == $parentId) {
|
| 285 |
-
if ($highestLevelCount == 1) {
|
| 286 |
-
$value['selected'] = true;
|
| 287 |
-
}
|
| 288 |
-
$value['level'] = $level;
|
| 289 |
-
$highestChild[] = $value;
|
| 290 |
-
}
|
| 291 |
-
}
|
| 292 |
-
} else {
|
| 293 |
-
$level = $level - 1;
|
| 294 |
-
foreach ($parents['values'][$level] as $value) {
|
| 295 |
-
if ($value['selected'] == true) {
|
| 296 |
-
$parentId = $value['parentId'];
|
| 297 |
-
$value['level'] = $level;
|
| 298 |
-
$highestChild[] = $value;
|
| 299 |
-
}
|
| 300 |
-
}
|
| 301 |
-
|
| 302 |
-
foreach ($parents['values'][$level] as $value) {
|
| 303 |
-
if ($parentId == $value['parentId'] && $value['selected'] == false) {
|
| 304 |
-
$value['level'] = $level;
|
| 305 |
-
$highestChild[] = $value;
|
| 306 |
-
}
|
| 307 |
-
}
|
| 308 |
-
}
|
| 309 |
-
|
| 310 |
-
for ($i = $level - 1; $i >= 2; $i--) {
|
| 311 |
-
$parents['values'][$i][$parentId]['selected'] = true;
|
| 312 |
-
$parents['values'][$i][$parentId]['level'] = $i;
|
| 313 |
-
$results[] = $parents['values'][$i][$parentId];
|
| 314 |
-
$parentId = $parents['values'][$i][$parentId]['parentId'];
|
| 315 |
-
}
|
| 316 |
-
$results = array_reverse($results);
|
| 317 |
-
|
| 318 |
-
}
|
| 319 |
-
$results = array_merge($results, $highestChild);
|
| 320 |
-
$this->maxLevel[$filter] = $level;
|
| 321 |
-
return $results;
|
| 322 |
-
}
|
| 323 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/code/community/Boxalino/CemSearch/Block/Product/List.php
DELETED
|
@@ -1,49 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
|
| 3 |
-
class Boxalino_CemSearch_Block_Product_List extends Mage_Catalog_Block_Product_List
|
| 4 |
-
{
|
| 5 |
-
/**
|
| 6 |
-
* Retrieve loaded category collection
|
| 7 |
-
*
|
| 8 |
-
* @return Mage_Eav_Model_Entity_Collection_Abstract
|
| 9 |
-
*/
|
| 10 |
-
protected function _getProductCollection()
|
| 11 |
-
{
|
| 12 |
-
if (Mage::getStoreConfig('Boxalino_General/general/enabled') == 0) {
|
| 13 |
-
return parent::_getProductCollection();
|
| 14 |
-
}
|
| 15 |
-
|
| 16 |
-
// make sure to only use products which are in the current category
|
| 17 |
-
if ($category = Mage::registry('current_category')) {
|
| 18 |
-
if (!$category->getIsAnchor()) {
|
| 19 |
-
return parent::_getProductCollection();
|
| 20 |
-
}
|
| 21 |
-
}
|
| 22 |
-
|
| 23 |
-
if (is_null($this->_productCollection)) {
|
| 24 |
-
$entity_ids = Mage::helper('Boxalino_CemSearch')->getSearchAdapter()->getEntitiesIds();
|
| 25 |
-
|
| 26 |
-
$this->_productCollection = Mage::getResourceModel('catalog/product_collection');
|
| 27 |
-
|
| 28 |
-
// Added check if there are any entity ids, otherwise force empty result
|
| 29 |
-
if (count($entity_ids) == 0) {
|
| 30 |
-
$entity_ids = array(0);
|
| 31 |
-
}
|
| 32 |
-
$this->_productCollection->addFieldToFilter('entity_id', $entity_ids)
|
| 33 |
-
->addAttributeToSelect('*');
|
| 34 |
-
|
| 35 |
-
// enforce boxalino ranking
|
| 36 |
-
$this->_productCollection->getSelect()->order(new Zend_Db_Expr('FIELD(e.entity_id,' . implode(',', $entity_ids).')'));
|
| 37 |
-
|
| 38 |
-
if (Mage::helper('catalog')->isModuleEnabled('Mage_Checkout')) {
|
| 39 |
-
Mage::getResourceSingleton('checkout/cart')->addExcludeProductFilter($this->_productCollection,
|
| 40 |
-
Mage::getSingleton('checkout/session')->getQuoteId()
|
| 41 |
-
);
|
| 42 |
-
$this->_addProductAttributesAndPrices($this->_productCollection);
|
| 43 |
-
}
|
| 44 |
-
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($this->_productCollection);
|
| 45 |
-
}
|
| 46 |
-
|
| 47 |
-
return $this->_productCollection;
|
| 48 |
-
}
|
| 49 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/code/community/Boxalino/CemSearch/Block/Product/List/Recommendation.php
DELETED
|
@@ -1,120 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
/**
|
| 3 |
-
* Created by: Simon Rupf <simon.rupf@boxalino.com>
|
| 4 |
-
* Created at: 15.04.2015 15:52
|
| 5 |
-
*/
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
/**
|
| 9 |
-
* Catalog product related items block
|
| 10 |
-
*
|
| 11 |
-
* @category Boxalino
|
| 12 |
-
* @package Boxalino_CemSearch
|
| 13 |
-
* @author Simon Rupf <simon.rupf@boxalino.com>
|
| 14 |
-
*/
|
| 15 |
-
class Boxalino_CemSearch_Block_Product_List_Recommendation extends Mage_Catalog_Block_Product_Abstract
|
| 16 |
-
{
|
| 17 |
-
protected $_itemCollection;
|
| 18 |
-
protected $_recommendationName = '';
|
| 19 |
-
protected $_recommendationAmount = 3;
|
| 20 |
-
protected $_recommendationContext = array();
|
| 21 |
-
protected $_recommendationParameterValues = array();
|
| 22 |
-
|
| 23 |
-
public function configure($name, $amount = 3, $context = array(), $parameterValues = array())
|
| 24 |
-
{
|
| 25 |
-
$this->_recommendationName = $name;
|
| 26 |
-
$this->_recommendationAmount = $amount;
|
| 27 |
-
$this->_recommendationContext = $context;
|
| 28 |
-
$this->_recommendationParameterValues = $parameterValues;
|
| 29 |
-
}
|
| 30 |
-
|
| 31 |
-
protected function _prepareData()
|
| 32 |
-
{
|
| 33 |
-
if (
|
| 34 |
-
Mage::getStoreConfig('Boxalino_General/general/enabled') == 0 ||
|
| 35 |
-
Mage::getStoreConfig('Boxalino_Recommendation/related/status', 0) == 0
|
| 36 |
-
) {
|
| 37 |
-
return parent::_prepareData();
|
| 38 |
-
}
|
| 39 |
-
|
| 40 |
-
if (isset($this->_recommendationContext['id'])) {
|
| 41 |
-
$_REQUEST['productId'] = $this->_recommendationContext['id'];
|
| 42 |
-
} elseif (count($this->_recommendationContext)) {
|
| 43 |
-
$_REQUEST['p13nRequestContext'] = $this->_recommendationContext;
|
| 44 |
-
foreach($_REQUEST['p13nRequestContext'] as $k => $v) {
|
| 45 |
-
if($v == '') {
|
| 46 |
-
switch($k) {
|
| 47 |
-
case 'id':
|
| 48 |
-
$_REQUEST['p13nRequestContext'][$k] = Mage::registry('product')->getId();
|
| 49 |
-
break;
|
| 50 |
-
case 'category':
|
| 51 |
-
$_REQUEST['p13nRequestContext'][$k] = Mage::registry('current_category');
|
| 52 |
-
break;
|
| 53 |
-
default:
|
| 54 |
-
if(isset($this->$_recommendationParameterValues[$k])) {
|
| 55 |
-
$_REQUEST['p13nRequestContext'][$k] = $this->_recommendationParameterValues[$k];
|
| 56 |
-
}
|
| 57 |
-
}
|
| 58 |
-
}
|
| 59 |
-
}
|
| 60 |
-
}
|
| 61 |
-
|
| 62 |
-
$p13nRecommendation = Boxalino_CemSearch_Helper_P13n_Recommendation::Instance();
|
| 63 |
-
|
| 64 |
-
$response = $p13nRecommendation->getRecommendation(
|
| 65 |
-
'free', $this->_recommendationName, $this->_recommendationAmount
|
| 66 |
-
);
|
| 67 |
-
$entityIds = array();
|
| 68 |
-
|
| 69 |
-
if ($response === null) {
|
| 70 |
-
$this->_itemCollection = new Varien_Data_Collection();
|
| 71 |
-
return $this;
|
| 72 |
-
}
|
| 73 |
-
|
| 74 |
-
foreach ($response as $item) {
|
| 75 |
-
$entityIds[] = $item[Mage::getStoreConfig('Boxalino_General/search/entity_id')];
|
| 76 |
-
}
|
| 77 |
-
|
| 78 |
-
$this->_itemCollection = Mage::getResourceModel('catalog/product_collection')
|
| 79 |
-
->addFieldToFilter('entity_id', $entityIds)
|
| 80 |
-
->addAttributeToSelect('*');
|
| 81 |
-
|
| 82 |
-
if (Mage::helper('catalog')->isModuleEnabled('Mage_Checkout')) {
|
| 83 |
-
Mage::getResourceSingleton('checkout/cart')->addExcludeProductFilter(
|
| 84 |
-
$this->_itemCollection,
|
| 85 |
-
Mage::getSingleton('checkout/session')->getQuoteId()
|
| 86 |
-
);
|
| 87 |
-
$this->_addProductAttributesAndPrices($this->_itemCollection);
|
| 88 |
-
}
|
| 89 |
-
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($this->_itemCollection);
|
| 90 |
-
|
| 91 |
-
$this->_itemCollection->load();
|
| 92 |
-
|
| 93 |
-
foreach ($this->_itemCollection as $product) {
|
| 94 |
-
$product->setDoNotUseCategoryId(true);
|
| 95 |
-
}
|
| 96 |
-
|
| 97 |
-
return $this;
|
| 98 |
-
}
|
| 99 |
-
|
| 100 |
-
protected function _beforeToHtml()
|
| 101 |
-
{
|
| 102 |
-
$this->_prepareData();
|
| 103 |
-
return parent::_beforeToHtml();
|
| 104 |
-
}
|
| 105 |
-
|
| 106 |
-
public function getItems()
|
| 107 |
-
{
|
| 108 |
-
return $this->_itemCollection;
|
| 109 |
-
}
|
| 110 |
-
|
| 111 |
-
/**
|
| 112 |
-
* Get tags array for saving cache
|
| 113 |
-
*
|
| 114 |
-
* @return array
|
| 115 |
-
*/
|
| 116 |
-
public function getCacheTags()
|
| 117 |
-
{
|
| 118 |
-
return array_merge(parent::getCacheTags(), $this->getItemsTags($this->getItems()));
|
| 119 |
-
}
|
| 120 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/code/community/Boxalino/CemSearch/Block/Product/List/Related.php
DELETED
|
@@ -1,60 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
|
| 3 |
-
/**
|
| 4 |
-
* Created by: Szymon Nosal <szymon.nosal@codete.com>
|
| 5 |
-
* Created at: 16.06.14 12:29
|
| 6 |
-
*/
|
| 7 |
-
class Boxalino_CemSearch_Block_Product_List_Related extends Mage_Catalog_Block_Product_List_Related
|
| 8 |
-
{
|
| 9 |
-
protected function _prepareData()
|
| 10 |
-
{
|
| 11 |
-
|
| 12 |
-
if (Mage::getStoreConfig('Boxalino_General/general/enabled') == 0 || Mage::getStoreConfig('Boxalino_Recommendation/related/status', 0) == 0) {
|
| 13 |
-
return parent::_prepareData();
|
| 14 |
-
}
|
| 15 |
-
$name = Mage::getStoreConfig('Boxalino_Recommendation/related/widget');
|
| 16 |
-
|
| 17 |
-
$product = Mage::registry('product');
|
| 18 |
-
/* @var $product Mage_Catalog_Model_Product */
|
| 19 |
-
|
| 20 |
-
##################################################################################
|
| 21 |
-
|
| 22 |
-
$_REQUEST['productId'] = $product->getId();
|
| 23 |
-
|
| 24 |
-
$p13nRecommendation = Boxalino_CemSearch_Helper_P13n_Recommendation::Instance();
|
| 25 |
-
|
| 26 |
-
$response = $p13nRecommendation->getRecommendation('product', $name);
|
| 27 |
-
$entityIds = array();
|
| 28 |
-
|
| 29 |
-
if ($response === null) {
|
| 30 |
-
$this->_itemCollection = new Varien_Data_Collection();
|
| 31 |
-
return $this;
|
| 32 |
-
}
|
| 33 |
-
|
| 34 |
-
foreach ($response as $item) {
|
| 35 |
-
$entityIds[] = $item[Mage::getStoreConfig('Boxalino_General/search/entity_id')];
|
| 36 |
-
}
|
| 37 |
-
|
| 38 |
-
###############################################################
|
| 39 |
-
$this->_itemCollection = Mage::getResourceModel('catalog/product_collection')
|
| 40 |
-
->addFieldToFilter('entity_id', $entityIds)
|
| 41 |
-
->addAttributeToSelect('*');
|
| 42 |
-
|
| 43 |
-
if (Mage::helper('catalog')->isModuleEnabled('Mage_Checkout')) {
|
| 44 |
-
Mage::getResourceSingleton('checkout/cart')->addExcludeProductFilter($this->_itemCollection,
|
| 45 |
-
Mage::getSingleton('checkout/session')->getQuoteId()
|
| 46 |
-
);
|
| 47 |
-
$this->_addProductAttributesAndPrices($this->_itemCollection);
|
| 48 |
-
}
|
| 49 |
-
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($this->_itemCollection);
|
| 50 |
-
|
| 51 |
-
$this->_itemCollection->load();
|
| 52 |
-
|
| 53 |
-
foreach ($this->_itemCollection as $product) {
|
| 54 |
-
$product->setDoNotUseCategoryId(true);
|
| 55 |
-
}
|
| 56 |
-
|
| 57 |
-
return $this;
|
| 58 |
-
}
|
| 59 |
-
|
| 60 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/code/community/Boxalino/CemSearch/Block/Product/List/Upsell.php
DELETED
|
@@ -1,67 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
|
| 3 |
-
/**
|
| 4 |
-
* Created by: Szymon Nosal <szymon.nosal@codete.com>
|
| 5 |
-
* Created at: 17.06.14 11:31
|
| 6 |
-
*/
|
| 7 |
-
class Boxalino_CemSearch_Block_Product_List_Upsell extends Mage_Catalog_Block_Product_List_Upsell
|
| 8 |
-
{
|
| 9 |
-
/**
|
| 10 |
-
* Default MAP renderer type
|
| 11 |
-
*
|
| 12 |
-
* @var string
|
| 13 |
-
*/
|
| 14 |
-
protected $_mapRenderer = 'msrp_noform';
|
| 15 |
-
|
| 16 |
-
protected $_itemCollection;
|
| 17 |
-
|
| 18 |
-
protected function _prepareData()
|
| 19 |
-
{
|
| 20 |
-
|
| 21 |
-
if (Mage::getStoreConfig('Boxalino_General/general/enabled') == 0 || Mage::getStoreConfig('Boxalino_Recommendation/upsell/status', 0) == 0) {
|
| 22 |
-
return parent::_prepareData();
|
| 23 |
-
}
|
| 24 |
-
$name = Mage::getStoreConfig('Boxalino_Recommendation/upsell/widget');
|
| 25 |
-
|
| 26 |
-
$product = Mage::registry('product');
|
| 27 |
-
$_REQUEST['productId'] = $product->getId();
|
| 28 |
-
|
| 29 |
-
$p13nRecommendation = Boxalino_CemSearch_Helper_P13n_Recommendation::Instance();
|
| 30 |
-
|
| 31 |
-
$response = $p13nRecommendation->getRecommendation('product', $name);
|
| 32 |
-
$entityIds = array();
|
| 33 |
-
|
| 34 |
-
if ($response === null) {
|
| 35 |
-
$this->_itemCollection = new Varien_Data_Collection();
|
| 36 |
-
return $this;
|
| 37 |
-
}
|
| 38 |
-
|
| 39 |
-
foreach ($response as $item) {
|
| 40 |
-
$entityIds[] = $item[Mage::getStoreConfig('Boxalino_General/search/entity_id')];
|
| 41 |
-
}
|
| 42 |
-
|
| 43 |
-
$this->_itemCollection = Mage::getResourceModel('catalog/product_collection')
|
| 44 |
-
->addFieldToFilter('entity_id', $entityIds)
|
| 45 |
-
->addAttributeToSelect('*');
|
| 46 |
-
|
| 47 |
-
if (Mage::helper('catalog')->isModuleEnabled('Mage_Checkout')) {
|
| 48 |
-
Mage::getResourceSingleton('checkout/cart')->addExcludeProductFilter($this->_itemCollection,
|
| 49 |
-
Mage::getSingleton('checkout/session')->getQuoteId()
|
| 50 |
-
);
|
| 51 |
-
$this->_addProductAttributesAndPrices($this->_itemCollection);
|
| 52 |
-
}
|
| 53 |
-
|
| 54 |
-
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($this->_itemCollection);
|
| 55 |
-
|
| 56 |
-
if ($this->getItemLimit('upsell') > 0) {
|
| 57 |
-
$this->_itemCollection->setPageSize($this->getItemLimit('upsell'));
|
| 58 |
-
}
|
| 59 |
-
|
| 60 |
-
$this->_itemCollection->load();
|
| 61 |
-
foreach ($this->_itemCollection as $product) {
|
| 62 |
-
$product->setDoNotUseCategoryId(true);
|
| 63 |
-
}
|
| 64 |
-
|
| 65 |
-
return $this;
|
| 66 |
-
}
|
| 67 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/code/community/Boxalino/CemSearch/CatalogSearch/Helper/Data.php
DELETED
|
@@ -1,27 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
|
| 3 |
-
class Boxalino_CemSearch_CatalogSearch_Helper_Data extends Mage_CatalogSearch_Helper_Data
|
| 4 |
-
{
|
| 5 |
-
|
| 6 |
-
protected $_urlForSearch;
|
| 7 |
-
|
| 8 |
-
public function setUrlForSearch($queryText)
|
| 9 |
-
{
|
| 10 |
-
$this->_urlForSearch = $queryText;
|
| 11 |
-
}
|
| 12 |
-
|
| 13 |
-
public function getUrlForSearch()
|
| 14 |
-
{
|
| 15 |
-
|
| 16 |
-
if (strlen($this->_urlForSearch) == 0) {
|
| 17 |
-
return $this->getEscapedQueryText();
|
| 18 |
-
}
|
| 19 |
-
|
| 20 |
-
return $this->_urlForSearch;
|
| 21 |
-
}
|
| 22 |
-
|
| 23 |
-
public function setQueryText($text)
|
| 24 |
-
{
|
| 25 |
-
$this->_queryText = $text;
|
| 26 |
-
}
|
| 27 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/code/community/Boxalino/CemSearch/Helper/Data.php
DELETED
|
@@ -1,351 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
|
| 3 |
-
class Boxalino_CemSearch_Helper_Data extends Mage_Core_Helper_Data
|
| 4 |
-
{
|
| 5 |
-
private $additionalFields = null;
|
| 6 |
-
private $searchAdapter = null;
|
| 7 |
-
|
| 8 |
-
public function __construct()
|
| 9 |
-
{
|
| 10 |
-
include_once(Mage::getModuleDir('', 'Boxalino_CemSearch') . '/Lib/vendor/Thrift/HttpP13n.php');
|
| 11 |
-
spl_autoload_register(array('Boxalino_CemSearch_Helper_Data', '__loadClass'), TRUE, TRUE);
|
| 12 |
-
}
|
| 13 |
-
|
| 14 |
-
public static function __loadClass($name)
|
| 15 |
-
{
|
| 16 |
-
if (strpos($name, 'Thrift\\') !== false) {
|
| 17 |
-
try {
|
| 18 |
-
include_once(Mage::getModuleDir('', 'Boxalino_CemSearch') . '/Lib/vendor/' . str_replace('\\', '/', $name) . '.php');
|
| 19 |
-
} catch (Exception $e) {
|
| 20 |
-
Mage::throwException($e->getMessage());
|
| 21 |
-
}
|
| 22 |
-
}
|
| 23 |
-
}
|
| 24 |
-
|
| 25 |
-
public function getBasketAmount()
|
| 26 |
-
{
|
| 27 |
-
$checkout = Mage::getSingleton('checkout/session');
|
| 28 |
-
$quote = $checkout->getQuote();
|
| 29 |
-
$amount = 0;
|
| 30 |
-
if ($quote) {
|
| 31 |
-
foreach ($quote->getAllVisibleItems() as $item) {
|
| 32 |
-
$amount += $item->getQty() * $item->getPrice();
|
| 33 |
-
}
|
| 34 |
-
}
|
| 35 |
-
return $amount;
|
| 36 |
-
}
|
| 37 |
-
|
| 38 |
-
public function getBasketItems()
|
| 39 |
-
{
|
| 40 |
-
$items = array();
|
| 41 |
-
$checkout = Mage::getSingleton('checkout/session');
|
| 42 |
-
$quote = $checkout->getQuote();
|
| 43 |
-
if ($quote) {
|
| 44 |
-
foreach ($quote->getAllVisibleItems() as $item) {
|
| 45 |
-
$items[] = $item->product_id;
|
| 46 |
-
}
|
| 47 |
-
}
|
| 48 |
-
return $items;
|
| 49 |
-
}
|
| 50 |
-
|
| 51 |
-
public function getBasketContent()
|
| 52 |
-
{
|
| 53 |
-
$checkout = Mage::getSingleton('checkout/session');
|
| 54 |
-
$quote = $checkout->getQuote();
|
| 55 |
-
$items = array();
|
| 56 |
-
if ($quote) {
|
| 57 |
-
foreach ($quote->getAllVisibleItems() as $item) {
|
| 58 |
-
$items[] = array(
|
| 59 |
-
'id' => $item->product_id,
|
| 60 |
-
'name' => $item->getProduct()->getName(),
|
| 61 |
-
'quantity' => $item->getQty(),
|
| 62 |
-
'price' => $item->getPrice(),
|
| 63 |
-
'widget' => $this->isProductFacilitated($item->product_id)
|
| 64 |
-
);
|
| 65 |
-
}
|
| 66 |
-
}
|
| 67 |
-
return @json_encode($items);
|
| 68 |
-
}
|
| 69 |
-
|
| 70 |
-
public function isSalesTrackingEnabled()
|
| 71 |
-
{
|
| 72 |
-
$trackSales = Mage::getStoreConfig('Boxalino_General/tracker/analytics');
|
| 73 |
-
return ($trackSales == 1);
|
| 74 |
-
}
|
| 75 |
-
|
| 76 |
-
public function isAnalyticsEnabled()
|
| 77 |
-
{
|
| 78 |
-
return (bool)Mage::getStoreConfig('Boxalino_General/tracker/analytics');
|
| 79 |
-
}
|
| 80 |
-
|
| 81 |
-
public function reportSearch($term, $filters = null)
|
| 82 |
-
{
|
| 83 |
-
if ($this->isAnalyticsEnabled()) {
|
| 84 |
-
$logTerm = addslashes($term);
|
| 85 |
-
$script = "_bxq.push(['trackSearch', '" . $logTerm . "', " . json_encode($filters) . "]);" . PHP_EOL;
|
| 86 |
-
return $script;
|
| 87 |
-
} else {
|
| 88 |
-
return '';
|
| 89 |
-
}
|
| 90 |
-
}
|
| 91 |
-
|
| 92 |
-
public function reportProductView($product)
|
| 93 |
-
{
|
| 94 |
-
if ($this->isAnalyticsEnabled()) {
|
| 95 |
-
$script = "_bxq.push(['trackProductView', '" . $product . "'])" . PHP_EOL;
|
| 96 |
-
return $script;
|
| 97 |
-
} else {
|
| 98 |
-
return '';
|
| 99 |
-
}
|
| 100 |
-
}
|
| 101 |
-
|
| 102 |
-
public function reportAddToBasket($product, $count, $price, $currency)
|
| 103 |
-
{
|
| 104 |
-
if ($this->isAnalyticsEnabled()) {
|
| 105 |
-
$script = "_bxq.push(['trackAddToBasket', '" . $product . "', " . $count . ", " . $price . ", '" . $currency . "']);" . PHP_EOL;
|
| 106 |
-
return $script;
|
| 107 |
-
} else {
|
| 108 |
-
return '';
|
| 109 |
-
}
|
| 110 |
-
}
|
| 111 |
-
|
| 112 |
-
public function reportCategoryView($categoryID)
|
| 113 |
-
{
|
| 114 |
-
if ($this->isAnalyticsEnabled()) {
|
| 115 |
-
$script = "_bxq.push(['trackCategoryView', '" . $categoryID . "'])" . PHP_EOL;
|
| 116 |
-
return $script;
|
| 117 |
-
} else {
|
| 118 |
-
return '';
|
| 119 |
-
}
|
| 120 |
-
}
|
| 121 |
-
|
| 122 |
-
public function reportLogin($customerId)
|
| 123 |
-
{
|
| 124 |
-
if ($this->isAnalyticsEnabled()) {
|
| 125 |
-
$script = "_bxq.push(['trackLogin', '" . $customerId . "'])" . PHP_EOL;
|
| 126 |
-
return $script;
|
| 127 |
-
} else {
|
| 128 |
-
return '';
|
| 129 |
-
}
|
| 130 |
-
}
|
| 131 |
-
|
| 132 |
-
/**
|
| 133 |
-
* @param $products array example:
|
| 134 |
-
* <code>
|
| 135 |
-
* array(
|
| 136 |
-
* array('product' => 'PRODUCTID1', 'quantity' => 1, 'price' => 59.90),
|
| 137 |
-
* array('product' => 'PRODUCTID2', 'quantity' => 2, 'price' => 10.0)
|
| 138 |
-
* )
|
| 139 |
-
* </code>
|
| 140 |
-
* @param $orderId string
|
| 141 |
-
* @param $price number
|
| 142 |
-
* @param $currency string
|
| 143 |
-
*/
|
| 144 |
-
public function reportPurchase($products, $orderId, $price, $currency)
|
| 145 |
-
{
|
| 146 |
-
$trackSales = Mage::getStoreConfig('Boxalino_General/tracker/track_sales');
|
| 147 |
-
|
| 148 |
-
$productsJson = json_encode($products);
|
| 149 |
-
if ($trackSales == 1) {
|
| 150 |
-
$script = "_bxq.push([" . PHP_EOL;
|
| 151 |
-
$script .= "'trackPurchase'," . PHP_EOL;
|
| 152 |
-
$script .= $price . "," . PHP_EOL;
|
| 153 |
-
$script .= "'" . $currency . "'," . PHP_EOL;
|
| 154 |
-
$script .= $productsJson . "," . PHP_EOL;
|
| 155 |
-
$script .= $orderId . "" . PHP_EOL;
|
| 156 |
-
$script .= "]);" . PHP_EOL;
|
| 157 |
-
return $script;
|
| 158 |
-
} else {
|
| 159 |
-
return '';
|
| 160 |
-
}
|
| 161 |
-
}
|
| 162 |
-
|
| 163 |
-
public function getLoggedInUserId()
|
| 164 |
-
{
|
| 165 |
-
if (Mage::getSingleton('customer/session')->isLoggedIn()) {
|
| 166 |
-
$customerData = Mage::getSingleton('customer/session')->getCustomer();
|
| 167 |
-
return $customerData->getId();
|
| 168 |
-
} else {
|
| 169 |
-
return null;
|
| 170 |
-
}
|
| 171 |
-
}
|
| 172 |
-
|
| 173 |
-
public function getAccount()
|
| 174 |
-
{
|
| 175 |
-
$isDev = Mage::getStoreConfig('Boxalino_General/general/account_dev');
|
| 176 |
-
$account = Mage::getStoreConfig('Boxalino_General/general/di_account');
|
| 177 |
-
|
| 178 |
-
if ($isDev) {
|
| 179 |
-
return $account . '_dev';
|
| 180 |
-
}
|
| 181 |
-
return $account;
|
| 182 |
-
}
|
| 183 |
-
|
| 184 |
-
public function getFiltersValues($params)
|
| 185 |
-
{
|
| 186 |
-
$filters = new stdClass();
|
| 187 |
-
if (isset($params['cat'])) {
|
| 188 |
-
$filters->filter_hc_category = '';
|
| 189 |
-
$category = Mage::getModel('catalog/category')->load($params['cat']);
|
| 190 |
-
$categories = explode('/', $category->getPath());
|
| 191 |
-
foreach ($categories as $cat) {
|
| 192 |
-
$name = $category = Mage::getModel('catalog/category')->load($cat)->getName();
|
| 193 |
-
if (strpos($name, '/') !== false) {
|
| 194 |
-
$name = str_replace('/', '\/', $name);
|
| 195 |
-
}
|
| 196 |
-
$filters->filter_hc_category .= '/' . $name;
|
| 197 |
-
|
| 198 |
-
}
|
| 199 |
-
unset($params['cat']);
|
| 200 |
-
}
|
| 201 |
-
|
| 202 |
-
if (isset($params['price'])) {
|
| 203 |
-
$prices = explode('-', $params['price']);
|
| 204 |
-
if (!empty($prices[0])) {
|
| 205 |
-
$filters->filter_from_incl_price = $prices[0];
|
| 206 |
-
}
|
| 207 |
-
if (!empty($prices[1])) {
|
| 208 |
-
$filters->filter_to_incl_price = $prices[1];
|
| 209 |
-
}
|
| 210 |
-
unset($params['price']);
|
| 211 |
-
}
|
| 212 |
-
if (isset($params)) {
|
| 213 |
-
foreach ($params as $param => $values) {
|
| 214 |
-
$getAttribute = Mage::getModel('catalog/product')->getResource()->getAttribute($param);
|
| 215 |
-
if ($getAttribute !== false) {
|
| 216 |
-
$values = html_entity_decode($values);
|
| 217 |
-
preg_match_all('!\d+!', $values, $matches);
|
| 218 |
-
if (is_array($matches[0])) {
|
| 219 |
-
$attrValues = array();
|
| 220 |
-
foreach ($matches[0] as $id) {
|
| 221 |
-
$paramName = 'filter_' . $param;
|
| 222 |
-
$attribute = $attribute = $getAttribute->getSource()->getOptionText($id);
|
| 223 |
-
$attrValues[] = $attribute;
|
| 224 |
-
}
|
| 225 |
-
$filters->$paramName = $attrValues;
|
| 226 |
-
}
|
| 227 |
-
}
|
| 228 |
-
}
|
| 229 |
-
}
|
| 230 |
-
return $filters;
|
| 231 |
-
}
|
| 232 |
-
|
| 233 |
-
/**
|
| 234 |
-
* Modifies a string to remove all non ASCII characters and spaces.
|
| 235 |
-
*/
|
| 236 |
-
public function sanitizeFieldName($text)
|
| 237 |
-
{
|
| 238 |
-
$maxLength = 50;
|
| 239 |
-
$delimiter = "_";
|
| 240 |
-
|
| 241 |
-
// replace non letter or digits by -
|
| 242 |
-
$text = preg_replace('~[^\\pL\d]+~u', $delimiter, $text);
|
| 243 |
-
|
| 244 |
-
// trim
|
| 245 |
-
$text = trim($text, $delimiter);
|
| 246 |
-
|
| 247 |
-
// transliterate
|
| 248 |
-
if (function_exists('iconv')) {
|
| 249 |
-
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
|
| 250 |
-
}
|
| 251 |
-
|
| 252 |
-
// lowercase
|
| 253 |
-
$text = strtolower($text);
|
| 254 |
-
|
| 255 |
-
// remove unwanted characters
|
| 256 |
-
$text = preg_replace('~[^_\w]+~', '', $text);
|
| 257 |
-
|
| 258 |
-
if (empty($text)) {
|
| 259 |
-
return null;
|
| 260 |
-
}
|
| 261 |
-
|
| 262 |
-
// max $maxLength (50) chars
|
| 263 |
-
$text = substr($text, 0, $maxLength);
|
| 264 |
-
$text = trim($text, $delimiter);
|
| 265 |
-
|
| 266 |
-
return $text;
|
| 267 |
-
}
|
| 268 |
-
|
| 269 |
-
public function getAdditionalFieldsFromP13n()
|
| 270 |
-
{
|
| 271 |
-
if ($this->additionalFields == null) {
|
| 272 |
-
$this->additionalFields = explode(',', Mage::getStoreConfig('Boxalino_General/general/additional_fields'));
|
| 273 |
-
}
|
| 274 |
-
return !empty($this->additionalFields) ? $this->additionalFields : array();
|
| 275 |
-
}
|
| 276 |
-
|
| 277 |
-
public function getSearchAdapter()
|
| 278 |
-
{
|
| 279 |
-
|
| 280 |
-
if ($this->searchAdapter === null) {
|
| 281 |
-
$storeConfig = Mage::getStoreConfig('Boxalino_General/general');
|
| 282 |
-
|
| 283 |
-
$p13nConfig = new Boxalino_CemSearch_Helper_P13n_Config(
|
| 284 |
-
$storeConfig['host'],
|
| 285 |
-
Mage::helper('Boxalino_CemSearch')->getAccount(),
|
| 286 |
-
$storeConfig['p13n_username'],
|
| 287 |
-
$storeConfig['p13n_password'],
|
| 288 |
-
$storeConfig['domain']
|
| 289 |
-
);
|
| 290 |
-
$p13nSort = new Boxalino_CemSearch_Helper_P13n_Sort();
|
| 291 |
-
|
| 292 |
-
$field = '';
|
| 293 |
-
$dir = '';
|
| 294 |
-
if(isset($_REQUEST['order'])){
|
| 295 |
-
if($_REQUEST['order'] == 'name'){
|
| 296 |
-
$field = 'title';
|
| 297 |
-
} elseif($_REQUEST['order'] == 'price'){
|
| 298 |
-
$field = 'discountedPrice';
|
| 299 |
-
}
|
| 300 |
-
}
|
| 301 |
-
if(isset($_REQUEST['dir'])){
|
| 302 |
-
$dir = $_REQUEST['dir']=='asc'?false:true;
|
| 303 |
-
} else{
|
| 304 |
-
$dir = false;
|
| 305 |
-
}
|
| 306 |
-
|
| 307 |
-
if($field !== '' && $dir !== ''){
|
| 308 |
-
$p13nSort->push($field, $dir);
|
| 309 |
-
}
|
| 310 |
-
|
| 311 |
-
$this->searchAdapter = new Boxalino_CemSearch_Helper_P13n_Adapter($p13nConfig);
|
| 312 |
-
|
| 313 |
-
/* @var $category Mage_Catalog_Model_Category */
|
| 314 |
-
$category = Mage::registry('current_category');
|
| 315 |
-
if (!empty($category)) {
|
| 316 |
-
$categoryPath = $category->getId();
|
| 317 |
-
$categoryNames = array('Default Category');
|
| 318 |
-
foreach ($category->getParentCategories() as $parentCategory) {
|
| 319 |
-
$categoryNames[] = $parentCategory->getName();
|
| 320 |
-
}
|
| 321 |
-
foreach ($categoryNames as $categoryName) {
|
| 322 |
-
$categoryPath .= '/' . $categoryName;
|
| 323 |
-
}
|
| 324 |
-
$_REQUEST['bx_categories'][0] = $categoryPath;
|
| 325 |
-
}
|
| 326 |
-
|
| 327 |
-
$generalConfig = Mage::getStoreConfig('Boxalino_General/search');
|
| 328 |
-
|
| 329 |
-
$this->searchAdapter->setupInquiry(
|
| 330 |
-
$generalConfig['quick_search'],
|
| 331 |
-
Mage::helper('catalogsearch')->getQueryText(),
|
| 332 |
-
substr(Mage::app()->getLocale()->getLocaleCode(), 0, 2),
|
| 333 |
-
array($generalConfig['entity_id'], 'categories'),
|
| 334 |
-
$p13nSort, 0,
|
| 335 |
-
($generalConfig['quick_search_limit'] == 0 ? 1000 : $generalConfig['quick_search_limit'])
|
| 336 |
-
);
|
| 337 |
-
|
| 338 |
-
if (isset($_GET['cat'])) {
|
| 339 |
-
$this->searchAdapter->addFilterCategory($_GET['cat']);
|
| 340 |
-
}
|
| 341 |
-
$this->searchAdapter->search();
|
| 342 |
-
$this->searchAdapter->prepareAdditionalDataFromP13n();
|
| 343 |
-
}
|
| 344 |
-
return $this->searchAdapter;
|
| 345 |
-
}
|
| 346 |
-
|
| 347 |
-
public function resetSearchAdapter()
|
| 348 |
-
{
|
| 349 |
-
$this->searchAdapter = null;
|
| 350 |
-
}
|
| 351 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/code/community/Boxalino/CemSearch/Helper/P13n/Adapter.php
DELETED
|
@@ -1,1043 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
|
| 3 |
-
/**
|
| 4 |
-
* User: Michal Sordyl
|
| 5 |
-
* Mail: michal.sordyl@codete.co
|
| 6 |
-
* Date: 28.05.14
|
| 7 |
-
*/
|
| 8 |
-
class Boxalino_CemSearch_Helper_P13n_Adapter
|
| 9 |
-
{
|
| 10 |
-
private $config = null;
|
| 11 |
-
private $p13n = null;
|
| 12 |
-
private $autocompleteRequest = null;
|
| 13 |
-
private $choiceRequest = null;
|
| 14 |
-
private $autocompleteResponse = null;
|
| 15 |
-
static private $choiceResponse = null;
|
| 16 |
-
private $returnFields = null;
|
| 17 |
-
private $inquiry = null;
|
| 18 |
-
private $searchQuery = null;
|
| 19 |
-
private $filters = array();
|
| 20 |
-
private $selectedFacets = array();
|
| 21 |
-
const VISITOR_COOKIE_TIME = 31536000;
|
| 22 |
-
|
| 23 |
-
public function __construct(Boxalino_CemSearch_Helper_P13n_Config $config)
|
| 24 |
-
{
|
| 25 |
-
$this->config = $config;
|
| 26 |
-
$this->p13n = new HttpP13n();
|
| 27 |
-
$this->configureP13n();
|
| 28 |
-
$this->createChoiceRequest();
|
| 29 |
-
}
|
| 30 |
-
|
| 31 |
-
private function getChoiceResponse()
|
| 32 |
-
{
|
| 33 |
-
if (empty(self::$choiceResponse)) {
|
| 34 |
-
$this->search();
|
| 35 |
-
}
|
| 36 |
-
return self::$choiceResponse;
|
| 37 |
-
}
|
| 38 |
-
|
| 39 |
-
private function configureP13n()
|
| 40 |
-
{
|
| 41 |
-
$this->p13n->setHost($this->config->getHost());
|
| 42 |
-
$this->p13n->setAuthorization($this->config->getUsername(), $this->config->getPassword());
|
| 43 |
-
}
|
| 44 |
-
|
| 45 |
-
private function createChoiceRequest()
|
| 46 |
-
{
|
| 47 |
-
$this->choiceRequest = $this->p13n->getChoiceRequest($this->config->getAccount(), $this->config->getDomain());
|
| 48 |
-
$this->choiceRequest = $this->p13n->addRequestContext($this->choiceRequest);
|
| 49 |
-
}
|
| 50 |
-
|
| 51 |
-
public function __destruct()
|
| 52 |
-
{
|
| 53 |
-
unset($this->p13n);
|
| 54 |
-
}
|
| 55 |
-
|
| 56 |
-
/**
|
| 57 |
-
* @param String $choiceId can be found on admin page /Recommendations/Widgets
|
| 58 |
-
* @param String test to search, eg 'shirt'
|
| 59 |
-
* @param String $language 2 letter language code, eg 'en'
|
| 60 |
-
* @param array $returnFields of field names, eg array('id', 'name')
|
| 61 |
-
* @param P13nSort $sort array('fieldName' => , 'reverse' =>);
|
| 62 |
-
* @param int $offset products to skip
|
| 63 |
-
* @param int $hitCount how many records
|
| 64 |
-
*/
|
| 65 |
-
public function setupInquiry($choiceId, $search, $language, $returnFields, $sort, $offset = 0, $hitCount = 10)
|
| 66 |
-
{
|
| 67 |
-
$this->inquiry = $this->createInquiry();
|
| 68 |
-
$returnFields = array_merge($returnFields, Mage::helper('Boxalino_CemSearch')->getAdditionalFieldsFromP13n());
|
| 69 |
-
$this->returnFields = $returnFields;
|
| 70 |
-
$this->createAndSetUpSearchQuery($search, $language, $returnFields, $offset, $hitCount);
|
| 71 |
-
$this->setUpSorting($sort);
|
| 72 |
-
|
| 73 |
-
$this->inquiry->choiceId = $choiceId;
|
| 74 |
-
|
| 75 |
-
}
|
| 76 |
-
|
| 77 |
-
public function setWithRelaxation($value)
|
| 78 |
-
{
|
| 79 |
-
$this->inquiry->withRelaxation = $value;
|
| 80 |
-
}
|
| 81 |
-
|
| 82 |
-
public function getChoiceRelaxation()
|
| 83 |
-
{
|
| 84 |
-
return self::$choiceResponse->variants[0]->searchRelaxation;
|
| 85 |
-
}
|
| 86 |
-
|
| 87 |
-
private function createInquiry()
|
| 88 |
-
{
|
| 89 |
-
$inquiry = new \com\boxalino\p13n\api\thrift\ChoiceInquiry();
|
| 90 |
-
return $inquiry;
|
| 91 |
-
}
|
| 92 |
-
|
| 93 |
-
private function createAndSetUpSearchQuery($search, $language, $returnFields, $offset, $hitCount)
|
| 94 |
-
{
|
| 95 |
-
$this->searchQuery = new \com\boxalino\p13n\api\thrift\SimpleSearchQuery();
|
| 96 |
-
$this->searchQuery->queryText = $search;
|
| 97 |
-
$this->searchQuery->indexId = $this->config->getAccount();
|
| 98 |
-
$this->searchQuery->language = $language;
|
| 99 |
-
$this->searchQuery->returnFields = $returnFields;
|
| 100 |
-
$this->searchQuery->offset = $offset;
|
| 101 |
-
$this->searchQuery->hitCount = $hitCount;
|
| 102 |
-
$this->searchQuery->facetRequests = $this->prepareFacets();
|
| 103 |
-
|
| 104 |
-
Boxalino_CemSearch_Model_Logger::saveFrontActions('query', $search);
|
| 105 |
-
Boxalino_CemSearch_Model_Logger::saveFrontActions('facets', $this->searchQuery->facetRequests);
|
| 106 |
-
}
|
| 107 |
-
|
| 108 |
-
private function setUpSorting(Boxalino_CemSearch_Helper_P13n_Sort $sorting)
|
| 109 |
-
{
|
| 110 |
-
$sortFieldsArray = $sorting->getSorts();
|
| 111 |
-
$sortFields = array();
|
| 112 |
-
foreach ($sortFieldsArray as $sortField) {
|
| 113 |
-
$sortFields[] = new \com\boxalino\p13n\api\thrift\SortField(array(
|
| 114 |
-
'fieldName' => $sortField['fieldName'],
|
| 115 |
-
'reverse' => $sortField['reverse']
|
| 116 |
-
));
|
| 117 |
-
}
|
| 118 |
-
if (!empty($sortFields)) {
|
| 119 |
-
$this->searchQuery->sortFields = $sortFields;
|
| 120 |
-
}
|
| 121 |
-
}
|
| 122 |
-
|
| 123 |
-
/**
|
| 124 |
-
* @param int $hierarchyId how deep is category tree in search, starts from 0 for main categories
|
| 125 |
-
* @param array $category names of categories in hierarchy
|
| 126 |
-
*
|
| 127 |
-
* exaples:
|
| 128 |
-
* $hierarchyId = 0;
|
| 129 |
-
* $category = array('Men');
|
| 130 |
-
* will search all products in category 'Men' (with subcategories)
|
| 131 |
-
*
|
| 132 |
-
* $hierarchyId = 1;
|
| 133 |
-
* $category = array('Men', 'Blazers');
|
| 134 |
-
* will search all products in category 'Men' (with subcategories)
|
| 135 |
-
*
|
| 136 |
-
*/
|
| 137 |
-
public function addFilterCategories($categoryId)
|
| 138 |
-
{
|
| 139 |
-
$categoryNames = array();
|
| 140 |
-
if (isset($categoryId) && $categoryId > 0) {
|
| 141 |
-
$category = Mage::getModel('catalog/category')->load($categoryId);
|
| 142 |
-
$path = $category->getPath();
|
| 143 |
-
$pathArray = explode('/', $path);
|
| 144 |
-
$skip = -2;
|
| 145 |
-
foreach ($pathArray as $catId) {
|
| 146 |
-
$categoryName = Mage::getModel('catalog/category')->load($catId)->getName();
|
| 147 |
-
|
| 148 |
-
if (++$skip > 0) {
|
| 149 |
-
$categoryNames[] = $categoryName;
|
| 150 |
-
}
|
| 151 |
-
}
|
| 152 |
-
|
| 153 |
-
$this->addFilterHierarchy('categories', $categoryId, $categoryNames);
|
| 154 |
-
|
| 155 |
-
}
|
| 156 |
-
}
|
| 157 |
-
|
| 158 |
-
/**
|
| 159 |
-
* @param $categoryId
|
| 160 |
-
*/
|
| 161 |
-
public function addFilterCategory($categoryId)
|
| 162 |
-
{
|
| 163 |
-
|
| 164 |
-
if (isset($categoryId) && $categoryId > 0) {
|
| 165 |
-
$category = Mage::getModel('catalog/category')->load($categoryId);
|
| 166 |
-
|
| 167 |
-
if ($category != null) {
|
| 168 |
-
$filter = new \com\boxalino\p13n\api\thrift\Filter();
|
| 169 |
-
|
| 170 |
-
$filter->fieldName = 'categories';
|
| 171 |
-
|
| 172 |
-
$filter->hierarchyId = $categoryId;
|
| 173 |
-
$filter->hierarchy = array($category->getName());
|
| 174 |
-
|
| 175 |
-
$this->filters[] = $filter;
|
| 176 |
-
}
|
| 177 |
-
|
| 178 |
-
}
|
| 179 |
-
|
| 180 |
-
}
|
| 181 |
-
|
| 182 |
-
/**
|
| 183 |
-
* @param string $field field name for filter
|
| 184 |
-
* @param int $hierarchyId names of categories in hierarchy
|
| 185 |
-
* @param int $hierarchy names of categories in hierarchy
|
| 186 |
-
* @param string|null $lang
|
| 187 |
-
*
|
| 188 |
-
*/
|
| 189 |
-
public function addFilterHierarchy($field, $hierarchyId, $hierarchy, $lang = null)
|
| 190 |
-
{
|
| 191 |
-
$filter = new \com\boxalino\p13n\api\thrift\Filter();
|
| 192 |
-
|
| 193 |
-
if ($lang) {
|
| 194 |
-
$filter->fieldName = $field . '_' . substr(Mage::app()->getLocale()->getLocaleCode(), 0, 2);
|
| 195 |
-
} else {
|
| 196 |
-
$filter->fieldName = $field;
|
| 197 |
-
}
|
| 198 |
-
|
| 199 |
-
$filter->hierarchyId = $hierarchyId;
|
| 200 |
-
$filter->hierarchy = $hierarchy;
|
| 201 |
-
|
| 202 |
-
$this->filters[] = $filter;
|
| 203 |
-
}
|
| 204 |
-
|
| 205 |
-
/**
|
| 206 |
-
* @param float $from
|
| 207 |
-
* @param float $to
|
| 208 |
-
*/
|
| 209 |
-
public function setupPrice($from, $to)
|
| 210 |
-
{
|
| 211 |
-
$this->filters[] = new \com\boxalino\p13n\api\thrift\Filter(array(
|
| 212 |
-
'fieldName' => 'discountedPrice',
|
| 213 |
-
'rangeFrom' => $from,
|
| 214 |
-
'rangeTo' => $to
|
| 215 |
-
));
|
| 216 |
-
}
|
| 217 |
-
|
| 218 |
-
/**
|
| 219 |
-
* @param string $field field name for filter
|
| 220 |
-
* @param mixed $value filter value
|
| 221 |
-
* @param string|null $lang
|
| 222 |
-
*
|
| 223 |
-
*/
|
| 224 |
-
public function addFilter($field, $value, $lang = null)
|
| 225 |
-
{
|
| 226 |
-
$filter = new \com\boxalino\p13n\api\thrift\Filter();
|
| 227 |
-
|
| 228 |
-
if ($lang) {
|
| 229 |
-
$filter->fieldName = $field . '_' . substr(Mage::app()->getLocale()->getLocaleCode(), 0, 2);
|
| 230 |
-
} else {
|
| 231 |
-
$filter->fieldName = $field;
|
| 232 |
-
}
|
| 233 |
-
|
| 234 |
-
if (is_array($value)) {
|
| 235 |
-
$filter->stringValues = $value;
|
| 236 |
-
} else {
|
| 237 |
-
$filter->stringValues = array($value);
|
| 238 |
-
}
|
| 239 |
-
|
| 240 |
-
$this->filters[] = $filter;
|
| 241 |
-
}
|
| 242 |
-
|
| 243 |
-
/**
|
| 244 |
-
* @param string $field field name for filter
|
| 245 |
-
* @param number $from param from
|
| 246 |
-
* @param number $to param from
|
| 247 |
-
* @param string|null $lang
|
| 248 |
-
*
|
| 249 |
-
*/
|
| 250 |
-
public function addFilterFromTo($field, $from, $to, $lang = null)
|
| 251 |
-
{
|
| 252 |
-
$filter = new \com\boxalino\p13n\api\thrift\Filter();
|
| 253 |
-
|
| 254 |
-
if ($lang) {
|
| 255 |
-
$filter->fieldName = $field . '_' . substr(Mage::app()->getLocale()->getLocaleCode(), 0, 2);
|
| 256 |
-
} else {
|
| 257 |
-
$filter->fieldName = $field;
|
| 258 |
-
}
|
| 259 |
-
|
| 260 |
-
$filter->rangeFrom = $from;
|
| 261 |
-
$filter->rangeTo = $to;
|
| 262 |
-
|
| 263 |
-
$this->filters[] = $filter;
|
| 264 |
-
}
|
| 265 |
-
|
| 266 |
-
public function autocomplete($text, $limit, $products_limit = 0, $fields = null)
|
| 267 |
-
{
|
| 268 |
-
$searchConfig = Mage::getStoreConfig('Boxalino_General/search');
|
| 269 |
-
if ($fields == null) {
|
| 270 |
-
array($searchConfig['entity_id'], 'title', 'score');
|
| 271 |
-
}
|
| 272 |
-
$this->autocompleteRequest = $this->getAutocompleteRequest($this->config->getAccount(), $this->config->getDomain());
|
| 273 |
-
$this->autocompleteRequest = $this->p13n->addRequestContext($this->autocompleteRequest);
|
| 274 |
-
|
| 275 |
-
$searchQuery = new \com\boxalino\p13n\api\thrift\SimpleSearchQuery();
|
| 276 |
-
$searchQuery->indexId = $this->config->getAccount();
|
| 277 |
-
$searchQuery->language = substr(Mage::app()->getLocale()->getLocaleCode(), 0, 2);
|
| 278 |
-
$searchQuery->returnFields = $fields;
|
| 279 |
-
$searchQuery->offset = 0;
|
| 280 |
-
$searchQuery->hitCount = $products_limit;
|
| 281 |
-
$searchQuery->queryText = $text;
|
| 282 |
-
$searchQuery->facetRequests = array();
|
| 283 |
-
|
| 284 |
-
$config = Mage::getStoreConfig('Boxalino_General/autocomplete_extra');
|
| 285 |
-
if ($config['enabled']) {
|
| 286 |
-
$facet = new \com\boxalino\p13n\api\thrift\FacetRequest();
|
| 287 |
-
$facet->fieldName = 'categories';
|
| 288 |
-
$facet->numerical = false;
|
| 289 |
-
$facet->range = false;
|
| 290 |
-
$searchQuery->facetRequests[] = $facet;
|
| 291 |
-
}
|
| 292 |
-
|
| 293 |
-
if ($this->filterByVisibleProducts()) {
|
| 294 |
-
$searchQuery->filters[] = $this->filterByVisibleProducts();
|
| 295 |
-
}
|
| 296 |
-
if ($this->filterByStatusProducts()) {
|
| 297 |
-
$searchQuery->filters[] = $this->filterByStatusProducts();
|
| 298 |
-
}
|
| 299 |
-
$autocompleteQuery = new \com\boxalino\p13n\api\thrift\AutocompleteQuery();
|
| 300 |
-
$autocompleteQuery->indexId = $this->config->getAccount();
|
| 301 |
-
$autocompleteQuery->language = substr(Mage::app()->getLocale()->getLocaleCode(), 0, 2);
|
| 302 |
-
$autocompleteQuery->queryText = $text;
|
| 303 |
-
$autocompleteQuery->suggestionsHitCount = $limit;
|
| 304 |
-
$autocompleteQuery->highlight = true;
|
| 305 |
-
$autocompleteQuery->highlightPre = '<em>';
|
| 306 |
-
$autocompleteQuery->highlightPost = '</em>';
|
| 307 |
-
|
| 308 |
-
$this->autocompleteRequest->choiceId = $searchConfig['autocomplete'];
|
| 309 |
-
$this->autocompleteRequest->autocompleteQuery = $autocompleteQuery;
|
| 310 |
-
$this->autocompleteRequest->searchChoiceId = $searchConfig['quick_search'];
|
| 311 |
-
$this->autocompleteRequest->searchQuery = $searchQuery;
|
| 312 |
-
|
| 313 |
-
Boxalino_CemSearch_Model_Logger::saveFrontActions('autocomplete_Query', $text);
|
| 314 |
-
Boxalino_CemSearch_Model_Logger::saveFrontActions('autocomplete_Request', $this->autocompleteRequest);
|
| 315 |
-
Boxalino_CemSearch_Model_Logger::saveFrontActions('autocomplete_Request_serialized', serialize($this->autocompleteRequest));
|
| 316 |
-
|
| 317 |
-
$this->autocompleteResponse = $this->p13n->autocomplete($this->autocompleteRequest);
|
| 318 |
-
|
| 319 |
-
Boxalino_CemSearch_Model_Logger::saveFrontActions('autocomplete_Response', $this->autocompleteResponse, 1);
|
| 320 |
-
|
| 321 |
-
}
|
| 322 |
-
|
| 323 |
-
public function getAutocompleteEntities()
|
| 324 |
-
{
|
| 325 |
-
$suggestions = array();
|
| 326 |
-
$config = Mage::getStoreConfig('Boxalino_General/autocomplete_extra');
|
| 327 |
-
|
| 328 |
-
foreach ($this->autocompleteResponse->hits as $hit) {
|
| 329 |
-
|
| 330 |
-
$tmp = array('text' => $hit->suggestion, 'html' => (strlen($hit->highlighted) ? $hit->highlighted : $hit->suggestion), 'hits' => $hit->searchResult->totalHitCount);
|
| 331 |
-
$facets = array();
|
| 332 |
-
|
| 333 |
-
if ($config['enabled']) {
|
| 334 |
-
$tmp['facets'] = array_slice($this->getFacetLeafs($hit->searchResult->facetResponses[0]->values, $hit, $config), 0, Mage::getStoreConfig('Boxalino_General/autocomplete_extra/items'));
|
| 335 |
-
}
|
| 336 |
-
|
| 337 |
-
$suggestions[] = $tmp;
|
| 338 |
-
}
|
| 339 |
-
return $suggestions;
|
| 340 |
-
}
|
| 341 |
-
|
| 342 |
-
protected function getFacetDepth($facet)
|
| 343 |
-
{
|
| 344 |
-
|
| 345 |
-
return substr_count($facet->stringValue, '/');
|
| 346 |
-
|
| 347 |
-
}
|
| 348 |
-
|
| 349 |
-
protected function getFacetLeafs($facets, $hit, $config)
|
| 350 |
-
{
|
| 351 |
-
$tmp = array();
|
| 352 |
-
|
| 353 |
-
foreach ($facets as $facet) {
|
| 354 |
-
|
| 355 |
-
foreach ($facet->hierarchy as $h) {
|
| 356 |
-
if (array_key_exists($h, $tmp)) {
|
| 357 |
-
unset($tmp[$h]);
|
| 358 |
-
}
|
| 359 |
-
}
|
| 360 |
-
|
| 361 |
-
$tmp[end($facet->hierarchy)] = array(
|
| 362 |
-
'title' => end($facet->hierarchy),
|
| 363 |
-
'hits' => $facet->hitCount,
|
| 364 |
-
'href' => $facet->stringValue,
|
| 365 |
-
'id' => substr(md5($hit->suggestion . '_' . $facet->stringValue), 0, 10)
|
| 366 |
-
);
|
| 367 |
-
}
|
| 368 |
-
|
| 369 |
-
if ($config['sort']) {
|
| 370 |
-
usort($tmp, array($this, 'cmpFacets'));
|
| 371 |
-
}
|
| 372 |
-
|
| 373 |
-
return $tmp;
|
| 374 |
-
}
|
| 375 |
-
|
| 376 |
-
private function cmpFacets($a, $b)
|
| 377 |
-
{
|
| 378 |
-
if ($a['hits'] == $b['hits']) {
|
| 379 |
-
return 0;
|
| 380 |
-
}
|
| 381 |
-
return ($a['hits'] > $b['hits']) ? -1 : 1;
|
| 382 |
-
}
|
| 383 |
-
|
| 384 |
-
private function filterByVisibleProducts()
|
| 385 |
-
{
|
| 386 |
-
$filter = new \com\boxalino\p13n\api\thrift\Filter();
|
| 387 |
-
$filter->fieldName = 'products_visibility';
|
| 388 |
-
$filter->negative = true;
|
| 389 |
-
$filter->stringValues = array(Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE, Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG);
|
| 390 |
-
return $filter;
|
| 391 |
-
}
|
| 392 |
-
|
| 393 |
-
private function filterByStatusProducts()
|
| 394 |
-
{
|
| 395 |
-
$filter = new \com\boxalino\p13n\api\thrift\Filter();
|
| 396 |
-
$filter->fieldName = 'products_status';
|
| 397 |
-
$filter->stringValues = array(Mage_Catalog_Model_Product_Status::STATUS_ENABLED);
|
| 398 |
-
return $filter;
|
| 399 |
-
}
|
| 400 |
-
|
| 401 |
-
private function extractItemsFromHits($hits, $hash, $entity_id, $map)
|
| 402 |
-
{
|
| 403 |
-
$items = array();
|
| 404 |
-
foreach ($hits as $item) {
|
| 405 |
-
$tmp = array();
|
| 406 |
-
$tmp['hash'] = $hash;
|
| 407 |
-
foreach ($item->values as $key => $value) {
|
| 408 |
-
if (array_key_exists($key, $map)) {
|
| 409 |
-
if (is_array($value)) {
|
| 410 |
-
$tmp[$map[$key]] = array_shift($value);
|
| 411 |
-
} else {
|
| 412 |
-
$tmp[$map[$key]] = $value;
|
| 413 |
-
}
|
| 414 |
-
}
|
| 415 |
-
}
|
| 416 |
-
$items[] = $tmp;
|
| 417 |
-
}
|
| 418 |
-
return $items;
|
| 419 |
-
}
|
| 420 |
-
|
| 421 |
-
public function getPrefixSearchHash() {
|
| 422 |
-
if ($this->autocompleteResponse->prefixSearchResult->totalHitCount > 0) {
|
| 423 |
-
return substr(md5($this->autocompleteResponse->prefixSearchResult->queryText), 0, 10);
|
| 424 |
-
} else {
|
| 425 |
-
return null;
|
| 426 |
-
}
|
| 427 |
-
}
|
| 428 |
-
|
| 429 |
-
public function getAutocompleteProducts($facets, $map = null, $fields = null)
|
| 430 |
-
{
|
| 431 |
-
if (!is_array($facets)) {
|
| 432 |
-
$facets = array();
|
| 433 |
-
}
|
| 434 |
-
|
| 435 |
-
$fs = array();
|
| 436 |
-
foreach($facets as $f) {
|
| 437 |
-
$fs[] = $f['id'];
|
| 438 |
-
}
|
| 439 |
-
|
| 440 |
-
$generalConfig = Mage::getStoreConfig('Boxalino_General/search');
|
| 441 |
-
$extraConfig = Mage::getStoreConfig('Boxalino_General/autocomplete_extra');
|
| 442 |
-
$entity_id = $generalConfig['entity_id'];
|
| 443 |
-
|
| 444 |
-
if (!is_array($map)) {
|
| 445 |
-
$map = array($entity_id => $entity_id);
|
| 446 |
-
}
|
| 447 |
-
|
| 448 |
-
if (!is_array($fields)) {
|
| 449 |
-
$fields = array($entity_id);
|
| 450 |
-
}
|
| 451 |
-
|
| 452 |
-
// prefix search result
|
| 453 |
-
$products = array();
|
| 454 |
-
$id = substr(md5($this->autocompleteResponse->prefixSearchResult->queryText), 0, 10);
|
| 455 |
-
$products[$id] = $this->extractItemsFromHits($this->autocompleteResponse->prefixSearchResult->hits, $id, $entity_id, $map);
|
| 456 |
-
|
| 457 |
-
// facets
|
| 458 |
-
if ($extraConfig['products'] == '1') {
|
| 459 |
-
$storeConfig = Mage::getStoreConfig('Boxalino_General/general');
|
| 460 |
-
$p13nConfig = new Boxalino_CemSearch_Helper_P13n_Config(
|
| 461 |
-
$storeConfig['host'],
|
| 462 |
-
Mage::helper('Boxalino_CemSearch')->getAccount(),
|
| 463 |
-
$storeConfig['p13n_username'],
|
| 464 |
-
$storeConfig['p13n_password'],
|
| 465 |
-
$storeConfig['domain']
|
| 466 |
-
);
|
| 467 |
-
$p13nSort = new Boxalino_CemSearch_Helper_P13n_Sort();
|
| 468 |
-
}
|
| 469 |
-
|
| 470 |
-
$lang = substr(Mage::app()->getLocale()->getLocaleCode(), 0, 2);
|
| 471 |
-
$i = 0;
|
| 472 |
-
$iMax = $generalConfig['autocomplete_limit'];
|
| 473 |
-
foreach ($this->autocompleteResponse->hits as $hit) {
|
| 474 |
-
if ($i++ >= $iMax) {
|
| 475 |
-
break;
|
| 476 |
-
}
|
| 477 |
-
|
| 478 |
-
$id = substr(md5($hit->suggestion), 0, 10);
|
| 479 |
-
$products[$id] = $this->extractItemsFromHits($hit->searchResult->hits, $id, $entity_id, $map);
|
| 480 |
-
|
| 481 |
-
if ($extraConfig['products'] == '1' && ($i == 1 || $extraConfig['enabled_for_all'] == '0')) {
|
| 482 |
-
$j = 0;
|
| 483 |
-
$jMax = $extraConfig['items'];
|
| 484 |
-
foreach ($hit->searchResult->facetResponses[0]->values as $f) {
|
| 485 |
-
if ($j++ >= $jMax) {
|
| 486 |
-
break;
|
| 487 |
-
}
|
| 488 |
-
|
| 489 |
-
$id = substr(md5($hit->suggestion . '_' . $f->stringValue), 0, 10);
|
| 490 |
-
|
| 491 |
-
if (!in_array($id, $fs)) {
|
| 492 |
-
if ($j >= $jMax) {
|
| 493 |
-
break;
|
| 494 |
-
}
|
| 495 |
-
continue;
|
| 496 |
-
}
|
| 497 |
-
|
| 498 |
-
$p13n = new Boxalino_CemSearch_Helper_P13n_Adapter($p13nConfig);
|
| 499 |
-
$p13n->setupInquiry(
|
| 500 |
-
$generalConfig['quick_search'],
|
| 501 |
-
$this->autocompleteResponse->prefixSearchResult->queryText,
|
| 502 |
-
$lang,
|
| 503 |
-
$fields,
|
| 504 |
-
$p13nSort,
|
| 505 |
-
0, 4
|
| 506 |
-
);
|
| 507 |
-
$p13n->setWithRelaxation(false);
|
| 508 |
-
|
| 509 |
-
$tmp = new \com\boxalino\p13n\api\thrift\FacetValue();
|
| 510 |
-
$tmp->stringValue = $f->stringValue;
|
| 511 |
-
|
| 512 |
-
$facet = new \com\boxalino\p13n\api\thrift\FacetRequest();
|
| 513 |
-
$facet->fieldName = 'categories';
|
| 514 |
-
$facet->numerical = false;
|
| 515 |
-
$facet->range = false;
|
| 516 |
-
$facet->selectedValues = array($tmp);
|
| 517 |
-
|
| 518 |
-
$p13n->searchQuery->facetRequests[] = $facet;
|
| 519 |
-
$p13n->search();
|
| 520 |
-
$response = $p13n->getChoiceResponse();
|
| 521 |
-
|
| 522 |
-
if (isset($response->variants[0]) && isset($response->variants[0]->searchResult->hits)) {
|
| 523 |
-
$products[$id] = $this->extractItemsFromHits($response->variants[0]->searchResult->hits, $id, $entity_id, $map);
|
| 524 |
-
}
|
| 525 |
-
}
|
| 526 |
-
}
|
| 527 |
-
}
|
| 528 |
-
|
| 529 |
-
return $products;
|
| 530 |
-
}
|
| 531 |
-
|
| 532 |
-
public function search()
|
| 533 |
-
{
|
| 534 |
-
if (!empty($this->filters)) {
|
| 535 |
-
$this->searchQuery->filters = $this->filters;
|
| 536 |
-
}
|
| 537 |
-
if ($this->filterByVisibleProducts()) {
|
| 538 |
-
$this->searchQuery->filters[] = $this->filterByVisibleProducts();
|
| 539 |
-
}
|
| 540 |
-
if ($this->filterByStatusProducts()) {
|
| 541 |
-
$this->searchQuery->filters[] = $this->filterByStatusProducts();
|
| 542 |
-
}
|
| 543 |
-
$this->inquiry->simpleSearchQuery = $this->searchQuery;
|
| 544 |
-
|
| 545 |
-
if (Mage::getStoreConfig('Boxalino_General/search_relaxation/enabled') == 1) {
|
| 546 |
-
$this->inquiry->withRelaxation = 1;
|
| 547 |
-
}
|
| 548 |
-
|
| 549 |
-
$this->choiceRequest->inquiries = array($this->inquiry);
|
| 550 |
-
|
| 551 |
-
Boxalino_CemSearch_Model_Logger::saveFrontActions('choice_Request', $this->choiceRequest);
|
| 552 |
-
Boxalino_CemSearch_Model_Logger::saveFrontActions('choice_Request_serialized', serialize($this->choiceRequest));
|
| 553 |
-
|
| 554 |
-
self::$choiceResponse = $this->p13n->choose($this->choiceRequest);
|
| 555 |
-
|
| 556 |
-
Boxalino_CemSearch_Model_Logger::saveFrontActions('choice_Response', self::$choiceResponse, 1);
|
| 557 |
-
}
|
| 558 |
-
|
| 559 |
-
private function prepareFacets()
|
| 560 |
-
{
|
| 561 |
-
$facets = array();
|
| 562 |
-
$normalFilters = '';
|
| 563 |
-
$topFilters = '';
|
| 564 |
-
$enableLeftFilters = Mage::getStoreConfig('Boxalino_General/filter/left_filters_enable');
|
| 565 |
-
$enableTopFilters = Mage::getStoreConfig('Boxalino_General/filter/top_filters_enable');
|
| 566 |
-
|
| 567 |
-
if ($enableLeftFilters == 1) {
|
| 568 |
-
$normalFilters = explode(',', Mage::getStoreConfig('Boxalino_General/filter/left_filters_normal'));
|
| 569 |
-
}
|
| 570 |
-
if ($enableTopFilters == 1) {
|
| 571 |
-
$topFilters = explode(',', Mage::getStoreConfig('Boxalino_General/filter/top_filters'));
|
| 572 |
-
}
|
| 573 |
-
if (!empty($normalFilters)) {
|
| 574 |
-
foreach ($normalFilters as $filterString) {
|
| 575 |
-
$filter = explode(':', $filterString);
|
| 576 |
-
if ($filter[0] != '') {
|
| 577 |
-
$facet = new \com\boxalino\p13n\api\thrift\FacetRequest();
|
| 578 |
-
$facet->fieldName = $filter[0];
|
| 579 |
-
$facet->numerical = $filter[1] == 'ranged' ? true : $filter[1] == 'numerical' ? true : false;
|
| 580 |
-
$facet->range = $filter[1] == 'ranged' ? true : false;
|
| 581 |
-
$facet->selectedValues = $this->facetSelectedValue($filter[0], $filter[1]);
|
| 582 |
-
$facet->sortOrder = isset($filter[2]) && $filter[2] == 1 ? 1 : 2;
|
| 583 |
-
$facets[] = $facet;
|
| 584 |
-
}
|
| 585 |
-
}
|
| 586 |
-
}
|
| 587 |
-
if ($topFilters) {
|
| 588 |
-
foreach ($topFilters as $filter) {
|
| 589 |
-
if ($filter != '') {
|
| 590 |
-
$facet = new \com\boxalino\p13n\api\thrift\FacetRequest();
|
| 591 |
-
$facet->fieldName = $filter;
|
| 592 |
-
$facet->numerical = false;
|
| 593 |
-
$facet->range = false;
|
| 594 |
-
$facet->selectedValues = $this->facetSelectedValue($filter, 'standard');
|
| 595 |
-
$facets[] = $facet;
|
| 596 |
-
}
|
| 597 |
-
}
|
| 598 |
-
}
|
| 599 |
-
return $facets;
|
| 600 |
-
}
|
| 601 |
-
|
| 602 |
-
private function facetSelectedValue($name, $option)
|
| 603 |
-
{
|
| 604 |
-
if (empty($this->selectedFacets)) {
|
| 605 |
-
foreach ($_REQUEST as $key => $values) {
|
| 606 |
-
if (strpos($key, 'bx_') !== false) {
|
| 607 |
-
$fieldName = substr($key, 3);
|
| 608 |
-
$values = !is_array($values)?array($values):$values;
|
| 609 |
-
foreach ($values as $value) {
|
| 610 |
-
$this->selectedFacets[$fieldName][] = $value;
|
| 611 |
-
}
|
| 612 |
-
}
|
| 613 |
-
}
|
| 614 |
-
}
|
| 615 |
-
$selectedFacets = array();
|
| 616 |
-
if (isset($this->selectedFacets[$name])) {
|
| 617 |
-
foreach ($this->selectedFacets[$name] as $value) {
|
| 618 |
-
$selectedFacet = new \com\boxalino\p13n\api\thrift\FacetValue();
|
| 619 |
-
if ($option == 'ranged') {
|
| 620 |
-
$rangedValue = explode('-', $value);
|
| 621 |
-
if ($rangedValue[0] != '*') {
|
| 622 |
-
$selectedFacet->rangeFromInclusive = $rangedValue[0];
|
| 623 |
-
}
|
| 624 |
-
if ($rangedValue[1] != '*') {
|
| 625 |
-
$selectedFacet->rangeToExclusive = $rangedValue[1];
|
| 626 |
-
}
|
| 627 |
-
} else {
|
| 628 |
-
$selectedFacet->stringValue = $value;
|
| 629 |
-
}
|
| 630 |
-
$selectedFacets[] = $selectedFacet;
|
| 631 |
-
|
| 632 |
-
}
|
| 633 |
-
return $selectedFacets;
|
| 634 |
-
}
|
| 635 |
-
return;
|
| 636 |
-
}
|
| 637 |
-
|
| 638 |
-
public function getEntitiesIds()
|
| 639 |
-
{
|
| 640 |
-
$result = array();
|
| 641 |
-
$response = $this->getChoiceResponse();
|
| 642 |
-
foreach ($response->variants as $variant) {
|
| 643 |
-
/** @var \com\boxalino\p13n\api\thrift\SearchResult $searchResult */
|
| 644 |
-
$searchResult = $variant->searchResult;
|
| 645 |
-
foreach ($searchResult->hits as $item) {
|
| 646 |
-
$result[] = $item->values[Mage::getStoreConfig('Boxalino_General/search/entity_id')][0];
|
| 647 |
-
}
|
| 648 |
-
}
|
| 649 |
-
|
| 650 |
-
return $result;
|
| 651 |
-
}
|
| 652 |
-
|
| 653 |
-
public function prepareAdditionalDataFromP13n()
|
| 654 |
-
{
|
| 655 |
-
$result = array();
|
| 656 |
-
$response = self::getChoiceResponse();
|
| 657 |
-
$additionalFields = Mage::helper('Boxalino_CemSearch')->getAdditionalFieldsFromP13n();
|
| 658 |
-
if (!empty($response->variants)) {
|
| 659 |
-
foreach ($response->variants as $variant) {
|
| 660 |
-
/** @var \com\boxalino\p13n\api\thrift\SearchResult $searchResult */
|
| 661 |
-
$searchResult = $variant->searchResult;
|
| 662 |
-
foreach ($searchResult->hits as $item) {
|
| 663 |
-
foreach ($additionalFields as $field) {
|
| 664 |
-
if (isset($item->values[$field])) {
|
| 665 |
-
if (!empty($item->values[$field])) {
|
| 666 |
-
$result[$item->values['id'][0]][$field] = $item->values[$field];
|
| 667 |
-
}
|
| 668 |
-
}
|
| 669 |
-
}
|
| 670 |
-
}
|
| 671 |
-
}
|
| 672 |
-
}
|
| 673 |
-
Mage::getModel('core/session')->setData('boxalino_additional_data', $result);
|
| 674 |
-
}
|
| 675 |
-
|
| 676 |
-
public function getFacetsData()
|
| 677 |
-
{
|
| 678 |
-
$preparedFacets = array();
|
| 679 |
-
$response = self::getChoiceResponse();
|
| 680 |
-
foreach ($response->variants as $variant) {
|
| 681 |
-
$facets = $variant->searchResult->facetResponses;
|
| 682 |
-
foreach ($facets as $facet) {
|
| 683 |
-
if (!empty($facet->values)) {
|
| 684 |
-
$filter[$facet->fieldName] = array();
|
| 685 |
-
foreach ($facet->values as $value) {
|
| 686 |
-
$param['stringValue'] = $value->stringValue;
|
| 687 |
-
$param['hitCount'] = $value->hitCount;
|
| 688 |
-
$param['rangeFromInclusive'] = $value->rangeFromInclusive;
|
| 689 |
-
$param['rangeToExclusive'] = $value->rangeToExclusive;
|
| 690 |
-
$param['hierarchyId'] = $value->hierarchyId;
|
| 691 |
-
$param['hierarchy'] = $value->hierarchy;
|
| 692 |
-
$param['selected'] = $value->selected;
|
| 693 |
-
$filter[$facet->fieldName][] = $param;
|
| 694 |
-
}
|
| 695 |
-
$preparedFacets = $filter;
|
| 696 |
-
}
|
| 697 |
-
}
|
| 698 |
-
}
|
| 699 |
-
return $preparedFacets;
|
| 700 |
-
}
|
| 701 |
-
|
| 702 |
-
public function printData()
|
| 703 |
-
{
|
| 704 |
-
$results = array();
|
| 705 |
-
/** @var \com\boxalino\p13n\api\thrift\Variant $variant */
|
| 706 |
-
foreach (self::$choiceResponse->variants as $variant) {
|
| 707 |
-
/** @var \com\boxalino\p13n\api\thrift\SearchResult $searchResult */
|
| 708 |
-
$searchResult = $variant->searchResult;
|
| 709 |
-
foreach ($searchResult->hits as $item) {
|
| 710 |
-
$result = array();
|
| 711 |
-
foreach ($item->values as $key => $value) {
|
| 712 |
-
if (is_array($value) && count($value) == 1) {
|
| 713 |
-
$result[$key] = array_shift($value);
|
| 714 |
-
} else {
|
| 715 |
-
$result[$key] = $value;
|
| 716 |
-
}
|
| 717 |
-
}
|
| 718 |
-
// Widget's meta data, mostly used for event tracking
|
| 719 |
-
$result['_widgetTitle'] = $variant->searchResultTitle;
|
| 720 |
-
$results[] = $result;
|
| 721 |
-
}
|
| 722 |
-
}
|
| 723 |
-
|
| 724 |
-
echo '<table border="1">';
|
| 725 |
-
echo '<tr>';
|
| 726 |
-
|
| 727 |
-
foreach ($this->returnFields as $field) {
|
| 728 |
-
echo '<td>' . $field . '</td>';
|
| 729 |
-
}
|
| 730 |
-
echo '</tr>';
|
| 731 |
-
|
| 732 |
-
foreach ($results as $result) {
|
| 733 |
-
echo '<tr>';
|
| 734 |
-
foreach ($this->returnFields as $field) {
|
| 735 |
-
echo '<td>' . $result[$field] . '</td>';
|
| 736 |
-
}
|
| 737 |
-
echo '</tr>';
|
| 738 |
-
}
|
| 739 |
-
echo '</table>';
|
| 740 |
-
|
| 741 |
-
}
|
| 742 |
-
|
| 743 |
-
/**
|
| 744 |
-
* @param string $accountname
|
| 745 |
-
* @param string $cookieDomain
|
| 746 |
-
* @return \com\boxalino\p13n\api\thrift\AutocompleteRequest
|
| 747 |
-
*/
|
| 748 |
-
private function getAutocompleteRequest($accountname, $cookieDomain = null)
|
| 749 |
-
{
|
| 750 |
-
$request = new \com\boxalino\p13n\api\thrift\AutocompleteRequest();
|
| 751 |
-
|
| 752 |
-
// Setup information about account
|
| 753 |
-
$userRecord = new \com\boxalino\p13n\api\thrift\UserRecord();
|
| 754 |
-
$userRecord->username = $accountname;
|
| 755 |
-
$request->userRecord = $userRecord;
|
| 756 |
-
|
| 757 |
-
if (empty($_COOKIE['cems'])) {
|
| 758 |
-
$sessionid = session_id();
|
| 759 |
-
if (empty($sessionid)) {
|
| 760 |
-
session_start();
|
| 761 |
-
$sessionid = session_id();
|
| 762 |
-
}
|
| 763 |
-
} else {
|
| 764 |
-
$sessionid = $_COOKIE['cems'];
|
| 765 |
-
}
|
| 766 |
-
|
| 767 |
-
if (empty($_COOKIE['cemv'])) {
|
| 768 |
-
$profileid = '';
|
| 769 |
-
if (function_exists('openssl_random_pseudo_bytes')) {
|
| 770 |
-
$profileid = bin2hex(openssl_random_pseudo_bytes(16));
|
| 771 |
-
}
|
| 772 |
-
if (empty($profileid)) {
|
| 773 |
-
$profileid = uniqid('', true);
|
| 774 |
-
}
|
| 775 |
-
} else {
|
| 776 |
-
$profileid = $_COOKIE['cemv'];
|
| 777 |
-
}
|
| 778 |
-
$request->profileId = $profileid;
|
| 779 |
-
|
| 780 |
-
// Refresh cookies
|
| 781 |
-
if (empty($cookieDomain)) {
|
| 782 |
-
setcookie('cems', $sessionid, 0);
|
| 783 |
-
setcookie('cemv', $profileid, time() + self::VISITOR_COOKIE_TIME);
|
| 784 |
-
} else {
|
| 785 |
-
setcookie('cems', $sessionid, 0, '/', $cookieDomain);
|
| 786 |
-
setcookie('cemv', $profileid, time() + 1800, '/', self::VISITOR_COOKIE_TIME);
|
| 787 |
-
}
|
| 788 |
-
|
| 789 |
-
return $request;
|
| 790 |
-
}
|
| 791 |
-
|
| 792 |
-
|
| 793 |
-
/*
|
| 794 |
-
* Recommendations
|
| 795 |
-
*/
|
| 796 |
-
protected $p13nServerHost = 'cdn.bx-cloud.com';
|
| 797 |
-
protected $p13nServerPort = 443;
|
| 798 |
-
protected $productIdFieldName;
|
| 799 |
-
protected $account;
|
| 800 |
-
protected $password;
|
| 801 |
-
protected $language;
|
| 802 |
-
protected $isDevelopment = false;
|
| 803 |
-
|
| 804 |
-
/**
|
| 805 |
-
* @param string $name
|
| 806 |
-
* @param array $returnFields
|
| 807 |
-
* @param int|null $minimumRecommendations
|
| 808 |
-
* @param int|null $maximumRecommendations
|
| 809 |
-
* @param string|null $scenario
|
| 810 |
-
* @return array
|
| 811 |
-
*/
|
| 812 |
-
public function getPersonalRecommendations(array $widgets, array $returnFields, $widgetType)
|
| 813 |
-
{
|
| 814 |
-
$variantNames = array();
|
| 815 |
-
$choiceRequest = $this->createRecommendationChoiceRequest();
|
| 816 |
-
foreach ($widgets as $widget) {
|
| 817 |
-
$name = $widget['name'];
|
| 818 |
-
$variantNames[] = $name;
|
| 819 |
-
$minimumRecommendations = (float)$widget['min_recs'];
|
| 820 |
-
$maximumRecommendations = (float)$widget['max_recs'];
|
| 821 |
-
if ($maximumRecommendations === null) {
|
| 822 |
-
$maximumRecommendations = 5;
|
| 823 |
-
}
|
| 824 |
-
|
| 825 |
-
$inquiry = $this->createRecommendationChoiceInquiry($name);
|
| 826 |
-
|
| 827 |
-
$searchQuery = $this->createRecommendationSearchQuery($returnFields);
|
| 828 |
-
$searchQuery->offset = 0;
|
| 829 |
-
$searchQuery->hitCount = $maximumRecommendations;
|
| 830 |
-
|
| 831 |
-
$inquiry->simpleSearchQuery = $searchQuery;
|
| 832 |
-
$inquiry->minHitCount = $minimumRecommendations;
|
| 833 |
-
if ($widgetType === 'basket' && $_REQUEST['basketContent']) {
|
| 834 |
-
$basketContent = json_decode($_REQUEST['basketContent'], true);
|
| 835 |
-
if ($basketContent !== false && count($basketContent)) {
|
| 836 |
-
$contextItems = array();
|
| 837 |
-
|
| 838 |
-
// Sort basket content by price
|
| 839 |
-
usort($basketContent, function ($a, $b) {
|
| 840 |
-
if ($a['price'] > $b['price']) {
|
| 841 |
-
return -1;
|
| 842 |
-
} elseif ($b['price'] > $a['price']) {
|
| 843 |
-
return 1;
|
| 844 |
-
}
|
| 845 |
-
return 0;
|
| 846 |
-
});
|
| 847 |
-
|
| 848 |
-
$basketItem = array_shift($basketContent);
|
| 849 |
-
|
| 850 |
-
$contextItem = new \com\boxalino\p13n\api\thrift\ContextItem();
|
| 851 |
-
$contextItem->indexId = $this->account;
|
| 852 |
-
$contextItem->fieldName = $this->productIdFieldName;
|
| 853 |
-
$contextItem->contextItemId = $basketItem['id'];
|
| 854 |
-
$contextItem->role = 'mainProduct';
|
| 855 |
-
|
| 856 |
-
$contextItems[] = $contextItem;
|
| 857 |
-
|
| 858 |
-
foreach ($basketContent as $basketItem) {
|
| 859 |
-
$contextItem = new \com\boxalino\p13n\api\thrift\ContextItem();
|
| 860 |
-
$contextItem->indexId = $this->account;
|
| 861 |
-
$contextItem->fieldName = $this->productIdFieldName;
|
| 862 |
-
$contextItem->contextItemId = $basketItem['id'];
|
| 863 |
-
$contextItem->role = 'subProduct';
|
| 864 |
-
|
| 865 |
-
$contextItems[] = $contextItem;
|
| 866 |
-
}
|
| 867 |
-
$inquiry->contextItems = $contextItems;
|
| 868 |
-
}
|
| 869 |
-
} elseif ($widgetType === 'product' && !empty($_REQUEST['productId'])) {
|
| 870 |
-
$productId = $_REQUEST['productId'];
|
| 871 |
-
$contextItem = new \com\boxalino\p13n\api\thrift\ContextItem();
|
| 872 |
-
$contextItem->indexId = $this->account;
|
| 873 |
-
$contextItem->fieldName = $this->productIdFieldName;
|
| 874 |
-
$contextItem->contextItemId = $productId;
|
| 875 |
-
$contextItem->role = 'mainProduct';
|
| 876 |
-
$inquiry->contextItems = array($contextItem);
|
| 877 |
-
}
|
| 878 |
-
if ($this->filterByVisibleProducts()) {
|
| 879 |
-
$inquiry->simpleSearchQuery->filters[] = $this->filterByVisibleProducts();
|
| 880 |
-
}
|
| 881 |
-
if ($this->filterByStatusProducts()) {
|
| 882 |
-
$inquiry->simpleSearchQuery->filters[] = $this->filterByStatusProducts();
|
| 883 |
-
}
|
| 884 |
-
$choiceRequest->inquiries[] = $inquiry;
|
| 885 |
-
}
|
| 886 |
-
$choiceRequest = $this->p13n->addRequestContext($choiceRequest);
|
| 887 |
-
|
| 888 |
-
if (isset($_REQUEST['productId'])) {
|
| 889 |
-
Boxalino_CemSearch_Model_Logger::saveFrontActions('recommendation_product_id', $_REQUEST['productId']);
|
| 890 |
-
} elseif (isset($_REQUEST['basketContent'])) {
|
| 891 |
-
Boxalino_CemSearch_Model_Logger::saveFrontActions('recommendation_basket_content', $_REQUEST['basketContent']);
|
| 892 |
-
}
|
| 893 |
-
Boxalino_CemSearch_Model_Logger::saveFrontActions('recommendation_Request', $choiceRequest);
|
| 894 |
-
Boxalino_CemSearch_Model_Logger::saveFrontActions('recommendation_Request_serialized', serialize($choiceRequest));
|
| 895 |
-
|
| 896 |
-
$choiceResponse = $this->p13n->choose($choiceRequest);
|
| 897 |
-
|
| 898 |
-
Boxalino_CemSearch_Model_Logger::saveFrontActions('recommendation_Response', $choiceResponse, 1);
|
| 899 |
-
$results = array();
|
| 900 |
-
/** @var \com\boxalino\p13n\api\thrift\Variant $variant */
|
| 901 |
-
foreach ($choiceResponse->variants as $variantId => $variant) {
|
| 902 |
-
$name = $variantNames[$variantId];
|
| 903 |
-
foreach ($variant->searchResult->hits as $item) {
|
| 904 |
-
$result = array();
|
| 905 |
-
foreach ($item->values as $key => $value) {
|
| 906 |
-
if (is_array($value) && count($value) == 1) {
|
| 907 |
-
$result[$key] = array_shift($value);
|
| 908 |
-
} else {
|
| 909 |
-
$result[$key] = $value;
|
| 910 |
-
}
|
| 911 |
-
}
|
| 912 |
-
if (!isset($result['name']) && isset($result['title'])) {
|
| 913 |
-
$result['name'] = $result['title'];
|
| 914 |
-
}
|
| 915 |
-
|
| 916 |
-
$result['_rule'] = $name . ':' . $variant->scenarioId . ':' . $variant->variantId;
|
| 917 |
-
$result['_choice'] = $name;
|
| 918 |
-
$result['_scenario'] = $variant->scenarioId;
|
| 919 |
-
$result['_variant'] = $variant->variantId;
|
| 920 |
-
$results[$name][] = $result;
|
| 921 |
-
}
|
| 922 |
-
}
|
| 923 |
-
return $results;
|
| 924 |
-
}
|
| 925 |
-
|
| 926 |
-
/**
|
| 927 |
-
* @param string $account
|
| 928 |
-
* @param array $authData
|
| 929 |
-
* @param string $language
|
| 930 |
-
* @param bool $isDevelopment
|
| 931 |
-
* @param int $entityIdFieldName
|
| 932 |
-
*/
|
| 933 |
-
public function createRecommendation($account, $authData, $language, $entityIdFieldName, $isDevelopment = false)
|
| 934 |
-
{
|
| 935 |
-
|
| 936 |
-
$this->productIdFieldName = $entityIdFieldName;
|
| 937 |
-
|
| 938 |
-
$this->account = $account;
|
| 939 |
-
$this->language = $language;
|
| 940 |
-
$this->isDevelopment = $isDevelopment;
|
| 941 |
-
// Created here first to load necessary files
|
| 942 |
-
$this->p13n = $this->createP13n($authData);
|
| 943 |
-
}
|
| 944 |
-
|
| 945 |
-
/**
|
| 946 |
-
* @return P13n
|
| 947 |
-
*/
|
| 948 |
-
private function createP13n($authData)
|
| 949 |
-
{
|
| 950 |
-
$p13n = new HttpP13n();
|
| 951 |
-
$p13n->setHost($this->p13nServerHost);
|
| 952 |
-
$p13n->setAuthorization($authData['username'], $authData['password']);
|
| 953 |
-
return $p13n;
|
| 954 |
-
}
|
| 955 |
-
|
| 956 |
-
/**
|
| 957 |
-
* @return \com\boxalino\p13n\api\thrift\ChoiceRequest
|
| 958 |
-
*/
|
| 959 |
-
protected function createRecommendationChoiceRequest()
|
| 960 |
-
{
|
| 961 |
-
$choiceRequest = new \com\boxalino\p13n\api\thrift\ChoiceRequest();
|
| 962 |
-
$choiceRequest->profileId = $this->getVisitorId();
|
| 963 |
-
|
| 964 |
-
$userRecord = new \com\boxalino\p13n\api\thrift\UserRecord();
|
| 965 |
-
$userRecord->username = $this->account;
|
| 966 |
-
|
| 967 |
-
$choiceRequest->userRecord = $userRecord;
|
| 968 |
-
|
| 969 |
-
return $choiceRequest;
|
| 970 |
-
}
|
| 971 |
-
|
| 972 |
-
/**
|
| 973 |
-
* @return string
|
| 974 |
-
*/
|
| 975 |
-
protected function getVisitorId()
|
| 976 |
-
{
|
| 977 |
-
$profileid = null;
|
| 978 |
-
if (empty($_COOKIE['cemv'])) {
|
| 979 |
-
$profileid = '';
|
| 980 |
-
if (function_exists('openssl_random_pseudo_bytes')) {
|
| 981 |
-
$profileid = bin2hex(openssl_random_pseudo_bytes(16));
|
| 982 |
-
}
|
| 983 |
-
if (empty($profileid)) {
|
| 984 |
-
$profileid = uniqid('', true);
|
| 985 |
-
}
|
| 986 |
-
} else {
|
| 987 |
-
$profileid = $_COOKIE['cemv'];
|
| 988 |
-
}
|
| 989 |
-
|
| 990 |
-
return $profileid;
|
| 991 |
-
}
|
| 992 |
-
|
| 993 |
-
/**
|
| 994 |
-
* @param string $name Choice name
|
| 995 |
-
* @param string|null $scope Choice scope (null for default)
|
| 996 |
-
* @return \com\boxalino\p13n\api\thrift\ChoiceInquiry
|
| 997 |
-
*/
|
| 998 |
-
protected function createRecommendationChoiceInquiry($name, $scope = null)
|
| 999 |
-
{
|
| 1000 |
-
$inquiry = new \com\boxalino\p13n\api\thrift\ChoiceInquiry();
|
| 1001 |
-
$inquiry->choiceId = $name;
|
| 1002 |
-
if ($scope !== null) {
|
| 1003 |
-
$inquiry->scope = $scope;
|
| 1004 |
-
}
|
| 1005 |
-
return $inquiry;
|
| 1006 |
-
}
|
| 1007 |
-
|
| 1008 |
-
/**
|
| 1009 |
-
* @param array $returnFields
|
| 1010 |
-
* @param string|null $query
|
| 1011 |
-
* @return \com\boxalino\p13n\api\thrift\SimpleSearchQuery
|
| 1012 |
-
*/
|
| 1013 |
-
protected function createRecommendationSearchQuery(array $returnFields, $query = null)
|
| 1014 |
-
{
|
| 1015 |
-
$searchQuery = new \com\boxalino\p13n\api\thrift\SimpleSearchQuery();
|
| 1016 |
-
$searchQuery->indexId = $this->account;
|
| 1017 |
-
if ($query !== null) {
|
| 1018 |
-
$searchQuery->queryText = $query;
|
| 1019 |
-
}
|
| 1020 |
-
$searchQuery->language = $this->language;
|
| 1021 |
-
$searchQuery->returnFields = $returnFields;
|
| 1022 |
-
|
| 1023 |
-
return $searchQuery;
|
| 1024 |
-
}
|
| 1025 |
-
|
| 1026 |
-
/**
|
| 1027 |
-
* @return string
|
| 1028 |
-
*/
|
| 1029 |
-
protected function getBigDataHost()
|
| 1030 |
-
{
|
| 1031 |
-
$hostname = gethostname();
|
| 1032 |
-
if (preg_match('#^c[0-9]+n([0-9]+)$#', $hostname, $match)) {
|
| 1033 |
-
return 'bd' . $match[1] . '.bx-cloud.com';
|
| 1034 |
-
}
|
| 1035 |
-
return $this->p13nServerHost;
|
| 1036 |
-
}
|
| 1037 |
-
|
| 1038 |
-
public function getSearchQuery()
|
| 1039 |
-
{
|
| 1040 |
-
return $this->searchQuery;
|
| 1041 |
-
}
|
| 1042 |
-
|
| 1043 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/code/community/Boxalino/CemSearch/Helper/P13n/Config.php
DELETED
|
@@ -1,59 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
|
| 3 |
-
/**
|
| 4 |
-
* User: Michal Sordyl
|
| 5 |
-
* Mail: michal.sordyl@codete.co
|
| 6 |
-
* Date: 28.05.14
|
| 7 |
-
*/
|
| 8 |
-
class Boxalino_CemSearch_Helper_P13n_Config
|
| 9 |
-
{
|
| 10 |
-
private $host;
|
| 11 |
-
private $account;
|
| 12 |
-
private $username;
|
| 13 |
-
private $password;
|
| 14 |
-
private $domain;
|
| 15 |
-
private $indexId;
|
| 16 |
-
|
| 17 |
-
/**
|
| 18 |
-
* @param $host your boxalino server host, eg cdn.bx-cloud.com
|
| 19 |
-
* @param $account name of account
|
| 20 |
-
* @param $username username for API. One user may have many accounts (above).
|
| 21 |
-
* @param $password password for username
|
| 22 |
-
* @param $domain shop domain
|
| 23 |
-
* @param $indexId propably same as account name
|
| 24 |
-
*/
|
| 25 |
-
public function __construct($host, $account, $username, $password, $domain)
|
| 26 |
-
{
|
| 27 |
-
$this->host = $host;
|
| 28 |
-
$this->account = $account;
|
| 29 |
-
$this->username = $username;
|
| 30 |
-
$this->password = $password;
|
| 31 |
-
$this->domain = $domain;
|
| 32 |
-
}
|
| 33 |
-
|
| 34 |
-
public function getAccount()
|
| 35 |
-
{
|
| 36 |
-
return $this->account;
|
| 37 |
-
}
|
| 38 |
-
|
| 39 |
-
public function getDomain()
|
| 40 |
-
{
|
| 41 |
-
return $this->domain;
|
| 42 |
-
}
|
| 43 |
-
|
| 44 |
-
public function getHost()
|
| 45 |
-
{
|
| 46 |
-
return $this->host;
|
| 47 |
-
}
|
| 48 |
-
|
| 49 |
-
public function getPassword()
|
| 50 |
-
{
|
| 51 |
-
return $this->password;
|
| 52 |
-
}
|
| 53 |
-
|
| 54 |
-
public function getUsername()
|
| 55 |
-
{
|
| 56 |
-
return $this->username;
|
| 57 |
-
}
|
| 58 |
-
|
| 59 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/code/community/Boxalino/CemSearch/Helper/P13n/Recommendation.php
DELETED
|
@@ -1,89 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
|
| 3 |
-
/**
|
| 4 |
-
* Created by: Szymon Nosal <szymon.nosal@codete.com>
|
| 5 |
-
* Created at: 12.06.14 16:36
|
| 6 |
-
*/
|
| 7 |
-
class Boxalino_CemSearch_Helper_P13n_Recommendation
|
| 8 |
-
{
|
| 9 |
-
private $returnFields = array('id');
|
| 10 |
-
private $results = array();
|
| 11 |
-
|
| 12 |
-
public static function Instance()
|
| 13 |
-
{
|
| 14 |
-
static $inst = null;
|
| 15 |
-
if ($inst === null) {
|
| 16 |
-
$inst = new Boxalino_CemSearch_Helper_P13n_Recommendation();
|
| 17 |
-
}
|
| 18 |
-
return $inst;
|
| 19 |
-
}
|
| 20 |
-
|
| 21 |
-
public function getRecommendation($widgetType, $widgetName, $amount = 3)
|
| 22 |
-
{
|
| 23 |
-
if (empty($this->results)) {
|
| 24 |
-
if ($widgetType == '') {
|
| 25 |
-
$widgets = array(array(
|
| 26 |
-
'name' => $widgetName, 'min_recs' => 0, 'max_recs' => $amount
|
| 27 |
-
));
|
| 28 |
-
$widgetType = 'product';
|
| 29 |
-
} else {
|
| 30 |
-
$widgets = $this->prepareWidgets($widgetType);
|
| 31 |
-
}
|
| 32 |
-
if (empty($widgets)) {
|
| 33 |
-
return null;
|
| 34 |
-
}
|
| 35 |
-
$account = Mage::helper('Boxalino_CemSearch')->getAccount();
|
| 36 |
-
$language = substr(Mage::app()->getLocale()->getLocaleCode(), 0, 2);
|
| 37 |
-
$returnFields = $this->returnFields;
|
| 38 |
-
|
| 39 |
-
$entity_id = Mage::getStoreConfig('Boxalino_General/search/entity_id');
|
| 40 |
-
$authData['username'] = Mage::getStoreConfig('Boxalino_General/general/p13n_username');
|
| 41 |
-
$authData['password'] = Mage::getStoreConfig('Boxalino_General/general/p13n_password');
|
| 42 |
-
$entityIdFieldName = 'entity_id';
|
| 43 |
-
if (isset($entity_id) && $entity_id !== '') {
|
| 44 |
-
$entityIdFieldName = $entity_id;
|
| 45 |
-
}
|
| 46 |
-
|
| 47 |
-
$storeConfig = Mage::getStoreConfig('Boxalino_General/general');
|
| 48 |
-
|
| 49 |
-
$p13nConfig = new Boxalino_CemSearch_Helper_P13n_Config(
|
| 50 |
-
$storeConfig['host'],
|
| 51 |
-
Mage::helper('Boxalino_CemSearch')->getAccount(),
|
| 52 |
-
$storeConfig['p13n_username'],
|
| 53 |
-
$storeConfig['p13n_password'],
|
| 54 |
-
$storeConfig['domain']
|
| 55 |
-
);
|
| 56 |
-
|
| 57 |
-
$p13nClient = new Boxalino_CemSearch_Helper_P13n_Adapter($p13nConfig);
|
| 58 |
-
$p13nClient->createRecommendation($account, $authData, $language, $entityIdFieldName, true);
|
| 59 |
-
$this->results = $p13nClient->getPersonalRecommendations($widgets, $returnFields, $widgetType);
|
| 60 |
-
}
|
| 61 |
-
|
| 62 |
-
// Added check in order to avoid PHP notice
|
| 63 |
-
if (!array_key_exists($widgetName, $this->results)) {
|
| 64 |
-
return null;
|
| 65 |
-
}
|
| 66 |
-
|
| 67 |
-
return $this->results[$widgetName];
|
| 68 |
-
}
|
| 69 |
-
|
| 70 |
-
private function prepareWidgets($widgetType)
|
| 71 |
-
{
|
| 72 |
-
$widgets = array();
|
| 73 |
-
$recommendations = Mage::getStoreConfig('Boxalino_Recommendation');
|
| 74 |
-
foreach ($recommendations as $recommendation) {
|
| 75 |
-
if (
|
| 76 |
-
(!empty($recommendation['min']) || $recommendation['min'] >= 0) &&
|
| 77 |
-
(!empty($recommendation['max']) || $recommendation['max'] >= 0) &&
|
| 78 |
-
!empty($recommendation['scenario']) &&
|
| 79 |
-
($recommendation['min'] <= $recommendation['max']) &&
|
| 80 |
-
$recommendation['status'] == true
|
| 81 |
-
) {
|
| 82 |
-
if ($recommendation['scenario'] == $widgetType) {
|
| 83 |
-
$widgets[] = array('name' => $recommendation['widget'], 'min_recs' => $recommendation['min'], 'max_recs' => $recommendation['max']);
|
| 84 |
-
}
|
| 85 |
-
}
|
| 86 |
-
}
|
| 87 |
-
return $widgets;
|
| 88 |
-
}
|
| 89 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/code/community/Boxalino/CemSearch/Helper/P13n/Sort.php
DELETED
|
@@ -1,36 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
|
| 3 |
-
/**
|
| 4 |
-
* User: Michal Sordyl
|
| 5 |
-
* Mail: michal.sordyl@codete.co
|
| 6 |
-
* Date: 02.06.14
|
| 7 |
-
*/
|
| 8 |
-
class Boxalino_CemSearch_Helper_P13n_Sort
|
| 9 |
-
{
|
| 10 |
-
private $sorts = array();
|
| 11 |
-
|
| 12 |
-
/**
|
| 13 |
-
* @param array $sorts array(array('fieldName' => , 'reverse' => ), ..... )
|
| 14 |
-
*/
|
| 15 |
-
public function __construct($sorts = array())
|
| 16 |
-
{
|
| 17 |
-
foreach ($sorts as $sort) {
|
| 18 |
-
$this->push($sort['fieldName'], $sort['order']);
|
| 19 |
-
}
|
| 20 |
-
}
|
| 21 |
-
|
| 22 |
-
/**
|
| 23 |
-
* @param $field name od field to sort by (i.e. discountedPrice / title)
|
| 24 |
-
* @param $reverse true for ASC, false for DESC
|
| 25 |
-
*/
|
| 26 |
-
public function push($field, $reverse)
|
| 27 |
-
{
|
| 28 |
-
$this->sorts[] = array('fieldName' => $field, 'reverse' => $reverse);
|
| 29 |
-
}
|
| 30 |
-
|
| 31 |
-
public function getSorts()
|
| 32 |
-
{
|
| 33 |
-
return $this->sorts;
|
| 34 |
-
}
|
| 35 |
-
|
| 36 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/code/community/Boxalino/CemSearch/Lib/AbstractThrift.php
DELETED
|
@@ -1,28 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
|
| 3 |
-
abstract class AbstractThrift
|
| 4 |
-
{
|
| 5 |
-
protected static $thriftClassLoader = null;
|
| 6 |
-
|
| 7 |
-
protected $dependencies = array();
|
| 8 |
-
|
| 9 |
-
public function __construct()
|
| 10 |
-
{
|
| 11 |
-
if (self::$thriftClassLoader === null) {
|
| 12 |
-
$this->initClassLoader();
|
| 13 |
-
}
|
| 14 |
-
}
|
| 15 |
-
|
| 16 |
-
protected function initClassLoader()
|
| 17 |
-
{
|
| 18 |
-
require_once(__DIR__ . '/vendor/Thrift/ClassLoader/ThriftClassLoader.php');
|
| 19 |
-
self::$thriftClassLoader = new \Thrift\ClassLoader\ThriftClassLoader(false);
|
| 20 |
-
self::$thriftClassLoader->registerNamespace('Thrift', __DIR__ . '/vendor');
|
| 21 |
-
self::$thriftClassLoader->register();
|
| 22 |
-
foreach ($this->dependencies as $dependency) {
|
| 23 |
-
require_once($dependency);
|
| 24 |
-
}
|
| 25 |
-
}
|
| 26 |
-
|
| 27 |
-
abstract protected function getClient($clientId = '');
|
| 28 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/code/community/Boxalino/CemSearch/Lib/vendor/Thrift/HttpP13n.php
DELETED
|
@@ -1,270 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
|
| 3 |
-
/**
|
| 4 |
-
* Class P13n
|
| 5 |
-
* @method \com\boxalino\p13n\api\thrift\ChoiceResponse choose(\com\boxalino\p13n\api\thrift\ChoiceRequest $choiceRequest)
|
| 6 |
-
*/
|
| 7 |
-
class HttpP13n
|
| 8 |
-
{
|
| 9 |
-
protected static $thriftClassLoader = null;
|
| 10 |
-
protected $dependencies = array(
|
| 11 |
-
'../../P13nService.php',
|
| 12 |
-
'../../Types.php',
|
| 13 |
-
);
|
| 14 |
-
protected $client = null;
|
| 15 |
-
protected $transport = null;
|
| 16 |
-
protected $host;
|
| 17 |
-
protected $port = 443;
|
| 18 |
-
protected $uri = '/p13n.web/p13n';
|
| 19 |
-
protected $schema = 'https';
|
| 20 |
-
protected $username;
|
| 21 |
-
protected $password;
|
| 22 |
-
|
| 23 |
-
/**
|
| 24 |
-
*
|
| 25 |
-
*/
|
| 26 |
-
public function __construct()
|
| 27 |
-
{
|
| 28 |
-
if (self::$thriftClassLoader === null) {
|
| 29 |
-
$this->initClassLoader();
|
| 30 |
-
}
|
| 31 |
-
}
|
| 32 |
-
|
| 33 |
-
public function __call($name, $arguments)
|
| 34 |
-
{
|
| 35 |
-
if (method_exists($this->getClient(), $name)) {
|
| 36 |
-
if (isset($arguments[0])) {
|
| 37 |
-
$arguments[0] = $this->addRequestContext($arguments[0]);
|
| 38 |
-
}
|
| 39 |
-
|
| 40 |
-
return call_user_func_array(array($this->getClient(), $name), $arguments);
|
| 41 |
-
} else {
|
| 42 |
-
throw new Exception("Method $name not supported in P13nService");
|
| 43 |
-
}
|
| 44 |
-
}
|
| 45 |
-
|
| 46 |
-
/**
|
| 47 |
-
* @param string $accountname
|
| 48 |
-
* @param string $cookieDomain
|
| 49 |
-
* @return string
|
| 50 |
-
*/
|
| 51 |
-
public function getChoiceRequest($accountname, $cookieDomain = null)
|
| 52 |
-
{
|
| 53 |
-
$choiceRequest = new \com\boxalino\p13n\api\thrift\ChoiceRequest();
|
| 54 |
-
|
| 55 |
-
// Setup information about account
|
| 56 |
-
$userRecord = new \com\boxalino\p13n\api\thrift\UserRecord();
|
| 57 |
-
$userRecord->username = $accountname;
|
| 58 |
-
$choiceRequest->userRecord = $userRecord;
|
| 59 |
-
|
| 60 |
-
// Setup request context
|
| 61 |
-
$sessionid = $this->getSessionId();
|
| 62 |
-
$profileid = $this->getVisitorId();
|
| 63 |
-
|
| 64 |
-
$choiceRequest->profileId = $profileid;
|
| 65 |
-
|
| 66 |
-
// Refresh cookies
|
| 67 |
-
if(empty($cookieDomain)) {
|
| 68 |
-
setcookie('cems', $sessionid, 0);
|
| 69 |
-
setcookie('cemv', $profileid, time() + 1800);
|
| 70 |
-
} else {
|
| 71 |
-
setcookie('cems', $sessionid, 0, '/', $cookieDomain);
|
| 72 |
-
setcookie('cemv', $profileid, time() + 1800, '/', $cookieDomain);
|
| 73 |
-
}
|
| 74 |
-
|
| 75 |
-
return $choiceRequest;
|
| 76 |
-
}
|
| 77 |
-
|
| 78 |
-
/**
|
| 79 |
-
* @return \com\boxalino\p13n\api\thrift\P13nServiceClient
|
| 80 |
-
*/
|
| 81 |
-
protected function getClient()
|
| 82 |
-
{
|
| 83 |
-
if ($this->client === null || $this->transport === null) {
|
| 84 |
-
if(function_exists('curl_version')) {
|
| 85 |
-
$this->transport = new \Thrift\Transport\P13nTCurlClient($this->host, $this->port, $this->uri, $this->schema);
|
| 86 |
-
} else {
|
| 87 |
-
$this->transport = new \Thrift\Transport\P13nTHttpClient($this->host, $this->port, $this->uri, $this->schema);
|
| 88 |
-
}
|
| 89 |
-
$this->transport->setAuthorization($this->username, $this->password);
|
| 90 |
-
$this->client = new \com\boxalino\p13n\api\thrift\P13nServiceClient(new \Thrift\Protocol\TCompactProtocol($this->transport));
|
| 91 |
-
}
|
| 92 |
-
return $this->client;
|
| 93 |
-
}
|
| 94 |
-
|
| 95 |
-
/**
|
| 96 |
-
* @param string $username
|
| 97 |
-
* @param string $password
|
| 98 |
-
*/
|
| 99 |
-
public function setAuthorization($username, $password)
|
| 100 |
-
{
|
| 101 |
-
$this->username = $username;
|
| 102 |
-
$this->password = $password;
|
| 103 |
-
$this->transport = null;
|
| 104 |
-
}
|
| 105 |
-
|
| 106 |
-
/**
|
| 107 |
-
* @param string $host
|
| 108 |
-
*/
|
| 109 |
-
public function setHost($host)
|
| 110 |
-
{
|
| 111 |
-
$this->host = $host;
|
| 112 |
-
$this->transport = null;
|
| 113 |
-
}
|
| 114 |
-
|
| 115 |
-
/**
|
| 116 |
-
* @param int $port
|
| 117 |
-
*/
|
| 118 |
-
public function setPort($port)
|
| 119 |
-
{
|
| 120 |
-
$this->port = $port;
|
| 121 |
-
$this->transport = null;
|
| 122 |
-
}
|
| 123 |
-
|
| 124 |
-
/**
|
| 125 |
-
* @param string $schema
|
| 126 |
-
*/
|
| 127 |
-
public function setSchema($schema)
|
| 128 |
-
{
|
| 129 |
-
$this->schema = $schema;
|
| 130 |
-
$this->transport = null;
|
| 131 |
-
}
|
| 132 |
-
|
| 133 |
-
/**
|
| 134 |
-
*
|
| 135 |
-
*/
|
| 136 |
-
protected function initClassLoader()
|
| 137 |
-
{
|
| 138 |
-
require_once __DIR__ . DIRECTORY_SEPARATOR . 'ClassLoader' . DIRECTORY_SEPARATOR . 'ThriftClassLoader.php';
|
| 139 |
-
self::$thriftClassLoader = new \Thrift\ClassLoader\ThriftClassLoader(false);
|
| 140 |
-
self::$thriftClassLoader->registerNamespace('Thrift', __DIR__ . DIRECTORY_SEPARATOR . '..');
|
| 141 |
-
self::$thriftClassLoader->register();
|
| 142 |
-
foreach ($this->dependencies as $dependency) {
|
| 143 |
-
require_once __DIR__ . DIRECTORY_SEPARATOR . $dependency;
|
| 144 |
-
}
|
| 145 |
-
}
|
| 146 |
-
|
| 147 |
-
/**
|
| 148 |
-
* @return \com\boxalino\p13n\api\thrift\RequestContext
|
| 149 |
-
*/
|
| 150 |
-
protected function getRequestContext()
|
| 151 |
-
{
|
| 152 |
-
$requestContext = new \com\boxalino\p13n\api\thrift\RequestContext();
|
| 153 |
-
$requestContext->parameters = array(
|
| 154 |
-
'User-Agent' => array(@$_SERVER['HTTP_USER_AGENT']),
|
| 155 |
-
'User-Host' => array($this->getIP()),
|
| 156 |
-
'User-SessionId' => array($this->getSessionId()),
|
| 157 |
-
'User-Referer' => array(@$_SERVER['HTTP_REFERER']),
|
| 158 |
-
'User-URL' => array($this->getCurrentURL())
|
| 159 |
-
);
|
| 160 |
-
|
| 161 |
-
if (isset($_REQUEST['p13nRequestContext']) && is_array($_REQUEST['p13nRequestContext'])) {
|
| 162 |
-
$requestContext->parameters = array_merge(
|
| 163 |
-
$_REQUEST['p13nRequestContext'],
|
| 164 |
-
$requestContext->parameters
|
| 165 |
-
);
|
| 166 |
-
}
|
| 167 |
-
|
| 168 |
-
return $requestContext;
|
| 169 |
-
}
|
| 170 |
-
|
| 171 |
-
/**
|
| 172 |
-
* @return string
|
| 173 |
-
*/
|
| 174 |
-
protected function getIP()
|
| 175 |
-
{
|
| 176 |
-
$ip = null;
|
| 177 |
-
$clientip = @$_SERVER['HTTP_CLIENT_IP'];
|
| 178 |
-
$forwardedip = @$_SERVER['HTTP_X_FORWARDED_FOR'];
|
| 179 |
-
if (filter_var($clientip, FILTER_VALIDATE_IP)) {
|
| 180 |
-
$ip = $clientip;
|
| 181 |
-
} elseif (filter_var($forwardedip, FILTER_VALIDATE_IP)) {
|
| 182 |
-
$ip = $forwardedip;
|
| 183 |
-
} else {
|
| 184 |
-
$ip = @$_SERVER['REMOTE_ADDR'];
|
| 185 |
-
}
|
| 186 |
-
|
| 187 |
-
return $ip;
|
| 188 |
-
}
|
| 189 |
-
|
| 190 |
-
/**
|
| 191 |
-
* @return string
|
| 192 |
-
*/
|
| 193 |
-
protected function getSessionId()
|
| 194 |
-
{
|
| 195 |
-
$sessionid = null;
|
| 196 |
-
if (empty($_COOKIE['cems'])) {
|
| 197 |
-
$sessionid = session_id();
|
| 198 |
-
if (empty($sessionid)) {
|
| 199 |
-
session_start();
|
| 200 |
-
$sessionid = session_id();
|
| 201 |
-
}
|
| 202 |
-
} else {
|
| 203 |
-
$sessionid = $_COOKIE['cems'];
|
| 204 |
-
}
|
| 205 |
-
|
| 206 |
-
return $sessionid;
|
| 207 |
-
}
|
| 208 |
-
|
| 209 |
-
/**
|
| 210 |
-
* @return string
|
| 211 |
-
*/
|
| 212 |
-
protected function getVisitorId()
|
| 213 |
-
{
|
| 214 |
-
$profileid = null;
|
| 215 |
-
if (empty($_COOKIE['cemv'])) {
|
| 216 |
-
$profileid = '';
|
| 217 |
-
if (function_exists('openssl_random_pseudo_bytes')) {
|
| 218 |
-
$profileid = bin2hex(openssl_random_pseudo_bytes(16));
|
| 219 |
-
}
|
| 220 |
-
if (empty($profileid)) {
|
| 221 |
-
$profileid = uniqid('', true);
|
| 222 |
-
}
|
| 223 |
-
} else {
|
| 224 |
-
$profileid = $_COOKIE['cemv'];
|
| 225 |
-
}
|
| 226 |
-
|
| 227 |
-
return $profileid;
|
| 228 |
-
}
|
| 229 |
-
|
| 230 |
-
/**
|
| 231 |
-
* @return string
|
| 232 |
-
*/
|
| 233 |
-
protected function getCurrentURL()
|
| 234 |
-
{
|
| 235 |
-
$protocol = strpos(strtolower(@$_SERVER['SERVER_PROTOCOL']), 'https') === false ? 'http' : 'https';
|
| 236 |
-
$hostname = @$_SERVER['HTTP_HOST'];
|
| 237 |
-
$requesturi = @$_SERVER['REQUEST_URI'];
|
| 238 |
-
|
| 239 |
-
return $protocol . '://' . $hostname . $requesturi;
|
| 240 |
-
}
|
| 241 |
-
|
| 242 |
-
/**
|
| 243 |
-
* @param \com\boxalino\p13n\api\thrift\AutocompleteRequest|\com\boxalino\p13n\api\thrift\ChoiceRequest|\com\boxalino\p13n\api\thrift\BatchChoiceRequest $request
|
| 244 |
-
* @return \com\boxalino\p13n\api\thrift\AutocompleteRequest|\com\boxalino\p13n\api\thrift\ChoiceRequest|\com\boxalino\p13n\api\thrift\BatchChoiceRequest
|
| 245 |
-
*/
|
| 246 |
-
public function addRequestContext($request)
|
| 247 |
-
{
|
| 248 |
-
if (
|
| 249 |
-
$request instanceof \com\boxalino\p13n\api\thrift\AutocompleteRequest ||
|
| 250 |
-
$request instanceof \com\boxalino\p13n\api\thrift\ChoiceRequest ||
|
| 251 |
-
$request instanceof \com\boxalino\p13n\api\thrift\BatchChoiceRequest
|
| 252 |
-
) {
|
| 253 |
-
if ($request->requestContext === null) {
|
| 254 |
-
$request->requestContext = $this->getRequestContext();
|
| 255 |
-
} else {
|
| 256 |
-
$requestContext = $this->getRequestContext();
|
| 257 |
-
foreach ($requestContext->parameters as $parameterName => $parameterValues) {
|
| 258 |
-
if (isset($request->requestContext->parameters[$parameterName])) {
|
| 259 |
-
continue;
|
| 260 |
-
}
|
| 261 |
-
|
| 262 |
-
$request->requestContext->parameters[$parameterName] = $parameterValues;
|
| 263 |
-
}
|
| 264 |
-
}
|
| 265 |
-
}
|
| 266 |
-
|
| 267 |
-
return $request;
|
| 268 |
-
}
|
| 269 |
-
|
| 270 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/code/community/Boxalino/CemSearch/Model/Advanced.php
DELETED
|
@@ -1,284 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
/**
|
| 3 |
-
* Created by: Szymon Nosal <szymon.nosal@codete.com>
|
| 4 |
-
* Created at: 06.06.14 11:45
|
| 5 |
-
*/
|
| 6 |
-
|
| 7 |
-
require_once 'Mage/CatalogSearch/Model/Advanced.php';
|
| 8 |
-
|
| 9 |
-
/**
|
| 10 |
-
*
|
| 11 |
-
* @category Mage
|
| 12 |
-
* @package Mage_CatalogSearch
|
| 13 |
-
* @author Szymon Nosal <szymon.nosal@codete.com>
|
| 14 |
-
*/
|
| 15 |
-
class Boxalino_CemSearch_Model_Advanced extends Mage_CatalogSearch_Model_Advanced
|
| 16 |
-
{
|
| 17 |
-
/**
|
| 18 |
-
* User friendly search criteria list
|
| 19 |
-
*
|
| 20 |
-
* @var array
|
| 21 |
-
*/
|
| 22 |
-
protected $_searchCriterias = array();
|
| 23 |
-
|
| 24 |
-
/**
|
| 25 |
-
* Current search engine
|
| 26 |
-
*
|
| 27 |
-
* @var object|Mage_CatalogSearch_Model_Resource_Fulltext_Engine
|
| 28 |
-
*/
|
| 29 |
-
protected $_engine;
|
| 30 |
-
|
| 31 |
-
/**
|
| 32 |
-
* Found products collection
|
| 33 |
-
*
|
| 34 |
-
* @var Mage_CatalogSearch_Model_Resource_Advanced_Collection
|
| 35 |
-
*/
|
| 36 |
-
protected $_productCollection;
|
| 37 |
-
|
| 38 |
-
/**
|
| 39 |
-
* Add advanced search filters to product collection
|
| 40 |
-
*
|
| 41 |
-
* @param array $values
|
| 42 |
-
* @return Mage_CatalogSearch_Model_Advanced
|
| 43 |
-
*/
|
| 44 |
-
public function addFilters($values, $ids = null)
|
| 45 |
-
{
|
| 46 |
-
|
| 47 |
-
if (Mage::getStoreConfig('Boxalino_General/general/enabled') == 0) {
|
| 48 |
-
return parent::addFilters($values, $ids);
|
| 49 |
-
}
|
| 50 |
-
|
| 51 |
-
$attributes = $this->getAttributes();
|
| 52 |
-
$hasConditions = true;
|
| 53 |
-
$allConditions = array();
|
| 54 |
-
|
| 55 |
-
foreach ($attributes as $attribute) {
|
| 56 |
-
/* @var $attribute Mage_Catalog_Model_Resource_Eav_Attribute */
|
| 57 |
-
if (!isset($values[$attribute->getAttributeCode()])) {
|
| 58 |
-
continue;
|
| 59 |
-
}
|
| 60 |
-
$value = $values[$attribute->getAttributeCode()];
|
| 61 |
-
if (!is_array($value)) {
|
| 62 |
-
$value = trim($value);
|
| 63 |
-
}
|
| 64 |
-
|
| 65 |
-
if ($attribute->getAttributeCode() == 'price') {
|
| 66 |
-
$value['from'] = isset($value['from']) ? trim($value['from']) : '';
|
| 67 |
-
$value['to'] = isset($value['to']) ? trim($value['to']) : '';
|
| 68 |
-
if (is_numeric($value['from']) || is_numeric($value['to'])) {
|
| 69 |
-
if (!empty($value['currency'])) {
|
| 70 |
-
$rate = Mage::app()->getStore()->getBaseCurrency()->getRate($value['currency']);
|
| 71 |
-
} else {
|
| 72 |
-
$rate = 1;
|
| 73 |
-
}
|
| 74 |
-
$this->_addSearchCriteria($attribute, $value);
|
| 75 |
-
}
|
| 76 |
-
} else if ($attribute->isIndexable()) {
|
| 77 |
-
if (!is_string($value) || strlen($value) != 0) {
|
| 78 |
-
$this->_addSearchCriteria($attribute, $value);
|
| 79 |
-
}
|
| 80 |
-
} else {
|
| 81 |
-
$condition = $this->_prepareCondition($attribute, $value);
|
| 82 |
-
if ($condition === false) {
|
| 83 |
-
continue;
|
| 84 |
-
}
|
| 85 |
-
|
| 86 |
-
$this->_addSearchCriteria($attribute, $value);
|
| 87 |
-
}
|
| 88 |
-
}
|
| 89 |
-
//Add id from boxalino
|
| 90 |
-
$this->getProductCollection()->addIdFromBoxalino($ids);
|
| 91 |
-
if ($allConditions) {
|
| 92 |
-
$this->getProductCollection()->addIdFromBoxalino($allConditions);
|
| 93 |
-
} else if (!$hasConditions) {
|
| 94 |
-
Mage::throwException(Mage::helper('catalogsearch')->__('Please specify at least one search term.'));
|
| 95 |
-
}
|
| 96 |
-
|
| 97 |
-
return $this;
|
| 98 |
-
}
|
| 99 |
-
|
| 100 |
-
/**
|
| 101 |
-
* Retrieve array of attributes used in advanced search
|
| 102 |
-
*
|
| 103 |
-
* @return array
|
| 104 |
-
*/
|
| 105 |
-
public function getAttributes()
|
| 106 |
-
{
|
| 107 |
-
/* @var $attributes Mage_Catalog_Model_Resource_Eav_Resource_Product_Attribute_Collection */
|
| 108 |
-
$attributes = $this->getData('attributes');
|
| 109 |
-
if (is_null($attributes)) {
|
| 110 |
-
$product = Mage::getModel('catalog/product');
|
| 111 |
-
$attributes = Mage::getResourceModel('catalog/product_attribute_collection')
|
| 112 |
-
->addHasOptionsFilter()
|
| 113 |
-
->addDisplayInAdvancedSearchFilter()
|
| 114 |
-
->addStoreLabel(Mage::app()->getStore()->getId())
|
| 115 |
-
->setOrder('main_table.attribute_id', 'asc')
|
| 116 |
-
->load();
|
| 117 |
-
foreach ($attributes as $attribute) {
|
| 118 |
-
$attribute->setEntity($product->getResource());
|
| 119 |
-
}
|
| 120 |
-
$this->setData('attributes', $attributes);
|
| 121 |
-
}
|
| 122 |
-
return $attributes;
|
| 123 |
-
}
|
| 124 |
-
|
| 125 |
-
/**
|
| 126 |
-
* Add data about search criteria to object state
|
| 127 |
-
*
|
| 128 |
-
* @param Mage_Eav_Model_Entity_Attribute $attribute
|
| 129 |
-
* @param mixed $value
|
| 130 |
-
* @return Mage_CatalogSearch_Model_Advanced
|
| 131 |
-
*/
|
| 132 |
-
protected function _addSearchCriteria($attribute, $value)
|
| 133 |
-
{
|
| 134 |
-
$name = $attribute->getStoreLabel();
|
| 135 |
-
|
| 136 |
-
if (is_array($value)) {
|
| 137 |
-
if (isset($value['from']) && isset($value['to'])) {
|
| 138 |
-
if (!empty($value['from']) || !empty($value['to'])) {
|
| 139 |
-
if (isset($value['currency'])) {
|
| 140 |
-
$currencyModel = Mage::getModel('directory/currency')->load($value['currency']);
|
| 141 |
-
$from = $currencyModel->format($value['from'], array(), false);
|
| 142 |
-
$to = $currencyModel->format($value['to'], array(), false);
|
| 143 |
-
} else {
|
| 144 |
-
$currencyModel = null;
|
| 145 |
-
}
|
| 146 |
-
|
| 147 |
-
if (strlen($value['from']) > 0 && strlen($value['to']) > 0) {
|
| 148 |
-
// -
|
| 149 |
-
$value = sprintf('%s - %s',
|
| 150 |
-
($currencyModel ? $from : $value['from']), ($currencyModel ? $to : $value['to']));
|
| 151 |
-
} elseif (strlen($value['from']) > 0) {
|
| 152 |
-
// and more
|
| 153 |
-
$value = Mage::helper('catalogsearch')->__('%s and greater', ($currencyModel ? $from : $value['from']));
|
| 154 |
-
} elseif (strlen($value['to']) > 0) {
|
| 155 |
-
// to
|
| 156 |
-
$value = Mage::helper('catalogsearch')->__('up to %s', ($currencyModel ? $to : $value['to']));
|
| 157 |
-
}
|
| 158 |
-
} else {
|
| 159 |
-
return $this;
|
| 160 |
-
}
|
| 161 |
-
}
|
| 162 |
-
}
|
| 163 |
-
|
| 164 |
-
if (($attribute->getFrontendInput() == 'select' || $attribute->getFrontendInput() == 'multiselect')
|
| 165 |
-
&& is_array($value)
|
| 166 |
-
) {
|
| 167 |
-
foreach ($value as $key => $val) {
|
| 168 |
-
$value[$key] = $attribute->getSource()->getOptionText($val);
|
| 169 |
-
|
| 170 |
-
if (is_array($value[$key])) {
|
| 171 |
-
$value[$key] = $value[$key]['label'];
|
| 172 |
-
}
|
| 173 |
-
}
|
| 174 |
-
$value = implode(', ', $value);
|
| 175 |
-
} else if ($attribute->getFrontendInput() == 'select' || $attribute->getFrontendInput() == 'multiselect') {
|
| 176 |
-
$value = $attribute->getSource()->getOptionText($value);
|
| 177 |
-
if (is_array($value))
|
| 178 |
-
$value = $value['label'];
|
| 179 |
-
} else if ($attribute->getFrontendInput() == 'boolean') {
|
| 180 |
-
$value = $value == 1
|
| 181 |
-
? Mage::helper('catalogsearch')->__('Yes')
|
| 182 |
-
: Mage::helper('catalogsearch')->__('No');
|
| 183 |
-
}
|
| 184 |
-
|
| 185 |
-
$this->_searchCriterias[] = array('name' => $name, 'value' => $value);
|
| 186 |
-
return $this;
|
| 187 |
-
}
|
| 188 |
-
|
| 189 |
-
/**
|
| 190 |
-
* Prepare search condition for attribute
|
| 191 |
-
*
|
| 192 |
-
* @deprecated after 1.4.1.0 - use Mage_CatalogSearch_Model_Resource_Advanced->_prepareCondition()
|
| 193 |
-
*
|
| 194 |
-
* @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute
|
| 195 |
-
* @param string|array $value
|
| 196 |
-
* @return mixed
|
| 197 |
-
*/
|
| 198 |
-
protected function _prepareCondition($attribute, $value)
|
| 199 |
-
{
|
| 200 |
-
return $this->_getResource()->prepareCondition($attribute, $value, $this->getProductCollection());
|
| 201 |
-
}
|
| 202 |
-
|
| 203 |
-
/**
|
| 204 |
-
* Retrieve resource instance wrapper
|
| 205 |
-
*
|
| 206 |
-
* @return Mage_CatalogSearch_Model_Resource_Advanced
|
| 207 |
-
*/
|
| 208 |
-
protected function _getResource()
|
| 209 |
-
{
|
| 210 |
-
$resourceName = $this->_engine->getResourceName();
|
| 211 |
-
if ($resourceName) {
|
| 212 |
-
$this->_resourceName = $resourceName;
|
| 213 |
-
}
|
| 214 |
-
return parent::_getResource();
|
| 215 |
-
}
|
| 216 |
-
|
| 217 |
-
/**
|
| 218 |
-
* Retrieve advanced search product collection
|
| 219 |
-
*
|
| 220 |
-
* @return Mage_CatalogSearch_Model_Resource_Advanced_Collection
|
| 221 |
-
*/
|
| 222 |
-
public function getProductCollection()
|
| 223 |
-
{
|
| 224 |
-
|
| 225 |
-
if (is_null($this->_productCollection)) {
|
| 226 |
-
$collection = $this->_engine->getAdvancedResultCollection();
|
| 227 |
-
$this->prepareProductCollection($collection);
|
| 228 |
-
if (!$collection) {
|
| 229 |
-
return $collection;
|
| 230 |
-
}
|
| 231 |
-
$this->_productCollection = $collection;
|
| 232 |
-
}
|
| 233 |
-
|
| 234 |
-
return $this->_productCollection;
|
| 235 |
-
}
|
| 236 |
-
|
| 237 |
-
/**
|
| 238 |
-
* Prepare product collection
|
| 239 |
-
*
|
| 240 |
-
* @param Mage_CatalogSearch_Model_Resource_Advanced_Collection $collection
|
| 241 |
-
* @return Mage_Catalog_Model_Layer
|
| 242 |
-
*/
|
| 243 |
-
public function prepareProductCollection($collection)
|
| 244 |
-
{
|
| 245 |
-
$collection->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
|
| 246 |
-
->setStore(Mage::app()->getStore())
|
| 247 |
-
->addMinimalPrice()
|
| 248 |
-
->addTaxPercents()
|
| 249 |
-
->addStoreFilter();
|
| 250 |
-
|
| 251 |
-
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
|
| 252 |
-
Mage::getSingleton('catalog/product_visibility')->addVisibleInSearchFilterToCollection($collection);
|
| 253 |
-
return $this;
|
| 254 |
-
}
|
| 255 |
-
|
| 256 |
-
/**
|
| 257 |
-
* Returns prepared search criterias in text
|
| 258 |
-
*
|
| 259 |
-
* @return array
|
| 260 |
-
*/
|
| 261 |
-
public function getSearchCriterias()
|
| 262 |
-
{
|
| 263 |
-
return $this->_searchCriterias;
|
| 264 |
-
}
|
| 265 |
-
|
| 266 |
-
/**
|
| 267 |
-
* Initialize resource model
|
| 268 |
-
*
|
| 269 |
-
*/
|
| 270 |
-
protected function _construct()
|
| 271 |
-
{
|
| 272 |
-
$this->_getEngine();
|
| 273 |
-
$this->_init('catalogsearch/advanced');
|
| 274 |
-
}
|
| 275 |
-
|
| 276 |
-
protected function _getEngine()
|
| 277 |
-
{
|
| 278 |
-
if ($this->_engine == null) {
|
| 279 |
-
$this->_engine = Mage::helper('catalogsearch')->getEngine();
|
| 280 |
-
}
|
| 281 |
-
|
| 282 |
-
return $this->_engine;
|
| 283 |
-
}
|
| 284 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/code/community/Boxalino/CemSearch/Model/Category.php
DELETED
|
@@ -1,46 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
/**
|
| 3 |
-
* Created by: Simon Rupf <simon.rupf@boxalino.com>
|
| 4 |
-
* Created at: 15.04.2015 14:47
|
| 5 |
-
*/
|
| 6 |
-
|
| 7 |
-
require_once 'Mage/Catalog/Model/Category.php';
|
| 8 |
-
|
| 9 |
-
/**
|
| 10 |
-
* Catalog category
|
| 11 |
-
*
|
| 12 |
-
* @category Boxalino
|
| 13 |
-
* @package Boxalino_CemSearch
|
| 14 |
-
* @author Simon Rupf <simon.rupf@boxalino.com>
|
| 15 |
-
*/
|
| 16 |
-
class Boxalino_CemSearch_Model_Category extends Mage_Catalog_Model_Category
|
| 17 |
-
{
|
| 18 |
-
/**
|
| 19 |
-
* Retrieve Available Product Listing Sort By
|
| 20 |
-
* code as key, value - name
|
| 21 |
-
*
|
| 22 |
-
* @return array
|
| 23 |
-
*/
|
| 24 |
-
public function getAvailableSortByOptions() {
|
| 25 |
-
$availableSortBy = array();
|
| 26 |
-
$defaultSortBy = Mage::getSingleton('catalog/config')
|
| 27 |
-
->getAttributeUsedForSortByArray();
|
| 28 |
-
if ($this->getAvailableSortBy()) {
|
| 29 |
-
foreach ($this->getAvailableSortBy() as $sortBy) {
|
| 30 |
-
if (isset($defaultSortBy[$sortBy])) {
|
| 31 |
-
$availableSortBy[$sortBy] = $defaultSortBy[$sortBy];
|
| 32 |
-
}
|
| 33 |
-
}
|
| 34 |
-
}
|
| 35 |
-
|
| 36 |
-
if (!$availableSortBy) {
|
| 37 |
-
$availableSortBy = $defaultSortBy;
|
| 38 |
-
}
|
| 39 |
-
|
| 40 |
-
// force ordering of results by position returned by p13n
|
| 41 |
-
$availableSortBy = array_merge(array('relevance'=>'Relevance'), $availableSortBy);
|
| 42 |
-
unset($availableSortBy['position']);
|
| 43 |
-
|
| 44 |
-
return $availableSortBy;
|
| 45 |
-
}
|
| 46 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/code/community/Boxalino/CemSearch/Model/Logger.php
DELETED
|
@@ -1,84 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
|
| 3 |
-
class Boxalino_CemSearch_Model_Logger
|
| 4 |
-
{
|
| 5 |
-
static private $_lastMemory = 0;
|
| 6 |
-
static private $_startLogging = null;
|
| 7 |
-
static private $_fileName = null;
|
| 8 |
-
|
| 9 |
-
/**
|
| 10 |
-
* @param string $type Error, Warning, Info, Success
|
| 11 |
-
* @param array $data array('memory_usage' => '', 'method' => '', 'description' => ''),
|
| 12 |
-
*/
|
| 13 |
-
static public function saveMemoryTracking($type, $loggedAction, array $data)
|
| 14 |
-
{
|
| 15 |
-
if (Mage::getStoreConfig('Boxalino_General/general/logs_saving')) {
|
| 16 |
-
if (self::$_startLogging == null) {
|
| 17 |
-
self::$_startLogging = date('d-m-Y_H:i:s');
|
| 18 |
-
}
|
| 19 |
-
if (self::$_fileName == null) {
|
| 20 |
-
self::initFile($loggedAction . '-' . self::$_startLogging . '.txt');
|
| 21 |
-
}
|
| 22 |
-
$difference = $data['memory_usage'] - self::$_lastMemory;
|
| 23 |
-
$line = date('d-m-Y H:i:s') . ' ' . strtoupper($type) . ': ' . $loggedAction . ' / ' . $data['method'] . ' / ' . $data['description'] . '. Memory usage: ' . $data['memory_usage'] . ' - Difference=' . $difference . "\n";
|
| 24 |
-
file_put_contents(self::$_fileName, $line, FILE_APPEND);
|
| 25 |
-
self::$_lastMemory = $data['memory_usage'];
|
| 26 |
-
}
|
| 27 |
-
}
|
| 28 |
-
|
| 29 |
-
static public function saveFrontActions($type, $data, $separator = false)
|
| 30 |
-
{
|
| 31 |
-
|
| 32 |
-
if (!Mage::getStoreConfig('Boxalino_General/general/logs_saving_frontend')) {
|
| 33 |
-
return;
|
| 34 |
-
}
|
| 35 |
-
|
| 36 |
-
$date = date('Y-m-d H:i:s');
|
| 37 |
-
|
| 38 |
-
if (isset($_REQUEST['dev_bx_disp']) && $_REQUEST['dev_bx_disp'] == 'true') {
|
| 39 |
-
print_r('<pre>');
|
| 40 |
-
print_r($date . ' ' . strtoupper($type) . '<br/>');
|
| 41 |
-
print_r($data);
|
| 42 |
-
print_r('</pre>');
|
| 43 |
-
|
| 44 |
-
print_r($separator ? "<br/>========================================================<br/>" : "<br/>");
|
| 45 |
-
}
|
| 46 |
-
|
| 47 |
-
$day = date('Y-m-d_H:i');
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
// Create file if not exist
|
| 51 |
-
$logDir = Mage::getBaseDir('var') . DS . 'boxalino_logs';
|
| 52 |
-
$file = $logDir . DS . 'request_' . $day;
|
| 53 |
-
|
| 54 |
-
if (!is_dir($logDir)) {
|
| 55 |
-
mkdir($logDir);
|
| 56 |
-
chmod($logDir, 0777);
|
| 57 |
-
}
|
| 58 |
-
|
| 59 |
-
if (!file_exists($file)) {
|
| 60 |
-
file_put_contents($file, '');
|
| 61 |
-
chmod($file, 0777);
|
| 62 |
-
}
|
| 63 |
-
|
| 64 |
-
//Save information into file
|
| 65 |
-
$line = $date . ' ' . strtoupper($type) . "\n" . print_r($data, true) . ($separator ? "\n=========================================================================\n" : "\n");
|
| 66 |
-
file_put_contents($file, $line, FILE_APPEND);
|
| 67 |
-
}
|
| 68 |
-
|
| 69 |
-
static private function initFile($name)
|
| 70 |
-
{
|
| 71 |
-
$logDir = Mage::getBaseDir('var') . DS . 'boxalino_logs';
|
| 72 |
-
self::$_fileName = $logDir . DS . $name;
|
| 73 |
-
|
| 74 |
-
if (!is_dir($logDir)) {
|
| 75 |
-
mkdir($logDir);
|
| 76 |
-
chmod($logDir, 0777);
|
| 77 |
-
}
|
| 78 |
-
|
| 79 |
-
if (!file_exists(self::$_fileName)) {
|
| 80 |
-
file_put_contents(self::$_fileName, '');
|
| 81 |
-
chmod(self::$_fileName, 0777);
|
| 82 |
-
}
|
| 83 |
-
}
|
| 84 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/code/community/Boxalino/CemSearch/Model/Resource/Advanced.php
DELETED
|
@@ -1,12 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
/**
|
| 3 |
-
* Created by: Szymon Nosal <szymon.nosal@codete.com>
|
| 4 |
-
* Created at: 05.06.14 13:57
|
| 5 |
-
*/
|
| 6 |
-
|
| 7 |
-
require_once 'Mage/CatalogSearch/Model/Resource/Advanced.php';
|
| 8 |
-
|
| 9 |
-
class Boxalino_CemSearch_Model_Resource_Advanced extends Mage_CatalogSearch_Model_Resource_Advanced
|
| 10 |
-
{
|
| 11 |
-
|
| 12 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/code/community/Boxalino/CemSearch/Model/Resource/Advanced/Collection.php
DELETED
|
@@ -1,30 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
/**
|
| 3 |
-
* Created by: Szymon Nosal <szymon.nosal@codete.com>
|
| 4 |
-
* Created at: 06.06.14 11:36
|
| 5 |
-
*/
|
| 6 |
-
|
| 7 |
-
/**
|
| 8 |
-
* Collection Advanced
|
| 9 |
-
*
|
| 10 |
-
* @category Boxalino
|
| 11 |
-
* @package Boxalino_CemSearch
|
| 12 |
-
* @author Szymon Nosal <szymon.nosal@codete.com>
|
| 13 |
-
*/
|
| 14 |
-
class Boxalino_CemSearch_Model_Resource_Advanced_Collection extends Mage_Catalog_Model_Resource_Product_Collection
|
| 15 |
-
{
|
| 16 |
-
/**
|
| 17 |
-
* Add products id to search
|
| 18 |
-
*
|
| 19 |
-
* @param array $ids
|
| 20 |
-
* @return Mage_CatalogSearch_Model_Resource_Advanced_Collection
|
| 21 |
-
*/
|
| 22 |
-
public function addIdFromBoxalino($ids)
|
| 23 |
-
{
|
| 24 |
-
|
| 25 |
-
$this->addFieldToFilter('entity_id', array('in' => $ids));
|
| 26 |
-
|
| 27 |
-
return $this;
|
| 28 |
-
}
|
| 29 |
-
|
| 30 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/code/community/Boxalino/CemSearch/Model/Resource/Fulltext.php
DELETED
|
@@ -1,258 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
|
| 3 |
-
require_once 'Mage/CatalogSearch/Model/Resource/Fulltext.php';
|
| 4 |
-
|
| 5 |
-
class Boxalino_CemSearch_Model_Resource_Fulltext extends Mage_CatalogSearch_Model_Resource_Fulltext
|
| 6 |
-
{
|
| 7 |
-
|
| 8 |
-
public function prepareResult($object, $queryText, $query)
|
| 9 |
-
{
|
| 10 |
-
|
| 11 |
-
$session = Mage::getSingleton('core/session');
|
| 12 |
-
$session->unsetData('relax');
|
| 13 |
-
$session->unsetData('relax_products');
|
| 14 |
-
$session->unsetData('relax_products_extra');
|
| 15 |
-
|
| 16 |
-
if (Mage::getStoreConfig('Boxalino_General/general/enabled') == 0) {
|
| 17 |
-
return parent::prepareResult($object, $queryText, $query);
|
| 18 |
-
}
|
| 19 |
-
|
| 20 |
-
if($queryText == ''){
|
| 21 |
-
return $this;
|
| 22 |
-
}
|
| 23 |
-
|
| 24 |
-
$searchAdapter = Mage::helper('Boxalino_CemSearch')->getSearchAdapter();
|
| 25 |
-
$entity_ids = $searchAdapter->getEntitiesIds();
|
| 26 |
-
|
| 27 |
-
//prepare suggestion
|
| 28 |
-
$relaxations = array();
|
| 29 |
-
$searchRelaxation = $searchAdapter->getChoiceRelaxation();
|
| 30 |
-
$suggestionConfig = Mage::getStoreConfig('Boxalino_General/search_suggestions');
|
| 31 |
-
|
| 32 |
-
if (
|
| 33 |
-
$suggestionConfig['enabled'] &&
|
| 34 |
-
is_object($searchRelaxation) &&
|
| 35 |
-
is_array($searchRelaxation->suggestionsResults) &&
|
| 36 |
-
count($searchRelaxation->suggestionsResults) > 0 &&
|
| 37 |
-
(
|
| 38 |
-
count($entity_ids) <= $suggestionConfig['min'] ||
|
| 39 |
-
count($entity_ids) >= $suggestionConfig['max']
|
| 40 |
-
)
|
| 41 |
-
) {
|
| 42 |
-
Boxalino_CemSearch_Model_Logger::saveFrontActions('prepareResult', 'suggestions detected');
|
| 43 |
-
|
| 44 |
-
foreach ($searchRelaxation->suggestionsResults as $suggestion) {
|
| 45 |
-
$relaxations[] = array(
|
| 46 |
-
'hits' => $suggestion->totalHitCount,
|
| 47 |
-
'text' => $suggestion->queryText,
|
| 48 |
-
'href' => urlencode($suggestion->queryText)
|
| 49 |
-
);
|
| 50 |
-
}
|
| 51 |
-
|
| 52 |
-
if ($suggestionConfig['sort']) {
|
| 53 |
-
usort($relaxations, array($this, 'cmp'));
|
| 54 |
-
}
|
| 55 |
-
}
|
| 56 |
-
|
| 57 |
-
$session->setData('relax', array_slice($relaxations, 0, $suggestionConfig['display']));
|
| 58 |
-
Boxalino_CemSearch_Model_Logger::saveFrontActions('prepareResult relax', $session->getData('relax'));
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
$this->resetSearchResults($query);
|
| 62 |
-
|
| 63 |
-
//relaxation
|
| 64 |
-
$relaxations_extra = array();
|
| 65 |
-
$relaxationConfig = Mage::getStoreConfig('Boxalino_General/search_relaxation');
|
| 66 |
-
|
| 67 |
-
if (
|
| 68 |
-
(
|
| 69 |
-
$entity_ids === null ||
|
| 70 |
-
count($entity_ids) <= $relaxationConfig['max']
|
| 71 |
-
) &&
|
| 72 |
-
is_object($searchRelaxation) &&
|
| 73 |
-
( count($searchRelaxation->subphrasesResults) > 0) &&
|
| 74 |
-
$relaxationConfig['enabled']
|
| 75 |
-
) {
|
| 76 |
-
|
| 77 |
-
Boxalino_CemSearch_Model_Logger::saveFrontActions('prepareResult', 'relaxations detected');
|
| 78 |
-
|
| 79 |
-
//display current products
|
| 80 |
-
$session = Mage::getSingleton('core/session');
|
| 81 |
-
$session->setData('relax_products', $entity_ids);
|
| 82 |
-
|
| 83 |
-
if (count($searchRelaxation->subphrasesResults) > 0) {
|
| 84 |
-
if (count($relaxations) == 0) {
|
| 85 |
-
$relaxations_extra = array();
|
| 86 |
-
}
|
| 87 |
-
|
| 88 |
-
foreach ($searchRelaxation->subphrasesResults as $subphrase) {
|
| 89 |
-
|
| 90 |
-
if (count($relaxations_extra) >= $relaxationConfig['relaxations']) {
|
| 91 |
-
continue;
|
| 92 |
-
}
|
| 93 |
-
|
| 94 |
-
$relaxations_extra[$subphrase->queryText] = array();
|
| 95 |
-
foreach ($subphrase->hits as $hit) {
|
| 96 |
-
$relaxations_extra[$subphrase->queryText][] = $hit->values['id'][0];
|
| 97 |
-
if (count($relaxations_extra[$subphrase->queryText]) >= $relaxationConfig['products']) {
|
| 98 |
-
break;
|
| 99 |
-
}
|
| 100 |
-
}
|
| 101 |
-
|
| 102 |
-
}
|
| 103 |
-
|
| 104 |
-
}
|
| 105 |
-
|
| 106 |
-
//display currently products
|
| 107 |
-
$session->setData('relax_products_extra', $relaxations_extra);
|
| 108 |
-
Boxalino_CemSearch_Model_Logger::saveFrontActions('prepareResult relax_products_extra', $session->getData('relax_products_extra'));
|
| 109 |
-
|
| 110 |
-
$this->resetSearchResults($query);
|
| 111 |
-
|
| 112 |
-
return $this;
|
| 113 |
-
|
| 114 |
-
} elseif (
|
| 115 |
-
count($entity_ids) == 0 &&
|
| 116 |
-
is_object($searchRelaxation) &&
|
| 117 |
-
count($searchRelaxation->subphrasesResults) == 0 &&
|
| 118 |
-
count($relaxations) > 0) {
|
| 119 |
-
Boxalino_CemSearch_Model_Logger::saveFrontActions('prepareResult', 'no relaxations');
|
| 120 |
-
|
| 121 |
-
$q = $relaxations[0];
|
| 122 |
-
$this->resetSearchResults($query);
|
| 123 |
-
|
| 124 |
-
/**
|
| 125 |
-
* Magento EE works peculiarly.
|
| 126 |
-
* Magento EE loads facets before execute search one more time.
|
| 127 |
-
* Magento CE works correctly.
|
| 128 |
-
*/
|
| 129 |
-
try {
|
| 130 |
-
if (Mage::getEdition() != 'Community') {
|
| 131 |
-
|
| 132 |
-
$params = $_GET;
|
| 133 |
-
$params['q'] = $q['text'];
|
| 134 |
-
$paramString = http_build_query($params);
|
| 135 |
-
|
| 136 |
-
$currentUrl = urldecode(Mage::helper('core/url')->getCurrentUrl());
|
| 137 |
-
$currentUrl = substr($currentUrl, 0, strpos($currentUrl, '?'));
|
| 138 |
-
|
| 139 |
-
header('Location: ' . $currentUrl . '?' . $paramString);
|
| 140 |
-
exit();
|
| 141 |
-
}
|
| 142 |
-
}catch (Exception $e){
|
| 143 |
-
|
| 144 |
-
}
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
Mage::helper('Boxalino_CemSearch')->resetSearchAdapter();
|
| 148 |
-
|
| 149 |
-
Mage::helper('catalogsearch')->setQueryText($q['text']);
|
| 150 |
-
|
| 151 |
-
$searchAdapter = Mage::helper('Boxalino_CemSearch')->getSearchAdapter();
|
| 152 |
-
$entity_ids = $searchAdapter->getEntitiesIds();
|
| 153 |
-
|
| 154 |
-
$session->unsetData('relax');
|
| 155 |
-
$session->unsetData('relax_products');
|
| 156 |
-
$session->unsetData('relax_products_extra');
|
| 157 |
-
|
| 158 |
-
}
|
| 159 |
-
|
| 160 |
-
$this->resetSearchResults($query);
|
| 161 |
-
|
| 162 |
-
if ($entity_ids === null || count($entity_ids) < 1) {
|
| 163 |
-
return $this;
|
| 164 |
-
}
|
| 165 |
-
|
| 166 |
-
$adapter = $this->_getWriteAdapter();
|
| 167 |
-
|
| 168 |
-
if (!$query->getIsProcessed() || true) {
|
| 169 |
-
|
| 170 |
-
$searchType = $object->getSearchType($query->getStoreId());
|
| 171 |
-
|
| 172 |
-
$preparedTerms = Mage::getResourceHelper('catalogsearch')
|
| 173 |
-
->prepareTerms($queryText, $query->getMaxQueryWords());
|
| 174 |
-
|
| 175 |
-
$bind = array();
|
| 176 |
-
$like = array();
|
| 177 |
-
$mainTableAlias = 's';
|
| 178 |
-
$fields = array(
|
| 179 |
-
'query_id' => new Zend_Db_Expr($query->getId()),
|
| 180 |
-
'product_id',
|
| 181 |
-
);
|
| 182 |
-
$select = $adapter->select()
|
| 183 |
-
->from(array($mainTableAlias => $this->getMainTable()), $fields)
|
| 184 |
-
->joinInner(array('e' => $this->getTable('catalog/product')),
|
| 185 |
-
'e.entity_id = s.product_id',
|
| 186 |
-
array())
|
| 187 |
-
->where($mainTableAlias . '.store_id = ?', (int)$query->getStoreId());
|
| 188 |
-
|
| 189 |
-
if ($searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_FULLTEXT
|
| 190 |
-
|| $searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_COMBINE
|
| 191 |
-
) {
|
| 192 |
-
$bind[':query'] = implode(' ', $preparedTerms[0]);
|
| 193 |
-
}
|
| 194 |
-
|
| 195 |
-
if (count($entity_ids) > 0) {
|
| 196 |
-
$select->where('(e.entity_id IN (' . implode(',', $entity_ids) . '))');
|
| 197 |
-
}
|
| 198 |
-
|
| 199 |
-
// enforce boxalino ranking
|
| 200 |
-
$select->order(new Zend_Db_Expr('FIELD(e.entity_id,' . implode(',', $entity_ids).')'));
|
| 201 |
-
|
| 202 |
-
if (
|
| 203 |
-
$searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_LIKE ||
|
| 204 |
-
$searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_FULLTEXT ||
|
| 205 |
-
$searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_COMBINE
|
| 206 |
-
) {
|
| 207 |
-
$innerSelect = (string) $select;
|
| 208 |
-
$select = $adapter->select()
|
| 209 |
-
->from(array(
|
| 210 |
-
'a' => new Zend_Db_Expr('(' . $innerSelect . ')')
|
| 211 |
-
), array(
|
| 212 |
-
'query_id',
|
| 213 |
-
'product_id'
|
| 214 |
-
))
|
| 215 |
-
->join(array(
|
| 216 |
-
'b' => new Zend_Db_Expr('(SELECT @s:= 0)')
|
| 217 |
-
), '', array(
|
| 218 |
-
'relevance' => new Zend_Db_Expr('@s:=@s+1')
|
| 219 |
-
))
|
| 220 |
-
->where('1=1'); // added to avoid collision with appended ON DUPLICATE
|
| 221 |
-
}
|
| 222 |
-
|
| 223 |
-
Boxalino_CemSearch_Model_Logger::saveFrontActions('Fulltext_PrepareResult', 'storing catalogsearch/result for entities with id: ' . implode(', ', $entity_ids));
|
| 224 |
-
$sql = $adapter->insertFromSelect($select,
|
| 225 |
-
$this->getTable('catalogsearch/result'),
|
| 226 |
-
array(),
|
| 227 |
-
Varien_Db_Adapter_Interface::INSERT_ON_DUPLICATE);
|
| 228 |
-
|
| 229 |
-
$adapter->query($sql, $bind);
|
| 230 |
-
|
| 231 |
-
$query->setIsProcessed(1);
|
| 232 |
-
}
|
| 233 |
-
|
| 234 |
-
return $this;
|
| 235 |
-
|
| 236 |
-
}
|
| 237 |
-
|
| 238 |
-
public function resetSearchResults($query = null)
|
| 239 |
-
{
|
| 240 |
-
$adapter = $this->_getWriteAdapter();
|
| 241 |
-
$adapter->update($this->getTable('catalogsearch/search_query'), array('is_processed' => 0));
|
| 242 |
-
|
| 243 |
-
if (!is_null($query)) {
|
| 244 |
-
$adapter->delete($this->getTable('catalogsearch/result'), 'query_id=' . $query->getId());
|
| 245 |
-
}
|
| 246 |
-
Mage::dispatchEvent('catalogsearch_reset_search_result');
|
| 247 |
-
|
| 248 |
-
return $this;
|
| 249 |
-
}
|
| 250 |
-
|
| 251 |
-
private function cmp($a, $b)
|
| 252 |
-
{
|
| 253 |
-
if ($a['hits'] == $b['hits']) {
|
| 254 |
-
return 0;
|
| 255 |
-
}
|
| 256 |
-
return ($a['hits'] > $b['hits']) ? -1 : 1;
|
| 257 |
-
}
|
| 258 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/code/community/Boxalino/CemSearch/controllers/AdvancedController.php
DELETED
|
@@ -1,158 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
/**
|
| 3 |
-
* Created by: Szymon Nosal <szymon.nosal@codete.com>
|
| 4 |
-
* Created at: 06.06.14 11:36
|
| 5 |
-
*/
|
| 6 |
-
|
| 7 |
-
require_once "Mage/CatalogSearch/controllers/AdvancedController.php";
|
| 8 |
-
|
| 9 |
-
/**
|
| 10 |
-
* Catalog Search Controller
|
| 11 |
-
*
|
| 12 |
-
* @category Mage
|
| 13 |
-
* @package Mage_CatalogSearch
|
| 14 |
-
* @module Catalog
|
| 15 |
-
*/
|
| 16 |
-
class Boxalino_CemSearch_AdvancedController extends Mage_CatalogSearch_AdvancedController
|
| 17 |
-
{
|
| 18 |
-
|
| 19 |
-
public function indexAction()
|
| 20 |
-
{
|
| 21 |
-
$this->loadLayout();
|
| 22 |
-
$this->_initLayoutMessages('catalogsearch/session');
|
| 23 |
-
$this->renderLayout();
|
| 24 |
-
}
|
| 25 |
-
|
| 26 |
-
public function resultAction()
|
| 27 |
-
{
|
| 28 |
-
|
| 29 |
-
$queryAttribute = array();
|
| 30 |
-
|
| 31 |
-
if (Mage::getStoreConfig('Boxalino_General/general/enabled') == 0) {
|
| 32 |
-
return parent::resultAction();
|
| 33 |
-
}
|
| 34 |
-
|
| 35 |
-
$this->loadLayout();
|
| 36 |
-
|
| 37 |
-
$params = $this->getRequest()->getQuery();
|
| 38 |
-
|
| 39 |
-
$tmp = Mage::getModel('catalogsearch/advanced');
|
| 40 |
-
try {
|
| 41 |
-
$tmp->addFilters($params);
|
| 42 |
-
} catch (Mage_Core_Exception $e) {
|
| 43 |
-
Mage::getSingleton('catalogsearch/session')->addError($e->getMessage());
|
| 44 |
-
$this->_redirectError(
|
| 45 |
-
Mage::getModel('core/url')
|
| 46 |
-
->setQueryParams($params)
|
| 47 |
-
->getUrl('*/*/')
|
| 48 |
-
);
|
| 49 |
-
}
|
| 50 |
-
|
| 51 |
-
foreach ($tmp->getAttributes() as $at) {
|
| 52 |
-
$queryAttribute[$at->getStoreLabel()] = $at->getAttributeCode();
|
| 53 |
-
}
|
| 54 |
-
|
| 55 |
-
$criteria = $tmp->getSearchCriterias();
|
| 56 |
-
unset($tmp);
|
| 57 |
-
$lang = substr(Mage::app()->getLocale()->getLocaleCode(), 0, 2);
|
| 58 |
-
|
| 59 |
-
//setUp Boxalino
|
| 60 |
-
$storeConfig = Mage::getStoreConfig('Boxalino_General/general');
|
| 61 |
-
$generalConfig = Mage::getStoreConfig('Boxalino_General/search');
|
| 62 |
-
|
| 63 |
-
$p13nConfig = new Boxalino_CemSearch_Helper_P13n_Config(
|
| 64 |
-
$storeConfig['host'],
|
| 65 |
-
Mage::helper('Boxalino_CemSearch')->getAccount(),
|
| 66 |
-
$storeConfig['p13n_username'],
|
| 67 |
-
$storeConfig['p13n_password'],
|
| 68 |
-
$storeConfig['domain']
|
| 69 |
-
);
|
| 70 |
-
$p13nSort = new Boxalino_CemSearch_Helper_P13n_Sort();
|
| 71 |
-
|
| 72 |
-
$p13n = new Boxalino_CemSearch_Helper_P13n_Adapter($p13nConfig);
|
| 73 |
-
|
| 74 |
-
$limit = $generalConfig['advanced_search_limit'] == 0 ? 1000 : $generalConfig['advanced_search_limit'];
|
| 75 |
-
|
| 76 |
-
//setup search
|
| 77 |
-
$p13n->setupInquiry(
|
| 78 |
-
$generalConfig['advanced_search'],
|
| 79 |
-
$params['name'],
|
| 80 |
-
$lang,
|
| 81 |
-
array($generalConfig['entity_id'], 'discountedPrice', 'title_' . $lang, 'score'),
|
| 82 |
-
$p13nSort,
|
| 83 |
-
0, $limit
|
| 84 |
-
);
|
| 85 |
-
//add filters
|
| 86 |
-
|
| 87 |
-
$skip = array('name');
|
| 88 |
-
|
| 89 |
-
foreach ($params as $key => $value) {
|
| 90 |
-
|
| 91 |
-
if (isset($value['from']) || isset($value['to'])) {
|
| 92 |
-
$from = null;
|
| 93 |
-
$to = null;
|
| 94 |
-
|
| 95 |
-
if (isset($params[$key]['from']) && $params[$key]['from'] != '' /* && $params['price']['from'] >= 0*/) {
|
| 96 |
-
$from = $params[$key]['from'];
|
| 97 |
-
}
|
| 98 |
-
if (isset($params[$key]['to']) && $params[$key]['to'] != '' /*&& $params['price']['to'] >= 0*/) {
|
| 99 |
-
$to = $params[$key]['to'];
|
| 100 |
-
}
|
| 101 |
-
|
| 102 |
-
$skip[] = $key;
|
| 103 |
-
|
| 104 |
-
if ($key == 'price') {
|
| 105 |
-
$key = 'discountedPrice';
|
| 106 |
-
}
|
| 107 |
-
|
| 108 |
-
if ($from == null && $to == null) {
|
| 109 |
-
continue;
|
| 110 |
-
}
|
| 111 |
-
$p13n->addFilterFromTo($key, $from, $to);
|
| 112 |
-
|
| 113 |
-
}
|
| 114 |
-
}
|
| 115 |
-
|
| 116 |
-
foreach ($criteria as $criterium) {
|
| 117 |
-
|
| 118 |
-
$name = Mage::helper("Boxalino_CemSearch")->sanitizeFieldName($queryAttribute[$criterium['name']]);
|
| 119 |
-
|
| 120 |
-
if (in_array($name, $skip)) {
|
| 121 |
-
continue;
|
| 122 |
-
}
|
| 123 |
-
|
| 124 |
-
$values = explode(", ", $criterium['value']);
|
| 125 |
-
|
| 126 |
-
if ($name == 'description') {
|
| 127 |
-
$name = 'body';
|
| 128 |
-
} else {
|
| 129 |
-
$name = 'products_' . $name;
|
| 130 |
-
}
|
| 131 |
-
|
| 132 |
-
$p13n->addFilter($name, $values, null);
|
| 133 |
-
}
|
| 134 |
-
|
| 135 |
-
//get result from boxalino
|
| 136 |
-
$p13n->search();
|
| 137 |
-
$p13n->prepareAdditionalDataFromP13n();
|
| 138 |
-
$entity_ids = $p13n->getEntitiesIds();
|
| 139 |
-
unset($p13n);
|
| 140 |
-
|
| 141 |
-
try {
|
| 142 |
-
Boxalino_CemSearch_Model_Logger::saveFrontActions('AdvancedController_ResultAction', 'storing catalogsearch/advanced for entities with id: ' . implode(', ', $entity_ids));
|
| 143 |
-
Mage::getSingleton('catalogsearch/advanced')->addFilters($params, $entity_ids);
|
| 144 |
-
} catch (Mage_Core_Exception $e) {
|
| 145 |
-
Mage::getSingleton('catalogsearch/session')->addError($e->getMessage());
|
| 146 |
-
$this->_redirectError(
|
| 147 |
-
Mage::getModel('core/url')
|
| 148 |
-
->setQueryParams($this->getRequest()->getQuery())
|
| 149 |
-
->getUrl('*/*/')
|
| 150 |
-
);
|
| 151 |
-
}
|
| 152 |
-
|
| 153 |
-
$this->_initLayoutMessages('catalog/session');
|
| 154 |
-
$this->renderLayout();
|
| 155 |
-
|
| 156 |
-
}
|
| 157 |
-
|
| 158 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/code/community/Boxalino/CemSearch/controllers/IndexController.php
DELETED
|
@@ -1,27 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
|
| 3 |
-
class Boxalino_CemSearch_IndexController extends Mage_Core_Controller_Front_Action
|
| 4 |
-
{
|
| 5 |
-
public function indexAction()
|
| 6 |
-
{
|
| 7 |
-
$this->loadLayout();
|
| 8 |
-
$this->renderLayout();
|
| 9 |
-
}
|
| 10 |
-
|
| 11 |
-
public function saveAction()
|
| 12 |
-
{
|
| 13 |
-
$name = '' . $this->getRequest()->getPost('name');
|
| 14 |
-
$surname = '' . $this->getRequest()->getPost('surname');
|
| 15 |
-
$phone = '' . $this->getRequest()->getPost('phone');
|
| 16 |
-
if (isset($name) && ($name != '') && isset($surname) && ($surname != '') && isset($phone) && ($phone != '')) {
|
| 17 |
-
$contact = Mage::getModel('test/test');
|
| 18 |
-
$contact->setData('name', $name);
|
| 19 |
-
$contact->setData('surname', $surname);
|
| 20 |
-
$contact->setData('phone', $phone);
|
| 21 |
-
$contact->save();
|
| 22 |
-
}
|
| 23 |
-
$this->_redirect('test/index/index');
|
| 24 |
-
}
|
| 25 |
-
}
|
| 26 |
-
|
| 27 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/code/community/Boxalino/CemSearch/controllers/ResultController.php
DELETED
|
@@ -1,10 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
require_once "Mage/CatalogSearch/controllers/ResultController.php";
|
| 3 |
-
|
| 4 |
-
class Boxalino_CemSearch_ResultController extends Mage_CatalogSearch_ResultController
|
| 5 |
-
{
|
| 6 |
-
public function indexAction()
|
| 7 |
-
{
|
| 8 |
-
parent::indexAction();
|
| 9 |
-
}
|
| 10 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/code/community/Boxalino/CemSearch/etc/adminhtml.xml
DELETED
|
@@ -1,26 +0,0 @@
|
|
| 1 |
-
<?xml version="1.0"?>
|
| 2 |
-
|
| 3 |
-
<config>
|
| 4 |
-
<acl>
|
| 5 |
-
<resources>
|
| 6 |
-
<admin>
|
| 7 |
-
<children>
|
| 8 |
-
<system>
|
| 9 |
-
<children>
|
| 10 |
-
<config>
|
| 11 |
-
<children>
|
| 12 |
-
<Boxalino_General>
|
| 13 |
-
<title>Boxalino CEM Search</title>
|
| 14 |
-
</Boxalino_General>
|
| 15 |
-
<Boxalino_Recommendation>
|
| 16 |
-
<title>Boxalino Recommendation</title>
|
| 17 |
-
</Boxalino_Recommendation>
|
| 18 |
-
</children>
|
| 19 |
-
</config>
|
| 20 |
-
</children>
|
| 21 |
-
</system>
|
| 22 |
-
</children>
|
| 23 |
-
</admin>
|
| 24 |
-
</resources>
|
| 25 |
-
</acl>
|
| 26 |
-
</config>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/code/community/Boxalino/CemSearch/etc/config.xml
DELETED
|
@@ -1,259 +0,0 @@
|
|
| 1 |
-
<?xml version="1.0"?>
|
| 2 |
-
<config>
|
| 3 |
-
<modules>
|
| 4 |
-
<Boxalino_CemSearch>
|
| 5 |
-
<version>2.10</version>
|
| 6 |
-
</Boxalino_CemSearch>
|
| 7 |
-
</modules>
|
| 8 |
-
<frontend>
|
| 9 |
-
<routers>
|
| 10 |
-
<catalogsearch>
|
| 11 |
-
<args>
|
| 12 |
-
<modules>
|
| 13 |
-
<Boxalino_CemSearch before="Mage_CatalogSearch">Boxalino_CemSearch</Boxalino_CemSearch>
|
| 14 |
-
</modules>
|
| 15 |
-
</args>
|
| 16 |
-
</catalogsearch>
|
| 17 |
-
<routeurfrontend>
|
| 18 |
-
<use>standard</use>
|
| 19 |
-
<args>
|
| 20 |
-
<module>Boxalino_CemSearch</module>
|
| 21 |
-
<frontName>cemsearch</frontName>
|
| 22 |
-
</args>
|
| 23 |
-
</routeurfrontend>
|
| 24 |
-
<routers>
|
| 25 |
-
<boxalinocem>
|
| 26 |
-
<use>standard</use>
|
| 27 |
-
<args>
|
| 28 |
-
<module>Boxalino_Cem</module>
|
| 29 |
-
<frontName>cem</frontName>
|
| 30 |
-
</args>
|
| 31 |
-
</boxalinocem>
|
| 32 |
-
</routers>
|
| 33 |
-
</routers>
|
| 34 |
-
<layout>
|
| 35 |
-
<updates>
|
| 36 |
-
<boxalino>
|
| 37 |
-
<file>boxalino.xml</file>
|
| 38 |
-
</boxalino>
|
| 39 |
-
</updates>
|
| 40 |
-
</layout>
|
| 41 |
-
<events>
|
| 42 |
-
<checkout_cart_product_add_after>
|
| 43 |
-
<observers>
|
| 44 |
-
<boxalinocem_cart_add>
|
| 45 |
-
<class>Boxalino_CemSearch_Model_Observer</class>
|
| 46 |
-
<method>onProductAddedToCart</method>
|
| 47 |
-
</boxalinocem_cart_add>
|
| 48 |
-
</observers>
|
| 49 |
-
</checkout_cart_product_add_after>
|
| 50 |
-
<checkout_onepage_controller_success_action>
|
| 51 |
-
<observers>
|
| 52 |
-
<boxalinocem_order_success>
|
| 53 |
-
<class>Boxalino_CemSearch_Model_Observer</class>
|
| 54 |
-
<method>onOrderSuccessPageView</method>
|
| 55 |
-
</boxalinocem_order_success>
|
| 56 |
-
</observers>
|
| 57 |
-
</checkout_onepage_controller_success_action>
|
| 58 |
-
<checkout_multishipping_controller_success_action>
|
| 59 |
-
<observers>
|
| 60 |
-
<boxalinocem_order_success>
|
| 61 |
-
<class>Boxalino_CemSearch_Model_Observer</class>
|
| 62 |
-
<method>onOrderSuccessPageView</method>
|
| 63 |
-
</boxalinocem_order_success>
|
| 64 |
-
</observers>
|
| 65 |
-
</checkout_multishipping_controller_success_action>
|
| 66 |
-
<catalog_controller_product_view>
|
| 67 |
-
<observers>
|
| 68 |
-
<boxalinocem_product_view>
|
| 69 |
-
<class>Boxalino_CemSearch_Model_Observer</class>
|
| 70 |
-
<method>onProductPageView</method>
|
| 71 |
-
</boxalinocem_product_view>
|
| 72 |
-
</observers>
|
| 73 |
-
</catalog_controller_product_view>
|
| 74 |
-
<catalog_controller_category_init_after>
|
| 75 |
-
<observers>
|
| 76 |
-
<boxalinocem_category_view>
|
| 77 |
-
<class>Boxalino_CemSearch_Model_Observer</class>
|
| 78 |
-
<method>onCategoryPageView</method>
|
| 79 |
-
</boxalinocem_category_view>
|
| 80 |
-
</observers>
|
| 81 |
-
</catalog_controller_category_init_after>
|
| 82 |
-
<customer_login>
|
| 83 |
-
<observers>
|
| 84 |
-
<boxalinocem_login>
|
| 85 |
-
<class>Boxalino_CemSearch_Model_Observer</class>
|
| 86 |
-
<method>onLogin</method>
|
| 87 |
-
</boxalinocem_login>
|
| 88 |
-
</observers>
|
| 89 |
-
</customer_login>
|
| 90 |
-
</events>
|
| 91 |
-
<translate>
|
| 92 |
-
<modules>
|
| 93 |
-
<Boxalino_CemSearch>
|
| 94 |
-
<files>
|
| 95 |
-
<default>Boxalino.csv</default>
|
| 96 |
-
</files>
|
| 97 |
-
</Boxalino_CemSearch>
|
| 98 |
-
</modules>
|
| 99 |
-
</translate>
|
| 100 |
-
</frontend>
|
| 101 |
-
<global>
|
| 102 |
-
<helpers>
|
| 103 |
-
<Boxalino_CemSearch>
|
| 104 |
-
<class>Boxalino_CemSearch_Helper</class>
|
| 105 |
-
</Boxalino_CemSearch>
|
| 106 |
-
<catalogsearch>
|
| 107 |
-
<rewrite>
|
| 108 |
-
<data>Boxalino_CemSearch_CatalogSearch_Helper_Data</data>
|
| 109 |
-
</rewrite>
|
| 110 |
-
</catalogsearch>
|
| 111 |
-
</helpers>
|
| 112 |
-
<models>
|
| 113 |
-
<boxalino_cemsearch>
|
| 114 |
-
<class>Boxalino_CemSearch_Model</class>
|
| 115 |
-
</boxalino_cemsearch>
|
| 116 |
-
<catalogsearch_resource>
|
| 117 |
-
<rewrite>
|
| 118 |
-
<fulltext>Boxalino_CemSearch_Model_Resource_Fulltext</fulltext>
|
| 119 |
-
</rewrite>
|
| 120 |
-
<rewrite>
|
| 121 |
-
<advanced_collection>Boxalino_CemSearch_Model_Resource_Advanced_Collection</advanced_collection>
|
| 122 |
-
</rewrite>
|
| 123 |
-
</catalogsearch_resource>
|
| 124 |
-
<catalogsearch>
|
| 125 |
-
<rewrite>
|
| 126 |
-
<advanced>Boxalino_CemSearch_Model_Advanced</advanced>
|
| 127 |
-
</rewrite>
|
| 128 |
-
</catalogsearch>
|
| 129 |
-
<catalog>
|
| 130 |
-
<rewrite>
|
| 131 |
-
<category>Boxalino_CemSearch_Model_Category</category>
|
| 132 |
-
</rewrite>
|
| 133 |
-
</catalog>
|
| 134 |
-
</models>
|
| 135 |
-
<resources>
|
| 136 |
-
<test_write>
|
| 137 |
-
<connection>
|
| 138 |
-
<use>core_write</use>
|
| 139 |
-
</connection>
|
| 140 |
-
</test_write>
|
| 141 |
-
<test_read>
|
| 142 |
-
<connection>
|
| 143 |
-
<use>core_read</use>
|
| 144 |
-
</connection>
|
| 145 |
-
</test_read>
|
| 146 |
-
</resources>
|
| 147 |
-
<blocks>
|
| 148 |
-
<boxalino>
|
| 149 |
-
<class>Boxalino_CemSearch_Block</class>
|
| 150 |
-
</boxalino>
|
| 151 |
-
<catalogsearch>
|
| 152 |
-
<rewrite>
|
| 153 |
-
<autocomplete>Boxalino_CemSearch_Block_Autocomplete</autocomplete>
|
| 154 |
-
</rewrite>
|
| 155 |
-
</catalogsearch>
|
| 156 |
-
<checkout>
|
| 157 |
-
<rewrite>
|
| 158 |
-
<cart_crosssell>Boxalino_CemSearch_Block_Cart_Crosssell</cart_crosssell>
|
| 159 |
-
</rewrite>
|
| 160 |
-
</checkout>
|
| 161 |
-
<catalog>
|
| 162 |
-
<rewrite>
|
| 163 |
-
<product_list_related>Boxalino_CemSearch_Block_Product_List_Related</product_list_related>
|
| 164 |
-
<product_list_upsell>Boxalino_CemSearch_Block_Product_List_Upsell</product_list_upsell>
|
| 165 |
-
</rewrite>
|
| 166 |
-
</catalog>
|
| 167 |
-
<!--<enterprise_targetrule>-->
|
| 168 |
-
<!--<rewrite>-->
|
| 169 |
-
<!--<catalog_product_list_related>Boxalino_CemSearch_Block_Product_List_Related</catalog_product_list_related>-->
|
| 170 |
-
<!--<catalog_product_list_upsell>Boxalino_CemSearch_Block_Product_List_Upsell</catalog_product_list_upsell>-->
|
| 171 |
-
<!--</rewrite>-->
|
| 172 |
-
<!--</enterprise_targetrule>-->
|
| 173 |
-
</blocks>
|
| 174 |
-
</global>
|
| 175 |
-
<default>
|
| 176 |
-
<Boxalino_General>
|
| 177 |
-
<general>
|
| 178 |
-
<enabled>1</enabled>
|
| 179 |
-
<account_dev>0</account_dev>
|
| 180 |
-
<host>cdn.bx-cloud.com</host>
|
| 181 |
-
<logs_saving>0</logs_saving>
|
| 182 |
-
</general>
|
| 183 |
-
<search>
|
| 184 |
-
<quick_search>search</quick_search>
|
| 185 |
-
<quick_search_limit>0</quick_search_limit>
|
| 186 |
-
<advanced_search>search</advanced_search>
|
| 187 |
-
<advanced_search_limit>0</advanced_search_limit>
|
| 188 |
-
<autocomplete>autocomplete</autocomplete>
|
| 189 |
-
<autocomplete_limit>6</autocomplete_limit>
|
| 190 |
-
<autocomplete_products_limit>3</autocomplete_products_limit>
|
| 191 |
-
<entity_id>id</entity_id>
|
| 192 |
-
</search>
|
| 193 |
-
<autocomplete_html>
|
| 194 |
-
<enabled>1</enabled>
|
| 195 |
-
<items>title:title,url:products_default_url,image:products_cache_image_url</items>
|
| 196 |
-
</autocomplete_html>
|
| 197 |
-
<autocomplete_extra>
|
| 198 |
-
<enabled>1</enabled>
|
| 199 |
-
<enabled_for_all>0</enabled_for_all>
|
| 200 |
-
<items>4</items>
|
| 201 |
-
<sort>1</sort>
|
| 202 |
-
<products>1</products>
|
| 203 |
-
</autocomplete_extra>
|
| 204 |
-
<search_suggestions>
|
| 205 |
-
<enabled>1</enabled>
|
| 206 |
-
<min>3</min>
|
| 207 |
-
<max>50</max>
|
| 208 |
-
<display>6</display>
|
| 209 |
-
<sort>1</sort>
|
| 210 |
-
</search_suggestions>
|
| 211 |
-
<search_relaxation>
|
| 212 |
-
<enabled>1</enabled>
|
| 213 |
-
<max>3</max>
|
| 214 |
-
<relaxations>3</relaxations>
|
| 215 |
-
<products>3</products>
|
| 216 |
-
</search_relaxation>
|
| 217 |
-
<filter>
|
| 218 |
-
<left_filters_enable>0</left_filters_enable>
|
| 219 |
-
<top_filters_enable>0</top_filters_enable>
|
| 220 |
-
<left_filters_multiselect>0</left_filters_multiselect>
|
| 221 |
-
<top_filters_multiselect>0</top_filters_multiselect>
|
| 222 |
-
</filter>
|
| 223 |
-
<tracker>
|
| 224 |
-
<charset>UTF-8</charset>
|
| 225 |
-
<enabled>1</enabled>
|
| 226 |
-
<debug>1</debug>
|
| 227 |
-
<analytics>1</analytics>
|
| 228 |
-
<track_sales>1</track_sales>
|
| 229 |
-
</tracker>
|
| 230 |
-
</Boxalino_General>
|
| 231 |
-
|
| 232 |
-
<Boxalino_Recommendation>
|
| 233 |
-
<!-- CART -->
|
| 234 |
-
<cart>
|
| 235 |
-
<status>1</status>
|
| 236 |
-
<widget>recommendation_cart</widget>
|
| 237 |
-
<min>0</min>
|
| 238 |
-
<max>3</max>
|
| 239 |
-
<scenario>basket</scenario>
|
| 240 |
-
</cart>
|
| 241 |
-
<!-- RELATED -->
|
| 242 |
-
<related>
|
| 243 |
-
<status>1</status>
|
| 244 |
-
<widget>recommendation_related</widget>
|
| 245 |
-
<min>0</min>
|
| 246 |
-
<max>3</max>
|
| 247 |
-
<scenario>product</scenario>
|
| 248 |
-
</related>
|
| 249 |
-
<!-- UPSELL -->
|
| 250 |
-
<upsell>
|
| 251 |
-
<status>1</status>
|
| 252 |
-
<widget>recommendation_upsell</widget>
|
| 253 |
-
<min>0</min>
|
| 254 |
-
<max>3</max>
|
| 255 |
-
<scenario>product</scenario>
|
| 256 |
-
</upsell>
|
| 257 |
-
</Boxalino_Recommendation>
|
| 258 |
-
</default>
|
| 259 |
-
</config>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/code/community/Boxalino/CemSearch/etc/system.xml
DELETED
|
@@ -1,775 +0,0 @@
|
|
| 1 |
-
<?xml version="1.0"?>
|
| 2 |
-
|
| 3 |
-
<config>
|
| 4 |
-
<tabs>
|
| 5 |
-
<boxalino translate="label" module="Boxalino_CemSearch">
|
| 6 |
-
<label>Boxalino Extensions</label>
|
| 7 |
-
<sort_order>100</sort_order>
|
| 8 |
-
</boxalino>
|
| 9 |
-
</tabs>
|
| 10 |
-
<sections>
|
| 11 |
-
<Boxalino_General translate="label" module="Boxalino_CemSearch">
|
| 12 |
-
<class>separator-top</class>
|
| 13 |
-
<label>Boxalino General Configuration</label>
|
| 14 |
-
<tab>boxalino</tab>
|
| 15 |
-
<frontend_type>text</frontend_type>
|
| 16 |
-
<sort_order>200</sort_order>
|
| 17 |
-
<show_in_default>1</show_in_default>
|
| 18 |
-
<show_in_website>1</show_in_website>
|
| 19 |
-
<show_in_store>1</show_in_store>
|
| 20 |
-
<groups>
|
| 21 |
-
<general translate="label">
|
| 22 |
-
<label>Boxalino General Configuration</label>
|
| 23 |
-
<frontend_type>text</frontend_type>
|
| 24 |
-
<sort_order>10</sort_order>
|
| 25 |
-
<show_in_default>1</show_in_default>
|
| 26 |
-
<show_in_website>1</show_in_website>
|
| 27 |
-
<show_in_store>1</show_in_store>
|
| 28 |
-
<fields>
|
| 29 |
-
<!-- ENABLED -->
|
| 30 |
-
<enabled translate="label">
|
| 31 |
-
<label>Enabled plugin</label>
|
| 32 |
-
<sort_order>1</sort_order>
|
| 33 |
-
<show_in_default>1</show_in_default>
|
| 34 |
-
<show_in_website>1</show_in_website>
|
| 35 |
-
<show_in_store>1</show_in_store>
|
| 36 |
-
<frontend_type>select</frontend_type>
|
| 37 |
-
<source_model>adminhtml/system_config_source_yesno</source_model>
|
| 38 |
-
</enabled>
|
| 39 |
-
<!-- MEMORY logging-->
|
| 40 |
-
<logs_saving translate="label">
|
| 41 |
-
<label>Logs Saving</label>
|
| 42 |
-
<frontend_type>text</frontend_type>
|
| 43 |
-
<sort_order>1</sort_order>
|
| 44 |
-
<show_in_default>1</show_in_default>
|
| 45 |
-
<show_in_website>0</show_in_website>
|
| 46 |
-
<show_in_store>0</show_in_store>
|
| 47 |
-
<frontend_type>select</frontend_type>
|
| 48 |
-
<source_model>adminhtml/system_config_source_yesno</source_model>
|
| 49 |
-
</logs_saving>
|
| 50 |
-
<logs_saving_frontend translate="label">
|
| 51 |
-
<label>Frontend Logs Saving</label>
|
| 52 |
-
<frontend_type>text</frontend_type>
|
| 53 |
-
<sort_order>1</sort_order>
|
| 54 |
-
<show_in_default>1</show_in_default>
|
| 55 |
-
<show_in_website>0</show_in_website>
|
| 56 |
-
<show_in_store>0</show_in_store>
|
| 57 |
-
<frontend_type>select</frontend_type>
|
| 58 |
-
<source_model>adminhtml/system_config_source_yesno</source_model>
|
| 59 |
-
</logs_saving_frontend>
|
| 60 |
-
<!-- ACCOUNT DEV -->
|
| 61 |
-
<account_dev translate="label">
|
| 62 |
-
<label>Development environment</label>
|
| 63 |
-
<frontend_type>text</frontend_type>
|
| 64 |
-
<sort_order>10</sort_order>
|
| 65 |
-
<show_in_default>1</show_in_default>
|
| 66 |
-
<show_in_website>1</show_in_website>
|
| 67 |
-
<show_in_store>0</show_in_store>
|
| 68 |
-
<frontend_type>select</frontend_type>
|
| 69 |
-
<source_model>adminhtml/system_config_source_yesno</source_model>
|
| 70 |
-
</account_dev>
|
| 71 |
-
<!-- DOMAIN -->
|
| 72 |
-
<domain translate="label">
|
| 73 |
-
<label>Domain</label>
|
| 74 |
-
<frontend_type>text</frontend_type>
|
| 75 |
-
<sort_order>20</sort_order>
|
| 76 |
-
<show_in_default>1</show_in_default>
|
| 77 |
-
<show_in_website>1</show_in_website>
|
| 78 |
-
<show_in_store>0</show_in_store>
|
| 79 |
-
<validate>required-entry</validate>
|
| 80 |
-
</domain>
|
| 81 |
-
<!-- HOST -->
|
| 82 |
-
<host translate="label">
|
| 83 |
-
<label>Host</label>
|
| 84 |
-
<frontend_type>text</frontend_type>
|
| 85 |
-
<sort_order>30</sort_order>
|
| 86 |
-
<show_in_default>1</show_in_default>
|
| 87 |
-
<show_in_website>1</show_in_website>
|
| 88 |
-
<show_in_store>0</show_in_store>
|
| 89 |
-
<validate>required-entry</validate>
|
| 90 |
-
</host>
|
| 91 |
-
<di_username translate="label">
|
| 92 |
-
<label>Data Intelligence Username</label>
|
| 93 |
-
<frontend_type>text</frontend_type>
|
| 94 |
-
<sort_order>40</sort_order>
|
| 95 |
-
<show_in_default>1</show_in_default>
|
| 96 |
-
<show_in_website>1</show_in_website>
|
| 97 |
-
<show_in_store>0</show_in_store>
|
| 98 |
-
<validate>required-entry</validate>
|
| 99 |
-
</di_username>
|
| 100 |
-
<di_password translate="label">
|
| 101 |
-
<label>Data Intelligence Password</label>
|
| 102 |
-
<frontend_type>text</frontend_type>
|
| 103 |
-
<sort_order>50</sort_order>
|
| 104 |
-
<show_in_default>1</show_in_default>
|
| 105 |
-
<show_in_website>1</show_in_website>
|
| 106 |
-
<show_in_store>0</show_in_store>
|
| 107 |
-
<validate>required-entry</validate>
|
| 108 |
-
</di_password>
|
| 109 |
-
<!-- ACCOUNT -->
|
| 110 |
-
<di_account translate="label">
|
| 111 |
-
<label>Data Intelligence Account</label>
|
| 112 |
-
<frontend_type>text</frontend_type>
|
| 113 |
-
<sort_order>60</sort_order>
|
| 114 |
-
<show_in_default>1</show_in_default>
|
| 115 |
-
<show_in_website>1</show_in_website>
|
| 116 |
-
<show_in_store>0</show_in_store>
|
| 117 |
-
<validate>required-entry</validate>
|
| 118 |
-
</di_account>
|
| 119 |
-
<!-- USERNAME -->
|
| 120 |
-
<p13n_username translate="label">
|
| 121 |
-
<label>P13n Username</label>
|
| 122 |
-
<frontend_type>text</frontend_type>
|
| 123 |
-
<sort_order>70</sort_order>
|
| 124 |
-
<show_in_default>1</show_in_default>
|
| 125 |
-
<show_in_website>1</show_in_website>
|
| 126 |
-
<show_in_store>0</show_in_store>
|
| 127 |
-
<validate>required-entry</validate>
|
| 128 |
-
</p13n_username>
|
| 129 |
-
<!-- PASSWORD -->
|
| 130 |
-
<p13n_password translate="label">
|
| 131 |
-
<label>P13n Password</label>
|
| 132 |
-
<frontend_type>text</frontend_type>
|
| 133 |
-
<sort_order>80</sort_order>
|
| 134 |
-
<show_in_default>1</show_in_default>
|
| 135 |
-
<show_in_website>1</show_in_website>
|
| 136 |
-
<show_in_store>0</show_in_store>
|
| 137 |
-
<validate>required-entry</validate>
|
| 138 |
-
</p13n_password>
|
| 139 |
-
<additional_fields>
|
| 140 |
-
<label>Return additional fields</label>
|
| 141 |
-
<frontend_type>text</frontend_type>
|
| 142 |
-
<comment><![CDATA[ Write here comma-separated names of fields from the Data Intelligence which should be returned with P13n response<br />
|
| 143 |
-
Colon separate option: global (without language version), local (with language version)]]></comment>
|
| 144 |
-
<sort_order>90</sort_order>
|
| 145 |
-
<show_in_default>1</show_in_default>
|
| 146 |
-
<show_in_website>1</show_in_website>
|
| 147 |
-
<show_in_store>0</show_in_store>
|
| 148 |
-
</additional_fields>
|
| 149 |
-
</fields>
|
| 150 |
-
</general>
|
| 151 |
-
|
| 152 |
-
<search translate="label" module="Boxalino_CemSearch">
|
| 153 |
-
<!--<label>Recommendations Widgets</label>-->
|
| 154 |
-
<label>Search Configuration</label>
|
| 155 |
-
<frontend_type>text</frontend_type>
|
| 156 |
-
<sort_order>41</sort_order>
|
| 157 |
-
<show_in_default>1</show_in_default>
|
| 158 |
-
<show_in_website>1</show_in_website>
|
| 159 |
-
<show_in_store>0</show_in_store>
|
| 160 |
-
<fields>
|
| 161 |
-
<!-- QUICK SEARCH -->
|
| 162 |
-
<quick_search translate="label">
|
| 163 |
-
<label>Quick search</label>
|
| 164 |
-
<frontend_type>text</frontend_type>
|
| 165 |
-
<sort_order>1</sort_order>
|
| 166 |
-
<show_in_default>1</show_in_default>
|
| 167 |
-
<show_in_website>1</show_in_website>
|
| 168 |
-
<show_in_store>0</show_in_store>
|
| 169 |
-
</quick_search>
|
| 170 |
-
<quick_search_limit translate="label">
|
| 171 |
-
<label>Quick search limit</label>
|
| 172 |
-
<comment><![CDATA[ 0 = without limit ]]></comment>
|
| 173 |
-
<frontend_type>text</frontend_type>
|
| 174 |
-
<sort_order>2</sort_order>
|
| 175 |
-
<show_in_default>1</show_in_default>
|
| 176 |
-
<show_in_website>1</show_in_website>
|
| 177 |
-
<show_in_store>0</show_in_store>
|
| 178 |
-
</quick_search_limit>
|
| 179 |
-
<!-- ADVANCED SEARCH -->
|
| 180 |
-
<advanced_search translate="label">
|
| 181 |
-
<label>Advanced search</label>
|
| 182 |
-
<frontend_type>text</frontend_type>
|
| 183 |
-
<sort_order>10</sort_order>
|
| 184 |
-
<show_in_default>1</show_in_default>
|
| 185 |
-
<show_in_website>1</show_in_website>
|
| 186 |
-
<show_in_store>0</show_in_store>
|
| 187 |
-
</advanced_search>
|
| 188 |
-
<advanced_search_limit translate="label">
|
| 189 |
-
<label>Advanced search limit</label>
|
| 190 |
-
<comment><![CDATA[ 0 = without limit ]]></comment>
|
| 191 |
-
<frontend_type>text</frontend_type>
|
| 192 |
-
<sort_order>11</sort_order>
|
| 193 |
-
<show_in_default>1</show_in_default>
|
| 194 |
-
<show_in_website>1</show_in_website>
|
| 195 |
-
<show_in_store>0</show_in_store>
|
| 196 |
-
</advanced_search_limit>
|
| 197 |
-
<!-- AUTOCOMPLETE -->
|
| 198 |
-
<autocomplete translate="label">
|
| 199 |
-
<label>Autocomplete</label>
|
| 200 |
-
<frontend_type>text</frontend_type>
|
| 201 |
-
<sort_order>20</sort_order>
|
| 202 |
-
<show_in_default>1</show_in_default>
|
| 203 |
-
<show_in_website>1</show_in_website>
|
| 204 |
-
<show_in_store>0</show_in_store>
|
| 205 |
-
</autocomplete>
|
| 206 |
-
<!-- AUTOCOMPLETE LIMIT-->
|
| 207 |
-
<autocomplete_limit translate="label">
|
| 208 |
-
<label>Autocomplete limit</label>
|
| 209 |
-
<frontend_type>text</frontend_type>
|
| 210 |
-
<sort_order>21</sort_order>
|
| 211 |
-
<show_in_default>1</show_in_default>
|
| 212 |
-
<show_in_website>1</show_in_website>
|
| 213 |
-
<show_in_store>0</show_in_store>
|
| 214 |
-
</autocomplete_limit>
|
| 215 |
-
<!-- AUTOCOMPLETE PRODUCTS LIMIT-->
|
| 216 |
-
<autocomplete_products_limit translate="label">
|
| 217 |
-
<label>Autocomplete products limit</label>
|
| 218 |
-
<frontend_type>text</frontend_type>
|
| 219 |
-
<sort_order>22</sort_order>
|
| 220 |
-
<show_in_default>1</show_in_default>
|
| 221 |
-
<show_in_website>1</show_in_website>
|
| 222 |
-
<show_in_store>0</show_in_store>
|
| 223 |
-
</autocomplete_products_limit>
|
| 224 |
-
<!-- Entity Id -->
|
| 225 |
-
<entity_id translate="label">
|
| 226 |
-
<label>Id field name</label>
|
| 227 |
-
<frontend_type>text</frontend_type>
|
| 228 |
-
<sort_order>30</sort_order>
|
| 229 |
-
<show_in_default>1</show_in_default>
|
| 230 |
-
<show_in_website>1</show_in_website>
|
| 231 |
-
<show_in_store>0</show_in_store>
|
| 232 |
-
</entity_id>
|
| 233 |
-
</fields>
|
| 234 |
-
</search>
|
| 235 |
-
<autocomplete_html translate="label" module="Boxalino_CemSearch">
|
| 236 |
-
<label>Autocomplete View</label>
|
| 237 |
-
<frontend_type>text</frontend_type>
|
| 238 |
-
<sort_order>45</sort_order>
|
| 239 |
-
<show_in_default>1</show_in_default>
|
| 240 |
-
<show_in_website>1</show_in_website>
|
| 241 |
-
<show_in_store>0</show_in_store>
|
| 242 |
-
<fields>
|
| 243 |
-
<enabled translate="label">
|
| 244 |
-
<label>Enable Magento logic</label>
|
| 245 |
-
<frontend_type>select</frontend_type>
|
| 246 |
-
<source_model>adminhtml/system_config_source_yesno</source_model>
|
| 247 |
-
<sort_order>10</sort_order>
|
| 248 |
-
<show_in_default>1</show_in_default>
|
| 249 |
-
<show_in_website>1</show_in_website>
|
| 250 |
-
<show_in_store>0</show_in_store>
|
| 251 |
-
</enabled>
|
| 252 |
-
<items translate="label">
|
| 253 |
-
<label>Mapping fields</label>
|
| 254 |
-
<frontend_type>text</frontend_type>
|
| 255 |
-
<comment><![CDATA[ Write here comma-separated names of fields which you want to use in autocomplete (for example: title)<br />
|
| 256 |
-
Colon separate name of attribute (left), from field name (right). <br/> Example: color:product_color<br />
|
| 257 |
-
<strong>Important</strong>: fields for product name and product url can't be change (title for product name, and url for product url ]]></comment>
|
| 258 |
-
<sort_order>20</sort_order>
|
| 259 |
-
<show_in_default>1</show_in_default>
|
| 260 |
-
<show_in_website>1</show_in_website>
|
| 261 |
-
<show_in_store>0</show_in_store>
|
| 262 |
-
</items>
|
| 263 |
-
</fields>
|
| 264 |
-
</autocomplete_html>
|
| 265 |
-
<autocomplete_extra translate="label" module="Boxalino_CemSearch">
|
| 266 |
-
<label>Autocomplete Categories Configuration</label>
|
| 267 |
-
<frontend_type>text</frontend_type>
|
| 268 |
-
<sort_order>50</sort_order>
|
| 269 |
-
<show_in_default>1</show_in_default>
|
| 270 |
-
<show_in_website>1</show_in_website>
|
| 271 |
-
<show_in_store>0</show_in_store>
|
| 272 |
-
<fields>
|
| 273 |
-
<enabled translate="label">
|
| 274 |
-
<label>Enable autocomplete categories</label>
|
| 275 |
-
<frontend_type>select</frontend_type>
|
| 276 |
-
<source_model>adminhtml/system_config_source_yesno</source_model>
|
| 277 |
-
<sort_order>10</sort_order>
|
| 278 |
-
<show_in_default>1</show_in_default>
|
| 279 |
-
<show_in_website>1</show_in_website>
|
| 280 |
-
<show_in_store>0</show_in_store>
|
| 281 |
-
</enabled>
|
| 282 |
-
<enabled_for_all translate="label">
|
| 283 |
-
<label>Display for all term</label>
|
| 284 |
-
<frontend_type>select</frontend_type>
|
| 285 |
-
<source_model>adminhtml/system_config_source_yesno</source_model>
|
| 286 |
-
<comment><![CDATA[ If no, then display categories for the first term only. <br /> If yes, then display categories for all terms. ]]></comment>
|
| 287 |
-
<sort_order>20</sort_order>
|
| 288 |
-
<show_in_default>1</show_in_default>
|
| 289 |
-
<show_in_website>1</show_in_website>
|
| 290 |
-
<show_in_store>0</show_in_store>
|
| 291 |
-
</enabled_for_all>
|
| 292 |
-
<items translate="label">
|
| 293 |
-
<label>Number of categories per term</label>
|
| 294 |
-
<frontend_type>text</frontend_type>
|
| 295 |
-
<sort_order>30</sort_order>
|
| 296 |
-
<show_in_default>1</show_in_default>
|
| 297 |
-
<show_in_website>1</show_in_website>
|
| 298 |
-
<show_in_store>0</show_in_store>
|
| 299 |
-
</items>
|
| 300 |
-
<sort translate="label">
|
| 301 |
-
<label>Sorting by products quantity</label>
|
| 302 |
-
<frontend_type>select</frontend_type>
|
| 303 |
-
<source_model>adminhtml/system_config_source_yesno</source_model>
|
| 304 |
-
<comment><![CDATA[ If yes, then sort by number of products. ]]></comment>
|
| 305 |
-
<sort_order>40</sort_order>
|
| 306 |
-
<show_in_default>1</show_in_default>
|
| 307 |
-
<show_in_website>1</show_in_website>
|
| 308 |
-
<show_in_store>0</show_in_store>
|
| 309 |
-
</sort>
|
| 310 |
-
<products translate="label">
|
| 311 |
-
<label>Enable product preview for categories</label>
|
| 312 |
-
<frontend_type>select</frontend_type>
|
| 313 |
-
<source_model>adminhtml/system_config_source_yesno</source_model>
|
| 314 |
-
<sort_order>50</sort_order>
|
| 315 |
-
<show_in_default>1</show_in_default>
|
| 316 |
-
<show_in_website>1</show_in_website>
|
| 317 |
-
<show_in_store>0</show_in_store>
|
| 318 |
-
</products>
|
| 319 |
-
</fields>
|
| 320 |
-
</autocomplete_extra>
|
| 321 |
-
<search_suggestions translate="label" module="Boxalino_CemSearch">
|
| 322 |
-
<label>Search Suggestions Configuration</label>
|
| 323 |
-
<frontend_type>text</frontend_type>
|
| 324 |
-
<sort_order>52</sort_order>
|
| 325 |
-
<show_in_default>1</show_in_default>
|
| 326 |
-
<show_in_website>1</show_in_website>
|
| 327 |
-
<show_in_store>0</show_in_store>
|
| 328 |
-
<fields>
|
| 329 |
-
<enabled translate="label">
|
| 330 |
-
<label>Enable search suggestion</label>
|
| 331 |
-
<frontend_type>select</frontend_type>
|
| 332 |
-
<source_model>adminhtml/system_config_source_yesno</source_model>
|
| 333 |
-
<sort_order>10</sort_order>
|
| 334 |
-
<show_in_default>1</show_in_default>
|
| 335 |
-
<show_in_website>1</show_in_website>
|
| 336 |
-
<show_in_store>0</show_in_store>
|
| 337 |
-
</enabled>
|
| 338 |
-
<min translate="label">
|
| 339 |
-
<label>Minimum for range</label>
|
| 340 |
-
<frontend_type>text</frontend_type>
|
| 341 |
-
<comment><![CDATA[ Display suggestion, when quantity of products is fewer than this value ]]></comment>
|
| 342 |
-
<sort_order>20</sort_order>
|
| 343 |
-
<show_in_default>1</show_in_default>
|
| 344 |
-
<show_in_website>1</show_in_website>
|
| 345 |
-
<show_in_store>0</show_in_store>
|
| 346 |
-
</min>
|
| 347 |
-
<max translate="label">
|
| 348 |
-
<label>Maximum for range</label>
|
| 349 |
-
<frontend_type>text</frontend_type>
|
| 350 |
-
<comment><![CDATA[ Display suggestion, when quantity of products is more than this value ]]></comment>
|
| 351 |
-
<sort_order>30</sort_order>
|
| 352 |
-
<show_in_default>1</show_in_default>
|
| 353 |
-
<show_in_website>1</show_in_website>
|
| 354 |
-
<show_in_store>0</show_in_store>
|
| 355 |
-
</max>
|
| 356 |
-
<display translate="label">
|
| 357 |
-
<label>Maximum number of suggestions</label>
|
| 358 |
-
<frontend_type>text</frontend_type>
|
| 359 |
-
<sort_order>40</sort_order>
|
| 360 |
-
<show_in_default>1</show_in_default>
|
| 361 |
-
<show_in_website>1</show_in_website>
|
| 362 |
-
<show_in_store>0</show_in_store>
|
| 363 |
-
</display>
|
| 364 |
-
<sort translate="label">
|
| 365 |
-
<label>Sorting by products quantity</label>
|
| 366 |
-
<frontend_type>select</frontend_type>
|
| 367 |
-
<source_model>adminhtml/system_config_source_yesno</source_model>
|
| 368 |
-
<comment><![CDATA[ If no, then sort by name ]]></comment>
|
| 369 |
-
<sort_order>50</sort_order>
|
| 370 |
-
<show_in_default>1</show_in_default>
|
| 371 |
-
<show_in_website>1</show_in_website>
|
| 372 |
-
<show_in_store>0</show_in_store>
|
| 373 |
-
</sort>
|
| 374 |
-
</fields>
|
| 375 |
-
</search_suggestions>
|
| 376 |
-
<search_relaxation translate="label" module="Boxalino_CemSearch">
|
| 377 |
-
<label>Search Relaxation Configuration</label>
|
| 378 |
-
<frontend_type>text</frontend_type>
|
| 379 |
-
<sort_order>55</sort_order>
|
| 380 |
-
<show_in_default>1</show_in_default>
|
| 381 |
-
<show_in_website>1</show_in_website>
|
| 382 |
-
<show_in_store>0</show_in_store>
|
| 383 |
-
<fields>
|
| 384 |
-
<enabled translate="label">
|
| 385 |
-
<label>Enable search relaxation</label>
|
| 386 |
-
<frontend_type>select</frontend_type>
|
| 387 |
-
<source_model>adminhtml/system_config_source_yesno</source_model>
|
| 388 |
-
<sort_order>1</sort_order>
|
| 389 |
-
<show_in_default>1</show_in_default>
|
| 390 |
-
<show_in_website>1</show_in_website>
|
| 391 |
-
<show_in_store>0</show_in_store>
|
| 392 |
-
</enabled>
|
| 393 |
-
<max translate="label">
|
| 394 |
-
<label>Maximum for quantity of products</label>
|
| 395 |
-
<frontend_type>text</frontend_type>
|
| 396 |
-
<comment><![CDATA[ Display relaxation, when quantity of products is less than this value ]]></comment>
|
| 397 |
-
<sort_order>10</sort_order>
|
| 398 |
-
<show_in_default>1</show_in_default>
|
| 399 |
-
<show_in_website>1</show_in_website>
|
| 400 |
-
<show_in_store>0</show_in_store>
|
| 401 |
-
</max>
|
| 402 |
-
<relaxations>
|
| 403 |
-
<label>Maximum of relaxations</label>
|
| 404 |
-
<frontend_type>text</frontend_type>
|
| 405 |
-
<sort_order>20</sort_order>
|
| 406 |
-
<show_in_default>1</show_in_default>
|
| 407 |
-
<show_in_website>1</show_in_website>
|
| 408 |
-
<show_in_store>0</show_in_store>
|
| 409 |
-
</relaxations>
|
| 410 |
-
<products>
|
| 411 |
-
<label>Maximum of products for relaxation</label>
|
| 412 |
-
<frontend_type>text</frontend_type>
|
| 413 |
-
<sort_order>30</sort_order>
|
| 414 |
-
<show_in_default>1</show_in_default>
|
| 415 |
-
<show_in_website>1</show_in_website>
|
| 416 |
-
<show_in_store>0</show_in_store>
|
| 417 |
-
</products>
|
| 418 |
-
</fields>
|
| 419 |
-
</search_relaxation>
|
| 420 |
-
<filter translate="label" module="Boxalino_CemSearch">
|
| 421 |
-
<label>Filters Configuration</label>
|
| 422 |
-
<frontend_type>text</frontend_type>
|
| 423 |
-
<sort_order>60</sort_order>
|
| 424 |
-
<show_in_default>1</show_in_default>
|
| 425 |
-
<show_in_website>1</show_in_website>
|
| 426 |
-
<show_in_store>1</show_in_store>
|
| 427 |
-
<fields>
|
| 428 |
-
<left_filters_enable translate="label">
|
| 429 |
-
<label>Enable filters (left side)</label>
|
| 430 |
-
<frontend_type>select</frontend_type>
|
| 431 |
-
<source_model>adminhtml/system_config_source_yesno</source_model>
|
| 432 |
-
<sort_order>39</sort_order>
|
| 433 |
-
<show_in_default>1</show_in_default>
|
| 434 |
-
<show_in_website>1</show_in_website>
|
| 435 |
-
<show_in_store>0</show_in_store>
|
| 436 |
-
</left_filters_enable>
|
| 437 |
-
<left_filters_multioption translate="label">
|
| 438 |
-
<label>Left filters multioption</label>
|
| 439 |
-
<frontend_type>select</frontend_type>
|
| 440 |
-
<source_model>adminhtml/system_config_source_yesno</source_model>
|
| 441 |
-
<sort_order>40</sort_order>
|
| 442 |
-
<show_in_default>1</show_in_default>
|
| 443 |
-
<show_in_website>1</show_in_website>
|
| 444 |
-
<show_in_store>0</show_in_store>
|
| 445 |
-
</left_filters_multioption>
|
| 446 |
-
<left_filters_normal translate="label">
|
| 447 |
-
<label>Normal filters (left side)</label>
|
| 448 |
-
<frontend_type>text</frontend_type>
|
| 449 |
-
<comment><![CDATA[ Write here comma-separated names of fields which you want to use as filters (for example: manufacturer)<br />
|
| 450 |
-
Colon separate name of field (left) from option (middle), and order (right). <br/> For order: 0 - alphabetical, 1 - count ]]></comment>
|
| 451 |
-
<sort_order>50</sort_order>
|
| 452 |
-
<show_in_default>1</show_in_default>
|
| 453 |
-
<show_in_website>1</show_in_website>
|
| 454 |
-
<show_in_store>0</show_in_store>
|
| 455 |
-
</left_filters_normal>
|
| 456 |
-
<left_filters_normal_title translate="label">
|
| 457 |
-
<label>Normal filters titles (left side)</label>
|
| 458 |
-
<frontend_type>text</frontend_type>
|
| 459 |
-
<comment>Write here comma-separated titles which should be displayed on page (in same order as names of fields)</comment>
|
| 460 |
-
<sort_order>51</sort_order>
|
| 461 |
-
<show_in_default>1</show_in_default>
|
| 462 |
-
<show_in_website>1</show_in_website>
|
| 463 |
-
<show_in_store>1</show_in_store>
|
| 464 |
-
</left_filters_normal_title>
|
| 465 |
-
<top_filters_enable translate="label">
|
| 466 |
-
<label>Enable top filters</label>
|
| 467 |
-
<frontend_type>select</frontend_type>
|
| 468 |
-
<source_model>adminhtml/system_config_source_yesno</source_model>
|
| 469 |
-
<sort_order>58</sort_order>
|
| 470 |
-
<show_in_default>1</show_in_default>
|
| 471 |
-
<show_in_website>1</show_in_website>
|
| 472 |
-
<show_in_store>0</show_in_store>
|
| 473 |
-
</top_filters_enable>
|
| 474 |
-
<top_filters_multioption translate="label">
|
| 475 |
-
<label>Top filters multioption</label>
|
| 476 |
-
<frontend_type>select</frontend_type>
|
| 477 |
-
<source_model>adminhtml/system_config_source_yesno</source_model>
|
| 478 |
-
<sort_order>59</sort_order>
|
| 479 |
-
<show_in_default>1</show_in_default>
|
| 480 |
-
<show_in_website>1</show_in_website>
|
| 481 |
-
<show_in_store>0</show_in_store>
|
| 482 |
-
</top_filters_multioption>
|
| 483 |
-
<top_filters translate="label">
|
| 484 |
-
<label>Top filters</label>
|
| 485 |
-
<frontend_type>text</frontend_type>
|
| 486 |
-
<comment>Write here comma-separated names of fields which you want to use as top filters</comment>
|
| 487 |
-
<sort_order>60</sort_order>
|
| 488 |
-
<show_in_default>1</show_in_default>
|
| 489 |
-
<show_in_website>1</show_in_website>
|
| 490 |
-
<show_in_store>0</show_in_store>
|
| 491 |
-
</top_filters>
|
| 492 |
-
<top_filters_title translate="label">
|
| 493 |
-
<label>Top filters titles</label>
|
| 494 |
-
<frontend_type>text</frontend_type>
|
| 495 |
-
<comment>Write here comma-separated titles which should be displayed on page (in same order as names of fields)</comment>
|
| 496 |
-
<sort_order>61</sort_order>
|
| 497 |
-
<show_in_default>1</show_in_default>
|
| 498 |
-
<show_in_website>1</show_in_website>
|
| 499 |
-
<show_in_store>1</show_in_store>
|
| 500 |
-
</top_filters_title>
|
| 501 |
-
</fields>
|
| 502 |
-
</filter>
|
| 503 |
-
<tracker translate="label" module="Boxalino_CemSearch">
|
| 504 |
-
<label>Tracking</label>
|
| 505 |
-
<frontend_type>text</frontend_type>
|
| 506 |
-
<sort_order>70</sort_order>
|
| 507 |
-
<show_in_default>1</show_in_default>
|
| 508 |
-
<show_in_website>1</show_in_website>
|
| 509 |
-
<show_in_store>1</show_in_store>
|
| 510 |
-
<fields>
|
| 511 |
-
<enabled translate="label">
|
| 512 |
-
<label>Enable plugin</label>
|
| 513 |
-
<frontend_type>select</frontend_type>
|
| 514 |
-
<source_model>adminhtml/system_config_source_yesno</source_model>
|
| 515 |
-
<sort_order>1</sort_order>
|
| 516 |
-
<show_in_default>1</show_in_default>
|
| 517 |
-
<show_in_website>1</show_in_website>
|
| 518 |
-
<show_in_store>0</show_in_store>
|
| 519 |
-
</enabled>
|
| 520 |
-
<track_sales translate="label">
|
| 521 |
-
<label>Enable Sales Tracking</label>
|
| 522 |
-
<frontend_type>select</frontend_type>
|
| 523 |
-
<source_model>adminhtml/system_config_source_yesno</source_model>
|
| 524 |
-
<sort_order>2</sort_order>
|
| 525 |
-
<show_in_default>1</show_in_default>
|
| 526 |
-
<show_in_website>1</show_in_website>
|
| 527 |
-
<show_in_store>0</show_in_store>
|
| 528 |
-
</track_sales>
|
| 529 |
-
<analytics translate="label">
|
| 530 |
-
<label>Enable Analytics</label>
|
| 531 |
-
<frontend_type>select</frontend_type>
|
| 532 |
-
<source_model>adminhtml/system_config_source_yesno</source_model>
|
| 533 |
-
<sort_order>3</sort_order>
|
| 534 |
-
<show_in_default>1</show_in_default>
|
| 535 |
-
<show_in_website>1</show_in_website>
|
| 536 |
-
<show_in_store>0</show_in_store>
|
| 537 |
-
</analytics>
|
| 538 |
-
<charset translate="label">
|
| 539 |
-
<label>Character encoding</label>
|
| 540 |
-
<frontend_type>text</frontend_type>
|
| 541 |
-
<sort_order>20</sort_order>
|
| 542 |
-
<show_in_default>1</show_in_default>
|
| 543 |
-
<show_in_website>1</show_in_website>
|
| 544 |
-
<show_in_store>0</show_in_store>
|
| 545 |
-
</charset>
|
| 546 |
-
</fields>
|
| 547 |
-
</tracker>
|
| 548 |
-
<jquery translate="label" module="Boxalino_CemSearch">
|
| 549 |
-
<label>jQuery Configuration</label>
|
| 550 |
-
<frontend_type>text</frontend_type>
|
| 551 |
-
<sort_order>80</sort_order>
|
| 552 |
-
<show_in_default>1</show_in_default>
|
| 553 |
-
<show_in_website>1</show_in_website>
|
| 554 |
-
<show_in_store>0</show_in_store>
|
| 555 |
-
<fields>
|
| 556 |
-
<jquery_file translate="label">
|
| 557 |
-
<label>Load jQuery File</label>
|
| 558 |
-
<frontend_type>select</frontend_type>
|
| 559 |
-
<source_model>adminhtml/system_config_source_yesno</source_model>
|
| 560 |
-
<sort_order>1</sort_order>
|
| 561 |
-
<show_in_default>1</show_in_default>
|
| 562 |
-
<show_in_website>1</show_in_website>
|
| 563 |
-
<show_in_store>0</show_in_store>
|
| 564 |
-
</jquery_file>
|
| 565 |
-
<noconflict_file translate="label">
|
| 566 |
-
<label>Load jQuery noConflict File</label>
|
| 567 |
-
<frontend_type>select</frontend_type>
|
| 568 |
-
<source_model>adminhtml/system_config_source_yesno</source_model>
|
| 569 |
-
<sort_order>2</sort_order>
|
| 570 |
-
<show_in_default>1</show_in_default>
|
| 571 |
-
<show_in_website>1</show_in_website>
|
| 572 |
-
<show_in_store>0</show_in_store>
|
| 573 |
-
</noconflict_file>
|
| 574 |
-
</fields>
|
| 575 |
-
</jquery>
|
| 576 |
-
</groups>
|
| 577 |
-
</Boxalino_General>
|
| 578 |
-
|
| 579 |
-
<Boxalino_Recommendation translate="label" module="Boxalino_CemSearch">
|
| 580 |
-
<class>separator-top</class>
|
| 581 |
-
<label>Boxalino Recommendation</label>
|
| 582 |
-
<tab>boxalino</tab>
|
| 583 |
-
<frontend_type>text</frontend_type>
|
| 584 |
-
<sort_order>300</sort_order>
|
| 585 |
-
<show_in_default>1</show_in_default>
|
| 586 |
-
<show_in_website>1</show_in_website>
|
| 587 |
-
<show_in_store>1</show_in_store>
|
| 588 |
-
<groups>
|
| 589 |
-
<!-- CART -->
|
| 590 |
-
<cart translate="label" module="Boxalino_CemSearch">
|
| 591 |
-
<label>Cart Configuration</label>
|
| 592 |
-
<comment><![CDATA[ Widget configuration for recommendation on basket page. ]]></comment>
|
| 593 |
-
<frontend_type>text</frontend_type>
|
| 594 |
-
<sort_order>100</sort_order>
|
| 595 |
-
<show_in_default>1</show_in_default>
|
| 596 |
-
<show_in_website>1</show_in_website>
|
| 597 |
-
<show_in_store>0</show_in_store>
|
| 598 |
-
<fields>
|
| 599 |
-
<!-- STATUS -->
|
| 600 |
-
<status translate="label">
|
| 601 |
-
<label>Widgets enabled</label>
|
| 602 |
-
<frontend_type>text</frontend_type>
|
| 603 |
-
<sort_order>10</sort_order>
|
| 604 |
-
<show_in_default>1</show_in_default>
|
| 605 |
-
<show_in_website>1</show_in_website>
|
| 606 |
-
<show_in_store>0</show_in_store>
|
| 607 |
-
<frontend_type>select</frontend_type>
|
| 608 |
-
<source_model>adminhtml/system_config_source_yesno</source_model>
|
| 609 |
-
</status>
|
| 610 |
-
<!-- WIDGET NAME -->
|
| 611 |
-
<widget translate="label">
|
| 612 |
-
<label>Widget name</label>
|
| 613 |
-
<frontend_type>text</frontend_type>
|
| 614 |
-
<sort_order>12</sort_order>
|
| 615 |
-
<show_in_default>1</show_in_default>
|
| 616 |
-
<show_in_website>1</show_in_website>
|
| 617 |
-
<show_in_store>0</show_in_store>
|
| 618 |
-
</widget>
|
| 619 |
-
<!-- MINIMUM -->
|
| 620 |
-
<min translate="label">
|
| 621 |
-
<label>Minimum recommendations</label>
|
| 622 |
-
<frontend_type>text</frontend_type>
|
| 623 |
-
<sort_order>16</sort_order>
|
| 624 |
-
<show_in_default>1</show_in_default>
|
| 625 |
-
<show_in_website>1</show_in_website>
|
| 626 |
-
<show_in_store>0</show_in_store>
|
| 627 |
-
</min>
|
| 628 |
-
<!-- MAXIMUM -->
|
| 629 |
-
<max translate="label">
|
| 630 |
-
<label>Maximum recommendations</label>
|
| 631 |
-
<frontend_type>text</frontend_type>
|
| 632 |
-
<sort_order>18</sort_order>
|
| 633 |
-
<show_in_default>1</show_in_default>
|
| 634 |
-
<show_in_website>1</show_in_website>
|
| 635 |
-
<show_in_store>0</show_in_store>
|
| 636 |
-
</max>
|
| 637 |
-
<!-- SCENARIO -->
|
| 638 |
-
<scenario translate="label">
|
| 639 |
-
<label>Scenario</label>
|
| 640 |
-
<frontend_type>text</frontend_type>
|
| 641 |
-
<sort_order>20</sort_order>
|
| 642 |
-
<show_in_default>1</show_in_default>
|
| 643 |
-
<show_in_website>1</show_in_website>
|
| 644 |
-
<show_in_store>0</show_in_store>
|
| 645 |
-
</scenario>
|
| 646 |
-
</fields>
|
| 647 |
-
</cart>
|
| 648 |
-
<!-- CART END -->
|
| 649 |
-
<!-- RELATED -->
|
| 650 |
-
<related translate="label" module="Boxalino_CemSearch">
|
| 651 |
-
<label>Related Configuration</label>
|
| 652 |
-
<comment><![CDATA[ Widget configuration for related recommendation on product page. ]]></comment>
|
| 653 |
-
<frontend_type>text</frontend_type>
|
| 654 |
-
<sort_order>200</sort_order>
|
| 655 |
-
<show_in_default>1</show_in_default>
|
| 656 |
-
<show_in_website>1</show_in_website>
|
| 657 |
-
<show_in_store>0</show_in_store>
|
| 658 |
-
<fields>
|
| 659 |
-
<!-- STATUS -->
|
| 660 |
-
<status translate="label">
|
| 661 |
-
<label>Widget enabled</label>
|
| 662 |
-
<frontend_type>text</frontend_type>
|
| 663 |
-
<sort_order>20</sort_order>
|
| 664 |
-
<show_in_default>1</show_in_default>
|
| 665 |
-
<show_in_website>1</show_in_website>
|
| 666 |
-
<show_in_store>0</show_in_store>
|
| 667 |
-
<frontend_type>select</frontend_type>
|
| 668 |
-
<source_model>adminhtml/system_config_source_yesno</source_model>
|
| 669 |
-
</status>
|
| 670 |
-
<!-- WIDGET NAME -->
|
| 671 |
-
<widget translate="label">
|
| 672 |
-
<label>Widgets name</label>
|
| 673 |
-
<frontend_type>text</frontend_type>
|
| 674 |
-
<sort_order>22</sort_order>
|
| 675 |
-
<show_in_default>1</show_in_default>
|
| 676 |
-
<show_in_website>1</show_in_website>
|
| 677 |
-
<show_in_store>0</show_in_store>
|
| 678 |
-
</widget>
|
| 679 |
-
<!-- MINIMUM -->
|
| 680 |
-
<min translate="label">
|
| 681 |
-
<label>Minimum recommendations</label>
|
| 682 |
-
<frontend_type>text</frontend_type>
|
| 683 |
-
<sort_order>26</sort_order>
|
| 684 |
-
<show_in_default>1</show_in_default>
|
| 685 |
-
<show_in_website>1</show_in_website>
|
| 686 |
-
<show_in_store>0</show_in_store>
|
| 687 |
-
</min>
|
| 688 |
-
<!-- MAXIMUM -->
|
| 689 |
-
<max translate="label">
|
| 690 |
-
<label>Maximum recommendations</label>
|
| 691 |
-
<frontend_type>text</frontend_type>
|
| 692 |
-
<sort_order>28</sort_order>
|
| 693 |
-
<show_in_default>1</show_in_default>
|
| 694 |
-
<show_in_website>1</show_in_website>
|
| 695 |
-
<show_in_store>0</show_in_store>
|
| 696 |
-
</max>
|
| 697 |
-
<!-- SCENARIO -->
|
| 698 |
-
<scenario translate="label">
|
| 699 |
-
<label>Scenario</label>
|
| 700 |
-
<frontend_type>text</frontend_type>
|
| 701 |
-
<sort_order>30</sort_order>
|
| 702 |
-
<show_in_default>1</show_in_default>
|
| 703 |
-
<show_in_website>1</show_in_website>
|
| 704 |
-
<show_in_store>0</show_in_store>
|
| 705 |
-
</scenario>
|
| 706 |
-
</fields>
|
| 707 |
-
</related>
|
| 708 |
-
<!-- RELATED END -->
|
| 709 |
-
|
| 710 |
-
<!-- UPSELL -->
|
| 711 |
-
<upsell translate="label" module="Boxalino_CemSearch">
|
| 712 |
-
<label>Upsell Configuration</label>
|
| 713 |
-
<comment><![CDATA[ Widget configuration for upsell recommendation on product page. ]]></comment>
|
| 714 |
-
<frontend_type>text</frontend_type>
|
| 715 |
-
<sort_order>300</sort_order>
|
| 716 |
-
<show_in_default>1</show_in_default>
|
| 717 |
-
<show_in_website>1</show_in_website>
|
| 718 |
-
<show_in_store>0</show_in_store>
|
| 719 |
-
<fields>
|
| 720 |
-
<!-- STATUS -->
|
| 721 |
-
<status translate="label">
|
| 722 |
-
<label>Widgets enabled</label>
|
| 723 |
-
<frontend_type>text</frontend_type>
|
| 724 |
-
<sort_order>30</sort_order>
|
| 725 |
-
<show_in_default>1</show_in_default>
|
| 726 |
-
<show_in_website>1</show_in_website>
|
| 727 |
-
<show_in_store>0</show_in_store>
|
| 728 |
-
<frontend_type>select</frontend_type>
|
| 729 |
-
<source_model>adminhtml/system_config_source_yesno</source_model>
|
| 730 |
-
</status>
|
| 731 |
-
<!-- WIDGET NAME -->
|
| 732 |
-
<widget translate="label">
|
| 733 |
-
<label>Widget name</label>
|
| 734 |
-
<frontend_type>text</frontend_type>
|
| 735 |
-
<sort_order>32</sort_order>
|
| 736 |
-
<show_in_default>1</show_in_default>
|
| 737 |
-
<show_in_website>1</show_in_website>
|
| 738 |
-
<show_in_store>0</show_in_store>
|
| 739 |
-
</widget>
|
| 740 |
-
<!-- MINIMUM -->
|
| 741 |
-
<min translate="label">
|
| 742 |
-
<label>Minimum recommendations</label>
|
| 743 |
-
<frontend_type>text</frontend_type>
|
| 744 |
-
<sort_order>36</sort_order>
|
| 745 |
-
<show_in_default>1</show_in_default>
|
| 746 |
-
<show_in_website>1</show_in_website>
|
| 747 |
-
<show_in_store>0</show_in_store>
|
| 748 |
-
</min>
|
| 749 |
-
<!-- MAXIMUM -->
|
| 750 |
-
<max translate="label">
|
| 751 |
-
<label>Maximum recommendations</label>
|
| 752 |
-
<frontend_type>text</frontend_type>
|
| 753 |
-
<sort_order>38</sort_order>
|
| 754 |
-
<show_in_default>1</show_in_default>
|
| 755 |
-
<show_in_website>1</show_in_website>
|
| 756 |
-
<show_in_store>0</show_in_store>
|
| 757 |
-
</max>
|
| 758 |
-
<!-- SCENARIO -->
|
| 759 |
-
<scenario translate="label">
|
| 760 |
-
<label>Scenario</label>
|
| 761 |
-
<frontend_type>text</frontend_type>
|
| 762 |
-
<sort_order>40</sort_order>
|
| 763 |
-
<show_in_default>1</show_in_default>
|
| 764 |
-
<show_in_website>1</show_in_website>
|
| 765 |
-
<show_in_store>0</show_in_store>
|
| 766 |
-
</scenario>
|
| 767 |
-
</fields>
|
| 768 |
-
</upsell>
|
| 769 |
-
<!-- UPSELL END -->
|
| 770 |
-
</groups>
|
| 771 |
-
</Boxalino_Recommendation>
|
| 772 |
-
|
| 773 |
-
</sections>
|
| 774 |
-
|
| 775 |
-
</config>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/code/community/Boxalino/Exporter/Helper/Data.php
DELETED
|
@@ -1,205 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
|
| 3 |
-
class Boxalino_Exporter_Helper_Data extends Mage_Core_Helper_Data
|
| 4 |
-
{
|
| 5 |
-
const URL_XML = '/frontend/dbmind/en/dbmind/api/data/source/update';
|
| 6 |
-
const URL_XML_DEV = '/frontend/dbmind/en/dbmind/api/data/source/update?dev=true';
|
| 7 |
-
const URL_ZIP = '/frontend/dbmind/en/dbmind/api/data/push';
|
| 8 |
-
const URL_ZIP_DEV = '/frontend/dbmind/en/dbmind/api/data/push?dev=true';
|
| 9 |
-
public $exportServer = '';
|
| 10 |
-
public $XML_DELIMITER = ',';
|
| 11 |
-
public $XML_ENCLOSURE = '"';
|
| 12 |
-
public $XML_ENCLOSURE_TEXT = """; // it's $XML_ENCLOSURE
|
| 13 |
-
public $XML_NEWLINE = '\n';
|
| 14 |
-
public $XML_ESCAPE = '\\\\';
|
| 15 |
-
public $XML_ENCODE = 'UTF-8';
|
| 16 |
-
public $XML_FORMAT = 'CSV';
|
| 17 |
-
protected $_attributesWithIds = array();
|
| 18 |
-
protected $_allTags = array();
|
| 19 |
-
protected $_countries = array();
|
| 20 |
-
protected $_languages = array(
|
| 21 |
-
'en',
|
| 22 |
-
'fr',
|
| 23 |
-
'de',
|
| 24 |
-
'it',
|
| 25 |
-
'es',
|
| 26 |
-
'zh',
|
| 27 |
-
'cz',
|
| 28 |
-
'ru',
|
| 29 |
-
);
|
| 30 |
-
|
| 31 |
-
/**
|
| 32 |
-
* @param $language
|
| 33 |
-
* @return bool
|
| 34 |
-
*/
|
| 35 |
-
public function isAvailableLanguages($language)
|
| 36 |
-
{
|
| 37 |
-
if (array_search($language, $this->_languages) !== false) {
|
| 38 |
-
return true;
|
| 39 |
-
}
|
| 40 |
-
return false;
|
| 41 |
-
}
|
| 42 |
-
|
| 43 |
-
public function getExportServer()
|
| 44 |
-
{
|
| 45 |
-
if (empty($this->exportServer)) {
|
| 46 |
-
$this->exportServer = Mage::getStoreConfig('boxalinoexporter/export_data/export_server');
|
| 47 |
-
}
|
| 48 |
-
|
| 49 |
-
return $this->exportServer;
|
| 50 |
-
}
|
| 51 |
-
|
| 52 |
-
/**
|
| 53 |
-
* @return array Return array with attributes which have connect optionId = optionValue
|
| 54 |
-
*/
|
| 55 |
-
public function attributesWithIds()
|
| 56 |
-
{
|
| 57 |
-
if (empty($this->_attributesWithIds)) {
|
| 58 |
-
$attributes = Mage::getResourceModel('eav/entity_attribute_collection')->getData();
|
| 59 |
-
foreach ($attributes as $attribute) {
|
| 60 |
-
if ($attribute['frontend_input'] == 'select' || $attribute['frontend_input'] == 'multiselect') {
|
| 61 |
-
$this->_attributesWithIds[] = $attribute['attribute_code'];
|
| 62 |
-
}
|
| 63 |
-
}
|
| 64 |
-
$attributes = null;
|
| 65 |
-
}
|
| 66 |
-
return $this->_attributesWithIds;
|
| 67 |
-
}
|
| 68 |
-
|
| 69 |
-
/**
|
| 70 |
-
* @return array Array of all tags array('tag_id' => 'value');
|
| 71 |
-
*/
|
| 72 |
-
public function getAllTags()
|
| 73 |
-
{
|
| 74 |
-
if (empty($this->_allTags)) {
|
| 75 |
-
$tagsModel = Mage::getModel('tag/tag');
|
| 76 |
-
$tags = $tagsModel->getCollection()->addStatusFilter($tagsModel->getApprovedStatus())->getData();
|
| 77 |
-
foreach ($tags as $tag) {
|
| 78 |
-
$this->_allTags[$tag['tag_id']] = $tag['name'];
|
| 79 |
-
}
|
| 80 |
-
$tags = null;
|
| 81 |
-
$tagsModel = null;
|
| 82 |
-
}
|
| 83 |
-
|
| 84 |
-
return $this->_allTags;
|
| 85 |
-
}
|
| 86 |
-
|
| 87 |
-
/**
|
| 88 |
-
* @return string URL to normal data sync
|
| 89 |
-
* @param $dev
|
| 90 |
-
*/
|
| 91 |
-
public function getZIPSyncUrl($dev = false)
|
| 92 |
-
{
|
| 93 |
-
$exportServer = $this->getExportServer();
|
| 94 |
-
if ($dev) {
|
| 95 |
-
return $exportServer . self::URL_ZIP_DEV;
|
| 96 |
-
} else {
|
| 97 |
-
return $exportServer . self::URL_ZIP;
|
| 98 |
-
}
|
| 99 |
-
}
|
| 100 |
-
|
| 101 |
-
/**
|
| 102 |
-
* @return string URL to delta sync
|
| 103 |
-
* @param $dev
|
| 104 |
-
*/
|
| 105 |
-
public function getXMLSyncUrl($dev = false)
|
| 106 |
-
{
|
| 107 |
-
$exportServer = $this->getExportServer();
|
| 108 |
-
if ($dev) {
|
| 109 |
-
return $exportServer . self::URL_XML_DEV;
|
| 110 |
-
} else {
|
| 111 |
-
return $exportServer . self::URL_XML;
|
| 112 |
-
}
|
| 113 |
-
|
| 114 |
-
}
|
| 115 |
-
|
| 116 |
-
public function getError($responseBody)
|
| 117 |
-
{
|
| 118 |
-
$htmlTagsToReplace = array('body', 'p', 'br');
|
| 119 |
-
$startPosition = strpos($responseBody, '<p>');
|
| 120 |
-
$endPosition = strpos($responseBody, '<br>') + 3;
|
| 121 |
-
$error = html_entity_decode(substr($responseBody, $startPosition, $endPosition));
|
| 122 |
-
foreach ($htmlTagsToReplace as $tag) {
|
| 123 |
-
$error = str_replace('<' . $tag . '>', PHP_EOL, $error);
|
| 124 |
-
}
|
| 125 |
-
return $error;
|
| 126 |
-
}
|
| 127 |
-
|
| 128 |
-
public function getCountry($countryCode)
|
| 129 |
-
{
|
| 130 |
-
|
| 131 |
-
if (!isset($this->_countries[$countryCode])) {
|
| 132 |
-
$country = Mage::getModel('directory/country')->loadByCode($countryCode);
|
| 133 |
-
$this->_countries[$countryCode] = $country;
|
| 134 |
-
}
|
| 135 |
-
|
| 136 |
-
return $this->_countries[$countryCode];
|
| 137 |
-
}
|
| 138 |
-
|
| 139 |
-
/**
|
| 140 |
-
* Modifies a string to remove all non ASCII characters and spaces.
|
| 141 |
-
*/
|
| 142 |
-
public function sanitizeFieldName($text)
|
| 143 |
-
{
|
| 144 |
-
|
| 145 |
-
$maxLength = 50;
|
| 146 |
-
$delimiter = "_";
|
| 147 |
-
|
| 148 |
-
// replace non letter or digits by -
|
| 149 |
-
$text = preg_replace('~[^\\pL\d]+~u', $delimiter, $text);
|
| 150 |
-
|
| 151 |
-
// trim
|
| 152 |
-
$text = trim($text, $delimiter);
|
| 153 |
-
|
| 154 |
-
// transliterate
|
| 155 |
-
if (function_exists('iconv')) {
|
| 156 |
-
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
|
| 157 |
-
}
|
| 158 |
-
|
| 159 |
-
// lowercase
|
| 160 |
-
$text = strtolower($text);
|
| 161 |
-
|
| 162 |
-
// remove unwanted characters
|
| 163 |
-
$text = preg_replace('~[^_\w]+~', '', $text);
|
| 164 |
-
|
| 165 |
-
if (empty($text)) {
|
| 166 |
-
return null;
|
| 167 |
-
}
|
| 168 |
-
|
| 169 |
-
// max $maxLength (50) chars
|
| 170 |
-
$text = substr($text, 0, $maxLength);
|
| 171 |
-
$text = trim($text, $delimiter);
|
| 172 |
-
|
| 173 |
-
return $text;
|
| 174 |
-
}
|
| 175 |
-
|
| 176 |
-
public function escapeString($string)
|
| 177 |
-
{
|
| 178 |
-
return htmlspecialchars(trim(preg_replace('/\s+/', ' ', $string)));
|
| 179 |
-
}
|
| 180 |
-
|
| 181 |
-
public function delTree($dir)
|
| 182 |
-
{
|
| 183 |
-
if (!file_exists($dir)) {
|
| 184 |
-
return;
|
| 185 |
-
}
|
| 186 |
-
$files = array_diff(scandir($dir), array('.', '..'));
|
| 187 |
-
foreach ($files as $file) {
|
| 188 |
-
if (is_dir("$dir/$file")) {
|
| 189 |
-
self::delTree("$dir/$file");
|
| 190 |
-
} else if (file_exists("$dir/$file")) {
|
| 191 |
-
@unlink("$dir/$file");
|
| 192 |
-
}
|
| 193 |
-
}
|
| 194 |
-
return rmdir($dir);
|
| 195 |
-
}
|
| 196 |
-
|
| 197 |
-
public function rewrittenProductUrl($productId, $storeId)
|
| 198 |
-
{
|
| 199 |
-
$coreUrl = Mage::getModel('core/url_rewrite');
|
| 200 |
-
$coreUrl->setStoreId($storeId);
|
| 201 |
-
$coreUrl->loadByIdPath(sprintf('product/%d', $productId));
|
| 202 |
-
return $coreUrl->getRequestPath();
|
| 203 |
-
}
|
| 204 |
-
|
| 205 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/code/community/Boxalino/Exporter/Model/Delta.php
DELETED
|
@@ -1,29 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
|
| 3 |
-
class Boxalino_Exporter_Model_Delta extends Mage_Index_Model_Indexer_Abstract
|
| 4 |
-
{
|
| 5 |
-
public function getName()
|
| 6 |
-
{
|
| 7 |
-
return Mage::helper('boxalinoexporter')->__('Boxalino Delta Data Export');
|
| 8 |
-
}
|
| 9 |
-
|
| 10 |
-
public function getDescription()
|
| 11 |
-
{
|
| 12 |
-
return Mage::helper('boxalinoexporter')->__('Send latest data to Boxalino');
|
| 13 |
-
}
|
| 14 |
-
|
| 15 |
-
protected function _construct()
|
| 16 |
-
{
|
| 17 |
-
$this->_init('boxalinoexporter/exporter_delta');
|
| 18 |
-
}
|
| 19 |
-
|
| 20 |
-
protected function _registerEvent(Mage_Index_Model_Event $event)
|
| 21 |
-
{
|
| 22 |
-
}
|
| 23 |
-
|
| 24 |
-
protected function _processEvent(Mage_Index_Model_Event $event)
|
| 25 |
-
{
|
| 26 |
-
}
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/code/community/Boxalino/Exporter/Model/Indexer.php
DELETED
|
@@ -1,29 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
|
| 3 |
-
class Boxalino_Exporter_Model_Indexer extends Mage_Index_Model_Indexer_Abstract
|
| 4 |
-
{
|
| 5 |
-
public function getName()
|
| 6 |
-
{
|
| 7 |
-
return Mage::helper('boxalinoexporter')->__('Boxalino Full Data Export');
|
| 8 |
-
}
|
| 9 |
-
|
| 10 |
-
public function getDescription()
|
| 11 |
-
{
|
| 12 |
-
return Mage::helper('boxalinoexporter')->__('Send all data to Boxalino');
|
| 13 |
-
}
|
| 14 |
-
|
| 15 |
-
protected function _construct()
|
| 16 |
-
{
|
| 17 |
-
$this->_init('boxalinoexporter/exporter_indexer');
|
| 18 |
-
}
|
| 19 |
-
|
| 20 |
-
protected function _registerEvent(Mage_Index_Model_Event $event)
|
| 21 |
-
{
|
| 22 |
-
}
|
| 23 |
-
|
| 24 |
-
protected function _processEvent(Mage_Index_Model_Event $event)
|
| 25 |
-
{
|
| 26 |
-
}
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/code/community/Boxalino/Exporter/Model/Mysql4/Exporter/Delta.php
DELETED
|
@@ -1,71 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
|
| 3 |
-
class Boxalino_Exporter_Model_Mysql4_Exporter_Delta extends Boxalino_Exporter_Model_Mysql4_Indexer
|
| 4 |
-
{
|
| 5 |
-
const INDEX_TYPE = 'delta';
|
| 6 |
-
|
| 7 |
-
/** @var date Date of last data sync */
|
| 8 |
-
protected $_lastIndex = 0;
|
| 9 |
-
|
| 10 |
-
/**
|
| 11 |
-
* @description Declare where Indexer should start
|
| 12 |
-
* @return void
|
| 13 |
-
*/
|
| 14 |
-
protected function _construct()
|
| 15 |
-
{
|
| 16 |
-
$this->_init('boxalinoexporter/delta', '');
|
| 17 |
-
}
|
| 18 |
-
|
| 19 |
-
/**
|
| 20 |
-
* @description Get date of last data sync
|
| 21 |
-
*/
|
| 22 |
-
protected function _getLastIndex()
|
| 23 |
-
{
|
| 24 |
-
if ($this->_lastIndex == 0) {
|
| 25 |
-
$this->_setLastIndex();
|
| 26 |
-
}
|
| 27 |
-
return $this->_lastIndex;
|
| 28 |
-
}
|
| 29 |
-
|
| 30 |
-
/**
|
| 31 |
-
* @description set when was last data sync
|
| 32 |
-
*/
|
| 33 |
-
protected function _setLastIndex()
|
| 34 |
-
{
|
| 35 |
-
$dates = array();
|
| 36 |
-
$indexes = Mage::getModel('index/indexer')->getProcessesCollection()->getData();
|
| 37 |
-
foreach ($indexes as $index) {
|
| 38 |
-
if ($index['indexer_code'] == 'boxalinoexporter_indexer' && !empty($index['started_at'])) {
|
| 39 |
-
$dates[] = DateTime::createFromFormat('Y-m-d H:i:s', $index['started_at']);
|
| 40 |
-
} elseif ($index['indexer_code'] == 'boxalinoexporter_delta' && !empty($index['ended_at'])) {
|
| 41 |
-
$dates[] = DateTime::createFromFormat('Y-m-d H:i:s', $index['ended_at']);
|
| 42 |
-
}
|
| 43 |
-
}
|
| 44 |
-
if (count($dates) == 2) {
|
| 45 |
-
if ($dates[0] > $dates[1]) {
|
| 46 |
-
$date = $dates[0]->format('Y-m-d H:i:s');
|
| 47 |
-
} else {
|
| 48 |
-
$date = $dates[1]->format('Y-m-d H:i:s');
|
| 49 |
-
}
|
| 50 |
-
} else {
|
| 51 |
-
$date = $dates[0]->format('Y-m-d H:i:s');
|
| 52 |
-
}
|
| 53 |
-
|
| 54 |
-
$this->_lastIndex = $date;
|
| 55 |
-
}
|
| 56 |
-
|
| 57 |
-
/**
|
| 58 |
-
* @description Get list of products with their tags
|
| 59 |
-
* @return object List of products with their tags
|
| 60 |
-
*/
|
| 61 |
-
protected function _getProductTags()
|
| 62 |
-
{
|
| 63 |
-
if (empty($this->_allProductTags)) {
|
| 64 |
-
$tags = Mage::getResourceModel('tag/product_collection')->addAttributeToFilter('updated_at', array('from' => $this->_getLastIndex(), 'date' => true))->getData();
|
| 65 |
-
foreach ($tags as $tag) {
|
| 66 |
-
$this->_allProductTags[$tag['entity_id']] = $tag['tag_id'];
|
| 67 |
-
}
|
| 68 |
-
}
|
| 69 |
-
return $this->_allProductTags;
|
| 70 |
-
}
|
| 71 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/code/community/Boxalino/Exporter/Model/Mysql4/Indexer.php
DELETED
|
@@ -1,2029 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
|
| 3 |
-
abstract class Boxalino_Exporter_Model_Mysql4_Indexer extends Mage_Core_Model_Mysql4_Abstract
|
| 4 |
-
{
|
| 5 |
-
/** @var array Configuration for each Store View */
|
| 6 |
-
protected $_storeConfig = array();
|
| 7 |
-
|
| 8 |
-
/** @var array Values of attributes where array('storeId' => array('attrName' => array('id' => 'value'))) */
|
| 9 |
-
protected $_attributesValues = array();
|
| 10 |
-
|
| 11 |
-
/** @var array Customer attributes */
|
| 12 |
-
protected $_customerAttributes = array();
|
| 13 |
-
|
| 14 |
-
/** @var array Number of stockQty for all products. Example: array('productId' => 'qty') */
|
| 15 |
-
protected $productsStockQty = array();
|
| 16 |
-
|
| 17 |
-
/** @var array List of attributes which module export to our server */
|
| 18 |
-
protected $_listOfAttributes = array();
|
| 19 |
-
|
| 20 |
-
/** @var array All tags of products */
|
| 21 |
-
protected $_allProductTags = array();
|
| 22 |
-
|
| 23 |
-
protected $_transformedCategories = array();
|
| 24 |
-
|
| 25 |
-
protected $_transformedTags = array();
|
| 26 |
-
|
| 27 |
-
protected $_transformedProducts = array();
|
| 28 |
-
|
| 29 |
-
protected $_categoryParent = array();
|
| 30 |
-
|
| 31 |
-
protected $_countries = null;
|
| 32 |
-
|
| 33 |
-
protected $_availableLanguages = array();
|
| 34 |
-
|
| 35 |
-
protected $_attributesValuesByName = array();
|
| 36 |
-
|
| 37 |
-
protected $_productsImages = array();
|
| 38 |
-
protected $_productsThumbnails = array();
|
| 39 |
-
|
| 40 |
-
protected $_files = array();
|
| 41 |
-
|
| 42 |
-
protected $_count = 0;
|
| 43 |
-
|
| 44 |
-
protected $_attrProdCount = array();
|
| 45 |
-
|
| 46 |
-
/** @var int Actually used storeId */
|
| 47 |
-
protected $_storeId = 0;
|
| 48 |
-
|
| 49 |
-
protected $_mainDir = '/tmp/boxalino';
|
| 50 |
-
protected $_dir = '';
|
| 51 |
-
|
| 52 |
-
protected $group = null;
|
| 53 |
-
|
| 54 |
-
protected $_helperExporter = null;
|
| 55 |
-
protected $_helperSearch = null;
|
| 56 |
-
protected $_helperImage = null;
|
| 57 |
-
|
| 58 |
-
protected $_entityIds = null;
|
| 59 |
-
protected $_prefix = '';
|
| 60 |
-
|
| 61 |
-
/**
|
| 62 |
-
* @description Start of reindex
|
| 63 |
-
*/
|
| 64 |
-
public function reindexAll()
|
| 65 |
-
{
|
| 66 |
-
|
| 67 |
-
$prefix = Mage::getConfig()->getTablePrefix();
|
| 68 |
-
$this->_prefix = $prefix;
|
| 69 |
-
|
| 70 |
-
self::logMem('Indexer init');
|
| 71 |
-
if (!file_exists($this->_mainDir)) {
|
| 72 |
-
mkdir($this->_mainDir);
|
| 73 |
-
}
|
| 74 |
-
$this->_websiteExport();
|
| 75 |
-
return $this;
|
| 76 |
-
}
|
| 77 |
-
|
| 78 |
-
/**
|
| 79 |
-
* @description Declare what code have to do for Website scope
|
| 80 |
-
* @return void
|
| 81 |
-
*/
|
| 82 |
-
protected function _websiteExport()
|
| 83 |
-
{
|
| 84 |
-
$this->_helperExporter = Mage::helper('boxalinoexporter');
|
| 85 |
-
$this->_helperSearch = Mage::helper('boxalinoexporter');
|
| 86 |
-
$this->_helperImage = Mage::helper('catalog/image');
|
| 87 |
-
|
| 88 |
-
self::logMem('Helpers init');
|
| 89 |
-
$indexStructure = $this->_getIndexStructure();
|
| 90 |
-
foreach ($indexStructure as $index => $languages) {
|
| 91 |
-
$this->_dir = $this->_mainDir . '/' . $index;
|
| 92 |
-
if (file_exists($this->_dir)) {
|
| 93 |
-
$this->_helperExporter->delTree($this->_dir);
|
| 94 |
-
}
|
| 95 |
-
self::logMem('After delTree');
|
| 96 |
-
|
| 97 |
-
$data = $this->_storeExport($languages);
|
| 98 |
-
|
| 99 |
-
self::logMem('something with attributes - before');
|
| 100 |
-
|
| 101 |
-
foreach ($this->_listOfAttributes as $k => $attr) {
|
| 102 |
-
if (
|
| 103 |
-
!isset($this->_attributesValuesByName[$attr]) ||
|
| 104 |
-
(isset($this->_attrProdCount[$attr]) &&
|
| 105 |
-
$this->_attrProdCount[$attr])
|
| 106 |
-
) {
|
| 107 |
-
continue;
|
| 108 |
-
} else {
|
| 109 |
-
unset($this->_attributesValuesByName[$attr]);
|
| 110 |
-
unset($this->_listOfAttributes[$k]);
|
| 111 |
-
}
|
| 112 |
-
}
|
| 113 |
-
|
| 114 |
-
self::logMem('something with attributes - after');
|
| 115 |
-
$file = $this->prepareFiles($data['categories'], $data['tags']);
|
| 116 |
-
self::logMem('Push files');
|
| 117 |
-
|
| 118 |
-
$this->pushXML($file);
|
| 119 |
-
$this->pushZip($file);
|
| 120 |
-
|
| 121 |
-
self::logMem('Files pushed');
|
| 122 |
-
|
| 123 |
-
$this->_transformedCategories = array();
|
| 124 |
-
$this->_transformedTags = array();
|
| 125 |
-
$this->_transformedProducts = array();
|
| 126 |
-
$this->_categoryParent = array();
|
| 127 |
-
$this->_availableLanguages = array();
|
| 128 |
-
$this->_attrProdCount = array();
|
| 129 |
-
$this->_count = 0;
|
| 130 |
-
|
| 131 |
-
}
|
| 132 |
-
}
|
| 133 |
-
|
| 134 |
-
/**
|
| 135 |
-
* @description generate the data for the language scope
|
| 136 |
-
* @param array $languages Array of languages to generate for this index
|
| 137 |
-
* @return array Data prepared for save to file
|
| 138 |
-
*/
|
| 139 |
-
protected function _storeExport($languages)
|
| 140 |
-
{
|
| 141 |
-
$categories = array();
|
| 142 |
-
$tags = array();
|
| 143 |
-
self::logMem('Preparing data for website start');
|
| 144 |
-
foreach ($languages as $language => $info) {
|
| 145 |
-
$storeId = $info['store']->getId();
|
| 146 |
-
|
| 147 |
-
self::logMem('Start store:' . $storeId);
|
| 148 |
-
$this->_prepareStoreConfig($storeId, $info['config']);
|
| 149 |
-
self::logMem('Configuration for store loaded');
|
| 150 |
-
$categories = $this->_exportCategories();
|
| 151 |
-
$tags = $this->_exportTags();
|
| 152 |
-
$this->_availableLanguages[] = $language;
|
| 153 |
-
|
| 154 |
-
}
|
| 155 |
-
$this->_exportCustomers($info['website']);
|
| 156 |
-
$this->_exportTransactions();
|
| 157 |
-
$this->_exportProducts($languages);
|
| 158 |
-
|
| 159 |
-
return array(
|
| 160 |
-
'categories' => $categories,
|
| 161 |
-
'tags' => $tags,
|
| 162 |
-
);
|
| 163 |
-
}
|
| 164 |
-
|
| 165 |
-
/**
|
| 166 |
-
* @description generate the index structure to iterate on
|
| 167 |
-
* @return array Index structure
|
| 168 |
-
*/
|
| 169 |
-
protected function _getIndexStructure()
|
| 170 |
-
{
|
| 171 |
-
$indexStructure = array();
|
| 172 |
-
foreach (Mage::app()->getWebsites() as $website) {
|
| 173 |
-
foreach ($website->getGroups() as $group) {
|
| 174 |
-
foreach ($group->getStores() as $store) {
|
| 175 |
-
$config = array_merge(
|
| 176 |
-
$store->getConfig('boxalinoexporter/export_data'),
|
| 177 |
-
$store->getConfig('Boxalino_General/general')
|
| 178 |
-
);
|
| 179 |
-
if ($config['enabled'] == '1') {
|
| 180 |
-
$index = $config['di_account'];
|
| 181 |
-
$lang = $config['language'];
|
| 182 |
-
$config['groupId'] = $store->getGroupId();
|
| 183 |
-
|
| 184 |
-
if (!array_key_exists($index, $indexStructure)) {
|
| 185 |
-
$indexStructure[$index] = array();
|
| 186 |
-
}
|
| 187 |
-
if (!array_key_exists($lang, $indexStructure[$index])) {
|
| 188 |
-
$indexStructure[$index][$lang] = array();
|
| 189 |
-
}
|
| 190 |
-
$indexStructure[$index][$lang] = array(
|
| 191 |
-
'config' => $config,
|
| 192 |
-
'website' => $website,
|
| 193 |
-
'store' => $store,
|
| 194 |
-
);
|
| 195 |
-
}
|
| 196 |
-
}
|
| 197 |
-
}
|
| 198 |
-
}
|
| 199 |
-
return $indexStructure;
|
| 200 |
-
}
|
| 201 |
-
|
| 202 |
-
/**
|
| 203 |
-
* @description Get configs for store by storeId
|
| 204 |
-
* @param int $storeId
|
| 205 |
-
* @return void
|
| 206 |
-
*/
|
| 207 |
-
protected function _prepareStoreConfig($storeId, $config)
|
| 208 |
-
{
|
| 209 |
-
$this->_storeId = $storeId;
|
| 210 |
-
$this->_storeConfig = $config;
|
| 211 |
-
|
| 212 |
-
if (!$this->_helperExporter->isAvailableLanguages($this->_storeConfig['language'])) {
|
| 213 |
-
Mage::throwException($this->_helperExporter->__('Language "' . $this->_storeConfig['language'] . '" is not available.'));
|
| 214 |
-
}
|
| 215 |
-
$this->_mergeAllAttributes();
|
| 216 |
-
$this->_getAllAttributesValues();
|
| 217 |
-
}
|
| 218 |
-
|
| 219 |
-
/**
|
| 220 |
-
* @description Merge default attributes with attributes added by user
|
| 221 |
-
* @return void
|
| 222 |
-
*/
|
| 223 |
-
protected function _mergeAllAttributes()
|
| 224 |
-
{
|
| 225 |
-
$this->_listOfAttributes = array(
|
| 226 |
-
'entity_id',
|
| 227 |
-
'name',
|
| 228 |
-
'description',
|
| 229 |
-
'short_description',
|
| 230 |
-
'sku',
|
| 231 |
-
'price',
|
| 232 |
-
'special_price',
|
| 233 |
-
'special_from_date',
|
| 234 |
-
'special_to_date',
|
| 235 |
-
'category_ids',
|
| 236 |
-
'visibility',
|
| 237 |
-
'status'
|
| 238 |
-
);
|
| 239 |
-
|
| 240 |
-
$attributes = array();
|
| 241 |
-
|
| 242 |
-
foreach (Mage::getResourceModel('catalog/product_attribute_collection')->getItems() as $at) {
|
| 243 |
-
$attributes[] = $at->getAttributeCode();
|
| 244 |
-
}
|
| 245 |
-
|
| 246 |
-
if (isset($this->_storeConfig['additional_attributes']) && $this->_storeConfig['additional_attributes'] != '') {
|
| 247 |
-
$fields = explode(',', $this->_storeConfig['additional_attributes']);
|
| 248 |
-
foreach ($fields as $field) {
|
| 249 |
-
|
| 250 |
-
if (!in_array($field, $attributes)) {
|
| 251 |
-
Mage::throwException("Attribute \"$field\" doesn't exist, please update your additional_attributes setting in the Boxalino Exporter settings!");
|
| 252 |
-
}
|
| 253 |
-
|
| 254 |
-
if ($field != null && strlen($field) > 0) {
|
| 255 |
-
$this->_listOfAttributes[] = $field;
|
| 256 |
-
}
|
| 257 |
-
|
| 258 |
-
}
|
| 259 |
-
unset($fields);
|
| 260 |
-
}
|
| 261 |
-
|
| 262 |
-
}
|
| 263 |
-
|
| 264 |
-
/**
|
| 265 |
-
* @description Merge default customer attributes with customer attributes added by user
|
| 266 |
-
* @param array $attributes optional, array to merge the user defined attributes into
|
| 267 |
-
* @return array
|
| 268 |
-
*/
|
| 269 |
-
protected function _mergeCustomerAttributes($attributes = array())
|
| 270 |
-
{
|
| 271 |
-
if (isset($this->_storeConfig['additional_customer_attributes']) && $this->_storeConfig['additional_customer_attributes'] != '') {
|
| 272 |
-
if(count($this->_customerAttributes) == 0) {
|
| 273 |
-
foreach (Mage::getModel('customer/customer')->getAttributes() as $at) {
|
| 274 |
-
$this->_customerAttributes[] = $at->getAttributeCode();
|
| 275 |
-
}
|
| 276 |
-
}
|
| 277 |
-
|
| 278 |
-
foreach (explode(',', $this->_storeConfig['additional_customer_attributes']) as $field) {
|
| 279 |
-
if (!in_array($field, $this->_customerAttributes)) {
|
| 280 |
-
Mage::throwException("Customer attribute \"$field\" doesn't exist, please update your additional_customer_attributes setting in the Boxalino Exporter settings!");
|
| 281 |
-
}
|
| 282 |
-
if ($field != null && strlen($field) > 0 && !in_array($field, $attributes)) {
|
| 283 |
-
$attributes[] = $field;
|
| 284 |
-
}
|
| 285 |
-
}
|
| 286 |
-
}
|
| 287 |
-
return $attributes;
|
| 288 |
-
}
|
| 289 |
-
|
| 290 |
-
/**
|
| 291 |
-
* @description Get labels for all Attributes where is optionsId = optionValue
|
| 292 |
-
* @return void
|
| 293 |
-
*/
|
| 294 |
-
protected function _getAllAttributesValues()
|
| 295 |
-
{
|
| 296 |
-
$attributesWithId = $this->_helperExporter->attributesWithIds();
|
| 297 |
-
foreach ($this->_listOfAttributes as $attribute) {
|
| 298 |
-
if (array_search($attribute, $attributesWithId) == true) {
|
| 299 |
-
$options = Mage::getModel('eav/config')->getAttribute('catalog_product', $attribute)->setStoreId($this->_storeId)->getSource()->getAllOptions();
|
| 300 |
-
foreach ($options as $option) {
|
| 301 |
-
if (!empty($option['value'])) {
|
| 302 |
-
$this->_attributesValues[$this->_storeId][$attribute][$option['value']] = $this->_helperSearch->escapeString($option['label']);
|
| 303 |
-
|
| 304 |
-
$value = intval($option['value']);
|
| 305 |
-
$name = 'value_' . $this->_storeConfig['language'];
|
| 306 |
-
|
| 307 |
-
if (isset($this->_attributesValuesByName[$attribute])) {
|
| 308 |
-
|
| 309 |
-
if (isset($this->_attributesValuesByName[$attribute][$value])) {
|
| 310 |
-
$this->_attributesValuesByName[$attribute][$value][$name] = /*strtolower*/
|
| 311 |
-
$this->_helperSearch->escapeString($option['label']);
|
| 312 |
-
} else {
|
| 313 |
-
$this->_attributesValuesByName[$attribute][$value] = array($attribute . '_id' => $value, $name => /*strtolower*/
|
| 314 |
-
$this->_helperSearch->escapeString($option['label']));
|
| 315 |
-
}
|
| 316 |
-
|
| 317 |
-
} else {
|
| 318 |
-
$this->_attributesValuesByName[$attribute] = array($value => array($attribute . '_id' => $value, $name => /*strtolower*/
|
| 319 |
-
$this->_helperSearch->escapeString($option['label'])));
|
| 320 |
-
}
|
| 321 |
-
|
| 322 |
-
}
|
| 323 |
-
}
|
| 324 |
-
unset($options);
|
| 325 |
-
}
|
| 326 |
-
}
|
| 327 |
-
unset($attributesWithId);
|
| 328 |
-
}
|
| 329 |
-
|
| 330 |
-
/**
|
| 331 |
-
* @description Preparing categories to export
|
| 332 |
-
* @return array Categories
|
| 333 |
-
*/
|
| 334 |
-
protected function _exportCategories()
|
| 335 |
-
{
|
| 336 |
-
if ($this->_storeConfig['export_categories']) {
|
| 337 |
-
self::logMem('Categories are not loaded');
|
| 338 |
-
$categories = $this->_getCategories();
|
| 339 |
-
self::logMem('Categories are loaded');
|
| 340 |
-
foreach ($categories as $category) {
|
| 341 |
-
|
| 342 |
-
if ($category->getParentId() == null) {
|
| 343 |
-
continue;
|
| 344 |
-
}
|
| 345 |
-
|
| 346 |
-
if (isset($this->_transformedCategories[$category->getId()])) {
|
| 347 |
-
$this->_transformedCategories[$category->getId()]['value_' . $this->_storeConfig['language']] = $this->_helperSearch->escapeString($category->getName());
|
| 348 |
-
} else {
|
| 349 |
-
$parentId = null;
|
| 350 |
-
if ($category->getParentId() != 0) {
|
| 351 |
-
$parentId = $category->getParentId();
|
| 352 |
-
}
|
| 353 |
-
$this->_transformedCategories[$category->getId()] = array('category_id' => $category->getId(), 'parent_id' => $parentId, 'value_' . $this->_storeConfig['language'] => $this->_helperSearch->escapeString($category->getName()));
|
| 354 |
-
}
|
| 355 |
-
}
|
| 356 |
-
$categories = null;
|
| 357 |
-
self::logMem('Categories are returned for data saving');
|
| 358 |
-
return $this->_transformedCategories;
|
| 359 |
-
}
|
| 360 |
-
return null;
|
| 361 |
-
}
|
| 362 |
-
|
| 363 |
-
/**
|
| 364 |
-
* @description Get list of all categories
|
| 365 |
-
* @return object All categories for Store
|
| 366 |
-
*/
|
| 367 |
-
protected function _getCategories()
|
| 368 |
-
{
|
| 369 |
-
$categories = Mage::getModel('catalog/category')->setStoreId($this->_storeId)->getCollection()->addAttributeToSelect('*');
|
| 370 |
-
return $categories;
|
| 371 |
-
}
|
| 372 |
-
|
| 373 |
-
/**
|
| 374 |
-
* @description Preparing tags to export
|
| 375 |
-
* @return array Tags
|
| 376 |
-
*
|
| 377 |
-
*/
|
| 378 |
-
protected function _exportTags()
|
| 379 |
-
{
|
| 380 |
-
|
| 381 |
-
if ($this->_storeConfig['export_tags']) {
|
| 382 |
-
self::logMem('Tags are not loaded');
|
| 383 |
-
$tags = $this->_helperExporter->getAllTags();
|
| 384 |
-
self::logMem('Tags are loaded');
|
| 385 |
-
|
| 386 |
-
foreach ($tags as $id => $tag) {
|
| 387 |
-
if (isset($this->_transformedTags[$id])) {
|
| 388 |
-
$this->_transformedTags[$id]['value_' . $this->_storeConfig['language']] = $tag;
|
| 389 |
-
} else {
|
| 390 |
-
$this->_transformedTags[$id] = array('tag_id' => $id, 'value_' . $this->_storeConfig['language'] => $tag);
|
| 391 |
-
}
|
| 392 |
-
}
|
| 393 |
-
|
| 394 |
-
$tags = null;
|
| 395 |
-
self::logMem('Tags are returned for data saving');
|
| 396 |
-
return $this->_transformedTags;
|
| 397 |
-
}
|
| 398 |
-
|
| 399 |
-
return null;
|
| 400 |
-
}
|
| 401 |
-
|
| 402 |
-
/**
|
| 403 |
-
* @description Preparing products to export
|
| 404 |
-
* @param array $languages language structure
|
| 405 |
-
* @return void
|
| 406 |
-
*/
|
| 407 |
-
protected function _exportProducts($languages)
|
| 408 |
-
{
|
| 409 |
-
self::logMem('Products - start of export');
|
| 410 |
-
$attrs = $this->_listOfAttributes;
|
| 411 |
-
self::logMem('Products - get info about attributes - before');
|
| 412 |
-
|
| 413 |
-
$db = $this->_getReadAdapter();
|
| 414 |
-
$select = $db->select()
|
| 415 |
-
->from(
|
| 416 |
-
array('main_table' => $this->_prefix . 'eav_attribute'),
|
| 417 |
-
array(
|
| 418 |
-
'attribute_id',
|
| 419 |
-
'attribute_code',
|
| 420 |
-
'backend_type',
|
| 421 |
-
)
|
| 422 |
-
)
|
| 423 |
-
->joinInner(
|
| 424 |
-
array('additional_table' => $this->_prefix . 'catalog_eav_attribute'),
|
| 425 |
-
'additional_table.attribute_id = main_table.attribute_id'
|
| 426 |
-
)
|
| 427 |
-
->where('main_table.entity_type_id = ?', $this->getEntityIdFor('catalog_product'))
|
| 428 |
-
->where('main_table.attribute_code IN(?)', $attrs);
|
| 429 |
-
|
| 430 |
-
self::logMem('Products - connected to DB, built attribute info query');
|
| 431 |
-
|
| 432 |
-
$attrsFromDb = array(
|
| 433 |
-
'int' => array(),
|
| 434 |
-
'varchar' => array(),
|
| 435 |
-
'text' => array(),
|
| 436 |
-
'decimal' => array(),
|
| 437 |
-
'datetime' => array(),
|
| 438 |
-
);
|
| 439 |
-
|
| 440 |
-
foreach ($db->fetchAll($select) as $r) {
|
| 441 |
-
$type = $r['backend_type'];
|
| 442 |
-
if (isset($attrsFromDb[$type])) {
|
| 443 |
-
$attrsFromDb[$type][] = $r['attribute_id'];
|
| 444 |
-
}
|
| 445 |
-
}
|
| 446 |
-
self::logMem('Products - attributes preparing done');
|
| 447 |
-
|
| 448 |
-
$countMax = $this->_storeConfig['maximum_population'];
|
| 449 |
-
$localeCount = 0;
|
| 450 |
-
|
| 451 |
-
$limit = $this->_storeConfig['export_chunk'];
|
| 452 |
-
$count = $limit;
|
| 453 |
-
$page = 1;
|
| 454 |
-
$header = true;
|
| 455 |
-
|
| 456 |
-
//prepare files
|
| 457 |
-
$filesMtM = array();
|
| 458 |
-
$tmp = array_keys($this->_attributesValuesByName);
|
| 459 |
-
$tmp[] = 'categories';
|
| 460 |
-
foreach ($tmp as $attr) {
|
| 461 |
-
|
| 462 |
-
$key = $attr;
|
| 463 |
-
|
| 464 |
-
if ($attr == 'categories') {
|
| 465 |
-
$key = 'category';
|
| 466 |
-
}
|
| 467 |
-
|
| 468 |
-
if (!file_exists($this->_dir)) {
|
| 469 |
-
mkdir($this->_dir);
|
| 470 |
-
}
|
| 471 |
-
|
| 472 |
-
$file = 'product_' . $attr . '.csv';
|
| 473 |
-
|
| 474 |
-
//save
|
| 475 |
-
if (!in_array($file, $this->_files)) {
|
| 476 |
-
$this->_files[] = $file;
|
| 477 |
-
}
|
| 478 |
-
|
| 479 |
-
$fh = fopen($this->_dir . '/' . $file, 'a');
|
| 480 |
-
fputcsv($fh, array('entity_id', $key . '_id'), $this->_helperExporter->XML_DELIMITER, $this->_helperExporter->XML_ENCLOSURE);
|
| 481 |
-
|
| 482 |
-
$filesMtM[$attr] = $fh;
|
| 483 |
-
|
| 484 |
-
}
|
| 485 |
-
|
| 486 |
-
if ($this->_storeConfig['export_product_images']) {
|
| 487 |
-
$file = 'product_cache_image_url.csv';
|
| 488 |
-
if (!in_array($file, $this->_files)) {
|
| 489 |
-
$this->_files[] = $file;
|
| 490 |
-
}
|
| 491 |
-
$fh = fopen($this->_dir . '/' . $file, 'a');
|
| 492 |
-
$h = array('entity_id', 'cache_image_url');
|
| 493 |
-
fputcsv($fh, $h, $this->_helperExporter->XML_DELIMITER, $this->_helperExporter->XML_ENCLOSURE);
|
| 494 |
-
}
|
| 495 |
-
|
| 496 |
-
if ($this->_storeConfig['export_product_images_thumbnail']) {
|
| 497 |
-
$file = 'product_cache_image_thumbnail_url.csv';
|
| 498 |
-
if (!in_array($file, $this->_files)) {
|
| 499 |
-
$this->_files[] = $file;
|
| 500 |
-
}
|
| 501 |
-
$fh = fopen($this->_dir . '/' . $file, 'a');
|
| 502 |
-
$h = array('entity_id', 'cache_image_thumbnail_url');
|
| 503 |
-
fputcsv($fh, $h, $this->_helperExporter->XML_DELIMITER, $this->_helperExporter->XML_ENCLOSURE);
|
| 504 |
-
}
|
| 505 |
-
|
| 506 |
-
while ($count >= $limit) {
|
| 507 |
-
if ($countMax > 0 && $this->_count >= $countMax) {
|
| 508 |
-
break;
|
| 509 |
-
}
|
| 510 |
-
|
| 511 |
-
foreach ($languages as $lang => $info) {
|
| 512 |
-
$storeObject = $info['store'];
|
| 513 |
-
$storeId = $storeObject->getId();
|
| 514 |
-
$storeBaseUrl = $storeObject->getBaseUrl();
|
| 515 |
-
$storeCode = $storeObject->getCode();
|
| 516 |
-
|
| 517 |
-
self::logMem('Products - fetch products - before');
|
| 518 |
-
$select = $db->select()
|
| 519 |
-
->from(
|
| 520 |
-
array('e' => $this->_prefix . 'catalog_product_entity')
|
| 521 |
-
)
|
| 522 |
-
->limit($limit, ($page - 1) * $limit);
|
| 523 |
-
|
| 524 |
-
$this->_getIndexType() == 'delta' ? $select->where('created_at >= ? OR updated_at >= ?', $this->_getLastIndex()) : '';
|
| 525 |
-
|
| 526 |
-
self::logMem('Products - fetch products - after');
|
| 527 |
-
|
| 528 |
-
$products = array();
|
| 529 |
-
$ids = array();
|
| 530 |
-
$count = 0;
|
| 531 |
-
foreach ($db->fetchAll($select) as $r) {
|
| 532 |
-
$products[$r['entity_id']] = $r;
|
| 533 |
-
$ids[] = $r['entity_id'];
|
| 534 |
-
$products[$r['entity_id']]['website'] = array();
|
| 535 |
-
$products[$r['entity_id']]['categories'] = array();
|
| 536 |
-
$count++;
|
| 537 |
-
}
|
| 538 |
-
|
| 539 |
-
// we have to check for settings on the different levels: Store(View) & Global
|
| 540 |
-
self::logMem('Products - get attributes - before');
|
| 541 |
-
$columns = array(
|
| 542 |
-
'entity_id',
|
| 543 |
-
'attribute_id',
|
| 544 |
-
);
|
| 545 |
-
$joinCondition = $db->quoteInto('t_s.attribute_id = t_d.attribute_id AND t_s.entity_id = t_d.entity_id AND t_s.store_id = ?', $storeId);
|
| 546 |
-
$joinColumns = array('value' => 'IF(t_s.value_id IS NULL, t_d.value, t_s.value)');
|
| 547 |
-
|
| 548 |
-
$select1 = $db->select()
|
| 549 |
-
->joinLeft(array('ea' => $this->_prefix . 'eav_attribute'), 't_d.attribute_id = ea.attribute_id', 'ea.attribute_code')
|
| 550 |
-
->where('t_d.store_id = ?', 0)
|
| 551 |
-
->where('t_d.entity_type_id = ?', $this->getEntityIdFor('catalog_product'))
|
| 552 |
-
->where('t_d.entity_id IN(?)', $ids);
|
| 553 |
-
$select2 = clone $select1;
|
| 554 |
-
$select3 = clone $select1;
|
| 555 |
-
$select4 = clone $select1;
|
| 556 |
-
$select5 = clone $select1;
|
| 557 |
-
|
| 558 |
-
$select1->from(
|
| 559 |
-
array('t_d' => $this->_prefix . 'catalog_product_entity_varchar'),
|
| 560 |
-
$columns
|
| 561 |
-
)
|
| 562 |
-
->joinLeft(
|
| 563 |
-
array('t_s' => $this->_prefix . 'catalog_product_entity_varchar'),
|
| 564 |
-
$joinCondition,
|
| 565 |
-
$joinColumns
|
| 566 |
-
)
|
| 567 |
-
->where('t_d.attribute_id IN(?)', $attrsFromDb['varchar']);
|
| 568 |
-
$select2->from(
|
| 569 |
-
array('t_d' => $this->_prefix . 'catalog_product_entity_text'),
|
| 570 |
-
$columns
|
| 571 |
-
)
|
| 572 |
-
->joinLeft(
|
| 573 |
-
array('t_s' => $this->_prefix . 'catalog_product_entity_text'),
|
| 574 |
-
$joinCondition,
|
| 575 |
-
$joinColumns
|
| 576 |
-
)
|
| 577 |
-
->where('t_d.attribute_id IN(?)', $attrsFromDb['text']);
|
| 578 |
-
$select3->from(
|
| 579 |
-
array('t_d' => $this->_prefix . 'catalog_product_entity_decimal'),
|
| 580 |
-
$columns
|
| 581 |
-
)
|
| 582 |
-
->joinLeft(
|
| 583 |
-
array('t_s' => $this->_prefix . 'catalog_product_entity_decimal'),
|
| 584 |
-
$joinCondition,
|
| 585 |
-
$joinColumns
|
| 586 |
-
)
|
| 587 |
-
->where('t_d.attribute_id IN(?)', $attrsFromDb['decimal']);
|
| 588 |
-
$select4->from(
|
| 589 |
-
array('t_d' => $this->_prefix . 'catalog_product_entity_int'),
|
| 590 |
-
$columns
|
| 591 |
-
)
|
| 592 |
-
->joinLeft(
|
| 593 |
-
array('t_s' => $this->_prefix . 'catalog_product_entity_int'),
|
| 594 |
-
$joinCondition,
|
| 595 |
-
$joinColumns
|
| 596 |
-
)
|
| 597 |
-
->where('t_d.attribute_id IN(?)', $attrsFromDb['int']);
|
| 598 |
-
$select5->from(
|
| 599 |
-
array('t_d' => $this->_prefix . 'catalog_product_entity_datetime'),
|
| 600 |
-
$columns
|
| 601 |
-
)
|
| 602 |
-
->joinLeft(
|
| 603 |
-
array('t_s' => $this->_prefix . 'catalog_product_entity_datetime'),
|
| 604 |
-
$joinCondition,
|
| 605 |
-
$joinColumns
|
| 606 |
-
)
|
| 607 |
-
->where('t_d.attribute_id IN(?)', $attrsFromDb['datetime']);
|
| 608 |
-
|
| 609 |
-
$select = $db->select()->union(
|
| 610 |
-
array($select1, $select2, $select3, $select4, $select5),
|
| 611 |
-
Zend_Db_Select::SQL_UNION_ALL
|
| 612 |
-
);
|
| 613 |
-
|
| 614 |
-
$select1 = null;
|
| 615 |
-
$select2 = null;
|
| 616 |
-
$select3 = null;
|
| 617 |
-
$select4 = null;
|
| 618 |
-
$select5 = null;
|
| 619 |
-
foreach ($db->fetchAll($select) as $r) {
|
| 620 |
-
$products[$r['entity_id']][$r['attribute_code']] = $r['value'];
|
| 621 |
-
}
|
| 622 |
-
self::logMem('Products - get attributes - after');
|
| 623 |
-
|
| 624 |
-
self::logMem('Products - get stock - before');
|
| 625 |
-
$select = $db->select()
|
| 626 |
-
->from(
|
| 627 |
-
$this->_prefix . 'cataloginventory_stock_status',
|
| 628 |
-
array(
|
| 629 |
-
'product_id',
|
| 630 |
-
'stock_status',
|
| 631 |
-
)
|
| 632 |
-
)
|
| 633 |
-
->where('stock_id = ?', 1)
|
| 634 |
-
->where('website_id = ?', 1)
|
| 635 |
-
->where('product_id IN(?)', $ids);
|
| 636 |
-
foreach ($db->fetchAll($select) as $r) {
|
| 637 |
-
$products[$r['product_id']]['stock_status'] = $r['stock_status'];
|
| 638 |
-
}
|
| 639 |
-
self::logMem('Products - get stock - after');
|
| 640 |
-
|
| 641 |
-
self::logMem('Products - get products from website - before');
|
| 642 |
-
$select = $db->select()
|
| 643 |
-
->from(
|
| 644 |
-
$this->_prefix . 'catalog_product_website',
|
| 645 |
-
array(
|
| 646 |
-
'product_id',
|
| 647 |
-
'website_id',
|
| 648 |
-
)
|
| 649 |
-
)
|
| 650 |
-
->where('product_id IN(?)', $ids);
|
| 651 |
-
foreach ($db->fetchAll($select) as $r) {
|
| 652 |
-
$products[$r['product_id']]['website'][] = $r['website_id'];
|
| 653 |
-
}
|
| 654 |
-
self::logMem('Products - get products from website - after');
|
| 655 |
-
|
| 656 |
-
self::logMem('Products - get products connections - before');
|
| 657 |
-
$select = $db->select()
|
| 658 |
-
->from(
|
| 659 |
-
$this->_prefix . 'catalog_product_super_link',
|
| 660 |
-
array(
|
| 661 |
-
'product_id',
|
| 662 |
-
'parent_id',
|
| 663 |
-
)
|
| 664 |
-
)
|
| 665 |
-
->where('product_id IN(?)', $ids);
|
| 666 |
-
foreach ($db->fetchAll($select) as $r) {
|
| 667 |
-
$products[$r['product_id']]['parent_id'] = $r['parent_id'];
|
| 668 |
-
}
|
| 669 |
-
self::logMem('Products - get products connections - after');
|
| 670 |
-
|
| 671 |
-
self::logMem('Products - get categories - before');
|
| 672 |
-
$select = $db->select()
|
| 673 |
-
->from(
|
| 674 |
-
$this->_prefix . 'catalog_category_product',
|
| 675 |
-
array(
|
| 676 |
-
'product_id',
|
| 677 |
-
'category_id',
|
| 678 |
-
)
|
| 679 |
-
)
|
| 680 |
-
->where('product_id IN(?)', $ids);
|
| 681 |
-
foreach ($db->fetchAll($select) as $r) {
|
| 682 |
-
$products[$r['product_id']]['categories'][] = $r['category_id'];
|
| 683 |
-
}
|
| 684 |
-
$select = null;
|
| 685 |
-
self::logMem('Products - get categories - after');
|
| 686 |
-
|
| 687 |
-
if (Mage::getEdition() == Mage::EDITION_ENTERPRISE) {
|
| 688 |
-
self::logMem('Products - get EE URL key - before');
|
| 689 |
-
$select = $db->select()
|
| 690 |
-
->from(
|
| 691 |
-
array('t_g' => $this->_prefix . 'catalog_product_entity_url_key'),
|
| 692 |
-
array('entity_id')
|
| 693 |
-
)
|
| 694 |
-
->joinLeft(
|
| 695 |
-
array('t_s' => $this->_prefix . 'catalog_product_entity_url_key'),
|
| 696 |
-
$db->quoteInto('t_s.attribute_id = t_g.attribute_id AND t_s.entity_id = t_g.entity_id AND t_s.store_id = ?', $storeId),
|
| 697 |
-
array('value' => 'IF(t_s.store_id IS NULL, t_g.value, t_s.value)')
|
| 698 |
-
)
|
| 699 |
-
->where('t_g.store_id = ?', 0)
|
| 700 |
-
->where('t_g.entity_id IN(?)', $ids);
|
| 701 |
-
foreach ($db->fetchAll($select) as $r) {
|
| 702 |
-
$products[$r['entity_id']]['url_key'] = $r['value'];
|
| 703 |
-
}
|
| 704 |
-
self::logMem('Products - get EE URL key - after');
|
| 705 |
-
}
|
| 706 |
-
$ids = null;
|
| 707 |
-
|
| 708 |
-
foreach ($products as $product) {
|
| 709 |
-
self::logMem('Products - start transform');
|
| 710 |
-
|
| 711 |
-
if (count($product['website']) == 0 || !in_array($this->_storeConfig['groupId'], $product['website'])) {
|
| 712 |
-
$product = null;
|
| 713 |
-
continue;
|
| 714 |
-
}
|
| 715 |
-
|
| 716 |
-
$id = $product['entity_id'];
|
| 717 |
-
$productParam = array();
|
| 718 |
-
$haveParent = false;
|
| 719 |
-
|
| 720 |
-
if (array_key_exists('parent_id', $product)) {
|
| 721 |
-
$id = $product['parent_id'];
|
| 722 |
-
$haveParent = true;
|
| 723 |
-
}
|
| 724 |
-
|
| 725 |
-
// apply special price time range
|
| 726 |
-
if (
|
| 727 |
-
!empty($product['special_price']) &&
|
| 728 |
-
$product['price'] > $product['special_price'] && (
|
| 729 |
-
!empty($product['special_from_date']) ||
|
| 730 |
-
!empty($product['special_to_date'])
|
| 731 |
-
)
|
| 732 |
-
) {
|
| 733 |
-
$product['special_price'] = Mage_Catalog_Model_Product_Type_Price::calculateSpecialPrice(
|
| 734 |
-
$product['price'],
|
| 735 |
-
$product['special_price'],
|
| 736 |
-
$product['special_from_date'],
|
| 737 |
-
$product['special_to_date'],
|
| 738 |
-
$storeObject
|
| 739 |
-
);
|
| 740 |
-
}
|
| 741 |
-
|
| 742 |
-
foreach ($attrs as $attr) {
|
| 743 |
-
self::logMem('Products - start attributes transform');
|
| 744 |
-
|
| 745 |
-
if (isset($this->_attributesValuesByName[$attr])) {
|
| 746 |
-
|
| 747 |
-
$val = array_key_exists($attr, $product) ? $this->_helperSearch->escapeString($product[$attr]) : '';
|
| 748 |
-
if ($val == null) {
|
| 749 |
-
continue;
|
| 750 |
-
}
|
| 751 |
-
|
| 752 |
-
$attr = $this->_helperSearch->sanitizeFieldName($attr);
|
| 753 |
-
|
| 754 |
-
$this->_attrProdCount[$attr] = true;
|
| 755 |
-
|
| 756 |
-
// visibility as defined in Mage_Catalog_Model_Product_Visibility:
|
| 757 |
-
// 4 - VISIBILITY_BOTH
|
| 758 |
-
// 3 - VISIBILITY_IN_SEARCH
|
| 759 |
-
// 2 - VISIBILITY_IN_CATALOG
|
| 760 |
-
// 1 - VISIBILITY_NOT_VISIBLE
|
| 761 |
-
// status as defined in Mage_Catalog_Model_Product_Status:
|
| 762 |
-
// 2 - STATUS_DISABLED
|
| 763 |
-
// 1 - STATUS_ENABLED
|
| 764 |
-
if ($attr == 'visibility' || $attr == 'status') {
|
| 765 |
-
$productParam[$attr . '_' . $lang] = $val;
|
| 766 |
-
} else {
|
| 767 |
-
fputcsv($filesMtM[$attr], array($id, $val), $this->_helperExporter->XML_DELIMITER, $this->_helperExporter->XML_ENCLOSURE);
|
| 768 |
-
}
|
| 769 |
-
|
| 770 |
-
$val = null;
|
| 771 |
-
continue;
|
| 772 |
-
}
|
| 773 |
-
|
| 774 |
-
$val = array_key_exists($attr, $product) ? $this->_helperSearch->escapeString($product[$attr]) : '';
|
| 775 |
-
switch ($attr) {
|
| 776 |
-
case 'category_ids':
|
| 777 |
-
break;
|
| 778 |
-
case 'description':
|
| 779 |
-
case 'short_description':
|
| 780 |
-
case 'name':
|
| 781 |
-
case 'status':
|
| 782 |
-
$productParam[$attr . '_' . $lang] = $val;
|
| 783 |
-
break;
|
| 784 |
-
default:
|
| 785 |
-
$productParam[$attr] = $val;
|
| 786 |
-
break;
|
| 787 |
-
}
|
| 788 |
-
self::logMem('Products - end attributes transform');
|
| 789 |
-
|
| 790 |
-
}
|
| 791 |
-
|
| 792 |
-
if ($haveParent) {
|
| 793 |
-
$product = null;
|
| 794 |
-
continue;
|
| 795 |
-
}
|
| 796 |
-
|
| 797 |
-
if (!isset($this->_transformedProducts['products'][$id])) {
|
| 798 |
-
if ($countMax > 0 && $this->_count >= $countMax) {
|
| 799 |
-
$product = null;
|
| 800 |
-
$products = null;
|
| 801 |
-
break;
|
| 802 |
-
}
|
| 803 |
-
$productParam['entity_id'] = $id;
|
| 804 |
-
$this->_transformedProducts['products'][$id] = $productParam;
|
| 805 |
-
|
| 806 |
-
// Add categories
|
| 807 |
-
if (isset($product['categories']) && count($product['categories']) > 0) {
|
| 808 |
-
foreach ($product['categories'] as $cat) {
|
| 809 |
-
|
| 810 |
-
while ($cat != null) {
|
| 811 |
-
fputcsv($filesMtM['categories'], array($id, $cat), $this->_helperExporter->XML_DELIMITER, $this->_helperExporter->XML_ENCLOSURE);
|
| 812 |
-
if (isset($this->_transformedCategories[$cat]['parent_id'])) {
|
| 813 |
-
$cat = $this->_transformedCategories[$cat]['parent_id'];
|
| 814 |
-
} else {
|
| 815 |
-
$cat = null;
|
| 816 |
-
}
|
| 817 |
-
}
|
| 818 |
-
}
|
| 819 |
-
}
|
| 820 |
-
$this->_count++;
|
| 821 |
-
$localeCount++;
|
| 822 |
-
|
| 823 |
-
// Add url to image cache
|
| 824 |
-
if ($this->_storeConfig['export_product_images']) {
|
| 825 |
-
$_product = Mage::getModel('catalog/product')->load($id);
|
| 826 |
-
$media_gallery = $_product->getMediaGallery();
|
| 827 |
-
foreach ($media_gallery['images'] as $_image) {
|
| 828 |
-
$url = $this->_helperImage->init($_product, 'image', $_image['file'])->__toString();
|
| 829 |
-
$url_tbm = $this->_helperImage->init($_product, 'thumbnail', $_image['file'])->resize(100)->__toString();
|
| 830 |
-
|
| 831 |
-
$this->_productsImages[] = array($id, $url);
|
| 832 |
-
$this->_productsThumbnails[] = array($id, $url_tbm);
|
| 833 |
-
}
|
| 834 |
-
}
|
| 835 |
-
|
| 836 |
-
} elseif (isset($this->_transformedProducts['products'][$id])) {
|
| 837 |
-
$this->_transformedProducts['products'][$id] = array_merge($this->_transformedProducts['products'][$id], $productParam);
|
| 838 |
-
}
|
| 839 |
-
|
| 840 |
-
// Add url to product for each languages
|
| 841 |
-
if ($this->_storeConfig['export_product_url']) {
|
| 842 |
-
if (array_key_exists('url_key', $product)) {
|
| 843 |
-
$url_path = $product['url_key'] . '.html';
|
| 844 |
-
} else {
|
| 845 |
-
$url_path = $this->_helperExporter->rewrittenProductUrl(
|
| 846 |
-
$id, $storeId
|
| 847 |
-
);
|
| 848 |
-
}
|
| 849 |
-
$this->_transformedProducts['products'][$id] = array_merge(
|
| 850 |
-
$this->_transformedProducts['products'][$id],
|
| 851 |
-
array('default_url_' . $lang => (
|
| 852 |
-
$storeBaseUrl . $url_path . '?___store=' . $storeCode
|
| 853 |
-
))
|
| 854 |
-
);
|
| 855 |
-
}
|
| 856 |
-
|
| 857 |
-
$productParam = null;
|
| 858 |
-
$product = null;
|
| 859 |
-
|
| 860 |
-
ksort($this->_transformedProducts['products'][$id]);
|
| 861 |
-
self::logMem('Products - end transform');
|
| 862 |
-
}
|
| 863 |
-
}
|
| 864 |
-
|
| 865 |
-
if (isset($this->_transformedProducts['products']) && count($this->_transformedProducts['products']) > 0) {
|
| 866 |
-
|
| 867 |
-
self::logMem('Products - validate names start');
|
| 868 |
-
|
| 869 |
-
$data = $this->_transformedProducts['products'];
|
| 870 |
-
|
| 871 |
-
if ($header && count($data) > 0) {
|
| 872 |
-
$data = array_merge(array(array_keys(end($data))), $data);
|
| 873 |
-
$header = false;
|
| 874 |
-
}
|
| 875 |
-
self::logMem('Products - save to file');
|
| 876 |
-
$this->savePartToCsv('products.csv', $data);
|
| 877 |
-
$data = null;
|
| 878 |
-
$this->_transformedProducts['products'] = null;
|
| 879 |
-
$this->_transformedProducts['products'] = array();
|
| 880 |
-
|
| 881 |
-
if ($this->_storeConfig['export_product_images']) {
|
| 882 |
-
self::logMem('Products - save images');
|
| 883 |
-
|
| 884 |
-
$d = $this->_productsImages;
|
| 885 |
-
$this->savePartToCsv('product_cache_image_url.csv', $d);
|
| 886 |
-
$d = null;
|
| 887 |
-
|
| 888 |
-
$d = $this->_productsThumbnails;
|
| 889 |
-
$this->savePartToCsv('product_cache_image_thumbnail_url.csv', $d);
|
| 890 |
-
$d = null;
|
| 891 |
-
$this->_productsImages = array();
|
| 892 |
-
$this->_productsThumbnails = array();
|
| 893 |
-
}
|
| 894 |
-
|
| 895 |
-
}
|
| 896 |
-
|
| 897 |
-
$page++;
|
| 898 |
-
|
| 899 |
-
$products = null;
|
| 900 |
-
|
| 901 |
-
}
|
| 902 |
-
|
| 903 |
-
$attrFDB = null;
|
| 904 |
-
$attrsFromDb = null;
|
| 905 |
-
$attrs = null;
|
| 906 |
-
$this->_transformedProducts = null;
|
| 907 |
-
$db = null;
|
| 908 |
-
|
| 909 |
-
//close file
|
| 910 |
-
foreach ($filesMtM as $f) {
|
| 911 |
-
fclose($f);
|
| 912 |
-
}
|
| 913 |
-
|
| 914 |
-
|
| 915 |
-
}
|
| 916 |
-
|
| 917 |
-
/**
|
| 918 |
-
* @description Preparing customers to export
|
| 919 |
-
* @param Mage_Core_Model_Website $website
|
| 920 |
-
* @return void
|
| 921 |
-
*
|
| 922 |
-
*/
|
| 923 |
-
protected function _exportCustomers(Mage_Core_Model_Website $website)
|
| 924 |
-
{
|
| 925 |
-
|
| 926 |
-
if (!$this->_storeConfig['export_customers']) {
|
| 927 |
-
return;
|
| 928 |
-
}
|
| 929 |
-
|
| 930 |
-
self::logMem('Customers - Countries are not loaded');
|
| 931 |
-
$countryCollection = Mage::getModel('directory/country')->getCollection();
|
| 932 |
-
self::logMem('Customers - Countries are loaded');
|
| 933 |
-
|
| 934 |
-
if ($this->_countries == null) {
|
| 935 |
-
foreach ($countryCollection as $country) {
|
| 936 |
-
$this->_countries[$country->getId()] = $country->getName();
|
| 937 |
-
}
|
| 938 |
-
}
|
| 939 |
-
$countryCollection = null;
|
| 940 |
-
|
| 941 |
-
$limit = $this->_storeConfig['export_chunk'];
|
| 942 |
-
$count = $limit;
|
| 943 |
-
$page = 1;
|
| 944 |
-
$header = true;
|
| 945 |
-
|
| 946 |
-
$attrsFromDb = array(
|
| 947 |
-
'int' => array(),
|
| 948 |
-
'static' => array(), // only supports email
|
| 949 |
-
'varchar' => array(),
|
| 950 |
-
'datetime' => array(),
|
| 951 |
-
);
|
| 952 |
-
$customer_attributes = $this->_mergeCustomerAttributes(array('dob', 'gender'));
|
| 953 |
-
|
| 954 |
-
$db = $this->_getReadAdapter();
|
| 955 |
-
$select = $db->select()
|
| 956 |
-
->from(
|
| 957 |
-
array('main_table' => $this->_prefix . 'eav_attribute'),
|
| 958 |
-
array(
|
| 959 |
-
'aid' => 'attribute_id',
|
| 960 |
-
'backend_type',
|
| 961 |
-
)
|
| 962 |
-
)
|
| 963 |
-
->joinInner(
|
| 964 |
-
array('additional_table' => $this->_prefix . 'customer_eav_attribute'),
|
| 965 |
-
'additional_table.attribute_id = main_table.attribute_id',
|
| 966 |
-
array()
|
| 967 |
-
)
|
| 968 |
-
->where('main_table.entity_type_id = ?', $this->getEntityIdFor('customer'))
|
| 969 |
-
->where('main_table.attribute_code IN (?)', $customer_attributes);
|
| 970 |
-
|
| 971 |
-
foreach ($db->fetchAll($select) as $attr) {
|
| 972 |
-
if (isset($attrsFromDb[$attr['backend_type']])) {
|
| 973 |
-
$attrsFromDb[$attr['backend_type']][] = $attr['aid'];
|
| 974 |
-
}
|
| 975 |
-
}
|
| 976 |
-
|
| 977 |
-
do {
|
| 978 |
-
self::logMem("Customers - load page $page");
|
| 979 |
-
$customers_to_save = array();
|
| 980 |
-
|
| 981 |
-
$customers = array();
|
| 982 |
-
|
| 983 |
-
$select = $db->select()
|
| 984 |
-
->from(
|
| 985 |
-
$this->_prefix . 'customer_entity',
|
| 986 |
-
array('entity_id', 'created_at', 'updated_at')
|
| 987 |
-
)
|
| 988 |
-
->where('entity_type_id = ?', '1')->limit($limit, ($page - 1) * $limit);
|
| 989 |
-
|
| 990 |
-
$this->_getIndexType() == 'delta' ? $select->where('created_at >= ? OR updated_at >= ?', $this->_getLastIndex()) : '';
|
| 991 |
-
|
| 992 |
-
foreach ($db->fetchAll($select) as $r) {
|
| 993 |
-
$customers[$r['entity_id']] = array('id' => $r['entity_id']);
|
| 994 |
-
}
|
| 995 |
-
|
| 996 |
-
$ids = array_keys($customers);
|
| 997 |
-
$columns = array(
|
| 998 |
-
'entity_id',
|
| 999 |
-
'attribute_id',
|
| 1000 |
-
'value',
|
| 1001 |
-
);
|
| 1002 |
-
|
| 1003 |
-
$select = $db->select()
|
| 1004 |
-
->where('ce.entity_type_id = ?', 1)
|
| 1005 |
-
->where('ce.entity_id IN (?)', $ids);
|
| 1006 |
-
|
| 1007 |
-
$select1 = null;
|
| 1008 |
-
$select2 = null;
|
| 1009 |
-
$select3 = null;
|
| 1010 |
-
$select4 = null;
|
| 1011 |
-
|
| 1012 |
-
$selects = array();
|
| 1013 |
-
|
| 1014 |
-
if (count($attrsFromDb['varchar']) > 0) {
|
| 1015 |
-
$select1 = clone $select;
|
| 1016 |
-
$select1->from(array('ce' => $this->_prefix . 'customer_entity_varchar'), $columns)
|
| 1017 |
-
->joinLeft(array('ea' => $this->_prefix . 'eav_attribute'), 'ce.attribute_id = ea.attribute_id', 'ea.attribute_code')
|
| 1018 |
-
->where('ce.attribute_id IN(?)', $attrsFromDb['varchar']);
|
| 1019 |
-
$selects[] = $select1;
|
| 1020 |
-
}
|
| 1021 |
-
|
| 1022 |
-
if (count($attrsFromDb['int']) > 0) {
|
| 1023 |
-
$select2 = clone $select;
|
| 1024 |
-
$select2->from(array('ce' => $this->_prefix . 'customer_entity_int'), $columns)
|
| 1025 |
-
->joinLeft(array('ea' => $this->_prefix . 'eav_attribute'), 'ce.attribute_id = ea.attribute_id', 'ea.attribute_code')
|
| 1026 |
-
->where('ce.attribute_id IN(?)', $attrsFromDb['int']);
|
| 1027 |
-
$selects[] = $select2;
|
| 1028 |
-
}
|
| 1029 |
-
|
| 1030 |
-
if (count($attrsFromDb['datetime']) > 0) {
|
| 1031 |
-
$select3 = clone $select;
|
| 1032 |
-
$select3->from(array('ce' => $this->_prefix . 'customer_entity_datetime'), $columns)
|
| 1033 |
-
->joinLeft(array('ea' => $this->_prefix . 'eav_attribute'), 'ce.attribute_id = ea.attribute_id', 'ea.attribute_code')
|
| 1034 |
-
->where('ce.attribute_id IN(?)', $attrsFromDb['datetime']);
|
| 1035 |
-
$selects[] = $select3;
|
| 1036 |
-
}
|
| 1037 |
-
|
| 1038 |
-
// only supports email
|
| 1039 |
-
if (count($attrsFromDb['static']) > 0) {
|
| 1040 |
-
$attributeId = current($attrsFromDb['static']);
|
| 1041 |
-
$select4 = clone $select
|
| 1042 |
-
->from(array('ce' => $this->_prefix . 'customer_entity'), array(
|
| 1043 |
-
'entity_id' => 'entity_id',
|
| 1044 |
-
'attribute_id' => new Zend_Db_Expr($attributeId),
|
| 1045 |
-
'value' => 'email',
|
| 1046 |
-
))
|
| 1047 |
-
->joinLeft(array('ea' => $this->_prefix . 'eav_attribute'), 'ea.attribute_id = ' . $attributeId, 'ea.attribute_code');
|
| 1048 |
-
$selects[] = $select4;
|
| 1049 |
-
}
|
| 1050 |
-
|
| 1051 |
-
$select = $db->select()
|
| 1052 |
-
->union(
|
| 1053 |
-
$selects,
|
| 1054 |
-
Zend_Db_Select::SQL_UNION_ALL
|
| 1055 |
-
);
|
| 1056 |
-
|
| 1057 |
-
foreach ($db->fetchAll($select) as $r) {
|
| 1058 |
-
$customers[$r['entity_id']][$r['attribute_code']] = $r['value'];
|
| 1059 |
-
}
|
| 1060 |
-
|
| 1061 |
-
$select = null;
|
| 1062 |
-
$select1 = null;
|
| 1063 |
-
$select2 = null;
|
| 1064 |
-
$select3 = null;
|
| 1065 |
-
$select4 = null;
|
| 1066 |
-
$selects = null;
|
| 1067 |
-
|
| 1068 |
-
$select = $db->select()
|
| 1069 |
-
->from(
|
| 1070 |
-
$this->_prefix . 'eav_attribute',
|
| 1071 |
-
array(
|
| 1072 |
-
'attribute_id',
|
| 1073 |
-
'attribute_code',
|
| 1074 |
-
)
|
| 1075 |
-
)
|
| 1076 |
-
->where('entity_type_id = ?', $this->getEntityIdFor('customer_address'))
|
| 1077 |
-
->where('attribute_code IN ("country_id","postcode")');
|
| 1078 |
-
|
| 1079 |
-
$addressAttr = array();
|
| 1080 |
-
foreach ($db->fetchAll($select) as $r) {
|
| 1081 |
-
$addressAttr[$r['attribute_id']] = $r['attribute_code'];
|
| 1082 |
-
}
|
| 1083 |
-
$addressIds = array_keys($addressAttr);
|
| 1084 |
-
|
| 1085 |
-
self::logMem('Customers - loaded page ' . $page);
|
| 1086 |
-
|
| 1087 |
-
foreach ($customers as $customer) {
|
| 1088 |
-
self::logMem('Customers - Load billing address ');
|
| 1089 |
-
$id = $customer['id'];
|
| 1090 |
-
|
| 1091 |
-
$select = $db->select()
|
| 1092 |
-
->from(
|
| 1093 |
-
$this->_prefix . 'customer_address_entity',
|
| 1094 |
-
array('entity_id')
|
| 1095 |
-
)
|
| 1096 |
-
->where('entity_type_id = ?', $this->getEntityIdFor('customer_address'))
|
| 1097 |
-
->where('parent_id = ?', $id)
|
| 1098 |
-
->order('entity_id DESC')
|
| 1099 |
-
->limit(1);
|
| 1100 |
-
|
| 1101 |
-
$select = $db->select()
|
| 1102 |
-
->from(
|
| 1103 |
-
$this->_prefix . 'customer_address_entity_varchar',
|
| 1104 |
-
array('attribute_id', 'value')
|
| 1105 |
-
)
|
| 1106 |
-
->where('entity_type_id = ?', $this->getEntityIdFor('customer_address'))
|
| 1107 |
-
->where('entity_id = ?', $select)
|
| 1108 |
-
->where('attribute_id IN(?)', $addressIds);
|
| 1109 |
-
|
| 1110 |
-
$billingResult = array();
|
| 1111 |
-
foreach ($db->fetchAll($select) as $br) {
|
| 1112 |
-
if (in_array($br['attribute_id'], $addressIds)) {
|
| 1113 |
-
$billingResult[$addressAttr[$br['attribute_id']]] = $br['value'];
|
| 1114 |
-
}
|
| 1115 |
-
}
|
| 1116 |
-
|
| 1117 |
-
$countryCode = null;
|
| 1118 |
-
if (isset($billingResult['country_id'])) {
|
| 1119 |
-
$countryCode = $billingResult['country_id'];
|
| 1120 |
-
}
|
| 1121 |
-
|
| 1122 |
-
if (array_key_exists('gender', $customer)) {
|
| 1123 |
-
if ($customer['gender'] % 2 == 0) {
|
| 1124 |
-
$customer['gender'] = 'female';
|
| 1125 |
-
} else {
|
| 1126 |
-
$customer['gender'] = 'male';
|
| 1127 |
-
}
|
| 1128 |
-
}
|
| 1129 |
-
|
| 1130 |
-
$customer_to_save = array(
|
| 1131 |
-
'customer_id' => $id,
|
| 1132 |
-
'country' => !empty($countryCode) ? $this->_helperExporter->getCountry($countryCode)->getName() : '',
|
| 1133 |
-
'zip' => array_key_exists('postcode', $billingResult) ? $billingResult['postcode'] : '',
|
| 1134 |
-
);
|
| 1135 |
-
foreach($customer_attributes as $attr) {
|
| 1136 |
-
$customer_to_save[$attr] = array_key_exists($attr, $customer) ? $customer[$attr] : '';
|
| 1137 |
-
}
|
| 1138 |
-
$customers_to_save[] = $customer_to_save;
|
| 1139 |
-
}
|
| 1140 |
-
|
| 1141 |
-
$data = $customers_to_save;
|
| 1142 |
-
|
| 1143 |
-
if (count($customers) == 0 && $header) {
|
| 1144 |
-
return null;
|
| 1145 |
-
}
|
| 1146 |
-
|
| 1147 |
-
if ($header) {
|
| 1148 |
-
$data = array_merge(array(array_keys(end($customers_to_save))), $customers_to_save);
|
| 1149 |
-
$header = false;
|
| 1150 |
-
}
|
| 1151 |
-
self::logMem('Customers - save to file');
|
| 1152 |
-
$this->savePartToCsv('customers.csv', $data);
|
| 1153 |
-
$data = null;
|
| 1154 |
-
|
| 1155 |
-
$count = count($customers_to_save);
|
| 1156 |
-
$page++;
|
| 1157 |
-
|
| 1158 |
-
} while ($count >= $limit);
|
| 1159 |
-
$customers = null;
|
| 1160 |
-
|
| 1161 |
-
self::logMem('Customers - end of exporting');
|
| 1162 |
-
}
|
| 1163 |
-
|
| 1164 |
-
/**
|
| 1165 |
-
* @description Preparing transactions to export
|
| 1166 |
-
* @return void
|
| 1167 |
-
*/
|
| 1168 |
-
protected function _exportTransactions()
|
| 1169 |
-
{
|
| 1170 |
-
if (!$this->_storeConfig['export_transactions']) {
|
| 1171 |
-
return;
|
| 1172 |
-
}
|
| 1173 |
-
|
| 1174 |
-
self::logMem('Transactions - start of export');
|
| 1175 |
-
$db = $this->_getReadAdapter();
|
| 1176 |
-
|
| 1177 |
-
$limit = $this->_storeConfig['export_chunk'];
|
| 1178 |
-
$count = $limit;
|
| 1179 |
-
$page = 1;
|
| 1180 |
-
$header = true;
|
| 1181 |
-
|
| 1182 |
-
while ($count >= $limit) {
|
| 1183 |
-
self::logMem('Transactions - load page ' . $page);
|
| 1184 |
-
$transactions_to_save = array();
|
| 1185 |
-
$configurable = array();
|
| 1186 |
-
|
| 1187 |
-
$select = $db
|
| 1188 |
-
->select()
|
| 1189 |
-
->from(
|
| 1190 |
-
array('order' => $this->_prefix . 'sales_flat_order'),
|
| 1191 |
-
array(
|
| 1192 |
-
'entity_id',
|
| 1193 |
-
'status',
|
| 1194 |
-
'updated_at',
|
| 1195 |
-
'created_at',
|
| 1196 |
-
'customer_id',
|
| 1197 |
-
'base_subtotal',
|
| 1198 |
-
'shipping_amount',
|
| 1199 |
-
)
|
| 1200 |
-
)
|
| 1201 |
-
->joinLeft(
|
| 1202 |
-
array('item' => $this->_prefix . 'sales_flat_order_item'),
|
| 1203 |
-
'order.entity_id = item.order_id',
|
| 1204 |
-
array(
|
| 1205 |
-
'product_id',
|
| 1206 |
-
'product_options',
|
| 1207 |
-
'price',
|
| 1208 |
-
'original_price',
|
| 1209 |
-
'product_type',
|
| 1210 |
-
'qty_ordered',
|
| 1211 |
-
)
|
| 1212 |
-
)
|
| 1213 |
-
->where('order.status <> ?', 'canceled')
|
| 1214 |
-
->order(array('order.entity_id', 'item.product_type'))
|
| 1215 |
-
->limit($limit, ($page - 1) * $limit);
|
| 1216 |
-
|
| 1217 |
-
$this->_getIndexType() == 'delta' ? $select->where('order.created_at >= ? OR order.updated_at >= ?', $this->_getLastIndex()) : '';
|
| 1218 |
-
|
| 1219 |
-
$transactions = $db->fetchAll($select);
|
| 1220 |
-
self::logMem("Transactions - loaded page $page");
|
| 1221 |
-
|
| 1222 |
-
foreach ($transactions as $transaction) {
|
| 1223 |
-
//is configurable
|
| 1224 |
-
if ($transaction['product_type'] == 'configurable') {
|
| 1225 |
-
$configurable[$transaction['product_id']] = $transaction;
|
| 1226 |
-
continue;
|
| 1227 |
-
}
|
| 1228 |
-
|
| 1229 |
-
$productOptions = unserialize($transaction['product_options']);
|
| 1230 |
-
|
| 1231 |
-
//is configurable - simple product
|
| 1232 |
-
if (intval($transaction['price']) == 0 && $transaction['product_type'] == 'simple') {
|
| 1233 |
-
if (isset($configurable[$productOptions['info_buyRequest']['product']])) {
|
| 1234 |
-
$pid = $configurable[$productOptions['info_buyRequest']['product']];
|
| 1235 |
-
|
| 1236 |
-
$transaction['original_price'] = $pid['original_price'];
|
| 1237 |
-
$transaction['price'] = $pid['price'];
|
| 1238 |
-
} else {
|
| 1239 |
-
$pid = Mage::getModel('catalog/product')->load($productOptions['info_buyRequest']['product']);
|
| 1240 |
-
|
| 1241 |
-
$transaction['original_price'] = ($pid->getPrice());
|
| 1242 |
-
$transaction['price'] = ($pid->getPrice());
|
| 1243 |
-
|
| 1244 |
-
$tmp = array();
|
| 1245 |
-
$tmp['original_price'] = $transaction['original_price'];
|
| 1246 |
-
$tmp['price'] = $transaction['price'];
|
| 1247 |
-
|
| 1248 |
-
$configurable[$productOptions['info_buyRequest']['product']] = $tmp;
|
| 1249 |
-
|
| 1250 |
-
$pid = null;
|
| 1251 |
-
$tmp = null;
|
| 1252 |
-
}
|
| 1253 |
-
}
|
| 1254 |
-
|
| 1255 |
-
$status = 0; // 0 - pending, 1 - confirmed, 2 - shipping
|
| 1256 |
-
if ($transaction['updated_at'] != $transaction['created_at']) {
|
| 1257 |
-
switch ($transaction['status']) {
|
| 1258 |
-
case 'canceled':
|
| 1259 |
-
continue;
|
| 1260 |
-
break;
|
| 1261 |
-
case 'processing':
|
| 1262 |
-
$status = 1;
|
| 1263 |
-
break;
|
| 1264 |
-
case 'complete':
|
| 1265 |
-
$status = 2;
|
| 1266 |
-
break;
|
| 1267 |
-
}
|
| 1268 |
-
}
|
| 1269 |
-
|
| 1270 |
-
$transactions_to_save[] = array(
|
| 1271 |
-
'order_id' => $transaction['entity_id'],
|
| 1272 |
-
'entity_id' => $transaction['product_id'],
|
| 1273 |
-
'customer_id' => array_key_exists('customer_id', $transaction) ? $transaction['customer_id'] : '',
|
| 1274 |
-
'price' => $transaction['original_price'],
|
| 1275 |
-
'discounted_price' => $transaction['price'],
|
| 1276 |
-
'quantity' => $transaction['qty_ordered'],
|
| 1277 |
-
'total_order_value' => ($transaction['base_subtotal'] + $transaction['shipping_amount']),
|
| 1278 |
-
'shipping_costs' => $transaction['shipping_amount'],
|
| 1279 |
-
'order_date' => $transaction['created_at'],
|
| 1280 |
-
'confirmation_date' => $status == 1 ? $transaction['updated_at'] : null,
|
| 1281 |
-
'shipping_date' => $status == 2 ? $transaction['updated_at'] : null,
|
| 1282 |
-
'status' => $transaction['status'],
|
| 1283 |
-
);
|
| 1284 |
-
}
|
| 1285 |
-
|
| 1286 |
-
$data = $transactions_to_save;
|
| 1287 |
-
$count = count($transactions);
|
| 1288 |
-
|
| 1289 |
-
$configurable = null;
|
| 1290 |
-
$transactions = null;
|
| 1291 |
-
|
| 1292 |
-
if ($count == 0 && $header) {
|
| 1293 |
-
return;
|
| 1294 |
-
}
|
| 1295 |
-
|
| 1296 |
-
if ($header) {
|
| 1297 |
-
$data = array_merge(array(array_keys(end($transactions_to_save))), $transactions_to_save);
|
| 1298 |
-
$header = false;
|
| 1299 |
-
}
|
| 1300 |
-
|
| 1301 |
-
self::logMem('Transactions - save to file');
|
| 1302 |
-
$this->savePartToCsv('transactions.csv', $data);
|
| 1303 |
-
$data = null;
|
| 1304 |
-
|
| 1305 |
-
$page++;
|
| 1306 |
-
|
| 1307 |
-
}
|
| 1308 |
-
|
| 1309 |
-
self::logMem('Transactions - end of export');
|
| 1310 |
-
}
|
| 1311 |
-
|
| 1312 |
-
/**
|
| 1313 |
-
* @return string Index type
|
| 1314 |
-
*/
|
| 1315 |
-
protected function _getIndexType()
|
| 1316 |
-
{
|
| 1317 |
-
return static::INDEX_TYPE; // access via late static binding (PHP 5.3)
|
| 1318 |
-
}
|
| 1319 |
-
|
| 1320 |
-
/**
|
| 1321 |
-
* @description Preparing files to send
|
| 1322 |
-
*/
|
| 1323 |
-
protected function prepareFiles(&$categories = null, &$tags = null)
|
| 1324 |
-
{
|
| 1325 |
-
|
| 1326 |
-
//Prepare attributes
|
| 1327 |
-
$csvFiles = array();
|
| 1328 |
-
if (!file_exists($this->_dir)) {
|
| 1329 |
-
mkdir($this->_dir);
|
| 1330 |
-
}
|
| 1331 |
-
|
| 1332 |
-
//create csvs
|
| 1333 |
-
//save attributes
|
| 1334 |
-
foreach ($this->_attributesValuesByName as $attrName => $attrValues) {
|
| 1335 |
-
$csvFiles[] = $this->createCsv($this->_helperSearch->sanitizeFieldName($attrName), $attrValues);
|
| 1336 |
-
}
|
| 1337 |
-
|
| 1338 |
-
//save categories
|
| 1339 |
-
if ($categories != null) {
|
| 1340 |
-
$csvFiles[] = $this->createCsv('categories', $categories);
|
| 1341 |
-
$categories = null;
|
| 1342 |
-
}
|
| 1343 |
-
|
| 1344 |
-
//save tags
|
| 1345 |
-
if ($tags != null && $this->_getProductTags() != null) {
|
| 1346 |
-
$csvFiles[] = $this->createCsv('tag', $tags);
|
| 1347 |
-
|
| 1348 |
-
$loop = 1;
|
| 1349 |
-
foreach ($this->_getProductTags() as $product_id => $tag_id) {
|
| 1350 |
-
$csvdata[] = array('id' => $loop++, 'entity_id' => $product_id, 'tag_id' => $tag_id);
|
| 1351 |
-
}
|
| 1352 |
-
|
| 1353 |
-
$csvFiles[] = $this->createCsv('product_tag', $csvdata);
|
| 1354 |
-
}
|
| 1355 |
-
//csvs done
|
| 1356 |
-
|
| 1357 |
-
//Create name for file
|
| 1358 |
-
$exportFile = $this->_dir . '/' . $this->_storeConfig['di_username'];
|
| 1359 |
-
$csvFiles = array_filter($csvFiles);
|
| 1360 |
-
|
| 1361 |
-
//Create xml
|
| 1362 |
-
$this->createXML($exportFile . '.xml', ($tags != null && $this->_getProductTags() != null) ? true : false);
|
| 1363 |
-
|
| 1364 |
-
//Create zip
|
| 1365 |
-
$this->createZip($exportFile . '.zip', array_filter($this->_files), $exportFile . '.xml');
|
| 1366 |
-
|
| 1367 |
-
return $exportFile;
|
| 1368 |
-
}
|
| 1369 |
-
|
| 1370 |
-
/**
|
| 1371 |
-
* @param $name
|
| 1372 |
-
* @param $data
|
| 1373 |
-
* @return string
|
| 1374 |
-
*/
|
| 1375 |
-
protected function createCsv($name, &$data)
|
| 1376 |
-
{
|
| 1377 |
-
$file = $name . '.csv';
|
| 1378 |
-
|
| 1379 |
-
if (!is_array($data) || count($data) == 0) {
|
| 1380 |
-
Mage::getModel('adminhtml/session')->addWarning("Data for $file is not an array or is empty. [" . gettype($data) . ']');
|
| 1381 |
-
}
|
| 1382 |
-
|
| 1383 |
-
$csvdata = array_merge(array(array_keys(end($data))), $data);
|
| 1384 |
-
$csvdata[0][0] = $this->_helperSearch->sanitizeFieldName($csvdata[0][0]);
|
| 1385 |
-
|
| 1386 |
-
$fh = fopen($this->_dir . '/' . $file, 'a');
|
| 1387 |
-
foreach ($csvdata as $dataRow) {
|
| 1388 |
-
fputcsv($fh, $dataRow, $this->_helperExporter->XML_DELIMITER, $this->_helperExporter->XML_ENCLOSURE);
|
| 1389 |
-
}
|
| 1390 |
-
fclose($fh);
|
| 1391 |
-
|
| 1392 |
-
$this->_files[] = $file;
|
| 1393 |
-
|
| 1394 |
-
return $file;
|
| 1395 |
-
}
|
| 1396 |
-
|
| 1397 |
-
/**
|
| 1398 |
-
* @description Get list of products with their tags
|
| 1399 |
-
* @return object List of products with their tags array('product_id' => 'tag_id');
|
| 1400 |
-
*/
|
| 1401 |
-
protected function _getProductTags()
|
| 1402 |
-
{
|
| 1403 |
-
if (empty($this->_allProductTags)) {
|
| 1404 |
-
$tags = Mage::getResourceModel('tag/product_collection')->getData();
|
| 1405 |
-
foreach ($tags as $tag) {
|
| 1406 |
-
$this->_allProductTags[$tag['entity_id']] = $tag['tag_id'];
|
| 1407 |
-
}
|
| 1408 |
-
$tags = null;
|
| 1409 |
-
}
|
| 1410 |
-
|
| 1411 |
-
return $this->_allProductTags;
|
| 1412 |
-
}
|
| 1413 |
-
|
| 1414 |
-
protected function createXML($name, $withTag)
|
| 1415 |
-
{
|
| 1416 |
-
|
| 1417 |
-
$xml = new SimpleXMLElement('<root/>');
|
| 1418 |
-
|
| 1419 |
-
$languages = $xml->addChild('languages');
|
| 1420 |
-
$containers = $xml->addChild('containers');
|
| 1421 |
-
|
| 1422 |
-
//languages
|
| 1423 |
-
foreach ($this->_availableLanguages as $lang) {
|
| 1424 |
-
$language = $languages->addChild('language');
|
| 1425 |
-
$language->addAttribute('id', $lang);
|
| 1426 |
-
}
|
| 1427 |
-
|
| 1428 |
-
//product
|
| 1429 |
-
$products = $containers->addChild('container');
|
| 1430 |
-
$products->addAttribute('id', 'products');
|
| 1431 |
-
$products->addAttribute('type', 'products');
|
| 1432 |
-
|
| 1433 |
-
$sources = $products->addChild('sources');
|
| 1434 |
-
//#########################################################################
|
| 1435 |
-
|
| 1436 |
-
//product source
|
| 1437 |
-
$source = $sources->addChild('source');
|
| 1438 |
-
$source->addAttribute('id', 'item_vals');
|
| 1439 |
-
$source->addAttribute('type', 'item_data_file');
|
| 1440 |
-
|
| 1441 |
-
$source->addChild('file')->addAttribute('value', 'products.csv');
|
| 1442 |
-
$source->addChild('itemIdColumn')->addAttribute('value', 'entity_id');
|
| 1443 |
-
|
| 1444 |
-
$this->sxml_append_options($source);
|
| 1445 |
-
//#########################################################################
|
| 1446 |
-
|
| 1447 |
-
$attrs = array_keys($this->_attributesValuesByName);
|
| 1448 |
-
if ($this->_storeConfig['export_tags'] && $withTag) {
|
| 1449 |
-
$attrs[] = 'tag';
|
| 1450 |
-
|
| 1451 |
-
}
|
| 1452 |
-
|
| 1453 |
-
foreach ($attrs as $attr) {
|
| 1454 |
-
if ($attr == 'visibility' || $attr == 'status') {
|
| 1455 |
-
continue;
|
| 1456 |
-
}
|
| 1457 |
-
$attr = $this->_helperSearch->sanitizeFieldName($attr);
|
| 1458 |
-
|
| 1459 |
-
//attribute
|
| 1460 |
-
$source = $sources->addChild('source');
|
| 1461 |
-
$source->addAttribute('type', 'resource');
|
| 1462 |
-
$source->addAttribute('id', 'resource_' . $attr);
|
| 1463 |
-
|
| 1464 |
-
$source->addChild('file')->addAttribute('value', $attr . '.csv');
|
| 1465 |
-
$source->addChild('referenceIdColumn')->addAttribute('value', $attr . '_id');
|
| 1466 |
-
$source->addChild('itemIdColumn')->addAttribute('value', $attr . '_id');
|
| 1467 |
-
|
| 1468 |
-
$labelColumns = $source->addChild('labelColumns');
|
| 1469 |
-
foreach ($this->_availableLanguages as $lang) {
|
| 1470 |
-
$label = $labelColumns->addChild('language');
|
| 1471 |
-
$label->addAttribute('name', $lang);
|
| 1472 |
-
$label->addAttribute('value', 'value_' . $lang);
|
| 1473 |
-
}
|
| 1474 |
-
|
| 1475 |
-
$this->sxml_append_options($source);
|
| 1476 |
-
|
| 1477 |
-
//product & attribute
|
| 1478 |
-
$source = $sources->addChild('source');
|
| 1479 |
-
$source->addAttribute('type', 'item_data_file');
|
| 1480 |
-
$source->addAttribute('id', 'item_' . $attr);
|
| 1481 |
-
|
| 1482 |
-
$source->addChild('file')->addAttribute('value', 'product_' . $attr . '.csv');
|
| 1483 |
-
$source->addChild('itemIdColumn')->addAttribute('value', 'entity_id');
|
| 1484 |
-
|
| 1485 |
-
$this->sxml_append_options($source);
|
| 1486 |
-
|
| 1487 |
-
}
|
| 1488 |
-
|
| 1489 |
-
//########################################################################
|
| 1490 |
-
if ($this->_storeConfig['export_categories']) {
|
| 1491 |
-
//categories
|
| 1492 |
-
$sourceCategory = $sources->addChild('source');
|
| 1493 |
-
$sourceCategory->addAttribute('type', 'hierarchical');
|
| 1494 |
-
$sourceCategory->addAttribute('id', 'resource_categories');
|
| 1495 |
-
|
| 1496 |
-
|
| 1497 |
-
$sourceCategory->addChild('file')->addAttribute('value', 'categories.csv');
|
| 1498 |
-
$sourceCategory->addChild('referenceIdColumn')->addAttribute('value', 'category_id');
|
| 1499 |
-
$sourceCategory->addChild('parentIdColumn')->addAttribute('value', 'parent_id');
|
| 1500 |
-
|
| 1501 |
-
$labelColumns = $sourceCategory->addChild('labelColumns');
|
| 1502 |
-
foreach ($this->_availableLanguages as $lang) {
|
| 1503 |
-
$label = $labelColumns->addChild('language');
|
| 1504 |
-
$label->addAttribute('name', $lang);
|
| 1505 |
-
$label->addAttribute('value', 'value_' . $lang);
|
| 1506 |
-
}
|
| 1507 |
-
|
| 1508 |
-
$this->sxml_append_options($sourceCategory);
|
| 1509 |
-
|
| 1510 |
-
//categories & products
|
| 1511 |
-
$source = $sources->addChild('source');
|
| 1512 |
-
$source->addAttribute('type', 'item_data_file');
|
| 1513 |
-
$source->addAttribute('id', 'item_categories');
|
| 1514 |
-
|
| 1515 |
-
|
| 1516 |
-
$source->addChild('file')->addAttribute('value', 'product_categories.csv');
|
| 1517 |
-
$source->addChild('itemIdColumn')->addAttribute('value', 'entity_id');
|
| 1518 |
-
|
| 1519 |
-
$this->sxml_append_options($source);
|
| 1520 |
-
}
|
| 1521 |
-
//#########################################################################
|
| 1522 |
-
|
| 1523 |
-
//########################################################################
|
| 1524 |
-
// IMAGES
|
| 1525 |
-
if ($this->_storeConfig['export_product_images']) {
|
| 1526 |
-
|
| 1527 |
-
//categories & products images
|
| 1528 |
-
$source = $sources->addChild('source');
|
| 1529 |
-
$source->addAttribute('type', 'item_data_file');
|
| 1530 |
-
$source->addAttribute('id', 'item_cache_image_url');
|
| 1531 |
-
|
| 1532 |
-
$source->addChild('file')->addAttribute('value', 'product_cache_image_url.csv');
|
| 1533 |
-
$source->addChild('itemIdColumn')->addAttribute('value', 'entity_id');
|
| 1534 |
-
|
| 1535 |
-
$this->sxml_append_options($source);
|
| 1536 |
-
}
|
| 1537 |
-
if ($this->_storeConfig['export_product_images_thumbnail']) {
|
| 1538 |
-
|
| 1539 |
-
//categories & products images
|
| 1540 |
-
$source = $sources->addChild('source');
|
| 1541 |
-
$source->addAttribute('type', 'item_data_file');
|
| 1542 |
-
$source->addAttribute('id', 'item_cache_image_thumbnail_url');
|
| 1543 |
-
|
| 1544 |
-
$source->addChild('file')->addAttribute('value', 'product_cache_image_thumbnail_url.csv');
|
| 1545 |
-
$source->addChild('itemIdColumn')->addAttribute('value', 'entity_id');
|
| 1546 |
-
|
| 1547 |
-
$this->sxml_append_options($source);
|
| 1548 |
-
}
|
| 1549 |
-
//#########################################################################
|
| 1550 |
-
|
| 1551 |
-
//property
|
| 1552 |
-
$properties = $products->addChild('properties');
|
| 1553 |
-
$props = $this->prepareProperties($withTag);
|
| 1554 |
-
|
| 1555 |
-
foreach ($props as $prop) {
|
| 1556 |
-
if ($prop['id'] == 'entity_id') {
|
| 1557 |
-
|
| 1558 |
-
}
|
| 1559 |
-
|
| 1560 |
-
$property = $properties->addChild('property');
|
| 1561 |
-
$property->addAttribute('id', $this->_helperSearch->sanitizeFieldName($prop['id']));
|
| 1562 |
-
$property->addAttribute('type', $prop['ptype']);
|
| 1563 |
-
|
| 1564 |
-
$transform = $property->addChild('transform');
|
| 1565 |
-
$logic = $transform->addChild('logic');
|
| 1566 |
-
$ls = $prop['name'] == null ? 'item_vals' : 'item_' . $prop['name'];
|
| 1567 |
-
$logic->addAttribute('source', $this->_helperSearch->sanitizeFieldName($ls));
|
| 1568 |
-
$logic->addAttribute('type', $prop['type']);
|
| 1569 |
-
if ($prop['has_lang'] == true) {
|
| 1570 |
-
foreach ($this->_availableLanguages as $lang) {
|
| 1571 |
-
$field = $logic->addChild('field');
|
| 1572 |
-
$field->addAttribute('column', $this->_helperSearch->sanitizeFieldName($prop['field']) . '_' . $lang);
|
| 1573 |
-
$field->addAttribute('language', $lang);
|
| 1574 |
-
}
|
| 1575 |
-
} else {
|
| 1576 |
-
$logic->addChild('field')->addAttribute('column', $this->_helperSearch->sanitizeFieldName($prop['field']));
|
| 1577 |
-
}
|
| 1578 |
-
|
| 1579 |
-
$params = $property->addChild('params');
|
| 1580 |
-
if ($prop['type'] != 'direct') {
|
| 1581 |
-
$params->addChild('referenceSource')->addAttribute('value', 'resource_' . $this->_helperSearch->sanitizeFieldName($prop['reference']));
|
| 1582 |
-
}
|
| 1583 |
-
|
| 1584 |
-
}
|
| 1585 |
-
//##################################
|
| 1586 |
-
|
| 1587 |
-
//##################################
|
| 1588 |
-
|
| 1589 |
-
if ($this->_storeConfig['export_customers']) {
|
| 1590 |
-
$customers = $containers->addChild('container');
|
| 1591 |
-
$customers->addAttribute('id', 'customers');
|
| 1592 |
-
$customers->addAttribute('type', 'customers');
|
| 1593 |
-
|
| 1594 |
-
$sources = $customers->addChild('sources');
|
| 1595 |
-
//#########################################################################
|
| 1596 |
-
|
| 1597 |
-
//customer source
|
| 1598 |
-
$source = $sources->addChild('source');
|
| 1599 |
-
$source->addAttribute('id', 'customer_vals');
|
| 1600 |
-
$source->addAttribute('type', 'item_data_file');
|
| 1601 |
-
|
| 1602 |
-
$source->addChild('file')->addAttribute('value', 'customers.csv');
|
| 1603 |
-
$source->addChild('itemIdColumn')->addAttribute('value', 'customer_id');
|
| 1604 |
-
|
| 1605 |
-
$this->sxml_append_options($source);
|
| 1606 |
-
//#########################################################################
|
| 1607 |
-
|
| 1608 |
-
$properties = $customers->addChild('properties');
|
| 1609 |
-
foreach (
|
| 1610 |
-
$this->_mergeCustomerAttributes(
|
| 1611 |
-
array('id', 'customer_id', 'country', 'zip', 'dob', 'gender')
|
| 1612 |
-
) as $prop
|
| 1613 |
-
) {
|
| 1614 |
-
$type = 'string';
|
| 1615 |
-
$column = $prop;
|
| 1616 |
-
switch($prop) {
|
| 1617 |
-
case 'id':
|
| 1618 |
-
$type = 'id';
|
| 1619 |
-
$column = 'customer_id';
|
| 1620 |
-
break;
|
| 1621 |
-
case 'dob':
|
| 1622 |
-
$type = 'date';
|
| 1623 |
-
break;
|
| 1624 |
-
}
|
| 1625 |
-
|
| 1626 |
-
$property = $properties->addChild('property');
|
| 1627 |
-
$property->addAttribute('id', $prop);
|
| 1628 |
-
$property->addAttribute('type', $type);
|
| 1629 |
-
|
| 1630 |
-
$transform = $property->addChild('transform');
|
| 1631 |
-
|
| 1632 |
-
$logic = $transform->addChild('logic');
|
| 1633 |
-
$logic->addAttribute('source', 'customer_vals');
|
| 1634 |
-
$logic->addAttribute('type', 'direct');
|
| 1635 |
-
$logic->addChild('field')->addAttribute('column', $column);
|
| 1636 |
-
|
| 1637 |
-
$property->addChild('params');
|
| 1638 |
-
}
|
| 1639 |
-
}
|
| 1640 |
-
|
| 1641 |
-
if ($this->_storeConfig['export_transactions']) {
|
| 1642 |
-
$transactions = $containers->addChild('container');
|
| 1643 |
-
$transactions->addAttribute('id', 'transactions');
|
| 1644 |
-
$transactions->addAttribute('type', 'transactions');
|
| 1645 |
-
|
| 1646 |
-
$sources = $transactions->addChild('sources');
|
| 1647 |
-
//#########################################################################
|
| 1648 |
-
|
| 1649 |
-
//transaction source
|
| 1650 |
-
$source = $sources->addChild('source');
|
| 1651 |
-
$source->addAttribute('id', 'transactions');
|
| 1652 |
-
$source->addAttribute('type', 'transactions');
|
| 1653 |
-
|
| 1654 |
-
$source->addChild('file')->addAttribute('value', 'transactions.csv');
|
| 1655 |
-
$source->addChild('orderIdColumn')->addAttribute('value', 'order_id');
|
| 1656 |
-
$customerIdColumn = $source->addChild('customerIdColumn');
|
| 1657 |
-
$customerIdColumn->addAttribute('value', 'customer_id');
|
| 1658 |
-
$customerIdColumn->addAttribute('customer_property_id', 'customer_id');
|
| 1659 |
-
$productIdColumn = $source->addChild('productIdColumn');
|
| 1660 |
-
$productIdColumn->addAttribute('value', 'entity_id');
|
| 1661 |
-
$productIdColumn->addAttribute('product_property_id', 'product_entity_id');
|
| 1662 |
-
$source->addChild('productListPriceColumn')->addAttribute('value', 'price');
|
| 1663 |
-
$source->addChild('productDiscountedPriceColumn')->addAttribute('value', 'discounted_price');
|
| 1664 |
-
$source->addChild('totalOrderValueColumn')->addAttribute('value', 'total_order_value');
|
| 1665 |
-
$source->addChild('shippingCostsColumn')->addAttribute('value', 'shipping_costs');
|
| 1666 |
-
$source->addChild('orderReceptionDateColumn')->addAttribute('value', 'order_date');
|
| 1667 |
-
$source->addChild('orderConfirmationDateColumn')->addAttribute('value', 'confirmation_date');
|
| 1668 |
-
$source->addChild('orderShippingDateColumn')->addAttribute('value', 'shipping_date');
|
| 1669 |
-
$source->addChild('orderStatusColumn')->addAttribute('value', 'status');
|
| 1670 |
-
|
| 1671 |
-
$this->sxml_append_options($source);
|
| 1672 |
-
//#########################################################################
|
| 1673 |
-
}
|
| 1674 |
-
|
| 1675 |
-
$dom = new DOMDocument('1.0');
|
| 1676 |
-
$dom->preserveWhiteSpace = false;
|
| 1677 |
-
$dom->formatOutput = true;
|
| 1678 |
-
$dom->loadXML($xml->asXML());
|
| 1679 |
-
$saveXML = $dom->saveXML();
|
| 1680 |
-
file_put_contents($name, $saveXML);
|
| 1681 |
-
}
|
| 1682 |
-
|
| 1683 |
-
/**
|
| 1684 |
-
* @desciption add default xmlElements
|
| 1685 |
-
* @param SimpleXMLElement $xml
|
| 1686 |
-
*/
|
| 1687 |
-
protected function sxml_append_options(SimpleXMLElement &$xml)
|
| 1688 |
-
{
|
| 1689 |
-
$xml->addChild('format')->addAttribute('value', $this->_helperExporter->XML_FORMAT);
|
| 1690 |
-
$xml->addChild('encoding')->addAttribute('value', $this->_helperExporter->XML_ENCODE);
|
| 1691 |
-
$xml->addChild('delimiter')->addAttribute('value', $this->_helperExporter->XML_DELIMITER);
|
| 1692 |
-
$xml->addChild('enclosure')->addAttribute('value', $this->_helperExporter->XML_ENCLOSURE);
|
| 1693 |
-
$xml->addChild('escape')->addAttribute('value', $this->_helperExporter->XML_ESCAPE);
|
| 1694 |
-
$xml->addChild('lineSeparator')->addAttribute('value', $this->_helperExporter->XML_NEWLINE);
|
| 1695 |
-
}
|
| 1696 |
-
|
| 1697 |
-
/**
|
| 1698 |
-
* @return array
|
| 1699 |
-
*/
|
| 1700 |
-
protected function prepareProperties($withTag)
|
| 1701 |
-
{
|
| 1702 |
-
|
| 1703 |
-
$properties = array();
|
| 1704 |
-
|
| 1705 |
-
$attrs = $this->_listOfAttributes;
|
| 1706 |
-
|
| 1707 |
-
if ($this->_storeConfig['export_product_url']) {
|
| 1708 |
-
$attrs[] = 'default_url';
|
| 1709 |
-
}
|
| 1710 |
-
|
| 1711 |
-
foreach ($attrs as $attr) {
|
| 1712 |
-
// set property type
|
| 1713 |
-
switch ($attr) {
|
| 1714 |
-
case 'category_ids':
|
| 1715 |
-
continue 2;
|
| 1716 |
-
case 'name':
|
| 1717 |
-
$ptype = 'title';
|
| 1718 |
-
break;
|
| 1719 |
-
case 'description':
|
| 1720 |
-
$ptype = 'body';
|
| 1721 |
-
break;
|
| 1722 |
-
case 'price':
|
| 1723 |
-
$ptype = 'price';
|
| 1724 |
-
break;
|
| 1725 |
-
case 'special_price':
|
| 1726 |
-
$ptype = 'discounted';
|
| 1727 |
-
break;
|
| 1728 |
-
case 'entity_id':
|
| 1729 |
-
$ptype = 'id';
|
| 1730 |
-
break;
|
| 1731 |
-
case 'short_description':
|
| 1732 |
-
case 'status':
|
| 1733 |
-
case 'visibility':
|
| 1734 |
-
case 'default_url':
|
| 1735 |
-
$ptype = 'text';
|
| 1736 |
-
break;
|
| 1737 |
-
case 'weight':
|
| 1738 |
-
case 'width':
|
| 1739 |
-
case 'height':
|
| 1740 |
-
case 'length':
|
| 1741 |
-
$ptype = 'number';
|
| 1742 |
-
break;
|
| 1743 |
-
default:
|
| 1744 |
-
$ptype = 'string';
|
| 1745 |
-
}
|
| 1746 |
-
|
| 1747 |
-
if (isset($this->_attributesValuesByName[$attr]) && $attr != 'visibility' && $attr != 'status') {
|
| 1748 |
-
$properties[] = array(
|
| 1749 |
-
'id' => $attr,
|
| 1750 |
-
'name' => $attr,
|
| 1751 |
-
'ptype' => 'text',
|
| 1752 |
-
'type' => 'reference',
|
| 1753 |
-
'field' => $attr . '_id',
|
| 1754 |
-
'has_lang' => false,
|
| 1755 |
-
'reference' => $attr
|
| 1756 |
-
);
|
| 1757 |
-
} else {
|
| 1758 |
-
$ref = null;
|
| 1759 |
-
$type = 'direct';
|
| 1760 |
-
$field = $attr;
|
| 1761 |
-
switch ($attr) {
|
| 1762 |
-
case 'description':
|
| 1763 |
-
case 'short_description':
|
| 1764 |
-
case 'visibility':
|
| 1765 |
-
case 'status':
|
| 1766 |
-
case 'name':
|
| 1767 |
-
case 'default_url':
|
| 1768 |
-
$lang = true;
|
| 1769 |
-
break;
|
| 1770 |
-
default:
|
| 1771 |
-
$lang = false;
|
| 1772 |
-
}
|
| 1773 |
-
$properties[] = array(
|
| 1774 |
-
'id' => $attr,
|
| 1775 |
-
'name' => null,
|
| 1776 |
-
'ptype' => $ptype,
|
| 1777 |
-
'type' => $type,
|
| 1778 |
-
'field' => $field,
|
| 1779 |
-
'has_lang' => $lang,
|
| 1780 |
-
'reference' => $ref
|
| 1781 |
-
);
|
| 1782 |
-
}
|
| 1783 |
-
}
|
| 1784 |
-
//tag
|
| 1785 |
-
if ($this->_storeConfig['export_tags'] && $withTag) {
|
| 1786 |
-
$properties[] = array(
|
| 1787 |
-
'id' => 'tag',
|
| 1788 |
-
'name' => 'tag',
|
| 1789 |
-
'ptype' => 'text',
|
| 1790 |
-
'type' => 'reference',
|
| 1791 |
-
'field' => 'tag_id',
|
| 1792 |
-
'has_lang' => false,
|
| 1793 |
-
'reference' => 'tag'
|
| 1794 |
-
);
|
| 1795 |
-
}
|
| 1796 |
-
|
| 1797 |
-
//categories
|
| 1798 |
-
if ($this->_storeConfig['export_categories']) {
|
| 1799 |
-
$properties[] = array(
|
| 1800 |
-
'id' => 'category',
|
| 1801 |
-
'name' => 'categories', //property id
|
| 1802 |
-
'ptype' => 'hierarchical', //property type
|
| 1803 |
-
'type' => 'reference', //logic type
|
| 1804 |
-
'field' => 'category_id', //field colummn
|
| 1805 |
-
'has_lang' => false,
|
| 1806 |
-
'reference' => 'categories'
|
| 1807 |
-
);
|
| 1808 |
-
}
|
| 1809 |
-
|
| 1810 |
-
//images
|
| 1811 |
-
if ($this->_storeConfig['export_product_images']) {
|
| 1812 |
-
$properties[] = array(
|
| 1813 |
-
'id' => 'cache_image_url',
|
| 1814 |
-
'name' => 'cache_image_url', //property id
|
| 1815 |
-
'ptype' => 'string', //property type
|
| 1816 |
-
'type' => 'direct', //logic type
|
| 1817 |
-
'field' => 'cache_image_url', //field colummn
|
| 1818 |
-
'has_lang' => false,
|
| 1819 |
-
);
|
| 1820 |
-
}
|
| 1821 |
-
|
| 1822 |
-
//images
|
| 1823 |
-
if ($this->_storeConfig['export_product_images_thumbnail']) {
|
| 1824 |
-
$properties[] = array(
|
| 1825 |
-
'id' => 'cache_image_thumbnail_url',
|
| 1826 |
-
'name' => 'cache_image_thumbnail_url', //property id
|
| 1827 |
-
'ptype' => 'string', //property type
|
| 1828 |
-
'type' => 'direct', //logic type
|
| 1829 |
-
'field' => 'cache_image_thumbnail_url', //field colummn
|
| 1830 |
-
'has_lang' => false,
|
| 1831 |
-
);
|
| 1832 |
-
}
|
| 1833 |
-
|
| 1834 |
-
|
| 1835 |
-
$properties[] = array(
|
| 1836 |
-
'id' => 'product_entity_id',
|
| 1837 |
-
'name' => null,
|
| 1838 |
-
'ptype' => 'string',
|
| 1839 |
-
'type' => 'direct',
|
| 1840 |
-
'field' => 'entity_id',
|
| 1841 |
-
'has_lang' => false,
|
| 1842 |
-
'reference' => null
|
| 1843 |
-
);
|
| 1844 |
-
|
| 1845 |
-
return $properties;
|
| 1846 |
-
}
|
| 1847 |
-
|
| 1848 |
-
/**
|
| 1849 |
-
* @param $name
|
| 1850 |
-
* @param $csvFiles
|
| 1851 |
-
*/
|
| 1852 |
-
protected function createZip($name, $csvFiles, $xml)
|
| 1853 |
-
{
|
| 1854 |
-
if (file_exists($name)) {
|
| 1855 |
-
@unlink($name);
|
| 1856 |
-
};
|
| 1857 |
-
|
| 1858 |
-
|
| 1859 |
-
|
| 1860 |
-
$zip = new ZipArchive();
|
| 1861 |
-
if ($zip->open($name, ZIPARCHIVE::CREATE)) {
|
| 1862 |
-
|
| 1863 |
-
foreach ($csvFiles as $f) {
|
| 1864 |
-
if (!$zip->addFile($this->_dir . '/' . $f, $f)) {
|
| 1865 |
-
throw new Exception(
|
| 1866 |
-
'Synchronization failure: Failed to add file "' .
|
| 1867 |
-
$this->_dir . '/' . $f . '" to the zip "' .
|
| 1868 |
-
$name . '". Please try again.'
|
| 1869 |
-
);
|
| 1870 |
-
}
|
| 1871 |
-
}
|
| 1872 |
-
|
| 1873 |
-
if (!$zip->addFile($xml, 'properties.xml')) {
|
| 1874 |
-
throw new Exception(
|
| 1875 |
-
'Synchronization failure: Failed to add file "' .
|
| 1876 |
-
$xml . '" to the zip "' .
|
| 1877 |
-
$name . '". Please try again.'
|
| 1878 |
-
);
|
| 1879 |
-
}
|
| 1880 |
-
|
| 1881 |
-
if (!$zip->close()) {
|
| 1882 |
-
throw new Exception(
|
| 1883 |
-
'Synchronization failure: Failed to close the zip "' .
|
| 1884 |
-
$name . '". Please try again.'
|
| 1885 |
-
);
|
| 1886 |
-
}
|
| 1887 |
-
|
| 1888 |
-
} else {
|
| 1889 |
-
throw new Exception(
|
| 1890 |
-
'Synchronization failure: Failed to open the zip "' .
|
| 1891 |
-
$name . '" for writing. Please check the permissions and try again.'
|
| 1892 |
-
);
|
| 1893 |
-
}
|
| 1894 |
-
}
|
| 1895 |
-
|
| 1896 |
-
protected function pushXML($file)
|
| 1897 |
-
{
|
| 1898 |
-
$fields = array(
|
| 1899 |
-
'username' => $this->_storeConfig['di_username'],
|
| 1900 |
-
'password' => $this->_storeConfig['di_password'],
|
| 1901 |
-
'account' => $this->_storeConfig['di_account'],
|
| 1902 |
-
'template' => 'standard_source',
|
| 1903 |
-
'xml' => file_get_contents($file . '.xml')
|
| 1904 |
-
);
|
| 1905 |
-
|
| 1906 |
-
$url = $this->_helperExporter->getXMLSyncUrl($this->_storeConfig['account_dev']);
|
| 1907 |
-
return $this->pushFile($fields, $url, 'xml');
|
| 1908 |
-
|
| 1909 |
-
}
|
| 1910 |
-
|
| 1911 |
-
protected function pushFile($fields, $url, $type)
|
| 1912 |
-
{
|
| 1913 |
-
if ($this->_getIndexType() == 'delta' && !in_array('products.csv', $this->_files)) {
|
| 1914 |
-
return 'skipped empty product delta sync';
|
| 1915 |
-
}
|
| 1916 |
-
|
| 1917 |
-
self::logMem($type . ' push');
|
| 1918 |
-
$s = curl_init();
|
| 1919 |
-
|
| 1920 |
-
curl_setopt($s, CURLOPT_URL, $url);
|
| 1921 |
-
curl_setopt($s, CURLOPT_TIMEOUT, 35000);
|
| 1922 |
-
curl_setopt($s, CURLOPT_POST, true);
|
| 1923 |
-
curl_setopt($s, CURLOPT_ENCODING, '');
|
| 1924 |
-
curl_setopt($s, CURLOPT_RETURNTRANSFER, true);
|
| 1925 |
-
curl_setopt($s, CURLOPT_POSTFIELDS, $fields);
|
| 1926 |
-
|
| 1927 |
-
$responseBody = curl_exec($s);
|
| 1928 |
-
curl_close($s);
|
| 1929 |
-
if (strpos($responseBody, 'Internal Server Error') !== false) {
|
| 1930 |
-
self::logMem($type . ' push error: ' . $responseBody);
|
| 1931 |
-
Mage::throwException($this->_helperExporter->getError($responseBody));;
|
| 1932 |
-
}
|
| 1933 |
-
self::logMem($type . ' pushed. Response: ' . $responseBody);
|
| 1934 |
-
return $responseBody;
|
| 1935 |
-
}
|
| 1936 |
-
|
| 1937 |
-
/**
|
| 1938 |
-
* @param $zip
|
| 1939 |
-
*/
|
| 1940 |
-
protected function pushZip($file)
|
| 1941 |
-
{
|
| 1942 |
-
$fields = array(
|
| 1943 |
-
'username' => $this->_storeConfig['di_username'],
|
| 1944 |
-
'password' => $this->_storeConfig['di_password'],
|
| 1945 |
-
'account' => $this->_storeConfig['di_account'],
|
| 1946 |
-
'dev' => $this->_storeConfig['account_dev'] == 0 ? 'false' : 'true',
|
| 1947 |
-
'delta' => $this->_getIndexType() == 'delta' ? 'true' : 'false',
|
| 1948 |
-
'data' => $this->getCurlFile("@$file.zip", "application/zip"),
|
| 1949 |
-
);
|
| 1950 |
-
|
| 1951 |
-
$url = $this->_helperExporter->getZIPSyncUrl($this->_storeConfig['account_dev']);
|
| 1952 |
-
|
| 1953 |
-
return $this->pushFile($fields, $url, 'zip');
|
| 1954 |
-
}
|
| 1955 |
-
|
| 1956 |
-
protected function getCurlFile($filename, $type)
|
| 1957 |
-
{
|
| 1958 |
-
try {
|
| 1959 |
-
if (class_exists('CURLFile')) {
|
| 1960 |
-
return new CURLFile(substr($filename, 1), $type);
|
| 1961 |
-
}
|
| 1962 |
-
} catch(Exception $e){
|
| 1963 |
-
return $filename . ";type=$type";
|
| 1964 |
-
}
|
| 1965 |
-
return $filename . ";type=$type";
|
| 1966 |
-
}
|
| 1967 |
-
|
| 1968 |
-
protected function savePartToCsv($file, &$data)
|
| 1969 |
-
{
|
| 1970 |
-
|
| 1971 |
-
if (!file_exists($this->_dir)) {
|
| 1972 |
-
mkdir($this->_dir);
|
| 1973 |
-
}
|
| 1974 |
-
|
| 1975 |
-
//save
|
| 1976 |
-
if (!in_array($file, $this->_files)) {
|
| 1977 |
-
$this->_files[] = $file;
|
| 1978 |
-
}
|
| 1979 |
-
|
| 1980 |
-
$fh = fopen($this->_dir . '/' . $file, 'a');
|
| 1981 |
-
foreach ($data as $dataRow) {
|
| 1982 |
-
fputcsv($fh, $dataRow, $this->_helperExporter->XML_DELIMITER, $this->_helperExporter->XML_ENCLOSURE);
|
| 1983 |
-
}
|
| 1984 |
-
fclose($fh);
|
| 1985 |
-
$data = null;
|
| 1986 |
-
$fh = null;
|
| 1987 |
-
|
| 1988 |
-
}
|
| 1989 |
-
|
| 1990 |
-
/**
|
| 1991 |
-
* Store memory tracking information in log file, if enabled
|
| 1992 |
-
*/
|
| 1993 |
-
private static function logMem($message)
|
| 1994 |
-
{
|
| 1995 |
-
$callers = debug_backtrace();
|
| 1996 |
-
Boxalino_CemSearch_Model_Logger::saveMemoryTracking(
|
| 1997 |
-
'info',
|
| 1998 |
-
'Indexer',
|
| 1999 |
-
array(
|
| 2000 |
-
'memory_usage' => memory_get_usage(true),
|
| 2001 |
-
'method' => $callers[1]['function'],
|
| 2002 |
-
'description' => $message
|
| 2003 |
-
)
|
| 2004 |
-
);
|
| 2005 |
-
}
|
| 2006 |
-
|
| 2007 |
-
/**
|
| 2008 |
-
* Fetch entity id for a entity type.
|
| 2009 |
-
*
|
| 2010 |
-
* @param string $entityType
|
| 2011 |
-
* @return null|string
|
| 2012 |
-
*/
|
| 2013 |
-
public function getEntityIdFor($entityType)
|
| 2014 |
-
{
|
| 2015 |
-
if ($this->_entityIds == null) {
|
| 2016 |
-
$db = $this->_getReadAdapter();
|
| 2017 |
-
$select = $db->select()
|
| 2018 |
-
->from(
|
| 2019 |
-
$this->_prefix . 'eav_entity_type',
|
| 2020 |
-
array('entity_type_id', 'entity_type_code')
|
| 2021 |
-
);
|
| 2022 |
-
$this->_entityIds = array();
|
| 2023 |
-
foreach ($db->fetchAll($select) as $row) {
|
| 2024 |
-
$this->_entityIds[$row['entity_type_code']] = $row['entity_type_id'];
|
| 2025 |
-
}
|
| 2026 |
-
}
|
| 2027 |
-
return array_key_exists($entityType, $this->_entityIds) ? $this->_entityIds[$entityType] : null;
|
| 2028 |
-
}
|
| 2029 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/code/community/Boxalino/Exporter/etc/adminhtml.xml
DELETED
|
@@ -1,23 +0,0 @@
|
|
| 1 |
-
<?xml version="1.0"?>
|
| 2 |
-
|
| 3 |
-
<config>
|
| 4 |
-
<acl>
|
| 5 |
-
<resources>
|
| 6 |
-
<admin>
|
| 7 |
-
<children>
|
| 8 |
-
<system>
|
| 9 |
-
<children>
|
| 10 |
-
<config>
|
| 11 |
-
<children>
|
| 12 |
-
<boxalinoexporter translate="title" module="boxalinoexporter">
|
| 13 |
-
<title>Boxalino Exporter</title>
|
| 14 |
-
</boxalinoexporter>
|
| 15 |
-
</children>
|
| 16 |
-
</config>
|
| 17 |
-
</children>
|
| 18 |
-
</system>
|
| 19 |
-
</children>
|
| 20 |
-
</admin>
|
| 21 |
-
</resources>
|
| 22 |
-
</acl>
|
| 23 |
-
</config>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/code/community/Boxalino/Exporter/etc/config.xml
DELETED
|
@@ -1,62 +0,0 @@
|
|
| 1 |
-
<?xml version="1.0"?>
|
| 2 |
-
<config>
|
| 3 |
-
<modules>
|
| 4 |
-
<Boxalino_Exporter>
|
| 5 |
-
<version>2.10</version>
|
| 6 |
-
</Boxalino_Exporter>
|
| 7 |
-
</modules>
|
| 8 |
-
<global>
|
| 9 |
-
<index>
|
| 10 |
-
<indexer>
|
| 11 |
-
<boxalinoexporter_indexer>
|
| 12 |
-
<model>boxalinoexporter/indexer</model>
|
| 13 |
-
</boxalinoexporter_indexer>
|
| 14 |
-
<boxalinoexporter_delta>
|
| 15 |
-
<model>boxalinoexporter/delta</model>
|
| 16 |
-
</boxalinoexporter_delta>
|
| 17 |
-
</indexer>
|
| 18 |
-
</index>
|
| 19 |
-
<helpers>
|
| 20 |
-
<boxalinoexporter>
|
| 21 |
-
<class>Boxalino_Exporter_Helper</class>
|
| 22 |
-
</boxalinoexporter>
|
| 23 |
-
</helpers>
|
| 24 |
-
<models>
|
| 25 |
-
<boxalinoexporter>
|
| 26 |
-
<class>Boxalino_Exporter_Model</class>
|
| 27 |
-
<resourceModel>boxalinoexporter_mysql4</resourceModel>
|
| 28 |
-
</boxalinoexporter>
|
| 29 |
-
<boxalinoexporter_mysql4>
|
| 30 |
-
<class>Boxalino_Exporter_Model_Mysql4</class>
|
| 31 |
-
</boxalinoexporter_mysql4>
|
| 32 |
-
</models>
|
| 33 |
-
</global>
|
| 34 |
-
<adminhtml>
|
| 35 |
-
<translate>
|
| 36 |
-
<modules>
|
| 37 |
-
<Boxalino_Exporter>
|
| 38 |
-
<files>
|
| 39 |
-
<default>Boxalino_Exporter.csv</default>
|
| 40 |
-
</files>
|
| 41 |
-
</Boxalino_Exporter>
|
| 42 |
-
</modules>
|
| 43 |
-
</translate>
|
| 44 |
-
</adminhtml>
|
| 45 |
-
<default>
|
| 46 |
-
<boxalinoexporter>
|
| 47 |
-
<export_data>
|
| 48 |
-
<export_server>http://di1.bx-cloud.com</export_server>
|
| 49 |
-
<export_product_url>1</export_product_url>
|
| 50 |
-
<export_product_images>1</export_product_images>
|
| 51 |
-
<export_product_images_thumbnail>1</export_product_images_thumbnail>
|
| 52 |
-
<maximum_population>0</maximum_population>
|
| 53 |
-
<language>en</language>
|
| 54 |
-
<export_categories>1</export_categories>
|
| 55 |
-
<export_tags>1</export_tags>
|
| 56 |
-
<export_customers>1</export_customers>
|
| 57 |
-
<export_transactions>1</export_transactions>
|
| 58 |
-
<export_chunk>200</export_chunk>
|
| 59 |
-
</export_data>
|
| 60 |
-
</boxalinoexporter>
|
| 61 |
-
</default>
|
| 62 |
-
</config>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/code/community/Boxalino/Exporter/etc/system.xml
DELETED
|
@@ -1,151 +0,0 @@
|
|
| 1 |
-
<?xml version="1.0"?>
|
| 2 |
-
|
| 3 |
-
<config>
|
| 4 |
-
<tabs>
|
| 5 |
-
<boxalino translate="label" module="boxalinoexporter">
|
| 6 |
-
<label>Boxalino Extensions</label>
|
| 7 |
-
<sort_order>100</sort_order>
|
| 8 |
-
</boxalino>
|
| 9 |
-
</tabs>
|
| 10 |
-
<sections>
|
| 11 |
-
<boxalinoexporter translate="label" module="boxalinoexporter">
|
| 12 |
-
<class>separator-top</class>
|
| 13 |
-
<label>Boxalino Exporter</label>
|
| 14 |
-
<tab>boxalino</tab>
|
| 15 |
-
<frontend_type>text</frontend_type>
|
| 16 |
-
<sort_order>800</sort_order>
|
| 17 |
-
<show_in_default>1</show_in_default>
|
| 18 |
-
<show_in_website>1</show_in_website>
|
| 19 |
-
<show_in_store>1</show_in_store>
|
| 20 |
-
<groups>
|
| 21 |
-
<export_data translate="label" module="boxalinoexporter">
|
| 22 |
-
<label>Export Data Configuration</label>
|
| 23 |
-
<frontend_type>text</frontend_type>
|
| 24 |
-
<sort_order>20</sort_order>
|
| 25 |
-
<show_in_default>1</show_in_default>
|
| 26 |
-
<show_in_website>1</show_in_website>
|
| 27 |
-
<show_in_store>1</show_in_store>
|
| 28 |
-
<fields>
|
| 29 |
-
<export_server translate="label">
|
| 30 |
-
<label>Export server</label>
|
| 31 |
-
<frontend_type>text</frontend_type>
|
| 32 |
-
<comment>Set server where data will be exported</comment>
|
| 33 |
-
<sort_order>1</sort_order>
|
| 34 |
-
<show_in_default>1</show_in_default>
|
| 35 |
-
<show_in_website>1</show_in_website>
|
| 36 |
-
<show_in_store>0</show_in_store>
|
| 37 |
-
</export_server>
|
| 38 |
-
<language translate="label">
|
| 39 |
-
<label>Language</label>
|
| 40 |
-
<frontend_type>text</frontend_type>
|
| 41 |
-
<comment>Set language of your store view
|
| 42 |
-
<![CDATA[<br />Available: en, fr, de, it, es, zh, cz, ru]]></comment>
|
| 43 |
-
<sort_order>2</sort_order>
|
| 44 |
-
<show_in_default>1</show_in_default>
|
| 45 |
-
<show_in_website>1</show_in_website>
|
| 46 |
-
<show_in_store>1</show_in_store>
|
| 47 |
-
</language>
|
| 48 |
-
<additional_attributes translate="label">
|
| 49 |
-
<label>Additional Attributes</label>
|
| 50 |
-
<comment>Write here comma-separated names of attributes which you want to export</comment>
|
| 51 |
-
<frontend_type>text</frontend_type>
|
| 52 |
-
<sort_order>10</sort_order>
|
| 53 |
-
<show_in_default>1</show_in_default>
|
| 54 |
-
<show_in_website>1</show_in_website>
|
| 55 |
-
<show_in_store>0</show_in_store>
|
| 56 |
-
</additional_attributes>
|
| 57 |
-
<export_product_url translate="label">
|
| 58 |
-
<label>Export products url</label>
|
| 59 |
-
<frontend_type>select</frontend_type>
|
| 60 |
-
<source_model>adminhtml/system_config_source_yesno</source_model>
|
| 61 |
-
<sort_order>15</sort_order>
|
| 62 |
-
<show_in_default>1</show_in_default>
|
| 63 |
-
<show_in_website>1</show_in_website>
|
| 64 |
-
<show_in_store>0</show_in_store>
|
| 65 |
-
</export_product_url>
|
| 66 |
-
<export_product_images translate="label">
|
| 67 |
-
<label>Export products images url</label>
|
| 68 |
-
<frontend_type>select</frontend_type>
|
| 69 |
-
<source_model>adminhtml/system_config_source_yesno</source_model>
|
| 70 |
-
<sort_order>16</sort_order>
|
| 71 |
-
<show_in_default>1</show_in_default>
|
| 72 |
-
<show_in_website>1</show_in_website>
|
| 73 |
-
<show_in_store>0</show_in_store>
|
| 74 |
-
</export_product_images>
|
| 75 |
-
<export_product_images_thumbnail translate="label">
|
| 76 |
-
<label>Export products thumbnail url</label>
|
| 77 |
-
<frontend_type>select</frontend_type>
|
| 78 |
-
<source_model>adminhtml/system_config_source_yesno</source_model>
|
| 79 |
-
<sort_order>17</sort_order>
|
| 80 |
-
<show_in_default>1</show_in_default>
|
| 81 |
-
<show_in_website>1</show_in_website>
|
| 82 |
-
<show_in_store>0</show_in_store>
|
| 83 |
-
</export_product_images_thumbnail>
|
| 84 |
-
<maximum_population translate="label">
|
| 85 |
-
<label>Maximum amount of product to export</label>
|
| 86 |
-
<comment>0=all</comment>
|
| 87 |
-
<frontend_type>text</frontend_type>
|
| 88 |
-
<sort_order>20</sort_order>
|
| 89 |
-
<show_in_default>1</show_in_default>
|
| 90 |
-
<show_in_website>1</show_in_website>
|
| 91 |
-
<show_in_store>0</show_in_store>
|
| 92 |
-
</maximum_population>
|
| 93 |
-
<export_categories translate="label">
|
| 94 |
-
<label>Export Categories</label>
|
| 95 |
-
<frontend_type>select</frontend_type>
|
| 96 |
-
<source_model>adminhtml/system_config_source_yesno</source_model>
|
| 97 |
-
<sort_order>30</sort_order>
|
| 98 |
-
<show_in_default>1</show_in_default>
|
| 99 |
-
<show_in_website>1</show_in_website>
|
| 100 |
-
<show_in_store>0</show_in_store>
|
| 101 |
-
</export_categories>
|
| 102 |
-
<export_tags translate="label">
|
| 103 |
-
<label>Export Tags</label>
|
| 104 |
-
<frontend_type>select</frontend_type>
|
| 105 |
-
<source_model>adminhtml/system_config_source_yesno</source_model>
|
| 106 |
-
<sort_order>40</sort_order>
|
| 107 |
-
<show_in_default>1</show_in_default>
|
| 108 |
-
<show_in_website>1</show_in_website>
|
| 109 |
-
<show_in_store>0</show_in_store>
|
| 110 |
-
</export_tags>
|
| 111 |
-
<export_customers translate="label">
|
| 112 |
-
<label>Export Customers</label>
|
| 113 |
-
<frontend_type>select</frontend_type>
|
| 114 |
-
<source_model>adminhtml/system_config_source_yesno</source_model>
|
| 115 |
-
<sort_order>50</sort_order>
|
| 116 |
-
<show_in_default>1</show_in_default>
|
| 117 |
-
<show_in_website>1</show_in_website>
|
| 118 |
-
<show_in_store>0</show_in_store>
|
| 119 |
-
</export_customers>
|
| 120 |
-
<additional_customer_attributes translate="label">
|
| 121 |
-
<label>Additional Customer Attributes</label>
|
| 122 |
-
<comment>Write here comma-separated names of customer attributes which you want to export</comment>
|
| 123 |
-
<frontend_type>text</frontend_type>
|
| 124 |
-
<sort_order>55</sort_order>
|
| 125 |
-
<show_in_default>1</show_in_default>
|
| 126 |
-
<show_in_website>1</show_in_website>
|
| 127 |
-
<show_in_store>0</show_in_store>
|
| 128 |
-
</additional_customer_attributes>
|
| 129 |
-
<export_transactions translate="label">
|
| 130 |
-
<label>Export Transactions</label>
|
| 131 |
-
<frontend_type>select</frontend_type>
|
| 132 |
-
<source_model>adminhtml/system_config_source_yesno</source_model>
|
| 133 |
-
<sort_order>60</sort_order>
|
| 134 |
-
<show_in_default>1</show_in_default>
|
| 135 |
-
<show_in_website>1</show_in_website>
|
| 136 |
-
<show_in_store>0</show_in_store>
|
| 137 |
-
</export_transactions>
|
| 138 |
-
<export_chunk translate="label">
|
| 139 |
-
<label>Chunk size</label>
|
| 140 |
-
<frontend_type>text</frontend_type>
|
| 141 |
-
<sort_order>70</sort_order>
|
| 142 |
-
<show_in_default>1</show_in_default>
|
| 143 |
-
<show_in_website>1</show_in_website>
|
| 144 |
-
<show_in_store>0</show_in_store>
|
| 145 |
-
</export_chunk>
|
| 146 |
-
</fields>
|
| 147 |
-
</export_data>
|
| 148 |
-
</groups>
|
| 149 |
-
</boxalinoexporter>
|
| 150 |
-
</sections>
|
| 151 |
-
</config>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/code/community/Boxalino/Intelligence/Block/Autocomplete.php
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
require_once "Mage/CatalogSearch/Block/Autocomplete.php";
|
| 4 |
+
|
| 5 |
+
/**
|
| 6 |
+
* Class Boxalino_Intelligence_Block_Autocomplete
|
| 7 |
+
*/
|
| 8 |
+
class Boxalino_Intelligence_Block_Autocomplete extends Mage_CatalogSearch_Block_Autocomplete{
|
| 9 |
+
|
| 10 |
+
/**
|
| 11 |
+
* @return string
|
| 12 |
+
*/
|
| 13 |
+
protected function _toHtml()
|
| 14 |
+
{
|
| 15 |
+
$html = '';
|
| 16 |
+
$suggestData = array();
|
| 17 |
+
if (!$this->_beforeToHtml()) {
|
| 18 |
+
return $html;
|
| 19 |
+
}
|
| 20 |
+
$autocompleteHelper = new Boxalino_Intelligence_Helper_Autocomplete();
|
| 21 |
+
try{
|
| 22 |
+
$suggestData = Mage::helper('intelligence')->getAdapter()->autocomplete(
|
| 23 |
+
$query = $this->helper('catalogsearch')->getQueryText(),
|
| 24 |
+
$autocompleteHelper
|
| 25 |
+
);
|
| 26 |
+
}catch(\Exception $e){
|
| 27 |
+
Mage::logException($e);
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
$html .= '<ul class="queries"><li style="display:none"></li>';
|
| 32 |
+
$suggestionHtml = '';
|
| 33 |
+
$productHtml = '<ul class="products">';
|
| 34 |
+
$first = true;
|
| 35 |
+
if(count($suggestData)){
|
| 36 |
+
foreach($suggestData as $index => $item){
|
| 37 |
+
$suggestionHtml .= '<li data-word="'.$item['hash'].'" title="'.$this->escapeHtml($item['title']).'"';
|
| 38 |
+
$suggestionHtml .= ' class="acsuggestion">';
|
| 39 |
+
$suggestionHtml .= '<span class"query-title">'.$this->escapeHtml($item['title']).'</span>';
|
| 40 |
+
$suggestionHtml .= '<span class="amount">('.$item['num_results'].')</span></li>';
|
| 41 |
+
|
| 42 |
+
foreach($item['products'] as $product){
|
| 43 |
+
$productHtml .= '<li title="'.$this->escapeHtml($item['title']).'"';
|
| 44 |
+
if(!$first){
|
| 45 |
+
$productHtml.= ' style="display:none" ';
|
| 46 |
+
}
|
| 47 |
+
$productHtml .= 'class="product-autocomplete" data-word="'.$item['hash'].'">';
|
| 48 |
+
$productHtml .= '<a href="'.$product['url'].'">';
|
| 49 |
+
$productHtml .= '<div class="product-image"><img src="'.$product['image'].'" alt="'.$this->escapeHtml($product['name']).'" /></div>';
|
| 50 |
+
$productHtml .= '<div class="product-title"><span>'.$this->escapeHtml($product['name']).'</span></div>';
|
| 51 |
+
$productHtml .= '</a></li>';
|
| 52 |
+
}
|
| 53 |
+
$first = false;
|
| 54 |
+
}
|
| 55 |
+
}
|
| 56 |
+
$html .= $suggestionHtml . '</ul>' . $productHtml . '</ul>';
|
| 57 |
+
return $html;
|
| 58 |
+
}
|
| 59 |
+
}
|
app/code/community/Boxalino/Intelligence/Block/Cart/Crosssell.php
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
/**
|
| 4 |
+
* Class Boxalino_Intelligence_Block_Cart_Crosssell
|
| 5 |
+
*/
|
| 6 |
+
class Boxalino_Intelligence_Block_Cart_Crosssell extends Mage_Checkout_Block_Cart_Crosssell{
|
| 7 |
+
|
| 8 |
+
/**
|
| 9 |
+
*
|
| 10 |
+
*/
|
| 11 |
+
public function _construct()
|
| 12 |
+
{
|
| 13 |
+
$this->getItems(false);
|
| 14 |
+
parent::_construct();
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
/**
|
| 18 |
+
* @param bool $execute
|
| 19 |
+
* @return array|null
|
| 20 |
+
*/
|
| 21 |
+
public function getItems($execute = true){
|
| 22 |
+
|
| 23 |
+
$bxHelperData = Mage::helper('intelligence');
|
| 24 |
+
if($bxHelperData->isPluginEnabled() && $bxHelperData->isCrosssellEnabled()){
|
| 25 |
+
$config = Mage::getStoreConfig('bxRecommendations/cart');
|
| 26 |
+
$items = array();
|
| 27 |
+
$products = array();
|
| 28 |
+
|
| 29 |
+
foreach ($this->getQuote()->getAllItems() as $item){
|
| 30 |
+
$product = $item->getProduct();
|
| 31 |
+
if($product) {
|
| 32 |
+
$products[] = $product;
|
| 33 |
+
}
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
$choiceId = (isset($config['widget']) && $config['widget'] != "") ? $config['widget'] : 'basket';
|
| 37 |
+
try{
|
| 38 |
+
$entity_ids = $bxHelperData->getAdapter()->getRecommendation(
|
| 39 |
+
$choiceId,
|
| 40 |
+
$products,
|
| 41 |
+
'basket',
|
| 42 |
+
$config['min'],
|
| 43 |
+
$config['max'],
|
| 44 |
+
$execute
|
| 45 |
+
);
|
| 46 |
+
}catch(\Exception $e){
|
| 47 |
+
Mage::logException($e);
|
| 48 |
+
return parent::getItems();
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
if(!$execute){
|
| 52 |
+
return null;
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
if(empty($entity_ids)){
|
| 56 |
+
return $items;
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
$itemCollection = Mage::getResourceModel('catalog/product_collection')
|
| 60 |
+
->addFieldToFilter('entity_id', $entity_ids)
|
| 61 |
+
->addAttributeToSelect('*');
|
| 62 |
+
|
| 63 |
+
if (Mage::helper('catalog')->isModuleEnabled('Mage_Checkout')) {
|
| 64 |
+
Mage::getResourceSingleton('checkout/cart')->addExcludeProductFilter($itemCollection,
|
| 65 |
+
Mage::getSingleton('checkout/session')->getQuoteId()
|
| 66 |
+
);
|
| 67 |
+
$this->_addProductAttributesAndPrices($itemCollection);
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
foreach ($itemCollection as $product){
|
| 71 |
+
$product->setDoNotUseCategoryId(true);
|
| 72 |
+
$items[] = $product;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
return $items;
|
| 76 |
+
}
|
| 77 |
+
return parent::getItems(); // TODO: Change the autogenerated stub
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
}
|
app/code/community/Boxalino/Intelligence/Block/Facets.php
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
/**
|
| 4 |
+
* Class Boxalino_Intelligence_Block_Facets
|
| 5 |
+
*/
|
| 6 |
+
class Boxalino_Intelligence_Block_Facets extends Mage_Core_Block_Template{
|
| 7 |
+
|
| 8 |
+
/**
|
| 9 |
+
* @param string $template
|
| 10 |
+
* @return $this|Mage_Core_Block_Template
|
| 11 |
+
*/
|
| 12 |
+
public function setTemplate($template)
|
| 13 |
+
{
|
| 14 |
+
if(Mage::helper('intelligence')->isPluginEnabled()){
|
| 15 |
+
return $this;
|
| 16 |
+
}
|
| 17 |
+
return parent::setTemplate($template);
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
/**
|
| 21 |
+
* @return array
|
| 22 |
+
*/
|
| 23 |
+
public function getTopFilter(){
|
| 24 |
+
$filter = [];
|
| 25 |
+
$layer = Mage::getSingleton('catalog/layer');
|
| 26 |
+
$bxHelperData = Mage::helper('intelligence');
|
| 27 |
+
|
| 28 |
+
if($bxHelperData->isFilterLayoutEnabled($layer) && $bxHelperData->isTopFilterEnabled()) {
|
| 29 |
+
|
| 30 |
+
try {
|
| 31 |
+
$facets = $bxHelperData->getAdapter()->getFacets();
|
| 32 |
+
if ($facets) {
|
| 33 |
+
$fieldName = $bxHelperData->getTopFacetFieldName();
|
| 34 |
+
$filter = $this->getLayout()->createBlock('boxalino/layer_filter_attribute')
|
| 35 |
+
->setLayer($this->getLayer())
|
| 36 |
+
->setAttributeModel(Mage::getResourceModel('catalog/eav_attribute'))
|
| 37 |
+
->setFieldName($fieldName)
|
| 38 |
+
->setFacets($facets)
|
| 39 |
+
->init();
|
| 40 |
+
return $filter;
|
| 41 |
+
}
|
| 42 |
+
} catch (\Exception $e) {
|
| 43 |
+
Mage::logException($e);
|
| 44 |
+
}
|
| 45 |
+
}
|
| 46 |
+
return $filter;
|
| 47 |
+
}
|
| 48 |
+
}
|
app/code/community/Boxalino/Intelligence/Block/Layer.php
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
/**
|
| 4 |
+
* Class Boxalino_Intelligence_Block_Layer
|
| 5 |
+
*/
|
| 6 |
+
class Boxalino_Intelligence_Block_Layer extends Mage_CatalogSearch_Block_Layer{
|
| 7 |
+
|
| 8 |
+
/**
|
| 9 |
+
* @var array Collection of Boxalino_Intelligence_Block_Layer_Filter_Attribute
|
| 10 |
+
*/
|
| 11 |
+
protected $bxFilters = array();
|
| 12 |
+
|
| 13 |
+
/**
|
| 14 |
+
* @param string $template
|
| 15 |
+
* @return $this
|
| 16 |
+
*/
|
| 17 |
+
public function setTemplate($template){
|
| 18 |
+
|
| 19 |
+
if(!Mage::helper('intelligence')->isPluginEnabled()){
|
| 20 |
+
return parent::setTemplate($template);
|
| 21 |
+
}
|
| 22 |
+
$this->_template = 'boxalino/catalog/layer/view.phtml';
|
| 23 |
+
return $this;
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
/**
|
| 27 |
+
* @return $this
|
| 28 |
+
*/
|
| 29 |
+
protected function _prepareFilters(){
|
| 30 |
+
|
| 31 |
+
$bxHelperData = Mage::helper('intelligence');
|
| 32 |
+
$filters = array();
|
| 33 |
+
$facets = $bxHelperData->getAdapter()->getFacets();
|
| 34 |
+
if ($facets) {
|
| 35 |
+
foreach ($bxHelperData->getLeftFacetFieldNames() as $fieldName) {
|
| 36 |
+
$filter = $this->getLayout()->createBlock('boxalino/layer_filter_attribute')
|
| 37 |
+
->setLayer($this->getLayer())
|
| 38 |
+
->setFacets($facets)
|
| 39 |
+
->setFieldName($fieldName)
|
| 40 |
+
->setAttributeModel(Mage::getResourceModel('catalog/eav_attribute'))
|
| 41 |
+
->init();
|
| 42 |
+
$filters[] = $filter;
|
| 43 |
+
}
|
| 44 |
+
}
|
| 45 |
+
$this->bxFilters = $filters;
|
| 46 |
+
return $this;
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
/**
|
| 50 |
+
* @return array
|
| 51 |
+
*/
|
| 52 |
+
public function getFilters(){
|
| 53 |
+
|
| 54 |
+
$bxHelperData = Mage::helper('intelligence');
|
| 55 |
+
if($bxHelperData->isFilterLayoutEnabled($this->getLayer()) && $bxHelperData->isLeftFilterEnabled()){
|
| 56 |
+
if(empty($this->bxFilters)){
|
| 57 |
+
$this->_prepareFilters();
|
| 58 |
+
}
|
| 59 |
+
return $this->bxFilters;
|
| 60 |
+
}
|
| 61 |
+
return parent::getFilters();
|
| 62 |
+
}
|
| 63 |
+
}
|
app/code/community/Boxalino/Intelligence/Block/Layer/FIlter/Attribute.php
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
/**
|
| 4 |
+
* Class Boxalino_Intelligence_Block_Layer_Filter_Attribute
|
| 5 |
+
*/
|
| 6 |
+
class Boxalino_Intelligence_Block_Layer_Filter_Attribute extends Mage_Catalog_Block_Layer_Filter_Abstract{
|
| 7 |
+
|
| 8 |
+
/**
|
| 9 |
+
* Boxalino_Intelligence_Block_Layer_Filter_Attribute constructor.
|
| 10 |
+
*/
|
| 11 |
+
public function __construct()
|
| 12 |
+
{
|
| 13 |
+
parent::__construct();
|
| 14 |
+
$this->_filterModelName = 'intelligence/layer_filter_attribute';
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
/**
|
| 18 |
+
* @param string $template
|
| 19 |
+
* @return $this
|
| 20 |
+
*/
|
| 21 |
+
public function setTemplate($template)
|
| 22 |
+
{
|
| 23 |
+
$this->_template = 'boxalino/catalog/layer/filter.phtml';
|
| 24 |
+
return $this;
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
/**
|
| 28 |
+
* @return $this
|
| 29 |
+
* @throws Mage_Core_Exception
|
| 30 |
+
*/
|
| 31 |
+
protected function _initFilter()
|
| 32 |
+
{
|
| 33 |
+
if (!$this->_filterModelName) {
|
| 34 |
+
Mage::throwException(Mage::helper('catalog')->__('Filter model name must be declared.'));
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
$this->_filter = Mage::getModel($this->_filterModelName)
|
| 38 |
+
->setLayer($this->getLayer())
|
| 39 |
+
->setFacets($this->getFacets())
|
| 40 |
+
->setFieldName($this->getFieldName());
|
| 41 |
+
return $this;
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
}
|
app/code/community/Boxalino/Intelligence/Block/Layer/State.php
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
/**
|
| 4 |
+
* Class Boxalino_Intelligence_Block_Layer_State
|
| 5 |
+
*/
|
| 6 |
+
class Boxalino_Intelligence_Block_Layer_State extends Mage_Catalog_Block_Layer_State{
|
| 7 |
+
|
| 8 |
+
/**
|
| 9 |
+
* @param string $template
|
| 10 |
+
* @return $this
|
| 11 |
+
*/
|
| 12 |
+
public function setTemplate($template)
|
| 13 |
+
{
|
| 14 |
+
if(!Mage::helper('intelligence')->isPluginEnabled()){
|
| 15 |
+
return parent::setTemplate($template);
|
| 16 |
+
}
|
| 17 |
+
$this->_template = 'boxalino/catalog/layer/state.phtml';
|
| 18 |
+
return $this;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
/**
|
| 22 |
+
* @return array
|
| 23 |
+
*/
|
| 24 |
+
public function getActiveFilters(){
|
| 25 |
+
|
| 26 |
+
$bxHelperData = Mage::helper('intelligence');
|
| 27 |
+
if ($bxHelperData->isFilterLayoutEnabled($this->getLayer())) {
|
| 28 |
+
|
| 29 |
+
$filters = array();
|
| 30 |
+
try{
|
| 31 |
+
$facets = $bxHelperData->getAdapter()->getFacets();
|
| 32 |
+
foreach ($bxHelperData->getAllFacetFieldNames() as $fieldName){
|
| 33 |
+
|
| 34 |
+
if($facets->isSelected($fieldName)){
|
| 35 |
+
$value = $facets->getSelectedValueLabel($fieldName);
|
| 36 |
+
if($fieldName == 'discountedPrice'){
|
| 37 |
+
$value = substr_replace($value, '0', strlen($value)-1);
|
| 38 |
+
}
|
| 39 |
+
$filter = Mage::getModel('intelligence/layer_filter_attribute')
|
| 40 |
+
->setFacets($facets)
|
| 41 |
+
->setFieldName($fieldName)
|
| 42 |
+
->setRequestVar($facets->getFacetParameterName($fieldName));
|
| 43 |
+
$filters[] = Mage::getModel('catalog/layer_filter_item')
|
| 44 |
+
->setFilter($filter)
|
| 45 |
+
->setValue($value)
|
| 46 |
+
->setFieldName($fieldName);
|
| 47 |
+
}
|
| 48 |
+
}
|
| 49 |
+
return $filters;
|
| 50 |
+
}catch(\Exception $e){
|
| 51 |
+
Mage::logException($e);
|
| 52 |
+
}
|
| 53 |
+
}
|
| 54 |
+
return parent::getActiveFilters();
|
| 55 |
+
}
|
| 56 |
+
}
|
app/code/community/Boxalino/Intelligence/Block/Layer/View.php
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
/**
|
| 4 |
+
* Class Boxalino_Intelligence_Block_Layer_View
|
| 5 |
+
*/
|
| 6 |
+
class Boxalino_Intelligence_Block_Layer_View extends Mage_Catalog_Block_Layer_View {
|
| 7 |
+
|
| 8 |
+
/**
|
| 9 |
+
* @var array Collection of Boxalino_Intelligence_Block_Layer_Filter_Attribute
|
| 10 |
+
*/
|
| 11 |
+
protected $bxFilters = array();
|
| 12 |
+
|
| 13 |
+
/**
|
| 14 |
+
* @param string $template
|
| 15 |
+
* @return $this
|
| 16 |
+
*/
|
| 17 |
+
public function setTemplate($template){
|
| 18 |
+
|
| 19 |
+
if(!Mage::helper('intelligence')->isPluginEnabled()){
|
| 20 |
+
return parent::setTemplate($template);
|
| 21 |
+
}
|
| 22 |
+
$this->_template = 'boxalino/catalog/layer/view.phtml';
|
| 23 |
+
return $this;
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
/**
|
| 27 |
+
* @return $this
|
| 28 |
+
*/
|
| 29 |
+
protected function _prepareFilters(){
|
| 30 |
+
|
| 31 |
+
$bxHelperData = Mage::helper('intelligence');
|
| 32 |
+
$filters = array();
|
| 33 |
+
try{
|
| 34 |
+
$facets = $bxHelperData->getAdapter()->getFacets();
|
| 35 |
+
if ($facets) {
|
| 36 |
+
foreach ($bxHelperData->getLeftFacetFieldNames() as $fieldName) {
|
| 37 |
+
|
| 38 |
+
$filter = $this->getLayout()->createBlock('boxalino/layer_filter_attribute')
|
| 39 |
+
->setLayer($this->getLayer())
|
| 40 |
+
->setFacets($facets)
|
| 41 |
+
->setFieldName($fieldName)
|
| 42 |
+
->setAttributeModel(Mage::getResourceModel('catalog/eav_attribute'))
|
| 43 |
+
->init();
|
| 44 |
+
$filters[] = $filter;
|
| 45 |
+
}
|
| 46 |
+
}
|
| 47 |
+
$this->bxFilters = $filters;
|
| 48 |
+
}catch(\Exception $e){
|
| 49 |
+
Mage::logException($e);
|
| 50 |
+
return parent::getFilters();
|
| 51 |
+
}
|
| 52 |
+
return $this;
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
/**
|
| 56 |
+
* @return array
|
| 57 |
+
*/
|
| 58 |
+
public function getFilters(){
|
| 59 |
+
|
| 60 |
+
$bxHelperData = Mage::helper('intelligence');
|
| 61 |
+
if($bxHelperData->isFilterLayoutEnabled($this->getLayer()) && $bxHelperData->isLeftFilterEnabled()){
|
| 62 |
+
if(empty($this->bxFilters)){
|
| 63 |
+
$this->_prepareFilters();
|
| 64 |
+
}
|
| 65 |
+
return $this->bxFilters;
|
| 66 |
+
}
|
| 67 |
+
return parent::getFilters();
|
| 68 |
+
}
|
| 69 |
+
}
|
app/code/community/Boxalino/Intelligence/Block/Product/List.php
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
/**
|
| 4 |
+
* Class Boxalino_Intelligence_Block_Product_List
|
| 5 |
+
*/
|
| 6 |
+
class Boxalino_Intelligence_Block_Product_List extends Mage_Catalog_Block_Product_List{
|
| 7 |
+
|
| 8 |
+
/**
|
| 9 |
+
* @var int
|
| 10 |
+
*/
|
| 11 |
+
public static $number = 0;
|
| 12 |
+
|
| 13 |
+
/**
|
| 14 |
+
* @return Mage_Eav_Model_Entity_Collection_Abstract
|
| 15 |
+
*/
|
| 16 |
+
protected function _getProductCollection(){
|
| 17 |
+
|
| 18 |
+
$bxHelperData = Mage::helper('intelligence');
|
| 19 |
+
$p13nHelper = $bxHelperData->getAdapter();
|
| 20 |
+
$layer = $this->getLayer();
|
| 21 |
+
|
| 22 |
+
try{
|
| 23 |
+
if($bxHelperData->isEnabledOnLayer($layer)){
|
| 24 |
+
if(count($this->_productCollection) && !$p13nHelper->areThereSubPhrases()){
|
| 25 |
+
return $this->_productCollection;
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
if(get_class($layer) == 'Mage_Catalog_Model_Layer'){
|
| 29 |
+
if(Mage::getBlockSingleton('catalog/category_view')->isContentMode()){
|
| 30 |
+
return parent::_getProductCollection();
|
| 31 |
+
}
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
if($p13nHelper->areThereSubPhrases()){
|
| 35 |
+
$queries = $p13nHelper->getSubPhrasesQueries();
|
| 36 |
+
$entity_ids = $p13nHelper->getSubPhraseEntitiesIds($queries[self::$number]);
|
| 37 |
+
$entity_ids = array_slice($entity_ids, 0, $bxHelperData->getSubPhrasesLimit());
|
| 38 |
+
}else{
|
| 39 |
+
$entity_ids = $p13nHelper->getEntitiesIds();
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
if(count($entity_ids) == 0){
|
| 43 |
+
$entity_ids = array(0);
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
$this->_setupCollection($entity_ids);
|
| 47 |
+
return $this->_productCollection;
|
| 48 |
+
|
| 49 |
+
}else{
|
| 50 |
+
return parent::_getProductCollection();
|
| 51 |
+
}
|
| 52 |
+
}catch(\Exception $e){
|
| 53 |
+
Mage::logException($e);
|
| 54 |
+
}
|
| 55 |
+
return parent::_getProductCollection();
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
/**
|
| 59 |
+
* @param $entity_ids
|
| 60 |
+
* @throws Exception
|
| 61 |
+
*/
|
| 62 |
+
private function _setupCollection($entity_ids){
|
| 63 |
+
|
| 64 |
+
$this->_productCollection = Mage::getResourceModel('catalog/product_collection');
|
| 65 |
+
|
| 66 |
+
$this->_productCollection
|
| 67 |
+
->setStore($this->getLayer()->getCurrentStore())
|
| 68 |
+
->addFieldToFilter('entity_id', $entity_ids)
|
| 69 |
+
->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
|
| 70 |
+
->addUrlRewrite($this->getLayer()->getCurrentCategory()->getId());
|
| 71 |
+
|
| 72 |
+
$this->_productCollection
|
| 73 |
+
->getSelect()
|
| 74 |
+
->order(new Zend_Db_Expr('FIELD(e.entity_id,' . implode(',', $entity_ids).')'));
|
| 75 |
+
|
| 76 |
+
$this->_productCollection->setCurBxPage($this->getToolbarBlock()->getCurrentPage());
|
| 77 |
+
$limit = $this->getRequest()->getParam('limit') ? $this->getRequest()->getParam('limit') : $this->getToolbarBlock()->getLimit();
|
| 78 |
+
|
| 79 |
+
try{
|
| 80 |
+
$totalHitCount = Mage::helper('intelligence')->getAdapter()->getTotalHitCount();
|
| 81 |
+
}catch(\Exception $e){
|
| 82 |
+
Mage::logException($e);
|
| 83 |
+
throw $e;
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
$lastPage = ceil($totalHitCount /$limit);
|
| 87 |
+
$this->_productCollection
|
| 88 |
+
->setLastBxPage($lastPage)
|
| 89 |
+
->setBxTotal($totalHitCount)
|
| 90 |
+
->setBxCount(count($entity_ids))
|
| 91 |
+
->load();
|
| 92 |
+
}
|
| 93 |
+
}
|
app/code/community/Boxalino/Intelligence/Block/Product/List/Related.php
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
/**
|
| 4 |
+
* Class Boxalino_Intelligence_Block_Product_List_Related
|
| 5 |
+
*/
|
| 6 |
+
class Boxalino_Intelligence_Block_Product_List_Related extends Mage_Catalog_Block_Product_List_Related{
|
| 7 |
+
|
| 8 |
+
/**
|
| 9 |
+
*
|
| 10 |
+
*/
|
| 11 |
+
public function _construct()
|
| 12 |
+
{
|
| 13 |
+
$this->_prepareData(false);
|
| 14 |
+
parent::_construct(); // TODO: Change the autogenerated stub
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
/**
|
| 18 |
+
* @param bool $execute
|
| 19 |
+
* @return $this|null
|
| 20 |
+
*/
|
| 21 |
+
protected function _prepareData($execute = true){
|
| 22 |
+
|
| 23 |
+
$bxHelperData = Mage::helper('intelligence');
|
| 24 |
+
if($bxHelperData->isPluginEnabled() && $bxHelperData->isRelatedEnabled()){
|
| 25 |
+
$product = Mage::registry('product');
|
| 26 |
+
$config = Mage::getStoreConfig('bxRecommendations/related');
|
| 27 |
+
$choiceId = (isset($config['widget']) && $config['widget'] != "") ? $config['widget'] : 'similar';
|
| 28 |
+
$entity_ids = array();
|
| 29 |
+
try{
|
| 30 |
+
$entity_ids = $bxHelperData->getAdapter()->getRecommendation(
|
| 31 |
+
$choiceId,
|
| 32 |
+
$product,
|
| 33 |
+
'product',
|
| 34 |
+
$config['min'],
|
| 35 |
+
$config['max'],
|
| 36 |
+
$execute
|
| 37 |
+
);
|
| 38 |
+
}catch(\Exception $e){
|
| 39 |
+
Mage::logException($e);
|
| 40 |
+
return parent::_prepareData();
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
if(!$execute){
|
| 44 |
+
return null;
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
if(empty($entity_ids)){
|
| 48 |
+
$entity_ids = array(0);
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
$this->_itemCollection = Mage::getResourceModel('catalog/product_collection')
|
| 52 |
+
->addFieldToFilter('entity_id', $entity_ids)
|
| 53 |
+
->addAttributeToSelect('*');
|
| 54 |
+
|
| 55 |
+
if (Mage::helper('catalog')->isModuleEnabled('Mage_Checkout')) {
|
| 56 |
+
Mage::getResourceSingleton('checkout/cart')->addExcludeProductFilter($this->_itemCollection,
|
| 57 |
+
Mage::getSingleton('checkout/session')->getQuoteId()
|
| 58 |
+
);
|
| 59 |
+
$this->_addProductAttributesAndPrices($this->_itemCollection);
|
| 60 |
+
}
|
| 61 |
+
$this->_itemCollection->load()->setBxTotal(count($entity_ids));
|
| 62 |
+
|
| 63 |
+
foreach ($this->_itemCollection as $product) {
|
| 64 |
+
$product->setDoNotUseCategoryId(true);
|
| 65 |
+
}
|
| 66 |
+
return $this;
|
| 67 |
+
}
|
| 68 |
+
return parent::_prepareData(); // TODO: Change the autogenerated stub
|
| 69 |
+
}
|
| 70 |
+
}
|
app/code/community/Boxalino/Intelligence/Block/Product/List/Toolbar.php
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
class Boxalino_Intelligence_Block_Product_List_Toolbar extends Mage_Catalog_Block_Product_List_Toolbar
|
| 4 |
+
{
|
| 5 |
+
|
| 6 |
+
public function getModeUrl($mode)
|
| 7 |
+
{
|
| 8 |
+
$url = $this->getPagerUrl(array($this->getModeVarName() => $mode, $this->getPageVarName() => null));
|
| 9 |
+
// remove limit parameter when switching between view mode, it should always set the limit to
|
| 10 |
+
// default when view mode is switched
|
| 11 |
+
$urlHelper = Mage::helper('core/url');
|
| 12 |
+
$url = $urlHelper->removeRequestParam(htmlspecialchars_decode($url), 'limit');
|
| 13 |
+
return $url;
|
| 14 |
+
}
|
| 15 |
+
}
|
app/code/community/Boxalino/Intelligence/Block/Product/List/Upsell.php
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
/**
|
| 4 |
+
* Class Boxalino_Intelligence_Block_Product_List_Upsell
|
| 5 |
+
*/
|
| 6 |
+
class Boxalino_Intelligence_Block_Product_List_Upsell extends Mage_Catalog_Block_Product_List_Upsell{
|
| 7 |
+
|
| 8 |
+
/**
|
| 9 |
+
*
|
| 10 |
+
*/
|
| 11 |
+
public function _construct()
|
| 12 |
+
{
|
| 13 |
+
$this->_prepareData(false);
|
| 14 |
+
parent::_construct();
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
/**
|
| 18 |
+
* @param bool $execute
|
| 19 |
+
* @return $this|null
|
| 20 |
+
*/
|
| 21 |
+
protected function _prepareData($execute = true){
|
| 22 |
+
|
| 23 |
+
$bxHelperData = Mage::helper('intelligence');
|
| 24 |
+
if($bxHelperData->isPluginEnabled() && $bxHelperData->isUpsellEnabled()){
|
| 25 |
+
|
| 26 |
+
$product = Mage::registry('product');
|
| 27 |
+
$config = Mage::getStoreConfig('bxRecommendations/upsell');
|
| 28 |
+
$choiceId = (isset($config['widget']) && $config['widget'] != "") ? $config['widget'] : 'complementary';
|
| 29 |
+
$entity_ids = array();
|
| 30 |
+
try{
|
| 31 |
+
$entity_ids = $bxHelperData->getAdapter()->getRecommendation(
|
| 32 |
+
$choiceId,
|
| 33 |
+
$product,
|
| 34 |
+
'product',
|
| 35 |
+
$config['min'],
|
| 36 |
+
$config['max'],
|
| 37 |
+
$execute
|
| 38 |
+
);
|
| 39 |
+
}catch(\Exception $e){
|
| 40 |
+
Mage::logException($e);
|
| 41 |
+
return parent::_prepareData();
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
if(!$execute){
|
| 45 |
+
return null;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
if(empty($entity_ids)){
|
| 49 |
+
$entity_ids = array(0);
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
$this->_itemCollection = Mage::getResourceModel('catalog/product_collection')
|
| 53 |
+
->addFieldToFilter('entity_id', $entity_ids)
|
| 54 |
+
->addAttributeToSelect('*');
|
| 55 |
+
|
| 56 |
+
if (Mage::helper('catalog')->isModuleEnabled('Mage_Checkout')) {
|
| 57 |
+
Mage::getResourceSingleton('checkout/cart')->addExcludeProductFilter($this->_itemCollection,
|
| 58 |
+
Mage::getSingleton('checkout/session')->getQuoteId()
|
| 59 |
+
);
|
| 60 |
+
$this->_addProductAttributesAndPrices($this->_itemCollection);
|
| 61 |
+
}
|
| 62 |
+
$this->_itemCollection->load()->setBxTotal(count($entity_ids));
|
| 63 |
+
|
| 64 |
+
foreach ($this->_itemCollection as $product) {
|
| 65 |
+
$product->setDoNotUseCategoryId(true);
|
| 66 |
+
}
|
| 67 |
+
return $this;
|
| 68 |
+
}
|
| 69 |
+
return parent::_prepareData();
|
| 70 |
+
}
|
| 71 |
+
}
|
app/code/community/Boxalino/Intelligence/Block/Recommendation.php
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
/**
|
| 4 |
+
* Class Boxalino_Intelligence_Block_Recommendation
|
| 5 |
+
*/
|
| 6 |
+
class Boxalino_Intelligence_Block_Recommendation extends Mage_Catalog_Block_Product_Abstract{
|
| 7 |
+
|
| 8 |
+
/**
|
| 9 |
+
* @var
|
| 10 |
+
*/
|
| 11 |
+
private $_itemCollection;
|
| 12 |
+
|
| 13 |
+
/**
|
| 14 |
+
* @var
|
| 15 |
+
*/
|
| 16 |
+
private $bxHelperData;
|
| 17 |
+
|
| 18 |
+
/*
|
| 19 |
+
*
|
| 20 |
+
*/
|
| 21 |
+
public function _construct(){
|
| 22 |
+
|
| 23 |
+
$this->bxHelperData = Mage::helper('intelligence');
|
| 24 |
+
if($this->bxHelperData->isSetup() && $this->bxHelperData->isPluginEnabled()){
|
| 25 |
+
$cmsBlock = $this->bxHelperData->getCmsBlock();
|
| 26 |
+
if($cmsBlock){
|
| 27 |
+
$recommendationBlocks = $this->getCmsRecommendationBlocks($cmsBlock);
|
| 28 |
+
$this->prepareRecommendations($recommendationBlocks);
|
| 29 |
+
$this->bxHelperData->setSetup(false);
|
| 30 |
+
}
|
| 31 |
+
}
|
| 32 |
+
parent::_construct(); // TODO: Change the autogenerated stub
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
/**
|
| 36 |
+
* @param $content
|
| 37 |
+
* @return array
|
| 38 |
+
*/
|
| 39 |
+
protected function getCmsRecommendationBlocks($content){
|
| 40 |
+
|
| 41 |
+
$results = array();
|
| 42 |
+
$recommendations = array();
|
| 43 |
+
preg_match_all("/\{\{(.*?)\}\}/",$content, $results);
|
| 44 |
+
|
| 45 |
+
if(isset($results[1])){
|
| 46 |
+
foreach($results[1] as $result){
|
| 47 |
+
if(strpos($result,'boxalino/recommendation')){
|
| 48 |
+
preg_match_all("/[-^\s](.*?)\=\"(.*?)\"/",$result, $sectionResults);
|
| 49 |
+
$result_holder = array();
|
| 50 |
+
foreach($sectionResults[1] as $index => $sectionResult){
|
| 51 |
+
$result_holder[$sectionResult] = $sectionResults[2][$index];
|
| 52 |
+
}
|
| 53 |
+
$recommendations[] = $result_holder;
|
| 54 |
+
}
|
| 55 |
+
}
|
| 56 |
+
}
|
| 57 |
+
return $recommendations;
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
protected function getLayoutRecommendationBlocks($content){
|
| 61 |
+
|
| 62 |
+
$results = array();
|
| 63 |
+
$recommendations = array();
|
| 64 |
+
preg_match_all("/\<block type=\"boxalino\/recommendation\"(.*?)\<\/block\>/" ,$content,$results);
|
| 65 |
+
|
| 66 |
+
if(isset($results[0])){
|
| 67 |
+
foreach ($results[0] as $block){
|
| 68 |
+
$params = array();
|
| 69 |
+
preg_match_all("/\<action(.*?)\<\/action\>/",$block, $params);
|
| 70 |
+
$data = array();
|
| 71 |
+
if(isset($params[1])){
|
| 72 |
+
foreach ($params[1] as $param){
|
| 73 |
+
$temp = array();
|
| 74 |
+
preg_match_all("/method\=\"set(.*?)\"\>\<value\>(.*?)\</", $param, $temp);
|
| 75 |
+
if(!isset($temp[1][0]) && !isset($temp[2][0])){
|
| 76 |
+
continue;
|
| 77 |
+
}
|
| 78 |
+
$data[strtolower($temp[1][0])] = $temp[2][0];
|
| 79 |
+
}
|
| 80 |
+
$recommendations[] = $data;
|
| 81 |
+
}
|
| 82 |
+
}
|
| 83 |
+
}
|
| 84 |
+
return $recommendations;
|
| 85 |
+
}
|
| 86 |
+
/**
|
| 87 |
+
* @param array $recommendations
|
| 88 |
+
* @return null
|
| 89 |
+
*/
|
| 90 |
+
protected function prepareRecommendations($recommendations = array()){
|
| 91 |
+
|
| 92 |
+
if($recommendations && is_array($recommendations)){
|
| 93 |
+
foreach($recommendations as $index => $widget){
|
| 94 |
+
|
| 95 |
+
try{
|
| 96 |
+
$recommendation = array();
|
| 97 |
+
$widgetConfig = $this->bxHelperData->getWidgetConfig($widget['widget']);
|
| 98 |
+
|
| 99 |
+
}catch(\Exception $e){
|
| 100 |
+
Mage::logException($e);
|
| 101 |
+
$widgetConfig = array();
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
try{
|
| 105 |
+
$recommendation['scenario'] = isset($widget['scenario']) ? $widget['scenario'] :
|
| 106 |
+
$widgetConfig['scenario'];
|
| 107 |
+
$recommendation['min'] = isset($widget['min']) ? $widget['min'] : $widgetConfig['min'];
|
| 108 |
+
$recommendation['max'] = isset($widget['max']) ? $widget['max'] : $widgetConfig['max'];
|
| 109 |
+
|
| 110 |
+
if (isset($widget['context'])) {
|
| 111 |
+
$recommendation['context'] = explode(',', str_replace(' ', '', $widget['context']));
|
| 112 |
+
} else {
|
| 113 |
+
$recommendation['context'] = $this->getWidgetContext($widgetConfig['scenario']);
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
$this->bxHelperData->getAdapter()->getRecommendation(
|
| 117 |
+
$widget['widget'],
|
| 118 |
+
$recommendation['context'],
|
| 119 |
+
$recommendation['scenario'],
|
| 120 |
+
3,
|
| 121 |
+
3,
|
| 122 |
+
false
|
| 123 |
+
);
|
| 124 |
+
}catch(\Exception $e){
|
| 125 |
+
Mage::logException($e);
|
| 126 |
+
}
|
| 127 |
+
}
|
| 128 |
+
}
|
| 129 |
+
return null;
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
/**
|
| 133 |
+
* @return mixed
|
| 134 |
+
*/
|
| 135 |
+
public function _getLoadedProductCollection(){
|
| 136 |
+
|
| 137 |
+
return $this->_getProductCollection();
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
/**
|
| 141 |
+
* @return mixed
|
| 142 |
+
*/
|
| 143 |
+
protected function _getProductCollection(){
|
| 144 |
+
|
| 145 |
+
if(!$this->_itemCollection && $this->bxHelperData->isPluginEnabled()){
|
| 146 |
+
$this->_prepareData();
|
| 147 |
+
}
|
| 148 |
+
return $this->_itemCollection;
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
/**
|
| 152 |
+
* @return $this
|
| 153 |
+
*/
|
| 154 |
+
protected function _prepareData(){
|
| 155 |
+
|
| 156 |
+
$entity_ids = array();
|
| 157 |
+
try{
|
| 158 |
+
$entity_ids = $this->bxHelperData->getAdapter()->getRecommendation(
|
| 159 |
+
$this->getData('widget'),
|
| 160 |
+
$this->getData('context')
|
| 161 |
+
);
|
| 162 |
+
}catch(\Exception $e){
|
| 163 |
+
Mage::logException($e);
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
|
| 167 |
+
if ((count($entity_ids) == 0)) {
|
| 168 |
+
$entity_ids = array(0);
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
$this->_itemCollection = $this->_productCollection = Mage::getResourceModel('catalog/product_collection');
|
| 172 |
+
$this->_itemCollection->addFieldToFilter('entity_id', $entity_ids)->addAttributeToSelect('*');
|
| 173 |
+
$this->_itemCollection->setBxCount(count($entity_ids));
|
| 174 |
+
$this->_itemCollection->load();
|
| 175 |
+
|
| 176 |
+
return $this;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
/**
|
| 180 |
+
* @return Mage_Core_Block_Abstract
|
| 181 |
+
*/
|
| 182 |
+
protected function _beforeToHtml(){
|
| 183 |
+
|
| 184 |
+
if($this->bxHelperData->isSetup()){
|
| 185 |
+
$recommendations = $this->getLayoutRecommendationBlocks($this->getLayout()->getXmlString());
|
| 186 |
+
if($recommendations){
|
| 187 |
+
$this->prepareRecommendations($recommendations);
|
| 188 |
+
}
|
| 189 |
+
$this->bxHelperData->setSetup(false);
|
| 190 |
+
}
|
| 191 |
+
$this->_prepareData();
|
| 192 |
+
return parent::_beforeToHtml(); // TODO: Change the autogenerated stub
|
| 193 |
+
}
|
| 194 |
+
}
|
app/code/community/Boxalino/Intelligence/Block/Result.php
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
/**
|
| 4 |
+
* Class Boxalino_Intelligence_Block_Result
|
| 5 |
+
*/
|
| 6 |
+
class Boxalino_Intelligence_Block_Result extends Mage_CatalogSearch_Block_Result{
|
| 7 |
+
|
| 8 |
+
/**
|
| 9 |
+
* @var bool
|
| 10 |
+
*/
|
| 11 |
+
protected $fallback = false;
|
| 12 |
+
|
| 13 |
+
/**
|
| 14 |
+
* @var null
|
| 15 |
+
*/
|
| 16 |
+
protected $subPhrases = null;
|
| 17 |
+
|
| 18 |
+
/**
|
| 19 |
+
* @var array
|
| 20 |
+
*/
|
| 21 |
+
protected $queries = array();
|
| 22 |
+
|
| 23 |
+
/**
|
| 24 |
+
* Boxalino_Intelligence_Block_Result constructor
|
| 25 |
+
*/
|
| 26 |
+
public function _construct(){
|
| 27 |
+
|
| 28 |
+
$this->bxHelperData = Mage::helper('intelligence');
|
| 29 |
+
try{
|
| 30 |
+
if( $this->bxHelperData->isSearchEnabled()){
|
| 31 |
+
if($this->hasSubPhrases()){
|
| 32 |
+
$this->queries = $this->bxHelperData->getAdapter()->getSubPhrasesQueries();
|
| 33 |
+
}
|
| 34 |
+
}else{
|
| 35 |
+
$this->fallback = true;
|
| 36 |
+
}
|
| 37 |
+
}catch(\Exception $e){
|
| 38 |
+
Mage::logException($e);
|
| 39 |
+
}
|
| 40 |
+
parent::_construct(); // TODO: Change the autogenerated stub
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
/**
|
| 44 |
+
* @param $index
|
| 45 |
+
* @return string
|
| 46 |
+
*/
|
| 47 |
+
public function getSearchQueryLink($index){
|
| 48 |
+
|
| 49 |
+
return Mage::getUrl('*/*', array('_query' => 'q=' . $this->queries[$index]));
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
/**
|
| 53 |
+
* @return int|null
|
| 54 |
+
*/
|
| 55 |
+
public function hasSubPhrases(){
|
| 56 |
+
|
| 57 |
+
try{
|
| 58 |
+
return Mage::helper('intelligence')->getAdapter()->areThereSubPhrases();
|
| 59 |
+
}catch(\Exception $e){
|
| 60 |
+
Mage::logException($e);
|
| 61 |
+
}
|
| 62 |
+
return null;
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
/**
|
| 66 |
+
* @param string $template
|
| 67 |
+
* @return $this|Mage_Core_Block_Template
|
| 68 |
+
*/
|
| 69 |
+
public function setTemplate($template){
|
| 70 |
+
|
| 71 |
+
if($this->fallback || !$this->hasSubPhrases()){
|
| 72 |
+
return parent::setTemplate($template);
|
| 73 |
+
}
|
| 74 |
+
$this->_template = 'boxalino/catalogsearch/result.phtml';
|
| 75 |
+
return $this;
|
| 76 |
+
}
|
| 77 |
+
/**
|
| 78 |
+
* Retrieve search result count
|
| 79 |
+
*
|
| 80 |
+
* @return string
|
| 81 |
+
*/
|
| 82 |
+
public function getResultCount(){
|
| 83 |
+
|
| 84 |
+
if($this->fallback){
|
| 85 |
+
return parent::getResultCount();
|
| 86 |
+
}
|
| 87 |
+
if (!$this->getData('result_count')) {
|
| 88 |
+
$bxHelperData = Mage::helper('intelligence');
|
| 89 |
+
$query = $this->_getQuery();
|
| 90 |
+
$size = $this->hasSubPhrases() ?
|
| 91 |
+
$bxHelperData->getAdapter()->getSubPhraseTotalHitCount(
|
| 92 |
+
$this->queries[Boxalino_Intelligence_Block_Product_List::$number]) :
|
| 93 |
+
$bxHelperData->getAdapter()->getTotalHitCount();
|
| 94 |
+
$this->setResultCount($size);
|
| 95 |
+
$query->setNumResults($size);
|
| 96 |
+
}
|
| 97 |
+
return $this->getData('result_count');
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
/**
|
| 101 |
+
* @return string
|
| 102 |
+
*/
|
| 103 |
+
public function getHeaderText(){
|
| 104 |
+
|
| 105 |
+
$bxHelperData = Mage::helper('intelligence');
|
| 106 |
+
if(!$this->fallback && $bxHelperData->getAdapter()->areResultsCorrected()){
|
| 107 |
+
return $this->__("Corrected search results for '%s'", $bxHelperData->getAdapter()->getCorrectedQuery());
|
| 108 |
+
}
|
| 109 |
+
return parent::getHeaderText();
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
/**
|
| 113 |
+
* @return string
|
| 114 |
+
*/
|
| 115 |
+
public function getProductListHtml(){
|
| 116 |
+
|
| 117 |
+
if($this->fallback){
|
| 118 |
+
return parent::getProductListHtml();
|
| 119 |
+
}
|
| 120 |
+
return $this->getChildHtml('search_result_list', false);
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
/**
|
| 124 |
+
* @return int
|
| 125 |
+
*/
|
| 126 |
+
public function getSubPhrasesResultCount() {
|
| 127 |
+
|
| 128 |
+
return sizeof($this->queries);
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
/**
|
| 132 |
+
* @param $index
|
| 133 |
+
* @return string
|
| 134 |
+
*/
|
| 135 |
+
public function getSubPhrasesResultText($index){
|
| 136 |
+
|
| 137 |
+
$query = $this->queries[$index];
|
| 138 |
+
return $this->__("Search result for: '%s'", $query);
|
| 139 |
+
}
|
| 140 |
+
}
|
app/code/community/Boxalino/{CemSearch → Intelligence}/Block/Script.php
RENAMED
|
@@ -1,29 +1,33 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
|
| 3 |
-
class
|
| 4 |
-
{
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
class Boxalino_Intelligence_Block_Script extends Mage_Core_Block_Template
|
| 4 |
+
{
|
| 5 |
+
|
| 6 |
+
public function setTemplate($template)
|
| 7 |
+
{
|
| 8 |
+
if(!Mage::helper('intelligence')->isPluginEnabled()){
|
| 9 |
+
return $this;
|
| 10 |
+
}
|
| 11 |
+
return parent::setTemplate($template); // TODO: Change the autogenerated stub
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
public function getScripts()
|
| 15 |
+
{
|
| 16 |
+
$html = '';
|
| 17 |
+
$session = Mage::getSingleton('Boxalino_Intelligence_Model_Session');
|
| 18 |
+
$scripts = $session->getScripts(false);
|
| 19 |
+
|
| 20 |
+
foreach ($scripts as $script) {
|
| 21 |
+
$html .= $script;
|
| 22 |
+
}
|
| 23 |
+
$session->clearScripts();
|
| 24 |
+
|
| 25 |
+
return $html;
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
public function isSearch()
|
| 29 |
+
{
|
| 30 |
+
$current = $this->getRequest()->getRouteName() . '/' . $this->getRequest()->getControllerName();
|
| 31 |
+
return $current == 'catalogsearch/result';
|
| 32 |
+
}
|
| 33 |
+
}
|
app/code/community/Boxalino/Intelligence/Block/Slider.php
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
/**
|
| 4 |
+
* Class Boxalino_Intelligence_Block_Slider
|
| 5 |
+
*/
|
| 6 |
+
class Boxalino_Intelligence_Block_Slider extends Mage_Core_Block_Template{
|
| 7 |
+
|
| 8 |
+
/**
|
| 9 |
+
* @param $price
|
| 10 |
+
* @return array
|
| 11 |
+
*/
|
| 12 |
+
private function explodePrice($price){
|
| 13 |
+
|
| 14 |
+
return explode("-", $price);
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
/**
|
| 18 |
+
* @return array|null
|
| 19 |
+
*/
|
| 20 |
+
public function getSliderValues(){
|
| 21 |
+
|
| 22 |
+
$bxHelperData = Mage::helper('intelligence');
|
| 23 |
+
$facets = $bxHelperData->getAdapter()->getFacets();
|
| 24 |
+
if(empty($facets) || empty($facets->getPriceRanges())){
|
| 25 |
+
return null;
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
$priceRange = $this->explodePrice($facets->getPriceRanges()[0]);
|
| 29 |
+
$selectedPrice = $facets->getSelectedPriceRange() !== null ?
|
| 30 |
+
$this->explodePrice($facets->getSelectedPriceRange()) : $priceRange;
|
| 31 |
+
if($priceRange[0] == $priceRange[1]){
|
| 32 |
+
$priceRange[1]++;
|
| 33 |
+
}
|
| 34 |
+
return array_merge($selectedPrice, $priceRange);
|
| 35 |
+
}
|
| 36 |
+
}
|
app/code/community/Boxalino/Intelligence/Helper/Autocomplete.php
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
/**
|
| 4 |
+
* Class Boxalino_Intelligence_Helper_Autocomplete
|
| 5 |
+
*/
|
| 6 |
+
class Boxalino_Intelligence_Helper_Autocomplete{
|
| 7 |
+
|
| 8 |
+
/**
|
| 9 |
+
* @param $products
|
| 10 |
+
* @return array
|
| 11 |
+
*/
|
| 12 |
+
public function getListValues($products){
|
| 13 |
+
$values = array();
|
| 14 |
+
foreach($products as $product){
|
| 15 |
+
$value = array();
|
| 16 |
+
$value['name'] = $product->getName();
|
| 17 |
+
$value['url'] = $product->getProductUrl();
|
| 18 |
+
$value['price'] = strip_tags($product->getFormatedPrice());
|
| 19 |
+
$value['image'] = $product->getThumbnailUrl();
|
| 20 |
+
$values[$product->getId()] = $value;
|
| 21 |
+
}
|
| 22 |
+
return $values;
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
}
|
app/code/community/Boxalino/Intelligence/Helper/BxFiles.php
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
/**
|
| 5 |
+
* Class BxFiles
|
| 6 |
+
* @package Boxalino\Intelligence\Helper
|
| 7 |
+
*/
|
| 8 |
+
class Boxalino_Intelligence_Helper_BxFiles
|
| 9 |
+
{
|
| 10 |
+
/**
|
| 11 |
+
* @var string
|
| 12 |
+
*/
|
| 13 |
+
public $XML_DELIMITER = ',';
|
| 14 |
+
|
| 15 |
+
/**
|
| 16 |
+
* @var string
|
| 17 |
+
*/
|
| 18 |
+
public $XML_ENCLOSURE = '"';
|
| 19 |
+
|
| 20 |
+
/**
|
| 21 |
+
* @var string
|
| 22 |
+
*/
|
| 23 |
+
public $XML_ENCLOSURE_TEXT = """; // it's $XML_ENCLOSURE
|
| 24 |
+
|
| 25 |
+
/**
|
| 26 |
+
* @var string
|
| 27 |
+
*/
|
| 28 |
+
public $XML_NEWLINE = '\n';
|
| 29 |
+
|
| 30 |
+
/**
|
| 31 |
+
* @var string
|
| 32 |
+
*/
|
| 33 |
+
public $XML_ESCAPE = '\\\\';
|
| 34 |
+
|
| 35 |
+
/**
|
| 36 |
+
* @var string
|
| 37 |
+
*/
|
| 38 |
+
public $XML_ENCODE = 'UTF-8';
|
| 39 |
+
|
| 40 |
+
/**
|
| 41 |
+
* @var string
|
| 42 |
+
*/
|
| 43 |
+
public $XML_FORMAT = 'CSV';
|
| 44 |
+
|
| 45 |
+
/**
|
| 46 |
+
* @var array
|
| 47 |
+
*/
|
| 48 |
+
protected $_attributesWithIds = array();
|
| 49 |
+
|
| 50 |
+
/**
|
| 51 |
+
* @var array
|
| 52 |
+
*/
|
| 53 |
+
protected $_allTags = array();
|
| 54 |
+
|
| 55 |
+
/**
|
| 56 |
+
* @var array
|
| 57 |
+
*/
|
| 58 |
+
protected $_countries = array();
|
| 59 |
+
|
| 60 |
+
/**
|
| 61 |
+
* @var array language code
|
| 62 |
+
*/
|
| 63 |
+
protected $_languages = array(
|
| 64 |
+
'en',
|
| 65 |
+
'fr',
|
| 66 |
+
'de',
|
| 67 |
+
'it',
|
| 68 |
+
'es',
|
| 69 |
+
'zh',
|
| 70 |
+
'cz',
|
| 71 |
+
'ru',
|
| 72 |
+
);
|
| 73 |
+
|
| 74 |
+
/**
|
| 75 |
+
* @var null
|
| 76 |
+
*/
|
| 77 |
+
protected $_mainDir = null;
|
| 78 |
+
|
| 79 |
+
/**
|
| 80 |
+
* @var null
|
| 81 |
+
*/
|
| 82 |
+
protected $_dir = null;
|
| 83 |
+
|
| 84 |
+
/**
|
| 85 |
+
* @var
|
| 86 |
+
*/
|
| 87 |
+
private $account;
|
| 88 |
+
|
| 89 |
+
/**
|
| 90 |
+
* @var
|
| 91 |
+
*/
|
| 92 |
+
private $config;
|
| 93 |
+
|
| 94 |
+
/**
|
| 95 |
+
* @var array
|
| 96 |
+
*/
|
| 97 |
+
protected $_files = array();
|
| 98 |
+
|
| 99 |
+
/**
|
| 100 |
+
* @var array
|
| 101 |
+
*/
|
| 102 |
+
private $filesMtM = array();
|
| 103 |
+
|
| 104 |
+
/**
|
| 105 |
+
* BxFiles constructor.
|
| 106 |
+
* @param $filesystem
|
| 107 |
+
* @param $account
|
| 108 |
+
* @param $config
|
| 109 |
+
*/
|
| 110 |
+
public function __construct($account, $config) {
|
| 111 |
+
$this->account = $account;
|
| 112 |
+
$this->config = $config;
|
| 113 |
+
$this->init();
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
/**
|
| 117 |
+
* Initializes directory for csv files
|
| 118 |
+
*/
|
| 119 |
+
public function init() {
|
| 120 |
+
|
| 121 |
+
$this->_mainDir = Mage::getBaseDir() . "/var/tmp/boxalino";
|
| 122 |
+
|
| 123 |
+
if (!file_exists($this->_mainDir)) {
|
| 124 |
+
mkdir($this->_mainDir, 0777 , true);
|
| 125 |
+
}
|
| 126 |
+
//
|
| 127 |
+
// if(!file_exists(Mage::getBaseDir() . "/var/log")){
|
| 128 |
+
// mkdir(Mage::getBaseDir() . "/var/log", 0777, true);
|
| 129 |
+
// }
|
| 130 |
+
$this->_dir = $this->_mainDir . '/' . $this->account;
|
| 131 |
+
if (file_exists($this->_dir)) {
|
| 132 |
+
$this->delTree($this->_dir);
|
| 133 |
+
}
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
/**
|
| 137 |
+
* @param $dir
|
| 138 |
+
* @return bool|void
|
| 139 |
+
*/
|
| 140 |
+
public function delTree($dir)
|
| 141 |
+
{
|
| 142 |
+
if (!file_exists($dir)) {
|
| 143 |
+
return;
|
| 144 |
+
}
|
| 145 |
+
$files = array_diff(scandir($dir), array('.', '..'));
|
| 146 |
+
foreach ($files as $file) {
|
| 147 |
+
if (is_dir("$dir/$file")) {
|
| 148 |
+
self::delTree("$dir/$file");
|
| 149 |
+
} else if (file_exists("$dir/$file")) {
|
| 150 |
+
@unlink("$dir/$file");
|
| 151 |
+
}
|
| 152 |
+
}
|
| 153 |
+
return rmdir($dir);
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
/**
|
| 157 |
+
* @param $file
|
| 158 |
+
* @return string
|
| 159 |
+
*/
|
| 160 |
+
public function getPath($file) {
|
| 161 |
+
if (!file_exists($this->_dir)) {
|
| 162 |
+
mkdir($this->_dir);
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
//save
|
| 166 |
+
if (!in_array($file, $this->_files)) {
|
| 167 |
+
$this->_files[] = $file;
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
return $this->_dir . '/' . $file;
|
| 171 |
+
}
|
| 172 |
+
|
| 173 |
+
/**
|
| 174 |
+
* @param $file
|
| 175 |
+
* @param $data
|
| 176 |
+
*/
|
| 177 |
+
public function savePartToCsv($file, &$data)
|
| 178 |
+
{
|
| 179 |
+
$path = $this->getPath($file);
|
| 180 |
+
|
| 181 |
+
$fh = fopen($path, 'a');
|
| 182 |
+
foreach ($data as $dataRow) {
|
| 183 |
+
fputcsv($fh, $dataRow, $this->XML_DELIMITER, $this->XML_ENCLOSURE);
|
| 184 |
+
}
|
| 185 |
+
fclose($fh);
|
| 186 |
+
$data = null;
|
| 187 |
+
$fh = null;
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
/**
|
| 191 |
+
* @param $file
|
| 192 |
+
*/
|
| 193 |
+
public function printFile($file) {
|
| 194 |
+
$path = $this->getPath($file);
|
| 195 |
+
echo file_get_contents($path);
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
/**
|
| 199 |
+
* @param $files
|
| 200 |
+
*/
|
| 201 |
+
public function prepareProductFiles($files) {
|
| 202 |
+
|
| 203 |
+
foreach ($files as $attrs) {
|
| 204 |
+
foreach($attrs as $attr){
|
| 205 |
+
$key = $attr['attribute_code'];
|
| 206 |
+
|
| 207 |
+
if ($attr['attribute_code'] == 'categories') {
|
| 208 |
+
$key = 'category';
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
if (!file_exists($this->_dir)) {
|
| 212 |
+
mkdir($this->_dir);
|
| 213 |
+
}
|
| 214 |
+
$file = 'product_' . $attr['attribute_code'] . '.csv';
|
| 215 |
+
|
| 216 |
+
//save
|
| 217 |
+
if (!in_array($file, $this->_files)) {
|
| 218 |
+
$this->_files[] = $file;
|
| 219 |
+
}
|
| 220 |
+
|
| 221 |
+
$fh = fopen($this->_dir . '/' . $file, 'a');
|
| 222 |
+
$this->filesMtM[$attr['attribute_code']] = $fh;
|
| 223 |
+
}
|
| 224 |
+
}
|
| 225 |
+
}
|
| 226 |
+
}
|
app/code/community/Boxalino/Intelligence/Helper/BxGeneral.php
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
class Boxalino_Intelligence_BxGeneral
|
| 4 |
+
{
|
| 5 |
+
/**
|
| 6 |
+
* @param $string
|
| 7 |
+
* @return string
|
| 8 |
+
*/
|
| 9 |
+
public function escapeString($string)
|
| 10 |
+
{
|
| 11 |
+
return htmlspecialchars(trim(preg_replace('/\s+/', ' ', $string)));
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
/**
|
| 15 |
+
* Modifies a string to remove all non ASCII characters and spaces.
|
| 16 |
+
*/
|
| 17 |
+
public function sanitizeFieldName($text)
|
| 18 |
+
{
|
| 19 |
+
$maxLength = 50;
|
| 20 |
+
$delimiter = "_";
|
| 21 |
+
|
| 22 |
+
// replace non letter or digits by -
|
| 23 |
+
$text = preg_replace('~[^\\pL\d]+~u', $delimiter, $text);
|
| 24 |
+
|
| 25 |
+
// trim
|
| 26 |
+
$text = trim($text, $delimiter);
|
| 27 |
+
|
| 28 |
+
// transliterate
|
| 29 |
+
if (function_exists('iconv')) {
|
| 30 |
+
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
// lowercase
|
| 34 |
+
$text = strtolower($text);
|
| 35 |
+
|
| 36 |
+
// remove unwanted characters
|
| 37 |
+
$text = preg_replace('~[^_\w]+~', '', $text);
|
| 38 |
+
|
| 39 |
+
if (empty($text)) {
|
| 40 |
+
return null;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
// max $maxLength (50) chars
|
| 44 |
+
$text = substr($text, 0, $maxLength);
|
| 45 |
+
$text = trim($text, $delimiter);
|
| 46 |
+
|
| 47 |
+
return $text;
|
| 48 |
+
}
|
| 49 |
+
}
|
app/code/community/Boxalino/Intelligence/Helper/BxIndexConfig.php
ADDED
|
@@ -0,0 +1,331 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
/**
|
| 4 |
+
* Class Boxalino_Intelligence_Helper_BxIndexConfig
|
| 5 |
+
*/
|
| 6 |
+
class Boxalino_Intelligence_Helper_BxIndexConfig
|
| 7 |
+
{
|
| 8 |
+
/**
|
| 9 |
+
* @var array
|
| 10 |
+
*/
|
| 11 |
+
private $indexConfig = array();
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
/**
|
| 15 |
+
* BxIndexConfig constructor.
|
| 16 |
+
* @param $websites
|
| 17 |
+
*/
|
| 18 |
+
public function __construct() {
|
| 19 |
+
$this->initialize();
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
/**
|
| 23 |
+
* @param $websites
|
| 24 |
+
* @throws \Exception
|
| 25 |
+
*/
|
| 26 |
+
public function initialize() {
|
| 27 |
+
$this->indexConfig = array();
|
| 28 |
+
$websites = Mage::app()->getWebsites();
|
| 29 |
+
foreach($websites as $website) {
|
| 30 |
+
foreach ($website->getGroups(true) as $group) {
|
| 31 |
+
foreach ($group->getStores() as $store) {
|
| 32 |
+
|
| 33 |
+
$enabled = $store->getConfig('bxExporter/exporter/enabled');
|
| 34 |
+
|
| 35 |
+
if($enabled == '1') {
|
| 36 |
+
|
| 37 |
+
$account = $store->getConfig('bxGeneral/general/account_name');
|
| 38 |
+
|
| 39 |
+
if($account == "") {
|
| 40 |
+
throw new \Exception(
|
| 41 |
+
"Configuration error detected: Boxalino Account Name cannot be null for any store where exporter is enabled."
|
| 42 |
+
);
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
$language = $store->getConfig('bxGeneral/advanced/language');
|
| 46 |
+
|
| 47 |
+
if($language == "") {
|
| 48 |
+
$locale = $store->getConfig('general/locale/code');
|
| 49 |
+
$parts = explode('_', $locale);
|
| 50 |
+
$language = $parts[0];
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
if (!array_key_exists($account, $this->indexConfig)) {
|
| 54 |
+
$this->indexConfig[$account] = array();
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
if (array_key_exists($language, $this->indexConfig[$account])) {
|
| 59 |
+
throw new \Exception(
|
| 60 |
+
"Configuration error detected: Language '$language' can only be pushed to account '$account' once. Please review and correct your boxalino plugin's configuration, including the various configuration levels per website, store view, etc."
|
| 61 |
+
);
|
| 62 |
+
}
|
| 63 |
+
$this->indexConfig[$account][$language] = array(
|
| 64 |
+
'website' => $website,
|
| 65 |
+
'group' => $group,
|
| 66 |
+
'store' => $store,
|
| 67 |
+
);
|
| 68 |
+
}
|
| 69 |
+
}
|
| 70 |
+
}
|
| 71 |
+
}
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
/**
|
| 75 |
+
* @return array
|
| 76 |
+
*/
|
| 77 |
+
public function getAccounts() {
|
| 78 |
+
return array_keys($this->indexConfig);
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
/**
|
| 82 |
+
* @param $account
|
| 83 |
+
* @return array
|
| 84 |
+
* @throws \Exception
|
| 85 |
+
*/
|
| 86 |
+
public function getAccountLanguages($account) {
|
| 87 |
+
return array_keys($this->getAccountArray($account));
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
/**
|
| 91 |
+
* @param $account
|
| 92 |
+
* @param $language
|
| 93 |
+
* @return mixed
|
| 94 |
+
* @throws \Exception
|
| 95 |
+
*/
|
| 96 |
+
public function getStore($account, $language) {
|
| 97 |
+
$array = $this->getAccountLanguageArray($account, $language);
|
| 98 |
+
return $array['store'];
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
/**
|
| 102 |
+
* @param $account
|
| 103 |
+
* @return mixed
|
| 104 |
+
* @throws \Exception
|
| 105 |
+
*/
|
| 106 |
+
private function getAccountArray($account) {
|
| 107 |
+
if(isset($this->indexConfig[$account])) {
|
| 108 |
+
return $this->indexConfig[$account];
|
| 109 |
+
}
|
| 110 |
+
throw new \Exception("Account is not defined: " . $account);
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
/**
|
| 114 |
+
* @param $account
|
| 115 |
+
* @return mixed
|
| 116 |
+
* @throws \Exception
|
| 117 |
+
*/
|
| 118 |
+
private function getAccountFirstLanguageArray($account) {
|
| 119 |
+
$accountArray = $this->getAccountArray($account);
|
| 120 |
+
foreach($accountArray as $l => $vals) {
|
| 121 |
+
return $vals;
|
| 122 |
+
}
|
| 123 |
+
throw new \Exception("Account " . $account . " does not contain any language");
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
/**
|
| 127 |
+
* @param $account
|
| 128 |
+
* @param $language
|
| 129 |
+
* @return mixed
|
| 130 |
+
* @throws \Exception
|
| 131 |
+
*/
|
| 132 |
+
private function getAccountLanguageArray($account, $language) {
|
| 133 |
+
$accountArray = $this->getAccountArray($account);
|
| 134 |
+
if(isset($accountArray[$language])) {
|
| 135 |
+
return $accountArray[$language];
|
| 136 |
+
}
|
| 137 |
+
throw new \Exception("Account " . $account . " does not contain a language " . $language);
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
/**
|
| 141 |
+
* @param $account
|
| 142 |
+
* @return mixed
|
| 143 |
+
* @throws \Exception
|
| 144 |
+
*/
|
| 145 |
+
public function getFirstAccountStore($account) {
|
| 146 |
+
$array = $this->getAccountFirstLanguageArray($account);
|
| 147 |
+
return $array['store'];
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
/**
|
| 151 |
+
* @param $account
|
| 152 |
+
* @return bool
|
| 153 |
+
*/
|
| 154 |
+
public function isCustomersExportEnabled($account) {
|
| 155 |
+
return $this->getFirstAccountStore($account)->getConfig('bxExporter/customers/enabled') == 1;
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
/**
|
| 159 |
+
* @param $account
|
| 160 |
+
* @return bool
|
| 161 |
+
*/
|
| 162 |
+
public function isTransactionsExportEnabled($account) {
|
| 163 |
+
return $this->getFirstAccountStore($account)->getConfig('bxExporter/transactions/enabled') == 1;
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
/**
|
| 167 |
+
* @return string
|
| 168 |
+
*/
|
| 169 |
+
public function toString() {
|
| 170 |
+
$lines = array();
|
| 171 |
+
foreach($this->indexConfig as $a => $vs) {
|
| 172 |
+
$lines[] = $a . " - " . implode(',', array_keys($vs));
|
| 173 |
+
}
|
| 174 |
+
return implode('\n', $lines);
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
/**
|
| 178 |
+
* @param $account
|
| 179 |
+
* @return mixed
|
| 180 |
+
*/
|
| 181 |
+
public function getAccountUsername($account) {
|
| 182 |
+
$username = $this->getFirstAccountStore($account)->getConfig('bxGeneral/general/username');
|
| 183 |
+
return $username != "" ? $username : $account;
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
+
/**
|
| 187 |
+
* @param $account
|
| 188 |
+
* @return mixed
|
| 189 |
+
* @throws \Exception
|
| 190 |
+
*/
|
| 191 |
+
public function getAccountPassword($account) {
|
| 192 |
+
$password = $this->getFirstAccountStore($account)->getConfig('bxGeneral/general/password');
|
| 193 |
+
if($password == '') {
|
| 194 |
+
throw new \Exception("you must defined a password in Boxalino -> General configuration section");
|
| 195 |
+
}
|
| 196 |
+
return $password;
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
/**
|
| 200 |
+
* @param $account
|
| 201 |
+
* @return mixed
|
| 202 |
+
*/
|
| 203 |
+
public function isAccountDev($account) {
|
| 204 |
+
return $this->getFirstAccountStore($account)->getConfig('bxGeneral/general/dev');
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
/**
|
| 208 |
+
* @param $account
|
| 209 |
+
* @return string
|
| 210 |
+
*/
|
| 211 |
+
public function getAccountExportServer($account) {
|
| 212 |
+
$exportServer = $this->getFirstAccountStore($account)->getConfig('bxExporter/exporter/export_server');
|
| 213 |
+
return $exportServer == '' ? 'http://di1.bx-cloud.com' : $exportServer;
|
| 214 |
+
}
|
| 215 |
+
|
| 216 |
+
/**
|
| 217 |
+
* @param $account
|
| 218 |
+
* @return bool
|
| 219 |
+
*/
|
| 220 |
+
public function exportProductImages($account) {
|
| 221 |
+
return $this->getFirstAccountStore($account)->getConfig('bxExporter/products/export_images') == 1;
|
| 222 |
+
}
|
| 223 |
+
|
| 224 |
+
/**
|
| 225 |
+
* @param $account
|
| 226 |
+
* @return bool
|
| 227 |
+
*/
|
| 228 |
+
public function exportProductUrl($account) {
|
| 229 |
+
return $this->getFirstAccountStore($account)->getConfig('bxExporter/products/export_url') == 1;
|
| 230 |
+
}
|
| 231 |
+
|
| 232 |
+
/**
|
| 233 |
+
* @param $account
|
| 234 |
+
* @return bool
|
| 235 |
+
*/
|
| 236 |
+
public function publishConfigurationChanges($account) {
|
| 237 |
+
return $this->getFirstAccountStore($account)->getConfig('bxExporter/advanced/publish_configuration_changes') == 1;
|
| 238 |
+
}
|
| 239 |
+
|
| 240 |
+
/**
|
| 241 |
+
* @param $allProperties
|
| 242 |
+
* @param $includes
|
| 243 |
+
* @param $excludes
|
| 244 |
+
* @param array $requiredProperties
|
| 245 |
+
* @return array
|
| 246 |
+
* @throws \Exception
|
| 247 |
+
*/
|
| 248 |
+
protected function getFinalProperties($allProperties, $includes, $excludes, $requiredProperties=array()) {
|
| 249 |
+
|
| 250 |
+
foreach($includes as $k => $incl) {
|
| 251 |
+
if($incl == "") {
|
| 252 |
+
unset($includes[$k]);
|
| 253 |
+
}
|
| 254 |
+
}
|
| 255 |
+
|
| 256 |
+
foreach($excludes as $k => $excl) {
|
| 257 |
+
if($excl == "") {
|
| 258 |
+
unset($excludes[$k]);
|
| 259 |
+
}
|
| 260 |
+
}
|
| 261 |
+
|
| 262 |
+
if(sizeof($includes) > 0) {
|
| 263 |
+
foreach($includes as $incl) {
|
| 264 |
+
if(!in_array($incl, $allProperties)) {
|
| 265 |
+
throw new \Exception("requested include property $incl which is not part of all the properties provided");
|
| 266 |
+
}
|
| 267 |
+
|
| 268 |
+
if(!in_array($incl, $requiredProperties)) {
|
| 269 |
+
$requiredProperties[] = $incl;
|
| 270 |
+
}
|
| 271 |
+
}
|
| 272 |
+
return $requiredProperties;
|
| 273 |
+
}
|
| 274 |
+
|
| 275 |
+
foreach($excludes as $excl) {
|
| 276 |
+
if(!in_array($excl, $allProperties)) {
|
| 277 |
+
throw new \Exception("requested exclude property $excl which is not part of all the properties provided");
|
| 278 |
+
}
|
| 279 |
+
if(in_array($excl, $requiredProperties)) {
|
| 280 |
+
throw new \Exception("requested exclude property $excl which is part of the required properties and therefore cannot be excluded");
|
| 281 |
+
}
|
| 282 |
+
}
|
| 283 |
+
|
| 284 |
+
$finalProperties = array();
|
| 285 |
+
foreach($allProperties as $i => $p) {
|
| 286 |
+
if(!in_array($p, $excludes)) {
|
| 287 |
+
$finalProperties[$i] = $p;
|
| 288 |
+
}
|
| 289 |
+
}
|
| 290 |
+
return $finalProperties;
|
| 291 |
+
}
|
| 292 |
+
|
| 293 |
+
/**
|
| 294 |
+
* @param $account
|
| 295 |
+
* @param $allProperties
|
| 296 |
+
* @param array $requiredProperties
|
| 297 |
+
* @return array
|
| 298 |
+
* @throws \Exception
|
| 299 |
+
*/
|
| 300 |
+
public function getAccountProductsProperties($account, $allProperties, $requiredProperties=array()) {
|
| 301 |
+
$includes = explode(',', $this->getFirstAccountStore($account)->getConfig('bxExporter/products/include_properties'));
|
| 302 |
+
$excludes = explode(',', $this->getFirstAccountStore($account)->getConfig('bxExporter/products/exclude_properties'));
|
| 303 |
+
return $this->getFinalProperties($allProperties, $includes, $excludes, $requiredProperties);
|
| 304 |
+
}
|
| 305 |
+
|
| 306 |
+
/**
|
| 307 |
+
* @param $account
|
| 308 |
+
* @param $allProperties
|
| 309 |
+
* @param array $requiredProperties
|
| 310 |
+
* @return array
|
| 311 |
+
* @throws \Exception
|
| 312 |
+
*/
|
| 313 |
+
public function getAccountCustomersProperties($account, $allProperties, $requiredProperties=array()) {
|
| 314 |
+
$includes = explode(',', $this->getFirstAccountStore($account)->getConfig('bxExporter/customers/include_properties'));
|
| 315 |
+
$excludes = explode(',', $this->getFirstAccountStore($account)->getConfig('bxExporter/customers/exclude_properties'));
|
| 316 |
+
return $this->getFinalProperties($allProperties, $includes, $excludes, $requiredProperties);
|
| 317 |
+
}
|
| 318 |
+
|
| 319 |
+
/**
|
| 320 |
+
* @param $account
|
| 321 |
+
* @param $allProperties
|
| 322 |
+
* @param array $requiredProperties
|
| 323 |
+
* @return array
|
| 324 |
+
* @throws \Exception
|
| 325 |
+
*/
|
| 326 |
+
public function getAccountTransactionsProperties($account, $allProperties, $requiredProperties=array()) {
|
| 327 |
+
$includes = explode(',', $this->getFirstAccountStore($account)->getConfig('bxExporter/transactions/include_properties'));
|
| 328 |
+
$excludes = explode(',', $this->getFirstAccountStore($account)->getConfig('bxExporter/transactions/exclude_properties'));
|
| 329 |
+
return $this->getFinalProperties($allProperties, $includes, $excludes, $requiredProperties);
|
| 330 |
+
}
|
| 331 |
+
}
|
app/code/community/Boxalino/Intelligence/Helper/Data.php
ADDED
|
@@ -0,0 +1,613 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
/**
|
| 4 |
+
* Class Boxalino_Intelligence_Helper_Data
|
| 5 |
+
*/
|
| 6 |
+
class Boxalino_Intelligence_Helper_Data extends Mage_Core_Helper_Data{
|
| 7 |
+
|
| 8 |
+
/**
|
| 9 |
+
* @var array
|
| 10 |
+
*/
|
| 11 |
+
protected $_countries = array();
|
| 12 |
+
|
| 13 |
+
/**
|
| 14 |
+
* @var array Plugin Configuration Object
|
| 15 |
+
*/
|
| 16 |
+
protected $bxConfig = null;
|
| 17 |
+
|
| 18 |
+
/**
|
| 19 |
+
* @var Boxalino_Intelligence_Helper_P13n_Adapter
|
| 20 |
+
*/
|
| 21 |
+
protected $adapter;
|
| 22 |
+
|
| 23 |
+
/**
|
| 24 |
+
* @var array CMS Block
|
| 25 |
+
*/
|
| 26 |
+
protected $cmsBlock = array();
|
| 27 |
+
|
| 28 |
+
/**
|
| 29 |
+
* @var bool
|
| 30 |
+
*/
|
| 31 |
+
protected $setup = true;
|
| 32 |
+
|
| 33 |
+
/**
|
| 34 |
+
* @var bool
|
| 35 |
+
*/
|
| 36 |
+
protected $fallback = false;
|
| 37 |
+
|
| 38 |
+
/**
|
| 39 |
+
* @param $countryCode
|
| 40 |
+
* @return mixed
|
| 41 |
+
*/
|
| 42 |
+
public function getCountry($countryCode)
|
| 43 |
+
{
|
| 44 |
+
if (!isset($this->_countries[$countryCode])) {
|
| 45 |
+
$country = Mage::getModel('directory/country')->loadByCode($countryCode);
|
| 46 |
+
$this->_countries[$countryCode] = $country;
|
| 47 |
+
}
|
| 48 |
+
return $this->_countries[$countryCode];
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
/**
|
| 52 |
+
* @return Boxalino_Intelligence_Helper_P13n_Adapter
|
| 53 |
+
*/
|
| 54 |
+
public function getAdapter(){
|
| 55 |
+
if(!$this->adapter){
|
| 56 |
+
$this->adapter = new Boxalino_Intelligence_Helper_P13n_Adapter();
|
| 57 |
+
}
|
| 58 |
+
return $this->adapter;
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
/**
|
| 62 |
+
* @param $text
|
| 63 |
+
* @return mixed|null|string
|
| 64 |
+
*/
|
| 65 |
+
public function sanitizeFieldName($text)
|
| 66 |
+
{
|
| 67 |
+
$maxLength = 50;
|
| 68 |
+
$delimiter = "_";
|
| 69 |
+
|
| 70 |
+
// replace non letter or digits by -
|
| 71 |
+
$text = preg_replace('~[^\\pL\d]+~u', $delimiter, $text);
|
| 72 |
+
|
| 73 |
+
// trim
|
| 74 |
+
$text = trim($text, $delimiter);
|
| 75 |
+
|
| 76 |
+
// transliterate
|
| 77 |
+
if (function_exists('iconv')) {
|
| 78 |
+
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
// lowercase
|
| 82 |
+
$text = strtolower($text);
|
| 83 |
+
|
| 84 |
+
// remove unwanted characters
|
| 85 |
+
$text = preg_replace('~[^_\w]+~', '', $text);
|
| 86 |
+
|
| 87 |
+
if (empty($text)) {
|
| 88 |
+
return null;
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
// max $maxLength (50) chars
|
| 92 |
+
$text = substr($text, 0, $maxLength);
|
| 93 |
+
$text = trim($text, $delimiter);
|
| 94 |
+
|
| 95 |
+
return $text;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
/**
|
| 99 |
+
* @param $product
|
| 100 |
+
* @param $count
|
| 101 |
+
* @param $price
|
| 102 |
+
* @param $currency
|
| 103 |
+
* @return string
|
| 104 |
+
*/
|
| 105 |
+
public function reportAddToBasket($product, $count, $price, $currency)
|
| 106 |
+
{
|
| 107 |
+
if ($this->isTrackerEnabled()) {
|
| 108 |
+
$script = "_bxq.push(['trackAddToBasket', '" . $product . "', " . $count . ", " . $price . ", '" . $currency . "']);" . PHP_EOL;
|
| 109 |
+
return $script;
|
| 110 |
+
} else {
|
| 111 |
+
return '';
|
| 112 |
+
}
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
/**
|
| 116 |
+
* @param $categoryID
|
| 117 |
+
* @return string
|
| 118 |
+
*/
|
| 119 |
+
public function reportCategoryView($categoryID)
|
| 120 |
+
{
|
| 121 |
+
if ($this->isTrackerEnabled()) {
|
| 122 |
+
$script = "_bxq.push(['trackCategoryView', '" . $categoryID . "'])" . PHP_EOL;
|
| 123 |
+
return $script;
|
| 124 |
+
} else {
|
| 125 |
+
return '';
|
| 126 |
+
}
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
/**
|
| 130 |
+
* @param $customerId
|
| 131 |
+
* @return string
|
| 132 |
+
*/
|
| 133 |
+
public function reportLogin($customerId)
|
| 134 |
+
{
|
| 135 |
+
if ($this->isTrackerEnabled()) {
|
| 136 |
+
$script = "_bxq.push(['trackLogin', '" . $customerId . "'])" . PHP_EOL;
|
| 137 |
+
return $script;
|
| 138 |
+
} else {
|
| 139 |
+
return '';
|
| 140 |
+
}
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
/**
|
| 144 |
+
* @param $product
|
| 145 |
+
* @return string
|
| 146 |
+
*/
|
| 147 |
+
public function reportProductView($product)
|
| 148 |
+
{
|
| 149 |
+
if ($this->isTrackerEnabled()) {
|
| 150 |
+
$script = "_bxq.push(['trackProductView', '" . $product . "'])" . PHP_EOL;
|
| 151 |
+
return $script;
|
| 152 |
+
} else {
|
| 153 |
+
return '';
|
| 154 |
+
}
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
/**
|
| 158 |
+
* @param $productId
|
| 159 |
+
* @param $storeId
|
| 160 |
+
* @return mixed
|
| 161 |
+
*/
|
| 162 |
+
public function rewrittenProductUrl($productId, $storeId)
|
| 163 |
+
{
|
| 164 |
+
$coreUrl = Mage::getModel('core/url_rewrite');
|
| 165 |
+
$coreUrl->setStoreId($storeId);
|
| 166 |
+
$coreUrl->loadByIdPath(sprintf('product/%d', $productId));
|
| 167 |
+
return $coreUrl->getRequestPath();
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
/**
|
| 171 |
+
* @param $widgetName
|
| 172 |
+
* @return array Widget Configuration
|
| 173 |
+
*/
|
| 174 |
+
public function getWidgetConfig($widgetName){
|
| 175 |
+
|
| 176 |
+
if(!$this->bxConfig == null || !isset($this->bxConfig['bxRecommendations'])){
|
| 177 |
+
$this->bxConfig['bxRecommendations'] = Mage::getStoreConfig('bxRecommendations');
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
$widgetNames = explode(',', $this->bxConfig['bxRecommendations']['others']['widget']);
|
| 181 |
+
$widgetScenarios = explode(',', $this->bxConfig['bxRecommendations']['others']['scenario']);
|
| 182 |
+
$widgetMin = explode(',', $this->bxConfig['bxRecommendations']['others']['min']);
|
| 183 |
+
$widgetMax = explode(',', $this->bxConfig['bxRecommendations']['others']['max']);
|
| 184 |
+
|
| 185 |
+
$index = array_search($widgetName, $widgetNames);
|
| 186 |
+
$widgetConfig = array();
|
| 187 |
+
if($index !== false){
|
| 188 |
+
$widgetConfig = array('widget' => $widgetNames[$index], 'scenario' => $widgetScenarios[$index],
|
| 189 |
+
'min' => $widgetMin[$index], 'max' => $widgetMax[$index]);
|
| 190 |
+
}else{
|
| 191 |
+
throw new \Exception("There is no configuration for this widget name: " . $widgetName);
|
| 192 |
+
}
|
| 193 |
+
return $widgetConfig;
|
| 194 |
+
}
|
| 195 |
+
|
| 196 |
+
/**
|
| 197 |
+
* @return array
|
| 198 |
+
*/
|
| 199 |
+
public function getAllFacetFieldNames() {
|
| 200 |
+
|
| 201 |
+
$allFacets = array_keys($this->getLeftFacets());
|
| 202 |
+
if($this->getTopFacetFieldName() != null) {
|
| 203 |
+
$allFacets[] = $this->getTopFacetFieldName();
|
| 204 |
+
}
|
| 205 |
+
return $allFacets;
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
/**
|
| 209 |
+
* @return mixed
|
| 210 |
+
*/
|
| 211 |
+
public function getTopFacetFieldName()
|
| 212 |
+
{
|
| 213 |
+
list($topField, $topOrder) = $this->getTopFacetConfig();
|
| 214 |
+
return $topField;
|
| 215 |
+
}
|
| 216 |
+
|
| 217 |
+
/**
|
| 218 |
+
* @return array|null
|
| 219 |
+
*/
|
| 220 |
+
public function getTopFacetConfig() {
|
| 221 |
+
|
| 222 |
+
if(!$this->bxConfig == null || !isset($this->bxConfig['bxSearch'])){
|
| 223 |
+
$this->bxConfig['bxSearch'] = Mage::getStoreConfig('bxSearch');
|
| 224 |
+
}
|
| 225 |
+
$field = $this->bxConfig['bxSearch']['top_facet']['field'];
|
| 226 |
+
$order = $this->bxConfig['bxSearch']['top_facet']['order'];
|
| 227 |
+
return array($field, $order);
|
| 228 |
+
}
|
| 229 |
+
|
| 230 |
+
/**
|
| 231 |
+
* @return array
|
| 232 |
+
*/
|
| 233 |
+
public function getLeftFacetFieldNames(){
|
| 234 |
+
return array_keys($this->getLeftFacets());
|
| 235 |
+
}
|
| 236 |
+
|
| 237 |
+
/**
|
| 238 |
+
* @return array
|
| 239 |
+
* @throws Exception
|
| 240 |
+
*/
|
| 241 |
+
public function getLeftFacets(){
|
| 242 |
+
|
| 243 |
+
$leftFacet = array_merge($this->getFilterProductAttributes(), $this->getLeftFacetConfig());
|
| 244 |
+
uasort($leftFacet, function($a, $b){
|
| 245 |
+
if($a['position'] == $b['position']){
|
| 246 |
+
return strcmp($a['label'],$b['label']);
|
| 247 |
+
}
|
| 248 |
+
if($b['position'] == -1){
|
| 249 |
+
return true;
|
| 250 |
+
}
|
| 251 |
+
return $a['position'] - $b['position'];
|
| 252 |
+
});
|
| 253 |
+
|
| 254 |
+
return $leftFacet;
|
| 255 |
+
}
|
| 256 |
+
|
| 257 |
+
/**
|
| 258 |
+
* @return array
|
| 259 |
+
* @throws Exception
|
| 260 |
+
*/
|
| 261 |
+
public function getLeftFacetConfig() {
|
| 262 |
+
|
| 263 |
+
if(!isset($this->bxConfig['bxSearch'])){
|
| 264 |
+
$this->bxConfig['bxSearch'] = Mage::getStoreConfig('bxSearch');
|
| 265 |
+
}
|
| 266 |
+
try{
|
| 267 |
+
$fields = explode(',', $this->bxConfig['bxSearch']['left_facets']['fields']);
|
| 268 |
+
$labels = explode(',', $this->bxConfig['bxSearch']['left_facets']['labels']);
|
| 269 |
+
$types = explode(',', $this->bxConfig['bxSearch']['left_facets']['types']);
|
| 270 |
+
$orders = explode(',', $this->bxConfig['bxSearch']['left_facets']['orders']);
|
| 271 |
+
$position = explode(',', $this->bxConfig['bxSearch']['left_facets']['position']);
|
| 272 |
+
|
| 273 |
+
}catch (\Exception $e){
|
| 274 |
+
Mage::logException($e);
|
| 275 |
+
return array();
|
| 276 |
+
}
|
| 277 |
+
|
| 278 |
+
if($fields[0] == "" || !$this->isLeftFilterEnabled()) {
|
| 279 |
+
return array();
|
| 280 |
+
}
|
| 281 |
+
if(sizeof($fields) != sizeof($labels)) {
|
| 282 |
+
throw new \Exception("number of defined left facets fields doesn't match the number of defined left facet labels: " . implode(',', $fields) . " versus " . implode(',', $labels));
|
| 283 |
+
}
|
| 284 |
+
if(sizeof($fields) != sizeof($types)) {
|
| 285 |
+
throw new \Exception("number of defined left facets fields doesn't match the number of defined left facet types: " . implode(',', $fields) . " versus " . implode(',', $types));
|
| 286 |
+
}
|
| 287 |
+
if(sizeof($fields) != sizeof($orders)) {
|
| 288 |
+
throw new \Exception("number of defined left facets fields doesn't match the number of defined left facet orders: " . implode(',', $fields) . " versus " . implode(',', $orders));
|
| 289 |
+
}
|
| 290 |
+
if(sizeof($fields) != sizeof($position)) {
|
| 291 |
+
throw new \Exception("number of defined left facets fields doesn't match the number of defined left facet position: " . implode(',', $fields) . " versus " . implode(',', $position));
|
| 292 |
+
}
|
| 293 |
+
|
| 294 |
+
$facets = array();
|
| 295 |
+
foreach($fields as $k => $field){
|
| 296 |
+
$facets[$field] = array(
|
| 297 |
+
'label' => $labels[$k],
|
| 298 |
+
'type' =>$types[$k],
|
| 299 |
+
'order' => $orders[$k],
|
| 300 |
+
'position' => $position[$k]);
|
| 301 |
+
}
|
| 302 |
+
return $facets;
|
| 303 |
+
}
|
| 304 |
+
|
| 305 |
+
/**
|
| 306 |
+
* @return Mage_Catalog_Model_Resource_Product_Attribute_Collection
|
| 307 |
+
*/
|
| 308 |
+
protected function _getFilterableAttributes(){
|
| 309 |
+
|
| 310 |
+
$collection = Mage::getResourceModel('catalog/product_attribute_collection');
|
| 311 |
+
$collection
|
| 312 |
+
->setITemObjectClass('catalog/resource_eav_attribute')
|
| 313 |
+
->addStoreLabel(Mage::app()->getStore()->getId())
|
| 314 |
+
->setOrder('position', 'ASC')
|
| 315 |
+
->addIsFilterableFilter()->load();
|
| 316 |
+
return $collection;
|
| 317 |
+
}
|
| 318 |
+
|
| 319 |
+
/**
|
| 320 |
+
* @return array
|
| 321 |
+
*/
|
| 322 |
+
public function getFilterProductAttributes(){
|
| 323 |
+
|
| 324 |
+
$attributes = array();
|
| 325 |
+
$attributeCollection = $this->_getFilterableAttributes();
|
| 326 |
+
|
| 327 |
+
$allowedTypes = array('multiselect', 'price', 'select');
|
| 328 |
+
foreach ($attributeCollection as $attribute) {
|
| 329 |
+
try{
|
| 330 |
+
$data = $attribute->getData();
|
| 331 |
+
if (!in_array($data['frontend_input'], $allowedTypes)) {
|
| 332 |
+
continue;
|
| 333 |
+
}
|
| 334 |
+
$position = $data['position'];
|
| 335 |
+
$code = $data['attribute_code'];
|
| 336 |
+
$type = 'list';
|
| 337 |
+
|
| 338 |
+
if ($code == 'price') {
|
| 339 |
+
$type = 'ranged';
|
| 340 |
+
}
|
| 341 |
+
$code = $code == 'price' ? 'discountedPrice' : $this->getProductAttributePrefix() . $code;
|
| 342 |
+
$attributes[$code] = array(
|
| 343 |
+
'label' => $attribute->getStoreLabel(Mage::app()->getStore()->getId()),
|
| 344 |
+
'type' => $type,
|
| 345 |
+
'order' => 0,
|
| 346 |
+
'position' => $position
|
| 347 |
+
);
|
| 348 |
+
}catch(\Exception $e){
|
| 349 |
+
Mage::logException($e);
|
| 350 |
+
continue;
|
| 351 |
+
}
|
| 352 |
+
}
|
| 353 |
+
return $attributes;
|
| 354 |
+
}
|
| 355 |
+
|
| 356 |
+
/**
|
| 357 |
+
* @param $fieldName
|
| 358 |
+
* @return bool
|
| 359 |
+
*/
|
| 360 |
+
public function isHierarchical($fieldName){
|
| 361 |
+
|
| 362 |
+
if(!$this->bxConfig == null || !isset($this->bxConfig['bxSearch'])){
|
| 363 |
+
$this->bxConfig['bxSearch'] = Mage::getStoreConfig('bxSearch');
|
| 364 |
+
}
|
| 365 |
+
$facetConfig = $this->bxConfig['bxSearch']['left_facets'];
|
| 366 |
+
$fields = explode(",", $facetConfig['fields']);
|
| 367 |
+
$type = explode(",", $facetConfig['types']);
|
| 368 |
+
|
| 369 |
+
if(in_array($fieldName,$fields )){
|
| 370 |
+
if($type[array_search($fieldName, $fields)] == 'hierarchical'){
|
| 371 |
+
return true;
|
| 372 |
+
}
|
| 373 |
+
}
|
| 374 |
+
return false;
|
| 375 |
+
}
|
| 376 |
+
|
| 377 |
+
/**
|
| 378 |
+
* @return int
|
| 379 |
+
*/
|
| 380 |
+
public function getCategoriesSortOrder(){
|
| 381 |
+
|
| 382 |
+
if(!$this->bxConfig == null || !isset($this->bxConfig['bxSearch'])){
|
| 383 |
+
$this->bxConfig['bxSearch'] = Mage::getStoreConfig('bxSearch');
|
| 384 |
+
}
|
| 385 |
+
|
| 386 |
+
$fields = explode(',', $this->bxConfig['bxSearch']['left_facets']['fields']);
|
| 387 |
+
$orders = explode(',', $this->bxConfig['bxSearch']['left_facets']['orders']);
|
| 388 |
+
|
| 389 |
+
foreach($fields as $index => $field){
|
| 390 |
+
if($field == 'categories'){
|
| 391 |
+
return (int)$orders[$index];
|
| 392 |
+
}
|
| 393 |
+
}
|
| 394 |
+
return 0;
|
| 395 |
+
}
|
| 396 |
+
|
| 397 |
+
/**
|
| 398 |
+
* @return string
|
| 399 |
+
*/
|
| 400 |
+
public function getLanguage() {
|
| 401 |
+
|
| 402 |
+
return substr(Mage::getStoreConfig('general/locale/code'), 0, 2);
|
| 403 |
+
}
|
| 404 |
+
|
| 405 |
+
/**
|
| 406 |
+
* @param $block
|
| 407 |
+
*/
|
| 408 |
+
public function setCmsBlock($block){
|
| 409 |
+
|
| 410 |
+
$this->cmsBlock = $block;
|
| 411 |
+
return $this;
|
| 412 |
+
}
|
| 413 |
+
|
| 414 |
+
/**
|
| 415 |
+
* @return array
|
| 416 |
+
*/
|
| 417 |
+
public function getCmsBlock(){
|
| 418 |
+
|
| 419 |
+
return $this->cmsBlock;
|
| 420 |
+
}
|
| 421 |
+
|
| 422 |
+
/**
|
| 423 |
+
* @return bool
|
| 424 |
+
*/
|
| 425 |
+
public function isSetup(){
|
| 426 |
+
|
| 427 |
+
return $this->setup;
|
| 428 |
+
}
|
| 429 |
+
|
| 430 |
+
/**
|
| 431 |
+
* @param $setup
|
| 432 |
+
*/
|
| 433 |
+
public function setSetup($setup){
|
| 434 |
+
|
| 435 |
+
$this->setup = $setup;
|
| 436 |
+
}
|
| 437 |
+
|
| 438 |
+
/**
|
| 439 |
+
* @return mixed
|
| 440 |
+
*/
|
| 441 |
+
public function getSubPhrasesLimit(){
|
| 442 |
+
if(!$this->bxConfig == null || !isset($this->bxConfig['bxSearch'])){
|
| 443 |
+
$this->bxConfig['bxSearch'] = Mage::getStoreConfig('bxSearch');
|
| 444 |
+
}
|
| 445 |
+
return $this->bxConfig['bxSearch']['advanced']['search_sub_phrases_limit'];
|
| 446 |
+
}
|
| 447 |
+
|
| 448 |
+
/**
|
| 449 |
+
* @return string
|
| 450 |
+
*/
|
| 451 |
+
private function getProductAttributePrefix(){
|
| 452 |
+
return 'products_';
|
| 453 |
+
}
|
| 454 |
+
|
| 455 |
+
/**
|
| 456 |
+
* @param $layer
|
| 457 |
+
* @return bool
|
| 458 |
+
*/
|
| 459 |
+
public function isEnabledOnLayer($layer){
|
| 460 |
+
switch(get_class($layer)){
|
| 461 |
+
case 'Mage_CatalogSearch_Model_Layer':
|
| 462 |
+
return $this->isSearchEnabled();
|
| 463 |
+
case 'Mage_Catalog_Model_Layer':
|
| 464 |
+
return $this->isNavigationEnabled();
|
| 465 |
+
default:
|
| 466 |
+
return false;
|
| 467 |
+
}
|
| 468 |
+
}
|
| 469 |
+
|
| 470 |
+
/**
|
| 471 |
+
* @return bool
|
| 472 |
+
*/
|
| 473 |
+
public function isPluginEnabled(){
|
| 474 |
+
if(!$this->bxConfig == null || !isset($this->bxConfig['bxGeneral'])){
|
| 475 |
+
$this->bxConfig['bxGeneral'] = Mage::getStoreConfig('bxGeneral');
|
| 476 |
+
}
|
| 477 |
+
return (bool)($this->bxConfig['bxGeneral']['general']['enabled'] && !$this->fallback);
|
| 478 |
+
}
|
| 479 |
+
|
| 480 |
+
/**
|
| 481 |
+
* @return bool
|
| 482 |
+
*/
|
| 483 |
+
public function isSearchEnabled(){
|
| 484 |
+
if(!$this->bxConfig == null || !isset($this->bxConfig['bxSearch'])) {
|
| 485 |
+
$this->bxConfig['bxSearch'] = Mage::getStoreConfig('bxSearch');
|
| 486 |
+
}
|
| 487 |
+
return (bool)$this->isPluginEnabled() && $this->bxConfig['bxSearch']['search']['enabled'];
|
| 488 |
+
}
|
| 489 |
+
|
| 490 |
+
/**
|
| 491 |
+
* @return bool
|
| 492 |
+
*/
|
| 493 |
+
public function isAutocompleteEnabled(){
|
| 494 |
+
if(!$this->bxConfig == null || !isset($this->bxConfig['bxSearch'])) {
|
| 495 |
+
$this->bxConfig['bxSearch'] = Mage::getStoreConfig('bxSearch');
|
| 496 |
+
}
|
| 497 |
+
return (bool)$this->isPluginEnabled() && $this->bxConfig['bxSearch']['autocomplete']['enabled'];
|
| 498 |
+
}
|
| 499 |
+
|
| 500 |
+
/**
|
| 501 |
+
* @return bool
|
| 502 |
+
*/
|
| 503 |
+
public function isTrackerEnabled()
|
| 504 |
+
{
|
| 505 |
+
if (!$this->bxConfig == null || !isset($this->bxConfig['bxGeneral'])) {
|
| 506 |
+
$this->bxConfig['bxGeneral'] = Mage::getStoreConfig('bxGeneral');
|
| 507 |
+
}
|
| 508 |
+
return (bool)$this->isPluginEnabled() && $this->bxConfig['bxGeneral']['tracker']['enabled'];
|
| 509 |
+
}
|
| 510 |
+
|
| 511 |
+
/**
|
| 512 |
+
* @return bool
|
| 513 |
+
*/
|
| 514 |
+
public function isCrosssellEnabled()
|
| 515 |
+
{
|
| 516 |
+
if(!$this->bxConfig == null || !isset($this->bxConfig['bxRecommendations'])){
|
| 517 |
+
$this->bxConfig['bxRecommendations'] = Mage::getStoreConfig('bxRecommendations');
|
| 518 |
+
}
|
| 519 |
+
return (bool)$this->isPluginEnabled() && $this->bxConfig['bxRecommendations']['cart']['status'];
|
| 520 |
+
}
|
| 521 |
+
|
| 522 |
+
/**
|
| 523 |
+
* @return bool
|
| 524 |
+
*/
|
| 525 |
+
public function isRelatedEnabled()
|
| 526 |
+
{
|
| 527 |
+
if(!$this->bxConfig == null || !isset($this->bxConfig['bxRecommendations'])){
|
| 528 |
+
$this->bxConfig['bxRecommendations'] = Mage::getStoreConfig('bxRecommendations');
|
| 529 |
+
}
|
| 530 |
+
return (bool)$this->isPluginEnabled() && $this->bxConfig['bxRecommendations']['related']['status'];
|
| 531 |
+
}
|
| 532 |
+
|
| 533 |
+
/**
|
| 534 |
+
* @return bool
|
| 535 |
+
*/
|
| 536 |
+
public function isUpsellEnabled()
|
| 537 |
+
{
|
| 538 |
+
if(!$this->bxConfig == null || !isset($this->bxConfig['bxRecommendations'])){
|
| 539 |
+
$this->bxConfig['bxRecommendations'] = Mage::getStoreConfig('bxRecommendations');
|
| 540 |
+
}
|
| 541 |
+
return (bool)$this->isPluginEnabled() && $this->bxConfig['bxRecommendations']['upsell']['status'];
|
| 542 |
+
}
|
| 543 |
+
|
| 544 |
+
/**
|
| 545 |
+
* @return bool
|
| 546 |
+
*/
|
| 547 |
+
public function isNavigationEnabled()
|
| 548 |
+
{
|
| 549 |
+
if(!$this->bxConfig == null || !isset($this->bxConfig['bxSearch'])) {
|
| 550 |
+
$this->bxConfig['bxSearch'] = Mage::getStoreConfig('bxSearch');
|
| 551 |
+
}
|
| 552 |
+
return (bool)($this->isPluginEnabled() && $this->bxConfig['bxSearch']['navigation']['enabled']);
|
| 553 |
+
}
|
| 554 |
+
|
| 555 |
+
/**
|
| 556 |
+
* @return bool
|
| 557 |
+
*/
|
| 558 |
+
public function isLeftFilterEnabled()
|
| 559 |
+
{
|
| 560 |
+
if(!$this->bxConfig == null || !isset($this->bxConfig['bxSearch'])) {
|
| 561 |
+
$this->bxConfig['bxSearch'] = Mage::getStoreConfig('bxSearch');
|
| 562 |
+
}
|
| 563 |
+
return $this->bxConfig['bxSearch']['left_facets']['enabled'];
|
| 564 |
+
}
|
| 565 |
+
|
| 566 |
+
/**
|
| 567 |
+
* @return bool
|
| 568 |
+
*/
|
| 569 |
+
public function isTopFilterEnabled()
|
| 570 |
+
{
|
| 571 |
+
if(!$this->bxConfig == null || !isset($this->bxConfig['bxSearch'])) {
|
| 572 |
+
$this->bxConfig['bxSearch'] = Mage::getStoreConfig('bxSearch');
|
| 573 |
+
}
|
| 574 |
+
return (bool)$this->bxConfig['bxSearch']['top_facet']['enabled'];
|
| 575 |
+
}
|
| 576 |
+
|
| 577 |
+
/**
|
| 578 |
+
* @return bool
|
| 579 |
+
*/
|
| 580 |
+
public function isFilterLayoutEnabled($layer){
|
| 581 |
+
|
| 582 |
+
$type = '';
|
| 583 |
+
switch(get_class($layer)){
|
| 584 |
+
case 'Mage_CatalogSearch_Model_Layer':
|
| 585 |
+
$type = 'search';
|
| 586 |
+
break;
|
| 587 |
+
case 'Mage_Catalog_Model_Layer':
|
| 588 |
+
$type = 'navigation';
|
| 589 |
+
break;
|
| 590 |
+
default:
|
| 591 |
+
return false;
|
| 592 |
+
}
|
| 593 |
+
|
| 594 |
+
if(!isset($this->bxConfig['bxSearch'])){
|
| 595 |
+
$this->bxConfig['bxSearch'] = Mage::getStoreConfig('bxSearch');
|
| 596 |
+
}
|
| 597 |
+
return (bool)($this->isEnabledOnLayer($layer) && $this->bxConfig['bxSearch'][$type]['filter']);
|
| 598 |
+
}
|
| 599 |
+
|
| 600 |
+
/**
|
| 601 |
+
* @param $fallback
|
| 602 |
+
*/
|
| 603 |
+
public function setFallback($fallback){
|
| 604 |
+
$this->fallback = $fallback;
|
| 605 |
+
}
|
| 606 |
+
|
| 607 |
+
/**
|
| 608 |
+
* @return bool
|
| 609 |
+
*/
|
| 610 |
+
public function getFallback(){
|
| 611 |
+
return $this->fallback;
|
| 612 |
+
}
|
| 613 |
+
}
|
app/code/community/Boxalino/Intelligence/Helper/P13n/Adapter.php
ADDED
|
@@ -0,0 +1,466 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
/**
|
| 4 |
+
* Class Boxalino_Intelligence_Helper_P13n_Adapter
|
| 5 |
+
*/
|
| 6 |
+
class Boxalino_Intelligence_Helper_P13n_Adapter{
|
| 7 |
+
|
| 8 |
+
/**
|
| 9 |
+
* @var \com\boxalino\bxclient\v1\BxClient
|
| 10 |
+
*/
|
| 11 |
+
private static $bxClient = null;
|
| 12 |
+
|
| 13 |
+
/**
|
| 14 |
+
* @var array
|
| 15 |
+
*/
|
| 16 |
+
private static $choiceContexts = array();
|
| 17 |
+
|
| 18 |
+
/**
|
| 19 |
+
* @var Mage_Core_Helper_Abstract
|
| 20 |
+
*/
|
| 21 |
+
protected $bxHelperData;
|
| 22 |
+
|
| 23 |
+
/**
|
| 24 |
+
* @var
|
| 25 |
+
*/
|
| 26 |
+
protected $currentSearchChoice;
|
| 27 |
+
|
| 28 |
+
/**
|
| 29 |
+
* Boxalino_Intelligence_Helper_P13n_Adapter constructor.
|
| 30 |
+
*/
|
| 31 |
+
public function __construct(){
|
| 32 |
+
|
| 33 |
+
$this->bxHelperData = Mage::helper('intelligence');
|
| 34 |
+
$libPath = Mage::getModuleDir('','Boxalino_Intelligence') . DIRECTORY_SEPARATOR . 'lib';
|
| 35 |
+
require_once($libPath . DIRECTORY_SEPARATOR . 'BxClient.php');
|
| 36 |
+
\com\boxalino\bxclient\v1\BxClient::LOAD_CLASSES($libPath);
|
| 37 |
+
|
| 38 |
+
if($this->bxHelperData->isPluginEnabled()){
|
| 39 |
+
$this->initializeBXClient();
|
| 40 |
+
}
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
/**
|
| 44 |
+
* Initialize BxClient
|
| 45 |
+
*/
|
| 46 |
+
protected function initializeBXClient() {
|
| 47 |
+
|
| 48 |
+
if(self::$bxClient == null) {
|
| 49 |
+
$generalConfig = Mage::getStoreConfig('bxGeneral');
|
| 50 |
+
$account = $generalConfig['general']['account_name'];
|
| 51 |
+
$password = $generalConfig['general']['password'];
|
| 52 |
+
$isDev = $generalConfig['general']['dev'];
|
| 53 |
+
$host = $generalConfig['advanced']['host'];
|
| 54 |
+
$p13n_username = $generalConfig['advanced']['p13n_username'];
|
| 55 |
+
$p13n_password = $generalConfig['advanced']['p13n_password'];
|
| 56 |
+
$domain = $generalConfig['general']['domain'];
|
| 57 |
+
self::$bxClient = new \com\boxalino\bxclient\v1\BxClient($account, $password, $domain, $isDev, $host, null, null, null, $p13n_username, $p13n_password);
|
| 58 |
+
self::$bxClient->setTimeout(Mage::getStoreConfig('bxGeneral/advanced/thrift_timeout'));
|
| 59 |
+
|
| 60 |
+
}
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
/**
|
| 64 |
+
* @param string $queryText
|
| 65 |
+
* @return array
|
| 66 |
+
*/
|
| 67 |
+
public function getSystemFilters($queryText="") {
|
| 68 |
+
|
| 69 |
+
$filters = array();
|
| 70 |
+
if($queryText == "") {
|
| 71 |
+
$filters[] = new \com\boxalino\bxclient\v1\BxFilter('products_visibility_' . $this->bxHelperData->getLanguage(), array(Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE, Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_SEARCH), true);
|
| 72 |
+
} else {
|
| 73 |
+
$filters[] = new \com\boxalino\bxclient\v1\BxFilter('products_visibility_' . $this->bxHelperData->getLanguage(), array(Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE, Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG), true);
|
| 74 |
+
}
|
| 75 |
+
$filters[] = new \com\boxalino\bxclient\v1\BxFilter('products_status', array(Mage_Catalog_Model_Product_Status::STATUS_ENABLED));
|
| 76 |
+
|
| 77 |
+
return $filters;
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
/**
|
| 81 |
+
* @return mixed|string
|
| 82 |
+
*/
|
| 83 |
+
public function getAutocompleteChoice() {
|
| 84 |
+
|
| 85 |
+
$choice = Mage::getStoreConfig('bxSearch/advanced/autocomplete_choice_id');
|
| 86 |
+
if($choice == null) {
|
| 87 |
+
$choice = "autocomplete";
|
| 88 |
+
}
|
| 89 |
+
$this->currentSearchChoice = $choice;
|
| 90 |
+
return $choice;
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
/**
|
| 94 |
+
* @param $queryText
|
| 95 |
+
* @return mixed|string
|
| 96 |
+
*/
|
| 97 |
+
public function getSearchChoice($queryText) {
|
| 98 |
+
|
| 99 |
+
if($queryText == null) {
|
| 100 |
+
$choice = Mage::getStoreConfig('bxSearch/advanced/navigation_choice_id');
|
| 101 |
+
if($choice == null) {
|
| 102 |
+
$choice = "navigation";
|
| 103 |
+
}
|
| 104 |
+
$this->currentSearchChoice = $choice;
|
| 105 |
+
return $choice;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
$choice = Mage::getStoreConfig('bxSearch/advanced/search_choice_id');
|
| 109 |
+
if($choice == null) {
|
| 110 |
+
$choice = "search";
|
| 111 |
+
}
|
| 112 |
+
$this->currentSearchChoice = $choice;
|
| 113 |
+
return $choice;
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
/**
|
| 117 |
+
* @return mixed|string
|
| 118 |
+
*/
|
| 119 |
+
public function getEntityIdFieldName() {
|
| 120 |
+
|
| 121 |
+
$entityIdFieldName = Mage::getStoreConfig('bxGeneral/advanced/entity_id');
|
| 122 |
+
if (!isset($entityIdFieldName) || $entityIdFieldName === '') {
|
| 123 |
+
$entityIdFieldName = 'products_group_id';
|
| 124 |
+
}
|
| 125 |
+
return $entityIdFieldName;
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
/**
|
| 129 |
+
* @param $queryText
|
| 130 |
+
* @param $autocomplete
|
| 131 |
+
* @return array
|
| 132 |
+
*/
|
| 133 |
+
public function autocomplete($queryText, $autocomplete){
|
| 134 |
+
|
| 135 |
+
$order = array();
|
| 136 |
+
$data = array();
|
| 137 |
+
$hash = null;
|
| 138 |
+
|
| 139 |
+
$autocompleteConfig = Mage::getStoreConfig('bxSearch/autocomplete');
|
| 140 |
+
$autocomplete_limit = $autocompleteConfig['limit'];
|
| 141 |
+
$products_limit = $autocompleteConfig['products_limit'];
|
| 142 |
+
|
| 143 |
+
if ($queryText) {
|
| 144 |
+
$bxRequest = new \com\boxalino\bxclient\v1\BxAutocompleteRequest($this->bxHelperData->getLanguage(), $queryText, $autocomplete_limit, $products_limit, $this->getAutocompleteChoice(), $this->getSearchChoice($queryText));
|
| 145 |
+
$searchRequest = $bxRequest->getBxSearchRequest();
|
| 146 |
+
|
| 147 |
+
$searchRequest->setReturnFields(array('products_group_id'));
|
| 148 |
+
$searchRequest->setGroupBy($this->getEntityIdFieldName());
|
| 149 |
+
$searchRequest->setFilters($this->getSystemFilters($queryText));
|
| 150 |
+
self::$bxClient->setAutocompleteRequest($bxRequest);
|
| 151 |
+
self::$bxClient->autocomplete();
|
| 152 |
+
$bxAutocompleteResponse = self::$bxClient->getAutocompleteResponse();
|
| 153 |
+
|
| 154 |
+
foreach ($bxAutocompleteResponse->getTextualSuggestions() as $i => $suggestion) {
|
| 155 |
+
$entity_ids = array();
|
| 156 |
+
$totalHitcount = $bxAutocompleteResponse->getTextualSuggestionTotalHitCount($suggestion);
|
| 157 |
+
|
| 158 |
+
if ($totalHitcount <= 0) {
|
| 159 |
+
continue;
|
| 160 |
+
}
|
| 161 |
+
|
| 162 |
+
$_data = array(
|
| 163 |
+
'title' => $suggestion,
|
| 164 |
+
'num_results' => $totalHitcount,
|
| 165 |
+
'hash' => substr(md5($suggestion . $i), 0, 10),
|
| 166 |
+
'products' => array()
|
| 167 |
+
);
|
| 168 |
+
|
| 169 |
+
foreach ($bxAutocompleteResponse->getBxSearchResponse($suggestion)->getHitIds($this->currentSearchChoice) as $id) {
|
| 170 |
+
$entity_ids[$id] = $id;
|
| 171 |
+
}
|
| 172 |
+
|
| 173 |
+
if (count($entity_ids) > 0) {
|
| 174 |
+
$collection = Mage::getResourceModel('catalog/product_collection');
|
| 175 |
+
$list = $collection->addFieldToFilter('entity_id', $entity_ids)
|
| 176 |
+
->addAttributeToselect('*')->load();
|
| 177 |
+
$productValues = $autocomplete->getListValues($list);
|
| 178 |
+
$list = null;
|
| 179 |
+
$_data['products'] = $productValues;
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
if ($_data['title'] == $queryText) {
|
| 183 |
+
array_unshift($data, $_data);
|
| 184 |
+
} else {
|
| 185 |
+
$data[] = $_data;
|
| 186 |
+
}
|
| 187 |
+
}
|
| 188 |
+
}
|
| 189 |
+
return $data;
|
| 190 |
+
}
|
| 191 |
+
|
| 192 |
+
/**
|
| 193 |
+
* @param $queryText
|
| 194 |
+
* @param int $pageOffset
|
| 195 |
+
* @param null $overwriteHitCount
|
| 196 |
+
* @param \com\boxalino\bxclient\v1\BxSortFields|null $bxSortFields
|
| 197 |
+
* @param null $categoryId
|
| 198 |
+
*/
|
| 199 |
+
public function search($queryText, $pageOffset = 0, $overwriteHitCount = null, \com\boxalino\bxclient\v1\BxSortFields $bxSortFields=null, $categoryId=null){
|
| 200 |
+
|
| 201 |
+
$returnFields = array($this->getEntityIdFieldName(), 'categories', 'discountedPrice', 'products_bx_grouped_price', 'title', 'score');
|
| 202 |
+
$additionalFields = explode(',', Mage::getStoreConfig('bxGeneral/advanced/additional_fields'));
|
| 203 |
+
$returnFields = array_merge($returnFields, $additionalFields);
|
| 204 |
+
$hitCount = $overwriteHitCount;
|
| 205 |
+
|
| 206 |
+
//create search request
|
| 207 |
+
$bxRequest = new \com\boxalino\bxclient\v1\BxSearchRequest($this->bxHelperData->getLanguage(), $queryText, $hitCount, $this->getSearchChoice($queryText));
|
| 208 |
+
$bxRequest->setGroupBy($this->getEntityIdFieldName());
|
| 209 |
+
$bxRequest->setReturnFields($returnFields);
|
| 210 |
+
$bxRequest->setOffset($pageOffset);
|
| 211 |
+
$bxRequest->setSortFields($bxSortFields);
|
| 212 |
+
$bxRequest->setFacets($this->prepareFacets());
|
| 213 |
+
$bxRequest->setFilters($this->getSystemFilters($queryText));
|
| 214 |
+
$bxRequest->setMax($hitCount);
|
| 215 |
+
|
| 216 |
+
if($categoryId != null) {
|
| 217 |
+
$filterField = "category_id";
|
| 218 |
+
$filterValues = array($categoryId);
|
| 219 |
+
$filterNegative = false;
|
| 220 |
+
$bxRequest->addFilter(new com\boxalino\bxclient\v1\BxFilter($filterField, $filterValues, $filterNegative));
|
| 221 |
+
}
|
| 222 |
+
self::$bxClient->addRequest($bxRequest);
|
| 223 |
+
}
|
| 224 |
+
|
| 225 |
+
/**
|
| 226 |
+
*
|
| 227 |
+
*/
|
| 228 |
+
public function simpleSearch(){
|
| 229 |
+
|
| 230 |
+
$request = Mage::app()->getRequest();
|
| 231 |
+
$queryText = Mage::helper('catalogsearch')->getEscapedQueryText();
|
| 232 |
+
if (self::$bxClient->getChoiceIdRecommendationRequest($this->getSearchChoice($queryText)) != null) {
|
| 233 |
+
return;
|
| 234 |
+
}
|
| 235 |
+
|
| 236 |
+
$field = '';
|
| 237 |
+
$dir = '';
|
| 238 |
+
$order = $request->getParam('order');
|
| 239 |
+
if (isset($order)) {
|
| 240 |
+
if ($order == 'name') {
|
| 241 |
+
$field = 'title';
|
| 242 |
+
} elseif ($order == 'price') {
|
| 243 |
+
$field = 'products_bx_grouped_price';
|
| 244 |
+
}
|
| 245 |
+
}
|
| 246 |
+
|
| 247 |
+
$dirOrder = $request->getParam('dir');
|
| 248 |
+
if ($dirOrder) {
|
| 249 |
+
$dir = $dirOrder == 'asc' ? false : true;
|
| 250 |
+
} else {
|
| 251 |
+
$dir = true;
|
| 252 |
+
}
|
| 253 |
+
|
| 254 |
+
$categoryId = $request->getParam($this->getUrlParameterPrefix() . 'category_id');
|
| 255 |
+
if (empty($categoryId)) {
|
| 256 |
+
|
| 257 |
+
$category = Mage::registry('current_category');
|
| 258 |
+
if (!empty($category)) {
|
| 259 |
+
$_REQUEST[$this->getUrlParameterPrefix() . 'category_id'][0] = $category->getId();
|
| 260 |
+
}
|
| 261 |
+
// GET param 'cat' may override the current_category,
|
| 262 |
+
// i.e. when clicking on subcategories in a category page
|
| 263 |
+
$cat = $request->getParam('id');
|
| 264 |
+
if (!empty($cat)) {
|
| 265 |
+
$_REQUEST[$this->getUrlParameterPrefix() . 'category_id'][0] = $cat;
|
| 266 |
+
}
|
| 267 |
+
}
|
| 268 |
+
|
| 269 |
+
$toolbar = Mage::getBlockSingleton('catalog/product_list_toolbar');
|
| 270 |
+
$overWriteLimit = $toolbar->getLimit();
|
| 271 |
+
$pageOffset = isset($_REQUEST['p'])? ($_REQUEST['p']-1)*($overWriteLimit) : 0;
|
| 272 |
+
$this->search($queryText, $pageOffset, $overWriteLimit, new \com\boxalino\bxclient\v1\BxSortFields($field, $dir), $categoryId);
|
| 273 |
+
}
|
| 274 |
+
|
| 275 |
+
/**
|
| 276 |
+
* @return string
|
| 277 |
+
*/
|
| 278 |
+
private function getUrlParameterPrefix() {
|
| 279 |
+
|
| 280 |
+
return 'bx_';
|
| 281 |
+
}
|
| 282 |
+
|
| 283 |
+
/**
|
| 284 |
+
* @return \com\boxalino\bxclient\v1\BxFacets
|
| 285 |
+
*/
|
| 286 |
+
private function prepareFacets(){
|
| 287 |
+
|
| 288 |
+
$bxFacets = new \com\boxalino\bxclient\v1\BxFacets();
|
| 289 |
+
$bxHelperData = Mage::helper('intelligence');
|
| 290 |
+
$selectedValues = array();
|
| 291 |
+
foreach ($_REQUEST as $key => $values) {
|
| 292 |
+
if (strpos($key, $this->getUrlParameterPrefix()) !== false) {
|
| 293 |
+
$fieldName = substr($key, 3);
|
| 294 |
+
$selectedValues[$fieldName] = !is_array($values)?array($values):$values;
|
| 295 |
+
}
|
| 296 |
+
}
|
| 297 |
+
|
| 298 |
+
$catId = isset($selectedValues['category_id']) && sizeof($selectedValues['category_id']) > 0 ? $selectedValues['category_id'][0] : null;
|
| 299 |
+
|
| 300 |
+
$bxFacets->addCategoryFacet($catId);
|
| 301 |
+
$attributeCollection = $bxHelperData->getLeftFacets();
|
| 302 |
+
|
| 303 |
+
foreach($attributeCollection as $code => $attribute){
|
| 304 |
+
$bound = $code == 'discountedPrice' ? true : false;
|
| 305 |
+
list($label, $type, $order, $position) = array_values($attribute);
|
| 306 |
+
$selectedValue = isset($selectedValues[$code]) ? $selectedValues[$code][0] : null;
|
| 307 |
+
|
| 308 |
+
$bxFacets->addFacet($code, $selectedValue, $type, $label, $order, $bound);
|
| 309 |
+
}
|
| 310 |
+
list($topField, $topOrder) = $bxHelperData->getTopFacetConfig();
|
| 311 |
+
|
| 312 |
+
if($topField) {
|
| 313 |
+
$selectedValue = isset($selectedValues[$topField][0]) ? $selectedValues[$topField][0] : null;
|
| 314 |
+
$bxFacets->addFacet($topField, $selectedValue, "string", $topField, $topOrder);
|
| 315 |
+
}
|
| 316 |
+
return $bxFacets;
|
| 317 |
+
}
|
| 318 |
+
|
| 319 |
+
/**
|
| 320 |
+
* @return int
|
| 321 |
+
*/
|
| 322 |
+
public function getTotalHitCount(){
|
| 323 |
+
|
| 324 |
+
$this->simpleSearch();
|
| 325 |
+
return self::$bxClient->getResponse()->getTotalHitCount($this->currentSearchChoice);
|
| 326 |
+
}
|
| 327 |
+
|
| 328 |
+
/**
|
| 329 |
+
* @return array
|
| 330 |
+
*/
|
| 331 |
+
public function getEntitiesIds()
|
| 332 |
+
{
|
| 333 |
+
$this->simpleSearch();
|
| 334 |
+
return self::$bxClient->getResponse()->getHitIds($this->currentSearchChoice);
|
| 335 |
+
}
|
| 336 |
+
|
| 337 |
+
/**
|
| 338 |
+
* @return null
|
| 339 |
+
*/
|
| 340 |
+
public function getFacets() {
|
| 341 |
+
|
| 342 |
+
$this->simpleSearch();
|
| 343 |
+
$facets = self::$bxClient->getResponse()->getFacets($this->currentSearchChoice);
|
| 344 |
+
if(empty($facets)){
|
| 345 |
+
return null;
|
| 346 |
+
}
|
| 347 |
+
$facets->setParameterPrefix($this->getUrlParameterPrefix());
|
| 348 |
+
return $facets;
|
| 349 |
+
}
|
| 350 |
+
|
| 351 |
+
/**
|
| 352 |
+
* @return null
|
| 353 |
+
*/
|
| 354 |
+
public function getCorrectedQuery() {
|
| 355 |
+
|
| 356 |
+
$this->simpleSearch();
|
| 357 |
+
return self::$bxClient->getResponse()->getCorrectedQuery($this->currentSearchChoice);
|
| 358 |
+
}
|
| 359 |
+
|
| 360 |
+
/**
|
| 361 |
+
* @return bool
|
| 362 |
+
*/
|
| 363 |
+
public function areResultsCorrected() {
|
| 364 |
+
|
| 365 |
+
$this->simpleSearch();
|
| 366 |
+
return self::$bxClient->getResponse()->areResultsCorrected($this->currentSearchChoice);
|
| 367 |
+
}
|
| 368 |
+
|
| 369 |
+
/**
|
| 370 |
+
* @return bool
|
| 371 |
+
*/
|
| 372 |
+
public function areThereSubPhrases() {
|
| 373 |
+
|
| 374 |
+
$this->simpleSearch();
|
| 375 |
+
return self::$bxClient->getResponse()->areThereSubPhrases($this->currentSearchChoice);
|
| 376 |
+
}
|
| 377 |
+
|
| 378 |
+
/**
|
| 379 |
+
* @return array
|
| 380 |
+
*/
|
| 381 |
+
public function getSubPhrasesQueries() {
|
| 382 |
+
|
| 383 |
+
$this->simpleSearch();
|
| 384 |
+
return self::$bxClient->getResponse()->getSubPhrasesQueries($this->currentSearchChoice);
|
| 385 |
+
}
|
| 386 |
+
|
| 387 |
+
/**
|
| 388 |
+
* @param $queryText
|
| 389 |
+
* @return int|mixed
|
| 390 |
+
*/
|
| 391 |
+
public function getSubPhraseTotalHitCount($queryText) {
|
| 392 |
+
|
| 393 |
+
$this->simpleSearch();
|
| 394 |
+
return self::$bxClient->getResponse()->getSubPhraseTotalHitCount($queryText,$this->currentSearchChoice);
|
| 395 |
+
}
|
| 396 |
+
|
| 397 |
+
/**
|
| 398 |
+
* @param $queryText
|
| 399 |
+
* @return array
|
| 400 |
+
*/
|
| 401 |
+
public function getSubPhraseEntitiesIds($queryText) {
|
| 402 |
+
$this->simpleSearch();
|
| 403 |
+
return self::$bxClient->getResponse()->getSubPhraseHitIds($queryText, $this->currentSearchChoice);
|
| 404 |
+
}
|
| 405 |
+
|
| 406 |
+
/**
|
| 407 |
+
* @param $widgetName
|
| 408 |
+
* @param array $context
|
| 409 |
+
* @param string $widgetType
|
| 410 |
+
* @param int $minAmount
|
| 411 |
+
* @param int $amount
|
| 412 |
+
* @param bool $execute
|
| 413 |
+
* @return array|void
|
| 414 |
+
*/
|
| 415 |
+
public function getRecommendation($widgetName, $context = array(), $widgetType = '', $minAmount = 3, $amount = 3, $execute=true){
|
| 416 |
+
|
| 417 |
+
if(!$execute) {
|
| 418 |
+
if(!isset(self::$choiceContexts[$widgetName])) {
|
| 419 |
+
self::$choiceContexts[$widgetName] = array();
|
| 420 |
+
}
|
| 421 |
+
if(in_array(json_encode($context), self::$choiceContexts[$widgetName])) {
|
| 422 |
+
return;
|
| 423 |
+
}
|
| 424 |
+
self::$choiceContexts[$widgetName][] = json_encode($context);
|
| 425 |
+
if ($widgetType == '') {
|
| 426 |
+
$bxRequest = new \com\boxalino\bxclient\v1\BxRecommendationRequest($this->bxHelperData->getLanguage(), $widgetName, $amount);
|
| 427 |
+
$bxRequest->setGroupBy($this->getEntityIdFieldName());
|
| 428 |
+
$bxRequest->setMin($minAmount);
|
| 429 |
+
$bxRequest->setFilters($this->getSystemFilters());
|
| 430 |
+
if (isset($context[0])) {
|
| 431 |
+
$product = $context[0];
|
| 432 |
+
$bxRequest->setProductContext($this->getEntityIdFieldName(), $product->getId());
|
| 433 |
+
}
|
| 434 |
+
self::$bxClient->addRequest($bxRequest);
|
| 435 |
+
} else {
|
| 436 |
+
if (($minAmount >= 0) && ($amount >= 0) && ($minAmount <= $amount)) {
|
| 437 |
+
$bxRequest = new \com\boxalino\bxclient\v1\BxRecommendationRequest($this->bxHelperData->getLanguage(), $widgetName, $amount, $minAmount);
|
| 438 |
+
$bxRequest->setGroupBy($this->getEntityIdFieldName());
|
| 439 |
+
$bxRequest->setFilters($this->getSystemFilters());
|
| 440 |
+
$bxRequest->setReturnFields(array($this->getEntityIdFieldName()));
|
| 441 |
+
if ($widgetType === 'basket' && is_array($context)) {
|
| 442 |
+
$basketProducts = array();
|
| 443 |
+
foreach($context as $product) {
|
| 444 |
+
$basketProducts[] = array('id'=>$product->getId(), 'price'=>$product->getPrice());
|
| 445 |
+
}
|
| 446 |
+
$bxRequest->setBasketProductWithPrices($this->getEntityIdFieldName(), $basketProducts);
|
| 447 |
+
} elseif ($widgetType === 'product' && !is_array($context)) {
|
| 448 |
+
$product = $context;
|
| 449 |
+
$bxRequest->setProductContext($this->getEntityIdFieldName(), $product->getId());
|
| 450 |
+
} elseif ($widgetType === 'category' && $context != null){
|
| 451 |
+
$filterField = "category_id";
|
| 452 |
+
$filterValues = is_array($context) ? $context : array($context);
|
| 453 |
+
$filterNegative = false;
|
| 454 |
+
|
| 455 |
+
$bxRequest->addFilter(new \com\boxalino\bxclient\v1\BxFilter($filterField, $filterValues, $filterNegative));
|
| 456 |
+
}
|
| 457 |
+
self::$bxClient->addRequest($bxRequest);
|
| 458 |
+
}
|
| 459 |
+
}
|
| 460 |
+
return array();
|
| 461 |
+
}
|
| 462 |
+
$count = array_search(json_encode(array($context)), self::$choiceContexts[$widgetName]);
|
| 463 |
+
// var_dump(self::$bxClient->getResponse());exit;
|
| 464 |
+
return self::$bxClient->getResponse()->getHitIds($widgetName, true, $count);
|
| 465 |
+
}
|
| 466 |
+
}
|
app/code/community/Boxalino/Intelligence/Model/Delta.php
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
/**
|
| 4 |
+
* Class Boxalino_Intelligence_Model_Delta
|
| 5 |
+
*/
|
| 6 |
+
class Boxalino_Intelligence_Model_Delta extends Mage_Index_Model_Indexer_Abstract{
|
| 7 |
+
|
| 8 |
+
/**
|
| 9 |
+
* @return string
|
| 10 |
+
*/
|
| 11 |
+
public function getName()
|
| 12 |
+
{
|
| 13 |
+
return "Boxalino Delta Data Export";
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
/**
|
| 17 |
+
* @return string
|
| 18 |
+
*/
|
| 19 |
+
public function getDescription()
|
| 20 |
+
{
|
| 21 |
+
return "Send latest data to Boxalino";
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
/**
|
| 25 |
+
*
|
| 26 |
+
*/
|
| 27 |
+
protected function _construct()
|
| 28 |
+
{
|
| 29 |
+
$this->_init('intelligence/exporter_delta');
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
/**
|
| 33 |
+
* @param Mage_Index_Model_Event $event
|
| 34 |
+
*/
|
| 35 |
+
public function _registerEvent(Mage_Index_Model_Event $event)
|
| 36 |
+
{
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
/**
|
| 40 |
+
* @param Mage_Index_Model_Event $event
|
| 41 |
+
*/
|
| 42 |
+
public function _processEvent(Mage_Index_Model_Event $event)
|
| 43 |
+
{
|
| 44 |
+
}
|
| 45 |
+
}
|
app/code/community/Boxalino/Intelligence/Model/Indexer.php
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
/**
|
| 4 |
+
* Class Boxalino_Intelligence_Model_Indexer
|
| 5 |
+
*/
|
| 6 |
+
class Boxalino_Intelligence_Model_Indexer extends Mage_Index_Model_Indexer_Abstract{
|
| 7 |
+
|
| 8 |
+
/**
|
| 9 |
+
* @return string
|
| 10 |
+
*/
|
| 11 |
+
public function getName()
|
| 12 |
+
{
|
| 13 |
+
return "Boxalino Full Data Export";
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
/**
|
| 17 |
+
* @return string
|
| 18 |
+
*/
|
| 19 |
+
public function getDescription()
|
| 20 |
+
{
|
| 21 |
+
return "Send all data to Boxalino";
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
/**
|
| 25 |
+
*
|
| 26 |
+
*/
|
| 27 |
+
protected function _construct()
|
| 28 |
+
{
|
| 29 |
+
$this->_init('intelligence/exporter_indexer');
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
/**
|
| 33 |
+
* @param Mage_Index_Model_Event $event
|
| 34 |
+
*/
|
| 35 |
+
protected function _registerEvent(Mage_Index_Model_Event $event)
|
| 36 |
+
{
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
/**
|
| 40 |
+
* @param Mage_Index_Model_Event $event
|
| 41 |
+
*/
|
| 42 |
+
protected function _processEvent(Mage_Index_Model_Event $event)
|
| 43 |
+
{
|
| 44 |
+
}
|
| 45 |
+
}
|
app/code/community/Boxalino/Intelligence/Model/Layer/Filter/Attribute.php
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
/**
|
| 4 |
+
* Class Boxalino_Intelligence_Model_Layer_Filter_Attribute
|
| 5 |
+
*/
|
| 6 |
+
class Boxalino_Intelligence_Model_Layer_Filter_Attribute extends Mage_Catalog_Model_Layer_Filter_Attribute{
|
| 7 |
+
|
| 8 |
+
/**
|
| 9 |
+
* @var null
|
| 10 |
+
*/
|
| 11 |
+
private $bxFacets = null;
|
| 12 |
+
|
| 13 |
+
/**
|
| 14 |
+
* @var array
|
| 15 |
+
*/
|
| 16 |
+
private $fieldName = array();
|
| 17 |
+
|
| 18 |
+
/**
|
| 19 |
+
* @param $bxFacets
|
| 20 |
+
*/
|
| 21 |
+
public function setFacets($bxFacets) {
|
| 22 |
+
|
| 23 |
+
$this->bxFacets = $bxFacets;
|
| 24 |
+
return $this;
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
/**
|
| 28 |
+
* @return null
|
| 29 |
+
*/
|
| 30 |
+
public function getFacets(){
|
| 31 |
+
return $this->bxFacets;
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
/**
|
| 35 |
+
* @param $fieldName
|
| 36 |
+
*/
|
| 37 |
+
public function setFieldName($fieldName) {
|
| 38 |
+
|
| 39 |
+
$this->fieldName = $fieldName;
|
| 40 |
+
return $this;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
/**
|
| 44 |
+
* @return mixed
|
| 45 |
+
*/
|
| 46 |
+
public function getName(){
|
| 47 |
+
|
| 48 |
+
return $this->bxFacets->getFacetLabel($this->fieldName);
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
/**
|
| 52 |
+
* @return array
|
| 53 |
+
*/
|
| 54 |
+
public function getFieldName(){
|
| 55 |
+
|
| 56 |
+
return $this->fieldName;
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
/**
|
| 60 |
+
*
|
| 61 |
+
*/
|
| 62 |
+
public function _initItems(){
|
| 63 |
+
|
| 64 |
+
$items = [];
|
| 65 |
+
$data = $this->_getItemsData();
|
| 66 |
+
foreach ($data as $itemData) {
|
| 67 |
+
$selected = isset($itemData['selected']) ? $itemData['selected'] : null;
|
| 68 |
+
$type = isset($itemData['type']) ? $itemData['type'] : null;
|
| 69 |
+
$items[] = $this->_createItem($itemData['label'], $itemData['value'], $itemData['count'], $selected, $type);
|
| 70 |
+
}
|
| 71 |
+
$this->_items = $items;
|
| 72 |
+
return $this;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
/**
|
| 76 |
+
* @param string $label
|
| 77 |
+
* @param mixed $value
|
| 78 |
+
* @param int $count
|
| 79 |
+
* @param null $selected
|
| 80 |
+
* @param null $type
|
| 81 |
+
* @return mixed
|
| 82 |
+
*/
|
| 83 |
+
public function _createItem($label, $value, $count = 0, $selected = null, $type = null){
|
| 84 |
+
|
| 85 |
+
return Mage::getModel('catalog/layer_filter_item')
|
| 86 |
+
->setFilter($this)
|
| 87 |
+
->setLabel($label)
|
| 88 |
+
->setValue($value)
|
| 89 |
+
->setCount($count)
|
| 90 |
+
->setSelected($selected)
|
| 91 |
+
->setType($type);
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
/**
|
| 95 |
+
* @return array
|
| 96 |
+
*/
|
| 97 |
+
protected function _getItemsData(){
|
| 98 |
+
|
| 99 |
+
$data = [];
|
| 100 |
+
$bxDataHelper = Mage::helper('intelligence');
|
| 101 |
+
$this->_requestVar = $this->bxFacets->getFacetParameterName($this->fieldName);
|
| 102 |
+
if (!$bxDataHelper->isHierarchical($this->fieldName)) {
|
| 103 |
+
foreach ($this->bxFacets->getFacetValues($this->fieldName) as $facetValue) {
|
| 104 |
+
if ($this->bxFacets->getSelectedValues($this->fieldName) && $this->bxFacets->getSelectedValues($this->fieldName)[0] == $facetValue) {
|
| 105 |
+
$value = $this->bxFacets->getSelectedValues($this->fieldName)[0] == $facetValue ? true : false;
|
| 106 |
+
$data[] = array(
|
| 107 |
+
'label' => strip_tags($this->bxFacets->getFacetValueLabel($this->fieldName, $facetValue)),
|
| 108 |
+
'value' => 0,
|
| 109 |
+
'count' => $this->bxFacets->getFacetValueCount($this->fieldName, $facetValue),
|
| 110 |
+
'selected' => $value,
|
| 111 |
+
'type' => 'flat'
|
| 112 |
+
);
|
| 113 |
+
} else {
|
| 114 |
+
$value = false;
|
| 115 |
+
$data[] = array(
|
| 116 |
+
'label' => strip_tags($this->bxFacets->getFacetValueLabel($this->fieldName, $facetValue)),
|
| 117 |
+
'value' => $this->bxFacets->getFacetValueParameterValue($this->fieldName, $facetValue),
|
| 118 |
+
'count' => $this->bxFacets->getFacetValueCount($this->fieldName, $facetValue),
|
| 119 |
+
'selected' => $value,
|
| 120 |
+
'type' => 'flat'
|
| 121 |
+
);
|
| 122 |
+
}
|
| 123 |
+
}
|
| 124 |
+
} else {
|
| 125 |
+
$count = 1;
|
| 126 |
+
$facetValues = array();
|
| 127 |
+
$parentCategories = $this->bxFacets->getParentCategories();
|
| 128 |
+
$parentCount = count($parentCategories);
|
| 129 |
+
$value = false;
|
| 130 |
+
foreach ($parentCategories as $key => $parentCategory) {
|
| 131 |
+
if ($count == 1) {
|
| 132 |
+
$count++;
|
| 133 |
+
$homeLabel = __("All Categories");
|
| 134 |
+
$data[] = array(
|
| 135 |
+
'label' => strip_tags($homeLabel),
|
| 136 |
+
'value' => 2,
|
| 137 |
+
'count' => $this->bxFacets->getParentCategoriesHitCount($key),
|
| 138 |
+
'selected' => $value,
|
| 139 |
+
'type' => 'home parent'
|
| 140 |
+
);
|
| 141 |
+
continue;
|
| 142 |
+
}
|
| 143 |
+
if ($parentCount == $count++) {
|
| 144 |
+
$value = true;
|
| 145 |
+
}
|
| 146 |
+
$data[] = array(
|
| 147 |
+
'label' => strip_tags($parentCategory),
|
| 148 |
+
'value' => $key,
|
| 149 |
+
'count' => $this->bxFacets->getParentCategoriesHitCount($key),
|
| 150 |
+
'selected' => $value,
|
| 151 |
+
'type' => 'parent'
|
| 152 |
+
);
|
| 153 |
+
}
|
| 154 |
+
$sortOrder = $bxDataHelper->getCategoriesSortOrder();
|
| 155 |
+
if($sortOrder == 2){
|
| 156 |
+
$facetLabels = $this->bxFacets->getCategoriesKeyLabels();
|
| 157 |
+
$childId = explode('/',end($facetLabels))[0];
|
| 158 |
+
$childParentId = Mage::getModel('catalog/category')->load($childId)->getParentId();
|
| 159 |
+
end($parentCategories);
|
| 160 |
+
$parentId = key($parentCategories);
|
| 161 |
+
$id = (($parentId == null) ? 2 : (($parentId == $childParentId) ? $parentId : $childParentId));
|
| 162 |
+
|
| 163 |
+
$cat = $this->categoryFactory->create()->load($id);
|
| 164 |
+
foreach($cat->getChildrenCategories() as $category){
|
| 165 |
+
if(isset($facetLabels[$category->getName()])) {
|
| 166 |
+
$facetValues[] = $facetLabels[$category->getName()];
|
| 167 |
+
}
|
| 168 |
+
}
|
| 169 |
+
}
|
| 170 |
+
if($facetValues == null){
|
| 171 |
+
$facetValues = $this->bxFacets->getCategories();
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
foreach ($facetValues as $facetValue) {
|
| 175 |
+
$id = $this->bxFacets->getFacetValueParameterValue($this->fieldName, $facetValue);
|
| 176 |
+
if ($sortOrder == 2 || Mage::helper('catalog/category')->canShow((int)$id)) {
|
| 177 |
+
$data[] = array(
|
| 178 |
+
'label' => strip_tags($this->bxFacets->getFacetValueLabel($this->fieldName, $facetValue)),
|
| 179 |
+
'value' => $id,
|
| 180 |
+
'count' => $this->bxFacets->getFacetValueCount($this->fieldName, $facetValue),
|
| 181 |
+
'selected' => false,
|
| 182 |
+
'type' => $value ? 'children' : 'home'
|
| 183 |
+
);
|
| 184 |
+
}
|
| 185 |
+
}
|
| 186 |
+
}
|
| 187 |
+
return $data;
|
| 188 |
+
}
|
| 189 |
+
}
|
app/code/community/Boxalino/Intelligence/Model/Mysql4/Exporter/Delta.php
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
class Boxalino_Intelligence_Model_Mysql4_Exporter_Delta extends Boxalino_Intelligence_Model_Mysql4_Indexer
|
| 4 |
+
{
|
| 5 |
+
const INDEX_TYPE = 'delta';
|
| 6 |
+
|
| 7 |
+
/** @var date Date of last data sync */
|
| 8 |
+
protected $_lastIndex = 0;
|
| 9 |
+
|
| 10 |
+
/**
|
| 11 |
+
* @description Declare where Indexer should start
|
| 12 |
+
* @return void
|
| 13 |
+
*/
|
| 14 |
+
protected function _construct()
|
| 15 |
+
{
|
| 16 |
+
$this->_init('intelligence/delta', '');
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
/**
|
| 20 |
+
* @description Get list of products with their tags
|
| 21 |
+
* @return object List of products with their tags
|
| 22 |
+
*/
|
| 23 |
+
protected function _getProductTags()
|
| 24 |
+
{
|
| 25 |
+
if (empty($this->_allProductTags)) {
|
| 26 |
+
$tags = Mage::getResourceModel('tag/product_collection')->addAttributeToFilter('updated_at', array('from' => $this->_getLastIndex(), 'date' => true))->getData();
|
| 27 |
+
foreach ($tags as $tag) {
|
| 28 |
+
$this->_allProductTags[$tag['entity_id']] = $tag['tag_id'];
|
| 29 |
+
}
|
| 30 |
+
}
|
| 31 |
+
return $this->_allProductTags;
|
| 32 |
+
}
|
| 33 |
+
}
|
app/code/community/Boxalino/{Exporter → Intelligence}/Model/Mysql4/Exporter/Indexer.php
RENAMED
|
@@ -1,16 +1,16 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
|
| 3 |
-
class
|
| 4 |
-
{
|
| 5 |
-
const INDEX_TYPE = 'full';
|
| 6 |
-
|
| 7 |
-
/**
|
| 8 |
-
* @description Declare where Indexer should start
|
| 9 |
-
* @return void
|
| 10 |
-
*/
|
| 11 |
-
protected function _construct()
|
| 12 |
-
{
|
| 13 |
-
$this->_init('
|
| 14 |
-
}
|
| 15 |
-
|
| 16 |
}
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
class Boxalino_Intelligence_Model_Mysql4_Exporter_Indexer extends Boxalino_Intelligence_Model_Mysql4_Indexer
|
| 4 |
+
{
|
| 5 |
+
const INDEX_TYPE = 'full';
|
| 6 |
+
|
| 7 |
+
/**
|
| 8 |
+
* @description Declare where Indexer should start
|
| 9 |
+
* @return void
|
| 10 |
+
*/
|
| 11 |
+
protected function _construct()
|
| 12 |
+
{
|
| 13 |
+
$this->_init('intelligence/indexer', '');
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
}
|
app/code/community/Boxalino/Intelligence/Model/Mysql4/Indexer.php
ADDED
|
@@ -0,0 +1,1481 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
/**
|
| 4 |
+
* Class Boxalino_Intelligence_Model_Mysql4_Indexer
|
| 5 |
+
*/
|
| 6 |
+
abstract class Boxalino_Intelligence_Model_Mysql4_Indexer extends Mage_Core_Model_Mysql4_Abstract{
|
| 7 |
+
|
| 8 |
+
/**
|
| 9 |
+
* @var
|
| 10 |
+
*/
|
| 11 |
+
protected $_prefix;
|
| 12 |
+
|
| 13 |
+
/**
|
| 14 |
+
* @var
|
| 15 |
+
*/
|
| 16 |
+
protected $config;
|
| 17 |
+
|
| 18 |
+
/**
|
| 19 |
+
* @var
|
| 20 |
+
*/
|
| 21 |
+
protected $bxData;
|
| 22 |
+
|
| 23 |
+
/**
|
| 24 |
+
* @var
|
| 25 |
+
*/
|
| 26 |
+
protected $indexType;
|
| 27 |
+
|
| 28 |
+
/**
|
| 29 |
+
* @var
|
| 30 |
+
*/
|
| 31 |
+
protected $_helperExporter;
|
| 32 |
+
|
| 33 |
+
/**
|
| 34 |
+
* @var null
|
| 35 |
+
*/
|
| 36 |
+
protected $_entityTypeIds = null;
|
| 37 |
+
|
| 38 |
+
/**
|
| 39 |
+
* @var int
|
| 40 |
+
*/
|
| 41 |
+
protected $_lastIndex = 0;
|
| 42 |
+
|
| 43 |
+
/**
|
| 44 |
+
* @var array
|
| 45 |
+
*/
|
| 46 |
+
protected $deltaIds = array();
|
| 47 |
+
|
| 48 |
+
/**
|
| 49 |
+
*
|
| 50 |
+
*/
|
| 51 |
+
const BOXALINO_LOG_FILE = 'boxalino_exporter.log';
|
| 52 |
+
|
| 53 |
+
/**
|
| 54 |
+
* @return $this
|
| 55 |
+
*/
|
| 56 |
+
public function reindexAll()
|
| 57 |
+
{
|
| 58 |
+
$this->loadBxLibrary();
|
| 59 |
+
$this->indexType = static::INDEX_TYPE;
|
| 60 |
+
$this->_prefix = Mage::getConfig()->getTablePrefix();
|
| 61 |
+
$this->exportStores();
|
| 62 |
+
return $this;
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
/**
|
| 66 |
+
*
|
| 67 |
+
*/
|
| 68 |
+
protected function exportStores(){
|
| 69 |
+
|
| 70 |
+
$this->_helperExporter = Mage::helper('intelligence');
|
| 71 |
+
Mage::log("bxLog: starting exportStores", Zend_Log::INFO, self::BOXALINO_LOG_FILE);
|
| 72 |
+
$this->config = Mage::helper('intelligence/bxindexconfig');
|
| 73 |
+
Mage::log("bxLog: retrieved index config: " . $this->config->toString(), Zend_Log::INFO, self::BOXALINO_LOG_FILE);
|
| 74 |
+
try {
|
| 75 |
+
foreach ($this->config->getAccounts() as $account) {
|
| 76 |
+
|
| 77 |
+
Mage::log("bxLog: initialize files on account: " . $account, Zend_Log::INFO, self::BOXALINO_LOG_FILE);
|
| 78 |
+
$files = Mage::helper('intelligence/bxfiles');
|
| 79 |
+
|
| 80 |
+
$bxClient = new \com\boxalino\bxclient\v1\BxClient($account, $this->config->getAccountPassword($account), "");
|
| 81 |
+
$this->bxData = new \com\boxalino\bxclient\v1\BxData($bxClient, $this->config->getAccountLanguages($account), $this->config->isAccountDev($account), false);
|
| 82 |
+
Mage::log("bxLog: verify credentials for account: " . $account, Zend_Log::INFO, self::BOXALINO_LOG_FILE);
|
| 83 |
+
$this->bxData->verifyCredentials();
|
| 84 |
+
|
| 85 |
+
Mage::log("bxLog: verify credentials for account: " . $account, Zend_Log::INFO, self::BOXALINO_LOG_FILE);
|
| 86 |
+
$categories = array();
|
| 87 |
+
foreach ($this->config->getAccountLanguages($account) as $language) {
|
| 88 |
+
$store = $this->config->getStore($account, $language);
|
| 89 |
+
Mage::log('bxLog: Start getStoreProductAttributes for language: ' . $language . ' on store: ' . $store->getId(), Zend_Log::INFO, self::BOXALINO_LOG_FILE);
|
| 90 |
+
Mage::log('bxLog: Start exportCategories for language: ' . $language . ' on store:' . $store->getId(), Zend_Log::INFO, self::BOXALINO_LOG_FILE);
|
| 91 |
+
$categories = $this->exportCategories($store, $language, $categories);
|
| 92 |
+
}
|
| 93 |
+
Mage::log('bxLog: Export the customers, transactions and product files for account: ' . $account, Zend_Log::INFO, self::BOXALINO_LOG_FILE);
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
$exportProducts = $this->exportProducts($account, $files);
|
| 97 |
+
if($this->indexType == 'full'){
|
| 98 |
+
$this->exportCustomers($account, $files);
|
| 99 |
+
$this->exportTransactions($account, $files);
|
| 100 |
+
$this->prepareData($account, $files, $categories);
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
if(!$exportProducts){
|
| 104 |
+
Mage::log('bxLog: No Products found for account: ' . $account, Zend_Log::INFO, self::BOXALINO_LOG_FILE);
|
| 105 |
+
Mage::log('bxLog: Finished account: ' . $account, Zend_Log::INFO, self::BOXALINO_LOG_FILE);
|
| 106 |
+
}else{
|
| 107 |
+
if($this->indexType == 'full'){
|
| 108 |
+
Mage::log('bxLog: Prepare the final files: ' . $account, Zend_Log::INFO, self::BOXALINO_LOG_FILE);
|
| 109 |
+
Mage::log('bxLog: Prepare XML configuration file: ' . $account, Zend_Log::INFO, self::BOXALINO_LOG_FILE);
|
| 110 |
+
try {
|
| 111 |
+
Mage::log('bxLog: Push the XML configuration file to the Data Indexing server for account: ' . $account, Zend_Log::INFO, self::BOXALINO_LOG_FILE);
|
| 112 |
+
$this->bxData->pushDataSpecifications();
|
| 113 |
+
} catch(\Exception $e) {
|
| 114 |
+
$value = @json_decode($e->getMessage(), true);
|
| 115 |
+
if(isset($value['error_type_number']) && $value['error_type_number'] == 3) {
|
| 116 |
+
Mage::log('bxLog: Try to push the XML file a second time, error 3 happens always at the very first time but not after: ' . $account, Zend_Log::INFO, self::BOXALINO_LOG_FILE);
|
| 117 |
+
$this->bxData->pushDataSpecifications();
|
| 118 |
+
} else {
|
| 119 |
+
throw $e;
|
| 120 |
+
}
|
| 121 |
+
}
|
| 122 |
+
Mage::log('bxLog: Publish the configuration changes from the magento2 owner for account: ' . $account, Zend_Log::INFO, self::BOXALINO_LOG_FILE);
|
| 123 |
+
$publish = $this->config->publishConfigurationChanges($account);
|
| 124 |
+
$changes = $this->bxData->publishChanges($publish);
|
| 125 |
+
if(sizeof($changes['changes']) > 0 && !$publish) {
|
| 126 |
+
Mage::log("changes in configuration detected but not published as publish configuration automatically option has not been activated for account: " . $account, Zend_Log::WARN, self::BOXALINO_LOG_FILE);
|
| 127 |
+
}
|
| 128 |
+
Mage::log('bxLog: Push the Zip data file to the Data Indexing server for account: ' . $account, Zend_Log::INFO, self::BOXALINO_LOG_FILE);
|
| 129 |
+
}
|
| 130 |
+
try{
|
| 131 |
+
$this->bxData->pushData();
|
| 132 |
+
}catch(\Exception $e){
|
| 133 |
+
throw $e;
|
| 134 |
+
}
|
| 135 |
+
Mage::log('bxLog: Finished account: ' . $account, Zend_Log::INFO, self::BOXALINO_LOG_FILE);
|
| 136 |
+
}
|
| 137 |
+
}
|
| 138 |
+
}catch(\Exception $e){
|
| 139 |
+
Mage::log("bxLog: failed with exception: " . $e->getMessage(), Zend_Log::INFO, self::BOXALINO_LOG_FILE);
|
| 140 |
+
}
|
| 141 |
+
Mage::log("bxLog: finished exportStores", Zend_Log::INFO, self::BOXALINO_LOG_FILE);
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
/**
|
| 145 |
+
* @param $account
|
| 146 |
+
* @param $files
|
| 147 |
+
* @param $categories
|
| 148 |
+
* @param null $tags
|
| 149 |
+
* @param null $productTags
|
| 150 |
+
*/
|
| 151 |
+
protected function prepareData($account, $files, $categories, $tags = null, $productTags = null){
|
| 152 |
+
$withTag = ($tags != null && $productTags != null) ? true : false;
|
| 153 |
+
$languages = $this->config->getAccountLanguages($account);
|
| 154 |
+
$categories = array_merge(array(array_keys(end($categories))), $categories);
|
| 155 |
+
$files->savePartToCsv('categories.csv', $categories);
|
| 156 |
+
$labelColumns = array();
|
| 157 |
+
foreach ($languages as $lang) {
|
| 158 |
+
$labelColumns[$lang] = 'value_' . $lang;
|
| 159 |
+
}
|
| 160 |
+
$this->bxData->addCategoryFile($files->getPath('categories.csv'), 'category_id', 'parent_id', $labelColumns);
|
| 161 |
+
$productToCategoriesSourceKey = $this->bxData->addCSVItemFile($files->getPath('product_categories.csv'), 'entity_id');
|
| 162 |
+
$this->bxData->setCategoryField($productToCategoriesSourceKey, 'category_id');
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
/**
|
| 166 |
+
* @param $account
|
| 167 |
+
* @return array
|
| 168 |
+
*/
|
| 169 |
+
protected function getStoreProductAttributes($account)
|
| 170 |
+
{
|
| 171 |
+
$db = $this->_getReadAdapter();
|
| 172 |
+
$select = $db->select()
|
| 173 |
+
->from(
|
| 174 |
+
array('a_t' => $db->getTableName($this->_prefix . 'eav_attribute')),
|
| 175 |
+
array('a_t.attribute_id', 'a_t.attribute_code')
|
| 176 |
+
)
|
| 177 |
+
->joinInner(
|
| 178 |
+
array('ca_t' => $db->getTableName($this->_prefix . 'catalog_eav_attribute')),
|
| 179 |
+
'ca_t.attribute_id = a_t.attribute_id'
|
| 180 |
+
);
|
| 181 |
+
|
| 182 |
+
$attributes = array();
|
| 183 |
+
$result = $db->query($select);
|
| 184 |
+
if($result->rowCount()){
|
| 185 |
+
while($attribute = $result->fetch()){
|
| 186 |
+
$attributes[$attribute['attribute_id']] = $attribute['attribute_code'];
|
| 187 |
+
}
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
Mage::log('bxLog: get all product attributes.', Zend_Log::INFO, self::BOXALINO_LOG_FILE);
|
| 191 |
+
|
| 192 |
+
$requiredProperties = array(
|
| 193 |
+
'entity_id',
|
| 194 |
+
'name',
|
| 195 |
+
'description',
|
| 196 |
+
'short_description',
|
| 197 |
+
'sku',
|
| 198 |
+
'price',
|
| 199 |
+
'special_price',
|
| 200 |
+
'special_from_date',
|
| 201 |
+
'special_to_date',
|
| 202 |
+
'category_ids',
|
| 203 |
+
'visibility',
|
| 204 |
+
'status'
|
| 205 |
+
);
|
| 206 |
+
Mage::log('bxLog: get configured product attributes.', Zend_Log::INFO, self::BOXALINO_LOG_FILE);
|
| 207 |
+
$attributes = $this->config->getAccountProductsProperties($account, $attributes, $requiredProperties);
|
| 208 |
+
Mage::log('bxLog: returning configured product attributes: ' . implode(',', array_values($attributes)), Zend_Log::INFO, self::BOXALINO_LOG_FILE);
|
| 209 |
+
|
| 210 |
+
return $attributes;
|
| 211 |
+
}
|
| 212 |
+
|
| 213 |
+
/**
|
| 214 |
+
* @param $account
|
| 215 |
+
* @param $files
|
| 216 |
+
* @return bool
|
| 217 |
+
*/
|
| 218 |
+
protected function exportProducts($account, $files){
|
| 219 |
+
$languages = $this->config->getAccountLanguages($account);
|
| 220 |
+
|
| 221 |
+
Mage::log('bxLog: Products - start of export for account ' . $account, Zend_Log::INFO, self::BOXALINO_LOG_FILE);
|
| 222 |
+
$attrs = $this->getStoreProductAttributes($account);
|
| 223 |
+
Mage::log('bxLog: Products - get info about attributes - before for account ' . $account, Zend_Log::INFO, self::BOXALINO_LOG_FILE);
|
| 224 |
+
|
| 225 |
+
$db = $this->_getReadAdapter();
|
| 226 |
+
|
| 227 |
+
$countMax = 1000000; //$this->_storeConfig['maximum_population'];
|
| 228 |
+
$limit = 1000; //$this->_storeConfig['export_chunk'];
|
| 229 |
+
$totalCount = 0;
|
| 230 |
+
$page = 1;
|
| 231 |
+
$header = true;
|
| 232 |
+
|
| 233 |
+
while (true) {
|
| 234 |
+
|
| 235 |
+
if ($countMax > 0 && $totalCount >= $countMax) {
|
| 236 |
+
break;
|
| 237 |
+
}
|
| 238 |
+
|
| 239 |
+
$select = $db->select()
|
| 240 |
+
->from(
|
| 241 |
+
array('e' => $db->getTableName($this->_prefix . 'catalog_product_entity'))
|
| 242 |
+
)
|
| 243 |
+
->limit($limit, ($page - 1) * $limit)
|
| 244 |
+
->joinLeft(
|
| 245 |
+
array('p_t' => $db->getTableName($this->_prefix . 'catalog_product_super_link')),
|
| 246 |
+
'e.entity_id = p_t.product_id', array('group_id' => 'parent_id')
|
| 247 |
+
);
|
| 248 |
+
if($this->indexType == 'delta')$select->where('created_at >= ? OR updated_at >= ?', $this->_getLastIndex());
|
| 249 |
+
|
| 250 |
+
|
| 251 |
+
$data = array();
|
| 252 |
+
$result = $db->query($select);
|
| 253 |
+
if($result->rowCount()){
|
| 254 |
+
while($row = $result->fetch()){
|
| 255 |
+
if($this->indexType == 'delta') $this->deltaIds[] = $row['entity_id'];
|
| 256 |
+
if($row['group_id'] == null) $row['group_id'] = $row['entity_id'];
|
| 257 |
+
$data[$row['entity_id']] = $row;
|
| 258 |
+
$totalCount++;
|
| 259 |
+
}
|
| 260 |
+
}else{
|
| 261 |
+
if($totalCount == 0){
|
| 262 |
+
return false;
|
| 263 |
+
}
|
| 264 |
+
break;
|
| 265 |
+
}
|
| 266 |
+
|
| 267 |
+
if ($header && count($data) > 0) {
|
| 268 |
+
$data = array_merge(array(array_keys(end($data))), $data);
|
| 269 |
+
$header = false;
|
| 270 |
+
}
|
| 271 |
+
|
| 272 |
+
$files->savePartToCsv('products.csv', $data);
|
| 273 |
+
$data = null;
|
| 274 |
+
$page++;
|
| 275 |
+
}
|
| 276 |
+
$attributeSourceKey = $this->bxData->addMainCSVItemFile($files->getPath('products.csv'), 'entity_id');
|
| 277 |
+
$this->bxData->addSourceStringField($attributeSourceKey, 'group_id', 'group_id');
|
| 278 |
+
$this->bxData->addFieldParameter($attributeSourceKey, 'group_id', 'multiValued', 'false');
|
| 279 |
+
|
| 280 |
+
$select = $db->select()
|
| 281 |
+
->from(
|
| 282 |
+
array('main_table' => $db->getTableName($this->_prefix . 'eav_attribute')),
|
| 283 |
+
array(
|
| 284 |
+
'attribute_id',
|
| 285 |
+
'attribute_code',
|
| 286 |
+
'backend_type',
|
| 287 |
+
'frontend_input',
|
| 288 |
+
)
|
| 289 |
+
)
|
| 290 |
+
->joinInner(
|
| 291 |
+
array('additional_table' => $db->getTableName($this->_prefix . 'catalog_eav_attribute'), 'is_global'),
|
| 292 |
+
'additional_table.attribute_id = main_table.attribute_id'
|
| 293 |
+
)
|
| 294 |
+
->where('main_table.entity_type_id = ?', $this->getEntityTypeId('catalog_product'))
|
| 295 |
+
->where('main_table.attribute_code IN(?)', $attrs);
|
| 296 |
+
|
| 297 |
+
$attrsFromDb = array(
|
| 298 |
+
'int' => array(),
|
| 299 |
+
'varchar' => array(),
|
| 300 |
+
'text' => array(),
|
| 301 |
+
'decimal' => array(),
|
| 302 |
+
'datetime' => array()
|
| 303 |
+
);
|
| 304 |
+
$result = $db->query($select);
|
| 305 |
+
if($result->rowCount()){
|
| 306 |
+
while($row = $result->fetch()){
|
| 307 |
+
$type = $row['backend_type'];
|
| 308 |
+
if (isset($attrsFromDb[$type])) {
|
| 309 |
+
$attrsFromDb[$type][$row['attribute_id']] = array(
|
| 310 |
+
'attribute_code' => $row['attribute_code'], 'is_global' => $row['is_global'],
|
| 311 |
+
'frontend_input' => $row['frontend_input']
|
| 312 |
+
);
|
| 313 |
+
}
|
| 314 |
+
}
|
| 315 |
+
}
|
| 316 |
+
|
| 317 |
+
$this->exportProductAttributes($attrsFromDb, $languages, $account, $files, $attributeSourceKey);
|
| 318 |
+
$this->exportProductInformation($files);
|
| 319 |
+
return true;
|
| 320 |
+
}
|
| 321 |
+
|
| 322 |
+
/**
|
| 323 |
+
* @param array $attrs
|
| 324 |
+
* @param $languages
|
| 325 |
+
* @param $account
|
| 326 |
+
* @param $files
|
| 327 |
+
*/
|
| 328 |
+
protected function exportProductAttributes($attrs = array(), $languages, $account, $files, $mainSourceKey){
|
| 329 |
+
$paramPriceLabel = '';
|
| 330 |
+
$paramSpecialPriceLabel = '';
|
| 331 |
+
|
| 332 |
+
$db = $this->_getReadAdapter();
|
| 333 |
+
$columns = array(
|
| 334 |
+
'entity_id',
|
| 335 |
+
'attribute_id',
|
| 336 |
+
'value',
|
| 337 |
+
'store_id'
|
| 338 |
+
);
|
| 339 |
+
$attrs['misc'][] = array('attribute_code' => 'categories');
|
| 340 |
+
$files->prepareProductFiles($attrs);
|
| 341 |
+
unset($attrs['misc']);
|
| 342 |
+
|
| 343 |
+
foreach($attrs as $attributeType => $types){
|
| 344 |
+
$select = $db->select()->from(
|
| 345 |
+
array('t_d' => $db->getTableName($this->_prefix . 'catalog_product_entity_' . $attributeType)),
|
| 346 |
+
$columns
|
| 347 |
+
);
|
| 348 |
+
if($this->indexType == 'delta')$select->where('t_d.entity_id IN(?)', $this->deltaIds);
|
| 349 |
+
foreach ($types as $attributeID => $attribute) {
|
| 350 |
+
Mage::log('bxLog: Products - exporting attribute: ' . $attribute['attribute_code'] . ' for ' . $account, Zend_Log::INFO, self::BOXALINO_LOG_FILE);
|
| 351 |
+
|
| 352 |
+
$optionSelect = in_array($attribute['frontend_input'], array('multiselect','select'));
|
| 353 |
+
$data = array();
|
| 354 |
+
$additionalData = array();
|
| 355 |
+
$exportAttribute = false;
|
| 356 |
+
$global = false;
|
| 357 |
+
$d = array();
|
| 358 |
+
$headerLangRow = array();
|
| 359 |
+
$optionValues = array();
|
| 360 |
+
|
| 361 |
+
foreach ($languages as $langIndex => $lang) {
|
| 362 |
+
|
| 363 |
+
$labelColumns[$lang] = 'value_' . $lang;
|
| 364 |
+
$storeObject = $this->config->getStore($account, $lang);
|
| 365 |
+
$storeId = $storeObject->getId();
|
| 366 |
+
|
| 367 |
+
if($attribute['attribute_code'] == 'url_key' || $attribute['attribute_code'] == 'image'){
|
| 368 |
+
$storeBaseUrl = $storeObject->getBaseUrl();
|
| 369 |
+
$imageBaseUrl = $storeObject->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . "catalog/product";
|
| 370 |
+
}
|
| 371 |
+
|
| 372 |
+
if ($attribute['attribute_code'] == 'visibility') {
|
| 373 |
+
|
| 374 |
+
$select = $db->select()
|
| 375 |
+
->from(
|
| 376 |
+
array('c_p_e' => $db->getTableName('catalog_product_entity')),
|
| 377 |
+
array('entity_id')
|
| 378 |
+
)
|
| 379 |
+
->joinLeft(
|
| 380 |
+
array('c_p_r' => $db->getTableName('catalog_product_relation')),
|
| 381 |
+
'c_p_e.entity_id = c_p_r.child_id',
|
| 382 |
+
array('parent_id'))
|
| 383 |
+
->join(
|
| 384 |
+
array('t_d' => $db->getTableName('catalog_product_entity_' . $attributeType)),
|
| 385 |
+
'(t_d.entity_id = c_p_r.parent_id) OR (t_d.entity_id = c_p_e.entity_id AND c_p_r.parent_id IS NULL)',
|
| 386 |
+
array(
|
| 387 |
+
'attribute_id',
|
| 388 |
+
'value',
|
| 389 |
+
'store_id'
|
| 390 |
+
)
|
| 391 |
+
);
|
| 392 |
+
if($this->indexType == 'delta')$select->where('c_p_e.entity_id IN(?)', $this->deltaIds);
|
| 393 |
+
}
|
| 394 |
+
if ($attribute['attribute_code'] == 'price' || $attribute['attribute_code'] == 'special_price') {
|
| 395 |
+
if($langIndex == 0) {
|
| 396 |
+
$priceSelect = $db->select()
|
| 397 |
+
->from(
|
| 398 |
+
array('c_p_r' => $db->getTableName('catalog_product_relation')),
|
| 399 |
+
array('parent_id')
|
| 400 |
+
)
|
| 401 |
+
->join(
|
| 402 |
+
array('t_d' => $db->getTableName('catalog_product_entity_' . $attributeType)),
|
| 403 |
+
't_d.entity_id = c_p_r.child_id',
|
| 404 |
+
array(
|
| 405 |
+
'value' => 'MIN(value)'
|
| 406 |
+
)
|
| 407 |
+
)->group(array('parent_id'))->where('t_d.attribute_id = ?', $attributeID);
|
| 408 |
+
$priceData = array();
|
| 409 |
+
|
| 410 |
+
foreach ($db->fetchAll($priceSelect) as $row) {
|
| 411 |
+
$priceData[] = $row;
|
| 412 |
+
}
|
| 413 |
+
|
| 414 |
+
if (sizeof($priceData)) {
|
| 415 |
+
$priceData = array_merge(array(array_keys(end($priceData))), $priceData);
|
| 416 |
+
} else {
|
| 417 |
+
$priceData = array(array('parent_id', 'value'));
|
| 418 |
+
}
|
| 419 |
+
$files->savePartToCsv($attribute['attribute_code'] . '.csv', $priceData);
|
| 420 |
+
$priceData = null;
|
| 421 |
+
}
|
| 422 |
+
}
|
| 423 |
+
if ($attribute['attribute_code'] == 'url_key') {
|
| 424 |
+
if (Mage::getEdition() == Mage::EDITION_ENTERPRISE) {
|
| 425 |
+
$select = $db->select()
|
| 426 |
+
->joinLeft(
|
| 427 |
+
array('t_g' => $db->getTableName($this->_prefix . 'catalog_product_entity_url_key')),
|
| 428 |
+
array('entity_id', 'attribute_id')
|
| 429 |
+
)
|
| 430 |
+
->joinLeft(
|
| 431 |
+
array('t_s' => $db->getTableName($this->_prefix . 'catalog_product_entity_url_key')),
|
| 432 |
+
't_s.attribute_id = t_g.attribute_id AND t_s.entity_id = t_g.entity_id',
|
| 433 |
+
array('value' => 'IF(t_s.store_id IS NULL, t_g.value, t_s.value)')
|
| 434 |
+
)
|
| 435 |
+
->where('t_g.attribute_id = ?', $attributeID)
|
| 436 |
+
->where('t_g.store_id = 0 OR t_g.store_id = ?', $storeId);
|
| 437 |
+
}
|
| 438 |
+
}
|
| 439 |
+
if($optionSelect){
|
| 440 |
+
$optionValueSelect = $db->select()
|
| 441 |
+
->from(
|
| 442 |
+
array('a_o' => $db->getTableName('eav_attribute_option')),
|
| 443 |
+
array(
|
| 444 |
+
'option_id',
|
| 445 |
+
new \Zend_Db_Expr("CASE WHEN c_o.value IS NULL THEN b_o.value ELSE c_o.value END as value")
|
| 446 |
+
)
|
| 447 |
+
)->joinLeft(array('b_o' => $db->getTableName('eav_attribute_option_value')),
|
| 448 |
+
'b_o.option_id = a_o.option_id AND b_o.store_id = 0',
|
| 449 |
+
array()
|
| 450 |
+
)->joinLeft(array('c_o' => $db->getTableName('eav_attribute_option_value')),
|
| 451 |
+
'c_o.option_id = a_o.option_id AND c_o.store_id = ' . $storeId,
|
| 452 |
+
array()
|
| 453 |
+
)->where('a_o.attribute_id = ?', $attributeID);
|
| 454 |
+
|
| 455 |
+
$fetchedOptionValues = $db->fetchAll($optionValueSelect);
|
| 456 |
+
|
| 457 |
+
if($fetchedOptionValues){
|
| 458 |
+
foreach($fetchedOptionValues as $v){
|
| 459 |
+
if(isset($optionValues[$v['option_id']])){
|
| 460 |
+
$optionValues[$v['option_id']]['value_' . $lang] = $v['value'];
|
| 461 |
+
}else{
|
| 462 |
+
$optionValues[$v['option_id']] = array($attribute['attribute_code'] . '_id' => $v['option_id'],
|
| 463 |
+
'value_' . $lang => $v['value']);
|
| 464 |
+
}
|
| 465 |
+
}
|
| 466 |
+
}else{
|
| 467 |
+
$exportAttribute = true;
|
| 468 |
+
$optionSelect = false;
|
| 469 |
+
}
|
| 470 |
+
$fetchedOptionValues = null;
|
| 471 |
+
}
|
| 472 |
+
|
| 473 |
+
$attributeSelect = clone $select;
|
| 474 |
+
$attributeSelect
|
| 475 |
+
->where('t_d.attribute_id = ?', $attributeID)
|
| 476 |
+
->where('t_d.store_id = 0 OR t_d.store_id = ?',$storeId);
|
| 477 |
+
|
| 478 |
+
$result = $db->query($attributeSelect);
|
| 479 |
+
|
| 480 |
+
if ($result->rowCount()) {
|
| 481 |
+
|
| 482 |
+
while ($row = $result->fetch()) {
|
| 483 |
+
|
| 484 |
+
if (isset($data[$row['entity_id']]) && !$optionSelect) {
|
| 485 |
+
if($row['store_id'] > $data[$row['entity_id']]['store_id']) {
|
| 486 |
+
$data[$row['entity_id']]['value_' . $lang] = $row['value'];
|
| 487 |
+
$data[$row['entity_id']]['store_id'] = $row['store_id'];
|
| 488 |
+
if(isset($additionalData[$row['entity_id']])){
|
| 489 |
+
if ($attribute['attribute_code'] == 'url_key') {
|
| 490 |
+
$url = $storeBaseUrl . $row['value'] . '.html';
|
| 491 |
+
$additionalData[$row['entity_id']]['value_' . $lang] = $url;
|
| 492 |
+
} else {
|
| 493 |
+
$url = $imageBaseUrl . $row['value'];
|
| 494 |
+
$additionalData[$row['entity_id']]['value_' . $lang] = $url;
|
| 495 |
+
}
|
| 496 |
+
}
|
| 497 |
+
continue;
|
| 498 |
+
}
|
| 499 |
+
$data[$row['entity_id']]['value_' . $lang] = $row['value'];
|
| 500 |
+
|
| 501 |
+
if (isset($additionalData[$row['entity_id']])) {
|
| 502 |
+
if ($attribute['attribute_code'] == 'url_key') {
|
| 503 |
+
$url = $storeBaseUrl . $row['value'] . '.html';
|
| 504 |
+
$additionalData[$row['entity_id']]['value_' . $lang] = $url;
|
| 505 |
+
} else {
|
| 506 |
+
$url = $imageBaseUrl . $row['value'];
|
| 507 |
+
$additionalData[$row['entity_id']]['value_' . $lang] = $url;
|
| 508 |
+
}
|
| 509 |
+
}
|
| 510 |
+
continue;
|
| 511 |
+
} else {
|
| 512 |
+
if ($attribute['attribute_code'] == 'url_key') {
|
| 513 |
+
if ($this->config->exportProductUrl($account)) {
|
| 514 |
+
$url = $storeBaseUrl . $row['value'] . '.html';
|
| 515 |
+
$additionalData[$row['entity_id']] = array('entity_id' => $row['entity_id'],
|
| 516 |
+
'store_id' => $row['store_id'],
|
| 517 |
+
'value_' . $lang => $url);
|
| 518 |
+
}
|
| 519 |
+
}
|
| 520 |
+
if ($attribute['attribute_code'] == 'image') {
|
| 521 |
+
if ($this->config->exportProductImages($account)) {
|
| 522 |
+
$url = $imageBaseUrl . $row['value'];
|
| 523 |
+
$additionalData[$row['entity_id']] = array('entity_id' => $row['entity_id'],
|
| 524 |
+
'value_' . $lang => $url);
|
| 525 |
+
}
|
| 526 |
+
}
|
| 527 |
+
if ($attribute['is_global'] != 1) {
|
| 528 |
+
if($optionSelect){
|
| 529 |
+
$values = explode(',',$row['value']);
|
| 530 |
+
foreach($values as $v){
|
| 531 |
+
$data[] = array('entity_id' => $row['entity_id'],
|
| 532 |
+
$attribute['attribute_code'] . '_id' => $v);
|
| 533 |
+
}
|
| 534 |
+
}else{
|
| 535 |
+
if(!isset($data[$row['entity_id']]) || $data[$row['entity_id']]['store_id'] < $row['store_id']) {
|
| 536 |
+
$data[$row['entity_id']] = array('entity_id' => $row['entity_id'],
|
| 537 |
+
'store_id' => $row['store_id'],'value_' . $lang => $row['value']);
|
| 538 |
+
}
|
| 539 |
+
}
|
| 540 |
+
continue;
|
| 541 |
+
}else{
|
| 542 |
+
if($optionSelect){
|
| 543 |
+
$values = explode(',',$row['value']);
|
| 544 |
+
foreach($values as $v){
|
| 545 |
+
$data[] = array('entity_id' => $row['entity_id'],
|
| 546 |
+
$attribute['attribute_code'] . '_id' => $v);
|
| 547 |
+
}
|
| 548 |
+
}else{
|
| 549 |
+
$valueLabel = $attribute['attribute_code'] == 'visibility' ||
|
| 550 |
+
$attribute['attribute_code'] == 'status' ||
|
| 551 |
+
$attribute['attribute_code'] == 'special_from_date' ||
|
| 552 |
+
$attribute['attribute_code'] == 'special_to_date' ? 'value_' . $lang : 'value';
|
| 553 |
+
$data[$row['entity_id']] = array('entity_id' => $row['entity_id'],
|
| 554 |
+
'store_id' => $row['store_id'],
|
| 555 |
+
$valueLabel => $row['value']);
|
| 556 |
+
}
|
| 557 |
+
}
|
| 558 |
+
}
|
| 559 |
+
}
|
| 560 |
+
if($attribute['is_global'] == 1){
|
| 561 |
+
$global = true;
|
| 562 |
+
if($attribute['attribute_code'] != 'visibility' &&
|
| 563 |
+
$attribute['attribute_code'] != 'status' &&
|
| 564 |
+
$attribute['attribute_code'] != 'special_from_date' &&
|
| 565 |
+
$attribute['attribute_code'] != 'special_to_date'
|
| 566 |
+
)
|
| 567 |
+
{
|
| 568 |
+
break;
|
| 569 |
+
}
|
| 570 |
+
}
|
| 571 |
+
}
|
| 572 |
+
}
|
| 573 |
+
if($optionSelect || $exportAttribute){
|
| 574 |
+
$optionHeader = array_merge(array($attribute['attribute_code'] . '_id'),$labelColumns);
|
| 575 |
+
$a = array_merge(array($optionHeader), $optionValues);
|
| 576 |
+
$files->savepartToCsv($attribute['attribute_code'].'.csv', $a);
|
| 577 |
+
$optionValues = null;
|
| 578 |
+
$a = null;
|
| 579 |
+
$optionSourceKey = $this->bxData->addResourceFile(
|
| 580 |
+
$files->getPath($attribute['attribute_code'] . '.csv'), $attribute['attribute_code'] . '_id',
|
| 581 |
+
$labelColumns);
|
| 582 |
+
if(sizeof($data) == 0){
|
| 583 |
+
$d = array(array('entity_id',$attribute['attribute_code'] . '_id'));
|
| 584 |
+
$files->savepartToCsv('product_' . $attribute['attribute_code'] . '.csv',$d);
|
| 585 |
+
$attributeSourceKey = $this->bxData->addCSVItemFile($files->getPath('product_' . $attribute['attribute_code'] . '.csv'), 'entity_id');
|
| 586 |
+
$this->bxData->addSourceLocalizedTextField($attributeSourceKey,$attribute['attribute_code'],
|
| 587 |
+
$attribute['attribute_code'] . '_id', $optionSourceKey);
|
| 588 |
+
}
|
| 589 |
+
}
|
| 590 |
+
if (sizeof($data)) {
|
| 591 |
+
if(!$global){
|
| 592 |
+
if(!$optionSelect){
|
| 593 |
+
$headerLangRow = array_merge(array('entity_id','store_id'), $labelColumns);
|
| 594 |
+
if(sizeof($additionalData)){
|
| 595 |
+
$additionalHeader = array_merge(array('entity_id','store_id'), $labelColumns);
|
| 596 |
+
$d = array_merge(array($additionalHeader), $additionalData);
|
| 597 |
+
if ($attribute['attribute_code'] == 'url_key') {
|
| 598 |
+
$files->savepartToCsv('product_default_url.csv', $d);
|
| 599 |
+
$sourceKey = $this->bxData->addCSVItemFile($files->getPath('product_default_url.csv'), 'entity_id');
|
| 600 |
+
$this->bxData->addSourceLocalizedTextField($sourceKey, 'default_url', $labelColumns);
|
| 601 |
+
} else {
|
| 602 |
+
$files->savepartToCsv('product_cache_image_url.csv', $d);
|
| 603 |
+
$sourceKey = $this->bxData->addCSVItemFile($files->getPath('product_cache_image_url.csv'), 'entity_id');
|
| 604 |
+
$this->bxData->addSourceLocalizedTextField($sourceKey, 'cache_image_url',$labelColumns);
|
| 605 |
+
}
|
| 606 |
+
}
|
| 607 |
+
$d = array_merge(array($headerLangRow), $data);
|
| 608 |
+
}else{
|
| 609 |
+
$d = array_merge(array(array('entity_id',$attribute['attribute_code'] . '_id')), $data);
|
| 610 |
+
}
|
| 611 |
+
}else {
|
| 612 |
+
$d = array_merge(array(array_keys(end($data))), $data);
|
| 613 |
+
}
|
| 614 |
+
|
| 615 |
+
|
| 616 |
+
$files->savepartToCsv('product_' . $attribute['attribute_code'] . '.csv', $d);
|
| 617 |
+
$fieldId = $this->_helperExporter->sanitizeFieldName($attribute['attribute_code']);
|
| 618 |
+
$attributeSourceKey = $this->bxData->addCSVItemFile($files->getPath('product_' . $attribute['attribute_code'] . '.csv'), 'entity_id');
|
| 619 |
+
|
| 620 |
+
switch($attribute['attribute_code']){
|
| 621 |
+
case $optionSelect == true:
|
| 622 |
+
$this->bxData->addSourceLocalizedTextField($attributeSourceKey,$attribute['attribute_code'],
|
| 623 |
+
$attribute['attribute_code'] . '_id', $optionSourceKey);
|
| 624 |
+
break;
|
| 625 |
+
case 'name':
|
| 626 |
+
$this->bxData->addSourceTitleField($attributeSourceKey, $labelColumns);
|
| 627 |
+
break;
|
| 628 |
+
case 'description':
|
| 629 |
+
$this->bxData->addSourceDescriptionField($attributeSourceKey, $labelColumns);
|
| 630 |
+
break;
|
| 631 |
+
case 'visibility':
|
| 632 |
+
case 'status':
|
| 633 |
+
case 'special_from_date':
|
| 634 |
+
case 'special_to_date':
|
| 635 |
+
$lc = array();
|
| 636 |
+
foreach ($languages as $lcl) {
|
| 637 |
+
$lc[$lcl] = 'value_' . $lcl;
|
| 638 |
+
}
|
| 639 |
+
$this->bxData->addSourceLocalizedTextField($attributeSourceKey, $fieldId, $lc);
|
| 640 |
+
break;
|
| 641 |
+
case 'price':
|
| 642 |
+
if(!$global){
|
| 643 |
+
$col = null;
|
| 644 |
+
foreach($labelColumns as $k => $v) {
|
| 645 |
+
$col = $v;
|
| 646 |
+
break;
|
| 647 |
+
}
|
| 648 |
+
$this->bxData->addSourceListPriceField($mainSourceKey, 'entity_id');
|
| 649 |
+
}else {
|
| 650 |
+
$this->bxData->addSourceListPriceField($mainSourceKey, 'entity_id');
|
| 651 |
+
}
|
| 652 |
+
|
| 653 |
+
if(!$global){
|
| 654 |
+
$this->bxData->addSourceLocalizedTextField($attributeSourceKey, "price_localized", $labelColumns);
|
| 655 |
+
} else {
|
| 656 |
+
$this->bxData->addSourceStringField($attributeSourceKey, "price_localized", 'value');
|
| 657 |
+
}
|
| 658 |
+
|
| 659 |
+
$paramPriceLabel = $global ? 'value' : reset($labelColumns);
|
| 660 |
+
$this->bxData->addFieldParameter($mainSourceKey,'bx_listprice', 'pc_fields', 'CASE WHEN (price.'.$paramPriceLabel.' IS NULL OR price.'.$paramPriceLabel.' <= 0) AND ref.value IS NOT NULL then ref.value ELSE price.'.$paramPriceLabel.' END as price_value');
|
| 661 |
+
$this->bxData->addFieldParameter($mainSourceKey,'bx_listprice', 'pc_tables', 'LEFT JOIN `%%EXTRACT_PROCESS_TABLE_BASE%%_products_product_price` as price ON t.entity_id = price.entity_id, LEFT JOIN `%%EXTRACT_PROCESS_TABLE_BASE%%_products_resource_price` as ref ON t.entity_id = ref.parent_id');
|
| 662 |
+
|
| 663 |
+
$this->bxData->addResourceFile($files->getPath($attribute['attribute_code'] . '.csv'), 'parent_id','value');
|
| 664 |
+
break;
|
| 665 |
+
case 'special_price':
|
| 666 |
+
if(!$global){
|
| 667 |
+
$col = null;
|
| 668 |
+
foreach($labelColumns as $k => $v) {
|
| 669 |
+
$col = $v;
|
| 670 |
+
break;
|
| 671 |
+
}
|
| 672 |
+
$this->bxData->addSourceDiscountedPriceField($mainSourceKey, 'entity_id');
|
| 673 |
+
}else {
|
| 674 |
+
$this->bxData->addSourceDiscountedPriceField($mainSourceKey, 'entity_id');
|
| 675 |
+
}
|
| 676 |
+
if(!$global){
|
| 677 |
+
$this->bxData->addSourceLocalizedTextField($attributeSourceKey, "special_price_localized", $labelColumns);
|
| 678 |
+
} else {
|
| 679 |
+
$this->bxData->addSourceStringField($attributeSourceKey, "special_price_localized", 'value');
|
| 680 |
+
}
|
| 681 |
+
|
| 682 |
+
$paramSpecialPriceLabel = $global ? 'value' : reset($labelColumns);
|
| 683 |
+
$this->bxData->addFieldParameter($mainSourceKey,'bx_discountedprice', 'pc_fields', 'CASE WHEN (price.'.$paramSpecialPriceLabel.' IS NULL OR price.'.$paramSpecialPriceLabel.' <= 0) AND ref.value IS NOT NULL then ref.value ELSE price.'.$paramSpecialPriceLabel.' END as price_value');
|
| 684 |
+
$this->bxData->addFieldParameter($mainSourceKey,'bx_discountedprice', 'pc_tables', 'LEFT JOIN `%%EXTRACT_PROCESS_TABLE_BASE%%_products_product_special_price` as price ON t.entity_id = price.entity_id, LEFT JOIN `%%EXTRACT_PROCESS_TABLE_BASE%%_products_resource_special_price` as ref ON t.entity_id = ref.parent_id');
|
| 685 |
+
|
| 686 |
+
$this->bxData->addResourceFile($files->getPath($attribute['attribute_code'] . '.csv'), 'parent_id','value');
|
| 687 |
+
break;
|
| 688 |
+
case ($attributeType == ('int' || 'decimal')) && $attribute['is_global'] == 1:
|
| 689 |
+
$this->bxData->addSourceNumberField($attributeSourceKey, $fieldId, 'value');
|
| 690 |
+
break;
|
| 691 |
+
default:
|
| 692 |
+
if(!$global){
|
| 693 |
+
$this->bxData->addSourceLocalizedTextField($attributeSourceKey, $fieldId, $labelColumns);
|
| 694 |
+
}else {
|
| 695 |
+
$this->bxData->addSourceStringField($attributeSourceKey, $fieldId, 'value');
|
| 696 |
+
}
|
| 697 |
+
break;
|
| 698 |
+
}
|
| 699 |
+
}
|
| 700 |
+
$data = null;
|
| 701 |
+
$additionalData = null;
|
| 702 |
+
$d = null;
|
| 703 |
+
$labelColumns = null;
|
| 704 |
+
}
|
| 705 |
+
}
|
| 706 |
+
$this->bxData->addSourceNumberField($mainSourceKey, 'bx_grouped_price', 'entity_id');
|
| 707 |
+
$this->bxData->addFieldParameter($mainSourceKey,'bx_grouped_price', 'pc_fields', 'CASE WHEN sref.value IS NOT NULL AND sref.value > 0 AND (ref.value IS NULL OR sref.value < ref.value) THEN sref.value WHEN ref.value IS NOT NULL then ref.value WHEN sprice.'.$paramSpecialPriceLabel.' IS NOT NULL AND sprice.'.$paramSpecialPriceLabel.' > 0 AND price.'.$paramPriceLabel.' > sprice.'.$paramSpecialPriceLabel.' THEN sprice.'.$paramSpecialPriceLabel.' ELSE price.'.$paramPriceLabel.' END as price_value');
|
| 708 |
+
$this->bxData->addFieldParameter($mainSourceKey,'bx_grouped_price', 'pc_tables', 'LEFT JOIN `%%EXTRACT_PROCESS_TABLE_BASE%%_products_product_price` as price ON t.entity_id = price.entity_id, LEFT JOIN `%%EXTRACT_PROCESS_TABLE_BASE%%_products_resource_price` as ref ON t.group_id = ref.parent_id, LEFT JOIN `%%EXTRACT_PROCESS_TABLE_BASE%%_products_product_special_price` as sprice ON t.entity_id = sprice.entity_id, LEFT JOIN `%%EXTRACT_PROCESS_TABLE_BASE%%_products_resource_special_price` as sref ON t.group_id = sref.parent_id');
|
| 709 |
+
$this->bxData->addFieldParameter($mainSourceKey,'bx_grouped_price', 'multiValued', 'false');
|
| 710 |
+
}
|
| 711 |
+
|
| 712 |
+
/**
|
| 713 |
+
* @param $files
|
| 714 |
+
*/
|
| 715 |
+
protected function exportProductInformation($files){
|
| 716 |
+
|
| 717 |
+
$fetchedResult = array();
|
| 718 |
+
$db = $this->_getReadAdapter();
|
| 719 |
+
//product stock
|
| 720 |
+
$select = $db->select()
|
| 721 |
+
->from(
|
| 722 |
+
$db->getTableName($this->_prefix . 'cataloginventory_stock_status'),
|
| 723 |
+
array(
|
| 724 |
+
'entity_id' => 'product_id',
|
| 725 |
+
'stock_status',
|
| 726 |
+
'qty'
|
| 727 |
+
)
|
| 728 |
+
)
|
| 729 |
+
->where('stock_id = ?', 1);
|
| 730 |
+
if($this->indexType == 'delta')$select->where('entity_id IN(?)', $this->deltaIds);
|
| 731 |
+
|
| 732 |
+
$result = $db->query($select);
|
| 733 |
+
|
| 734 |
+
if($result->rowCount()){
|
| 735 |
+
while($row = $result->fetch()){
|
| 736 |
+
$data[] = array('entity_id'=>$row['entity_id'], 'qty'=>$row['qty']);
|
| 737 |
+
}
|
| 738 |
+
|
| 739 |
+
$d = array_merge(array(array_keys(end($data))), $data);
|
| 740 |
+
$files->savePartToCsv('product_stock.csv', $d);
|
| 741 |
+
$data = null;
|
| 742 |
+
$d = null;
|
| 743 |
+
$attributeSourceKey = $this->bxData->addCSVItemFile($files->getPath('product_stock.csv'), 'entity_id');
|
| 744 |
+
$this->bxData->addSourceNumberField($attributeSourceKey, 'qty', 'qty');
|
| 745 |
+
}
|
| 746 |
+
|
| 747 |
+
//product categories
|
| 748 |
+
$select = $db->select()
|
| 749 |
+
->from(
|
| 750 |
+
$db->getTableName($this->_prefix . 'catalog_category_product'),
|
| 751 |
+
array(
|
| 752 |
+
'entity_id' => 'product_id',
|
| 753 |
+
'category_id',
|
| 754 |
+
'position'
|
| 755 |
+
)
|
| 756 |
+
);
|
| 757 |
+
if($this->indexType == 'delta')$select->where('entity_id IN(?)', $this->deltaIds);
|
| 758 |
+
|
| 759 |
+
$result = $db->query($select);
|
| 760 |
+
|
| 761 |
+
if($result->rowCount()){
|
| 762 |
+
while($row = $result->fetch()){
|
| 763 |
+
$data[] = $row;
|
| 764 |
+
}
|
| 765 |
+
$d = array_merge(array(array_keys(end($data))), $data);
|
| 766 |
+
$files->savePartToCsv('product_categories.csv', $d);
|
| 767 |
+
$data = null;
|
| 768 |
+
$d = null;
|
| 769 |
+
}
|
| 770 |
+
|
| 771 |
+
//product super link
|
| 772 |
+
$select = $db->select()
|
| 773 |
+
->from(
|
| 774 |
+
$db->getTableName($this->_prefix . 'catalog_product_super_link'),
|
| 775 |
+
array(
|
| 776 |
+
'entity_id' => 'product_id',
|
| 777 |
+
'parent_id',
|
| 778 |
+
'link_id'
|
| 779 |
+
)
|
| 780 |
+
);
|
| 781 |
+
if($this->indexType == 'delta')$select->where('entity_id IN(?)', $this->deltaIds);
|
| 782 |
+
|
| 783 |
+
|
| 784 |
+
$result = $db->query($select);
|
| 785 |
+
|
| 786 |
+
if($result->rowCount()){
|
| 787 |
+
while($row = $result->fetch()){
|
| 788 |
+
$data[] = $row;
|
| 789 |
+
}
|
| 790 |
+
|
| 791 |
+
$d = array_merge(array(array_keys(end($data))), $data);
|
| 792 |
+
$files->savePartToCsv('product_parent.csv', $d);
|
| 793 |
+
$data = null;
|
| 794 |
+
$d = null;
|
| 795 |
+
$attributeSourceKey = $this->bxData->addCSVItemFile($files->getPath('product_parent.csv'), 'entity_id');
|
| 796 |
+
$this->bxData->addSourceStringField($attributeSourceKey, 'parent_id', 'parent_id');
|
| 797 |
+
$this->bxData->addSourceStringField($attributeSourceKey, 'link_id', 'link_id');
|
| 798 |
+
}
|
| 799 |
+
|
| 800 |
+
//product link
|
| 801 |
+
$select = $db->select()
|
| 802 |
+
->from(
|
| 803 |
+
array('pl'=> $db->getTableName($this->_prefix . 'catalog_product_link')),
|
| 804 |
+
array(
|
| 805 |
+
'entity_id' => 'product_id',
|
| 806 |
+
'linked_product_id',
|
| 807 |
+
'lt.code'
|
| 808 |
+
)
|
| 809 |
+
)
|
| 810 |
+
->joinLeft(
|
| 811 |
+
array('lt' => $db->getTableName($this->_prefix . 'catalog_product_link_type')),
|
| 812 |
+
'pl.link_type_id = lt.link_type_id', array()
|
| 813 |
+
)
|
| 814 |
+
->where('lt.link_type_id = pl.link_type_id');
|
| 815 |
+
if($this->indexType == 'delta')$select->where('pl.entity_id IN(?)', $this->deltaIds);
|
| 816 |
+
|
| 817 |
+
|
| 818 |
+
$result = $db->query($select);
|
| 819 |
+
|
| 820 |
+
if($result->rowCount()){
|
| 821 |
+
while($row = $result->fetch()){
|
| 822 |
+
$data[] = $row;
|
| 823 |
+
}
|
| 824 |
+
$d = array_merge(array(array_keys(end($data))), $data);
|
| 825 |
+
$files->savePartToCsv('product_links.csv', $d);
|
| 826 |
+
$data = null;
|
| 827 |
+
$d = null;
|
| 828 |
+
$attributeSourceKey = $this->bxData->addCSVItemFile($files->getPath('product_links.csv'), 'entity_id');
|
| 829 |
+
$this->bxData->addSourceStringField($attributeSourceKey, 'code', 'code');
|
| 830 |
+
$this->bxData->addSourceStringField($attributeSourceKey, 'linked_product_id', 'linked_product_id');
|
| 831 |
+
}
|
| 832 |
+
}
|
| 833 |
+
|
| 834 |
+
/**
|
| 835 |
+
* @param $account
|
| 836 |
+
* @param $files
|
| 837 |
+
* @throws Zend_Db_Select_Exception
|
| 838 |
+
*/
|
| 839 |
+
protected function exportCustomers($account, $files){
|
| 840 |
+
if(!$this->config->isCustomersExportEnabled($account)) {
|
| 841 |
+
return;
|
| 842 |
+
}
|
| 843 |
+
|
| 844 |
+
$limit = 1000;
|
| 845 |
+
$count = $limit;
|
| 846 |
+
$page = 1;
|
| 847 |
+
$header = true;
|
| 848 |
+
|
| 849 |
+
$attrsFromDb = array(
|
| 850 |
+
'int' => array(),
|
| 851 |
+
'static' => array(), // only supports email
|
| 852 |
+
'varchar' => array(),
|
| 853 |
+
'datetime' => array(),
|
| 854 |
+
);
|
| 855 |
+
|
| 856 |
+
$customer_attributes = $this->getCustomerAttributes($account);
|
| 857 |
+
|
| 858 |
+
$db = $this->_getReadAdapter();
|
| 859 |
+
$select = $db->select()
|
| 860 |
+
->from(
|
| 861 |
+
array('main_table' => $db->getTableName($this->_prefix . 'eav_attribute')),
|
| 862 |
+
array(
|
| 863 |
+
'aid' => 'attribute_id',
|
| 864 |
+
'backend_type',
|
| 865 |
+
)
|
| 866 |
+
)
|
| 867 |
+
->joinInner(
|
| 868 |
+
array('additional_table' => $db->getTableName($this->_prefix . 'customer_eav_attribute')),
|
| 869 |
+
'additional_table.attribute_id = main_table.attribute_id',
|
| 870 |
+
array()
|
| 871 |
+
)
|
| 872 |
+
->where('main_table.entity_type_id = ?', $this->getEntityTypeId('customer'))
|
| 873 |
+
->where('main_table.attribute_code IN (?)', $customer_attributes);
|
| 874 |
+
|
| 875 |
+
$result = $db->query($select);
|
| 876 |
+
if($result->rowCount()){
|
| 877 |
+
while($row = $result->fetch()){
|
| 878 |
+
$attrsFromDb[$row['backend_type']][] = $row['aid'];
|
| 879 |
+
}
|
| 880 |
+
}
|
| 881 |
+
|
| 882 |
+
do{
|
| 883 |
+
$customers_to_save = array();
|
| 884 |
+
$customers = array();
|
| 885 |
+
|
| 886 |
+
$select = $db->select()
|
| 887 |
+
->from(
|
| 888 |
+
$db->getTableName($this->_prefix . 'customer_entity'),
|
| 889 |
+
array('entity_id', 'created_at', 'updated_at')
|
| 890 |
+
)
|
| 891 |
+
->limit($limit, ($page - 1) * $limit);
|
| 892 |
+
|
| 893 |
+
$result = $db->query($select);
|
| 894 |
+
if($result->rowCount()){
|
| 895 |
+
while($row = $result->fetch()){
|
| 896 |
+
$customers[$row['entity_id']] = array('id' => $row['entity_id']);
|
| 897 |
+
}
|
| 898 |
+
}
|
| 899 |
+
|
| 900 |
+
$ids = array_keys($customers);
|
| 901 |
+
|
| 902 |
+
$columns = array(
|
| 903 |
+
'entity_id',
|
| 904 |
+
'attribute_id',
|
| 905 |
+
'value',
|
| 906 |
+
);
|
| 907 |
+
|
| 908 |
+
$select = $db->select()
|
| 909 |
+
->where('ce.entity_type_id = ?', 1)
|
| 910 |
+
->where('ce.entity_id IN (?)', $ids);
|
| 911 |
+
|
| 912 |
+
$select1 = null;
|
| 913 |
+
$select2 = null;
|
| 914 |
+
$select3 = null;
|
| 915 |
+
$select4 = null;
|
| 916 |
+
|
| 917 |
+
$selects = array();
|
| 918 |
+
|
| 919 |
+
if (count($attrsFromDb['varchar']) > 0) {
|
| 920 |
+
$select1 = clone $select;
|
| 921 |
+
$select1->from(array('ce' => $db->getTableName($this->_prefix . 'customer_entity_varchar')), $columns)
|
| 922 |
+
->joinLeft(array('ea' => $db->getTableName('eav_attribute')), 'ce.attribute_id = ea.attribute_id', 'ea.attribute_code')
|
| 923 |
+
->where('ce.attribute_id IN(?)', $attrsFromDb['varchar']);
|
| 924 |
+
$selects[] = $select1;
|
| 925 |
+
}
|
| 926 |
+
|
| 927 |
+
if (count($attrsFromDb['int']) > 0) {
|
| 928 |
+
$select2 = clone $select;
|
| 929 |
+
$select2->from(array('ce' => $db->getTableName($this->_prefix . 'customer_entity_int')), $columns)
|
| 930 |
+
->joinLeft(array('ea' => $db->getTableName($this->_prefix . 'eav_attribute')), 'ce.attribute_id = ea.attribute_id', 'ea.attribute_code')
|
| 931 |
+
->where('ce.attribute_id IN(?)', $attrsFromDb['int']);
|
| 932 |
+
$selects[] = $select2;
|
| 933 |
+
}
|
| 934 |
+
|
| 935 |
+
if (count($attrsFromDb['datetime']) > 0) {
|
| 936 |
+
$select3 = clone $select;
|
| 937 |
+
$select3->from(array('ce' => $db->getTableName($this->_prefix . 'customer_entity_datetime')), $columns)
|
| 938 |
+
->joinLeft(array('ea' => $db->getTableName($this->_prefix . 'eav_attribute')), 'ce.attribute_id = ea.attribute_id', 'ea.attribute_code')
|
| 939 |
+
->where('ce.attribute_id IN(?)', $attrsFromDb['datetime']);
|
| 940 |
+
$selects[] = $select3;
|
| 941 |
+
}
|
| 942 |
+
|
| 943 |
+
// only supports email
|
| 944 |
+
if (count($attrsFromDb['static']) > 0) {
|
| 945 |
+
$attributeId = current($attrsFromDb['static']);
|
| 946 |
+
$select4 = $db->select()
|
| 947 |
+
->from(array('ce' => $db->getTableName($this->_prefix . 'customer_entity')), array(
|
| 948 |
+
'entity_id' => 'entity_id',
|
| 949 |
+
'attribute_id' => new \Zend_Db_Expr($attributeId),
|
| 950 |
+
'value' => 'email',
|
| 951 |
+
))
|
| 952 |
+
->joinLeft(array('ea' => $db->getTableName($this->_prefix . 'eav_attribute')), 'ea.attribute_id = ' . $attributeId, 'ea.attribute_code')
|
| 953 |
+
->where('ce.entity_id IN (?)', $ids);
|
| 954 |
+
$selects[] = $select4;
|
| 955 |
+
}
|
| 956 |
+
|
| 957 |
+
$select = $db->select()
|
| 958 |
+
->union(
|
| 959 |
+
$selects,
|
| 960 |
+
Zend_Db_Select::SQL_UNION_ALL
|
| 961 |
+
);
|
| 962 |
+
|
| 963 |
+
$result = $db->query($select);
|
| 964 |
+
if($result->rowCount()){
|
| 965 |
+
while($row = $result->fetch()){
|
| 966 |
+
$customers[$row['entity_id']][$row['attribute_code']] = $row['value'];
|
| 967 |
+
}
|
| 968 |
+
}
|
| 969 |
+
|
| 970 |
+
$select = null;
|
| 971 |
+
$select1 = null;
|
| 972 |
+
$select2 = null;
|
| 973 |
+
$select3 = null;
|
| 974 |
+
$select4 = null;
|
| 975 |
+
$selects = null;
|
| 976 |
+
|
| 977 |
+
$select = $db->select()
|
| 978 |
+
->from(
|
| 979 |
+
$db->getTableName($this->_prefix . 'eav_attribute'),
|
| 980 |
+
array(
|
| 981 |
+
'attribute_id',
|
| 982 |
+
'attribute_code',
|
| 983 |
+
)
|
| 984 |
+
)
|
| 985 |
+
->where('entity_type_id = ?', $this->getEntityTypeId('customer_address'))
|
| 986 |
+
->where('attribute_code IN (?)', array('country_id', 'postcode'));
|
| 987 |
+
|
| 988 |
+
$addressAttr = array();
|
| 989 |
+
|
| 990 |
+
$result = $db->query($select);
|
| 991 |
+
if($result->rowCount()){
|
| 992 |
+
while($row = $result->fetch()){
|
| 993 |
+
$addressAttr[$row['attribute_id']] = $row['attribute_code'];
|
| 994 |
+
}
|
| 995 |
+
}
|
| 996 |
+
|
| 997 |
+
$addressIds = array_keys($addressAttr);
|
| 998 |
+
|
| 999 |
+
foreach ($customers as $customer) {
|
| 1000 |
+
$id = $customer['id'];
|
| 1001 |
+
|
| 1002 |
+
$select = $db->select()
|
| 1003 |
+
->from($db->getTableName($this->_prefix . 'customer_address_entity'),
|
| 1004 |
+
array('entity_id')
|
| 1005 |
+
)
|
| 1006 |
+
->where('entity_type_id = ?', $this->getEntityTypeId('customer_address'))
|
| 1007 |
+
->where('parent_id = ?', $id)
|
| 1008 |
+
->order('entity_id DESC')
|
| 1009 |
+
->limit(1);
|
| 1010 |
+
|
| 1011 |
+
$select = $db->select()
|
| 1012 |
+
->from($db->getTableName($this->_prefix . 'customer_address_entity_varchar'),
|
| 1013 |
+
array('attribute_id', 'value')
|
| 1014 |
+
)
|
| 1015 |
+
->where('entity_type_id = ?', $this->getEntityTypeId('customer_address'))
|
| 1016 |
+
->where('entity_id = ?', $select)
|
| 1017 |
+
->where('attribute_id IN(?)', $addressIds);
|
| 1018 |
+
|
| 1019 |
+
$billingResult = array();
|
| 1020 |
+
$result = $db->query($select);
|
| 1021 |
+
if($result->rowCount()){
|
| 1022 |
+
while($row = $result->fetch()){
|
| 1023 |
+
$billingResult[$addressAttr[$row['attribute_id']]] = $row['value'];
|
| 1024 |
+
}
|
| 1025 |
+
}
|
| 1026 |
+
|
| 1027 |
+
$countryCode = null;
|
| 1028 |
+
if(isset($billingResult['country_id'])){
|
| 1029 |
+
$countryCode = $billingResult['country_id'];
|
| 1030 |
+
}
|
| 1031 |
+
|
| 1032 |
+
if (array_key_exists('gender', $customer)) {
|
| 1033 |
+
if ($customer['gender'] % 2 == 0) {
|
| 1034 |
+
$customer['gender'] = 'female';
|
| 1035 |
+
} else {
|
| 1036 |
+
$customer['gender'] = 'male';
|
| 1037 |
+
}
|
| 1038 |
+
}
|
| 1039 |
+
|
| 1040 |
+
$customer_to_save = array(
|
| 1041 |
+
'customer_id' => $id,
|
| 1042 |
+
'country' => !empty($countryCode) ? $this->_helperExporter->getCountry($countryCode)->getName() : '',
|
| 1043 |
+
'zip' => array_key_exists('postcode', $billingResult) ? $billingResult['postcode'] : '',
|
| 1044 |
+
);
|
| 1045 |
+
|
| 1046 |
+
foreach($customer_attributes as $attr) {
|
| 1047 |
+
$customer_to_save[$attr] = array_key_exists($attr, $customer) ? $customer[$attr] : '';
|
| 1048 |
+
}
|
| 1049 |
+
$customers_to_save[] = $customer_to_save;
|
| 1050 |
+
}
|
| 1051 |
+
|
| 1052 |
+
$data = $customers_to_save;
|
| 1053 |
+
|
| 1054 |
+
if (count($customers) == 0 && $header) {
|
| 1055 |
+
return null;
|
| 1056 |
+
}
|
| 1057 |
+
|
| 1058 |
+
if ($header) {
|
| 1059 |
+
$data = array_merge(array(array_keys(end($customers_to_save))), $customers_to_save);
|
| 1060 |
+
$header = false;
|
| 1061 |
+
}
|
| 1062 |
+
$files->savePartToCsv('customers.csv', $data);
|
| 1063 |
+
$data = null;
|
| 1064 |
+
|
| 1065 |
+
$count = count($customers_to_save);
|
| 1066 |
+
$page++;
|
| 1067 |
+
|
| 1068 |
+
}while($count >= $limit);
|
| 1069 |
+
$customers = null;
|
| 1070 |
+
|
| 1071 |
+
if ($this->config->isCustomersExportEnabled($account)) {
|
| 1072 |
+
|
| 1073 |
+
$customerSourceKey = $this->bxData->addMainCSVCustomerFile($files->getPath('customers.csv'), 'customer_id');
|
| 1074 |
+
|
| 1075 |
+
foreach ($customer_attributes as $prop) {
|
| 1076 |
+
if($prop == 'id') {
|
| 1077 |
+
continue;
|
| 1078 |
+
}
|
| 1079 |
+
$this->bxData->addSourceStringField($customerSourceKey, $prop, $prop);
|
| 1080 |
+
}
|
| 1081 |
+
}
|
| 1082 |
+
}
|
| 1083 |
+
|
| 1084 |
+
/**
|
| 1085 |
+
* @param $account
|
| 1086 |
+
* @return array
|
| 1087 |
+
*/
|
| 1088 |
+
protected function getCustomerAttributes($account)
|
| 1089 |
+
{
|
| 1090 |
+
$attributes = array();
|
| 1091 |
+
Mage::log('bxLog: get all customer attributes for account: ' . $account, Zend_Log::INFO, self::BOXALINO_LOG_FILE);
|
| 1092 |
+
|
| 1093 |
+
$db = $this->_getReadAdapter();
|
| 1094 |
+
$select = $db->select()
|
| 1095 |
+
->from(
|
| 1096 |
+
array('main_table' => $db->getTableName('eav_attribute')),
|
| 1097 |
+
array(
|
| 1098 |
+
'attribute_code',
|
| 1099 |
+
)
|
| 1100 |
+
)
|
| 1101 |
+
->where('main_table.entity_type_id = ?', $this->getEntityTypeId('customer'));
|
| 1102 |
+
|
| 1103 |
+
$result = $db->query($select);
|
| 1104 |
+
if($result->rowCount()){
|
| 1105 |
+
while($row = $result->fetch()){
|
| 1106 |
+
$attributes[$row['attribute_code']] = $row['attribute_code'];
|
| 1107 |
+
}
|
| 1108 |
+
}
|
| 1109 |
+
|
| 1110 |
+
$requiredProperties = array('dob', 'gender');
|
| 1111 |
+
Mage::log('bxLog: get configured customer attributes for account: ' . $account, Zend_Log::INFO, self::BOXALINO_LOG_FILE);
|
| 1112 |
+
$filteredAttributes = $this->config->getAccountCustomersProperties($account, $attributes, $requiredProperties);
|
| 1113 |
+
|
| 1114 |
+
foreach($attributes as $k => $attribute) {
|
| 1115 |
+
if(!in_array($attribute, $filteredAttributes)) {
|
| 1116 |
+
unset($attributes[$k]);
|
| 1117 |
+
}
|
| 1118 |
+
}
|
| 1119 |
+
Mage::log('bxLog: returning configured customer attributes for account ' . $account . ': ' . implode(',', array_values($attributes)), Zend_Log::INFO, self::BOXALINO_LOG_FILE);
|
| 1120 |
+
return $attributes;
|
| 1121 |
+
}
|
| 1122 |
+
|
| 1123 |
+
/**
|
| 1124 |
+
* @param $account
|
| 1125 |
+
* @param $files
|
| 1126 |
+
*/
|
| 1127 |
+
protected function exportTransactions($account, $files){
|
| 1128 |
+
if(!$this->config->isTransactionsExportEnabled($account)){
|
| 1129 |
+
return;
|
| 1130 |
+
}
|
| 1131 |
+
|
| 1132 |
+
$db = $this->_getReadAdapter();
|
| 1133 |
+
$limit = 1000;
|
| 1134 |
+
$count = $limit;
|
| 1135 |
+
$page = 1;
|
| 1136 |
+
$header = true;
|
| 1137 |
+
$transactions_to_save = array();
|
| 1138 |
+
|
| 1139 |
+
$salt = $db->quote(
|
| 1140 |
+
((string) Mage::getConfig()->getNode('global/crypt/key')) .
|
| 1141 |
+
$account
|
| 1142 |
+
);
|
| 1143 |
+
|
| 1144 |
+
while($count >= $limit){
|
| 1145 |
+
|
| 1146 |
+
$configurable = array();
|
| 1147 |
+
$select = $db
|
| 1148 |
+
->select()
|
| 1149 |
+
->from(
|
| 1150 |
+
array('order' => $db->getTableName($this->_prefix . 'sales_flat_order')),
|
| 1151 |
+
array(
|
| 1152 |
+
'entity_id',
|
| 1153 |
+
'status',
|
| 1154 |
+
'updated_at',
|
| 1155 |
+
'created_at',
|
| 1156 |
+
'customer_id',
|
| 1157 |
+
'base_subtotal',
|
| 1158 |
+
'shipping_amount',
|
| 1159 |
+
)
|
| 1160 |
+
)
|
| 1161 |
+
->joinLeft(
|
| 1162 |
+
array('item' => $db->getTableName($this->_prefix . 'sales_flat_order_item')),
|
| 1163 |
+
'order.entity_id = item.order_id',
|
| 1164 |
+
array(
|
| 1165 |
+
'product_id',
|
| 1166 |
+
'product_options',
|
| 1167 |
+
'price',
|
| 1168 |
+
'original_price',
|
| 1169 |
+
'product_type',
|
| 1170 |
+
'qty_ordered',
|
| 1171 |
+
)
|
| 1172 |
+
)
|
| 1173 |
+
->joinLeft(
|
| 1174 |
+
array('guest' => $db->getTableName($this->_prefix . 'sales_flat_order_address')),
|
| 1175 |
+
'order.billing_address_id = guest.entity_id',
|
| 1176 |
+
array(
|
| 1177 |
+
'guest_id' => 'IF(guest.email IS NOT NULL, SHA1(CONCAT(guest.email, ' . $salt . ')), NULL)'
|
| 1178 |
+
)
|
| 1179 |
+
)
|
| 1180 |
+
->where('order.status <> ?', 'canceled')
|
| 1181 |
+
->order(array('order.entity_id', 'item.product_type'))
|
| 1182 |
+
->limit($limit, ($page - 1) * $limit);
|
| 1183 |
+
|
| 1184 |
+
$transaction_attributes = $this->getTransactionAttributes($account);
|
| 1185 |
+
|
| 1186 |
+
if (count($transaction_attributes)) {
|
| 1187 |
+
$billing_columns = $shipping_columns = array();
|
| 1188 |
+
foreach ($transaction_attributes as $attribute) {
|
| 1189 |
+
$billing_columns['billing_' . $attribute] = $attribute;
|
| 1190 |
+
$shipping_columns['shipping_' . $attribute] = $attribute;
|
| 1191 |
+
}
|
| 1192 |
+
$select->joinLeft(
|
| 1193 |
+
array('billing_address' => $db->getTableName($this->_prefix . 'sales_flat_order_address')),
|
| 1194 |
+
'order.billing_address_id = billing_address.entity_id',
|
| 1195 |
+
$billing_columns
|
| 1196 |
+
)
|
| 1197 |
+
->joinLeft(
|
| 1198 |
+
array('shipping_address' => $db->getTableName($this->_prefix . 'sales_flat_order_address')),
|
| 1199 |
+
'order.shipping_address_id = shipping_address.entity_id',
|
| 1200 |
+
$shipping_columns
|
| 1201 |
+
);
|
| 1202 |
+
}
|
| 1203 |
+
|
| 1204 |
+
$transactions = array();
|
| 1205 |
+
$result = $db->query($select);
|
| 1206 |
+
if($result->rowCount()){
|
| 1207 |
+
while($transaction = $result->fetch()){
|
| 1208 |
+
|
| 1209 |
+
if ($transaction['product_type'] == 'configurable') {
|
| 1210 |
+
$configurable[$transaction['product_id']] = $transaction;
|
| 1211 |
+
continue;
|
| 1212 |
+
}
|
| 1213 |
+
$productOptions = unserialize($transaction['product_options']);
|
| 1214 |
+
if (intval($transaction['price']) == 0 && $transaction['product_type'] == 'simple' && isset($productOptions['info_buyRequest']['product'])) {
|
| 1215 |
+
if (isset($configurable[$productOptions['info_buyRequest']['product']])) {
|
| 1216 |
+
$pid = $configurable[$productOptions['info_buyRequest']['product']];
|
| 1217 |
+
|
| 1218 |
+
$transaction['original_price'] = $pid['original_price'];
|
| 1219 |
+
$transaction['price'] = $pid['price'];
|
| 1220 |
+
} else {
|
| 1221 |
+
$product = $this->productFactory->create();
|
| 1222 |
+
try {
|
| 1223 |
+
$pid = Mage::getModel('catalog/product')->load($productOptions['info_buyRequest']['product']);
|
| 1224 |
+
|
| 1225 |
+
$transaction['original_price'] = ($pid->getPrice());
|
| 1226 |
+
$transaction['price'] = ($pid->getPrice());
|
| 1227 |
+
|
| 1228 |
+
$tmp = array();
|
| 1229 |
+
$tmp['original_price'] = $transaction['original_price'];
|
| 1230 |
+
$tmp['price'] = $transaction['price'];
|
| 1231 |
+
|
| 1232 |
+
$configurable[$productOptions['info_buyRequest']['product']] = $tmp;
|
| 1233 |
+
|
| 1234 |
+
$pid = null;
|
| 1235 |
+
$tmp = null;
|
| 1236 |
+
} catch (\Exception $e) {
|
| 1237 |
+
Mage::log($e, Zend_Log::CRIT, self::BOXALINO_LOG_FILE);
|
| 1238 |
+
}
|
| 1239 |
+
}
|
| 1240 |
+
}
|
| 1241 |
+
|
| 1242 |
+
$status = 0;
|
| 1243 |
+
if ($transaction['updated_at'] != $transaction['created_at']) {
|
| 1244 |
+
switch ($transaction['status']) {
|
| 1245 |
+
case 'canceled':
|
| 1246 |
+
continue;
|
| 1247 |
+
break;
|
| 1248 |
+
case 'processing':
|
| 1249 |
+
$status = 1;
|
| 1250 |
+
break;
|
| 1251 |
+
case 'complete':
|
| 1252 |
+
$status = 2;
|
| 1253 |
+
break;
|
| 1254 |
+
}
|
| 1255 |
+
}
|
| 1256 |
+
$final_transaction = array(
|
| 1257 |
+
'order_id' => $transaction['entity_id'],
|
| 1258 |
+
'entity_id' => $transaction['product_id'],
|
| 1259 |
+
'customer_id' => $transaction['customer_id'],
|
| 1260 |
+
'guest_id' => $transaction['guest_id'],
|
| 1261 |
+
'price' => $transaction['original_price'],
|
| 1262 |
+
'discounted_price' => $transaction['price'],
|
| 1263 |
+
'quantity' => $transaction['qty_ordered'],
|
| 1264 |
+
'total_order_value' => ($transaction['base_subtotal'] + $transaction['shipping_amount']),
|
| 1265 |
+
'shipping_costs' => $transaction['shipping_amount'],
|
| 1266 |
+
'order_date' => $transaction['created_at'],
|
| 1267 |
+
'confirmation_date' => $status == 1 ? $transaction['updated_at'] : null,
|
| 1268 |
+
'shipping_date' => $status == 2 ? $transaction['updated_at'] : null,
|
| 1269 |
+
'status' => $transaction['status'],
|
| 1270 |
+
);
|
| 1271 |
+
|
| 1272 |
+
if (count($transaction_attributes)) {
|
| 1273 |
+
foreach ($transaction_attributes as $attribute) {
|
| 1274 |
+
$final_transaction['billing_' . $attribute] = $transaction['billing_' . $attribute];
|
| 1275 |
+
$final_transaction['shipping_' . $attribute] = $transaction['shipping_' . $attribute];
|
| 1276 |
+
}
|
| 1277 |
+
}
|
| 1278 |
+
|
| 1279 |
+
$transactions_to_save[] = $final_transaction;
|
| 1280 |
+
$guest_id_transaction = null;
|
| 1281 |
+
$final_transaction = null;
|
| 1282 |
+
}
|
| 1283 |
+
}else{
|
| 1284 |
+
return ;
|
| 1285 |
+
}
|
| 1286 |
+
|
| 1287 |
+
$data[] = $transactions_to_save;
|
| 1288 |
+
$count = count($transactions);
|
| 1289 |
+
$configurable = null;
|
| 1290 |
+
$transactions = null;
|
| 1291 |
+
|
| 1292 |
+
if ($header) {
|
| 1293 |
+
$data = array_merge(array(array_keys(end($transactions_to_save))), $transactions_to_save);
|
| 1294 |
+
$header = false;
|
| 1295 |
+
$transactions_to_save = null;
|
| 1296 |
+
}
|
| 1297 |
+
Mage::log('bxLog: Transactions - save to file for account ' . $account, Zend_Log::INFO, self::BOXALINO_LOG_FILE);
|
| 1298 |
+
$files->savePartToCsv('transactions.csv', $data);
|
| 1299 |
+
$data = null;
|
| 1300 |
+
$page++;
|
| 1301 |
+
}
|
| 1302 |
+
$sourceKey = $this->bxData->setCSVTransactionFile($files->getPath('transactions.csv'), 'order_id', 'entity_id', 'customer_id', 'order_date', 'total_order_value', 'price', 'discounted_price');
|
| 1303 |
+
$this->bxData->addSourceCustomerGuestProperty($sourceKey,'guest_id');
|
| 1304 |
+
Mage::log('bxLog: Transactions - end of export for account ' . $account, Zend_Log::INFO, self::BOXALINO_LOG_FILE);
|
| 1305 |
+
}
|
| 1306 |
+
|
| 1307 |
+
/**
|
| 1308 |
+
* @param $account
|
| 1309 |
+
* @return array
|
| 1310 |
+
*/
|
| 1311 |
+
protected function getTransactionAttributes($account){
|
| 1312 |
+
|
| 1313 |
+
$setupConfig = Mage::getConfig()->getResourceConnectionConfig("default_setup");
|
| 1314 |
+
|
| 1315 |
+
if(!isset($setupConfig->dbname)) {
|
| 1316 |
+
Mage::log("default_setup configuration doesn't provide a dbname in getResourceConnectionConfig", Zend_Log::WARN, self::BOXALINO_LOG_FILE);
|
| 1317 |
+
return array();
|
| 1318 |
+
}
|
| 1319 |
+
$attributes = array();
|
| 1320 |
+
$db = $this->_getReadAdapter();
|
| 1321 |
+
$select = $db->select()
|
| 1322 |
+
->from(
|
| 1323 |
+
'INFORMATION_SCHEMA.COLUMNS',
|
| 1324 |
+
array('COLUMN_NAME')
|
| 1325 |
+
)
|
| 1326 |
+
->where('TABLE_SCHEMA=?', $setupConfig->dbname)
|
| 1327 |
+
->where('TABLE_NAME=?', $db->getTableName($this->_prefix . 'sales_flat_order_address'));
|
| 1328 |
+
$this->_entityIds = array();
|
| 1329 |
+
|
| 1330 |
+
$result = $db->query($select);
|
| 1331 |
+
if($result->rowCount()){
|
| 1332 |
+
while($row = $result->fetch()){
|
| 1333 |
+
$attributes[$row['COLUMN_NAME']] = $row['COLUMN_NAME'];
|
| 1334 |
+
}
|
| 1335 |
+
}
|
| 1336 |
+
|
| 1337 |
+
$requiredProperties = array();
|
| 1338 |
+
$filteredAttributes = $this->config->getAccountTransactionsProperties($account, $attributes, $requiredProperties);
|
| 1339 |
+
|
| 1340 |
+
foreach($attributes as $k => $attribute) {
|
| 1341 |
+
if(!in_array($attribute, $filteredAttributes)) {
|
| 1342 |
+
unset($attributes[$k]);
|
| 1343 |
+
}
|
| 1344 |
+
}
|
| 1345 |
+
return $attributes;
|
| 1346 |
+
}
|
| 1347 |
+
|
| 1348 |
+
/**
|
| 1349 |
+
* @param $store
|
| 1350 |
+
* @param $language
|
| 1351 |
+
* @param $transformedCategories
|
| 1352 |
+
* @return mixed
|
| 1353 |
+
*/
|
| 1354 |
+
protected function exportCategories($store, $language, $transformedCategories)
|
| 1355 |
+
{
|
| 1356 |
+
$categoryTypeId = $this->getEntityTypeId('catalog_category');
|
| 1357 |
+
$db = $this->_getReadAdapter();
|
| 1358 |
+
$select = $db->select()
|
| 1359 |
+
->from(
|
| 1360 |
+
array('c_t' => $db->getTableName('catalog_category_entity')),
|
| 1361 |
+
array('entity_id', 'parent_id')
|
| 1362 |
+
)
|
| 1363 |
+
->joinInner(
|
| 1364 |
+
array('c_v' => $db->getTableName('catalog_category_entity_varchar')),
|
| 1365 |
+
'c_v.entity_id = c_t.entity_id',
|
| 1366 |
+
array('c_v.value', 'c_v.store_id')
|
| 1367 |
+
)
|
| 1368 |
+
->where('c_v.attribute_id = ?', $this->getAttributeId('name',$categoryTypeId))
|
| 1369 |
+
->where('c_v.store_id = ? OR c_v.store_id = 0', $store->getId());
|
| 1370 |
+
|
| 1371 |
+
|
| 1372 |
+
$result = $db->query($select);
|
| 1373 |
+
if($result->rowCount()){
|
| 1374 |
+
while($row = $result->fetch()){
|
| 1375 |
+
if (!$row['parent_id']) {
|
| 1376 |
+
continue;
|
| 1377 |
+
}
|
| 1378 |
+
if(isset($transformedCategories[$row['entity_id']])) {
|
| 1379 |
+
$transformedCategories[$row['entity_id']]['value_' .$language] = $row['value'];
|
| 1380 |
+
continue;
|
| 1381 |
+
}
|
| 1382 |
+
$transformedCategories[$row['entity_id']] = array(
|
| 1383 |
+
'category_id' => $row['entity_id'],
|
| 1384 |
+
'parent_id' => $row['parent_id'],
|
| 1385 |
+
'value_' . $language => $row['value']
|
| 1386 |
+
);
|
| 1387 |
+
}
|
| 1388 |
+
}
|
| 1389 |
+
return $transformedCategories;
|
| 1390 |
+
}
|
| 1391 |
+
|
| 1392 |
+
/**
|
| 1393 |
+
* @param $entityType
|
| 1394 |
+
* @return null
|
| 1395 |
+
*/
|
| 1396 |
+
protected function getEntityTypeId($entityType)
|
| 1397 |
+
{
|
| 1398 |
+
if ($this->_entityTypeIds == null) {
|
| 1399 |
+
$db = $this->_getReadAdapter();
|
| 1400 |
+
$select = $db->select()
|
| 1401 |
+
->from(
|
| 1402 |
+
$db->getTableName('eav_entity_type'),
|
| 1403 |
+
array('entity_type_id', 'entity_type_code')
|
| 1404 |
+
);
|
| 1405 |
+
|
| 1406 |
+
$result = $db->query($select);
|
| 1407 |
+
if($result->rowCount()){
|
| 1408 |
+
while ($row = $result->fetch()) {
|
| 1409 |
+
$this->_entityTypeIds[$row['entity_type_code']] = $row['entity_type_id'];
|
| 1410 |
+
}
|
| 1411 |
+
}
|
| 1412 |
+
}
|
| 1413 |
+
return array_key_exists($entityType, $this->_entityTypeIds) ? $this->_entityTypeIds[$entityType] : null;
|
| 1414 |
+
}
|
| 1415 |
+
|
| 1416 |
+
/**
|
| 1417 |
+
* @param $attr_code
|
| 1418 |
+
* @return null
|
| 1419 |
+
*/
|
| 1420 |
+
protected function getAttributeId($attr_code){
|
| 1421 |
+
$db = $this->_getReadAdapter();
|
| 1422 |
+
$select = $db->select()
|
| 1423 |
+
->from(
|
| 1424 |
+
array('a_t' => $db->getTableName('eav_attribute')),
|
| 1425 |
+
array('attribute_id')
|
| 1426 |
+
)->where('a_t.attribute_code = ?', $attr_code);
|
| 1427 |
+
|
| 1428 |
+
$result = $db->query($select);
|
| 1429 |
+
if($result->rowCount()){
|
| 1430 |
+
while ($row = $result->fetch()) {
|
| 1431 |
+
return $row['attribute_id'];
|
| 1432 |
+
}
|
| 1433 |
+
|
| 1434 |
+
}
|
| 1435 |
+
return null;
|
| 1436 |
+
}
|
| 1437 |
+
|
| 1438 |
+
/**
|
| 1439 |
+
* @return int
|
| 1440 |
+
*/
|
| 1441 |
+
protected function _getLastIndex()
|
| 1442 |
+
{
|
| 1443 |
+
if ($this->_lastIndex == 0) {
|
| 1444 |
+
$this->_setLastIndex();
|
| 1445 |
+
}
|
| 1446 |
+
return $this->_lastIndex;
|
| 1447 |
+
}
|
| 1448 |
+
|
| 1449 |
+
/**
|
| 1450 |
+
*
|
| 1451 |
+
*/
|
| 1452 |
+
protected function _setLastIndex()
|
| 1453 |
+
{
|
| 1454 |
+
$dates = array();
|
| 1455 |
+
$indexes = Mage::getModel('index/indexer')->getProcessesCollection()->getData();
|
| 1456 |
+
foreach ($indexes as $index) {
|
| 1457 |
+
if ($index['indexer_code'] == 'boxalinoexporter_indexer' && !empty($index['started_at'])) {
|
| 1458 |
+
$dates[] = DateTime::createFromFormat('Y-m-d H:i:s', $index['started_at']);
|
| 1459 |
+
} elseif ($index['indexer_code'] == 'boxalinoexporter_delta' && !empty($index['ended_at'])) {
|
| 1460 |
+
$dates[] = DateTime::createFromFormat('Y-m-d H:i:s', $index['ended_at']);
|
| 1461 |
+
}
|
| 1462 |
+
}
|
| 1463 |
+
if (count($dates) == 2) {
|
| 1464 |
+
if ($dates[0] > $dates[1]) {
|
| 1465 |
+
$date = $dates[0]->format('Y-m-d H:i:s');
|
| 1466 |
+
} else {
|
| 1467 |
+
$date = $dates[1]->format('Y-m-d H:i:s');
|
| 1468 |
+
}
|
| 1469 |
+
} else {
|
| 1470 |
+
$date = $dates[0]->format('Y-m-d H:i:s');
|
| 1471 |
+
}
|
| 1472 |
+
|
| 1473 |
+
$this->_lastIndex = $date;
|
| 1474 |
+
}
|
| 1475 |
+
|
| 1476 |
+
protected function loadBxLibrary(){
|
| 1477 |
+
$libPath = __DIR__ . '/../../Lib';
|
| 1478 |
+
require_once($libPath . '/BxClient.php');
|
| 1479 |
+
\com\boxalino\bxclient\v1\BxClient::LOAD_CLASSES($libPath);
|
| 1480 |
+
}
|
| 1481 |
+
}
|
app/code/community/Boxalino/{CemSearch → Intelligence}/Model/Observer.php
RENAMED
|
@@ -1,111 +1,109 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
$
|
| 37 |
-
$
|
| 38 |
-
$
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
$
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
$
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
$
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
$
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
}
|
| 111 |
-
}
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
class Boxalino_Intelligence_Model_Observer{
|
| 4 |
+
|
| 5 |
+
public function onProductAddedToCart(Varien_Event_Observer $event)
|
| 6 |
+
{
|
| 7 |
+
|
| 8 |
+
try {
|
| 9 |
+
$session = Mage::getSingleton('Boxalino_Intelligence_Model_Session');
|
| 10 |
+
$script = Mage::helper('intelligence')->reportAddToBasket(
|
| 11 |
+
$event->getProduct()->getId(),
|
| 12 |
+
$event->getQuoteItem()->getQty(),
|
| 13 |
+
$event->getProduct()->getSpecialPrice() > 0 ? $event->getProduct()->getSpecialPrice() : $event->getProduct()->getPrice(),
|
| 14 |
+
Mage::app()->getStore()->getCurrentCurrencyCode()
|
| 15 |
+
);
|
| 16 |
+
$session->addScript($script);
|
| 17 |
+
} catch (Exception $e) {
|
| 18 |
+
if (Mage::helper('intelligence')->isDebugEnabled()) {
|
| 19 |
+
echo($e);
|
| 20 |
+
exit;
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
}
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
public function onOrderSuccessPageView(Varien_Event_Observer $event)
|
| 27 |
+
{
|
| 28 |
+
try {
|
| 29 |
+
$orders = Mage::getModel('sales/order')->getCollection()
|
| 30 |
+
->setOrder('entity_id', 'DESC')
|
| 31 |
+
->setPageSize(1)
|
| 32 |
+
->setCurPage(1);
|
| 33 |
+
$order = $orders->getFirstItem();
|
| 34 |
+
$orderData = $order->getData();
|
| 35 |
+
$transactionId = $orderData['entity_id'];
|
| 36 |
+
$products = array();
|
| 37 |
+
$fullPrice = 0;
|
| 38 |
+
foreach ($order->getAllItems() as $item) {
|
| 39 |
+
if ($item->getPrice() > 0) {
|
| 40 |
+
$products[] = array(
|
| 41 |
+
'product' => $item->getProduct()->getId(),
|
| 42 |
+
'quantity' => $item->getData('qty_ordered'),
|
| 43 |
+
'price' => $item->getPrice()
|
| 44 |
+
);
|
| 45 |
+
$fullPrice += $item->getPrice() * $item->getData('qty_ordered');
|
| 46 |
+
}
|
| 47 |
+
}
|
| 48 |
+
$script = Mage::helper('intelligence')->reportPurchase($products, $transactionId, $fullPrice, Mage::app()->getStore()->getCurrentCurrencyCode());
|
| 49 |
+
|
| 50 |
+
$session = Mage::getSingleton('Boxalino_Intelligence_Model_Session');
|
| 51 |
+
$session->addScript($script);
|
| 52 |
+
} catch (Exception $e) {
|
| 53 |
+
if (Mage::helper('intelligence')->isDebugEnabled()) {
|
| 54 |
+
echo($e);
|
| 55 |
+
exit;
|
| 56 |
+
}
|
| 57 |
+
}
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
public function onProductPageView(Varien_Event_Observer $event)
|
| 62 |
+
{
|
| 63 |
+
try {
|
| 64 |
+
$productId = $event['product']->getId();
|
| 65 |
+
$script = Mage::helper('intelligence')->reportProductView($productId);
|
| 66 |
+
|
| 67 |
+
$session = Mage::getSingleton('Boxalino_Intelligence_Model_Session');
|
| 68 |
+
$session->addScript($script);
|
| 69 |
+
} catch (Exception $e) {
|
| 70 |
+
if (Mage::helper('intelligence')->isDebugEnabled()) {
|
| 71 |
+
echo($e);
|
| 72 |
+
exit;
|
| 73 |
+
}
|
| 74 |
+
}
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
public function onCategoryPageView(Varien_Event_Observer $event)
|
| 78 |
+
{
|
| 79 |
+
|
| 80 |
+
try {
|
| 81 |
+
$categoryId = $event['category']['entity_id'];
|
| 82 |
+
$script = Mage::helper('intelligence')->reportCategoryView($categoryId);
|
| 83 |
+
|
| 84 |
+
$session = Mage::getSingleton('Boxalino_Intelligence_Model_Session');
|
| 85 |
+
$session->addScript($script);
|
| 86 |
+
} catch (Exception $e) {
|
| 87 |
+
if (Mage::helper('intelligence')->isDebugEnabled()) {
|
| 88 |
+
echo($e);
|
| 89 |
+
exit;
|
| 90 |
+
}
|
| 91 |
+
}
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
public function onLogin(Varien_Event_Observer $event)
|
| 95 |
+
{
|
| 96 |
+
try {
|
| 97 |
+
$userId = $event['customer']['entity_id'];
|
| 98 |
+
$script = Mage::helper('intelligence')->reportLogin($userId);
|
| 99 |
+
|
| 100 |
+
$session = Mage::getSingleton('Boxalino_Intelligence_Model_Session');
|
| 101 |
+
$session->addScript($script);
|
| 102 |
+
} catch (Exception $e) {
|
| 103 |
+
if (Mage::helper('intelligence')->isDebugEnabled()) {
|
| 104 |
+
echo($e);
|
| 105 |
+
exit;
|
| 106 |
+
}
|
| 107 |
+
}
|
| 108 |
+
}
|
| 109 |
+
}
|
|
|
|
|
|
app/code/community/Boxalino/Intelligence/Model/Resource/Product/Collection.php
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
class Boxalino_Intelligence_Model_Resource_Product_Collection extends Mage_Catalog_Model_Resource_Product_Collection{
|
| 4 |
+
/**
|
| 5 |
+
* @var int
|
| 6 |
+
*/
|
| 7 |
+
protected $bxCurPage = 0;
|
| 8 |
+
|
| 9 |
+
/**
|
| 10 |
+
* @var int
|
| 11 |
+
*/
|
| 12 |
+
protected $bxLastPage = 0;
|
| 13 |
+
|
| 14 |
+
/**
|
| 15 |
+
* @var int
|
| 16 |
+
*/
|
| 17 |
+
protected $bxTotal = 0;
|
| 18 |
+
|
| 19 |
+
/**
|
| 20 |
+
* @var int
|
| 21 |
+
*/
|
| 22 |
+
protected $bxCount = 0;
|
| 23 |
+
|
| 24 |
+
/**
|
| 25 |
+
* @var bool
|
| 26 |
+
*/
|
| 27 |
+
protected $fallback = false;
|
| 28 |
+
|
| 29 |
+
/**
|
| 30 |
+
*
|
| 31 |
+
*/
|
| 32 |
+
public function _construct(){
|
| 33 |
+
|
| 34 |
+
$bxHelperData = Mage::helper('intelligence');
|
| 35 |
+
$this->fallback = $bxHelperData->getFallback();
|
| 36 |
+
$layer = $this->getLayer();
|
| 37 |
+
if(Mage::app()->getStore()->isAdmin() || !$bxHelperData->isEnabledOnLayer($layer)){
|
| 38 |
+
$this->fallback = true;
|
| 39 |
+
}
|
| 40 |
+
parent::_construct();
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
/**
|
| 44 |
+
* @return Mage_Core_Model_Abstract|mixed
|
| 45 |
+
*/
|
| 46 |
+
private function getLayer()
|
| 47 |
+
{
|
| 48 |
+
$layer = Mage::registry('current_layer');
|
| 49 |
+
if ($layer) {
|
| 50 |
+
return $layer;
|
| 51 |
+
}
|
| 52 |
+
return Mage::getSingleton('catalog/layer');
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
/**
|
| 56 |
+
* @param $bxCurPage
|
| 57 |
+
*/
|
| 58 |
+
public function setCurBxPage($bxCurPage) {
|
| 59 |
+
|
| 60 |
+
$this->bxCurPage = $bxCurPage;
|
| 61 |
+
return $this;
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
/**
|
| 65 |
+
* @param $bxLastPage
|
| 66 |
+
*/
|
| 67 |
+
public function setLastBxPage($bxLastPage) {
|
| 68 |
+
|
| 69 |
+
$this->bxLastPage = $bxLastPage;
|
| 70 |
+
return $this;
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
/**
|
| 74 |
+
* @param $bxTotal
|
| 75 |
+
*/
|
| 76 |
+
public function setBxTotal($bxTotal) {
|
| 77 |
+
|
| 78 |
+
$this->bxTotal = $bxTotal;
|
| 79 |
+
return $this;
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
/**
|
| 83 |
+
* @return int
|
| 84 |
+
*/
|
| 85 |
+
public function getSize() {
|
| 86 |
+
|
| 87 |
+
if($this->fallback){
|
| 88 |
+
return parent::getSize();
|
| 89 |
+
}
|
| 90 |
+
return $this->bxTotal;
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
/**
|
| 94 |
+
* @return int
|
| 95 |
+
*/
|
| 96 |
+
public function count(){
|
| 97 |
+
|
| 98 |
+
if($this->fallback){
|
| 99 |
+
return parent::count();
|
| 100 |
+
}
|
| 101 |
+
return $this->bxCount;
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
/**
|
| 105 |
+
* @param $count
|
| 106 |
+
* @return $this
|
| 107 |
+
*/
|
| 108 |
+
public function setBxCount($count){
|
| 109 |
+
|
| 110 |
+
$this->bxCount = $count;
|
| 111 |
+
return $this;
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
/**
|
| 115 |
+
* @param int $displacement
|
| 116 |
+
* @return int
|
| 117 |
+
*/
|
| 118 |
+
public function getCurPage($displacement = 0) {
|
| 119 |
+
|
| 120 |
+
if($this->fallback){
|
| 121 |
+
return parent::getCurPage();
|
| 122 |
+
}
|
| 123 |
+
return $this->bxCurPage + $displacement;
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
/**
|
| 127 |
+
* @return int
|
| 128 |
+
*/
|
| 129 |
+
public function getLastPageNumber() {
|
| 130 |
+
|
| 131 |
+
if($this->fallback){
|
| 132 |
+
return parent::getLastPageNumber();
|
| 133 |
+
}
|
| 134 |
+
return $this->bxLastPage;
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
}
|
app/code/community/Boxalino/{CemSearch → Intelligence}/Model/Session.php
RENAMED
|
@@ -1,32 +1,32 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
|
| 3 |
-
class
|
| 4 |
-
{
|
| 5 |
-
|
| 6 |
-
public function __construct()
|
| 7 |
-
{
|
| 8 |
-
$this->init('checkout');
|
| 9 |
-
}
|
| 10 |
-
|
| 11 |
-
public function addScript($script)
|
| 12 |
-
{
|
| 13 |
-
if (!isset($this->_data['scipts']) || !is_array($this->_data['scipts'])) {
|
| 14 |
-
$this->_data['scipts'] = array();
|
| 15 |
-
}
|
| 16 |
-
$this->_data['scipts'][] = $script;
|
| 17 |
-
}
|
| 18 |
-
|
| 19 |
-
public function getScripts()
|
| 20 |
-
{
|
| 21 |
-
$scripts = array();
|
| 22 |
-
if (isset($this->_data['scipts']) && is_array($this->_data['scipts'])) {
|
| 23 |
-
$scripts = $this->_data['scipts'];
|
| 24 |
-
}
|
| 25 |
-
return $scripts;
|
| 26 |
-
}
|
| 27 |
-
|
| 28 |
-
public function clearScripts()
|
| 29 |
-
{
|
| 30 |
-
$this->_data['scipts'] = array();
|
| 31 |
-
}
|
| 32 |
-
}
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
class Boxalino_Intelligence_Model_Session extends Mage_Core_Model_Session_Abstract
|
| 4 |
+
{
|
| 5 |
+
|
| 6 |
+
public function __construct()
|
| 7 |
+
{
|
| 8 |
+
$this->init('checkout');
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
public function addScript($script)
|
| 12 |
+
{
|
| 13 |
+
if (!isset($this->_data['scipts']) || !is_array($this->_data['scipts'])) {
|
| 14 |
+
$this->_data['scipts'] = array();
|
| 15 |
+
}
|
| 16 |
+
$this->_data['scipts'][] = $script;
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
public function getScripts()
|
| 20 |
+
{
|
| 21 |
+
$scripts = array();
|
| 22 |
+
if (isset($this->_data['scipts']) && is_array($this->_data['scipts'])) {
|
| 23 |
+
$scripts = $this->_data['scipts'];
|
| 24 |
+
}
|
| 25 |
+
return $scripts;
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
public function clearScripts()
|
| 29 |
+
{
|
| 30 |
+
$this->_data['scipts'] = array();
|
| 31 |
+
}
|
| 32 |
+
}
|
app/code/community/Boxalino/Intelligence/Model/Template/Filter.php
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
/**
|
| 4 |
+
* Class Boxalino_Intelligence_Model_Template_Filter
|
| 5 |
+
*/
|
| 6 |
+
class Boxalino_Intelligence_Model_Template_Filter extends Mage_Widget_Model_Template_Filter{
|
| 7 |
+
|
| 8 |
+
/**
|
| 9 |
+
* @param string $value
|
| 10 |
+
* @return string
|
| 11 |
+
*/
|
| 12 |
+
public function filter($value){
|
| 13 |
+
|
| 14 |
+
if(strpos($value,'boxalino/recommendation')){
|
| 15 |
+
Mage::helper('intelligence')->setCmsBlock($value);
|
| 16 |
+
}
|
| 17 |
+
return parent::filter($value);
|
| 18 |
+
}
|
| 19 |
+
}
|
app/code/community/Boxalino/{CemSearch → Intelligence}/controllers/AjaxController.php
RENAMED
|
@@ -1,47 +1,50 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
/**
|
| 3 |
-
* Magento
|
| 4 |
-
*
|
| 5 |
-
* NOTICE OF LICENSE
|
| 6 |
-
*
|
| 7 |
-
* This source file is subject to the Open Software License (OSL 3.0)
|
| 8 |
-
* that is bundled with this package in the file LICENSE.txt.
|
| 9 |
-
* It is also available through the world-wide-web at this URL:
|
| 10 |
-
* http://opensource.org/licenses/osl-3.0.php
|
| 11 |
-
* If you did not receive a copy of the license and are unable to
|
| 12 |
-
* obtain it through the world-wide-web, please send an email
|
| 13 |
-
* to license@magentocommerce.com so we can send you a copy immediately.
|
| 14 |
-
*
|
| 15 |
-
* DISCLAIMER
|
| 16 |
-
*
|
| 17 |
-
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
| 18 |
-
* versions in the future. If you wish to customize Magento for your
|
| 19 |
-
* needs please refer to http://www.magentocommerce.com for more information.
|
| 20 |
-
*
|
| 21 |
-
* @category Mage
|
| 22 |
-
* @package Mage_CatalogSearch
|
| 23 |
-
* @copyright Copyright (c) 2014 Magento Inc. (http://www.magentocommerce.com)
|
| 24 |
-
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
| 25 |
-
*/
|
| 26 |
-
|
| 27 |
-
/**
|
| 28 |
-
* Catalog Search Controller
|
| 29 |
-
*
|
| 30 |
-
* @category Mage
|
| 31 |
-
* @package Mage_CatalogSearch
|
| 32 |
-
* @module Catalog
|
| 33 |
-
*/
|
| 34 |
-
|
| 35 |
-
require_once "Mage/CatalogSearch/controllers/AjaxController.php";
|
| 36 |
-
|
| 37 |
-
class
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* Magento
|
| 4 |
+
*
|
| 5 |
+
* NOTICE OF LICENSE
|
| 6 |
+
*
|
| 7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
| 8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
| 9 |
+
* It is also available through the world-wide-web at this URL:
|
| 10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
| 11 |
+
* If you did not receive a copy of the license and are unable to
|
| 12 |
+
* obtain it through the world-wide-web, please send an email
|
| 13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
| 14 |
+
*
|
| 15 |
+
* DISCLAIMER
|
| 16 |
+
*
|
| 17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
| 18 |
+
* versions in the future. If you wish to customize Magento for your
|
| 19 |
+
* needs please refer to http://www.magentocommerce.com for more information.
|
| 20 |
+
*
|
| 21 |
+
* @category Mage
|
| 22 |
+
* @package Mage_CatalogSearch
|
| 23 |
+
* @copyright Copyright (c) 2014 Magento Inc. (http://www.magentocommerce.com)
|
| 24 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
| 25 |
+
*/
|
| 26 |
+
|
| 27 |
+
/**
|
| 28 |
+
* Catalog Search Controller
|
| 29 |
+
*
|
| 30 |
+
* @category Mage
|
| 31 |
+
* @package Mage_CatalogSearch
|
| 32 |
+
* @module Catalog
|
| 33 |
+
*/
|
| 34 |
+
|
| 35 |
+
require_once "Mage/CatalogSearch/controllers/AjaxController.php";
|
| 36 |
+
|
| 37 |
+
class Boxalino_Intelligence_AjaxController extends Mage_CatalogSearch_AjaxController{
|
| 38 |
+
|
| 39 |
+
/**
|
| 40 |
+
*
|
| 41 |
+
*/
|
| 42 |
+
public function suggestAction()
|
| 43 |
+
{
|
| 44 |
+
if (!$this->getRequest()->getParam('q', false)) {
|
| 45 |
+
$this->getResponse()->setRedirect(Mage::getSingleton('core/url')->getBaseUrl());
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
$this->getResponse()->setBody($this->getLayout()->createBlock('catalogsearch/autocomplete')->toHtml());
|
| 49 |
+
}
|
| 50 |
+
}
|
app/code/community/Boxalino/Intelligence/controllers/CategoryController.php
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
require_once "Mage/Catalog/controllers/CategoryController.php";
|
| 3 |
+
|
| 4 |
+
/**
|
| 5 |
+
* Class Boxalino_Intelligence_CategoryController
|
| 6 |
+
*/
|
| 7 |
+
class Boxalino_Intelligence_CategoryController extends Mage_Catalog_CategoryController{
|
| 8 |
+
|
| 9 |
+
/**
|
| 10 |
+
*
|
| 11 |
+
*/
|
| 12 |
+
public function viewAction()
|
| 13 |
+
{
|
| 14 |
+
if(isset($_REQUEST['bx_category_id']) && $_REQUEST['bx_category_id'] != 0) {
|
| 15 |
+
$catId = $this->getRequest()->getParam('id', false);
|
| 16 |
+
|
| 17 |
+
if ($catId) {
|
| 18 |
+
if ($catId != $_REQUEST['bx_category_id']) {
|
| 19 |
+
$_category = Mage::getModel('catalog/category')
|
| 20 |
+
->setStore(Mage::app()->getStore()->getId())
|
| 21 |
+
->load($_REQUEST['bx_category_id']);
|
| 22 |
+
$url = $_category->getUrl($_category);
|
| 23 |
+
$this->getResponse()->setRedirect($url)->sendResponse();
|
| 24 |
+
}
|
| 25 |
+
}
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
$bxHelperData = Mage::helper('intelligence');
|
| 29 |
+
|
| 30 |
+
try{
|
| 31 |
+
if($bxHelperData->isNavigationEnabled()){
|
| 32 |
+
if(count($bxHelperData->getAdapter()->getEntitiesIds()) == 0){
|
| 33 |
+
$bxHelperData->setFallback(true);
|
| 34 |
+
}
|
| 35 |
+
}
|
| 36 |
+
}catch(\Exception $e){
|
| 37 |
+
Mage::logException($e);
|
| 38 |
+
$bxHelperData->setFallback(true);
|
| 39 |
+
}
|
| 40 |
+
return parent::viewAction();
|
| 41 |
+
}
|
| 42 |
+
}
|
app/code/community/Boxalino/Intelligence/controllers/ResultController.php
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
require_once "Mage/CatalogSearch/controllers/ResultController.php";
|
| 3 |
+
|
| 4 |
+
/**
|
| 5 |
+
* Class Boxalino_Intelligence_ResultController
|
| 6 |
+
*/
|
| 7 |
+
class Boxalino_Intelligence_ResultController extends Mage_CatalogSearch_ResultController{
|
| 8 |
+
|
| 9 |
+
/**
|
| 10 |
+
* @return $this|void
|
| 11 |
+
*/
|
| 12 |
+
public function indexAction()
|
| 13 |
+
{
|
| 14 |
+
$bxHelperData = Mage::helper('intelligence');
|
| 15 |
+
try{
|
| 16 |
+
if($bxHelperData->isSearchEnabled() && $bxHelperData->getAdapter()->areThereSubPhrases()){
|
| 17 |
+
$queries = $bxHelperData->getAdapter()->getSubPhrasesQueries();
|
| 18 |
+
|
| 19 |
+
if(count($queries) < 2) {
|
| 20 |
+
$this->_redirect('*/*/*', array('q'=>$queries[0]));
|
| 21 |
+
return $this;
|
| 22 |
+
}
|
| 23 |
+
}
|
| 24 |
+
}catch(\Exception $e){
|
| 25 |
+
Mage::logException($e);
|
| 26 |
+
$bxHelperData->setFallback(true);
|
| 27 |
+
}
|
| 28 |
+
return parent::indexAction();
|
| 29 |
+
}
|
| 30 |
+
}
|
app/code/community/Boxalino/Intelligence/etc/adminhtml.xml
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0"?>
|
| 2 |
+
<config>
|
| 3 |
+
<acl>
|
| 4 |
+
<resources>
|
| 5 |
+
<admin>
|
| 6 |
+
<children>
|
| 7 |
+
<system>
|
| 8 |
+
<children>
|
| 9 |
+
<config>
|
| 10 |
+
<children>
|
| 11 |
+
<bxGeneral>
|
| 12 |
+
<title>Boxalino General</title>
|
| 13 |
+
</bxGeneral>
|
| 14 |
+
<bxExporter>
|
| 15 |
+
<title>Boxalino Exporter</title>
|
| 16 |
+
</bxExporter>
|
| 17 |
+
<bxSearch>
|
| 18 |
+
<title>Boxalino Search</title>
|
| 19 |
+
</bxSearch>
|
| 20 |
+
<bxRecommendations>
|
| 21 |
+
<title>Boxalino Recommendation</title>
|
| 22 |
+
</bxRecommendations>
|
| 23 |
+
</children>
|
| 24 |
+
</config>
|
| 25 |
+
</children>
|
| 26 |
+
</system>
|
| 27 |
+
</children>
|
| 28 |
+
</admin>
|
| 29 |
+
</resources>
|
| 30 |
+
</acl>
|
| 31 |
+
</config>
|
app/code/community/Boxalino/Intelligence/etc/config.xml
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0" encoding="UTF-8" ?>
|
| 2 |
+
|
| 3 |
+
<config>
|
| 4 |
+
<modules>
|
| 5 |
+
<Boxalino_Intelligence>
|
| 6 |
+
<version>2.14</version>
|
| 7 |
+
</Boxalino_Intelligence>
|
| 8 |
+
</modules>
|
| 9 |
+
|
| 10 |
+
<frontend>
|
| 11 |
+
<routers>
|
| 12 |
+
<catalogsearch>
|
| 13 |
+
<args>
|
| 14 |
+
<modules>
|
| 15 |
+
<Boxalino_Intelligence before="Mage_CatalogSearch">Boxalino_Intelligence</Boxalino_Intelligence>
|
| 16 |
+
</modules>
|
| 17 |
+
</args>
|
| 18 |
+
</catalogsearch>
|
| 19 |
+
<catalog>
|
| 20 |
+
<args>
|
| 21 |
+
<modules>
|
| 22 |
+
<Boxalino_Intelligence before="Mage_Catalog">Boxalino_Intelligence</Boxalino_Intelligence>
|
| 23 |
+
</modules>
|
| 24 |
+
</args>
|
| 25 |
+
</catalog>
|
| 26 |
+
</routers>
|
| 27 |
+
<layout>
|
| 28 |
+
<updates>
|
| 29 |
+
<intelligence>
|
| 30 |
+
<file>boxalino.xml</file>
|
| 31 |
+
</intelligence>
|
| 32 |
+
</updates>
|
| 33 |
+
</layout>
|
| 34 |
+
<events>
|
| 35 |
+
<checkout_cart_product_add_after>
|
| 36 |
+
<observers>
|
| 37 |
+
<intelligence_cart_add>
|
| 38 |
+
<class>Boxalino_Intelligence_Model_Observer</class>
|
| 39 |
+
<method>onProductAddedToCart</method>
|
| 40 |
+
</intelligence_cart_add>
|
| 41 |
+
</observers>
|
| 42 |
+
</checkout_cart_product_add_after>
|
| 43 |
+
<checkout_onepage_controller_success_action>
|
| 44 |
+
<observers>
|
| 45 |
+
<intelligence_order_success>
|
| 46 |
+
<class>Boxalino_Intelligence_Model_Observer</class>
|
| 47 |
+
<method>onOrderSuccessPageView</method>
|
| 48 |
+
</intelligence_order_success>
|
| 49 |
+
</observers>
|
| 50 |
+
</checkout_onepage_controller_success_action>
|
| 51 |
+
<checkout_multishipping_controller_success_action>
|
| 52 |
+
<observers>
|
| 53 |
+
<intelligence_order_success>
|
| 54 |
+
<class>Boxalino_Intelligence_Model_Observer</class>
|
| 55 |
+
<method>onOrderSuccessPageView</method>
|
| 56 |
+
</intelligence_order_success>
|
| 57 |
+
</observers>
|
| 58 |
+
</checkout_multishipping_controller_success_action>
|
| 59 |
+
<catalog_controller_product_view>
|
| 60 |
+
<observers>
|
| 61 |
+
<intelligence_product_view>
|
| 62 |
+
<class>Boxalino_Intelligence_Model_Observer</class>
|
| 63 |
+
<method>onProductPageView</method>
|
| 64 |
+
</intelligence_product_view>
|
| 65 |
+
</observers>
|
| 66 |
+
</catalog_controller_product_view>
|
| 67 |
+
<catalog_controller_category_init_after>
|
| 68 |
+
<observers>
|
| 69 |
+
<intelligence_category_view>
|
| 70 |
+
<class>Boxalino_Intelligence_Model_Observer</class>
|
| 71 |
+
<method>onCategoryPageView</method>
|
| 72 |
+
</intelligence_category_view>
|
| 73 |
+
</observers>
|
| 74 |
+
</catalog_controller_category_init_after>
|
| 75 |
+
<customer_login>
|
| 76 |
+
<observers>
|
| 77 |
+
<intelligence_login>
|
| 78 |
+
<class>Boxalino_Intelligence_Model_Observer</class>
|
| 79 |
+
<method>onLogin</method>
|
| 80 |
+
</intelligence_login>
|
| 81 |
+
</observers>
|
| 82 |
+
</customer_login>
|
| 83 |
+
</events>
|
| 84 |
+
</frontend>
|
| 85 |
+
<global>
|
| 86 |
+
<index>
|
| 87 |
+
<indexer>
|
| 88 |
+
<boxalinoexporter_indexer>
|
| 89 |
+
<model>intelligence/indexer</model>
|
| 90 |
+
</boxalinoexporter_indexer>
|
| 91 |
+
<boxalinoexporter_delta>
|
| 92 |
+
<model>intelligence/delta</model>
|
| 93 |
+
</boxalinoexporter_delta>
|
| 94 |
+
</indexer>
|
| 95 |
+
</index>
|
| 96 |
+
|
| 97 |
+
<models>
|
| 98 |
+
<intelligence>
|
| 99 |
+
<class>Boxalino_Intelligence_Model</class>
|
| 100 |
+
</intelligence>
|
| 101 |
+
<catalog_resource>
|
| 102 |
+
<rewrite>
|
| 103 |
+
<product_collection>Boxalino_Intelligence_Model_Resource_Product_Collection</product_collection>
|
| 104 |
+
</rewrite>
|
| 105 |
+
</catalog_resource>
|
| 106 |
+
<intelligence>
|
| 107 |
+
<class>Boxalino_Intelligence_Model</class>
|
| 108 |
+
<resourceModel>boxalinoexporter_mysql4</resourceModel>
|
| 109 |
+
</intelligence>
|
| 110 |
+
<boxalinoexporter_mysql4>
|
| 111 |
+
<class>Boxalino_Intelligence_Model_Mysql4</class>
|
| 112 |
+
</boxalinoexporter_mysql4>
|
| 113 |
+
<widget>
|
| 114 |
+
<rewrite>
|
| 115 |
+
<template_filter>Boxalino_Intelligence_Model_Template_Filter</template_filter>
|
| 116 |
+
</rewrite>
|
| 117 |
+
</widget>
|
| 118 |
+
</models>
|
| 119 |
+
|
| 120 |
+
<helpers>
|
| 121 |
+
<intelligence>
|
| 122 |
+
<class>Boxalino_Intelligence_Helper</class>
|
| 123 |
+
</intelligence>
|
| 124 |
+
</helpers>
|
| 125 |
+
|
| 126 |
+
<blocks>
|
| 127 |
+
<boxalino>
|
| 128 |
+
<class>Boxalino_Intelligence_Block</class>
|
| 129 |
+
</boxalino>
|
| 130 |
+
<catalogsearch>
|
| 131 |
+
<rewrite>
|
| 132 |
+
<autocomplete>Boxalino_Intelligence_Block_Autocomplete</autocomplete>
|
| 133 |
+
<result>Boxalino_Intelligence_Block_Result</result>
|
| 134 |
+
<layer>Boxalino_Intelligence_Block_Layer</layer>
|
| 135 |
+
</rewrite>
|
| 136 |
+
</catalogsearch>
|
| 137 |
+
<catalog>
|
| 138 |
+
<rewrite>
|
| 139 |
+
<product_list>Boxalino_Intelligence_Block_Product_List</product_list>
|
| 140 |
+
<product_list_toolbar>Boxalino_Intelligence_Block_Product_List_Toolbar</product_list_toolbar>
|
| 141 |
+
<layer_view>Boxalino_Intelligence_Block_Layer_View</layer_view>
|
| 142 |
+
<layer_state>Boxalino_Intelligence_Block_Layer_State</layer_state>
|
| 143 |
+
<product_list_related>Boxalino_Intelligence_Block_Product_List_Related</product_list_related>
|
| 144 |
+
<product_list_upsell>Boxalino_Intelligence_Block_Product_List_Upsell</product_list_upsell>
|
| 145 |
+
</rewrite>
|
| 146 |
+
</catalog>
|
| 147 |
+
<checkout>
|
| 148 |
+
<rewrite>
|
| 149 |
+
<cart_crosssell>Boxalino_Intelligence_Block_Cart_Crosssell</cart_crosssell>
|
| 150 |
+
</rewrite>
|
| 151 |
+
</checkout>
|
| 152 |
+
</blocks>
|
| 153 |
+
</global>
|
| 154 |
+
|
| 155 |
+
<default>
|
| 156 |
+
<bxGeneral>
|
| 157 |
+
<general>
|
| 158 |
+
<enabled>1</enabled>
|
| 159 |
+
<dev>0</dev>
|
| 160 |
+
</general>
|
| 161 |
+
<advanced>
|
| 162 |
+
<thrift_timeout>2</thrift_timeout>
|
| 163 |
+
</advanced>
|
| 164 |
+
</bxGeneral>
|
| 165 |
+
<bxExporter>
|
| 166 |
+
<exporter>
|
| 167 |
+
<enabled>1</enabled>
|
| 168 |
+
</exporter>
|
| 169 |
+
<customers>
|
| 170 |
+
<enabled>1</enabled>
|
| 171 |
+
</customers>
|
| 172 |
+
<transactions>
|
| 173 |
+
<enabled>1</enabled>
|
| 174 |
+
</transactions>
|
| 175 |
+
<advanced>
|
| 176 |
+
<publish_configuration_changes>1</publish_configuration_changes>
|
| 177 |
+
</advanced>
|
| 178 |
+
</bxExporter>
|
| 179 |
+
<bxSearch>
|
| 180 |
+
<search>
|
| 181 |
+
<enabled>0</enabled>
|
| 182 |
+
</search>
|
| 183 |
+
<autocomplete>
|
| 184 |
+
<enabled>1</enabled>
|
| 185 |
+
<limit>7</limit>
|
| 186 |
+
<products_limit>1</products_limit>
|
| 187 |
+
</autocomplete>
|
| 188 |
+
<advanced>
|
| 189 |
+
<search_sub_phrases_limit>3</search_sub_phrases_limit>
|
| 190 |
+
</advanced>
|
| 191 |
+
</bxSearch>
|
| 192 |
+
<bxRecommendations>
|
| 193 |
+
<cart>
|
| 194 |
+
<status>1</status>
|
| 195 |
+
<min>3</min>
|
| 196 |
+
<max>3</max>
|
| 197 |
+
</cart>
|
| 198 |
+
<related>
|
| 199 |
+
<status>1</status>
|
| 200 |
+
<min>3</min>
|
| 201 |
+
<max>3</max>
|
| 202 |
+
</related>
|
| 203 |
+
<upsell>
|
| 204 |
+
<status>1</status>
|
| 205 |
+
<min>3</min>
|
| 206 |
+
<max>3</max>
|
| 207 |
+
</upsell>
|
| 208 |
+
</bxRecommendations>
|
| 209 |
+
</default>
|
| 210 |
+
</config>
|
app/code/community/Boxalino/Intelligence/etc/system.xml
ADDED
|
@@ -0,0 +1,947 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0"?>
|
| 2 |
+
|
| 3 |
+
<config>
|
| 4 |
+
<tabs>
|
| 5 |
+
<boxalino translate="label" module="intelligence">
|
| 6 |
+
<label>Boxalino Extension</label>
|
| 7 |
+
<sort_order>100</sort_order>
|
| 8 |
+
</boxalino>
|
| 9 |
+
</tabs>
|
| 10 |
+
<sections>
|
| 11 |
+
<bxGeneral translate="label" module="intelligence">
|
| 12 |
+
<label>General</label>
|
| 13 |
+
<tab>boxalino</tab>
|
| 14 |
+
<frontend_type>text</frontend_type>
|
| 15 |
+
<sort_order>1000</sort_order>
|
| 16 |
+
<show_in_default>1</show_in_default>
|
| 17 |
+
<show_in_website>1</show_in_website>
|
| 18 |
+
<show_in_store>1</show_in_store>
|
| 19 |
+
<groups>
|
| 20 |
+
<general translate="label">
|
| 21 |
+
<label>General</label>
|
| 22 |
+
<frontend_type>text</frontend_type>
|
| 23 |
+
<sort_order>10</sort_order>
|
| 24 |
+
<show_in_default>1</show_in_default>
|
| 25 |
+
<show_in_website>1</show_in_website>
|
| 26 |
+
<show_in_store>1</show_in_store>
|
| 27 |
+
<fields>
|
| 28 |
+
<enabled translate="label">
|
| 29 |
+
<label>Enable plugin</label>
|
| 30 |
+
<frontend_type>select</frontend_type>
|
| 31 |
+
<source_model>adminhtml/system_config_source_enabledisable</source_model>
|
| 32 |
+
<sort_order>1</sort_order>
|
| 33 |
+
<show_in_default>1</show_in_default>
|
| 34 |
+
<show_in_website>1</show_in_website>
|
| 35 |
+
<show_in_store>1</show_in_store>
|
| 36 |
+
<comment>Is the overall Boxalino plugin active (global switch)?</comment>
|
| 37 |
+
</enabled>
|
| 38 |
+
<account_name translate="label">
|
| 39 |
+
<label>Boxalino account name</label>
|
| 40 |
+
<frontend_type>text</frontend_type>
|
| 41 |
+
<sort_order>2</sort_order>
|
| 42 |
+
<show_in_default>1</show_in_default>
|
| 43 |
+
<show_in_website>1</show_in_website>
|
| 44 |
+
<show_in_store>1</show_in_store>
|
| 45 |
+
<validate>required-entry</validate>
|
| 46 |
+
<comment>Please request your account with credentials by contacting support@boxalino.com</comment>
|
| 47 |
+
</account_name>
|
| 48 |
+
<password translate="label">
|
| 49 |
+
<label>Boxalino password</label>
|
| 50 |
+
<frontend_type>password</frontend_type>
|
| 51 |
+
<sort_order>3</sort_order>
|
| 52 |
+
<show_in_default>1</show_in_default>
|
| 53 |
+
<show_in_website>1</show_in_website>
|
| 54 |
+
<show_in_store>1</show_in_store>
|
| 55 |
+
<validate>required-entry</validate>
|
| 56 |
+
<comment>Please request your account with credentials by contacting support@boxalino.com</comment>
|
| 57 |
+
</password>
|
| 58 |
+
<dev translate="label">
|
| 59 |
+
<label>Dev</label>
|
| 60 |
+
<frontend_type>select</frontend_type>
|
| 61 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
| 62 |
+
<sort_order>4</sort_order>
|
| 63 |
+
<show_in_default>1</show_in_default>
|
| 64 |
+
<show_in_website>1</show_in_website>
|
| 65 |
+
<show_in_store>1</show_in_store>
|
| 66 |
+
<comment>Is the account a development account or a production account? (Yes=DEV, No=PROD)</comment>
|
| 67 |
+
</dev>
|
| 68 |
+
<domain translate="label">
|
| 69 |
+
<label>Domain</label>
|
| 70 |
+
<frontend_type>text</frontend_type>
|
| 71 |
+
<sort_order>5</sort_order>
|
| 72 |
+
<show_in_default>1</show_in_default>
|
| 73 |
+
<show_in_website>1</show_in_website>
|
| 74 |
+
<show_in_store>1</show_in_store>
|
| 75 |
+
<comment>What is your domain (e.g.: www.myshop.com)? Used to store cookie information about session id and visitor id.</comment>
|
| 76 |
+
</domain>
|
| 77 |
+
</fields>
|
| 78 |
+
</general>
|
| 79 |
+
<tracker translate="label">
|
| 80 |
+
<label>Tracker</label>
|
| 81 |
+
<frontend_type>text</frontend_type>
|
| 82 |
+
<sort_order>20</sort_order>
|
| 83 |
+
<show_in_default>1</show_in_default>
|
| 84 |
+
<show_in_website>1</show_in_website>
|
| 85 |
+
<show_in_store>1</show_in_store>
|
| 86 |
+
<fields>
|
| 87 |
+
<enabled translate="label">
|
| 88 |
+
<label>Enable tracker</label>
|
| 89 |
+
<frontend_type>select</frontend_type>
|
| 90 |
+
<source_model>adminhtml/system_config_source_enabledisable</source_model>
|
| 91 |
+
<sort_order>1</sort_order>
|
| 92 |
+
<show_in_default>1</show_in_default>
|
| 93 |
+
<show_in_website>1</show_in_website>
|
| 94 |
+
<show_in_store>1</show_in_store>
|
| 95 |
+
<comment>Is the JavaScript tracker enabled?</comment>
|
| 96 |
+
</enabled>
|
| 97 |
+
</fields>
|
| 98 |
+
</tracker>
|
| 99 |
+
<advanced>
|
| 100 |
+
<label>Advanced</label>
|
| 101 |
+
<frontend_type>text</frontend_type>
|
| 102 |
+
<sort_order>30</sort_order>
|
| 103 |
+
<show_in_default>1</show_in_default>
|
| 104 |
+
<show_in_website>1</show_in_website>
|
| 105 |
+
<show_in_store>1</show_in_store>
|
| 106 |
+
<fields>
|
| 107 |
+
<host translate="label">
|
| 108 |
+
<label>Host</label>
|
| 109 |
+
<frontend_type>text</frontend_type>
|
| 110 |
+
<sort_order>1</sort_order>
|
| 111 |
+
<show_in_default>1</show_in_default>
|
| 112 |
+
<show_in_website>1</show_in_website>
|
| 113 |
+
<show_in_store>1</show_in_store>
|
| 114 |
+
<comment>Optional: uses default value "cdn.bx-cloud.com" if left empty</comment>
|
| 115 |
+
</host>
|
| 116 |
+
<p13n_username>
|
| 117 |
+
<label>P13n Username</label>
|
| 118 |
+
<frontend_type>text</frontend_type>
|
| 119 |
+
<sort_order>2</sort_order>
|
| 120 |
+
<show_in_default>1</show_in_default>
|
| 121 |
+
<show_in_website>1</show_in_website>
|
| 122 |
+
<show_in_store>1</show_in_store>
|
| 123 |
+
<comment>Optional: uses default credentials if left empty</comment>
|
| 124 |
+
</p13n_username>
|
| 125 |
+
<p13n_password>
|
| 126 |
+
<label>P13n Password</label>
|
| 127 |
+
<frontend_type>text</frontend_type>
|
| 128 |
+
<sort_order>3</sort_order>
|
| 129 |
+
<show_in_default>1</show_in_default>
|
| 130 |
+
<show_in_website>1</show_in_website>
|
| 131 |
+
<show_in_store>1</show_in_store>
|
| 132 |
+
<comment>Optional: uses default credentials if left empty</comment>
|
| 133 |
+
</p13n_password>
|
| 134 |
+
<language>
|
| 135 |
+
<label>Overwrite language</label>
|
| 136 |
+
<frontend_type>text</frontend_type>
|
| 137 |
+
<sort_order>4</sort_order>
|
| 138 |
+
<show_in_default>1</show_in_default>
|
| 139 |
+
<show_in_website>1</show_in_website>
|
| 140 |
+
<show_in_store>1</show_in_store>
|
| 141 |
+
<comment>Optional: uses store's "general/locale/code" value by default</comment>
|
| 142 |
+
</language>
|
| 143 |
+
<username>
|
| 144 |
+
<label>Boxalino User name</label>
|
| 145 |
+
<frontend_type>text</frontend_type>
|
| 146 |
+
<sort_order>5</sort_order>
|
| 147 |
+
<show_in_default>1</show_in_default>
|
| 148 |
+
<show_in_website>1</show_in_website>
|
| 149 |
+
<show_in_store>1</show_in_store>
|
| 150 |
+
<comment>Optional: leave empty to use account name as username (typical case)</comment>
|
| 151 |
+
</username>
|
| 152 |
+
<entity_id>
|
| 153 |
+
<label>Id field name</label>
|
| 154 |
+
<frontend_type>text</frontend_type>
|
| 155 |
+
<sort_order>6</sort_order>
|
| 156 |
+
<show_in_default>1</show_in_default>
|
| 157 |
+
<show_in_website>1</show_in_website>
|
| 158 |
+
<show_in_store>1</show_in_store>
|
| 159 |
+
<comment>Optional: specify special field name for search and recommendation grouping</comment>
|
| 160 |
+
</entity_id>
|
| 161 |
+
<additional_fields>
|
| 162 |
+
<label>Returned fields</label>
|
| 163 |
+
<frontend_type>text</frontend_type>
|
| 164 |
+
<sort_order>7</sort_order>
|
| 165 |
+
<show_in_default>1</show_in_default>
|
| 166 |
+
<show_in_website>1</show_in_website>
|
| 167 |
+
<show_in_store>1</show_in_store>
|
| 168 |
+
<comment><![CDATA[ Optional: Write here comma-separated names of fields in Boxalino response Colon separate option:
|
| 169 |
+
<br>-global (without language version)<br>-local (with language version)]]></comment>
|
| 170 |
+
</additional_fields>
|
| 171 |
+
<thrift_timeout>
|
| 172 |
+
<label>Timeout limit to our server</label>
|
| 173 |
+
<frontend_type>text</frontend_type>
|
| 174 |
+
<sort_order>8</sort_order>
|
| 175 |
+
<show_in_default>1</show_in_default>
|
| 176 |
+
<show_in_website>1</show_in_website>
|
| 177 |
+
<show_in_store>1</show_in_store>
|
| 178 |
+
<comment>Optional: default value is 2 seconds and should normally not be changed.</comment>
|
| 179 |
+
</thrift_timeout>
|
| 180 |
+
</fields>
|
| 181 |
+
</advanced>
|
| 182 |
+
</groups>
|
| 183 |
+
</bxGeneral>
|
| 184 |
+
<bxExporter translate="label" module="intelligence">
|
| 185 |
+
<label>Exporter</label>
|
| 186 |
+
<tab>boxalino</tab>
|
| 187 |
+
<frontend_type>text</frontend_type>
|
| 188 |
+
<sort_order>2000</sort_order>
|
| 189 |
+
<show_in_default>1</show_in_default>
|
| 190 |
+
<show_in_website>1</show_in_website>
|
| 191 |
+
<show_in_store>1</show_in_store>
|
| 192 |
+
<groups>
|
| 193 |
+
<exporter>
|
| 194 |
+
<label>General</label>
|
| 195 |
+
<frontend_type>text</frontend_type>
|
| 196 |
+
<sort_order>10</sort_order>
|
| 197 |
+
<show_in_default>1</show_in_default>
|
| 198 |
+
<show_in_website>1</show_in_website>
|
| 199 |
+
<show_in_store>1</show_in_store>
|
| 200 |
+
<fields>
|
| 201 |
+
<enabled translate="label">
|
| 202 |
+
<label>Enable export</label>
|
| 203 |
+
<frontend_type>select</frontend_type>
|
| 204 |
+
<source_model>adminhtml/system_config_source_enabledisable</source_model>
|
| 205 |
+
<sort_order>1</sort_order>
|
| 206 |
+
<show_in_default>1</show_in_default>
|
| 207 |
+
<show_in_website>1</show_in_website>
|
| 208 |
+
<show_in_store>1</show_in_store>
|
| 209 |
+
</enabled>
|
| 210 |
+
</fields>
|
| 211 |
+
</exporter>
|
| 212 |
+
<products>
|
| 213 |
+
<label>Products</label>
|
| 214 |
+
<frontend_type>text</frontend_type>
|
| 215 |
+
<sort_order>20</sort_order>
|
| 216 |
+
<show_in_default>1</show_in_default>
|
| 217 |
+
<show_in_website>1</show_in_website>
|
| 218 |
+
<show_in_store>1</show_in_store>
|
| 219 |
+
<fields>
|
| 220 |
+
<include_properties translate="label">
|
| 221 |
+
<label>List of product properties to include in export</label>
|
| 222 |
+
<frontend_type>text</frontend_type>
|
| 223 |
+
<sort_order>1</sort_order>
|
| 224 |
+
<show_in_default>1</show_in_default>
|
| 225 |
+
<show_in_website>1</show_in_website>
|
| 226 |
+
<show_in_store>1</show_in_store>
|
| 227 |
+
<comment>
|
| 228 |
+
Optional: list of product properties separated by ','; if left empty,
|
| 229 |
+
then all properties will be exported except the ones defined as excluded properties
|
| 230 |
+
(next parameter)
|
| 231 |
+
</comment>
|
| 232 |
+
</include_properties>
|
| 233 |
+
<exclude_properties translate="label">
|
| 234 |
+
<label>List of product properties to exclude from export</label>
|
| 235 |
+
<frontend_type>text</frontend_type>
|
| 236 |
+
<sort_order>2</sort_order>
|
| 237 |
+
<show_in_default>1</show_in_default>
|
| 238 |
+
<show_in_website>1</show_in_website>
|
| 239 |
+
<show_in_store>1</show_in_store>
|
| 240 |
+
<comment>
|
| 241 |
+
Optional: list of product properties separated by ','; if left empty,
|
| 242 |
+
then all properties will be exported, this field is ignored if the list of
|
| 243 |
+
product properties to include is not empty.
|
| 244 |
+
</comment>
|
| 245 |
+
</exclude_properties>
|
| 246 |
+
<export_images translate="label">
|
| 247 |
+
<label>Enable export product images</label>
|
| 248 |
+
<frontend_type>select</frontend_type>
|
| 249 |
+
<source_model>adminhtml/system_config_source_enabledisable</source_model>
|
| 250 |
+
<sort_order>3</sort_order>
|
| 251 |
+
<show_in_default>1</show_in_default>
|
| 252 |
+
<show_in_website>1</show_in_website>
|
| 253 |
+
<show_in_store>1</show_in_store>
|
| 254 |
+
<comment>
|
| 255 |
+
Optional: Export image and thumbnail image urls (not required if standard usage
|
| 256 |
+
of search and recommendations in Magento, as Magento renders the images itself). If
|
| 257 |
+
activated, makes export slower.
|
| 258 |
+
</comment>
|
| 259 |
+
</export_images>
|
| 260 |
+
<export_url translate="label">
|
| 261 |
+
<label>Enable export product urls</label>
|
| 262 |
+
<frontend_type>select</frontend_type>
|
| 263 |
+
<source_model>adminhtml/system_config_source_enabledisable</source_model>
|
| 264 |
+
<sort_order>4</sort_order>
|
| 265 |
+
<show_in_default>1</show_in_default>
|
| 266 |
+
<show_in_website>1</show_in_website>
|
| 267 |
+
<show_in_store>1</show_in_store>
|
| 268 |
+
<comment>
|
| 269 |
+
Optional: Export product urls (not required if standard usage of search and
|
| 270 |
+
recommendations in Magento, as Magento renders the url itself).. If activated,
|
| 271 |
+
makes export slower.
|
| 272 |
+
</comment>
|
| 273 |
+
</export_url>
|
| 274 |
+
</fields>
|
| 275 |
+
</products>
|
| 276 |
+
<customers>
|
| 277 |
+
<label>Customers</label>
|
| 278 |
+
<frontend_type>text</frontend_type>
|
| 279 |
+
<sort_order>30</sort_order>
|
| 280 |
+
<show_in_default>1</show_in_default>
|
| 281 |
+
<show_in_website>1</show_in_website>
|
| 282 |
+
<show_in_store>1</show_in_store>
|
| 283 |
+
<fields>
|
| 284 |
+
<enabled translate="label">
|
| 285 |
+
<label>Enable export</label>
|
| 286 |
+
<frontend_type>select</frontend_type>
|
| 287 |
+
<source_model>adminhtml/system_config_source_enabledisable</source_model>
|
| 288 |
+
<sort_order>1</sort_order>
|
| 289 |
+
<show_in_default>1</show_in_default>
|
| 290 |
+
<show_in_website>1</show_in_website>
|
| 291 |
+
<show_in_store>1</show_in_store>
|
| 292 |
+
</enabled>
|
| 293 |
+
<include_properties translate="label">
|
| 294 |
+
<label>List of customer properties to include in export</label>
|
| 295 |
+
<frontend_type>text</frontend_type>
|
| 296 |
+
<sort_order>2</sort_order>
|
| 297 |
+
<show_in_default>1</show_in_default>
|
| 298 |
+
<show_in_website>1</show_in_website>
|
| 299 |
+
<show_in_store>1</show_in_store>
|
| 300 |
+
<comment>
|
| 301 |
+
Optional: list of customer properties separated by ','; if left empty,
|
| 302 |
+
then all properties will be exported except the ones defined as excluded properties
|
| 303 |
+
(next parameter)
|
| 304 |
+
</comment>
|
| 305 |
+
</include_properties>
|
| 306 |
+
<exclude_properties translate="label">
|
| 307 |
+
<label>List of customer properties to exclude from export</label>
|
| 308 |
+
<frontend_type>text</frontend_type>
|
| 309 |
+
<sort_order>3</sort_order>
|
| 310 |
+
<show_in_default>1</show_in_default>
|
| 311 |
+
<show_in_website>1</show_in_website>
|
| 312 |
+
<show_in_store>1</show_in_store>
|
| 313 |
+
<comment>
|
| 314 |
+
Optional: list of customer properties separated by ','; if left empty, then all
|
| 315 |
+
properties will be exported, this field is ignored if the list of customer properties
|
| 316 |
+
to include is not empty.
|
| 317 |
+
</comment>
|
| 318 |
+
</exclude_properties>
|
| 319 |
+
</fields>
|
| 320 |
+
</customers>
|
| 321 |
+
<transactions>
|
| 322 |
+
<label>Transaction</label>
|
| 323 |
+
<frontend_type>text</frontend_type>
|
| 324 |
+
<sort_order>40</sort_order>
|
| 325 |
+
<show_in_default>1</show_in_default>
|
| 326 |
+
<show_in_website>1</show_in_website>
|
| 327 |
+
<show_in_store>1</show_in_store>
|
| 328 |
+
<fields>
|
| 329 |
+
<enabled translate="label">
|
| 330 |
+
<label>Enable export</label>
|
| 331 |
+
<frontend_type>select</frontend_type>
|
| 332 |
+
<source_model>adminhtml/system_config_source_enabledisable</source_model>
|
| 333 |
+
<sort_order>1</sort_order>
|
| 334 |
+
<show_in_default>1</show_in_default>
|
| 335 |
+
<show_in_website>1</show_in_website>
|
| 336 |
+
<show_in_store>1</show_in_store>
|
| 337 |
+
</enabled>
|
| 338 |
+
<include_properties translate="label">
|
| 339 |
+
<label>List of transaction properties to include in export</label>
|
| 340 |
+
<frontend_type>text</frontend_type>
|
| 341 |
+
<sort_order>2</sort_order>
|
| 342 |
+
<show_in_default>1</show_in_default>
|
| 343 |
+
<show_in_website>1</show_in_website>
|
| 344 |
+
<show_in_store>1</show_in_store>
|
| 345 |
+
<comment>
|
| 346 |
+
Optional: list of transaction properties separated by ','; if left empty,
|
| 347 |
+
then all properties will be exported except the ones defined as excluded properties
|
| 348 |
+
(next parameter)
|
| 349 |
+
</comment>
|
| 350 |
+
</include_properties>
|
| 351 |
+
<exclude_properties translate="label">
|
| 352 |
+
<label>List of transaction properties to exclude from export</label>
|
| 353 |
+
<frontend_type>text</frontend_type>
|
| 354 |
+
<sort_order>3</sort_order>
|
| 355 |
+
<show_in_default>1</show_in_default>
|
| 356 |
+
<show_in_website>1</show_in_website>
|
| 357 |
+
<show_in_store>1</show_in_store>
|
| 358 |
+
<comment>
|
| 359 |
+
Optional: list of transaction properties separated by ','; if left empty, then all
|
| 360 |
+
properties will be exported, this field is ignored if the list of transaction properties
|
| 361 |
+
to include is not empty.
|
| 362 |
+
</comment>
|
| 363 |
+
</exclude_properties>
|
| 364 |
+
</fields>
|
| 365 |
+
</transactions>
|
| 366 |
+
<advanced>
|
| 367 |
+
<label>Advanced</label>
|
| 368 |
+
<frontend_type>text</frontend_type>
|
| 369 |
+
<sort_order>50</sort_order>
|
| 370 |
+
<show_in_default>1</show_in_default>
|
| 371 |
+
<show_in_website>1</show_in_website>
|
| 372 |
+
<show_in_store>1</show_in_store>
|
| 373 |
+
<fields>
|
| 374 |
+
<export_server translate="label">
|
| 375 |
+
<label>Boxalino export server</label>
|
| 376 |
+
<frontend_type>text</frontend_type>
|
| 377 |
+
<sort_order>1</sort_order>
|
| 378 |
+
<show_in_default>1</show_in_default>
|
| 379 |
+
<show_in_website>1</show_in_website>
|
| 380 |
+
<show_in_store>1</show_in_store>
|
| 381 |
+
<comment>Optional: http://di1.bx-cloud.com by default if left empty</comment>
|
| 382 |
+
</export_server>
|
| 383 |
+
<publish_configuration_changes translate="label">
|
| 384 |
+
<label>Publish configuration changes automatically</label>
|
| 385 |
+
<frontend_type>select</frontend_type>
|
| 386 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
| 387 |
+
<sort_order>2</sort_order>
|
| 388 |
+
<show_in_default>1</show_in_default>
|
| 389 |
+
<show_in_website>1</show_in_website>
|
| 390 |
+
<show_in_store>1</show_in_store>
|
| 391 |
+
<comment>
|
| 392 |
+
True by default. Any changes in product/customers/transaction properties will
|
| 393 |
+
be automatically validated. For safety, it is recommended to de-activate this option
|
| 394 |
+
once in production to make sure no unwanted changes are automatically published.
|
| 395 |
+
However, if not activated, changes in the configuration will not be considered until
|
| 396 |
+
published otherwise and, in the case of property deletions, the data sync might fail
|
| 397 |
+
until the changes are published. Publishing of the configuration can be done by
|
| 398 |
+
re-activating this option and running a full data sync again, or by publishing the
|
| 399 |
+
configuration directly in Boxalino Data Intelligence web-admin.
|
| 400 |
+
</comment>
|
| 401 |
+
</publish_configuration_changes>
|
| 402 |
+
</fields>
|
| 403 |
+
</advanced>
|
| 404 |
+
</groups>
|
| 405 |
+
</bxExporter>
|
| 406 |
+
|
| 407 |
+
<bxSearch translate="label" module="intelligence">
|
| 408 |
+
<label>Search - Navigation</label>
|
| 409 |
+
<tab>boxalino</tab>
|
| 410 |
+
<frontend_type>text</frontend_type>
|
| 411 |
+
<sort_order>3000</sort_order>
|
| 412 |
+
<show_in_default>1</show_in_default>
|
| 413 |
+
<show_in_website>1</show_in_website>
|
| 414 |
+
<show_in_store>1</show_in_store>
|
| 415 |
+
<groups>
|
| 416 |
+
<search>
|
| 417 |
+
<label>Search</label>
|
| 418 |
+
<frontend_type>text</frontend_type>
|
| 419 |
+
<sort_order>10</sort_order>
|
| 420 |
+
<show_in_default>1</show_in_default>
|
| 421 |
+
<show_in_website>1</show_in_website>
|
| 422 |
+
<show_in_store>1</show_in_store>
|
| 423 |
+
<fields>
|
| 424 |
+
<enabled tranlate="label">
|
| 425 |
+
<label>Enable search</label>
|
| 426 |
+
<frontend_type>select</frontend_type>
|
| 427 |
+
<source_model>adminhtml/system_config_source_enabledisable</source_model>
|
| 428 |
+
<sort_order>1</sort_order>
|
| 429 |
+
<show_in_default>1</show_in_default>
|
| 430 |
+
<show_in_website>1</show_in_website>
|
| 431 |
+
<show_in_store>1</show_in_store>
|
| 432 |
+
<comment>Is Boxalino search active?</comment>
|
| 433 |
+
</enabled>
|
| 434 |
+
<filter tranlate="label">
|
| 435 |
+
<label>Enable boxalino filter layout</label>
|
| 436 |
+
<frontend_type>select</frontend_type>
|
| 437 |
+
<source_model>adminhtml/system_config_source_enabledisable</source_model>
|
| 438 |
+
<sort_order>2</sort_order>
|
| 439 |
+
<show_in_default>1</show_in_default>
|
| 440 |
+
<show_in_website>1</show_in_website>
|
| 441 |
+
<show_in_store>1</show_in_store>
|
| 442 |
+
<comment>Is Boxalino filter layout active?</comment>
|
| 443 |
+
</filter>
|
| 444 |
+
</fields>
|
| 445 |
+
</search>
|
| 446 |
+
<navigation>
|
| 447 |
+
<label>Navigation</label>
|
| 448 |
+
<frontend_type>text</frontend_type>
|
| 449 |
+
<sort_order>20</sort_order>
|
| 450 |
+
<show_in_default>1</show_in_default>
|
| 451 |
+
<show_in_website>1</show_in_website>
|
| 452 |
+
<show_in_store>1</show_in_store>
|
| 453 |
+
<fields>
|
| 454 |
+
<enabled tranlate="label">
|
| 455 |
+
<label>Enable navigation</label>
|
| 456 |
+
<frontend_type>select</frontend_type>
|
| 457 |
+
<source_model>adminhtml/system_config_source_enabledisable</source_model>
|
| 458 |
+
<sort_order>1</sort_order>
|
| 459 |
+
<show_in_default>1</show_in_default>
|
| 460 |
+
<show_in_website>1</show_in_website>
|
| 461 |
+
<show_in_store>1</show_in_store>
|
| 462 |
+
<comment>Is Boxalino navigation active?</comment>
|
| 463 |
+
</enabled>
|
| 464 |
+
<filter tranlate="label">
|
| 465 |
+
<label>Enable boxalino filter layout</label>
|
| 466 |
+
<frontend_type>select</frontend_type>
|
| 467 |
+
<source_model>adminhtml/system_config_source_enabledisable</source_model>
|
| 468 |
+
<sort_order>2</sort_order>
|
| 469 |
+
<show_in_default>1</show_in_default>
|
| 470 |
+
<show_in_website>1</show_in_website>
|
| 471 |
+
<show_in_store>1</show_in_store>
|
| 472 |
+
<comment>Is Boxalino filter layout active?</comment>
|
| 473 |
+
</filter>
|
| 474 |
+
</fields>
|
| 475 |
+
</navigation>
|
| 476 |
+
<left_facets>
|
| 477 |
+
<label>Left facets</label>
|
| 478 |
+
<frontend_type>text</frontend_type>
|
| 479 |
+
<sort_order>30</sort_order>
|
| 480 |
+
<show_in_default>1</show_in_default>
|
| 481 |
+
<show_in_website>1</show_in_website>
|
| 482 |
+
<show_in_store>1</show_in_store>
|
| 483 |
+
<fields>
|
| 484 |
+
<enabled tranlate="label">
|
| 485 |
+
<label>Enable left filter</label>
|
| 486 |
+
<frontend_type>select</frontend_type>
|
| 487 |
+
<source_model>adminhtml/system_config_source_enabledisable</source_model>
|
| 488 |
+
<sort_order>1</sort_order>
|
| 489 |
+
<show_in_default>1</show_in_default>
|
| 490 |
+
<show_in_website>1</show_in_website>
|
| 491 |
+
<show_in_store>1</show_in_store>
|
| 492 |
+
<comment>Is Boxalino left filter active?</comment>
|
| 493 |
+
</enabled>
|
| 494 |
+
<fields tranlate="label">
|
| 495 |
+
<label>Field names</label>
|
| 496 |
+
<frontend_type>text</frontend_type>
|
| 497 |
+
<sort_order>2</sort_order>
|
| 498 |
+
<show_in_default>1</show_in_default>
|
| 499 |
+
<show_in_website>1</show_in_website>
|
| 500 |
+
<show_in_store>1</show_in_store>
|
| 501 |
+
<comment>
|
| 502 |
+
The list of the field names of the facets to display on the left
|
| 503 |
+
(extends Magento Search Layered Navigation). Ordered list (from top to bottom)
|
| 504 |
+
of the field names to be used as left facets (values separated by ','). N.b.:
|
| 505 |
+
prefix "products_" is needed for all non-system fields (most of the fields except
|
| 506 |
+
price, discountedPrice and categories).N.b.: value for categories is "categories";
|
| 507 |
+
field name of price is "discountedPrice"
|
| 508 |
+
</comment>
|
| 509 |
+
</fields>
|
| 510 |
+
<labels tranlate="label">
|
| 511 |
+
<label>Facet labels</label>
|
| 512 |
+
<frontend_type>text</frontend_type>
|
| 513 |
+
<sort_order>3</sort_order>
|
| 514 |
+
<show_in_default>1</show_in_default>
|
| 515 |
+
<show_in_website>1</show_in_website>
|
| 516 |
+
<show_in_store>1</show_in_store>
|
| 517 |
+
<comment>
|
| 518 |
+
Label to be displayed on the store (should be set in each store language individually).
|
| 519 |
+
Ordered list matching the values of Field names (values separated by ',').
|
| 520 |
+
</comment>
|
| 521 |
+
</labels>
|
| 522 |
+
<types tranlate="label">
|
| 523 |
+
<label>Facet types</label>
|
| 524 |
+
<frontend_type>text</frontend_type>
|
| 525 |
+
<sort_order>4</sort_order>
|
| 526 |
+
<show_in_default>1</show_in_default>
|
| 527 |
+
<show_in_website>1</show_in_website>
|
| 528 |
+
<show_in_store>1</show_in_store>
|
| 529 |
+
<comment>
|
| 530 |
+
The type of the facet. Ordered list matching the values of Field names
|
| 531 |
+
(values separated by ','). Possible values: "list" (most common value, to be
|
| 532 |
+
used in most cases), "ranged" (e.g.: for "discountedPrice"), "hierarchical"
|
| 533 |
+
(e.g.: for "categories"), "numerical" (for numerical values)
|
| 534 |
+
</comment>
|
| 535 |
+
</types>
|
| 536 |
+
<orders tranlate="label">
|
| 537 |
+
<label>Ordering of facet values</label>
|
| 538 |
+
<frontend_type>text</frontend_type>
|
| 539 |
+
<sort_order>5</sort_order>
|
| 540 |
+
<show_in_default>1</show_in_default>
|
| 541 |
+
<show_in_website>1</show_in_website>
|
| 542 |
+
<show_in_store>1</show_in_store>
|
| 543 |
+
<comment>
|
| 544 |
+
<![CDATA[The ordering to sort the values in a facet. Ordered list matching the values
|
| 545 |
+
of Field names (values separated by ',').<br />0 = "order by count values from
|
| 546 |
+
biggest to smallest"<br />1 = "order alphabetically the values from A to Z"<br />2 =
|
| 547 |
+
"order by Magento categorization" (only for category)]]>
|
| 548 |
+
</comment>
|
| 549 |
+
</orders>
|
| 550 |
+
<position tranlate="label">
|
| 551 |
+
<label>Position of facet values</label>
|
| 552 |
+
<frontend_type>text</frontend_type>
|
| 553 |
+
<sort_order>6</sort_order>
|
| 554 |
+
<show_in_default>1</show_in_default>
|
| 555 |
+
<show_in_website>1</show_in_website>
|
| 556 |
+
<show_in_store>1</show_in_store>
|
| 557 |
+
<comment>
|
| 558 |
+
<![CDATA[The position of the facet appearing in the filter. Ordered list matching
|
| 559 |
+
the values of Field names (values separated by ',').<br />If the position overlaps with
|
| 560 |
+
other attributes defined in magento, the position is determined alphabetical.]]>
|
| 561 |
+
</comment>
|
| 562 |
+
</position>
|
| 563 |
+
</fields>
|
| 564 |
+
</left_facets>
|
| 565 |
+
<top_facet>
|
| 566 |
+
<label>Top facet</label>
|
| 567 |
+
<frontend_type>text</frontend_type>
|
| 568 |
+
<sort_order>40</sort_order>
|
| 569 |
+
<show_in_default>1</show_in_default>
|
| 570 |
+
<show_in_website>1</show_in_website>
|
| 571 |
+
<show_in_store>1</show_in_store>
|
| 572 |
+
<fields>
|
| 573 |
+
<enabled tranlate="label">
|
| 574 |
+
<label>Enable top filter</label>
|
| 575 |
+
<frontend_type>select</frontend_type>
|
| 576 |
+
<source_model>adminhtml/system_config_source_enabledisable</source_model>
|
| 577 |
+
<sort_order>1</sort_order>
|
| 578 |
+
<show_in_default>1</show_in_default>
|
| 579 |
+
<show_in_website>1</show_in_website>
|
| 580 |
+
<show_in_store>1</show_in_store>
|
| 581 |
+
<comment>Is Boxalino left filter active?</comment>
|
| 582 |
+
</enabled>
|
| 583 |
+
<field tranlate="label">
|
| 584 |
+
<label>Field name</label>
|
| 585 |
+
<frontend_type>text</frontend_type>
|
| 586 |
+
<sort_order>2</sort_order>
|
| 587 |
+
<show_in_default>1</show_in_default>
|
| 588 |
+
<show_in_website>1</show_in_website>
|
| 589 |
+
<show_in_store>1</show_in_store>
|
| 590 |
+
<comment>
|
| 591 |
+
Optional: display a list of filter values on top of the search results (typically
|
| 592 |
+
"value-oriented" facets with icons like: "in discount", "new", "top ranked", etc.).
|
| 593 |
+
N.b.: prefix "products_" is needed for all non-system fields (most of the fields
|
| 594 |
+
except price, discountedPrice and categories)
|
| 595 |
+
</comment>
|
| 596 |
+
</field>
|
| 597 |
+
<order tranlate="label">
|
| 598 |
+
<label>Ordering of facet values</label>
|
| 599 |
+
<frontend_type>text</frontend_type>
|
| 600 |
+
<sort_order>3</sort_order>
|
| 601 |
+
<show_in_default>1</show_in_default>
|
| 602 |
+
<show_in_website>1</show_in_website>
|
| 603 |
+
<show_in_store>1</show_in_store>
|
| 604 |
+
<comment>
|
| 605 |
+
<![CDATA[The ordering to sort the values in a facet.<br />0 = "order by count values
|
| 606 |
+
from biggest to smallest"<br />1 = "order alphabetically the values from A to Z"]]>
|
| 607 |
+
</comment>
|
| 608 |
+
</order>
|
| 609 |
+
</fields>
|
| 610 |
+
</top_facet>
|
| 611 |
+
<autocomplete>
|
| 612 |
+
<label>Autocomplete</label>
|
| 613 |
+
<frontend_type>text</frontend_type>
|
| 614 |
+
<sort_order>50</sort_order>
|
| 615 |
+
<show_in_default>1</show_in_default>
|
| 616 |
+
<show_in_website>1</show_in_website>
|
| 617 |
+
<show_in_store>1</show_in_store>
|
| 618 |
+
<fields>
|
| 619 |
+
<enabled tranlate="label">
|
| 620 |
+
<label>Enable autocomplete</label>
|
| 621 |
+
<frontend_type>select</frontend_type>
|
| 622 |
+
<source_model>adminhtml/system_config_source_enabledisable</source_model>
|
| 623 |
+
<sort_order>1</sort_order>
|
| 624 |
+
<show_in_default>1</show_in_default>
|
| 625 |
+
<show_in_website>1</show_in_website>
|
| 626 |
+
<show_in_store>1</show_in_store>
|
| 627 |
+
<comment>Is Boxalino search as you type (autocomplete) active?</comment>
|
| 628 |
+
</enabled>
|
| 629 |
+
<limit tranlate="label">
|
| 630 |
+
<label>Limit of textual suggestions</label>
|
| 631 |
+
<frontend_type>text</frontend_type>
|
| 632 |
+
<sort_order>2</sort_order>
|
| 633 |
+
<show_in_default>1</show_in_default>
|
| 634 |
+
<show_in_website>1</show_in_website>
|
| 635 |
+
<show_in_store>1</show_in_store>
|
| 636 |
+
<comment>
|
| 637 |
+
Maximum number of search textual suggestions to display under the search bar
|
| 638 |
+
while the user is typing
|
| 639 |
+
</comment>
|
| 640 |
+
</limit>
|
| 641 |
+
<products_limit tranlate="label">
|
| 642 |
+
<label>Limit of product suggestions</label>
|
| 643 |
+
<frontend_type>text</frontend_type>
|
| 644 |
+
<sort_order>3</sort_order>
|
| 645 |
+
<show_in_default>1</show_in_default>
|
| 646 |
+
<show_in_website>1</show_in_website>
|
| 647 |
+
<show_in_store>1</show_in_store>
|
| 648 |
+
<comment>
|
| 649 |
+
Maximum number of product suggestions to display under the search bar
|
| 650 |
+
while the user is typing
|
| 651 |
+
</comment>
|
| 652 |
+
</products_limit>
|
| 653 |
+
</fields>
|
| 654 |
+
</autocomplete>
|
| 655 |
+
<advanced>
|
| 656 |
+
<label>Advanced</label>
|
| 657 |
+
<frontend_type>text</frontend_type>
|
| 658 |
+
<sort_order>60</sort_order>
|
| 659 |
+
<show_in_default>1</show_in_default>
|
| 660 |
+
<show_in_website>1</show_in_website>
|
| 661 |
+
<show_in_store>1</show_in_store>
|
| 662 |
+
<fields>
|
| 663 |
+
<search_choice_id tranlate="label">
|
| 664 |
+
<label>Search choice ID</label>
|
| 665 |
+
<frontend_type>text</frontend_type>
|
| 666 |
+
<sort_order>1</sort_order>
|
| 667 |
+
<show_in_default>1</show_in_default>
|
| 668 |
+
<show_in_website>1</show_in_website>
|
| 669 |
+
<show_in_store>1</show_in_store>
|
| 670 |
+
<comment>Optional: default value is "search" and should normally not be changed</comment>
|
| 671 |
+
</search_choice_id>
|
| 672 |
+
<autocomplete_choice_id tranlate="label">
|
| 673 |
+
<label>Autocomplete choice ID</label>
|
| 674 |
+
<frontend_type>text</frontend_type>
|
| 675 |
+
<sort_order>2</sort_order>
|
| 676 |
+
<show_in_default>1</show_in_default>
|
| 677 |
+
<show_in_website>1</show_in_website>
|
| 678 |
+
<show_in_store>1</show_in_store>
|
| 679 |
+
<comment>
|
| 680 |
+
Optional: default value is "autocomplete" and should normally not be changed
|
| 681 |
+
</comment>
|
| 682 |
+
</autocomplete_choice_id>
|
| 683 |
+
<navigation_choice_id tranlate="label">
|
| 684 |
+
<label>Navigation choice ID</label>
|
| 685 |
+
<frontend_type>text</frontend_type>
|
| 686 |
+
<sort_order>3</sort_order>
|
| 687 |
+
<show_in_default>1</show_in_default>
|
| 688 |
+
<show_in_website>1</show_in_website>
|
| 689 |
+
<show_in_store>1</show_in_store>
|
| 690 |
+
<comment>
|
| 691 |
+
Optional: default value is "navigation" and should normally not be changed
|
| 692 |
+
</comment>
|
| 693 |
+
</navigation_choice_id>
|
| 694 |
+
<search_sub_phrases_limit tranlate="label">
|
| 695 |
+
<label>Search limit for sub-phrases</label>
|
| 696 |
+
<frontend_type>text</frontend_type>
|
| 697 |
+
<sort_order>4</sort_order>
|
| 698 |
+
<show_in_default>1</show_in_default>
|
| 699 |
+
<show_in_website>1</show_in_website>
|
| 700 |
+
<show_in_store>1</show_in_store>
|
| 701 |
+
<comment>
|
| 702 |
+
Optional: default value is 3 and should normally not be changed.
|
| 703 |
+
</comment>
|
| 704 |
+
</search_sub_phrases_limit>
|
| 705 |
+
</fields>
|
| 706 |
+
</advanced>
|
| 707 |
+
</groups>
|
| 708 |
+
</bxSearch>
|
| 709 |
+
<bxRecommendations translate="label" module="intelligence">
|
| 710 |
+
<label>Recommendation</label>
|
| 711 |
+
<tab>boxalino</tab>
|
| 712 |
+
<frontend_type>text</frontend_type>
|
| 713 |
+
<sort_order>4000</sort_order>
|
| 714 |
+
<show_in_default>1</show_in_default>
|
| 715 |
+
<show_in_website>1</show_in_website>
|
| 716 |
+
<show_in_store>1</show_in_store>
|
| 717 |
+
<groups>
|
| 718 |
+
<cart>
|
| 719 |
+
<label>Cart recommendation</label>
|
| 720 |
+
<frontend_type>text</frontend_type>
|
| 721 |
+
<sort_order>10</sort_order>
|
| 722 |
+
<show_in_default>1</show_in_default>
|
| 723 |
+
<show_in_website>1</show_in_website>
|
| 724 |
+
<show_in_store>1</show_in_store>
|
| 725 |
+
<comment><![CDATA[ Widget configuration for recommendation on basket page. ]]></comment>
|
| 726 |
+
<fields>
|
| 727 |
+
<status tranlate="label">
|
| 728 |
+
<label>Widgets enabled</label>
|
| 729 |
+
<frontend_type>select</frontend_type>
|
| 730 |
+
<source_model>adminhtml/system_config_source_enabledisable</source_model>
|
| 731 |
+
<sort_order>1</sort_order>
|
| 732 |
+
<show_in_default>1</show_in_default>
|
| 733 |
+
<show_in_website>1</show_in_website>
|
| 734 |
+
<show_in_store>1</show_in_store>
|
| 735 |
+
</status>
|
| 736 |
+
<min tranlate="label">
|
| 737 |
+
<label>Minimum recommended items</label>
|
| 738 |
+
<frontend_type>text</frontend_type>
|
| 739 |
+
<sort_order>2</sort_order>
|
| 740 |
+
<show_in_default>1</show_in_default>
|
| 741 |
+
<show_in_website>1</show_in_website>
|
| 742 |
+
<show_in_store>1</show_in_store>
|
| 743 |
+
<comment>
|
| 744 |
+
E.g.: if you want 4 recommendations (no more no less), then write 4 both on
|
| 745 |
+
minimum and maximum recommended items
|
| 746 |
+
</comment>
|
| 747 |
+
</min>
|
| 748 |
+
<max tranlate="label">
|
| 749 |
+
<label>Maximum recommended items</label>
|
| 750 |
+
<frontend_type>text</frontend_type>
|
| 751 |
+
<sort_order>3</sort_order>
|
| 752 |
+
<show_in_default>1</show_in_default>
|
| 753 |
+
<show_in_website>1</show_in_website>
|
| 754 |
+
<show_in_store>1</show_in_store>
|
| 755 |
+
<comment>
|
| 756 |
+
E.g.: if you want 4 recommendations (no more no less), then write 4 both on
|
| 757 |
+
minimum and maximum recommended items
|
| 758 |
+
</comment>
|
| 759 |
+
</max>
|
| 760 |
+
<widget tranlate="label">
|
| 761 |
+
<label>Widget name</label>
|
| 762 |
+
<frontend_type>text</frontend_type>
|
| 763 |
+
<sort_order>4</sort_order>
|
| 764 |
+
<show_in_default>1</show_in_default>
|
| 765 |
+
<show_in_website>1</show_in_website>
|
| 766 |
+
<show_in_store>1</show_in_store>
|
| 767 |
+
<comment>
|
| 768 |
+
Optional: default value is "basket" and should normally not be changed
|
| 769 |
+
</comment>
|
| 770 |
+
</widget>
|
| 771 |
+
</fields>
|
| 772 |
+
</cart>
|
| 773 |
+
<related>
|
| 774 |
+
<label>Product detail page: related recommendations</label>
|
| 775 |
+
<frontend_type>text</frontend_type>
|
| 776 |
+
<sort_order>20</sort_order>
|
| 777 |
+
<show_in_default>1</show_in_default>
|
| 778 |
+
<show_in_website>1</show_in_website>
|
| 779 |
+
<show_in_store>1</show_in_store>
|
| 780 |
+
<comment><![CDATA[ Widget configuration for related recommendation on product page. ]]></comment>
|
| 781 |
+
<fields>
|
| 782 |
+
<status tranlate="label">
|
| 783 |
+
<label>Widgets enabled</label>
|
| 784 |
+
<frontend_type>select</frontend_type>
|
| 785 |
+
<source_model>adminhtml/system_config_source_enabledisable</source_model>
|
| 786 |
+
<sort_order>1</sort_order>
|
| 787 |
+
<show_in_default>1</show_in_default>
|
| 788 |
+
<show_in_website>1</show_in_website>
|
| 789 |
+
<show_in_store>1</show_in_store>
|
| 790 |
+
</status>
|
| 791 |
+
<min tranlate="label">
|
| 792 |
+
<label>Minimum recommended items</label>
|
| 793 |
+
<frontend_type>text</frontend_type>
|
| 794 |
+
<sort_order>2</sort_order>
|
| 795 |
+
<show_in_default>1</show_in_default>
|
| 796 |
+
<show_in_website>1</show_in_website>
|
| 797 |
+
<show_in_store>1</show_in_store>
|
| 798 |
+
<comment>
|
| 799 |
+
E.g.: if you want 4 recommendations (no more no less), then write 4 both on
|
| 800 |
+
minimum and maximum recommended items
|
| 801 |
+
</comment>
|
| 802 |
+
</min>
|
| 803 |
+
<max tranlate="label">
|
| 804 |
+
<label>Maximum recommended items</label>
|
| 805 |
+
<frontend_type>text</frontend_type>
|
| 806 |
+
<sort_order>3</sort_order>
|
| 807 |
+
<show_in_default>1</show_in_default>
|
| 808 |
+
<show_in_website>1</show_in_website>
|
| 809 |
+
<show_in_store>1</show_in_store>
|
| 810 |
+
<comment>
|
| 811 |
+
E.g.: if you want 4 recommendations (no more no less), then write 4 both on
|
| 812 |
+
minimum and maximum recommended items
|
| 813 |
+
</comment>
|
| 814 |
+
</max>
|
| 815 |
+
<widget tranlate="label">
|
| 816 |
+
<label>Widget name</label>
|
| 817 |
+
<frontend_type>text</frontend_type>
|
| 818 |
+
<sort_order>4</sort_order>
|
| 819 |
+
<show_in_default>1</show_in_default>
|
| 820 |
+
<show_in_website>1</show_in_website>
|
| 821 |
+
<show_in_store>1</show_in_store>
|
| 822 |
+
<comment>
|
| 823 |
+
Optional: default value is "similar" and should normally not be changed
|
| 824 |
+
</comment>
|
| 825 |
+
</widget>
|
| 826 |
+
</fields>
|
| 827 |
+
</related>
|
| 828 |
+
<upsell>
|
| 829 |
+
<label>Product detail page: upsell recommendations</label>
|
| 830 |
+
<frontend_type>text</frontend_type>
|
| 831 |
+
<sort_order>30</sort_order>
|
| 832 |
+
<show_in_default>1</show_in_default>
|
| 833 |
+
<show_in_website>1</show_in_website>
|
| 834 |
+
<show_in_store>1</show_in_store>
|
| 835 |
+
<comment><![CDATA[ Widget configuration for upsell recommendation on product page. ]]></comment>
|
| 836 |
+
<fields>
|
| 837 |
+
<status tranlate="label">
|
| 838 |
+
<label>Widgets enabled</label>
|
| 839 |
+
<frontend_type>select</frontend_type>
|
| 840 |
+
<source_model>adminhtml/system_config_source_enabledisable</source_model>
|
| 841 |
+
<sort_order>1</sort_order>
|
| 842 |
+
<show_in_default>1</show_in_default>
|
| 843 |
+
<show_in_website>1</show_in_website>
|
| 844 |
+
<show_in_store>1</show_in_store>
|
| 845 |
+
</status>
|
| 846 |
+
<min tranlate="label">
|
| 847 |
+
<label>Minimum recommended items</label>
|
| 848 |
+
<frontend_type>text</frontend_type>
|
| 849 |
+
<sort_order>2</sort_order>
|
| 850 |
+
<show_in_default>1</show_in_default>
|
| 851 |
+
<show_in_website>1</show_in_website>
|
| 852 |
+
<show_in_store>1</show_in_store>
|
| 853 |
+
<comment>
|
| 854 |
+
E.g.: if you want 4 recommendations (no more no less), then write 4 both on
|
| 855 |
+
minimum and maximum recommended items
|
| 856 |
+
</comment>
|
| 857 |
+
</min>
|
| 858 |
+
<max tranlate="label">
|
| 859 |
+
<label>Maximum recommended items</label>
|
| 860 |
+
<frontend_type>text</frontend_type>
|
| 861 |
+
<sort_order>3</sort_order>
|
| 862 |
+
<show_in_default>1</show_in_default>
|
| 863 |
+
<show_in_website>1</show_in_website>
|
| 864 |
+
<show_in_store>1</show_in_store>
|
| 865 |
+
<comment>
|
| 866 |
+
E.g.: if you want 4 recommendations (no more no less), then write 4 both on
|
| 867 |
+
minimum and maximum recommended items
|
| 868 |
+
</comment>
|
| 869 |
+
</max>
|
| 870 |
+
<widget tranlate="label">
|
| 871 |
+
<label>Widget name</label>
|
| 872 |
+
<frontend_type>text</frontend_type>
|
| 873 |
+
<sort_order>4</sort_order>
|
| 874 |
+
<show_in_default>1</show_in_default>
|
| 875 |
+
<show_in_website>1</show_in_website>
|
| 876 |
+
<show_in_store>1</show_in_store>
|
| 877 |
+
<comment>
|
| 878 |
+
Optional: default value is "complementary" and should normally not be changed
|
| 879 |
+
</comment>
|
| 880 |
+
</widget>
|
| 881 |
+
</fields>
|
| 882 |
+
</upsell>
|
| 883 |
+
<others>
|
| 884 |
+
<label>Other recommendations Configuration</label>
|
| 885 |
+
<frontend_type>text</frontend_type>
|
| 886 |
+
<sort_order>40</sort_order>
|
| 887 |
+
<show_in_default>1</show_in_default>
|
| 888 |
+
<show_in_website>1</show_in_website>
|
| 889 |
+
<show_in_store>1</show_in_store>
|
| 890 |
+
<comment><![CDATA[ Widget configuration for upsell recommendation on product page. ]]></comment>
|
| 891 |
+
<fields>
|
| 892 |
+
<widget tranlate="label">
|
| 893 |
+
<label>Widget names</label>
|
| 894 |
+
<frontend_type>text</frontend_type>
|
| 895 |
+
<sort_order>1</sort_order>
|
| 896 |
+
<show_in_default>1</show_in_default>
|
| 897 |
+
<show_in_website>1</show_in_website>
|
| 898 |
+
<show_in_store>1</show_in_store>
|
| 899 |
+
<comment>
|
| 900 |
+
Optional: if you want to have other recommendations,
|
| 901 |
+
list them by names here (separated by comma)
|
| 902 |
+
</comment>
|
| 903 |
+
</widget>
|
| 904 |
+
<min tranlate="label">
|
| 905 |
+
<label>Minimum recommended items</label>
|
| 906 |
+
<frontend_type>text</frontend_type>
|
| 907 |
+
<sort_order>2</sort_order>
|
| 908 |
+
<show_in_default>1</show_in_default>
|
| 909 |
+
<show_in_website>1</show_in_website>
|
| 910 |
+
<show_in_store>1</show_in_store>
|
| 911 |
+
<comment>
|
| 912 |
+
Optional: if define other recommendation widgets, list the minimum recommended
|
| 913 |
+
items you want for each (separated by coma, same order)
|
| 914 |
+
</comment>
|
| 915 |
+
</min>
|
| 916 |
+
<max tranlate="label">
|
| 917 |
+
<label>Maximum recommended items</label>
|
| 918 |
+
<frontend_type>text</frontend_type>
|
| 919 |
+
<sort_order>3</sort_order>
|
| 920 |
+
<show_in_default>1</show_in_default>
|
| 921 |
+
<show_in_website>1</show_in_website>
|
| 922 |
+
<show_in_store>1</show_in_store>
|
| 923 |
+
<comment>
|
| 924 |
+
Optional: if define other recommendation widgets, list the maximum recommended
|
| 925 |
+
items you want for each (separated by coma, same order)
|
| 926 |
+
</comment>
|
| 927 |
+
</max>
|
| 928 |
+
<scenario tranlate="label">
|
| 929 |
+
<label>Types</label>
|
| 930 |
+
<frontend_type>text</frontend_type>
|
| 931 |
+
<sort_order>4</sort_order>
|
| 932 |
+
<show_in_default>1</show_in_default>
|
| 933 |
+
<show_in_website>1</show_in_website>
|
| 934 |
+
<show_in_store>1</show_in_store>
|
| 935 |
+
<comment>
|
| 936 |
+
Optional: if define other recommendation types, for each one: on which page the
|
| 937 |
+
recommendation appear (separated by coma, same order). Possible values: 'product'
|
| 938 |
+
if appear on a product page, 'basket' if appear on the basket, 'category' if appear
|
| 939 |
+
on a category page, 'search' if appear on a search page, 'others' in other cases.
|
| 940 |
+
</comment>
|
| 941 |
+
</scenario>
|
| 942 |
+
</fields>
|
| 943 |
+
</others>
|
| 944 |
+
</groups>
|
| 945 |
+
</bxRecommendations>
|
| 946 |
+
</sections>
|
| 947 |
+
</config>
|
app/code/community/Boxalino/Intelligence/lib/BxAutocompleteRequest.php
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
namespace com\boxalino\bxclient\v1;
|
| 4 |
+
|
| 5 |
+
class BxAutocompleteRequest
|
| 6 |
+
{
|
| 7 |
+
protected $language;
|
| 8 |
+
protected $queryText;
|
| 9 |
+
protected $choiceId;
|
| 10 |
+
protected $textualSuggestionsHitCount;
|
| 11 |
+
protected $bxSearchRequest;
|
| 12 |
+
|
| 13 |
+
protected $indexId = null;
|
| 14 |
+
|
| 15 |
+
public function __construct($language, $queryText, $textualSuggestionsHitCount, $productSuggestionHitCount = 5, $autocompleteChoiceId = 'autocomplete', $searchChoiceId = 'search') {
|
| 16 |
+
$this->language = $language;
|
| 17 |
+
$this->queryText = $queryText;
|
| 18 |
+
$this->textualSuggestionsHitCount = $textualSuggestionsHitCount;
|
| 19 |
+
if($autocompleteChoiceId == null){
|
| 20 |
+
$autocompleteChoiceId = 'autocomplete';
|
| 21 |
+
}
|
| 22 |
+
$this->choiceId = $autocompleteChoiceId;
|
| 23 |
+
$this->bxSearchRequest = new BxSearchRequest($language, $queryText, $productSuggestionHitCount, $searchChoiceId);
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
public function getBxSearchRequest() {
|
| 27 |
+
return $this->bxSearchRequest;
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
public function setBxSearchRequest($bxSearchRequest) {
|
| 31 |
+
$this->bxSearchRequest = $bxSearchRequest;
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
public function getLanguage() {
|
| 35 |
+
return $this->language;
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
public function setLanguage($language) {
|
| 39 |
+
$this->language = $language;
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
public function getQuerytext() {
|
| 43 |
+
return $this->queryText;
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
public function setQuerytext($queryText) {
|
| 47 |
+
$this->queryText = $queryText;
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
public function getChoiceId() {
|
| 51 |
+
return $this->choiceId;
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
public function setChoiceId($choiceId) {
|
| 55 |
+
$this->choiceId = $choiceId;
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
public function getTextualSuggestionHitCount() {
|
| 59 |
+
return $this->textualSuggestionsHitCount;
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
public function setTextualSuggestionHitCount($textualSuggestionsHitCount) {
|
| 63 |
+
$this->textualSuggestionsHitCount = $textualSuggestionsHitCount;
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
public function getIndexId() {
|
| 67 |
+
return $this->indexId;
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
public function setIndexId($indexId) {
|
| 71 |
+
$this->indexId = $indexId;
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
public function setDefaultIndexId($indexId) {
|
| 75 |
+
if($this->indexId == null) {
|
| 76 |
+
$this->setIndexId($indexId);
|
| 77 |
+
}
|
| 78 |
+
$this->bxSearchRequest->setDefaultIndexId($indexId);
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
private function getAutocompleteQuery() {
|
| 82 |
+
$autocompleteQuery = new \com\boxalino\p13n\api\thrift\AutocompleteQuery();
|
| 83 |
+
$autocompleteQuery->indexId = $this->getIndexId();
|
| 84 |
+
$autocompleteQuery->language = $this->language;
|
| 85 |
+
$autocompleteQuery->queryText = $this->queryText;
|
| 86 |
+
$autocompleteQuery->suggestionsHitCount = $this->textualSuggestionsHitCount;
|
| 87 |
+
$autocompleteQuery->highlight = true;
|
| 88 |
+
$autocompleteQuery->highlightPre = '<em>';
|
| 89 |
+
$autocompleteQuery->highlightPost = '</em>';
|
| 90 |
+
return $autocompleteQuery;
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
private $propertyQueries = array();
|
| 94 |
+
public function addPropertyQuery($field, $hitCount, $evaluateTotal=false) {
|
| 95 |
+
$propertyQuery = new \com\boxalino\p13n\api\thrift\PropertyQuery();
|
| 96 |
+
$propertyQuery->name = $field;
|
| 97 |
+
$propertyQuery->hitCount = $hitCount;
|
| 98 |
+
$propertyQuery->evaluateTotal = $evaluateTotal;
|
| 99 |
+
$this->propertyQueries[] = $propertyQuery;
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
public function resetPropertyQueries() {
|
| 103 |
+
$this->propertyQueries = array();
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
public function getAutocompleteThriftRequest($profileid, $thriftUserRecord) {
|
| 107 |
+
$autocompleteRequest = new \com\boxalino\p13n\api\thrift\AutocompleteRequest();
|
| 108 |
+
$autocompleteRequest->userRecord = $thriftUserRecord;
|
| 109 |
+
$autocompleteRequest->profileId = $profileid;
|
| 110 |
+
$autocompleteRequest->choiceId = $this->choiceId;
|
| 111 |
+
$autocompleteRequest->searchQuery = $this->bxSearchRequest->getSimpleSearchQuery();
|
| 112 |
+
$autocompleteRequest->searchChoiceId = $this->bxSearchRequest->getChoiceId();
|
| 113 |
+
$autocompleteRequest->autocompleteQuery = $this->getAutocompleteQuery();
|
| 114 |
+
|
| 115 |
+
if(sizeof($this->propertyQueries)>0) {
|
| 116 |
+
$autocompleteRequest->propertyQueries = $this->propertyQueries;
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
return $autocompleteRequest;
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
}
|
app/code/community/Boxalino/Intelligence/lib/BxAutocompleteResponse.php
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
namespace com\boxalino\bxclient\v1;
|
| 4 |
+
|
| 5 |
+
class BxAutocompleteResponse
|
| 6 |
+
{
|
| 7 |
+
private $response;
|
| 8 |
+
private $bxAutocompleteRequest;
|
| 9 |
+
public function __construct($response, $bxAutocompleteRequest=null) {
|
| 10 |
+
$this->response = $response;
|
| 11 |
+
$this->bxAutocompleteRequest = $bxAutocompleteRequest;
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
public function getResponse() {
|
| 15 |
+
return $this->response;
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
public function getPrefixSearchHash() {
|
| 19 |
+
if ($this->getResponse()->prefixSearchResult->totalHitCount > 0) {
|
| 20 |
+
return substr(md5($this->getResponse()->prefixSearchResult->queryText), 0, 10);
|
| 21 |
+
} else {
|
| 22 |
+
return null;
|
| 23 |
+
}
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
public function getTextualSuggestions() {
|
| 27 |
+
$suggestions = array();
|
| 28 |
+
foreach ($this->getResponse()->hits as $hit) {
|
| 29 |
+
$suggestions[] = $hit->suggestion;
|
| 30 |
+
}
|
| 31 |
+
return $suggestions;
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
protected function getTextualSuggestionHit($suggestion) {
|
| 35 |
+
foreach ($this->getResponse()->hits as $hit) {
|
| 36 |
+
if($hit->suggestion == $suggestion) {
|
| 37 |
+
return $hit;
|
| 38 |
+
}
|
| 39 |
+
}
|
| 40 |
+
throw new \Exception("unexisting textual suggestion provided " . $suggestion);
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
public function getTextualSuggestionTotalHitCount($suggestion) {
|
| 44 |
+
$hit = $this->getTextualSuggestionHit($suggestion);
|
| 45 |
+
return $hit->searchResult->totalHitCount;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
public function getBxSearchResponse($textualSuggestion = null) {
|
| 49 |
+
$searchResult = $textualSuggestion == null ? $this->getResponse()->prefixSearchResult : $this->getTextualSuggestionHit($textualSuggestion)->searchResult;
|
| 50 |
+
return new \com\boxalino\bxclient\v1\BxChooseResponse($searchResult, $this->bxAutocompleteRequest->getBxSearchRequest());
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
public function getPropertyHits($field) {
|
| 54 |
+
foreach ($this->getResponse()->propertyResults as $propertyResult) {
|
| 55 |
+
if ($propertyResult->name == $field) {
|
| 56 |
+
return $propertyResult->hits;
|
| 57 |
+
}
|
| 58 |
+
}
|
| 59 |
+
return array();
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
public function getPropertyHit($field, $hitValue) {
|
| 63 |
+
foreach ($this->getPropertyHits($field) as $hit) {
|
| 64 |
+
if($hit->value == $hitValue) {
|
| 65 |
+
return $hit;
|
| 66 |
+
}
|
| 67 |
+
}
|
| 68 |
+
return null;
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
public function getPropertyHitValues($field) {
|
| 72 |
+
$hitValues = array();
|
| 73 |
+
foreach ($this->getPropertyHits($field) as $hit) {
|
| 74 |
+
$hitValues[] = $hit->value;
|
| 75 |
+
}
|
| 76 |
+
return $hitValues;
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
public function getPropertyHitValueLabel($field, $hitValue) {
|
| 80 |
+
$hit = $this->getPropertyHit($field, $hitValue);
|
| 81 |
+
if($hit != null) {
|
| 82 |
+
return $hit->label;
|
| 83 |
+
}
|
| 84 |
+
return null;
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
public function getPropertyHitValueTotalHitCount($field, $hitValue) {
|
| 88 |
+
$hit = $this->getPropertyHit($field, $hitValue);
|
| 89 |
+
if($hit != null) {
|
| 90 |
+
return $hit->totalHitCount;
|
| 91 |
+
}
|
| 92 |
+
return null;
|
| 93 |
+
}
|
| 94 |
+
}
|
app/code/community/Boxalino/Intelligence/lib/BxChooseResponse.php
ADDED
|
@@ -0,0 +1,248 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
namespace com\boxalino\bxclient\v1;
|
| 4 |
+
|
| 5 |
+
class BxChooseResponse
|
| 6 |
+
{
|
| 7 |
+
private $response;
|
| 8 |
+
private $bxRequests;
|
| 9 |
+
public function __construct($response, $bxRequests=array()) {
|
| 10 |
+
$this->response = $response;
|
| 11 |
+
$this->bxRequests = is_array($bxRequests) ? $bxRequests : array($bxRequests);
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
public function getResponse() {
|
| 15 |
+
return $this->response;
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
public function getChoiceResponseVariant($choice=null, $count=0) {
|
| 19 |
+
|
| 20 |
+
foreach($this->bxRequests as $k => $bxRequest) {
|
| 21 |
+
if($choice != null && $choice == $bxRequest->getChoiceId()) {
|
| 22 |
+
if($count > 0){
|
| 23 |
+
$count--;
|
| 24 |
+
continue;
|
| 25 |
+
}
|
| 26 |
+
return $this->getChoiceIdResponseVariant($k);
|
| 27 |
+
}
|
| 28 |
+
}
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
protected function getChoiceIdResponseVariant($id=0) {
|
| 32 |
+
$response = $this->getResponse();
|
| 33 |
+
if (!empty($response->variants) && isset($response->variants[$id])) {
|
| 34 |
+
return $response->variants[$id];
|
| 35 |
+
}
|
| 36 |
+
//autocompletion case (no variants)
|
| 37 |
+
if(get_class($response) == 'com\boxalino\p13n\api\thrift\SearchResult') {
|
| 38 |
+
$variant = new \com\boxalino\p13n\api\thrift\Variant();
|
| 39 |
+
$variant->searchResult = $response;
|
| 40 |
+
return $variant;
|
| 41 |
+
}
|
| 42 |
+
throw new \Exception("no variant provided in choice response for variant id $id");
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
protected function getFirstPositiveSuggestionSearchResult($variant, $maxDistance=10) {
|
| 46 |
+
if(!isset($variant->searchRelaxation->suggestionsResults)) {
|
| 47 |
+
return null;
|
| 48 |
+
}
|
| 49 |
+
foreach($variant->searchRelaxation->suggestionsResults as $searchResult) {
|
| 50 |
+
if($searchResult->totalHitCount > 0) {
|
| 51 |
+
if($searchResult->queryText == "" || $variant->searchResult->queryText == "") {
|
| 52 |
+
continue;
|
| 53 |
+
}
|
| 54 |
+
$distance = levenshtein($searchResult->queryText, $variant->searchResult->queryText);
|
| 55 |
+
if($distance <= $maxDistance && $distance != -1) {
|
| 56 |
+
return $searchResult;
|
| 57 |
+
}
|
| 58 |
+
}
|
| 59 |
+
}
|
| 60 |
+
return null;
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
public function getVariantSearchResult($variant, $considerRelaxation=true, $maxDistance=10) {
|
| 64 |
+
|
| 65 |
+
$searchResult = $variant->searchResult;
|
| 66 |
+
if($considerRelaxation && $variant->searchResult->totalHitCount == 0) {
|
| 67 |
+
return $this->getFirstPositiveSuggestionSearchResult($variant, $maxDistance);
|
| 68 |
+
}
|
| 69 |
+
return $searchResult;
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
public function getSearchResultHitIds($searchResult) {
|
| 73 |
+
$ids = array();
|
| 74 |
+
if($searchResult) {
|
| 75 |
+
if($searchResult->hits){
|
| 76 |
+
foreach ($searchResult->hits as $item) {
|
| 77 |
+
$ids[] = $item->values['products_group_id'][0];
|
| 78 |
+
}
|
| 79 |
+
}elseif(isset($searchResult->hitsGroups)){
|
| 80 |
+
foreach ($searchResult->hitsGroups as $hitGroup){
|
| 81 |
+
$ids[] = $hitGroup->groupValue;
|
| 82 |
+
}
|
| 83 |
+
}
|
| 84 |
+
}
|
| 85 |
+
return $ids;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
public function getHitIds($choice=null, $considerRelaxation=true, $count=0, $maxDistance=10) {
|
| 89 |
+
|
| 90 |
+
$variant = $this->getChoiceResponseVariant($choice, $count);
|
| 91 |
+
return $this->getSearchResultHitIds($this->getVariantSearchResult($variant, $considerRelaxation, $maxDistance));
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
public function getSearchHitFieldValues($searchResult, $fields=null) {
|
| 95 |
+
$fieldValues = array();
|
| 96 |
+
if($searchResult) {
|
| 97 |
+
foreach ($searchResult->hits as $item) {
|
| 98 |
+
$finalFields = $fields;
|
| 99 |
+
if($finalFields == null) {
|
| 100 |
+
$finalFields = array_keys($item->values);
|
| 101 |
+
}
|
| 102 |
+
foreach ($finalFields as $field) {
|
| 103 |
+
if (isset($item->values[$field])) {
|
| 104 |
+
if (!empty($item->values[$field])) {
|
| 105 |
+
$fieldValues[$item->values['id'][0]][$field] = $item->values[$field];
|
| 106 |
+
}
|
| 107 |
+
}
|
| 108 |
+
if(!isset($fieldValues[$item->values['id'][0]][$field])) {
|
| 109 |
+
$fieldValues[$item->values['id'][0]][$field] = array();
|
| 110 |
+
}
|
| 111 |
+
}
|
| 112 |
+
}
|
| 113 |
+
}
|
| 114 |
+
return $fieldValues;
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
protected function getRequestFacets($choice=null) {
|
| 118 |
+
if($choice == null) {
|
| 119 |
+
if(isset($this->bxRequests[0])) {
|
| 120 |
+
return $this->bxRequests[0]->getFacets();
|
| 121 |
+
}
|
| 122 |
+
return null;
|
| 123 |
+
}
|
| 124 |
+
foreach($this->bxRequests as $bxRequest) {
|
| 125 |
+
if($bxRequest->getChoiceId() == $choice) {
|
| 126 |
+
return $bxRequest->getFacets();
|
| 127 |
+
}
|
| 128 |
+
}
|
| 129 |
+
return null;
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
public function getFacets($choice=null, $considerRelaxation=true, $count=0, $maxDistance=10) {
|
| 133 |
+
|
| 134 |
+
$variant = $this->getChoiceResponseVariant($choice, $count);
|
| 135 |
+
$searchResult = $this->getVariantSearchResult($variant, $considerRelaxation, $maxDistance);
|
| 136 |
+
$facets = $this->getRequestFacets($choice);
|
| 137 |
+
|
| 138 |
+
if(empty($facets) || $searchResult == null){
|
| 139 |
+
return null;
|
| 140 |
+
}
|
| 141 |
+
$facets->setFacetResponse($searchResult->facetResponses);
|
| 142 |
+
return $facets;
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
public function getHitFieldValues($fields, $choice=null, $considerRelaxation=true, $count=0, $maxDistance=10) {
|
| 146 |
+
$variant = $this->getChoiceResponseVariant($choice, $count);
|
| 147 |
+
return $this->getSearchHitFieldValues($this->getVariantSearchResult($variant, $considerRelaxation, $maxDistance), $fields);
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
public function getFirstHitFieldValue($field=null, $returnOneValue=true, $hitIndex=0, $choice=null, $count=0, $maxDistance=10) {
|
| 151 |
+
$fieldNames = null;
|
| 152 |
+
if($field != null) {
|
| 153 |
+
$fieldNames = array($field);
|
| 154 |
+
}
|
| 155 |
+
$count = 0;
|
| 156 |
+
foreach($this->getHitFieldValues($fieldNames, $choice, true, $count, $maxDistance) as $id => $fieldValueMap) {
|
| 157 |
+
if($count++ < $hitIndex) {
|
| 158 |
+
continue;
|
| 159 |
+
}
|
| 160 |
+
foreach($fieldValueMap as $fieldName => $fieldValues) {
|
| 161 |
+
if(sizeof($fieldValues)>0) {
|
| 162 |
+
if($returnOneValue) {
|
| 163 |
+
return $fieldValues[0];
|
| 164 |
+
} else {
|
| 165 |
+
return $fieldValues;
|
| 166 |
+
}
|
| 167 |
+
}
|
| 168 |
+
}
|
| 169 |
+
}
|
| 170 |
+
return null;
|
| 171 |
+
}
|
| 172 |
+
|
| 173 |
+
public function getTotalHitCount($choice=null, $considerRelaxation=true, $count=0, $maxDistance=10) {
|
| 174 |
+
$variant = $this->getChoiceResponseVariant($choice, $count);
|
| 175 |
+
$searchResult = $this->getVariantSearchResult($variant, $considerRelaxation, $maxDistance);
|
| 176 |
+
if($searchResult == null) {
|
| 177 |
+
return 0;
|
| 178 |
+
}
|
| 179 |
+
return $searchResult->totalHitCount;
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
public function areResultsCorrected($choice=null, $count=0, $maxDistance=10) {
|
| 183 |
+
return $this->getTotalHitCount($choice, false, $count) == 0 && $this->getTotalHitCount($choice, true, $count, $maxDistance) > 0 && $this->areThereSubPhrases() == false;
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
+
public function getCorrectedQuery($choice=null, $count=0) {
|
| 187 |
+
$variant = $this->getChoiceResponseVariant($choice, $count);
|
| 188 |
+
$searchResult = $this->getVariantSearchResult($variant);
|
| 189 |
+
if($searchResult) {
|
| 190 |
+
return $searchResult->queryText;
|
| 191 |
+
}
|
| 192 |
+
return null;
|
| 193 |
+
}
|
| 194 |
+
|
| 195 |
+
public function areThereSubPhrases($choice=null, $count=0) {
|
| 196 |
+
$variant = $this->getChoiceResponseVariant($choice, $count);
|
| 197 |
+
return isset($variant->searchRelaxation->subphrasesResults) && sizeof($variant->searchRelaxation->subphrasesResults) > 0;
|
| 198 |
+
}
|
| 199 |
+
|
| 200 |
+
public function getSubPhrasesQueries($choice=null, $count=0) {
|
| 201 |
+
if(!$this->areThereSubPhrases($choice, $count)) {
|
| 202 |
+
return array();
|
| 203 |
+
}
|
| 204 |
+
$queries = array();
|
| 205 |
+
$variant = $this->getChoiceResponseVariant($choice, $count);
|
| 206 |
+
foreach($variant->searchRelaxation->subphrasesResults as $searchResult) {
|
| 207 |
+
$queries[] = $searchResult->queryText;
|
| 208 |
+
}
|
| 209 |
+
return $queries;
|
| 210 |
+
}
|
| 211 |
+
|
| 212 |
+
protected function getSubPhraseSearchResult($queryText, $choice=null, $count=0) {
|
| 213 |
+
if(!$this->areThereSubPhrases($choice, $count)) {
|
| 214 |
+
return null;
|
| 215 |
+
}
|
| 216 |
+
$variant = $this->getChoiceResponseVariant($choice, $count);
|
| 217 |
+
foreach($variant->searchRelaxation->subphrasesResults as $searchResult) {
|
| 218 |
+
if($searchResult->queryText == $queryText) {
|
| 219 |
+
return $searchResult;
|
| 220 |
+
}
|
| 221 |
+
}
|
| 222 |
+
return null;
|
| 223 |
+
}
|
| 224 |
+
|
| 225 |
+
public function getSubPhraseTotalHitCount($queryText, $choice=null, $count=0) {
|
| 226 |
+
$searchResult = $this->getSubPhraseSearchResult($queryText, $choice, $count);
|
| 227 |
+
if($searchResult) {
|
| 228 |
+
return $searchResult->totalHitCount;
|
| 229 |
+
}
|
| 230 |
+
return 0;
|
| 231 |
+
}
|
| 232 |
+
|
| 233 |
+
public function getSubPhraseHitIds($queryText, $choice=null, $count=0) {
|
| 234 |
+
$searchResult = $this->getSubPhraseSearchResult($queryText, $choice, $count);
|
| 235 |
+
if($searchResult) {
|
| 236 |
+
return $this->getSearchResultHitIds($searchResult);
|
| 237 |
+
}
|
| 238 |
+
return array();
|
| 239 |
+
}
|
| 240 |
+
|
| 241 |
+
public function getSubPhraseHitFieldValues($queryText, $fields, $choice=null, $considerRelaxation=true, $count=0) {
|
| 242 |
+
$searchResult = $this->getSubPhraseSearchResult($queryText, $choice, $count);
|
| 243 |
+
if($searchResult) {
|
| 244 |
+
return $this->getSearchHitFieldValues($searchResult, $fields);
|
| 245 |
+
}
|
| 246 |
+
return array();
|
| 247 |
+
}
|
| 248 |
+
}
|
app/code/community/Boxalino/Intelligence/lib/BxClient.php
ADDED
|
@@ -0,0 +1,422 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
namespace com\boxalino\bxclient\v1;
|
| 4 |
+
|
| 5 |
+
class BxClient
|
| 6 |
+
{
|
| 7 |
+
private $account;
|
| 8 |
+
private $password;
|
| 9 |
+
private $isDev;
|
| 10 |
+
private $host;
|
| 11 |
+
private $port;
|
| 12 |
+
private $uri;
|
| 13 |
+
private $schema;
|
| 14 |
+
private $p13n_username;
|
| 15 |
+
private $p13n_password;
|
| 16 |
+
private $domain;
|
| 17 |
+
|
| 18 |
+
private $autocompleteRequests = null;
|
| 19 |
+
private $autocompleteResponses = null;
|
| 20 |
+
|
| 21 |
+
private $chooseRequests = array();
|
| 22 |
+
private $chooseResponses = null;
|
| 23 |
+
|
| 24 |
+
const VISITOR_COOKIE_TIME = 31536000;
|
| 25 |
+
|
| 26 |
+
private $_timeout = 2;
|
| 27 |
+
private $requestContextParameters = array();
|
| 28 |
+
|
| 29 |
+
private $sessionId = null;
|
| 30 |
+
private $profileId = null;
|
| 31 |
+
|
| 32 |
+
public function __construct($account, $password, $domain, $isDev=false, $host=null, $port=null, $uri=null, $schema=null, $p13n_username=null, $p13n_password=null) {
|
| 33 |
+
if (isset($_REQUEST['_d_bx_account']) && isset($_REQUEST['_d_bx_password'])) {
|
| 34 |
+
// for debug purposes only, never include credentials in request
|
| 35 |
+
$account = $_REQUEST['_d_bx_account'];
|
| 36 |
+
$password = $_REQUEST['_d_bx_password'];
|
| 37 |
+
}
|
| 38 |
+
$this->account = $account;
|
| 39 |
+
$this->password = $password;
|
| 40 |
+
$this->isDev = $isDev;
|
| 41 |
+
$this->host = $host;
|
| 42 |
+
if($this->host == null) {
|
| 43 |
+
$this->host = "cdn.bx-cloud.com";
|
| 44 |
+
}
|
| 45 |
+
$this->port = $port;
|
| 46 |
+
if($this->port == null) {
|
| 47 |
+
$this->port = 443;
|
| 48 |
+
}
|
| 49 |
+
$this->uri = $uri;
|
| 50 |
+
if($this->uri == null) {
|
| 51 |
+
$this->uri = '/p13n.web/p13n';
|
| 52 |
+
}
|
| 53 |
+
$this->schema = $schema;
|
| 54 |
+
if($this->schema == null) {
|
| 55 |
+
$this->schema = 'https';
|
| 56 |
+
}
|
| 57 |
+
$this->p13n_username = $p13n_username;
|
| 58 |
+
if($this->p13n_username == null) {
|
| 59 |
+
$this->p13n_username = "boxalino";
|
| 60 |
+
}
|
| 61 |
+
$this->p13n_password = $p13n_password;
|
| 62 |
+
if($this->p13n_password == null) {
|
| 63 |
+
$this->p13n_password = "tkZ8EXfzeZc6SdXZntCU";
|
| 64 |
+
}
|
| 65 |
+
$this->domain = $domain;
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
public static function LOAD_CLASSES($libPath) {
|
| 69 |
+
|
| 70 |
+
require_once($libPath . '/Thrift/ClassLoader/ThriftClassLoader.php');
|
| 71 |
+
$cl = new \Thrift\ClassLoader\ThriftClassLoader(false);
|
| 72 |
+
$cl->registerNamespace('Thrift', $libPath);
|
| 73 |
+
$cl->register(true);
|
| 74 |
+
require_once($libPath . '/P13nService.php');
|
| 75 |
+
require_once($libPath . '/Types.php');
|
| 76 |
+
|
| 77 |
+
require_once($libPath . "/BxFacets.php");
|
| 78 |
+
require_once($libPath . "/BxFilter.php");
|
| 79 |
+
require_once($libPath . "/BxRequest.php");
|
| 80 |
+
require_once($libPath . "/BxRecommendationRequest.php");
|
| 81 |
+
require_once($libPath . "/BxSearchRequest.php");
|
| 82 |
+
require_once($libPath . "/BxAutocompleteRequest.php");
|
| 83 |
+
require_once($libPath . "/BxSortFields.php");
|
| 84 |
+
require_once($libPath . "/BxChooseResponse.php");
|
| 85 |
+
require_once($libPath . "/BxAutocompleteResponse.php");
|
| 86 |
+
require_once($libPath . "/BxData.php");
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
public function getAccount($checkDev = true) {
|
| 90 |
+
if($checkDev && $this->isDev) {
|
| 91 |
+
return $this->account . '_dev';
|
| 92 |
+
}
|
| 93 |
+
return $this->account;
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
public function getUsername() {
|
| 97 |
+
return $this->getAccount(false);
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
public function getPassword() {
|
| 101 |
+
return $this->password;
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
private function getSessionAndProfile() {
|
| 105 |
+
|
| 106 |
+
if($this->sessionId != null && $this->profileId != null) {
|
| 107 |
+
return array($this->sessionId, $this->profileId);
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
if (empty($_COOKIE['cems'])) {
|
| 111 |
+
$sessionId = session_id();
|
| 112 |
+
if (empty($sessionId)) {
|
| 113 |
+
session_start();
|
| 114 |
+
$sessionId = session_id();
|
| 115 |
+
}
|
| 116 |
+
} else {
|
| 117 |
+
$sessionId = $_COOKIE['cems'];
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
if (empty($_COOKIE['cemv'])) {
|
| 121 |
+
$profileId = session_id();
|
| 122 |
+
if (empty($profileId)) {
|
| 123 |
+
session_start();
|
| 124 |
+
$profileId = session_id();
|
| 125 |
+
}
|
| 126 |
+
} else {
|
| 127 |
+
$profileId = $_COOKIE['cemv'];
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
// Refresh cookies
|
| 131 |
+
if (empty($this->domain)) {
|
| 132 |
+
setcookie('cems', $sessionId, 0);
|
| 133 |
+
setcookie('cemv', $profileId, time() + self::VISITOR_COOKIE_TIME);
|
| 134 |
+
} else {
|
| 135 |
+
setcookie('cems', $sessionId, 0, '/', $this->domain);
|
| 136 |
+
setcookie('cemv', $profileId, time() + self::VISITOR_COOKIE_TIME, '/', $this->domain);
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
$this->sessionId = $sessionId;
|
| 140 |
+
$this->profileId = $profileId;
|
| 141 |
+
|
| 142 |
+
return array($this->sessionId, $this->profileId);
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
private function getUserRecord() {
|
| 146 |
+
$userRecord = new \com\boxalino\p13n\api\thrift\UserRecord();
|
| 147 |
+
$userRecord->username = $this->getAccount();
|
| 148 |
+
return $userRecord;
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
private function getP13n($timeout=2, $useCurlIfAvailable=true){
|
| 152 |
+
|
| 153 |
+
if($useCurlIfAvailable && function_exists('curl_version')) {
|
| 154 |
+
$transport = new \Thrift\Transport\P13nTCurlClient($this->host, $this->port, $this->uri, $this->schema);
|
| 155 |
+
} else {
|
| 156 |
+
$transport = new \Thrift\Transport\P13nTHttpClient($this->host, $this->port, $this->uri, $this->schema);
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
$transport->setAuthorization($this->p13n_username, $this->p13n_password);
|
| 160 |
+
$transport->setTimeoutSecs($timeout);
|
| 161 |
+
$client = new \com\boxalino\p13n\api\thrift\P13nServiceClient(new \Thrift\Protocol\TCompactProtocol($transport));
|
| 162 |
+
$transport->open();
|
| 163 |
+
return $client;
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
public function getChoiceRequest($inquiries, $requestContext = null) {
|
| 167 |
+
|
| 168 |
+
$choiceRequest = new \com\boxalino\p13n\api\thrift\ChoiceRequest();
|
| 169 |
+
|
| 170 |
+
list($sessionid, $profileid) = $this->getSessionAndProfile();
|
| 171 |
+
|
| 172 |
+
$choiceRequest->userRecord = $this->getUserRecord();
|
| 173 |
+
$choiceRequest->profileId = $profileid;
|
| 174 |
+
$choiceRequest->inquiries = $inquiries;
|
| 175 |
+
if($requestContext == null) {
|
| 176 |
+
$requestContext = $this->getRequestContext();
|
| 177 |
+
}
|
| 178 |
+
$choiceRequest->requestContext = $requestContext;
|
| 179 |
+
|
| 180 |
+
return $choiceRequest;
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
protected function getIP()
|
| 184 |
+
{
|
| 185 |
+
$ip = null;
|
| 186 |
+
$clientip = @$_SERVER['HTTP_CLIENT_IP'];
|
| 187 |
+
$forwardedip = @$_SERVER['HTTP_X_FORWARDED_FOR'];
|
| 188 |
+
if (filter_var($clientip, FILTER_VALIDATE_IP)) {
|
| 189 |
+
$ip = $clientip;
|
| 190 |
+
} elseif (filter_var($forwardedip, FILTER_VALIDATE_IP)) {
|
| 191 |
+
$ip = $forwardedip;
|
| 192 |
+
} else {
|
| 193 |
+
$ip = @$_SERVER['REMOTE_ADDR'];
|
| 194 |
+
}
|
| 195 |
+
|
| 196 |
+
return $ip;
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
protected function getCurrentURL()
|
| 200 |
+
{
|
| 201 |
+
$protocol = strpos(strtolower(@$_SERVER['SERVER_PROTOCOL']), 'https') === false ? 'http' : 'https';
|
| 202 |
+
$hostname = @$_SERVER['HTTP_HOST'];
|
| 203 |
+
$requesturi = @$_SERVER['REQUEST_URI'];
|
| 204 |
+
|
| 205 |
+
return $protocol . '://' . $hostname . $requesturi;
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
public function addRequestContextParameter($name, $values) {
|
| 209 |
+
if(!is_array($values)) {
|
| 210 |
+
$values = array($values);
|
| 211 |
+
}
|
| 212 |
+
$this->requestContextParameters[$name] = $values;
|
| 213 |
+
}
|
| 214 |
+
|
| 215 |
+
public function resetRequestContextParameter() {
|
| 216 |
+
$this->requestContextParameters = array();
|
| 217 |
+
}
|
| 218 |
+
|
| 219 |
+
protected function getRequestContext()
|
| 220 |
+
{
|
| 221 |
+
list($sessionid, $profileid) = $this->getSessionAndProfile();
|
| 222 |
+
|
| 223 |
+
$requestContext = new \com\boxalino\p13n\api\thrift\RequestContext();
|
| 224 |
+
$requestContext->parameters = array(
|
| 225 |
+
'User-Agent' => array(@$_SERVER['HTTP_USER_AGENT']),
|
| 226 |
+
'User-Host' => array($this->getIP()),
|
| 227 |
+
'User-SessionId' => array($sessionid),
|
| 228 |
+
'User-Referer' => array(@$_SERVER['HTTP_REFERER']),
|
| 229 |
+
'User-URL' => array($this->getCurrentURL())
|
| 230 |
+
);
|
| 231 |
+
foreach($this->requestContextParameters as $k => $v) {
|
| 232 |
+
$requestContext->parameters[$k] = $v;
|
| 233 |
+
}
|
| 234 |
+
|
| 235 |
+
if (isset($_REQUEST['p13nRequestContext']) && is_array($_REQUEST['p13nRequestContext'])) {
|
| 236 |
+
$requestContext->parameters = array_merge(
|
| 237 |
+
$_REQUEST['p13nRequestContext'],
|
| 238 |
+
$requestContext->parameters
|
| 239 |
+
);
|
| 240 |
+
}
|
| 241 |
+
|
| 242 |
+
return $requestContext;
|
| 243 |
+
}
|
| 244 |
+
|
| 245 |
+
private function throwCorrectP13nException($e) {
|
| 246 |
+
if(strpos($e->getMessage(), 'Could not connect ') !== false) {
|
| 247 |
+
throw new \Exception('The connection to our server failed even before checking your credentials. This might be typically caused by 2 possible things: wrong values in host, port, schema or uri (typical value should be host=cdn.bx-cloud.com, port=443, uri =/p13n.web/p13n and schema=https, your values are : host=' . $this->host . ', port=' . $this->port . ', schema=' . $this->schema . ', uri=' . $this->uri . '). Another possibility, is that your server environment has a problem with ssl certificate (peer certificate cannot be authenticated with given ca certificates), which you can either fix, or avoid the problem by adding the line "curl_setopt(self::$curlHandle, CURLOPT_SSL_VERIFYPEER, false);" in the file "lib\Thrift\Transport\P13nTCurlClient" after the call to curl_init in the function flush. Full error message=' . $e->getMessage());
|
| 248 |
+
}
|
| 249 |
+
if(strpos($e->getMessage(), 'Bad protocol id in TCompact message') !== false) {
|
| 250 |
+
throw new \Exception('The connection to our server has worked, but your credentials were refused. Provided credentials username=' . $this->p13n_username. ', password=' . $this->p13n_password . '. Full error message=' . $e->getMessage());
|
| 251 |
+
}
|
| 252 |
+
if(strpos($e->getMessage(), 'choice not found') !== false) {
|
| 253 |
+
$parts = explode('choice not found', $e->getMessage());
|
| 254 |
+
$pieces = explode(' at ', $parts[1]);
|
| 255 |
+
$choiceId = str_replace(':', '', trim($pieces[0]));
|
| 256 |
+
throw new \Exception("Configuration not live on account " . $this->getAccount() . ": choice $choiceId doesn't exist. NB: If you get a message indicating that the choice doesn't exist, this probably means that your choice configuraiton has not been loaded yet. It will happen automatically within 24 hours after your account's creation, but you can force it by calling (call it only once, not every time) \$bxData->publishChoices(); like in the example backend_data_init.php");
|
| 257 |
+
}
|
| 258 |
+
if(strpos($e->getMessage(), 'Solr returned status 404') !== false) {
|
| 259 |
+
throw new \Exception("Data not live on account " . $this->getAccount() . ": index returns status 404. Please publish your data first, like in example backend_data_basic.php.");
|
| 260 |
+
}
|
| 261 |
+
if(strpos($e->getMessage(), 'undefined field ') !== false) {
|
| 262 |
+
$parts = explode('undefined field ', $e->getMessage());
|
| 263 |
+
$pieces = explode(' at ', $parts[1]);
|
| 264 |
+
$field = str_replace(':', '', trim($pieces[0]));
|
| 265 |
+
throw new \Exception("You request in your filter or facets a non-existing field of your account " . $this->getAccount() . ": field $field doesn't exist.");
|
| 266 |
+
}
|
| 267 |
+
if(strpos($e->getMessage(), 'All choice variants are excluded') !== false) {
|
| 268 |
+
throw new \Exception("You have an invalid configuration for with a choice defined, but having no defined strategies. This is a quite unusual case, please contact support@boxalino.com to get support.");
|
| 269 |
+
}
|
| 270 |
+
throw $e;
|
| 271 |
+
}
|
| 272 |
+
|
| 273 |
+
private function p13nchoose($choiceRequest) {
|
| 274 |
+
try {
|
| 275 |
+
$choiceResponse = $this->getP13n($this->_timeout)->choose($choiceRequest);
|
| 276 |
+
if(isset($_REQUEST['dev_bx_disp']) && $_REQUEST['dev_bx_disp'] == 'true') {
|
| 277 |
+
echo "<pre><h1>Choice Request</h1>";
|
| 278 |
+
var_dump($choiceRequest);
|
| 279 |
+
echo "<br><h1>Choice Response</h1>";
|
| 280 |
+
var_dump($choiceResponse);
|
| 281 |
+
echo "</pre>";
|
| 282 |
+
exit;
|
| 283 |
+
}
|
| 284 |
+
return $choiceResponse;
|
| 285 |
+
} catch(\Exception $e) {
|
| 286 |
+
$this->throwCorrectP13nException($e);
|
| 287 |
+
}
|
| 288 |
+
}
|
| 289 |
+
|
| 290 |
+
public function addRequest($request) {
|
| 291 |
+
$request->setDefaultIndexId($this->getAccount());
|
| 292 |
+
$this->chooseRequests[] = $request;
|
| 293 |
+
}
|
| 294 |
+
|
| 295 |
+
public function resetRequests() {
|
| 296 |
+
$this->chooseRequests = array();
|
| 297 |
+
}
|
| 298 |
+
|
| 299 |
+
public function getRequest($index=0) {
|
| 300 |
+
if(sizeof($this->chooseRequests) <= $index) {
|
| 301 |
+
return null;
|
| 302 |
+
}
|
| 303 |
+
return $this->chooseRequests[$index];
|
| 304 |
+
}
|
| 305 |
+
|
| 306 |
+
public function getChoiceIdRecommendationRequest($choiceId) {
|
| 307 |
+
foreach ($this->chooseRequests as $request){
|
| 308 |
+
if($request->getChoiceId() == $choiceId) {
|
| 309 |
+
return $request;
|
| 310 |
+
}
|
| 311 |
+
}
|
| 312 |
+
return null;
|
| 313 |
+
}
|
| 314 |
+
|
| 315 |
+
public function getRecommendationRequests(){
|
| 316 |
+
$requests = array();
|
| 317 |
+
foreach ($this->chooseRequests as $request){
|
| 318 |
+
if($request instanceof BxRecommendationRequest){
|
| 319 |
+
$requests[] = $request;
|
| 320 |
+
}
|
| 321 |
+
}
|
| 322 |
+
return $requests;
|
| 323 |
+
}
|
| 324 |
+
|
| 325 |
+
public function getThriftChoiceRequest() {
|
| 326 |
+
$choiceInquiries = array();
|
| 327 |
+
|
| 328 |
+
foreach($this->chooseRequests as $request) {
|
| 329 |
+
|
| 330 |
+
$choiceInquiry = new \com\boxalino\p13n\api\thrift\ChoiceInquiry();
|
| 331 |
+
$choiceInquiry->choiceId = $request->getChoiceId();
|
| 332 |
+
$choiceInquiry->simpleSearchQuery = $request->getSimpleSearchQuery($this->getAccount());
|
| 333 |
+
$choiceInquiry->contextItems = $request->getContextItems();
|
| 334 |
+
$choiceInquiry->minHitCount = $request->getMin();
|
| 335 |
+
$choiceInquiry->withRelaxation = $request->getWithRelaxation();
|
| 336 |
+
|
| 337 |
+
$choiceInquiries[] = $choiceInquiry;
|
| 338 |
+
}
|
| 339 |
+
|
| 340 |
+
$choiceRequest = $this->getChoiceRequest($choiceInquiries, $this->getRequestContext());
|
| 341 |
+
return $choiceRequest;
|
| 342 |
+
}
|
| 343 |
+
|
| 344 |
+
protected function choose() {
|
| 345 |
+
$this->chooseResponses = $this->p13nchoose($this->getThriftChoiceRequest());
|
| 346 |
+
}
|
| 347 |
+
|
| 348 |
+
public function getResponse() {
|
| 349 |
+
if(!$this->chooseResponses) {
|
| 350 |
+
$this->choose();
|
| 351 |
+
}
|
| 352 |
+
return new \com\boxalino\bxclient\v1\BxChooseResponse($this->chooseResponses, $this->chooseRequests);
|
| 353 |
+
}
|
| 354 |
+
|
| 355 |
+
public function setAutocompleteRequest($request) {
|
| 356 |
+
$this->setAutocompleteRequests(array($request));
|
| 357 |
+
}
|
| 358 |
+
|
| 359 |
+
public function setAutocompleteRequests($requests) {
|
| 360 |
+
foreach ($requests as $request) {
|
| 361 |
+
$this->enhanceAutoCompleterequest($request);
|
| 362 |
+
}
|
| 363 |
+
$this->autocompleteRequests = $requests;
|
| 364 |
+
}
|
| 365 |
+
|
| 366 |
+
private function enhanceAutoCompleterequest(&$request) {
|
| 367 |
+
$request->setDefaultIndexId($this->getAccount());
|
| 368 |
+
}
|
| 369 |
+
|
| 370 |
+
private function p13nautocomplete($autocompleteRequest) {
|
| 371 |
+
try {
|
| 372 |
+
return $this->getP13n($this->_timeout)->autocomplete($autocompleteRequest);
|
| 373 |
+
} catch(\Exception $e) {
|
| 374 |
+
$this->throwCorrectP13nException($e);
|
| 375 |
+
}
|
| 376 |
+
}
|
| 377 |
+
|
| 378 |
+
public function autocomplete()
|
| 379 |
+
{
|
| 380 |
+
list($sessionid, $profileid) = $this->getSessionAndProfile();
|
| 381 |
+
$userRecord = $this->getUserRecord();
|
| 382 |
+
$p13nrequests = array_map(function($request) use(&$profileid, &$userRecord) {
|
| 383 |
+
return $request->getAutocompleteThriftRequest($profileid, $userRecord);
|
| 384 |
+
}, $this->autocompleteRequests);
|
| 385 |
+
$i = -1;
|
| 386 |
+
$this->autocompleteResponses = array_map(function($response) use (&$i) {
|
| 387 |
+
$request = $this->autocompleteRequests[++$i];
|
| 388 |
+
return new BxAutocompleteResponse($response, $request);
|
| 389 |
+
}, $this->p13nautocompleteAll($p13nrequests));
|
| 390 |
+
|
| 391 |
+
}
|
| 392 |
+
|
| 393 |
+
public function getAutocompleteResponse() {
|
| 394 |
+
$responses = $this->getAutocompleteResponses();
|
| 395 |
+
if(isset($responses[0])) {
|
| 396 |
+
return $responses[0];
|
| 397 |
+
}
|
| 398 |
+
return null;
|
| 399 |
+
}
|
| 400 |
+
|
| 401 |
+
private function p13nautocompleteAll($requests) {
|
| 402 |
+
$requestBundle = new \com\boxalino\p13n\api\thrift\AutocompleteRequestBundle();
|
| 403 |
+
$requestBundle->requests = $requests;
|
| 404 |
+
try {
|
| 405 |
+
return $this->getP13n($this->_timeout)->autocompleteAll($requestBundle)->responses;
|
| 406 |
+
} catch(\Exception $e) {
|
| 407 |
+
$this->throwCorrectP13nException($e);
|
| 408 |
+
}
|
| 409 |
+
}
|
| 410 |
+
|
| 411 |
+
public function getAutocompleteResponses() {
|
| 412 |
+
if (!$this->autocompleteResponses) {
|
| 413 |
+
$this->autocomplete();
|
| 414 |
+
}
|
| 415 |
+
return $this->autocompleteResponses;
|
| 416 |
+
}
|
| 417 |
+
|
| 418 |
+
public function setTimeout($timeout) {
|
| 419 |
+
$this->_timeout = $timeout;
|
| 420 |
+
}
|
| 421 |
+
|
| 422 |
+
}
|
app/code/community/Boxalino/Intelligence/lib/BxData.php
ADDED
|
@@ -0,0 +1,658 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
namespace com\boxalino\bxclient\v1;
|
| 4 |
+
|
| 5 |
+
class BxData
|
| 6 |
+
{
|
| 7 |
+
const URL_VERIFY_CREDENTIALS = '/frontend/dbmind/en/dbmind/api/credentials/verify';
|
| 8 |
+
const URL_XML = '/frontend/dbmind/en/dbmind/api/data/source/update';
|
| 9 |
+
const URL_PUBLISH_CONFIGURATION_CHANGES = '/frontend/dbmind/en/dbmind/api/configuration/publish/owner';
|
| 10 |
+
const URL_ZIP = '/frontend/dbmind/en/dbmind/api/data/push';
|
| 11 |
+
|
| 12 |
+
const URL_EXECUTE_TASK = '/frontend/dbmind/en/dbmind/files/task/execute';
|
| 13 |
+
|
| 14 |
+
private $bxClient;
|
| 15 |
+
private $languages;
|
| 16 |
+
private $isDev;
|
| 17 |
+
private $isDelta;
|
| 18 |
+
|
| 19 |
+
private $sources = array();
|
| 20 |
+
|
| 21 |
+
private $host = 'http://di1.bx-cloud.com';
|
| 22 |
+
|
| 23 |
+
private $owner = 'bx_client_data_api';
|
| 24 |
+
|
| 25 |
+
public function __construct($bxClient, $languages = array(), $isDev=false, $isDelta=false) {
|
| 26 |
+
$this->bxClient = $bxClient;
|
| 27 |
+
$this->languages = $languages;
|
| 28 |
+
$this->isDev = $isDev;
|
| 29 |
+
$this->isDelta = $isDelta;
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
public function setLanguages($languages) {
|
| 33 |
+
$this->languages = $languages;
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
public function getLanguages() {
|
| 37 |
+
return $this->languages;
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
public function addMainCSVItemFile($filePath, $itemIdColumn, $encoding = 'UTF-8', $delimiter = ',', $enclosure = "\"", $escape = "\\\\", $lineSeparator = "\\n", $sourceId = 'item_vals', $container = 'products', $validate=true) {
|
| 41 |
+
$sourceKey = $this->addCSVItemFile($filePath, $itemIdColumn, $encoding, $delimiter, $enclosure, $escape, $lineSeparator, $sourceId, $container, $validate);
|
| 42 |
+
$this->addSourceIdField($sourceKey, $itemIdColumn, null, $validate) ;
|
| 43 |
+
$this->addSourceStringField($sourceKey, "bx_item_id", $itemIdColumn, null, $validate) ;
|
| 44 |
+
return $sourceKey;
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
public function addMainCSVCustomerFile($filePath, $itemIdColumn, $encoding = 'UTF-8', $delimiter = ',', $enclosure = "\&", $escape = "\\\\", $lineSeparator = "\\n", $sourceId = 'customers', $container = 'customers', $validate=true) {
|
| 48 |
+
$sourceKey = $this->addCSVItemFile($filePath, $itemIdColumn, $encoding, $delimiter, $enclosure, $escape, $lineSeparator, $sourceId, $container, $validate);
|
| 49 |
+
$this->addSourceIdField($sourceKey, $itemIdColumn, null, $validate) ;
|
| 50 |
+
$this->addSourceStringField($sourceKey, "bx_customer_id", $itemIdColumn, null, $validate) ;
|
| 51 |
+
return $sourceKey;
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
public function addCSVItemFile($filePath, $itemIdColumn, $encoding = 'UTF-8', $delimiter = ',', $enclosure = "\&", $escape = "\\\\", $lineSeparator = "\\n", $sourceId = null, $container = 'products', $validate=true) {
|
| 55 |
+
$params = array('itemIdColumn'=>$itemIdColumn, 'encoding'=>$encoding, 'delimiter'=>$delimiter, 'enclosure'=>$enclosure, 'escape'=>$escape, 'lineSeparator'=>$lineSeparator);
|
| 56 |
+
if($sourceId == null) {
|
| 57 |
+
$sourceId = $this->getFileNameFromPath($filePath, true);
|
| 58 |
+
}
|
| 59 |
+
return $this->addSourceFile($filePath, $sourceId, $container, 'item_data_file', 'CSV', $params, $validate);
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
public function addCSVCustomerFile($filePath, $itemIdColumn, $encoding = 'UTF-8', $delimiter = ',', $enclosure = "\&", $escape = "\\\\", $lineSeparator = "\\n", $sourceId = null, $container = 'customers', $validate=true) {
|
| 63 |
+
$params = array('itemIdColumn'=>$itemIdColumn, 'encoding'=>$encoding, 'delimiter'=>$delimiter, 'enclosure'=>$enclosure, 'escape'=>$escape, 'lineSeparator'=>$lineSeparator);
|
| 64 |
+
if($sourceId == null) {
|
| 65 |
+
$sourceId = $this->getFileNameFromPath($filePath, true);
|
| 66 |
+
}
|
| 67 |
+
return $this->addSourceFile($filePath, $sourceId, $container, 'item_data_file', 'CSV', $params, $validate);
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
public function addCategoryFile($filePath, $categoryIdColumn, $parentIdColumn, $categoryLabelColumns, $encoding = 'UTF-8', $delimiter = ',', $enclosure = "\&", $escape = "\\\\", $lineSeparator = "\\n", $sourceId = 'resource_categories', $container = 'products', $validate=true) {
|
| 71 |
+
$params = array('referenceIdColumn'=>$categoryIdColumn, 'parentIdColumn'=>$parentIdColumn, 'labelColumns'=>$categoryLabelColumns, 'encoding'=>$encoding, 'delimiter'=>$delimiter, 'enclosure'=>$enclosure, 'escape'=>$escape, 'lineSeparator'=>$lineSeparator);
|
| 72 |
+
return $this->addSourceFile($filePath, $sourceId, $container, 'hierarchical', 'CSV', $params, $validate);
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
public function addResourceFile($filePath, $categoryIdColumn, $labelColumns, $encoding = 'UTF-8', $delimiter = ',', $enclosure = "\&", $escape = "\\\\", $lineSeparator = "\\n", $sourceId = null, $container = 'products', $validate=true) {
|
| 76 |
+
$params = array('referenceIdColumn'=>$categoryIdColumn, 'labelColumns'=>$labelColumns, 'encoding'=>$encoding, 'delimiter'=>$delimiter, 'enclosure'=>$enclosure, 'escape'=>$escape, 'lineSeparator'=>$lineSeparator);
|
| 77 |
+
if($sourceId == null) {
|
| 78 |
+
$sourceId = 'resource_' . $this->getFileNameFromPath($filePath, true);
|
| 79 |
+
}
|
| 80 |
+
return $this->addSourceFile($filePath, $sourceId, $container, 'resource', 'CSV', $params, $validate);
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
public function setCSVTransactionFile($filePath, $orderIdColumn, $productIdColumn, $customerIdColumn, $orderDateIdColumn, $totalOrderValueColumn, $productListPriceColumn, $productDiscountedPriceColumn, $productIdField='bx_item_id', $customerIdField='bx_customer_id', $productsContainer = 'products', $customersContainer = 'customers', $format = 'CSV', $encoding = 'UTF-8', $delimiter = ',', $enclosure = "\&", $escape = "\\\\", $lineSeparator = "\\n",$container = 'transactions', $sourceId = 'transactions', $validate=true) {
|
| 86 |
+
|
| 87 |
+
$params = array('encoding'=>$encoding, 'delimiter'=>$delimiter, 'enclosure'=>$enclosure, 'escape'=>$escape, 'lineSeparator'=>$lineSeparator);
|
| 88 |
+
|
| 89 |
+
$params['file'] = $this->getFileNameFromPath($filePath);
|
| 90 |
+
$params['orderIdColumn'] = $orderIdColumn;
|
| 91 |
+
$params['productIdColumn'] = $productIdColumn;
|
| 92 |
+
$params['product_property_id'] = $productIdField;
|
| 93 |
+
$params['customerIdColumn'] = $customerIdColumn;
|
| 94 |
+
$params['customer_property_id'] = $customerIdField;
|
| 95 |
+
$params['productListPriceColumn'] = $productListPriceColumn;
|
| 96 |
+
$params['productDiscountedPriceColumn'] = $productDiscountedPriceColumn;
|
| 97 |
+
$params['totalOrderValueColumn'] = $totalOrderValueColumn;
|
| 98 |
+
$params['orderReceptionDateColumn'] = $orderDateIdColumn;
|
| 99 |
+
|
| 100 |
+
return $this->addSourceFile($filePath, $sourceId, $container, 'transactions', $format, $params, $validate);
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
public function addSourceFile($filePath, $sourceId, $container, $type, $format='CSV', $params=array(), $validate=true) {
|
| 104 |
+
if(sizeof($this->getLanguages())==0) {
|
| 105 |
+
throw new \Exception("trying to add a source before having declared the languages with method setLanguages");
|
| 106 |
+
}
|
| 107 |
+
if(!isset($this->sources[$container])) {
|
| 108 |
+
$this->sources[$container] = array();
|
| 109 |
+
}
|
| 110 |
+
$params['filePath'] = $filePath;
|
| 111 |
+
$params['format'] = $format;
|
| 112 |
+
$params['type'] = $type;
|
| 113 |
+
$this->sources[$container][$sourceId] = $params;
|
| 114 |
+
if($validate) {
|
| 115 |
+
$this->validateSource($container, $sourceId);
|
| 116 |
+
}
|
| 117 |
+
$this->sourceIdContainers[$sourceId] = $container;
|
| 118 |
+
return $this->encodesourceKey($container, $sourceId);
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
public function decodeSourceKey($sourceKey) {
|
| 122 |
+
return explode('-', $sourceKey);
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
public function encodesourceKey($container, $sourceId) {
|
| 126 |
+
return $container.'-'.$sourceId;
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
public function getSourceCSVRow($container, $sourceId, $row=0, $maxRow = 2) {
|
| 130 |
+
if(!isset($this->sources[$container][$sourceId]['rows'])) {
|
| 131 |
+
if (($handle = fopen($this->sources[$container][$sourceId]['filePath'], "r")) !== FALSE) {
|
| 132 |
+
$count = 1;
|
| 133 |
+
$this->sources[$container][$sourceId]['rows'] = array();
|
| 134 |
+
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
|
| 135 |
+
$this->sources[$container][$sourceId]['rows'][] = $data;
|
| 136 |
+
if($count++>=$maxRow) {
|
| 137 |
+
break;
|
| 138 |
+
}
|
| 139 |
+
}
|
| 140 |
+
fclose($handle);
|
| 141 |
+
}
|
| 142 |
+
}
|
| 143 |
+
if(isset($this->sources[$container][$sourceId]['rows'][$row])) {
|
| 144 |
+
return $this->sources[$container][$sourceId]['rows'][$row];
|
| 145 |
+
}
|
| 146 |
+
return null;
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
public function validateSource($container, $sourceId) {
|
| 150 |
+
$source = $this->sources[$container][$sourceId];
|
| 151 |
+
if($source['format'] == 'CSV') {
|
| 152 |
+
if(isset($source['itemIdColumn'])) {
|
| 153 |
+
$this->validateColumnExistance($container, $sourceId, $source['itemIdColumn']);
|
| 154 |
+
}
|
| 155 |
+
}
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
public function validateColumnExistance($container, $sourceId, $col) {
|
| 159 |
+
$row = $this->getSourceCSVRow($container, $sourceId, 0);
|
| 160 |
+
if(!in_array($col, $row)) {
|
| 161 |
+
throw new \Exception("the source '$sourceId' in the container '$container' declares an column '$col' which is not present in the header row of the provided CSV file: " . implode(',', $row));
|
| 162 |
+
}
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
public function addSourceIdField($sourceKey, $col, $referenceSourceKey=null, $validate=true) {
|
| 166 |
+
$this->addSourceField($sourceKey, 'bx_id', "id", false, $col, $referenceSourceKey, $validate);
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
public function addSourceTitleField($sourceKey, $colMap, $referenceSourceKey=null, $validate=true) {
|
| 170 |
+
$this->addSourceField($sourceKey, "bx_title", "title", true, $colMap, $referenceSourceKey, $validate);
|
| 171 |
+
}
|
| 172 |
+
|
| 173 |
+
public function addSourceDescriptionField($sourceKey, $colMap, $referenceSourceKey=null, $validate=true) {
|
| 174 |
+
$this->addSourceField($sourceKey, "bx_description", "body", true, $colMap, $referenceSourceKey, $validate);
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
public function addSourceListPriceField($sourceKey, $col, $referenceSourceKey=null, $validate=true) {
|
| 178 |
+
$this->addSourceField($sourceKey, "bx_listprice", "price", false, $col, $referenceSourceKey, $validate);
|
| 179 |
+
}
|
| 180 |
+
|
| 181 |
+
public function addSourceDiscountedPriceField($sourceKey, $col, $referenceSourceKey=null, $validate=true) {
|
| 182 |
+
$this->addSourceField($sourceKey, "bx_discountedprice", "discounted", false, $col, $referenceSourceKey, $validate);
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
public function addSourceLocalizedTextField($sourceKey, $fieldName, $colMap, $referenceSourceKey=null, $validate=true) {
|
| 186 |
+
$this->addSourceField($sourceKey, $fieldName, "text", true, $colMap, $referenceSourceKey, $validate);
|
| 187 |
+
}
|
| 188 |
+
|
| 189 |
+
public function addSourceStringField($sourceKey, $fieldName, $col, $referenceSourceKey=null, $validate=true) {
|
| 190 |
+
$this->addSourceField($sourceKey, $fieldName, "string", false, $col, $referenceSourceKey, $validate);
|
| 191 |
+
}
|
| 192 |
+
|
| 193 |
+
public function addSourceNumberField($sourceKey, $fieldName, $col, $referenceSourceKey=null, $validate=true) {
|
| 194 |
+
$this->addSourceField($sourceKey, $fieldName, "number", false, $col, $referenceSourceKey, $validate);
|
| 195 |
+
}
|
| 196 |
+
|
| 197 |
+
public function setCategoryField($sourceKey, $col, $referenceSourceKey="resource_categories", $validate=true) {
|
| 198 |
+
if($referenceSourceKey == "resource_categories") {
|
| 199 |
+
list($container, $sourceId) = $this->decodeSourceKey($sourceKey);
|
| 200 |
+
$referenceSourceKey = $this->encodesourceKey($container, $referenceSourceKey);
|
| 201 |
+
}
|
| 202 |
+
$this->addSourceField($sourceKey, "category", "hierarchical", false, $col, $referenceSourceKey, $validate);
|
| 203 |
+
}
|
| 204 |
+
|
| 205 |
+
public function addSourceField($sourceKey, $fieldName, $type, $localized, $colMap, $referenceSourceKey=null, $validate=true) {
|
| 206 |
+
list($container, $sourceId) = $this->decodeSourceKey($sourceKey);
|
| 207 |
+
if(!isset($this->sources[$container][$sourceId]['fields'])) {
|
| 208 |
+
$this->sources[$container][$sourceId]['fields'] = array();
|
| 209 |
+
}
|
| 210 |
+
$this->sources[$container][$sourceId]['fields'][$fieldName] = array('type'=>$type, 'localized'=>$localized, 'map'=>$colMap, 'referenceSourceKey'=>$referenceSourceKey);
|
| 211 |
+
if($this->sources[$container][$sourceId]['format'] == 'CSV') {
|
| 212 |
+
if($localized && $referenceSourceKey == null) {
|
| 213 |
+
if(!is_array($colMap)) {
|
| 214 |
+
throw new \Exception("'$fieldName': invalid column field name for a localized field (expect an array with a column name for each language array(lang=>colName)): " . serialize($colMap));
|
| 215 |
+
}
|
| 216 |
+
foreach($this->getLanguages() as $lang) {
|
| 217 |
+
if(!isset($colMap[$lang])) {
|
| 218 |
+
throw new \Exception("'$fieldName': no language column provided for language '$lang' in provided column map): " . serialize($colMap));
|
| 219 |
+
}
|
| 220 |
+
if(!is_string($colMap[$lang])) {
|
| 221 |
+
throw new \Exception("'$fieldName': invalid column field name for a non-localized field (expect a string): " . serialize($colMap));
|
| 222 |
+
}
|
| 223 |
+
if($validate) {
|
| 224 |
+
$this->validateColumnExistance($container, $sourceId, $colMap[$lang]);
|
| 225 |
+
}
|
| 226 |
+
}
|
| 227 |
+
} else {
|
| 228 |
+
if(!is_string($colMap)) {
|
| 229 |
+
throw new \Exception("'$fieldName' invalid column field name for a non-localized field (expect a string): " . serialize($colMap));
|
| 230 |
+
}
|
| 231 |
+
if($validate) {
|
| 232 |
+
$this->validateColumnExistance($container, $sourceId, $colMap);
|
| 233 |
+
}
|
| 234 |
+
}
|
| 235 |
+
}
|
| 236 |
+
}
|
| 237 |
+
|
| 238 |
+
public function setFieldIsMultiValued($sourceKey, $fieldName, $multiValued = true) {
|
| 239 |
+
$this->addFieldParameter($sourceKey, $fieldName, 'multiValued', $multiValued ? 'true' : 'false');
|
| 240 |
+
}
|
| 241 |
+
|
| 242 |
+
public function addSourceCustomerGuestProperty($sourceKey, $parameterValue) {
|
| 243 |
+
$this->addSourceParameter($sourceKey, "guest_property_id", $parameterValue);
|
| 244 |
+
}
|
| 245 |
+
|
| 246 |
+
public function addSourceParameter($sourceKey, $parameterName, $parameterValue) {
|
| 247 |
+
list($container, $sourceId) = $this->decodeSourceKey($sourceKey);
|
| 248 |
+
if(!isset($this->sources[$container][$sourceId])) {
|
| 249 |
+
throw new \Exception("trying to add a source parameter on sourceId '$sourceId', container '$container' while this source doesn't exist");
|
| 250 |
+
}
|
| 251 |
+
$this->sources[$container][$sourceId][$parameterName] = $parameterValue;
|
| 252 |
+
}
|
| 253 |
+
|
| 254 |
+
public function addFieldParameter($sourceKey, $fieldName, $parameterName, $parameterValue) {
|
| 255 |
+
list($container, $sourceId) = $this->decodeSourceKey($sourceKey);
|
| 256 |
+
if(!isset($this->sources[$container][$sourceId]['fields'][$fieldName])) {
|
| 257 |
+
throw new \Exception("trying to add a field parameter on sourceId '$sourceId', container '$container', fieldName '$fieldName' while this field doesn't exist");
|
| 258 |
+
}
|
| 259 |
+
if(!isset($this->sources[$container][$sourceId]['fields'][$fieldName]['fieldParameters'])) {
|
| 260 |
+
$this->sources[$container][$sourceId]['fields'][$fieldName]['fieldParameters'] = array();
|
| 261 |
+
}
|
| 262 |
+
$this->sources[$container][$sourceId]['fields'][$fieldName]['fieldParameters'][$parameterName] = $parameterValue;
|
| 263 |
+
}
|
| 264 |
+
|
| 265 |
+
public function getXML() {
|
| 266 |
+
|
| 267 |
+
$xml = new \SimpleXMLElement('<root/>');
|
| 268 |
+
|
| 269 |
+
//languages
|
| 270 |
+
$languagesXML = $xml->addChild('languages');
|
| 271 |
+
foreach ($this->getLanguages() as $lang) {
|
| 272 |
+
$language = $languagesXML->addChild('language');
|
| 273 |
+
$language->addAttribute('id', $lang);
|
| 274 |
+
}
|
| 275 |
+
|
| 276 |
+
//containers
|
| 277 |
+
$containers = $xml->addChild('containers');
|
| 278 |
+
foreach($this->sources as $containerName => $containerSources) {
|
| 279 |
+
|
| 280 |
+
$container = $containers->addChild('container');
|
| 281 |
+
$container->addAttribute('id', $containerName);
|
| 282 |
+
$container->addAttribute('type', $containerName);
|
| 283 |
+
|
| 284 |
+
$sources = $container->addChild('sources');
|
| 285 |
+
$properties = $container->addChild('properties');
|
| 286 |
+
|
| 287 |
+
//foreach source
|
| 288 |
+
foreach($containerSources as $sourceId => $sourceValues) {
|
| 289 |
+
|
| 290 |
+
$source = $sources->addChild('source');
|
| 291 |
+
$source->addAttribute('id', $sourceId);
|
| 292 |
+
$source->addAttribute('type', $sourceValues['type']);
|
| 293 |
+
|
| 294 |
+
$sourceValues['file'] = $this->getFileNameFromPath($sourceValues['filePath']);
|
| 295 |
+
|
| 296 |
+
$parameters = array(
|
| 297 |
+
'file'=>false,
|
| 298 |
+
'format'=>'CSV',
|
| 299 |
+
'encoding'=>'UTF-8',
|
| 300 |
+
'delimiter'=>',',
|
| 301 |
+
'enclosure'=>'"',
|
| 302 |
+
'escape'=>'\\\\',
|
| 303 |
+
'lineSeparator'=>"\\n"
|
| 304 |
+
);
|
| 305 |
+
|
| 306 |
+
switch($sourceValues['type']) {
|
| 307 |
+
case 'item_data_file':
|
| 308 |
+
$parameters['itemIdColumn'] = false;
|
| 309 |
+
break;
|
| 310 |
+
|
| 311 |
+
case 'hierarchical':
|
| 312 |
+
$parameters['referenceIdColumn'] = false;
|
| 313 |
+
$parameters['parentIdColumn'] = false;
|
| 314 |
+
$parameters['labelColumns'] = false;
|
| 315 |
+
break;
|
| 316 |
+
|
| 317 |
+
case 'resource':
|
| 318 |
+
$parameters['referenceIdColumn'] = false;
|
| 319 |
+
$parameters['itemIdColumn'] = false;
|
| 320 |
+
$parameters['labelColumns'] = false;
|
| 321 |
+
$sourceValues['itemIdColumn'] = $sourceValues['referenceIdColumn'];
|
| 322 |
+
break;
|
| 323 |
+
|
| 324 |
+
case 'transactions':
|
| 325 |
+
$parameters = $sourceValues;
|
| 326 |
+
unset($parameters['filePath']);
|
| 327 |
+
unset($parameters['type']);
|
| 328 |
+
unset($parameters['product_property_id']);
|
| 329 |
+
unset($parameters['customer_property_id']);
|
| 330 |
+
break;
|
| 331 |
+
}
|
| 332 |
+
|
| 333 |
+
foreach($parameters as $parameter => $defaultValue) {
|
| 334 |
+
$value = isset($sourceValues[$parameter]) ? $sourceValues[$parameter] : $defaultValue;
|
| 335 |
+
if($value === false) {
|
| 336 |
+
throw new \Exception("source parameter '$parameter' required but not defined in source id '$sourceId' for container '$containerName'");
|
| 337 |
+
}
|
| 338 |
+
$param = $source->addChild($parameter);
|
| 339 |
+
if(is_array($value)) {
|
| 340 |
+
foreach($value as $language => $languageColumn) {
|
| 341 |
+
$languageParam = $param->addChild("language");
|
| 342 |
+
$languageParam->addAttribute('name', $language);
|
| 343 |
+
$languageParam->addAttribute('value', $languageColumn);
|
| 344 |
+
}
|
| 345 |
+
} else {
|
| 346 |
+
$param->addAttribute('value', $value);
|
| 347 |
+
}
|
| 348 |
+
|
| 349 |
+
if($sourceValues['type'] == 'transactions') {
|
| 350 |
+
switch($parameter) {
|
| 351 |
+
case 'productIdColumn':
|
| 352 |
+
$param->addAttribute('product_property_id', $sourceValues['product_property_id']);
|
| 353 |
+
break;
|
| 354 |
+
|
| 355 |
+
case 'customerIdColumn':
|
| 356 |
+
$param->addAttribute('customer_property_id', $sourceValues['customer_property_id']);
|
| 357 |
+
|
| 358 |
+
if(isset($sourceValues['guest_property_id'])) {
|
| 359 |
+
$param->addAttribute('guest_property_id', $sourceValues['guest_property_id']);
|
| 360 |
+
}
|
| 361 |
+
break;
|
| 362 |
+
}
|
| 363 |
+
}
|
| 364 |
+
}
|
| 365 |
+
|
| 366 |
+
if(isset($sourceValues['fields'])) {
|
| 367 |
+
foreach($sourceValues['fields'] as $fieldId => $fieldValues) {
|
| 368 |
+
|
| 369 |
+
$property = $properties->addChild('property');
|
| 370 |
+
$property->addAttribute('id', $fieldId);
|
| 371 |
+
$property->addAttribute('type', $fieldValues['type']);
|
| 372 |
+
|
| 373 |
+
$transform = $property->addChild('transform');
|
| 374 |
+
$logic = $transform->addChild('logic');
|
| 375 |
+
$logic->addAttribute('source', $sourceId);
|
| 376 |
+
$referenceSourceKey = isset($fieldValues['referenceSourceKey']) ? $fieldValues['referenceSourceKey'] : null;
|
| 377 |
+
$logicType = $referenceSourceKey == null ? 'direct' : 'reference';
|
| 378 |
+
if($logicType == 'direct') {
|
| 379 |
+
if(isset($fieldValues['fieldParameters'])) {
|
| 380 |
+
foreach ($fieldValues['fieldParameters'] as $parameterName => $parameterValue) {
|
| 381 |
+
switch ($parameterName) {
|
| 382 |
+
case 'pc_fields':
|
| 383 |
+
case 'pc_tables':
|
| 384 |
+
$logicType = 'advanced';
|
| 385 |
+
}
|
| 386 |
+
}
|
| 387 |
+
}
|
| 388 |
+
}
|
| 389 |
+
$logic->addAttribute('type', $logicType);
|
| 390 |
+
if(is_array($fieldValues['map'])) {
|
| 391 |
+
foreach($this->getLanguages() as $lang) {
|
| 392 |
+
$field = $logic->addChild('field');
|
| 393 |
+
$field->addAttribute('column', $fieldValues['map'][$lang]);
|
| 394 |
+
$field->addAttribute('language', $lang);
|
| 395 |
+
}
|
| 396 |
+
} else {
|
| 397 |
+
$field = $logic->addChild('field');
|
| 398 |
+
$field->addAttribute('column', $fieldValues['map']);
|
| 399 |
+
}
|
| 400 |
+
|
| 401 |
+
$params = $property->addChild('params');
|
| 402 |
+
if($referenceSourceKey) {
|
| 403 |
+
$referenceSource = $params->addChild('referenceSource');
|
| 404 |
+
list($referenceContainer, $referenceSourceId) = $this->decodeSourceKey($referenceSourceKey);
|
| 405 |
+
$referenceSource->addAttribute('value', $referenceSourceId);
|
| 406 |
+
}
|
| 407 |
+
if(isset($fieldValues['fieldParameters'])) {
|
| 408 |
+
foreach($fieldValues['fieldParameters'] as $parameterName => $parameterValue) {
|
| 409 |
+
$fieldParameter = $params->addChild('fieldParameter');
|
| 410 |
+
$fieldParameter->addAttribute('name', $parameterName);
|
| 411 |
+
$fieldParameter->addAttribute('value', $parameterValue);
|
| 412 |
+
}
|
| 413 |
+
}
|
| 414 |
+
}
|
| 415 |
+
}
|
| 416 |
+
}
|
| 417 |
+
}
|
| 418 |
+
|
| 419 |
+
$dom = dom_import_simplexml($xml)->ownerDocument;
|
| 420 |
+
$dom->formatOutput = true;
|
| 421 |
+
return $dom->saveXML();
|
| 422 |
+
}
|
| 423 |
+
|
| 424 |
+
protected function callAPI($fields, $url, $temporaryFilePath=null)
|
| 425 |
+
{
|
| 426 |
+
$s = curl_init();
|
| 427 |
+
|
| 428 |
+
curl_setopt($s, CURLOPT_URL, $url);
|
| 429 |
+
curl_setopt($s, CURLOPT_TIMEOUT, 35000);
|
| 430 |
+
curl_setopt($s, CURLOPT_POST, true);
|
| 431 |
+
curl_setopt($s, CURLOPT_ENCODING, '');
|
| 432 |
+
curl_setopt($s, CURLOPT_RETURNTRANSFER, true);
|
| 433 |
+
curl_setopt($s, CURLOPT_POSTFIELDS, $fields);
|
| 434 |
+
|
| 435 |
+
$responseBody = curl_exec($s);
|
| 436 |
+
|
| 437 |
+
if($responseBody === false)
|
| 438 |
+
{
|
| 439 |
+
if(strpos(curl_error($s), "couldn't open file") !== false) {
|
| 440 |
+
if($temporaryFilePath !== null) {
|
| 441 |
+
throw new \Exception('There seems to be a problem with the folder BxData uses to temporarily store a zip file with all your files before sending it. As you are currently provided a path, this is most likely the problem. Please make sure it is a valid path, or leave it to null (default value), then BxData will use sys_get_temp_dir() + "/bxclient" which typically works fine.');
|
| 442 |
+
} else {
|
| 443 |
+
throw new \Exception('There seems to be a problem with the folder BxData uses to temporarily store a zip file with all your files before sending it. This means that the default path BxData uses sys_get_temp_dir() + "/bxclient" is not supported and you need to path a working path to the pushData function.');
|
| 444 |
+
}
|
| 445 |
+
}
|
| 446 |
+
throw new \Exception('Curl error: ' . curl_error($s));
|
| 447 |
+
}
|
| 448 |
+
|
| 449 |
+
curl_close($s);
|
| 450 |
+
if (strpos($responseBody, 'Internal Server Error') !== false) {
|
| 451 |
+
throw new \Exception($this->getError($responseBody));;
|
| 452 |
+
}
|
| 453 |
+
return $this->checkResponseBody($responseBody, $url);
|
| 454 |
+
}
|
| 455 |
+
|
| 456 |
+
public function getError($responseBody) {
|
| 457 |
+
return $responseBody;
|
| 458 |
+
}
|
| 459 |
+
|
| 460 |
+
public function checkResponseBody($responseBody, $url) {
|
| 461 |
+
if($responseBody == null) {
|
| 462 |
+
throw new \Exception("API response of call to $url is empty string, this is an error!");
|
| 463 |
+
}
|
| 464 |
+
$value = json_decode($responseBody, true);
|
| 465 |
+
if(sizeof($value) != 1 || !isset($value['token'])) {
|
| 466 |
+
if(!isset($value['changes'])) {
|
| 467 |
+
throw new \Exception($responseBody);
|
| 468 |
+
}
|
| 469 |
+
}
|
| 470 |
+
return $value;
|
| 471 |
+
}
|
| 472 |
+
|
| 473 |
+
public function pushDataSpecifications($ignoreDeltaException=false) {
|
| 474 |
+
|
| 475 |
+
if(!$ignoreDeltaException && $this->isDelta) {
|
| 476 |
+
throw new \Exception("You should not push specifications when you are pushing a delta file. Only do it when you are preparing full files. Set method parameter ignoreDeltaException to true to ignore this exception and publish anyway.");
|
| 477 |
+
}
|
| 478 |
+
|
| 479 |
+
$fields = array(
|
| 480 |
+
'username' => $this->bxClient->getUsername(),
|
| 481 |
+
'password' => $this->bxClient->getPassword(),
|
| 482 |
+
'account' => $this->bxClient->getAccount(false),
|
| 483 |
+
'owner' => $this->owner,
|
| 484 |
+
'xml' => $this->getXML()
|
| 485 |
+
);
|
| 486 |
+
|
| 487 |
+
$url = $this->host . self::URL_XML;
|
| 488 |
+
return $this->callAPI($fields, $url);
|
| 489 |
+
}
|
| 490 |
+
|
| 491 |
+
public function checkChanges() {
|
| 492 |
+
$this->publishOwnerChanges(false);
|
| 493 |
+
}
|
| 494 |
+
|
| 495 |
+
public function publishChanges() {
|
| 496 |
+
$this->publishOwnerChanges(true);
|
| 497 |
+
}
|
| 498 |
+
|
| 499 |
+
public function publishOwnerChanges($publish=true) {
|
| 500 |
+
if($this->isDev) {
|
| 501 |
+
$publish = false;
|
| 502 |
+
}
|
| 503 |
+
$fields = array(
|
| 504 |
+
'username' => $this->bxClient->getUsername(),
|
| 505 |
+
'password' => $this->bxClient->getPassword(),
|
| 506 |
+
'account' => $this->bxClient->getAccount(false),
|
| 507 |
+
'owner' => $this->owner,
|
| 508 |
+
'publish' => ($publish ? 'true' : 'false')
|
| 509 |
+
);
|
| 510 |
+
|
| 511 |
+
$url = $this->host . self::URL_PUBLISH_CONFIGURATION_CHANGES;
|
| 512 |
+
return $this->callAPI($fields, $url);
|
| 513 |
+
}
|
| 514 |
+
|
| 515 |
+
public function verifyCredentials() {
|
| 516 |
+
$fields = array(
|
| 517 |
+
'username' => $this->bxClient->getUsername(),
|
| 518 |
+
'password' => $this->bxClient->getPassword(),
|
| 519 |
+
'account' => $this->bxClient->getAccount(false),
|
| 520 |
+
'owner' => $this->owner
|
| 521 |
+
);
|
| 522 |
+
|
| 523 |
+
$url = $this->host . self::URL_VERIFY_CREDENTIALS;
|
| 524 |
+
return $this->callAPI($fields, $url);
|
| 525 |
+
}
|
| 526 |
+
|
| 527 |
+
public function getFileNameFromPath($filePath, $withoutExtension=false) {
|
| 528 |
+
$parts = explode('/', $filePath);
|
| 529 |
+
$file = $parts[sizeof($parts)-1];
|
| 530 |
+
if($withoutExtension) {
|
| 531 |
+
$parts = explode('.', $file);
|
| 532 |
+
return $parts[0];
|
| 533 |
+
}
|
| 534 |
+
return $file;
|
| 535 |
+
}
|
| 536 |
+
|
| 537 |
+
public function getFiles() {
|
| 538 |
+
$files = array();
|
| 539 |
+
foreach($this->sources as $container => $containerSources) {
|
| 540 |
+
foreach($containerSources as $sourceId => $sourceValues) {
|
| 541 |
+
if(!isset($sourceValues['file'])) {
|
| 542 |
+
$sourceValues['file'] = $this->getFileNameFromPath($sourceValues['filePath']);
|
| 543 |
+
}
|
| 544 |
+
$files[$sourceValues['file']] = $sourceValues['filePath'];
|
| 545 |
+
}
|
| 546 |
+
}
|
| 547 |
+
return $files;
|
| 548 |
+
}
|
| 549 |
+
|
| 550 |
+
public function createZip($temporaryFilePath=null, $name='bxdata.zip')
|
| 551 |
+
{
|
| 552 |
+
if($temporaryFilePath === null) {
|
| 553 |
+
$temporaryFilePath = sys_get_temp_dir() . '/bxclient';
|
| 554 |
+
}
|
| 555 |
+
|
| 556 |
+
if ($temporaryFilePath != "" && !file_exists($temporaryFilePath)) {
|
| 557 |
+
mkdir($temporaryFilePath);
|
| 558 |
+
}
|
| 559 |
+
|
| 560 |
+
$zipFilePath = $temporaryFilePath . '/' . $name;
|
| 561 |
+
|
| 562 |
+
if (file_exists($zipFilePath)) {
|
| 563 |
+
@unlink($zipFilePath);
|
| 564 |
+
}
|
| 565 |
+
|
| 566 |
+
$files = $this->getFiles();
|
| 567 |
+
|
| 568 |
+
$zip = new \ZipArchive();
|
| 569 |
+
if ($zip->open($zipFilePath, \ZipArchive::CREATE)) {
|
| 570 |
+
|
| 571 |
+
foreach ($files as $f => $filePath) {
|
| 572 |
+
if (!$zip->addFile($filePath, $f)) {
|
| 573 |
+
throw new \Exception(
|
| 574 |
+
'Synchronization failure: Failed to add file "' .
|
| 575 |
+
$filePath . '" to the zip "' .
|
| 576 |
+
$name . '". Please try again.'
|
| 577 |
+
);
|
| 578 |
+
}
|
| 579 |
+
}
|
| 580 |
+
|
| 581 |
+
if (!$zip->addFromString ('properties.xml', $this->getXML())) {
|
| 582 |
+
throw new \Exception(
|
| 583 |
+
'Synchronization failure: Failed to add xml string to the zip "' .
|
| 584 |
+
$name . '". Please try again.'
|
| 585 |
+
);
|
| 586 |
+
}
|
| 587 |
+
|
| 588 |
+
if (!$zip->close()) {
|
| 589 |
+
throw new \Exception(
|
| 590 |
+
'Synchronization failure: Failed to close the zip "' .
|
| 591 |
+
$name . '". Please try again.'
|
| 592 |
+
);
|
| 593 |
+
}
|
| 594 |
+
|
| 595 |
+
} else {
|
| 596 |
+
throw new \Exception(
|
| 597 |
+
'Synchronization failure: Failed to open the zip "' .
|
| 598 |
+
$name . '" for writing. Please check the permissions and try again.'
|
| 599 |
+
);
|
| 600 |
+
}
|
| 601 |
+
|
| 602 |
+
return $zipFilePath;
|
| 603 |
+
}
|
| 604 |
+
|
| 605 |
+
public function pushData($temporaryFilePath=null) {
|
| 606 |
+
|
| 607 |
+
$zipFile = $this->createZip($temporaryFilePath);
|
| 608 |
+
|
| 609 |
+
$fields = array(
|
| 610 |
+
'username' => $this->bxClient->getUsername(),
|
| 611 |
+
'password' => $this->bxClient->getPassword(),
|
| 612 |
+
'account' => $this->bxClient->getAccount(false),
|
| 613 |
+
'owner' => $this->owner,
|
| 614 |
+
'dev' => ($this->isDev ? 'true' : 'false'),
|
| 615 |
+
'delta' => ($this->isDelta ? 'true' : 'false'),
|
| 616 |
+
'data' => $this->getCurlFile($zipFile, "application/zip")
|
| 617 |
+
);
|
| 618 |
+
|
| 619 |
+
$url = $this->host . self::URL_ZIP;
|
| 620 |
+
return $this->callAPI($fields, $url, $temporaryFilePath);
|
| 621 |
+
}
|
| 622 |
+
|
| 623 |
+
protected function getCurlFile($filename, $type)
|
| 624 |
+
{
|
| 625 |
+
try {
|
| 626 |
+
if (class_exists('CURLFile')) {
|
| 627 |
+
return new \CURLFile($filename, $type);
|
| 628 |
+
}
|
| 629 |
+
} catch(\Exception $e) {}
|
| 630 |
+
return "@$filename;type=$type";
|
| 631 |
+
}
|
| 632 |
+
|
| 633 |
+
public function getTaskExecuteUrl($taskName) {
|
| 634 |
+
return $this->host . self::URL_EXECUTE_TASK . '?iframeAccount=' . $this->bxClient->getAccount() . '&task_process=' . $taskName;
|
| 635 |
+
}
|
| 636 |
+
|
| 637 |
+
public function publishChoices($isTest = false, $taskName="generate_optimization") {
|
| 638 |
+
|
| 639 |
+
if($this->isDev) {
|
| 640 |
+
$taskName .= '_dev';
|
| 641 |
+
}
|
| 642 |
+
if($isTest) {
|
| 643 |
+
$taskName .= '_test';
|
| 644 |
+
}
|
| 645 |
+
$url = $this->getTaskExecuteUrl($taskName);
|
| 646 |
+
file_get_contents($url);
|
| 647 |
+
}
|
| 648 |
+
|
| 649 |
+
public function prepareCorpusIndex($taskName="corpus") {
|
| 650 |
+
$url = $this->getTaskExecuteUrl($taskName);
|
| 651 |
+
file_get_contents($url);
|
| 652 |
+
}
|
| 653 |
+
|
| 654 |
+
public function prepareAutocompleteIndex($fields, $taskName="autocomplete") {
|
| 655 |
+
$url = $this->getTaskExecuteUrl($taskName);
|
| 656 |
+
file_get_contents($url);
|
| 657 |
+
}
|
| 658 |
+
}
|
app/code/community/Boxalino/Intelligence/lib/BxFacets.php
ADDED
|
@@ -0,0 +1,531 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
namespace com\boxalino\bxclient\v1;
|
| 4 |
+
|
| 5 |
+
class BxFacets
|
| 6 |
+
{
|
| 7 |
+
public $facets = array();
|
| 8 |
+
protected $facetResponse = null;
|
| 9 |
+
|
| 10 |
+
protected $selectedPriceValues = null;
|
| 11 |
+
|
| 12 |
+
protected $parameterPrefix = '';
|
| 13 |
+
|
| 14 |
+
protected $priceFieldName = 'discountedPrice';
|
| 15 |
+
|
| 16 |
+
public function setFacetResponse($facetResponse) {
|
| 17 |
+
$this->facetResponse = $facetResponse;
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
public function getCategoryFieldName() {
|
| 21 |
+
return "categories";
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
private $filters = array();
|
| 25 |
+
|
| 26 |
+
public function getFilters() {
|
| 27 |
+
return $this->filters;
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
public function addCategoryFacet($selectedValue=null, $order=2) {
|
| 31 |
+
if($selectedValue) {
|
| 32 |
+
$this->addFacet('category_id', $selectedValue, 'hierarchical', '1');
|
| 33 |
+
}
|
| 34 |
+
$this->addFacet($this->getCategoryFieldName(), null, 'hierarchical', $order);
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
public function addPriceRangeFacet($selectedValue=null, $order=2, $label='Price', $fieldName = 'discountedPrice') {
|
| 38 |
+
$this->priceFieldName = $fieldName;
|
| 39 |
+
$this->addRangedFacet($fieldName, $selectedValue, $label, $order, true);
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
public function addRangedFacet($fieldName, $selectedValue=null, $label=null, $order=2, $boundsOnly=false) {
|
| 43 |
+
$this->addFacet($fieldName, $selectedValue, 'ranged', $label, $order, $boundsOnly);
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
public function addFacet($fieldName, $selectedValue=null, $type='string', $label=null, $order=2, $boundsOnly=false) {
|
| 47 |
+
$selectedValues = array();
|
| 48 |
+
if($selectedValue) {
|
| 49 |
+
$selectedValues[] = $selectedValue;
|
| 50 |
+
}
|
| 51 |
+
$this->facets[$fieldName] = array('label'=>$label, 'type'=>$type, 'order'=>$order, 'selectedValues'=>$selectedValues, 'boundsOnly'=>$boundsOnly);
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
public function setParameterPrefix($parameterPrefix) {
|
| 55 |
+
$this->parameterPrefix = $parameterPrefix;
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
protected function isCategories($fieldName) {
|
| 59 |
+
return strpos($fieldName, 'categories') !== false ;
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
public function getFacetParameterName($fieldName) {
|
| 63 |
+
$parameterName = $fieldName;
|
| 64 |
+
if($this->isCategories($fieldName)) {
|
| 65 |
+
$parameterName = 'category_id';
|
| 66 |
+
}
|
| 67 |
+
return $this->parameterPrefix . $parameterName;
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
public function getFieldNames() {
|
| 71 |
+
return array_keys($this->facets);
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
protected function getFacetResponse($fieldName) {
|
| 75 |
+
foreach($this->facetResponse as $facetResponse) {
|
| 76 |
+
if($facetResponse->fieldName == $fieldName) {
|
| 77 |
+
return $facetResponse;
|
| 78 |
+
}
|
| 79 |
+
}
|
| 80 |
+
throw new \Exception("trying to get facet response on unexisting fieldname " . $fieldName);
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
protected function getFacetType($fieldName) {
|
| 84 |
+
$type = 'string';
|
| 85 |
+
if(isset($this->facets[$fieldName])) {
|
| 86 |
+
$type = $this->facets[$fieldName]['type'];
|
| 87 |
+
}
|
| 88 |
+
return $type;
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
protected function buildTree($response, $parents = array(), $parentLevel = 0) {
|
| 92 |
+
if(sizeof($parents)==0) {
|
| 93 |
+
foreach($response as $node) {
|
| 94 |
+
if(sizeof($node->hierarchy) == 1) {
|
| 95 |
+
$parents = $node->hierarchy;
|
| 96 |
+
}
|
| 97 |
+
}
|
| 98 |
+
}
|
| 99 |
+
$children = array();
|
| 100 |
+
foreach($response as $node) {
|
| 101 |
+
if(sizeof($node->hierarchy) == $parentLevel + 2) {
|
| 102 |
+
$allTrue = true;
|
| 103 |
+
foreach($parents as $k => $v) {
|
| 104 |
+
if(!isset($node->hierarchy[$k]) || $node->hierarchy[$k] != $v) {
|
| 105 |
+
$allTrue = false;
|
| 106 |
+
}
|
| 107 |
+
}
|
| 108 |
+
if($allTrue) {
|
| 109 |
+
$children[] = $this->buildTree($response, $node->hierarchy, $parentLevel+1);
|
| 110 |
+
}
|
| 111 |
+
}
|
| 112 |
+
}
|
| 113 |
+
foreach($response as $node) {
|
| 114 |
+
if(sizeof($node->hierarchy) == $parentLevel + 1) {
|
| 115 |
+
$allTrue = true;
|
| 116 |
+
foreach($node->hierarchy as $k => $v) {
|
| 117 |
+
if($parents[$k] != $v) {
|
| 118 |
+
$allTrue = false;
|
| 119 |
+
}
|
| 120 |
+
}
|
| 121 |
+
if($allTrue) {
|
| 122 |
+
return array('node'=>$node, 'children'=>$children);
|
| 123 |
+
}
|
| 124 |
+
}
|
| 125 |
+
}
|
| 126 |
+
return null;
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
protected function getFirstNodeWithSeveralChildren($tree) {
|
| 130 |
+
if(sizeof($tree['children']) == 0) {
|
| 131 |
+
return null;
|
| 132 |
+
}
|
| 133 |
+
if(sizeof($tree['children']) > 1) {
|
| 134 |
+
return $tree;
|
| 135 |
+
}
|
| 136 |
+
return $this->getFirstNodeWithSeveralChildren($tree['children'][0]);
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
public function getSelectedTreeNode($tree) {
|
| 140 |
+
if(!isset($this->facets['category_id'])){
|
| 141 |
+
return $tree;
|
| 142 |
+
}
|
| 143 |
+
if(!$tree['node']){
|
| 144 |
+
return null;
|
| 145 |
+
}
|
| 146 |
+
$parts = explode('/', $tree['node']->stringValue);
|
| 147 |
+
if($parts[0] == $this->facets['category_id']['selectedValues'][0]) {
|
| 148 |
+
return $tree;
|
| 149 |
+
}
|
| 150 |
+
foreach($tree['children'] as $node) {
|
| 151 |
+
$result = $this->getSelectedTreeNode($node);
|
| 152 |
+
if($result != null) {
|
| 153 |
+
return $result;
|
| 154 |
+
}
|
| 155 |
+
}
|
| 156 |
+
return null;
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
protected function getFacetKeysValues($fieldName) {
|
| 160 |
+
if($fieldName == "") {
|
| 161 |
+
return array();
|
| 162 |
+
}
|
| 163 |
+
$facetValues = array();
|
| 164 |
+
$facetResponse = $this->getFacetResponse($fieldName);
|
| 165 |
+
$type = $this->getFacetType($fieldName);
|
| 166 |
+
switch($type) {
|
| 167 |
+
case 'hierarchical':
|
| 168 |
+
$tree = $this->buildTree($facetResponse->values);
|
| 169 |
+
$tree = $this->getSelectedTreeNode($tree);
|
| 170 |
+
$node = $this->getFirstNodeWithSeveralChildren($tree);
|
| 171 |
+
if($node) {
|
| 172 |
+
foreach($node['children'] as $node) {
|
| 173 |
+
$facetValues[$node['node']->stringValue] = $node['node'];
|
| 174 |
+
}
|
| 175 |
+
}
|
| 176 |
+
break;
|
| 177 |
+
case 'ranged':
|
| 178 |
+
foreach($facetResponse->values as $facetValue) {
|
| 179 |
+
$facetValues[$facetValue->rangeFromInclusive . '-' . $facetValue->rangeToExclusive] = $facetValue;
|
| 180 |
+
}
|
| 181 |
+
break;
|
| 182 |
+
default:
|
| 183 |
+
foreach($facetResponse->values as $facetValue) {
|
| 184 |
+
$facetValues[$facetValue->stringValue] = $facetValue;
|
| 185 |
+
}
|
| 186 |
+
break;
|
| 187 |
+
}
|
| 188 |
+
return $facetValues;
|
| 189 |
+
}
|
| 190 |
+
|
| 191 |
+
public function getSelectedValues($fieldName) {
|
| 192 |
+
$selectedValues = array();
|
| 193 |
+
foreach($this->getFacetValues($fieldName) as $key) {
|
| 194 |
+
if($this->isFacetValueSelected($fieldName, $key)) {
|
| 195 |
+
$selectedValues[] = $key;
|
| 196 |
+
}
|
| 197 |
+
}
|
| 198 |
+
return $selectedValues;
|
| 199 |
+
}
|
| 200 |
+
|
| 201 |
+
protected function getFacetByFieldName($fieldName) {
|
| 202 |
+
foreach($this->facets as $fn => $facet) {
|
| 203 |
+
if($fieldName == $fn) {
|
| 204 |
+
return $facet;
|
| 205 |
+
}
|
| 206 |
+
}
|
| 207 |
+
return null;
|
| 208 |
+
}
|
| 209 |
+
|
| 210 |
+
public function isSelected($fieldName, $ignoreCategories=false) {
|
| 211 |
+
if($fieldName == "") {
|
| 212 |
+
return false;
|
| 213 |
+
}
|
| 214 |
+
if($this->isCategories($fieldName)) {
|
| 215 |
+
if($ignoreCategories) {
|
| 216 |
+
return false;
|
| 217 |
+
}
|
| 218 |
+
}
|
| 219 |
+
if(sizeof($this->getSelectedValues($fieldName)) > 0) {
|
| 220 |
+
return true;
|
| 221 |
+
}
|
| 222 |
+
$facet = $this->getFacetByFieldName($fieldName);
|
| 223 |
+
if($facet != null) {
|
| 224 |
+
if($facet['type'] == 'hierarchical') {
|
| 225 |
+
$facetResponse = $this->getFacetResponse($fieldName);
|
| 226 |
+
$tree = $this->buildTree($facetResponse->values);
|
| 227 |
+
$tree = $this->getSelectedTreeNode($tree);
|
| 228 |
+
return $tree && sizeof($tree['node']->hierarchy)>1;
|
| 229 |
+
}
|
| 230 |
+
return isset($this->facets[$fieldName]['selectedValues']) && sizeof($this->facets[$fieldName]['selectedValues']) > 0;
|
| 231 |
+
}
|
| 232 |
+
return false;
|
| 233 |
+
}
|
| 234 |
+
|
| 235 |
+
public function getTreeParent($tree, $treeEnd) {
|
| 236 |
+
foreach($tree['children'] as $child) {
|
| 237 |
+
if($child['node']->stringValue == $treeEnd['node']->stringValue) {
|
| 238 |
+
return $tree;
|
| 239 |
+
}
|
| 240 |
+
$parent = $this->getTreeParent($child, $treeEnd);
|
| 241 |
+
if($parent) {
|
| 242 |
+
return $parent;
|
| 243 |
+
}
|
| 244 |
+
}
|
| 245 |
+
return null;
|
| 246 |
+
}
|
| 247 |
+
|
| 248 |
+
public function getParentCategories() {
|
| 249 |
+
$fieldName = 'categories';
|
| 250 |
+
$facetResponse = $this->getFacetResponse($fieldName);
|
| 251 |
+
$tree = $this->buildTree($facetResponse->values);
|
| 252 |
+
$treeEnd = $this->getSelectedTreeNode($tree);
|
| 253 |
+
if($treeEnd == null) {
|
| 254 |
+
return array();
|
| 255 |
+
}
|
| 256 |
+
if($treeEnd['node']->stringValue == $tree['node']->stringValue) {
|
| 257 |
+
return array();
|
| 258 |
+
}
|
| 259 |
+
$parents = array();
|
| 260 |
+
$parent = $treeEnd;
|
| 261 |
+
while($parent) {
|
| 262 |
+
$parts = explode('/', $parent['node']->stringValue);
|
| 263 |
+
$parents[] = array($parts[0], $parts[sizeof($parts)-1]);
|
| 264 |
+
$parent = $this->getTreeParent($tree, $parent);
|
| 265 |
+
}
|
| 266 |
+
krsort($parents);
|
| 267 |
+
$final = array();
|
| 268 |
+
foreach($parents as $v) {
|
| 269 |
+
$final[$v[0]] = $v[1];
|
| 270 |
+
}
|
| 271 |
+
return $final;
|
| 272 |
+
}
|
| 273 |
+
public function getParentCategoriesHitCount($id){
|
| 274 |
+
$fieldName = 'categories';
|
| 275 |
+
$facetResponse = $this->getFacetResponse($fieldName);
|
| 276 |
+
$tree = $this->buildTree($facetResponse->values);
|
| 277 |
+
$treeEnd = $this->getSelectedTreeNode($tree);
|
| 278 |
+
if($treeEnd == null) {
|
| 279 |
+
return $tree['node']->hitCount;
|
| 280 |
+
}
|
| 281 |
+
if($treeEnd['node']->stringValue == $tree['node']->stringValue) {
|
| 282 |
+
return $tree['node']->hitCount;
|
| 283 |
+
}
|
| 284 |
+
$parent = $treeEnd;
|
| 285 |
+
while($parent) {
|
| 286 |
+
if($parent['node']->hierarchyId == $id){
|
| 287 |
+
return $parent['node']->hitCount;
|
| 288 |
+
}
|
| 289 |
+
$parent = $this->getTreeParent($tree, $parent);
|
| 290 |
+
}
|
| 291 |
+
return 0;
|
| 292 |
+
}
|
| 293 |
+
|
| 294 |
+
public function getSelectedValueLabel($fieldName, $index=0) {
|
| 295 |
+
|
| 296 |
+
if($fieldName == "") {
|
| 297 |
+
return "";
|
| 298 |
+
}
|
| 299 |
+
$svs = $this->getSelectedValues($fieldName);
|
| 300 |
+
|
| 301 |
+
if(isset($svs[$index])) {
|
| 302 |
+
return $this->getFacetValueLabel($fieldName, $svs[$index]);
|
| 303 |
+
}
|
| 304 |
+
$facet = $this->getFacetByFieldName($fieldName);
|
| 305 |
+
if($facet != null) {
|
| 306 |
+
if($facet['type'] == 'hierarchical') {
|
| 307 |
+
$facetResponse = $this->getFacetResponse($fieldName);
|
| 308 |
+
$tree = $this->buildTree($facetResponse->values);
|
| 309 |
+
$tree = $this->getSelectedTreeNode($tree);
|
| 310 |
+
$parts = explode('/', $tree['node']->stringValue);
|
| 311 |
+
return $parts[sizeof($parts)-1];
|
| 312 |
+
}
|
| 313 |
+
if($facet['type'] == 'ranged') {
|
| 314 |
+
if(isset($this->facets[$fieldName]['selectedValues'][0])) {
|
| 315 |
+
$values = explode('-', $this->facets[$fieldName]['selectedValues'][0]);
|
| 316 |
+
|
| 317 |
+
return $this->facets[$fieldName]['selectedValues'][0];
|
| 318 |
+
}
|
| 319 |
+
}
|
| 320 |
+
if(isset($facet['selectedValues'][0])) {
|
| 321 |
+
return $facet['selectedValues'][0];
|
| 322 |
+
}
|
| 323 |
+
return "";
|
| 324 |
+
}
|
| 325 |
+
return "";
|
| 326 |
+
}
|
| 327 |
+
|
| 328 |
+
public function getPriceFieldName() {
|
| 329 |
+
return $this->priceFieldName;
|
| 330 |
+
}
|
| 331 |
+
|
| 332 |
+
public function getCategoriesKeyLabels() {
|
| 333 |
+
$categoryValueArray = array();
|
| 334 |
+
foreach ($this->getCategories() as $v){
|
| 335 |
+
$label = $this->getCategoryValueLabel($v);
|
| 336 |
+
$categoryValueArray[$label] = $v;
|
| 337 |
+
}
|
| 338 |
+
return $categoryValueArray;
|
| 339 |
+
}
|
| 340 |
+
|
| 341 |
+
public function getCategories() {
|
| 342 |
+
return $this->getFacetValues($this->getCategoryFieldName());
|
| 343 |
+
}
|
| 344 |
+
|
| 345 |
+
public function getPriceRanges() {
|
| 346 |
+
|
| 347 |
+
return $this->getFacetValues($this->getPriceFieldName());
|
| 348 |
+
}
|
| 349 |
+
|
| 350 |
+
public function getFacetValues($fieldName) {
|
| 351 |
+
return array_keys($this->getFacetKeysValues($fieldName));
|
| 352 |
+
}
|
| 353 |
+
|
| 354 |
+
public function getFacetLabel($fieldName) {
|
| 355 |
+
if(isset($this->facets[$fieldName])) {
|
| 356 |
+
return $this->facets[$fieldName]['label'];
|
| 357 |
+
}
|
| 358 |
+
return $fieldName;
|
| 359 |
+
}
|
| 360 |
+
|
| 361 |
+
protected function getFacetValueArray($fieldName, $facetValue) {
|
| 362 |
+
|
| 363 |
+
if(($fieldName == $this->priceFieldName) && ($this->selectedPriceValues != null)){
|
| 364 |
+
$from = round($this->selectedPriceValues[0]->rangeFromInclusive, 2);
|
| 365 |
+
$to = round($this->selectedPriceValues[0]->rangeToExclusive, 2);
|
| 366 |
+
$valueLabel = $from . ' - ' . $to;
|
| 367 |
+
$paramValue = "$from-$to";
|
| 368 |
+
return array($valueLabel, $paramValue, null, true);
|
| 369 |
+
}
|
| 370 |
+
|
| 371 |
+
$keyValues = $this->getFacetKeysValues($fieldName);
|
| 372 |
+
|
| 373 |
+
if(is_array($facetValue)){
|
| 374 |
+
$facetValue = reset($facetValue);
|
| 375 |
+
}
|
| 376 |
+
if(!isset($keyValues[$facetValue])) {
|
| 377 |
+
throw new \Exception("Requesting an invalid facet values for fieldname: " . $fieldName . ", requested value: " . $facetValue . ", available values . " . implode(',', array_keys($keyValues)));
|
| 378 |
+
}
|
| 379 |
+
|
| 380 |
+
$type = $this->getFacetType($fieldName);
|
| 381 |
+
$fv = isset($keyValues[$facetValue]) ? $keyValues[$facetValue] : null;
|
| 382 |
+
switch($type) {
|
| 383 |
+
case 'hierarchical':
|
| 384 |
+
$parts = explode("/", $fv->stringValue);
|
| 385 |
+
return array($parts[sizeof($parts)-1], $parts[0], $fv->hitCount, $fv->selected);
|
| 386 |
+
case 'ranged':
|
| 387 |
+
$from = round($fv->rangeFromInclusive, 2);
|
| 388 |
+
$to = round($fv->rangeToExclusive, 2);
|
| 389 |
+
$valueLabel = $from . ' - ' . $to;
|
| 390 |
+
$paramValue = $fv->stringValue;
|
| 391 |
+
$paramValue = "$from-$to";
|
| 392 |
+
return array($valueLabel, $paramValue, $fv->hitCount, $fv->selected);
|
| 393 |
+
|
| 394 |
+
default:
|
| 395 |
+
$fv = $keyValues[$facetValue];
|
| 396 |
+
return array($fv->stringValue, $fv->stringValue, $fv->hitCount, $fv->selected);
|
| 397 |
+
}
|
| 398 |
+
}
|
| 399 |
+
|
| 400 |
+
public function getCategoryValueLabel($facetValue){
|
| 401 |
+
return $this->getFacetValueLabel($this->getCategoryFieldName(), $facetValue);
|
| 402 |
+
}
|
| 403 |
+
|
| 404 |
+
public function getSelectedPriceRange(){
|
| 405 |
+
$valueLabel = null;
|
| 406 |
+
if($this->selectedPriceValues !== null && ($this->selectedPriceValues != null)){
|
| 407 |
+
$from = round($this->selectedPriceValues[0]->rangeFromInclusive, 2);
|
| 408 |
+
$to = round($this->selectedPriceValues[0]->rangeToExclusive, 2);
|
| 409 |
+
$valueLabel = $from . '-' . $to;
|
| 410 |
+
}
|
| 411 |
+
return $valueLabel;
|
| 412 |
+
}
|
| 413 |
+
|
| 414 |
+
public function getPriceValueLabel($facetValue) {
|
| 415 |
+
return $this->getFacetValueLabel($this->getPriceFieldName(), $facetValue);
|
| 416 |
+
}
|
| 417 |
+
|
| 418 |
+
public function getFacetValueLabel($fieldName, $facetValue) {
|
| 419 |
+
list($label, $parameterValue, $hitCount, $selected) = $this->getFacetValueArray($fieldName, $facetValue);
|
| 420 |
+
return $label;
|
| 421 |
+
}
|
| 422 |
+
|
| 423 |
+
public function getCategoryValueCount($facetValue){
|
| 424 |
+
return $this->getFacetValueCount($this->getCategoryFieldName(), $facetValue);
|
| 425 |
+
}
|
| 426 |
+
|
| 427 |
+
public function getPriceValueCount($facetValue) {
|
| 428 |
+
return $this->getFacetValueCount($this->getPriceFieldName(), $facetValue);
|
| 429 |
+
}
|
| 430 |
+
|
| 431 |
+
public function getFacetValueCount($fieldName, $facetValue) {
|
| 432 |
+
list($label, $parameterValue, $hitCount, $selected) = $this->getFacetValueArray($fieldName, $facetValue);
|
| 433 |
+
return $hitCount;
|
| 434 |
+
}
|
| 435 |
+
|
| 436 |
+
public function getCategoryValueId($facetValue) {
|
| 437 |
+
return $this->getFacetValueParameterValue($this->getCategoryFieldName(), $facetValue);
|
| 438 |
+
}
|
| 439 |
+
|
| 440 |
+
public function getPriceValueParameterValue($facetValue) {
|
| 441 |
+
return $this->getFacetValueParameterValue($this->getPriceFieldName(), $facetValue);
|
| 442 |
+
}
|
| 443 |
+
|
| 444 |
+
public function getFacetValueParameterValue($fieldName, $facetValue) {
|
| 445 |
+
list($label, $parameterValue, $hitCount, $selected) = $this->getFacetValueArray($fieldName, $facetValue);
|
| 446 |
+
return $parameterValue;
|
| 447 |
+
}
|
| 448 |
+
|
| 449 |
+
public function isPriceValueSelected($facetValue) {
|
| 450 |
+
return $this->isFacetValueSelected($this->getPriceFieldName(), $facetValue);
|
| 451 |
+
}
|
| 452 |
+
|
| 453 |
+
public function isFacetValueSelected($fieldName, $facetValue) {
|
| 454 |
+
list($label, $parameterValue, $hitCount, $selected) = $this->getFacetValueArray($fieldName, $facetValue);
|
| 455 |
+
return $selected;
|
| 456 |
+
}
|
| 457 |
+
|
| 458 |
+
public function getThriftFacets() {
|
| 459 |
+
|
| 460 |
+
$thriftFacets = array();
|
| 461 |
+
|
| 462 |
+
foreach($this->facets as $fieldName => $facet) {
|
| 463 |
+
$type = $facet['type'];
|
| 464 |
+
$order = $facet['order'];
|
| 465 |
+
|
| 466 |
+
if($fieldName == 'discountedPrice'){
|
| 467 |
+
$this->selectedPriceValues = $this->facetSelectedValue($fieldName, $type);
|
| 468 |
+
}
|
| 469 |
+
|
| 470 |
+
$facetRequest = new \com\boxalino\p13n\api\thrift\FacetRequest();
|
| 471 |
+
$facetRequest->fieldName = $fieldName;
|
| 472 |
+
$facetRequest->numerical = $type == 'ranged' ? true : $type == 'numerical' ? true : false;
|
| 473 |
+
$facetRequest->range = $type == 'ranged' ? true : false;
|
| 474 |
+
$facetRequest->boundsOnly = $facet['boundsOnly'];
|
| 475 |
+
$facetRequest->selectedValues = $this->facetSelectedValue($fieldName, $type);
|
| 476 |
+
$facetRequest->sortOrder = isset($order) && $order == 1 ? 1 : 2;
|
| 477 |
+
$thriftFacets[] = $facetRequest;
|
| 478 |
+
}
|
| 479 |
+
|
| 480 |
+
return $thriftFacets;
|
| 481 |
+
}
|
| 482 |
+
|
| 483 |
+
private function facetSelectedValue($fieldName, $option)
|
| 484 |
+
{
|
| 485 |
+
$selectedFacets = array();
|
| 486 |
+
if (isset($this->facets[$fieldName]['selectedValues'])) {
|
| 487 |
+
foreach ($this->facets[$fieldName]['selectedValues'] as $value) {
|
| 488 |
+
$selectedFacet = new \com\boxalino\p13n\api\thrift\FacetValue();
|
| 489 |
+
if ($option == 'ranged') {
|
| 490 |
+
$rangedValue = explode('-', $value);
|
| 491 |
+
if ($rangedValue[0] != '*') {
|
| 492 |
+
$selectedFacet->rangeFromInclusive = $rangedValue[0];
|
| 493 |
+
}
|
| 494 |
+
if ($rangedValue[1] != '*') {
|
| 495 |
+
$selectedFacet->rangeToExclusive = $rangedValue[1] + 0.01;
|
| 496 |
+
}
|
| 497 |
+
} else {
|
| 498 |
+
$selectedFacet->stringValue = $value;
|
| 499 |
+
}
|
| 500 |
+
$selectedFacets[] = $selectedFacet;
|
| 501 |
+
|
| 502 |
+
}
|
| 503 |
+
return $selectedFacets;
|
| 504 |
+
}
|
| 505 |
+
return;
|
| 506 |
+
}
|
| 507 |
+
|
| 508 |
+
public function getParentId($fieldName, $id){
|
| 509 |
+
$hierarchy = array();
|
| 510 |
+
|
| 511 |
+
foreach ($this->facetResponse as $response) {
|
| 512 |
+
if($response->fieldName == $fieldName){
|
| 513 |
+
foreach($response->values as $item){
|
| 514 |
+
if($item->hierarchyId == $id){
|
| 515 |
+
$hierarchy = $item->hierarchy;
|
| 516 |
+
if(count($hierarchy) < 4) {
|
| 517 |
+
return 1;
|
| 518 |
+
}
|
| 519 |
+
}
|
| 520 |
+
}
|
| 521 |
+
foreach ($response->values as $item) {
|
| 522 |
+
if (count($item->hierarchy) == count($hierarchy) - 1) {
|
| 523 |
+
if ($item->hierarchy[count($hierarchy) - 2] === $hierarchy[count($hierarchy) - 2]) {
|
| 524 |
+
return $item->hierarchyId;
|
| 525 |
+
}
|
| 526 |
+
}
|
| 527 |
+
}
|
| 528 |
+
}
|
| 529 |
+
}
|
| 530 |
+
}
|
| 531 |
+
}
|
app/code/community/Boxalino/Intelligence/lib/BxFilter.php
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
namespace com\boxalino\bxclient\v1;
|
| 4 |
+
|
| 5 |
+
class BxFilter
|
| 6 |
+
{
|
| 7 |
+
protected $fieldName;
|
| 8 |
+
protected $values;
|
| 9 |
+
protected $negative;
|
| 10 |
+
|
| 11 |
+
protected $hierarchyId = null;
|
| 12 |
+
protected $hierarchy = null;
|
| 13 |
+
protected $rangeFrom = null;
|
| 14 |
+
protected $rangeTo = null;
|
| 15 |
+
|
| 16 |
+
public function __construct($fieldName, $values=array(), $negative = false) {
|
| 17 |
+
$this->fieldName = $fieldName;
|
| 18 |
+
$this->values = $values;
|
| 19 |
+
$this->negative = $negative;
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
public function getFieldName() {
|
| 23 |
+
return $this->fieldName;
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
public function getValues() {
|
| 27 |
+
return $this->values;
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
public function isNegative() {
|
| 31 |
+
return $this->negative;
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
public function getHierarchyId() {
|
| 35 |
+
return $this->hierarchyId;
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
public function setHierarchyId($hierarchyId) {
|
| 39 |
+
$this->hierarchyId = $hierarchyId;
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
public function getHierarchy() {
|
| 43 |
+
return $this->hierarchy;
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
public function setHierarchy($hierarchy) {
|
| 47 |
+
$this->hierarchy = $hierarchy;
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
public function getRangeFrom() {
|
| 51 |
+
return $this->rangeFrom;
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
public function setRangeFrom($rangeFrom) {
|
| 55 |
+
$this->rangeFrom = $rangeFrom;
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
public function getRangeTo() {
|
| 59 |
+
return $this->rangeTo;
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
public function setRangeTo($rangeTo) {
|
| 63 |
+
$this->rangeTo = $rangeTo;
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
public function getThriftFilter() {
|
| 67 |
+
$filter = new \com\boxalino\p13n\api\thrift\Filter();
|
| 68 |
+
$filter->fieldName = $this->fieldName;
|
| 69 |
+
$filter->negative = $this->negative;
|
| 70 |
+
$filter->stringValues = $this->values;
|
| 71 |
+
if($this->hierarchyId) {
|
| 72 |
+
$filter->hierarchyId = $this->hierarchyId;
|
| 73 |
+
}
|
| 74 |
+
if($this->hierarchy) {
|
| 75 |
+
$filter->hierarchy = $this->hierarchy;
|
| 76 |
+
}
|
| 77 |
+
if($this->rangeFrom) {
|
| 78 |
+
$filter->rangeFrom = $this->rangeFrom;
|
| 79 |
+
}
|
| 80 |
+
if($this->rangeTo) {
|
| 81 |
+
$filter->rangeTo = $this->rangeTo;
|
| 82 |
+
}
|
| 83 |
+
return $filter;
|
| 84 |
+
}
|
| 85 |
+
}
|
app/code/community/Boxalino/Intelligence/lib/BxRecommendationRequest.php
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
namespace com\boxalino\bxclient\v1;
|
| 4 |
+
|
| 5 |
+
class BxRecommendationRequest extends BxRequest
|
| 6 |
+
{
|
| 7 |
+
}
|
app/code/community/Boxalino/Intelligence/lib/BxRequest.php
ADDED
|
@@ -0,0 +1,255 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
namespace com\boxalino\bxclient\v1;
|
| 4 |
+
|
| 5 |
+
class BxRequest
|
| 6 |
+
{
|
| 7 |
+
protected $language;
|
| 8 |
+
protected $groupBy;
|
| 9 |
+
protected $choiceId;
|
| 10 |
+
protected $min;
|
| 11 |
+
protected $max;
|
| 12 |
+
protected $withRelaxation;
|
| 13 |
+
|
| 14 |
+
protected $indexId = null;
|
| 15 |
+
protected $returnFields = array();
|
| 16 |
+
protected $offset = 0;
|
| 17 |
+
protected $queryText = "";
|
| 18 |
+
protected $bxFacets = null;
|
| 19 |
+
protected $bxSortFields = null;
|
| 20 |
+
protected $bxFilters = array();
|
| 21 |
+
protected $orFilters = false;
|
| 22 |
+
|
| 23 |
+
public function __construct($language, $choiceId, $max=10, $min=0) {
|
| 24 |
+
if($choiceId == ''){
|
| 25 |
+
throw new \Exception('BxRequest created with null choiceId');
|
| 26 |
+
}
|
| 27 |
+
$this->language = $language;
|
| 28 |
+
$this->choiceId = $choiceId;
|
| 29 |
+
$this->min = (float)$min;
|
| 30 |
+
$this->max = (float)$max;
|
| 31 |
+
if($this->max == 0) {
|
| 32 |
+
$this->max = 1;
|
| 33 |
+
}
|
| 34 |
+
$this->withRelaxation = $choiceId == 'search';
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
public function getWithRelaxation() {
|
| 38 |
+
return $this->withRelaxation;
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
public function setWithRelaxation($withRelaxation) {
|
| 42 |
+
$this->withRelaxation = $withRelaxation;
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
public function getReturnFields() {
|
| 46 |
+
return $this->returnFields;
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
public function setReturnFields($returnFields) {
|
| 50 |
+
$this->returnFields = $returnFields;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
public function getOffset() {
|
| 54 |
+
return $this->offset;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
public function setOffset($offset) {
|
| 58 |
+
$this->offset = $offset;
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
public function getQuerytext() {
|
| 62 |
+
return $this->queryText;
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
public function setQuerytext($queryText) {
|
| 66 |
+
$this->queryText = $queryText;
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
public function getFacets() {
|
| 70 |
+
return $this->bxFacets;
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
public function setFacets($bxFacets) {
|
| 74 |
+
$this->bxFacets = $bxFacets;
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
public function getSortFields() {
|
| 78 |
+
return $this->bxSortFields;
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
public function setSortFields($bxSortFields) {
|
| 82 |
+
$this->bxSortFields = $bxSortFields;
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
public function getFilters() {
|
| 86 |
+
$filters = $this->bxFilters;
|
| 87 |
+
if($this->getFacets()) {
|
| 88 |
+
foreach($this->getFacets()->getFilters() as $filter) {
|
| 89 |
+
$filters[] = $filter;
|
| 90 |
+
}
|
| 91 |
+
}
|
| 92 |
+
return $this->bxFilters;
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
public function setFilters($bxFilters) {
|
| 96 |
+
$this->bxFilters = $bxFilters;
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
public function addFilter($bxFilter) {
|
| 100 |
+
$this->bxFilters[$bxFilter->getFieldName()] = $bxFilter;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
public function getOrFilters() {
|
| 104 |
+
return $this->orFilters;
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
public function setOrFilters($orFilters) {
|
| 108 |
+
$this->orFilters = $orFilters;
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
public function addSortField($field, $reverse = false) {
|
| 112 |
+
if($this->bxSortFields == null) {
|
| 113 |
+
$this->bxSortFields = new \com\boxalino\bxclient\v1\BxSortFields();
|
| 114 |
+
}
|
| 115 |
+
$this->bxSortFields->push($field, $reverse);
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
public function getChoiceId() {
|
| 119 |
+
return $this->choiceId;
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
public function setChoiceId($choiceId) {
|
| 123 |
+
$this->choiceId = $choiceId;
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
public function getMax() {
|
| 127 |
+
return $this->max;
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
public function setMax($max) {
|
| 131 |
+
$this->max = $max;
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
public function getMin() {
|
| 135 |
+
return $this->min;
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
public function setMin($min) {
|
| 139 |
+
$this->min = $min;
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
public function getIndexId() {
|
| 143 |
+
return $this->indexId;
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
public function setIndexId($indexId) {
|
| 147 |
+
$this->indexId = $indexId;
|
| 148 |
+
foreach($this->contextItems as $k => $contextItem) {
|
| 149 |
+
if($contextItem->indexId == null) {
|
| 150 |
+
$this->contextItems[$k]->indexId = $indexId;
|
| 151 |
+
}
|
| 152 |
+
}
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
public function setDefaultIndexId($indexId) {
|
| 156 |
+
if($this->indexId == null) {
|
| 157 |
+
$this->setIndexId($indexId);
|
| 158 |
+
}
|
| 159 |
+
}
|
| 160 |
+
|
| 161 |
+
public function getLanguage() {
|
| 162 |
+
return $this->language;
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
public function setLanguage($language) {
|
| 166 |
+
$this->language = $language;
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
public function getGroupBy(){
|
| 170 |
+
return $this->groupBy;
|
| 171 |
+
}
|
| 172 |
+
|
| 173 |
+
public function setGroupBy($groupBy){
|
| 174 |
+
$this->groupBy = $groupBy;
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
public function getSimpleSearchQuery() {
|
| 178 |
+
|
| 179 |
+
$searchQuery = new \com\boxalino\p13n\api\thrift\SimpleSearchQuery();
|
| 180 |
+
$searchQuery->indexId = $this->getIndexId();
|
| 181 |
+
$searchQuery->language = $this->getLanguage();
|
| 182 |
+
$searchQuery->returnFields = $this->getReturnFields();
|
| 183 |
+
$searchQuery->offset = $this->getOffset();
|
| 184 |
+
$searchQuery->hitCount = $this->getMax();
|
| 185 |
+
$searchQuery->queryText = $this->getQueryText();
|
| 186 |
+
if(in_array('products_group_id', $this->getReturnFields())){
|
| 187 |
+
$searchQuery->groupBy = $this->groupBy;
|
| 188 |
+
}
|
| 189 |
+
if(sizeof($this->getFilters()) > 0) {
|
| 190 |
+
$searchQuery->filters = array();
|
| 191 |
+
foreach($this->getFilters() as $filter) {
|
| 192 |
+
$searchQuery->filters[] = $filter->getThriftFilter();
|
| 193 |
+
}
|
| 194 |
+
}
|
| 195 |
+
$searchQuery->orFilters = $this->getOrFilters();
|
| 196 |
+
if($this->getFacets()) {
|
| 197 |
+
$searchQuery->facetRequests = $this->getFacets()->getThriftFacets();
|
| 198 |
+
}
|
| 199 |
+
if($this->getSortFields()) {
|
| 200 |
+
$searchQuery->sortFields = $this->getSortFields()->getThriftSortFields();
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
return $searchQuery;
|
| 204 |
+
}
|
| 205 |
+
|
| 206 |
+
protected $contextItems = array();
|
| 207 |
+
public function setProductContext($fieldName, $contextItemId, $role = 'mainProduct') {
|
| 208 |
+
$contextItem = new \com\boxalino\p13n\api\thrift\ContextItem();
|
| 209 |
+
$contextItem->indexId = $this->getIndexId();
|
| 210 |
+
$contextItem->fieldName = $fieldName;
|
| 211 |
+
$contextItem->contextItemId = $contextItemId;
|
| 212 |
+
$contextItem->role = $role;
|
| 213 |
+
$this->contextItems[] = $contextItem;
|
| 214 |
+
}
|
| 215 |
+
|
| 216 |
+
public function setBasketProductWithPrices($fieldName, $basketContent, $role = 'mainProduct', $subRole = 'mainProduct') {
|
| 217 |
+
if ($basketContent !== false && count($basketContent)) {
|
| 218 |
+
|
| 219 |
+
// Sort basket content by price
|
| 220 |
+
usort($basketContent, function ($a, $b) {
|
| 221 |
+
if ($a['price'] > $b['price']) {
|
| 222 |
+
return -1;
|
| 223 |
+
} elseif ($b['price'] > $a['price']) {
|
| 224 |
+
return 1;
|
| 225 |
+
}
|
| 226 |
+
return 0;
|
| 227 |
+
});
|
| 228 |
+
|
| 229 |
+
$basketItem = array_shift($basketContent);
|
| 230 |
+
|
| 231 |
+
$contextItem = new \com\boxalino\p13n\api\thrift\ContextItem();
|
| 232 |
+
$contextItem->indexId = $this->getIndexId();
|
| 233 |
+
$contextItem->fieldName = $fieldName;
|
| 234 |
+
$contextItem->contextItemId = $basketItem['id'];
|
| 235 |
+
$contextItem->role = $role;
|
| 236 |
+
|
| 237 |
+
$this->contextItems[] = $contextItem;
|
| 238 |
+
|
| 239 |
+
foreach ($basketContent as $basketItem) {
|
| 240 |
+
$contextItem = new \com\boxalino\p13n\api\thrift\ContextItem();
|
| 241 |
+
$contextItem->indexId = $this->getIndexId();
|
| 242 |
+
$contextItem->fieldName = $fieldName;
|
| 243 |
+
$contextItem->contextItemId = $basketItem['id'];
|
| 244 |
+
$contextItem->role = $subRole;
|
| 245 |
+
|
| 246 |
+
$this->contextItems[] = $contextItem;
|
| 247 |
+
}
|
| 248 |
+
}
|
| 249 |
+
}
|
| 250 |
+
|
| 251 |
+
public function getContextItems() {
|
| 252 |
+
return $this->contextItems;
|
| 253 |
+
}
|
| 254 |
+
|
| 255 |
+
}
|
app/code/community/Boxalino/Intelligence/lib/BxSearchRequest.php
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
namespace com\boxalino\bxclient\v1;
|
| 4 |
+
|
| 5 |
+
class BxSearchRequest extends BxRequest
|
| 6 |
+
{
|
| 7 |
+
public function __construct($language, $queryText, $max=10, $choiceId=null) {
|
| 8 |
+
if($choiceId == null) {
|
| 9 |
+
$choiceId = 'search';
|
| 10 |
+
}
|
| 11 |
+
parent::__construct($language, $choiceId, $max, 0);
|
| 12 |
+
$this->setQueryText($queryText);
|
| 13 |
+
}
|
| 14 |
+
}
|
app/code/community/Boxalino/Intelligence/lib/BxSortFields.php
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
namespace com\boxalino\bxclient\v1;
|
| 4 |
+
|
| 5 |
+
class BxSortFields
|
| 6 |
+
{
|
| 7 |
+
private $sorts = array();
|
| 8 |
+
|
| 9 |
+
public function __construct($field=null, $reverse=false)
|
| 10 |
+
{
|
| 11 |
+
if($field) {
|
| 12 |
+
$this->push($field, $reverse);
|
| 13 |
+
}
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
/**
|
| 17 |
+
* @param $field name od field to sort by (i.e. discountedPrice / title)
|
| 18 |
+
* @param $reverse true for ASC, false for DESC
|
| 19 |
+
*/
|
| 20 |
+
public function push($field, $reverse=false)
|
| 21 |
+
{
|
| 22 |
+
$this->sorts[$field] = $reverse;
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
public function getSortFields()
|
| 26 |
+
{
|
| 27 |
+
return array_keys($this->sorts);
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
public function isFieldReverse($field) {
|
| 31 |
+
if(isset($this->sorts[$field]) && $this->sorts[$field]) {
|
| 32 |
+
return true;
|
| 33 |
+
}
|
| 34 |
+
return false;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
public function getThriftSortFields() {
|
| 38 |
+
$sortFields = array();
|
| 39 |
+
foreach ($this->getSortFields() as $field) {
|
| 40 |
+
$sortFields[] = new \com\boxalino\p13n\api\thrift\SortField(array(
|
| 41 |
+
'fieldName' => $field,
|
| 42 |
+
'reverse' => $this->isFieldReverse($field)
|
| 43 |
+
));
|
| 44 |
+
}
|
| 45 |
+
return $sortFields;
|
| 46 |
+
}
|
| 47 |
+
}
|
app/code/community/Boxalino/{CemSearch/Lib → Intelligence/lib}/P13nService.php
RENAMED
|
@@ -1,1064 +1,1309 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
namespace com\boxalino\p13n\api\thrift;
|
| 3 |
-
/**
|
| 4 |
-
* Autogenerated by Thrift Compiler (0.9.
|
| 5 |
-
*
|
| 6 |
-
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
|
| 7 |
-
* @generated
|
| 8 |
-
*/
|
| 9 |
-
use Thrift\Base\TBase;
|
| 10 |
-
use Thrift\Type\TType;
|
| 11 |
-
use Thrift\Type\TMessageType;
|
| 12 |
-
use Thrift\Exception\TException;
|
| 13 |
-
use Thrift\Exception\TProtocolException;
|
| 14 |
-
use Thrift\Protocol\TProtocol;
|
| 15 |
-
use Thrift\Protocol\TBinaryProtocolAccelerated;
|
| 16 |
-
use Thrift\Exception\TApplicationException;
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
interface P13nServiceIf {
|
| 20 |
-
/**
|
| 21 |
-
* <dl>
|
| 22 |
-
* <dt>@param choiceRequest</dt>
|
| 23 |
-
* <dd>the ChoiceRequest object containing your request</dd>
|
| 24 |
-
*
|
| 25 |
-
* <dt>@return</dt>
|
| 26 |
-
* <dd>a ChoiceResponse object containing the list of variants</dd>
|
| 27 |
-
*
|
| 28 |
-
* <dt>@throws P13nServiceException</dt>
|
| 29 |
-
* <dd>an exception containing an error message</dd>
|
| 30 |
-
* </dl>
|
| 31 |
-
*
|
| 32 |
-
* @param \com\boxalino\p13n\api\thrift\ChoiceRequest $choiceRequest
|
| 33 |
-
* @return \com\boxalino\p13n\api\thrift\ChoiceResponse list of personalized variants. Item's index corresponds to the index of the
|
| 34 |
-
* ChoiceInquiry
|
| 35 |
-
*
|
| 36 |
-
* @throws \com\boxalino\p13n\api\thrift\P13nServiceException
|
| 37 |
-
*/
|
| 38 |
-
public function choose(\com\boxalino\p13n\api\thrift\ChoiceRequest $choiceRequest);
|
| 39 |
-
/**
|
| 40 |
-
* <dl>
|
| 41 |
-
* <dt>@param batchChoiceRequest</dt>
|
| 42 |
-
* <dd>the BatchChoiceRequest object containing your requests</dd>
|
| 43 |
-
*
|
| 44 |
-
* <dt>@return</dt>
|
| 45 |
-
* <dd>a BatchChoiceResponse object containing the list of variants for each request</dd>
|
| 46 |
-
*
|
| 47 |
-
* <dt>@throws P13nServiceException</dt>
|
| 48 |
-
* <dd>an exception containing an error message</dd>
|
| 49 |
-
* </dl>
|
| 50 |
-
*
|
| 51 |
-
* @param \com\boxalino\p13n\api\thrift\BatchChoiceRequest $batchChoiceRequest
|
| 52 |
-
* @return \com\boxalino\p13n\api\thrift\BatchChoiceResponse <dl>
|
| 53 |
-
* <dt>variants</dt>
|
| 54 |
-
* <dd><b>deprecated</b> - contains non-null value only if
|
| 55 |
-
* corresponding BatchChoiceRequest had only one ChoiceInquiry</dd>
|
| 56 |
-
*
|
| 57 |
-
* <dt>selectedVariants</dt>
|
| 58 |
-
* <dd>outer list corresponds to profileIds given in BatchChoiceRequest, while
|
| 59 |
-
* inner list corresponds to list of ChoiceInquiries from BatchChoiceRequest</dd>
|
| 60 |
-
* </dl>
|
| 61 |
-
*
|
| 62 |
-
* @throws \com\boxalino\p13n\api\thrift\P13nServiceException
|
| 63 |
-
*/
|
| 64 |
-
public function batchChoose(\com\boxalino\p13n\api\thrift\BatchChoiceRequest $batchChoiceRequest);
|
| 65 |
-
/**
|
| 66 |
-
* <dl>
|
| 67 |
-
* <dt>@param request</dt>
|
| 68 |
-
* <dd>the AutocompleteRequest object containing your request</dd>
|
| 69 |
-
*
|
| 70 |
-
* <dt>@return</dt>
|
| 71 |
-
* <dd>a AutocompleteResponse object containing the list of hits</dd>
|
| 72 |
-
*
|
| 73 |
-
* <dt>@throws P13nServiceException</dt>
|
| 74 |
-
* <dd>an exception containing an error message</dd>
|
| 75 |
-
* </dl>
|
| 76 |
-
*
|
| 77 |
-
* @param \com\boxalino\p13n\api\thrift\AutocompleteRequest $request
|
| 78 |
-
* @return \com\boxalino\p13n\api\thrift\AutocompleteResponse
|
| 79 |
-
* @throws \com\boxalino\p13n\api\thrift\P13nServiceException
|
| 80 |
-
*/
|
| 81 |
-
public function autocomplete(\com\boxalino\p13n\api\thrift\AutocompleteRequest $request);
|
| 82 |
-
/**
|
| 83 |
-
*
|
| 84 |
-
*
|
| 85 |
-
* @
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
{
|
| 106 |
-
$this->
|
| 107 |
-
|
| 108 |
-
}
|
| 109 |
-
|
| 110 |
-
public function
|
| 111 |
-
{
|
| 112 |
-
$
|
| 113 |
-
$
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
$this->output_->
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
$
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
}
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
}
|
| 163 |
-
|
| 164 |
-
public function
|
| 165 |
-
{
|
| 166 |
-
$
|
| 167 |
-
$
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
$this->output_->
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
$
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
}
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
}
|
| 217 |
-
|
| 218 |
-
public function
|
| 219 |
-
{
|
| 220 |
-
$
|
| 221 |
-
$
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
$this->output_->
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
$
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
}
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
}
|
| 271 |
-
|
| 272 |
-
public function
|
| 273 |
-
{
|
| 274 |
-
$
|
| 275 |
-
$
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
$this->output_->
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
$
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
}
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
public function
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
|
| 372 |
-
|
| 373 |
-
|
| 374 |
-
|
| 375 |
-
|
| 376 |
-
|
| 377 |
-
|
| 378 |
-
|
| 379 |
-
|
| 380 |
-
|
| 381 |
-
|
| 382 |
-
|
| 383 |
-
|
| 384 |
-
|
| 385 |
-
|
| 386 |
-
|
| 387 |
-
|
| 388 |
-
|
| 389 |
-
|
| 390 |
-
|
| 391 |
-
|
| 392 |
-
|
| 393 |
-
|
| 394 |
-
|
| 395 |
-
|
| 396 |
-
|
| 397 |
-
|
| 398 |
-
|
| 399 |
-
|
| 400 |
-
|
| 401 |
-
|
| 402 |
-
|
| 403 |
-
|
| 404 |
-
|
| 405 |
-
|
| 406 |
-
|
| 407 |
-
|
| 408 |
-
|
| 409 |
-
|
| 410 |
-
|
| 411 |
-
|
| 412 |
-
|
| 413 |
-
|
| 414 |
-
|
| 415 |
-
|
| 416 |
-
|
| 417 |
-
|
| 418 |
-
|
| 419 |
-
|
| 420 |
-
|
| 421 |
-
|
| 422 |
-
|
| 423 |
-
|
| 424 |
-
|
| 425 |
-
|
| 426 |
-
|
| 427 |
-
|
| 428 |
-
|
| 429 |
-
|
| 430 |
-
|
| 431 |
-
|
| 432 |
-
|
| 433 |
-
|
| 434 |
-
|
| 435 |
-
|
| 436 |
-
|
| 437 |
-
|
| 438 |
-
|
| 439 |
-
|
| 440 |
-
|
| 441 |
-
|
| 442 |
-
|
| 443 |
-
|
| 444 |
-
|
| 445 |
-
|
| 446 |
-
{
|
| 447 |
-
$xfer = 0;
|
| 448 |
-
$
|
| 449 |
-
$
|
| 450 |
-
|
| 451 |
-
|
| 452 |
-
|
| 453 |
-
|
| 454 |
-
$xfer += $
|
| 455 |
-
|
| 456 |
-
|
| 457 |
-
|
| 458 |
-
|
| 459 |
-
|
| 460 |
-
|
| 461 |
-
|
| 462 |
-
|
| 463 |
-
|
| 464 |
-
|
| 465 |
-
|
| 466 |
-
|
| 467 |
-
|
| 468 |
-
|
| 469 |
-
|
| 470 |
-
|
| 471 |
-
|
| 472 |
-
|
| 473 |
-
|
| 474 |
-
|
| 475 |
-
|
| 476 |
-
|
| 477 |
-
|
| 478 |
-
|
| 479 |
-
|
| 480 |
-
|
| 481 |
-
|
| 482 |
-
|
| 483 |
-
|
| 484 |
-
|
| 485 |
-
|
| 486 |
-
|
| 487 |
-
|
| 488 |
-
|
| 489 |
-
|
| 490 |
-
|
| 491 |
-
|
| 492 |
-
|
| 493 |
-
|
| 494 |
-
|
| 495 |
-
|
| 496 |
-
|
| 497 |
-
|
| 498 |
-
|
| 499 |
-
|
| 500 |
-
|
| 501 |
-
|
| 502 |
-
|
| 503 |
-
|
| 504 |
-
|
| 505 |
-
|
| 506 |
-
|
| 507 |
-
|
| 508 |
-
|
| 509 |
-
|
| 510 |
-
|
| 511 |
-
|
| 512 |
-
|
| 513 |
-
|
| 514 |
-
|
| 515 |
-
|
| 516 |
-
|
| 517 |
-
|
| 518 |
-
|
| 519 |
-
|
| 520 |
-
|
| 521 |
-
|
| 522 |
-
|
| 523 |
-
|
| 524 |
-
|
| 525 |
-
|
| 526 |
-
|
| 527 |
-
|
| 528 |
-
|
| 529 |
-
|
| 530 |
-
|
| 531 |
-
|
| 532 |
-
|
| 533 |
-
|
| 534 |
-
|
| 535 |
-
|
| 536 |
-
|
| 537 |
-
|
| 538 |
-
|
| 539 |
-
|
| 540 |
-
|
| 541 |
-
|
| 542 |
-
$
|
| 543 |
-
$
|
| 544 |
-
|
| 545 |
-
|
| 546 |
-
|
| 547 |
-
|
| 548 |
-
|
| 549 |
-
|
| 550 |
-
|
| 551 |
-
|
| 552 |
-
|
| 553 |
-
|
| 554 |
-
|
| 555 |
-
|
| 556 |
-
|
| 557 |
-
|
| 558 |
-
|
| 559 |
-
|
| 560 |
-
|
| 561 |
-
|
| 562 |
-
|
| 563 |
-
|
| 564 |
-
|
| 565 |
-
|
| 566 |
-
|
| 567 |
-
|
| 568 |
-
|
| 569 |
-
|
| 570 |
-
|
| 571 |
-
|
| 572 |
-
|
| 573 |
-
|
| 574 |
-
|
| 575 |
-
|
| 576 |
-
|
| 577 |
-
|
| 578 |
-
|
| 579 |
-
|
| 580 |
-
|
| 581 |
-
|
| 582 |
-
|
| 583 |
-
|
| 584 |
-
|
| 585 |
-
|
| 586 |
-
|
| 587 |
-
|
| 588 |
-
|
| 589 |
-
|
| 590 |
-
|
| 591 |
-
|
| 592 |
-
|
| 593 |
-
|
| 594 |
-
|
| 595 |
-
|
| 596 |
-
|
| 597 |
-
|
| 598 |
-
|
| 599 |
-
|
| 600 |
-
|
| 601 |
-
|
| 602 |
-
|
| 603 |
-
|
| 604 |
-
|
| 605 |
-
|
| 606 |
-
|
| 607 |
-
|
| 608 |
-
|
| 609 |
-
|
| 610 |
-
|
| 611 |
-
|
| 612 |
-
|
| 613 |
-
|
| 614 |
-
|
| 615 |
-
|
| 616 |
-
|
| 617 |
-
|
| 618 |
-
|
| 619 |
-
|
| 620 |
-
|
| 621 |
-
|
| 622 |
-
|
| 623 |
-
|
| 624 |
-
|
| 625 |
-
|
| 626 |
-
|
| 627 |
-
|
| 628 |
-
|
| 629 |
-
|
| 630 |
-
|
| 631 |
-
{
|
| 632 |
-
$xfer = 0;
|
| 633 |
-
$
|
| 634 |
-
$
|
| 635 |
-
|
| 636 |
-
|
| 637 |
-
|
| 638 |
-
|
| 639 |
-
$xfer += $
|
| 640 |
-
|
| 641 |
-
|
| 642 |
-
|
| 643 |
-
|
| 644 |
-
|
| 645 |
-
|
| 646 |
-
|
| 647 |
-
|
| 648 |
-
|
| 649 |
-
|
| 650 |
-
|
| 651 |
-
|
| 652 |
-
|
| 653 |
-
|
| 654 |
-
|
| 655 |
-
|
| 656 |
-
|
| 657 |
-
|
| 658 |
-
|
| 659 |
-
|
| 660 |
-
|
| 661 |
-
|
| 662 |
-
|
| 663 |
-
|
| 664 |
-
|
| 665 |
-
|
| 666 |
-
|
| 667 |
-
|
| 668 |
-
|
| 669 |
-
|
| 670 |
-
|
| 671 |
-
|
| 672 |
-
|
| 673 |
-
|
| 674 |
-
|
| 675 |
-
|
| 676 |
-
|
| 677 |
-
|
| 678 |
-
|
| 679 |
-
|
| 680 |
-
|
| 681 |
-
|
| 682 |
-
|
| 683 |
-
|
| 684 |
-
|
| 685 |
-
|
| 686 |
-
|
| 687 |
-
|
| 688 |
-
|
| 689 |
-
|
| 690 |
-
|
| 691 |
-
|
| 692 |
-
|
| 693 |
-
|
| 694 |
-
|
| 695 |
-
|
| 696 |
-
|
| 697 |
-
|
| 698 |
-
|
| 699 |
-
|
| 700 |
-
|
| 701 |
-
|
| 702 |
-
|
| 703 |
-
|
| 704 |
-
|
| 705 |
-
|
| 706 |
-
|
| 707 |
-
|
| 708 |
-
|
| 709 |
-
|
| 710 |
-
|
| 711 |
-
|
| 712 |
-
|
| 713 |
-
|
| 714 |
-
|
| 715 |
-
|
| 716 |
-
|
| 717 |
-
|
| 718 |
-
|
| 719 |
-
|
| 720 |
-
|
| 721 |
-
|
| 722 |
-
|
| 723 |
-
|
| 724 |
-
|
| 725 |
-
|
| 726 |
-
|
| 727 |
-
$
|
| 728 |
-
$
|
| 729 |
-
|
| 730 |
-
|
| 731 |
-
|
| 732 |
-
|
| 733 |
-
|
| 734 |
-
|
| 735 |
-
|
| 736 |
-
|
| 737 |
-
|
| 738 |
-
|
| 739 |
-
|
| 740 |
-
|
| 741 |
-
|
| 742 |
-
|
| 743 |
-
|
| 744 |
-
|
| 745 |
-
|
| 746 |
-
|
| 747 |
-
|
| 748 |
-
|
| 749 |
-
|
| 750 |
-
|
| 751 |
-
|
| 752 |
-
|
| 753 |
-
|
| 754 |
-
|
| 755 |
-
|
| 756 |
-
|
| 757 |
-
|
| 758 |
-
|
| 759 |
-
|
| 760 |
-
|
| 761 |
-
|
| 762 |
-
|
| 763 |
-
|
| 764 |
-
|
| 765 |
-
|
| 766 |
-
|
| 767 |
-
|
| 768 |
-
|
| 769 |
-
|
| 770 |
-
|
| 771 |
-
|
| 772 |
-
|
| 773 |
-
|
| 774 |
-
|
| 775 |
-
|
| 776 |
-
|
| 777 |
-
|
| 778 |
-
|
| 779 |
-
|
| 780 |
-
|
| 781 |
-
|
| 782 |
-
|
| 783 |
-
|
| 784 |
-
|
| 785 |
-
|
| 786 |
-
|
| 787 |
-
|
| 788 |
-
|
| 789 |
-
|
| 790 |
-
|
| 791 |
-
|
| 792 |
-
|
| 793 |
-
|
| 794 |
-
|
| 795 |
-
|
| 796 |
-
|
| 797 |
-
|
| 798 |
-
|
| 799 |
-
|
| 800 |
-
|
| 801 |
-
|
| 802 |
-
|
| 803 |
-
|
| 804 |
-
|
| 805 |
-
|
| 806 |
-
|
| 807 |
-
|
| 808 |
-
|
| 809 |
-
|
| 810 |
-
|
| 811 |
-
|
| 812 |
-
|
| 813 |
-
|
| 814 |
-
|
| 815 |
-
|
| 816 |
-
{
|
| 817 |
-
$xfer = 0;
|
| 818 |
-
$
|
| 819 |
-
$
|
| 820 |
-
|
| 821 |
-
|
| 822 |
-
|
| 823 |
-
|
| 824 |
-
$xfer += $
|
| 825 |
-
|
| 826 |
-
|
| 827 |
-
|
| 828 |
-
|
| 829 |
-
|
| 830 |
-
|
| 831 |
-
|
| 832 |
-
|
| 833 |
-
|
| 834 |
-
|
| 835 |
-
|
| 836 |
-
|
| 837 |
-
|
| 838 |
-
|
| 839 |
-
|
| 840 |
-
|
| 841 |
-
|
| 842 |
-
|
| 843 |
-
|
| 844 |
-
|
| 845 |
-
|
| 846 |
-
|
| 847 |
-
|
| 848 |
-
|
| 849 |
-
|
| 850 |
-
|
| 851 |
-
|
| 852 |
-
|
| 853 |
-
|
| 854 |
-
|
| 855 |
-
|
| 856 |
-
|
| 857 |
-
|
| 858 |
-
|
| 859 |
-
|
| 860 |
-
|
| 861 |
-
|
| 862 |
-
|
| 863 |
-
|
| 864 |
-
|
| 865 |
-
|
| 866 |
-
|
| 867 |
-
|
| 868 |
-
|
| 869 |
-
|
| 870 |
-
|
| 871 |
-
|
| 872 |
-
|
| 873 |
-
|
| 874 |
-
|
| 875 |
-
|
| 876 |
-
|
| 877 |
-
|
| 878 |
-
|
| 879 |
-
|
| 880 |
-
|
| 881 |
-
|
| 882 |
-
|
| 883 |
-
|
| 884 |
-
|
| 885 |
-
|
| 886 |
-
|
| 887 |
-
|
| 888 |
-
|
| 889 |
-
|
| 890 |
-
|
| 891 |
-
|
| 892 |
-
|
| 893 |
-
|
| 894 |
-
|
| 895 |
-
|
| 896 |
-
|
| 897 |
-
|
| 898 |
-
|
| 899 |
-
|
| 900 |
-
|
| 901 |
-
|
| 902 |
-
|
| 903 |
-
|
| 904 |
-
|
| 905 |
-
|
| 906 |
-
|
| 907 |
-
|
| 908 |
-
|
| 909 |
-
|
| 910 |
-
|
| 911 |
-
|
| 912 |
-
$
|
| 913 |
-
$
|
| 914 |
-
|
| 915 |
-
|
| 916 |
-
|
| 917 |
-
|
| 918 |
-
|
| 919 |
-
|
| 920 |
-
|
| 921 |
-
|
| 922 |
-
|
| 923 |
-
|
| 924 |
-
|
| 925 |
-
|
| 926 |
-
|
| 927 |
-
|
| 928 |
-
|
| 929 |
-
|
| 930 |
-
|
| 931 |
-
|
| 932 |
-
|
| 933 |
-
|
| 934 |
-
|
| 935 |
-
|
| 936 |
-
|
| 937 |
-
|
| 938 |
-
|
| 939 |
-
|
| 940 |
-
|
| 941 |
-
|
| 942 |
-
|
| 943 |
-
|
| 944 |
-
|
| 945 |
-
|
| 946 |
-
|
| 947 |
-
|
| 948 |
-
|
| 949 |
-
|
| 950 |
-
|
| 951 |
-
|
| 952 |
-
|
| 953 |
-
|
| 954 |
-
|
| 955 |
-
|
| 956 |
-
|
| 957 |
-
|
| 958 |
-
|
| 959 |
-
|
| 960 |
-
|
| 961 |
-
|
| 962 |
-
|
| 963 |
-
|
| 964 |
-
|
| 965 |
-
|
| 966 |
-
|
| 967 |
-
|
| 968 |
-
|
| 969 |
-
|
| 970 |
-
|
| 971 |
-
|
| 972 |
-
|
| 973 |
-
|
| 974 |
-
|
| 975 |
-
|
| 976 |
-
|
| 977 |
-
|
| 978 |
-
|
| 979 |
-
|
| 980 |
-
|
| 981 |
-
|
| 982 |
-
|
| 983 |
-
|
| 984 |
-
|
| 985 |
-
|
| 986 |
-
|
| 987 |
-
|
| 988 |
-
|
| 989 |
-
|
| 990 |
-
|
| 991 |
-
|
| 992 |
-
|
| 993 |
-
|
| 994 |
-
|
| 995 |
-
|
| 996 |
-
|
| 997 |
-
|
| 998 |
-
|
| 999 |
-
|
| 1000 |
-
|
| 1001 |
-
{
|
| 1002 |
-
$xfer = 0;
|
| 1003 |
-
$
|
| 1004 |
-
$
|
| 1005 |
-
|
| 1006 |
-
|
| 1007 |
-
|
| 1008 |
-
|
| 1009 |
-
$xfer += $
|
| 1010 |
-
|
| 1011 |
-
|
| 1012 |
-
|
| 1013 |
-
|
| 1014 |
-
|
| 1015 |
-
|
| 1016 |
-
|
| 1017 |
-
|
| 1018 |
-
|
| 1019 |
-
|
| 1020 |
-
|
| 1021 |
-
|
| 1022 |
-
|
| 1023 |
-
|
| 1024 |
-
|
| 1025 |
-
|
| 1026 |
-
|
| 1027 |
-
|
| 1028 |
-
|
| 1029 |
-
|
| 1030 |
-
|
| 1031 |
-
|
| 1032 |
-
|
| 1033 |
-
|
| 1034 |
-
|
| 1035 |
-
|
| 1036 |
-
|
| 1037 |
-
|
| 1038 |
-
|
| 1039 |
-
|
| 1040 |
-
|
| 1041 |
-
|
| 1042 |
-
|
| 1043 |
-
|
| 1044 |
-
|
| 1045 |
-
|
| 1046 |
-
|
| 1047 |
-
|
| 1048 |
-
|
| 1049 |
-
|
| 1050 |
-
|
| 1051 |
-
|
| 1052 |
-
|
| 1053 |
-
|
| 1054 |
-
|
| 1055 |
-
|
| 1056 |
-
|
| 1057 |
-
|
| 1058 |
-
|
| 1059 |
-
|
| 1060 |
-
|
| 1061 |
-
|
| 1062 |
-
|
| 1063 |
-
|
| 1064 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
namespace com\boxalino\p13n\api\thrift;
|
| 3 |
+
/**
|
| 4 |
+
* Autogenerated by Thrift Compiler (0.9.3)
|
| 5 |
+
*
|
| 6 |
+
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
|
| 7 |
+
* @generated
|
| 8 |
+
*/
|
| 9 |
+
use Thrift\Base\TBase;
|
| 10 |
+
use Thrift\Type\TType;
|
| 11 |
+
use Thrift\Type\TMessageType;
|
| 12 |
+
use Thrift\Exception\TException;
|
| 13 |
+
use Thrift\Exception\TProtocolException;
|
| 14 |
+
use Thrift\Protocol\TProtocol;
|
| 15 |
+
use Thrift\Protocol\TBinaryProtocolAccelerated;
|
| 16 |
+
use Thrift\Exception\TApplicationException;
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
interface P13nServiceIf {
|
| 20 |
+
/**
|
| 21 |
+
* <dl>
|
| 22 |
+
* <dt>@param choiceRequest</dt>
|
| 23 |
+
* <dd>the ChoiceRequest object containing your request</dd>
|
| 24 |
+
*
|
| 25 |
+
* <dt>@return</dt>
|
| 26 |
+
* <dd>a ChoiceResponse object containing the list of variants</dd>
|
| 27 |
+
*
|
| 28 |
+
* <dt>@throws P13nServiceException</dt>
|
| 29 |
+
* <dd>an exception containing an error message</dd>
|
| 30 |
+
* </dl>
|
| 31 |
+
*
|
| 32 |
+
* @param \com\boxalino\p13n\api\thrift\ChoiceRequest $choiceRequest
|
| 33 |
+
* @return \com\boxalino\p13n\api\thrift\ChoiceResponse list of personalized variants. Item's index corresponds to the index of the
|
| 34 |
+
* ChoiceInquiry
|
| 35 |
+
*
|
| 36 |
+
* @throws \com\boxalino\p13n\api\thrift\P13nServiceException
|
| 37 |
+
*/
|
| 38 |
+
public function choose(\com\boxalino\p13n\api\thrift\ChoiceRequest $choiceRequest);
|
| 39 |
+
/**
|
| 40 |
+
* <dl>
|
| 41 |
+
* <dt>@param batchChoiceRequest</dt>
|
| 42 |
+
* <dd>the BatchChoiceRequest object containing your requests</dd>
|
| 43 |
+
*
|
| 44 |
+
* <dt>@return</dt>
|
| 45 |
+
* <dd>a BatchChoiceResponse object containing the list of variants for each request</dd>
|
| 46 |
+
*
|
| 47 |
+
* <dt>@throws P13nServiceException</dt>
|
| 48 |
+
* <dd>an exception containing an error message</dd>
|
| 49 |
+
* </dl>
|
| 50 |
+
*
|
| 51 |
+
* @param \com\boxalino\p13n\api\thrift\BatchChoiceRequest $batchChoiceRequest
|
| 52 |
+
* @return \com\boxalino\p13n\api\thrift\BatchChoiceResponse <dl>
|
| 53 |
+
* <dt>variants</dt>
|
| 54 |
+
* <dd><b>deprecated</b> - contains non-null value only if
|
| 55 |
+
* corresponding BatchChoiceRequest had only one ChoiceInquiry</dd>
|
| 56 |
+
*
|
| 57 |
+
* <dt>selectedVariants</dt>
|
| 58 |
+
* <dd>outer list corresponds to profileIds given in BatchChoiceRequest, while
|
| 59 |
+
* inner list corresponds to list of ChoiceInquiries from BatchChoiceRequest</dd>
|
| 60 |
+
* </dl>
|
| 61 |
+
*
|
| 62 |
+
* @throws \com\boxalino\p13n\api\thrift\P13nServiceException
|
| 63 |
+
*/
|
| 64 |
+
public function batchChoose(\com\boxalino\p13n\api\thrift\BatchChoiceRequest $batchChoiceRequest);
|
| 65 |
+
/**
|
| 66 |
+
* <dl>
|
| 67 |
+
* <dt>@param request</dt>
|
| 68 |
+
* <dd>the AutocompleteRequest object containing your request</dd>
|
| 69 |
+
*
|
| 70 |
+
* <dt>@return</dt>
|
| 71 |
+
* <dd>a AutocompleteResponse object containing the list of hits</dd>
|
| 72 |
+
*
|
| 73 |
+
* <dt>@throws P13nServiceException</dt>
|
| 74 |
+
* <dd>an exception containing an error message</dd>
|
| 75 |
+
* </dl>
|
| 76 |
+
*
|
| 77 |
+
* @param \com\boxalino\p13n\api\thrift\AutocompleteRequest $request
|
| 78 |
+
* @return \com\boxalino\p13n\api\thrift\AutocompleteResponse
|
| 79 |
+
* @throws \com\boxalino\p13n\api\thrift\P13nServiceException
|
| 80 |
+
*/
|
| 81 |
+
public function autocomplete(\com\boxalino\p13n\api\thrift\AutocompleteRequest $request);
|
| 82 |
+
/**
|
| 83 |
+
* @param \com\boxalino\p13n\api\thrift\AutocompleteRequestBundle $bundle
|
| 84 |
+
* @return \com\boxalino\p13n\api\thrift\AutocompleteResponseBundle
|
| 85 |
+
* @throws \com\boxalino\p13n\api\thrift\P13nServiceException
|
| 86 |
+
*/
|
| 87 |
+
public function autocompleteAll(\com\boxalino\p13n\api\thrift\AutocompleteRequestBundle $bundle);
|
| 88 |
+
/**
|
| 89 |
+
* Updating a choice or creating a new choice if choiceId is not given in choiceUpdateRequest.
|
| 90 |
+
*
|
| 91 |
+
* @param \com\boxalino\p13n\api\thrift\ChoiceUpdateRequest $choiceUpdateRequest
|
| 92 |
+
* @return \com\boxalino\p13n\api\thrift\ChoiceUpdateResponse Server response for one ChoiceUpdateRequest
|
| 93 |
+
*
|
| 94 |
+
* @throws \com\boxalino\p13n\api\thrift\P13nServiceException
|
| 95 |
+
*/
|
| 96 |
+
public function updateChoice(\com\boxalino\p13n\api\thrift\ChoiceUpdateRequest $choiceUpdateRequest);
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
class P13nServiceClient implements \com\boxalino\p13n\api\thrift\P13nServiceIf {
|
| 100 |
+
protected $input_ = null;
|
| 101 |
+
protected $output_ = null;
|
| 102 |
+
|
| 103 |
+
protected $seqid_ = 0;
|
| 104 |
+
|
| 105 |
+
public function __construct($input, $output=null) {
|
| 106 |
+
$this->input_ = $input;
|
| 107 |
+
$this->output_ = $output ? $output : $input;
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
public function choose(\com\boxalino\p13n\api\thrift\ChoiceRequest $choiceRequest)
|
| 111 |
+
{
|
| 112 |
+
$this->send_choose($choiceRequest);
|
| 113 |
+
return $this->recv_choose();
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
public function send_choose(\com\boxalino\p13n\api\thrift\ChoiceRequest $choiceRequest)
|
| 117 |
+
{
|
| 118 |
+
$args = new \com\boxalino\p13n\api\thrift\P13nService_choose_args();
|
| 119 |
+
$args->choiceRequest = $choiceRequest;
|
| 120 |
+
$bin_accel = ($this->output_ instanceof TBinaryProtocolAccelerated) && function_exists('thrift_protocol_write_binary');
|
| 121 |
+
if ($bin_accel)
|
| 122 |
+
{
|
| 123 |
+
thrift_protocol_write_binary($this->output_, 'choose', TMessageType::CALL, $args, $this->seqid_, $this->output_->isStrictWrite());
|
| 124 |
+
}
|
| 125 |
+
else
|
| 126 |
+
{
|
| 127 |
+
$this->output_->writeMessageBegin('choose', TMessageType::CALL, $this->seqid_);
|
| 128 |
+
$args->write($this->output_);
|
| 129 |
+
$this->output_->writeMessageEnd();
|
| 130 |
+
$this->output_->getTransport()->flush();
|
| 131 |
+
}
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
public function recv_choose()
|
| 135 |
+
{
|
| 136 |
+
$bin_accel = ($this->input_ instanceof TBinaryProtocolAccelerated) && function_exists('thrift_protocol_read_binary');
|
| 137 |
+
if ($bin_accel) $result = thrift_protocol_read_binary($this->input_, '\com\boxalino\p13n\api\thrift\P13nService_choose_result', $this->input_->isStrictRead());
|
| 138 |
+
else
|
| 139 |
+
{
|
| 140 |
+
$rseqid = 0;
|
| 141 |
+
$fname = null;
|
| 142 |
+
$mtype = 0;
|
| 143 |
+
|
| 144 |
+
$this->input_->readMessageBegin($fname, $mtype, $rseqid);
|
| 145 |
+
if ($mtype == TMessageType::EXCEPTION) {
|
| 146 |
+
$x = new TApplicationException();
|
| 147 |
+
$x->read($this->input_);
|
| 148 |
+
$this->input_->readMessageEnd();
|
| 149 |
+
throw $x;
|
| 150 |
+
}
|
| 151 |
+
$result = new \com\boxalino\p13n\api\thrift\P13nService_choose_result();
|
| 152 |
+
$result->read($this->input_);
|
| 153 |
+
$this->input_->readMessageEnd();
|
| 154 |
+
}
|
| 155 |
+
if ($result->success !== null) {
|
| 156 |
+
return $result->success;
|
| 157 |
+
}
|
| 158 |
+
if ($result->p13nServiceException !== null) {
|
| 159 |
+
throw $result->p13nServiceException;
|
| 160 |
+
}
|
| 161 |
+
throw new \Exception("choose failed: unknown result");
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
public function batchChoose(\com\boxalino\p13n\api\thrift\BatchChoiceRequest $batchChoiceRequest)
|
| 165 |
+
{
|
| 166 |
+
$this->send_batchChoose($batchChoiceRequest);
|
| 167 |
+
return $this->recv_batchChoose();
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
public function send_batchChoose(\com\boxalino\p13n\api\thrift\BatchChoiceRequest $batchChoiceRequest)
|
| 171 |
+
{
|
| 172 |
+
$args = new \com\boxalino\p13n\api\thrift\P13nService_batchChoose_args();
|
| 173 |
+
$args->batchChoiceRequest = $batchChoiceRequest;
|
| 174 |
+
$bin_accel = ($this->output_ instanceof TBinaryProtocolAccelerated) && function_exists('thrift_protocol_write_binary');
|
| 175 |
+
if ($bin_accel)
|
| 176 |
+
{
|
| 177 |
+
thrift_protocol_write_binary($this->output_, 'batchChoose', TMessageType::CALL, $args, $this->seqid_, $this->output_->isStrictWrite());
|
| 178 |
+
}
|
| 179 |
+
else
|
| 180 |
+
{
|
| 181 |
+
$this->output_->writeMessageBegin('batchChoose', TMessageType::CALL, $this->seqid_);
|
| 182 |
+
$args->write($this->output_);
|
| 183 |
+
$this->output_->writeMessageEnd();
|
| 184 |
+
$this->output_->getTransport()->flush();
|
| 185 |
+
}
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
public function recv_batchChoose()
|
| 189 |
+
{
|
| 190 |
+
$bin_accel = ($this->input_ instanceof TBinaryProtocolAccelerated) && function_exists('thrift_protocol_read_binary');
|
| 191 |
+
if ($bin_accel) $result = thrift_protocol_read_binary($this->input_, '\com\boxalino\p13n\api\thrift\P13nService_batchChoose_result', $this->input_->isStrictRead());
|
| 192 |
+
else
|
| 193 |
+
{
|
| 194 |
+
$rseqid = 0;
|
| 195 |
+
$fname = null;
|
| 196 |
+
$mtype = 0;
|
| 197 |
+
|
| 198 |
+
$this->input_->readMessageBegin($fname, $mtype, $rseqid);
|
| 199 |
+
if ($mtype == TMessageType::EXCEPTION) {
|
| 200 |
+
$x = new TApplicationException();
|
| 201 |
+
$x->read($this->input_);
|
| 202 |
+
$this->input_->readMessageEnd();
|
| 203 |
+
throw $x;
|
| 204 |
+
}
|
| 205 |
+
$result = new \com\boxalino\p13n\api\thrift\P13nService_batchChoose_result();
|
| 206 |
+
$result->read($this->input_);
|
| 207 |
+
$this->input_->readMessageEnd();
|
| 208 |
+
}
|
| 209 |
+
if ($result->success !== null) {
|
| 210 |
+
return $result->success;
|
| 211 |
+
}
|
| 212 |
+
if ($result->p13nServiceException !== null) {
|
| 213 |
+
throw $result->p13nServiceException;
|
| 214 |
+
}
|
| 215 |
+
throw new \Exception("batchChoose failed: unknown result");
|
| 216 |
+
}
|
| 217 |
+
|
| 218 |
+
public function autocomplete(\com\boxalino\p13n\api\thrift\AutocompleteRequest $request)
|
| 219 |
+
{
|
| 220 |
+
$this->send_autocomplete($request);
|
| 221 |
+
return $this->recv_autocomplete();
|
| 222 |
+
}
|
| 223 |
+
|
| 224 |
+
public function send_autocomplete(\com\boxalino\p13n\api\thrift\AutocompleteRequest $request)
|
| 225 |
+
{
|
| 226 |
+
$args = new \com\boxalino\p13n\api\thrift\P13nService_autocomplete_args();
|
| 227 |
+
$args->request = $request;
|
| 228 |
+
$bin_accel = ($this->output_ instanceof TBinaryProtocolAccelerated) && function_exists('thrift_protocol_write_binary');
|
| 229 |
+
if ($bin_accel)
|
| 230 |
+
{
|
| 231 |
+
thrift_protocol_write_binary($this->output_, 'autocomplete', TMessageType::CALL, $args, $this->seqid_, $this->output_->isStrictWrite());
|
| 232 |
+
}
|
| 233 |
+
else
|
| 234 |
+
{
|
| 235 |
+
$this->output_->writeMessageBegin('autocomplete', TMessageType::CALL, $this->seqid_);
|
| 236 |
+
$args->write($this->output_);
|
| 237 |
+
$this->output_->writeMessageEnd();
|
| 238 |
+
$this->output_->getTransport()->flush();
|
| 239 |
+
}
|
| 240 |
+
}
|
| 241 |
+
|
| 242 |
+
public function recv_autocomplete()
|
| 243 |
+
{
|
| 244 |
+
$bin_accel = ($this->input_ instanceof TBinaryProtocolAccelerated) && function_exists('thrift_protocol_read_binary');
|
| 245 |
+
if ($bin_accel) $result = thrift_protocol_read_binary($this->input_, '\com\boxalino\p13n\api\thrift\P13nService_autocomplete_result', $this->input_->isStrictRead());
|
| 246 |
+
else
|
| 247 |
+
{
|
| 248 |
+
$rseqid = 0;
|
| 249 |
+
$fname = null;
|
| 250 |
+
$mtype = 0;
|
| 251 |
+
|
| 252 |
+
$this->input_->readMessageBegin($fname, $mtype, $rseqid);
|
| 253 |
+
if ($mtype == TMessageType::EXCEPTION) {
|
| 254 |
+
$x = new TApplicationException();
|
| 255 |
+
$x->read($this->input_);
|
| 256 |
+
$this->input_->readMessageEnd();
|
| 257 |
+
throw $x;
|
| 258 |
+
}
|
| 259 |
+
$result = new \com\boxalino\p13n\api\thrift\P13nService_autocomplete_result();
|
| 260 |
+
$result->read($this->input_);
|
| 261 |
+
$this->input_->readMessageEnd();
|
| 262 |
+
}
|
| 263 |
+
if ($result->success !== null) {
|
| 264 |
+
return $result->success;
|
| 265 |
+
}
|
| 266 |
+
if ($result->p13nServiceException !== null) {
|
| 267 |
+
throw $result->p13nServiceException;
|
| 268 |
+
}
|
| 269 |
+
throw new \Exception("autocomplete failed: unknown result");
|
| 270 |
+
}
|
| 271 |
+
|
| 272 |
+
public function autocompleteAll(\com\boxalino\p13n\api\thrift\AutocompleteRequestBundle $bundle)
|
| 273 |
+
{
|
| 274 |
+
$this->send_autocompleteAll($bundle);
|
| 275 |
+
return $this->recv_autocompleteAll();
|
| 276 |
+
}
|
| 277 |
+
|
| 278 |
+
public function send_autocompleteAll(\com\boxalino\p13n\api\thrift\AutocompleteRequestBundle $bundle)
|
| 279 |
+
{
|
| 280 |
+
$args = new \com\boxalino\p13n\api\thrift\P13nService_autocompleteAll_args();
|
| 281 |
+
$args->bundle = $bundle;
|
| 282 |
+
$bin_accel = ($this->output_ instanceof TBinaryProtocolAccelerated) && function_exists('thrift_protocol_write_binary');
|
| 283 |
+
if ($bin_accel)
|
| 284 |
+
{
|
| 285 |
+
thrift_protocol_write_binary($this->output_, 'autocompleteAll', TMessageType::CALL, $args, $this->seqid_, $this->output_->isStrictWrite());
|
| 286 |
+
}
|
| 287 |
+
else
|
| 288 |
+
{
|
| 289 |
+
$this->output_->writeMessageBegin('autocompleteAll', TMessageType::CALL, $this->seqid_);
|
| 290 |
+
$args->write($this->output_);
|
| 291 |
+
$this->output_->writeMessageEnd();
|
| 292 |
+
$this->output_->getTransport()->flush();
|
| 293 |
+
}
|
| 294 |
+
}
|
| 295 |
+
|
| 296 |
+
public function recv_autocompleteAll()
|
| 297 |
+
{
|
| 298 |
+
$bin_accel = ($this->input_ instanceof TBinaryProtocolAccelerated) && function_exists('thrift_protocol_read_binary');
|
| 299 |
+
if ($bin_accel) $result = thrift_protocol_read_binary($this->input_, '\com\boxalino\p13n\api\thrift\P13nService_autocompleteAll_result', $this->input_->isStrictRead());
|
| 300 |
+
else
|
| 301 |
+
{
|
| 302 |
+
$rseqid = 0;
|
| 303 |
+
$fname = null;
|
| 304 |
+
$mtype = 0;
|
| 305 |
+
|
| 306 |
+
$this->input_->readMessageBegin($fname, $mtype, $rseqid);
|
| 307 |
+
if ($mtype == TMessageType::EXCEPTION) {
|
| 308 |
+
$x = new TApplicationException();
|
| 309 |
+
$x->read($this->input_);
|
| 310 |
+
$this->input_->readMessageEnd();
|
| 311 |
+
throw $x;
|
| 312 |
+
}
|
| 313 |
+
$result = new \com\boxalino\p13n\api\thrift\P13nService_autocompleteAll_result();
|
| 314 |
+
$result->read($this->input_);
|
| 315 |
+
$this->input_->readMessageEnd();
|
| 316 |
+
}
|
| 317 |
+
if ($result->success !== null) {
|
| 318 |
+
return $result->success;
|
| 319 |
+
}
|
| 320 |
+
if ($result->p13nServiceException !== null) {
|
| 321 |
+
throw $result->p13nServiceException;
|
| 322 |
+
}
|
| 323 |
+
throw new \Exception("autocompleteAll failed: unknown result");
|
| 324 |
+
}
|
| 325 |
+
|
| 326 |
+
public function updateChoice(\com\boxalino\p13n\api\thrift\ChoiceUpdateRequest $choiceUpdateRequest)
|
| 327 |
+
{
|
| 328 |
+
$this->send_updateChoice($choiceUpdateRequest);
|
| 329 |
+
return $this->recv_updateChoice();
|
| 330 |
+
}
|
| 331 |
+
|
| 332 |
+
public function send_updateChoice(\com\boxalino\p13n\api\thrift\ChoiceUpdateRequest $choiceUpdateRequest)
|
| 333 |
+
{
|
| 334 |
+
$args = new \com\boxalino\p13n\api\thrift\P13nService_updateChoice_args();
|
| 335 |
+
$args->choiceUpdateRequest = $choiceUpdateRequest;
|
| 336 |
+
$bin_accel = ($this->output_ instanceof TBinaryProtocolAccelerated) && function_exists('thrift_protocol_write_binary');
|
| 337 |
+
if ($bin_accel)
|
| 338 |
+
{
|
| 339 |
+
thrift_protocol_write_binary($this->output_, 'updateChoice', TMessageType::CALL, $args, $this->seqid_, $this->output_->isStrictWrite());
|
| 340 |
+
}
|
| 341 |
+
else
|
| 342 |
+
{
|
| 343 |
+
$this->output_->writeMessageBegin('updateChoice', TMessageType::CALL, $this->seqid_);
|
| 344 |
+
$args->write($this->output_);
|
| 345 |
+
$this->output_->writeMessageEnd();
|
| 346 |
+
$this->output_->getTransport()->flush();
|
| 347 |
+
}
|
| 348 |
+
}
|
| 349 |
+
|
| 350 |
+
public function recv_updateChoice()
|
| 351 |
+
{
|
| 352 |
+
$bin_accel = ($this->input_ instanceof TBinaryProtocolAccelerated) && function_exists('thrift_protocol_read_binary');
|
| 353 |
+
if ($bin_accel) $result = thrift_protocol_read_binary($this->input_, '\com\boxalino\p13n\api\thrift\P13nService_updateChoice_result', $this->input_->isStrictRead());
|
| 354 |
+
else
|
| 355 |
+
{
|
| 356 |
+
$rseqid = 0;
|
| 357 |
+
$fname = null;
|
| 358 |
+
$mtype = 0;
|
| 359 |
+
|
| 360 |
+
$this->input_->readMessageBegin($fname, $mtype, $rseqid);
|
| 361 |
+
if ($mtype == TMessageType::EXCEPTION) {
|
| 362 |
+
$x = new TApplicationException();
|
| 363 |
+
$x->read($this->input_);
|
| 364 |
+
$this->input_->readMessageEnd();
|
| 365 |
+
throw $x;
|
| 366 |
+
}
|
| 367 |
+
$result = new \com\boxalino\p13n\api\thrift\P13nService_updateChoice_result();
|
| 368 |
+
$result->read($this->input_);
|
| 369 |
+
$this->input_->readMessageEnd();
|
| 370 |
+
}
|
| 371 |
+
if ($result->success !== null) {
|
| 372 |
+
return $result->success;
|
| 373 |
+
}
|
| 374 |
+
if ($result->p13nServiceException !== null) {
|
| 375 |
+
throw $result->p13nServiceException;
|
| 376 |
+
}
|
| 377 |
+
throw new \Exception("updateChoice failed: unknown result");
|
| 378 |
+
}
|
| 379 |
+
|
| 380 |
+
}
|
| 381 |
+
|
| 382 |
+
// HELPER FUNCTIONS AND STRUCTURES
|
| 383 |
+
|
| 384 |
+
class P13nService_choose_args {
|
| 385 |
+
static $_TSPEC;
|
| 386 |
+
|
| 387 |
+
/**
|
| 388 |
+
* @var \com\boxalino\p13n\api\thrift\ChoiceRequest
|
| 389 |
+
*/
|
| 390 |
+
public $choiceRequest = null;
|
| 391 |
+
|
| 392 |
+
public function __construct($vals=null) {
|
| 393 |
+
if (!isset(self::$_TSPEC)) {
|
| 394 |
+
self::$_TSPEC = array(
|
| 395 |
+
-1 => array(
|
| 396 |
+
'var' => 'choiceRequest',
|
| 397 |
+
'type' => TType::STRUCT,
|
| 398 |
+
'class' => '\com\boxalino\p13n\api\thrift\ChoiceRequest',
|
| 399 |
+
),
|
| 400 |
+
);
|
| 401 |
+
}
|
| 402 |
+
if (is_array($vals)) {
|
| 403 |
+
if (isset($vals['choiceRequest'])) {
|
| 404 |
+
$this->choiceRequest = $vals['choiceRequest'];
|
| 405 |
+
}
|
| 406 |
+
}
|
| 407 |
+
}
|
| 408 |
+
|
| 409 |
+
public function getName() {
|
| 410 |
+
return 'P13nService_choose_args';
|
| 411 |
+
}
|
| 412 |
+
|
| 413 |
+
public function read($input)
|
| 414 |
+
{
|
| 415 |
+
$xfer = 0;
|
| 416 |
+
$fname = null;
|
| 417 |
+
$ftype = 0;
|
| 418 |
+
$fid = 0;
|
| 419 |
+
$xfer += $input->readStructBegin($fname);
|
| 420 |
+
while (true)
|
| 421 |
+
{
|
| 422 |
+
$xfer += $input->readFieldBegin($fname, $ftype, $fid);
|
| 423 |
+
if ($ftype == TType::STOP) {
|
| 424 |
+
break;
|
| 425 |
+
}
|
| 426 |
+
switch ($fid)
|
| 427 |
+
{
|
| 428 |
+
case -1:
|
| 429 |
+
if ($ftype == TType::STRUCT) {
|
| 430 |
+
$this->choiceRequest = new \com\boxalino\p13n\api\thrift\ChoiceRequest();
|
| 431 |
+
$xfer += $this->choiceRequest->read($input);
|
| 432 |
+
} else {
|
| 433 |
+
$xfer += $input->skip($ftype);
|
| 434 |
+
}
|
| 435 |
+
break;
|
| 436 |
+
default:
|
| 437 |
+
$xfer += $input->skip($ftype);
|
| 438 |
+
break;
|
| 439 |
+
}
|
| 440 |
+
$xfer += $input->readFieldEnd();
|
| 441 |
+
}
|
| 442 |
+
$xfer += $input->readStructEnd();
|
| 443 |
+
return $xfer;
|
| 444 |
+
}
|
| 445 |
+
|
| 446 |
+
public function write($output) {
|
| 447 |
+
$xfer = 0;
|
| 448 |
+
$xfer += $output->writeStructBegin('P13nService_choose_args');
|
| 449 |
+
if ($this->choiceRequest !== null) {
|
| 450 |
+
if (!is_object($this->choiceRequest)) {
|
| 451 |
+
throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA);
|
| 452 |
+
}
|
| 453 |
+
$xfer += $output->writeFieldBegin('choiceRequest', TType::STRUCT, -1);
|
| 454 |
+
$xfer += $this->choiceRequest->write($output);
|
| 455 |
+
$xfer += $output->writeFieldEnd();
|
| 456 |
+
}
|
| 457 |
+
$xfer += $output->writeFieldStop();
|
| 458 |
+
$xfer += $output->writeStructEnd();
|
| 459 |
+
return $xfer;
|
| 460 |
+
}
|
| 461 |
+
|
| 462 |
+
}
|
| 463 |
+
|
| 464 |
+
class P13nService_choose_result {
|
| 465 |
+
static $_TSPEC;
|
| 466 |
+
|
| 467 |
+
/**
|
| 468 |
+
* @var \com\boxalino\p13n\api\thrift\ChoiceResponse
|
| 469 |
+
*/
|
| 470 |
+
public $success = null;
|
| 471 |
+
/**
|
| 472 |
+
* @var \com\boxalino\p13n\api\thrift\P13nServiceException
|
| 473 |
+
*/
|
| 474 |
+
public $p13nServiceException = null;
|
| 475 |
+
|
| 476 |
+
public function __construct($vals=null) {
|
| 477 |
+
if (!isset(self::$_TSPEC)) {
|
| 478 |
+
self::$_TSPEC = array(
|
| 479 |
+
0 => array(
|
| 480 |
+
'var' => 'success',
|
| 481 |
+
'type' => TType::STRUCT,
|
| 482 |
+
'class' => '\com\boxalino\p13n\api\thrift\ChoiceResponse',
|
| 483 |
+
),
|
| 484 |
+
1 => array(
|
| 485 |
+
'var' => 'p13nServiceException',
|
| 486 |
+
'type' => TType::STRUCT,
|
| 487 |
+
'class' => '\com\boxalino\p13n\api\thrift\P13nServiceException',
|
| 488 |
+
),
|
| 489 |
+
);
|
| 490 |
+
}
|
| 491 |
+
if (is_array($vals)) {
|
| 492 |
+
if (isset($vals['success'])) {
|
| 493 |
+
$this->success = $vals['success'];
|
| 494 |
+
}
|
| 495 |
+
if (isset($vals['p13nServiceException'])) {
|
| 496 |
+
$this->p13nServiceException = $vals['p13nServiceException'];
|
| 497 |
+
}
|
| 498 |
+
}
|
| 499 |
+
}
|
| 500 |
+
|
| 501 |
+
public function getName() {
|
| 502 |
+
return 'P13nService_choose_result';
|
| 503 |
+
}
|
| 504 |
+
|
| 505 |
+
public function read($input)
|
| 506 |
+
{
|
| 507 |
+
$xfer = 0;
|
| 508 |
+
$fname = null;
|
| 509 |
+
$ftype = 0;
|
| 510 |
+
$fid = 0;
|
| 511 |
+
$xfer += $input->readStructBegin($fname);
|
| 512 |
+
while (true)
|
| 513 |
+
{
|
| 514 |
+
$xfer += $input->readFieldBegin($fname, $ftype, $fid);
|
| 515 |
+
if ($ftype == TType::STOP) {
|
| 516 |
+
break;
|
| 517 |
+
}
|
| 518 |
+
switch ($fid)
|
| 519 |
+
{
|
| 520 |
+
case 0:
|
| 521 |
+
if ($ftype == TType::STRUCT) {
|
| 522 |
+
$this->success = new \com\boxalino\p13n\api\thrift\ChoiceResponse();
|
| 523 |
+
$xfer += $this->success->read($input);
|
| 524 |
+
} else {
|
| 525 |
+
$xfer += $input->skip($ftype);
|
| 526 |
+
}
|
| 527 |
+
break;
|
| 528 |
+
case 1:
|
| 529 |
+
if ($ftype == TType::STRUCT) {
|
| 530 |
+
$this->p13nServiceException = new \com\boxalino\p13n\api\thrift\P13nServiceException();
|
| 531 |
+
$xfer += $this->p13nServiceException->read($input);
|
| 532 |
+
} else {
|
| 533 |
+
$xfer += $input->skip($ftype);
|
| 534 |
+
}
|
| 535 |
+
break;
|
| 536 |
+
default:
|
| 537 |
+
$xfer += $input->skip($ftype);
|
| 538 |
+
break;
|
| 539 |
+
}
|
| 540 |
+
$xfer += $input->readFieldEnd();
|
| 541 |
+
}
|
| 542 |
+
$xfer += $input->readStructEnd();
|
| 543 |
+
return $xfer;
|
| 544 |
+
}
|
| 545 |
+
|
| 546 |
+
public function write($output) {
|
| 547 |
+
$xfer = 0;
|
| 548 |
+
$xfer += $output->writeStructBegin('P13nService_choose_result');
|
| 549 |
+
if ($this->success !== null) {
|
| 550 |
+
if (!is_object($this->success)) {
|
| 551 |
+
throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA);
|
| 552 |
+
}
|
| 553 |
+
$xfer += $output->writeFieldBegin('success', TType::STRUCT, 0);
|
| 554 |
+
$xfer += $this->success->write($output);
|
| 555 |
+
$xfer += $output->writeFieldEnd();
|
| 556 |
+
}
|
| 557 |
+
if ($this->p13nServiceException !== null) {
|
| 558 |
+
$xfer += $output->writeFieldBegin('p13nServiceException', TType::STRUCT, 1);
|
| 559 |
+
$xfer += $this->p13nServiceException->write($output);
|
| 560 |
+
$xfer += $output->writeFieldEnd();
|
| 561 |
+
}
|
| 562 |
+
$xfer += $output->writeFieldStop();
|
| 563 |
+
$xfer += $output->writeStructEnd();
|
| 564 |
+
return $xfer;
|
| 565 |
+
}
|
| 566 |
+
|
| 567 |
+
}
|
| 568 |
+
|
| 569 |
+
class P13nService_batchChoose_args {
|
| 570 |
+
static $_TSPEC;
|
| 571 |
+
|
| 572 |
+
/**
|
| 573 |
+
* @var \com\boxalino\p13n\api\thrift\BatchChoiceRequest
|
| 574 |
+
*/
|
| 575 |
+
public $batchChoiceRequest = null;
|
| 576 |
+
|
| 577 |
+
public function __construct($vals=null) {
|
| 578 |
+
if (!isset(self::$_TSPEC)) {
|
| 579 |
+
self::$_TSPEC = array(
|
| 580 |
+
-1 => array(
|
| 581 |
+
'var' => 'batchChoiceRequest',
|
| 582 |
+
'type' => TType::STRUCT,
|
| 583 |
+
'class' => '\com\boxalino\p13n\api\thrift\BatchChoiceRequest',
|
| 584 |
+
),
|
| 585 |
+
);
|
| 586 |
+
}
|
| 587 |
+
if (is_array($vals)) {
|
| 588 |
+
if (isset($vals['batchChoiceRequest'])) {
|
| 589 |
+
$this->batchChoiceRequest = $vals['batchChoiceRequest'];
|
| 590 |
+
}
|
| 591 |
+
}
|
| 592 |
+
}
|
| 593 |
+
|
| 594 |
+
public function getName() {
|
| 595 |
+
return 'P13nService_batchChoose_args';
|
| 596 |
+
}
|
| 597 |
+
|
| 598 |
+
public function read($input)
|
| 599 |
+
{
|
| 600 |
+
$xfer = 0;
|
| 601 |
+
$fname = null;
|
| 602 |
+
$ftype = 0;
|
| 603 |
+
$fid = 0;
|
| 604 |
+
$xfer += $input->readStructBegin($fname);
|
| 605 |
+
while (true)
|
| 606 |
+
{
|
| 607 |
+
$xfer += $input->readFieldBegin($fname, $ftype, $fid);
|
| 608 |
+
if ($ftype == TType::STOP) {
|
| 609 |
+
break;
|
| 610 |
+
}
|
| 611 |
+
switch ($fid)
|
| 612 |
+
{
|
| 613 |
+
case -1:
|
| 614 |
+
if ($ftype == TType::STRUCT) {
|
| 615 |
+
$this->batchChoiceRequest = new \com\boxalino\p13n\api\thrift\BatchChoiceRequest();
|
| 616 |
+
$xfer += $this->batchChoiceRequest->read($input);
|
| 617 |
+
} else {
|
| 618 |
+
$xfer += $input->skip($ftype);
|
| 619 |
+
}
|
| 620 |
+
break;
|
| 621 |
+
default:
|
| 622 |
+
$xfer += $input->skip($ftype);
|
| 623 |
+
break;
|
| 624 |
+
}
|
| 625 |
+
$xfer += $input->readFieldEnd();
|
| 626 |
+
}
|
| 627 |
+
$xfer += $input->readStructEnd();
|
| 628 |
+
return $xfer;
|
| 629 |
+
}
|
| 630 |
+
|
| 631 |
+
public function write($output) {
|
| 632 |
+
$xfer = 0;
|
| 633 |
+
$xfer += $output->writeStructBegin('P13nService_batchChoose_args');
|
| 634 |
+
if ($this->batchChoiceRequest !== null) {
|
| 635 |
+
if (!is_object($this->batchChoiceRequest)) {
|
| 636 |
+
throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA);
|
| 637 |
+
}
|
| 638 |
+
$xfer += $output->writeFieldBegin('batchChoiceRequest', TType::STRUCT, -1);
|
| 639 |
+
$xfer += $this->batchChoiceRequest->write($output);
|
| 640 |
+
$xfer += $output->writeFieldEnd();
|
| 641 |
+
}
|
| 642 |
+
$xfer += $output->writeFieldStop();
|
| 643 |
+
$xfer += $output->writeStructEnd();
|
| 644 |
+
return $xfer;
|
| 645 |
+
}
|
| 646 |
+
|
| 647 |
+
}
|
| 648 |
+
|
| 649 |
+
class P13nService_batchChoose_result {
|
| 650 |
+
static $_TSPEC;
|
| 651 |
+
|
| 652 |
+
/**
|
| 653 |
+
* @var \com\boxalino\p13n\api\thrift\BatchChoiceResponse
|
| 654 |
+
*/
|
| 655 |
+
public $success = null;
|
| 656 |
+
/**
|
| 657 |
+
* @var \com\boxalino\p13n\api\thrift\P13nServiceException
|
| 658 |
+
*/
|
| 659 |
+
public $p13nServiceException = null;
|
| 660 |
+
|
| 661 |
+
public function __construct($vals=null) {
|
| 662 |
+
if (!isset(self::$_TSPEC)) {
|
| 663 |
+
self::$_TSPEC = array(
|
| 664 |
+
0 => array(
|
| 665 |
+
'var' => 'success',
|
| 666 |
+
'type' => TType::STRUCT,
|
| 667 |
+
'class' => '\com\boxalino\p13n\api\thrift\BatchChoiceResponse',
|
| 668 |
+
),
|
| 669 |
+
1 => array(
|
| 670 |
+
'var' => 'p13nServiceException',
|
| 671 |
+
'type' => TType::STRUCT,
|
| 672 |
+
'class' => '\com\boxalino\p13n\api\thrift\P13nServiceException',
|
| 673 |
+
),
|
| 674 |
+
);
|
| 675 |
+
}
|
| 676 |
+
if (is_array($vals)) {
|
| 677 |
+
if (isset($vals['success'])) {
|
| 678 |
+
$this->success = $vals['success'];
|
| 679 |
+
}
|
| 680 |
+
if (isset($vals['p13nServiceException'])) {
|
| 681 |
+
$this->p13nServiceException = $vals['p13nServiceException'];
|
| 682 |
+
}
|
| 683 |
+
}
|
| 684 |
+
}
|
| 685 |
+
|
| 686 |
+
public function getName() {
|
| 687 |
+
return 'P13nService_batchChoose_result';
|
| 688 |
+
}
|
| 689 |
+
|
| 690 |
+
public function read($input)
|
| 691 |
+
{
|
| 692 |
+
$xfer = 0;
|
| 693 |
+
$fname = null;
|
| 694 |
+
$ftype = 0;
|
| 695 |
+
$fid = 0;
|
| 696 |
+
$xfer += $input->readStructBegin($fname);
|
| 697 |
+
while (true)
|
| 698 |
+
{
|
| 699 |
+
$xfer += $input->readFieldBegin($fname, $ftype, $fid);
|
| 700 |
+
if ($ftype == TType::STOP) {
|
| 701 |
+
break;
|
| 702 |
+
}
|
| 703 |
+
switch ($fid)
|
| 704 |
+
{
|
| 705 |
+
case 0:
|
| 706 |
+
if ($ftype == TType::STRUCT) {
|
| 707 |
+
$this->success = new \com\boxalino\p13n\api\thrift\BatchChoiceResponse();
|
| 708 |
+
$xfer += $this->success->read($input);
|
| 709 |
+
} else {
|
| 710 |
+
$xfer += $input->skip($ftype);
|
| 711 |
+
}
|
| 712 |
+
break;
|
| 713 |
+
case 1:
|
| 714 |
+
if ($ftype == TType::STRUCT) {
|
| 715 |
+
$this->p13nServiceException = new \com\boxalino\p13n\api\thrift\P13nServiceException();
|
| 716 |
+
$xfer += $this->p13nServiceException->read($input);
|
| 717 |
+
} else {
|
| 718 |
+
$xfer += $input->skip($ftype);
|
| 719 |
+
}
|
| 720 |
+
break;
|
| 721 |
+
default:
|
| 722 |
+
$xfer += $input->skip($ftype);
|
| 723 |
+
break;
|
| 724 |
+
}
|
| 725 |
+
$xfer += $input->readFieldEnd();
|
| 726 |
+
}
|
| 727 |
+
$xfer += $input->readStructEnd();
|
| 728 |
+
return $xfer;
|
| 729 |
+
}
|
| 730 |
+
|
| 731 |
+
public function write($output) {
|
| 732 |
+
$xfer = 0;
|
| 733 |
+
$xfer += $output->writeStructBegin('P13nService_batchChoose_result');
|
| 734 |
+
if ($this->success !== null) {
|
| 735 |
+
if (!is_object($this->success)) {
|
| 736 |
+
throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA);
|
| 737 |
+
}
|
| 738 |
+
$xfer += $output->writeFieldBegin('success', TType::STRUCT, 0);
|
| 739 |
+
$xfer += $this->success->write($output);
|
| 740 |
+
$xfer += $output->writeFieldEnd();
|
| 741 |
+
}
|
| 742 |
+
if ($this->p13nServiceException !== null) {
|
| 743 |
+
$xfer += $output->writeFieldBegin('p13nServiceException', TType::STRUCT, 1);
|
| 744 |
+
$xfer += $this->p13nServiceException->write($output);
|
| 745 |
+
$xfer += $output->writeFieldEnd();
|
| 746 |
+
}
|
| 747 |
+
$xfer += $output->writeFieldStop();
|
| 748 |
+
$xfer += $output->writeStructEnd();
|
| 749 |
+
return $xfer;
|
| 750 |
+
}
|
| 751 |
+
|
| 752 |
+
}
|
| 753 |
+
|
| 754 |
+
class P13nService_autocomplete_args {
|
| 755 |
+
static $_TSPEC;
|
| 756 |
+
|
| 757 |
+
/**
|
| 758 |
+
* @var \com\boxalino\p13n\api\thrift\AutocompleteRequest
|
| 759 |
+
*/
|
| 760 |
+
public $request = null;
|
| 761 |
+
|
| 762 |
+
public function __construct($vals=null) {
|
| 763 |
+
if (!isset(self::$_TSPEC)) {
|
| 764 |
+
self::$_TSPEC = array(
|
| 765 |
+
-1 => array(
|
| 766 |
+
'var' => 'request',
|
| 767 |
+
'type' => TType::STRUCT,
|
| 768 |
+
'class' => '\com\boxalino\p13n\api\thrift\AutocompleteRequest',
|
| 769 |
+
),
|
| 770 |
+
);
|
| 771 |
+
}
|
| 772 |
+
if (is_array($vals)) {
|
| 773 |
+
if (isset($vals['request'])) {
|
| 774 |
+
$this->request = $vals['request'];
|
| 775 |
+
}
|
| 776 |
+
}
|
| 777 |
+
}
|
| 778 |
+
|
| 779 |
+
public function getName() {
|
| 780 |
+
return 'P13nService_autocomplete_args';
|
| 781 |
+
}
|
| 782 |
+
|
| 783 |
+
public function read($input)
|
| 784 |
+
{
|
| 785 |
+
$xfer = 0;
|
| 786 |
+
$fname = null;
|
| 787 |
+
$ftype = 0;
|
| 788 |
+
$fid = 0;
|
| 789 |
+
$xfer += $input->readStructBegin($fname);
|
| 790 |
+
while (true)
|
| 791 |
+
{
|
| 792 |
+
$xfer += $input->readFieldBegin($fname, $ftype, $fid);
|
| 793 |
+
if ($ftype == TType::STOP) {
|
| 794 |
+
break;
|
| 795 |
+
}
|
| 796 |
+
switch ($fid)
|
| 797 |
+
{
|
| 798 |
+
case -1:
|
| 799 |
+
if ($ftype == TType::STRUCT) {
|
| 800 |
+
$this->request = new \com\boxalino\p13n\api\thrift\AutocompleteRequest();
|
| 801 |
+
$xfer += $this->request->read($input);
|
| 802 |
+
} else {
|
| 803 |
+
$xfer += $input->skip($ftype);
|
| 804 |
+
}
|
| 805 |
+
break;
|
| 806 |
+
default:
|
| 807 |
+
$xfer += $input->skip($ftype);
|
| 808 |
+
break;
|
| 809 |
+
}
|
| 810 |
+
$xfer += $input->readFieldEnd();
|
| 811 |
+
}
|
| 812 |
+
$xfer += $input->readStructEnd();
|
| 813 |
+
return $xfer;
|
| 814 |
+
}
|
| 815 |
+
|
| 816 |
+
public function write($output) {
|
| 817 |
+
$xfer = 0;
|
| 818 |
+
$xfer += $output->writeStructBegin('P13nService_autocomplete_args');
|
| 819 |
+
if ($this->request !== null) {
|
| 820 |
+
if (!is_object($this->request)) {
|
| 821 |
+
throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA);
|
| 822 |
+
}
|
| 823 |
+
$xfer += $output->writeFieldBegin('request', TType::STRUCT, -1);
|
| 824 |
+
$xfer += $this->request->write($output);
|
| 825 |
+
$xfer += $output->writeFieldEnd();
|
| 826 |
+
}
|
| 827 |
+
$xfer += $output->writeFieldStop();
|
| 828 |
+
$xfer += $output->writeStructEnd();
|
| 829 |
+
return $xfer;
|
| 830 |
+
}
|
| 831 |
+
|
| 832 |
+
}
|
| 833 |
+
|
| 834 |
+
class P13nService_autocomplete_result {
|
| 835 |
+
static $_TSPEC;
|
| 836 |
+
|
| 837 |
+
/**
|
| 838 |
+
* @var \com\boxalino\p13n\api\thrift\AutocompleteResponse
|
| 839 |
+
*/
|
| 840 |
+
public $success = null;
|
| 841 |
+
/**
|
| 842 |
+
* @var \com\boxalino\p13n\api\thrift\P13nServiceException
|
| 843 |
+
*/
|
| 844 |
+
public $p13nServiceException = null;
|
| 845 |
+
|
| 846 |
+
public function __construct($vals=null) {
|
| 847 |
+
if (!isset(self::$_TSPEC)) {
|
| 848 |
+
self::$_TSPEC = array(
|
| 849 |
+
0 => array(
|
| 850 |
+
'var' => 'success',
|
| 851 |
+
'type' => TType::STRUCT,
|
| 852 |
+
'class' => '\com\boxalino\p13n\api\thrift\AutocompleteResponse',
|
| 853 |
+
),
|
| 854 |
+
1 => array(
|
| 855 |
+
'var' => 'p13nServiceException',
|
| 856 |
+
'type' => TType::STRUCT,
|
| 857 |
+
'class' => '\com\boxalino\p13n\api\thrift\P13nServiceException',
|
| 858 |
+
),
|
| 859 |
+
);
|
| 860 |
+
}
|
| 861 |
+
if (is_array($vals)) {
|
| 862 |
+
if (isset($vals['success'])) {
|
| 863 |
+
$this->success = $vals['success'];
|
| 864 |
+
}
|
| 865 |
+
if (isset($vals['p13nServiceException'])) {
|
| 866 |
+
$this->p13nServiceException = $vals['p13nServiceException'];
|
| 867 |
+
}
|
| 868 |
+
}
|
| 869 |
+
}
|
| 870 |
+
|
| 871 |
+
public function getName() {
|
| 872 |
+
return 'P13nService_autocomplete_result';
|
| 873 |
+
}
|
| 874 |
+
|
| 875 |
+
public function read($input)
|
| 876 |
+
{
|
| 877 |
+
$xfer = 0;
|
| 878 |
+
$fname = null;
|
| 879 |
+
$ftype = 0;
|
| 880 |
+
$fid = 0;
|
| 881 |
+
$xfer += $input->readStructBegin($fname);
|
| 882 |
+
while (true)
|
| 883 |
+
{
|
| 884 |
+
$xfer += $input->readFieldBegin($fname, $ftype, $fid);
|
| 885 |
+
if ($ftype == TType::STOP) {
|
| 886 |
+
break;
|
| 887 |
+
}
|
| 888 |
+
switch ($fid)
|
| 889 |
+
{
|
| 890 |
+
case 0:
|
| 891 |
+
if ($ftype == TType::STRUCT) {
|
| 892 |
+
$this->success = new \com\boxalino\p13n\api\thrift\AutocompleteResponse();
|
| 893 |
+
$xfer += $this->success->read($input);
|
| 894 |
+
} else {
|
| 895 |
+
$xfer += $input->skip($ftype);
|
| 896 |
+
}
|
| 897 |
+
break;
|
| 898 |
+
case 1:
|
| 899 |
+
if ($ftype == TType::STRUCT) {
|
| 900 |
+
$this->p13nServiceException = new \com\boxalino\p13n\api\thrift\P13nServiceException();
|
| 901 |
+
$xfer += $this->p13nServiceException->read($input);
|
| 902 |
+
} else {
|
| 903 |
+
$xfer += $input->skip($ftype);
|
| 904 |
+
}
|
| 905 |
+
break;
|
| 906 |
+
default:
|
| 907 |
+
$xfer += $input->skip($ftype);
|
| 908 |
+
break;
|
| 909 |
+
}
|
| 910 |
+
$xfer += $input->readFieldEnd();
|
| 911 |
+
}
|
| 912 |
+
$xfer += $input->readStructEnd();
|
| 913 |
+
return $xfer;
|
| 914 |
+
}
|
| 915 |
+
|
| 916 |
+
public function write($output) {
|
| 917 |
+
$xfer = 0;
|
| 918 |
+
$xfer += $output->writeStructBegin('P13nService_autocomplete_result');
|
| 919 |
+
if ($this->success !== null) {
|
| 920 |
+
if (!is_object($this->success)) {
|
| 921 |
+
throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA);
|
| 922 |
+
}
|
| 923 |
+
$xfer += $output->writeFieldBegin('success', TType::STRUCT, 0);
|
| 924 |
+
$xfer += $this->success->write($output);
|
| 925 |
+
$xfer += $output->writeFieldEnd();
|
| 926 |
+
}
|
| 927 |
+
if ($this->p13nServiceException !== null) {
|
| 928 |
+
$xfer += $output->writeFieldBegin('p13nServiceException', TType::STRUCT, 1);
|
| 929 |
+
$xfer += $this->p13nServiceException->write($output);
|
| 930 |
+
$xfer += $output->writeFieldEnd();
|
| 931 |
+
}
|
| 932 |
+
$xfer += $output->writeFieldStop();
|
| 933 |
+
$xfer += $output->writeStructEnd();
|
| 934 |
+
return $xfer;
|
| 935 |
+
}
|
| 936 |
+
|
| 937 |
+
}
|
| 938 |
+
|
| 939 |
+
class P13nService_autocompleteAll_args {
|
| 940 |
+
static $_TSPEC;
|
| 941 |
+
|
| 942 |
+
/**
|
| 943 |
+
* @var \com\boxalino\p13n\api\thrift\AutocompleteRequestBundle
|
| 944 |
+
*/
|
| 945 |
+
public $bundle = null;
|
| 946 |
+
|
| 947 |
+
public function __construct($vals=null) {
|
| 948 |
+
if (!isset(self::$_TSPEC)) {
|
| 949 |
+
self::$_TSPEC = array(
|
| 950 |
+
-1 => array(
|
| 951 |
+
'var' => 'bundle',
|
| 952 |
+
'type' => TType::STRUCT,
|
| 953 |
+
'class' => '\com\boxalino\p13n\api\thrift\AutocompleteRequestBundle',
|
| 954 |
+
),
|
| 955 |
+
);
|
| 956 |
+
}
|
| 957 |
+
if (is_array($vals)) {
|
| 958 |
+
if (isset($vals['bundle'])) {
|
| 959 |
+
$this->bundle = $vals['bundle'];
|
| 960 |
+
}
|
| 961 |
+
}
|
| 962 |
+
}
|
| 963 |
+
|
| 964 |
+
public function getName() {
|
| 965 |
+
return 'P13nService_autocompleteAll_args';
|
| 966 |
+
}
|
| 967 |
+
|
| 968 |
+
public function read($input)
|
| 969 |
+
{
|
| 970 |
+
$xfer = 0;
|
| 971 |
+
$fname = null;
|
| 972 |
+
$ftype = 0;
|
| 973 |
+
$fid = 0;
|
| 974 |
+
$xfer += $input->readStructBegin($fname);
|
| 975 |
+
while (true)
|
| 976 |
+
{
|
| 977 |
+
$xfer += $input->readFieldBegin($fname, $ftype, $fid);
|
| 978 |
+
if ($ftype == TType::STOP) {
|
| 979 |
+
break;
|
| 980 |
+
}
|
| 981 |
+
switch ($fid)
|
| 982 |
+
{
|
| 983 |
+
case -1:
|
| 984 |
+
if ($ftype == TType::STRUCT) {
|
| 985 |
+
$this->bundle = new \com\boxalino\p13n\api\thrift\AutocompleteRequestBundle();
|
| 986 |
+
$xfer += $this->bundle->read($input);
|
| 987 |
+
} else {
|
| 988 |
+
$xfer += $input->skip($ftype);
|
| 989 |
+
}
|
| 990 |
+
break;
|
| 991 |
+
default:
|
| 992 |
+
$xfer += $input->skip($ftype);
|
| 993 |
+
break;
|
| 994 |
+
}
|
| 995 |
+
$xfer += $input->readFieldEnd();
|
| 996 |
+
}
|
| 997 |
+
$xfer += $input->readStructEnd();
|
| 998 |
+
return $xfer;
|
| 999 |
+
}
|
| 1000 |
+
|
| 1001 |
+
public function write($output) {
|
| 1002 |
+
$xfer = 0;
|
| 1003 |
+
$xfer += $output->writeStructBegin('P13nService_autocompleteAll_args');
|
| 1004 |
+
if ($this->bundle !== null) {
|
| 1005 |
+
if (!is_object($this->bundle)) {
|
| 1006 |
+
throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA);
|
| 1007 |
+
}
|
| 1008 |
+
$xfer += $output->writeFieldBegin('bundle', TType::STRUCT, -1);
|
| 1009 |
+
$xfer += $this->bundle->write($output);
|
| 1010 |
+
$xfer += $output->writeFieldEnd();
|
| 1011 |
+
}
|
| 1012 |
+
$xfer += $output->writeFieldStop();
|
| 1013 |
+
$xfer += $output->writeStructEnd();
|
| 1014 |
+
return $xfer;
|
| 1015 |
+
}
|
| 1016 |
+
|
| 1017 |
+
}
|
| 1018 |
+
|
| 1019 |
+
class P13nService_autocompleteAll_result {
|
| 1020 |
+
static $_TSPEC;
|
| 1021 |
+
|
| 1022 |
+
/**
|
| 1023 |
+
* @var \com\boxalino\p13n\api\thrift\AutocompleteResponseBundle
|
| 1024 |
+
*/
|
| 1025 |
+
public $success = null;
|
| 1026 |
+
/**
|
| 1027 |
+
* @var \com\boxalino\p13n\api\thrift\P13nServiceException
|
| 1028 |
+
*/
|
| 1029 |
+
public $p13nServiceException = null;
|
| 1030 |
+
|
| 1031 |
+
public function __construct($vals=null) {
|
| 1032 |
+
if (!isset(self::$_TSPEC)) {
|
| 1033 |
+
self::$_TSPEC = array(
|
| 1034 |
+
0 => array(
|
| 1035 |
+
'var' => 'success',
|
| 1036 |
+
'type' => TType::STRUCT,
|
| 1037 |
+
'class' => '\com\boxalino\p13n\api\thrift\AutocompleteResponseBundle',
|
| 1038 |
+
),
|
| 1039 |
+
1 => array(
|
| 1040 |
+
'var' => 'p13nServiceException',
|
| 1041 |
+
'type' => TType::STRUCT,
|
| 1042 |
+
'class' => '\com\boxalino\p13n\api\thrift\P13nServiceException',
|
| 1043 |
+
),
|
| 1044 |
+
);
|
| 1045 |
+
}
|
| 1046 |
+
if (is_array($vals)) {
|
| 1047 |
+
if (isset($vals['success'])) {
|
| 1048 |
+
$this->success = $vals['success'];
|
| 1049 |
+
}
|
| 1050 |
+
if (isset($vals['p13nServiceException'])) {
|
| 1051 |
+
$this->p13nServiceException = $vals['p13nServiceException'];
|
| 1052 |
+
}
|
| 1053 |
+
}
|
| 1054 |
+
}
|
| 1055 |
+
|
| 1056 |
+
public function getName() {
|
| 1057 |
+
return 'P13nService_autocompleteAll_result';
|
| 1058 |
+
}
|
| 1059 |
+
|
| 1060 |
+
public function read($input)
|
| 1061 |
+
{
|
| 1062 |
+
$xfer = 0;
|
| 1063 |
+
$fname = null;
|
| 1064 |
+
$ftype = 0;
|
| 1065 |
+
$fid = 0;
|
| 1066 |
+
$xfer += $input->readStructBegin($fname);
|
| 1067 |
+
while (true)
|
| 1068 |
+
{
|
| 1069 |
+
$xfer += $input->readFieldBegin($fname, $ftype, $fid);
|
| 1070 |
+
if ($ftype == TType::STOP) {
|
| 1071 |
+
break;
|
| 1072 |
+
}
|
| 1073 |
+
switch ($fid)
|
| 1074 |
+
{
|
| 1075 |
+
case 0:
|
| 1076 |
+
if ($ftype == TType::STRUCT) {
|
| 1077 |
+
$this->success = new \com\boxalino\p13n\api\thrift\AutocompleteResponseBundle();
|
| 1078 |
+
$xfer += $this->success->read($input);
|
| 1079 |
+
} else {
|
| 1080 |
+
$xfer += $input->skip($ftype);
|
| 1081 |
+
}
|
| 1082 |
+
break;
|
| 1083 |
+
case 1:
|
| 1084 |
+
if ($ftype == TType::STRUCT) {
|
| 1085 |
+
$this->p13nServiceException = new \com\boxalino\p13n\api\thrift\P13nServiceException();
|
| 1086 |
+
$xfer += $this->p13nServiceException->read($input);
|
| 1087 |
+
} else {
|
| 1088 |
+
$xfer += $input->skip($ftype);
|
| 1089 |
+
}
|
| 1090 |
+
break;
|
| 1091 |
+
default:
|
| 1092 |
+
$xfer += $input->skip($ftype);
|
| 1093 |
+
break;
|
| 1094 |
+
}
|
| 1095 |
+
$xfer += $input->readFieldEnd();
|
| 1096 |
+
}
|
| 1097 |
+
$xfer += $input->readStructEnd();
|
| 1098 |
+
return $xfer;
|
| 1099 |
+
}
|
| 1100 |
+
|
| 1101 |
+
public function write($output) {
|
| 1102 |
+
$xfer = 0;
|
| 1103 |
+
$xfer += $output->writeStructBegin('P13nService_autocompleteAll_result');
|
| 1104 |
+
if ($this->success !== null) {
|
| 1105 |
+
if (!is_object($this->success)) {
|
| 1106 |
+
throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA);
|
| 1107 |
+
}
|
| 1108 |
+
$xfer += $output->writeFieldBegin('success', TType::STRUCT, 0);
|
| 1109 |
+
$xfer += $this->success->write($output);
|
| 1110 |
+
$xfer += $output->writeFieldEnd();
|
| 1111 |
+
}
|
| 1112 |
+
if ($this->p13nServiceException !== null) {
|
| 1113 |
+
$xfer += $output->writeFieldBegin('p13nServiceException', TType::STRUCT, 1);
|
| 1114 |
+
$xfer += $this->p13nServiceException->write($output);
|
| 1115 |
+
$xfer += $output->writeFieldEnd();
|
| 1116 |
+
}
|
| 1117 |
+
$xfer += $output->writeFieldStop();
|
| 1118 |
+
$xfer += $output->writeStructEnd();
|
| 1119 |
+
return $xfer;
|
| 1120 |
+
}
|
| 1121 |
+
|
| 1122 |
+
}
|
| 1123 |
+
|
| 1124 |
+
class P13nService_updateChoice_args {
|
| 1125 |
+
static $_TSPEC;
|
| 1126 |
+
|
| 1127 |
+
/**
|
| 1128 |
+
* @var \com\boxalino\p13n\api\thrift\ChoiceUpdateRequest
|
| 1129 |
+
*/
|
| 1130 |
+
public $choiceUpdateRequest = null;
|
| 1131 |
+
|
| 1132 |
+
public function __construct($vals=null) {
|
| 1133 |
+
if (!isset(self::$_TSPEC)) {
|
| 1134 |
+
self::$_TSPEC = array(
|
| 1135 |
+
-1 => array(
|
| 1136 |
+
'var' => 'choiceUpdateRequest',
|
| 1137 |
+
'type' => TType::STRUCT,
|
| 1138 |
+
'class' => '\com\boxalino\p13n\api\thrift\ChoiceUpdateRequest',
|
| 1139 |
+
),
|
| 1140 |
+
);
|
| 1141 |
+
}
|
| 1142 |
+
if (is_array($vals)) {
|
| 1143 |
+
if (isset($vals['choiceUpdateRequest'])) {
|
| 1144 |
+
$this->choiceUpdateRequest = $vals['choiceUpdateRequest'];
|
| 1145 |
+
}
|
| 1146 |
+
}
|
| 1147 |
+
}
|
| 1148 |
+
|
| 1149 |
+
public function getName() {
|
| 1150 |
+
return 'P13nService_updateChoice_args';
|
| 1151 |
+
}
|
| 1152 |
+
|
| 1153 |
+
public function read($input)
|
| 1154 |
+
{
|
| 1155 |
+
$xfer = 0;
|
| 1156 |
+
$fname = null;
|
| 1157 |
+
$ftype = 0;
|
| 1158 |
+
$fid = 0;
|
| 1159 |
+
$xfer += $input->readStructBegin($fname);
|
| 1160 |
+
while (true)
|
| 1161 |
+
{
|
| 1162 |
+
$xfer += $input->readFieldBegin($fname, $ftype, $fid);
|
| 1163 |
+
if ($ftype == TType::STOP) {
|
| 1164 |
+
break;
|
| 1165 |
+
}
|
| 1166 |
+
switch ($fid)
|
| 1167 |
+
{
|
| 1168 |
+
case -1:
|
| 1169 |
+
if ($ftype == TType::STRUCT) {
|
| 1170 |
+
$this->choiceUpdateRequest = new \com\boxalino\p13n\api\thrift\ChoiceUpdateRequest();
|
| 1171 |
+
$xfer += $this->choiceUpdateRequest->read($input);
|
| 1172 |
+
} else {
|
| 1173 |
+
$xfer += $input->skip($ftype);
|
| 1174 |
+
}
|
| 1175 |
+
break;
|
| 1176 |
+
default:
|
| 1177 |
+
$xfer += $input->skip($ftype);
|
| 1178 |
+
break;
|
| 1179 |
+
}
|
| 1180 |
+
$xfer += $input->readFieldEnd();
|
| 1181 |
+
}
|
| 1182 |
+
$xfer += $input->readStructEnd();
|
| 1183 |
+
return $xfer;
|
| 1184 |
+
}
|
| 1185 |
+
|
| 1186 |
+
public function write($output) {
|
| 1187 |
+
$xfer = 0;
|
| 1188 |
+
$xfer += $output->writeStructBegin('P13nService_updateChoice_args');
|
| 1189 |
+
if ($this->choiceUpdateRequest !== null) {
|
| 1190 |
+
if (!is_object($this->choiceUpdateRequest)) {
|
| 1191 |
+
throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA);
|
| 1192 |
+
}
|
| 1193 |
+
$xfer += $output->writeFieldBegin('choiceUpdateRequest', TType::STRUCT, -1);
|
| 1194 |
+
$xfer += $this->choiceUpdateRequest->write($output);
|
| 1195 |
+
$xfer += $output->writeFieldEnd();
|
| 1196 |
+
}
|
| 1197 |
+
$xfer += $output->writeFieldStop();
|
| 1198 |
+
$xfer += $output->writeStructEnd();
|
| 1199 |
+
return $xfer;
|
| 1200 |
+
}
|
| 1201 |
+
|
| 1202 |
+
}
|
| 1203 |
+
|
| 1204 |
+
class P13nService_updateChoice_result {
|
| 1205 |
+
static $_TSPEC;
|
| 1206 |
+
|
| 1207 |
+
/**
|
| 1208 |
+
* @var \com\boxalino\p13n\api\thrift\ChoiceUpdateResponse
|
| 1209 |
+
*/
|
| 1210 |
+
public $success = null;
|
| 1211 |
+
/**
|
| 1212 |
+
* @var \com\boxalino\p13n\api\thrift\P13nServiceException
|
| 1213 |
+
*/
|
| 1214 |
+
public $p13nServiceException = null;
|
| 1215 |
+
|
| 1216 |
+
public function __construct($vals=null) {
|
| 1217 |
+
if (!isset(self::$_TSPEC)) {
|
| 1218 |
+
self::$_TSPEC = array(
|
| 1219 |
+
0 => array(
|
| 1220 |
+
'var' => 'success',
|
| 1221 |
+
'type' => TType::STRUCT,
|
| 1222 |
+
'class' => '\com\boxalino\p13n\api\thrift\ChoiceUpdateResponse',
|
| 1223 |
+
),
|
| 1224 |
+
1 => array(
|
| 1225 |
+
'var' => 'p13nServiceException',
|
| 1226 |
+
'type' => TType::STRUCT,
|
| 1227 |
+
'class' => '\com\boxalino\p13n\api\thrift\P13nServiceException',
|
| 1228 |
+
),
|
| 1229 |
+
);
|
| 1230 |
+
}
|
| 1231 |
+
if (is_array($vals)) {
|
| 1232 |
+
if (isset($vals['success'])) {
|
| 1233 |
+
$this->success = $vals['success'];
|
| 1234 |
+
}
|
| 1235 |
+
if (isset($vals['p13nServiceException'])) {
|
| 1236 |
+
$this->p13nServiceException = $vals['p13nServiceException'];
|
| 1237 |
+
}
|
| 1238 |
+
}
|
| 1239 |
+
}
|
| 1240 |
+
|
| 1241 |
+
public function getName() {
|
| 1242 |
+
return 'P13nService_updateChoice_result';
|
| 1243 |
+
}
|
| 1244 |
+
|
| 1245 |
+
public function read($input)
|
| 1246 |
+
{
|
| 1247 |
+
$xfer = 0;
|
| 1248 |
+
$fname = null;
|
| 1249 |
+
$ftype = 0;
|
| 1250 |
+
$fid = 0;
|
| 1251 |
+
$xfer += $input->readStructBegin($fname);
|
| 1252 |
+
while (true)
|
| 1253 |
+
{
|
| 1254 |
+
$xfer += $input->readFieldBegin($fname, $ftype, $fid);
|
| 1255 |
+
if ($ftype == TType::STOP) {
|
| 1256 |
+
break;
|
| 1257 |
+
}
|
| 1258 |
+
switch ($fid)
|
| 1259 |
+
{
|
| 1260 |
+
case 0:
|
| 1261 |
+
if ($ftype == TType::STRUCT) {
|
| 1262 |
+
$this->success = new \com\boxalino\p13n\api\thrift\ChoiceUpdateResponse();
|
| 1263 |
+
$xfer += $this->success->read($input);
|
| 1264 |
+
} else {
|
| 1265 |
+
$xfer += $input->skip($ftype);
|
| 1266 |
+
}
|
| 1267 |
+
break;
|
| 1268 |
+
case 1:
|
| 1269 |
+
if ($ftype == TType::STRUCT) {
|
| 1270 |
+
$this->p13nServiceException = new \com\boxalino\p13n\api\thrift\P13nServiceException();
|
| 1271 |
+
$xfer += $this->p13nServiceException->read($input);
|
| 1272 |
+
} else {
|
| 1273 |
+
$xfer += $input->skip($ftype);
|
| 1274 |
+
}
|
| 1275 |
+
break;
|
| 1276 |
+
default:
|
| 1277 |
+
$xfer += $input->skip($ftype);
|
| 1278 |
+
break;
|
| 1279 |
+
}
|
| 1280 |
+
$xfer += $input->readFieldEnd();
|
| 1281 |
+
}
|
| 1282 |
+
$xfer += $input->readStructEnd();
|
| 1283 |
+
return $xfer;
|
| 1284 |
+
}
|
| 1285 |
+
|
| 1286 |
+
public function write($output) {
|
| 1287 |
+
$xfer = 0;
|
| 1288 |
+
$xfer += $output->writeStructBegin('P13nService_updateChoice_result');
|
| 1289 |
+
if ($this->success !== null) {
|
| 1290 |
+
if (!is_object($this->success)) {
|
| 1291 |
+
throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA);
|
| 1292 |
+
}
|
| 1293 |
+
$xfer += $output->writeFieldBegin('success', TType::STRUCT, 0);
|
| 1294 |
+
$xfer += $this->success->write($output);
|
| 1295 |
+
$xfer += $output->writeFieldEnd();
|
| 1296 |
+
}
|
| 1297 |
+
if ($this->p13nServiceException !== null) {
|
| 1298 |
+
$xfer += $output->writeFieldBegin('p13nServiceException', TType::STRUCT, 1);
|
| 1299 |
+
$xfer += $this->p13nServiceException->write($output);
|
| 1300 |
+
$xfer += $output->writeFieldEnd();
|
| 1301 |
+
}
|
| 1302 |
+
$xfer += $output->writeFieldStop();
|
| 1303 |
+
$xfer += $output->writeStructEnd();
|
| 1304 |
+
return $xfer;
|
| 1305 |
+
}
|
| 1306 |
+
|
| 1307 |
+
}
|
| 1308 |
+
|
| 1309 |
+
|
app/code/community/Boxalino/{CemSearch/Lib/vendor → Intelligence/lib}/Thrift/Base/TBase.php
RENAMED
|
@@ -1,367 +1,367 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
/*
|
| 3 |
-
* Licensed to the Apache Software Foundation (ASF) under one
|
| 4 |
-
* or more contributor license agreements. See the NOTICE file
|
| 5 |
-
* distributed with this work for additional information
|
| 6 |
-
* regarding copyright ownership. The ASF licenses this file
|
| 7 |
-
* to you under the Apache License, Version 2.0 (the
|
| 8 |
-
* "License"); you may not use this file except in compliance
|
| 9 |
-
* with the License. You may obtain a copy of the License at
|
| 10 |
-
*
|
| 11 |
-
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
-
*
|
| 13 |
-
* Unless required by applicable law or agreed to in writing,
|
| 14 |
-
* software distributed under the License is distributed on an
|
| 15 |
-
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 16 |
-
* KIND, either express or implied. See the License for the
|
| 17 |
-
* specific language governing permissions and limitations
|
| 18 |
-
* under the License.
|
| 19 |
-
*
|
| 20 |
-
* @package thrift
|
| 21 |
-
*/
|
| 22 |
-
|
| 23 |
-
namespace Thrift\Base;
|
| 24 |
-
|
| 25 |
-
use Thrift\Type\TType;
|
| 26 |
-
|
| 27 |
-
/**
|
| 28 |
-
* Base class from which other Thrift structs extend. This is so that we can
|
| 29 |
-
* cut back on the size of the generated code which is turning out to have a
|
| 30 |
-
* nontrivial cost just to load thanks to the wondrously abysmal implementation
|
| 31 |
-
* of PHP. Note that code is intentionally duplicated in here to avoid making
|
| 32 |
-
* function calls for every field or member of a container..
|
| 33 |
-
*/
|
| 34 |
-
abstract class TBase {
|
| 35 |
-
|
| 36 |
-
static $tmethod = array(TType::BOOL => 'Bool',
|
| 37 |
-
TType::BYTE => 'Byte',
|
| 38 |
-
TType::I16 => 'I16',
|
| 39 |
-
TType::I32 => 'I32',
|
| 40 |
-
TType::I64 => 'I64',
|
| 41 |
-
TType::DOUBLE => 'Double',
|
| 42 |
-
TType::STRING => 'String');
|
| 43 |
-
|
| 44 |
-
abstract function read($input);
|
| 45 |
-
|
| 46 |
-
abstract function write($output);
|
| 47 |
-
|
| 48 |
-
public function __construct($spec=null, $vals=null) {
|
| 49 |
-
if (is_array($spec) && is_array($vals)) {
|
| 50 |
-
foreach ($spec as $fid => $fspec) {
|
| 51 |
-
$var = $fspec['var'];
|
| 52 |
-
if (isset($vals[$var])) {
|
| 53 |
-
$this->$var = $vals[$var];
|
| 54 |
-
}
|
| 55 |
-
}
|
| 56 |
-
}
|
| 57 |
-
}
|
| 58 |
-
|
| 59 |
-
public function __wakeup()
|
| 60 |
-
{
|
| 61 |
-
$this->__construct(get_object_vars($this));
|
| 62 |
-
}
|
| 63 |
-
|
| 64 |
-
private function _readMap(&$var, $spec, $input) {
|
| 65 |
-
$xfer = 0;
|
| 66 |
-
$ktype = $spec['ktype'];
|
| 67 |
-
$vtype = $spec['vtype'];
|
| 68 |
-
$kread = $vread = null;
|
| 69 |
-
if (isset(TBase::$tmethod[$ktype])) {
|
| 70 |
-
$kread = 'read'.TBase::$tmethod[$ktype];
|
| 71 |
-
} else {
|
| 72 |
-
$kspec = $spec['key'];
|
| 73 |
-
}
|
| 74 |
-
if (isset(TBase::$tmethod[$vtype])) {
|
| 75 |
-
$vread = 'read'.TBase::$tmethod[$vtype];
|
| 76 |
-
} else {
|
| 77 |
-
$vspec = $spec['val'];
|
| 78 |
-
}
|
| 79 |
-
$var = array();
|
| 80 |
-
$_ktype = $_vtype = $size = 0;
|
| 81 |
-
$xfer += $input->readMapBegin($_ktype, $_vtype, $size);
|
| 82 |
-
for ($i = 0; $i < $size; ++$i) {
|
| 83 |
-
$key = $val = null;
|
| 84 |
-
if ($kread !== null) {
|
| 85 |
-
$xfer += $input->$kread($key);
|
| 86 |
-
} else {
|
| 87 |
-
switch ($ktype) {
|
| 88 |
-
case TType::STRUCT:
|
| 89 |
-
$class = $kspec['class'];
|
| 90 |
-
$key = new $class();
|
| 91 |
-
$xfer += $key->read($input);
|
| 92 |
-
break;
|
| 93 |
-
case TType::MAP:
|
| 94 |
-
$xfer += $this->_readMap($key, $kspec, $input);
|
| 95 |
-
break;
|
| 96 |
-
case TType::LST:
|
| 97 |
-
$xfer += $this->_readList($key, $kspec, $input, false);
|
| 98 |
-
break;
|
| 99 |
-
case TType::SET:
|
| 100 |
-
$xfer += $this->_readList($key, $kspec, $input, true);
|
| 101 |
-
break;
|
| 102 |
-
}
|
| 103 |
-
}
|
| 104 |
-
if ($vread !== null) {
|
| 105 |
-
$xfer += $input->$vread($val);
|
| 106 |
-
} else {
|
| 107 |
-
switch ($vtype) {
|
| 108 |
-
case TType::STRUCT:
|
| 109 |
-
$class = $vspec['class'];
|
| 110 |
-
$val = new $class();
|
| 111 |
-
$xfer += $val->read($input);
|
| 112 |
-
break;
|
| 113 |
-
case TType::MAP:
|
| 114 |
-
$xfer += $this->_readMap($val, $vspec, $input);
|
| 115 |
-
break;
|
| 116 |
-
case TType::LST:
|
| 117 |
-
$xfer += $this->_readList($val, $vspec, $input, false);
|
| 118 |
-
break;
|
| 119 |
-
case TType::SET:
|
| 120 |
-
$xfer += $this->_readList($val, $vspec, $input, true);
|
| 121 |
-
break;
|
| 122 |
-
}
|
| 123 |
-
}
|
| 124 |
-
$var[$key] = $val;
|
| 125 |
-
}
|
| 126 |
-
$xfer += $input->readMapEnd();
|
| 127 |
-
return $xfer;
|
| 128 |
-
}
|
| 129 |
-
|
| 130 |
-
private function _readList(&$var, $spec, $input, $set=false) {
|
| 131 |
-
$xfer = 0;
|
| 132 |
-
$etype = $spec['etype'];
|
| 133 |
-
$eread = $vread = null;
|
| 134 |
-
if (isset(TBase::$tmethod[$etype])) {
|
| 135 |
-
$eread = 'read'.TBase::$tmethod[$etype];
|
| 136 |
-
} else {
|
| 137 |
-
$espec = $spec['elem'];
|
| 138 |
-
}
|
| 139 |
-
$var = array();
|
| 140 |
-
$_etype = $size = 0;
|
| 141 |
-
if ($set) {
|
| 142 |
-
$xfer += $input->readSetBegin($_etype, $size);
|
| 143 |
-
} else {
|
| 144 |
-
$xfer += $input->readListBegin($_etype, $size);
|
| 145 |
-
}
|
| 146 |
-
for ($i = 0; $i < $size; ++$i) {
|
| 147 |
-
$elem = null;
|
| 148 |
-
if ($eread !== null) {
|
| 149 |
-
$xfer += $input->$eread($elem);
|
| 150 |
-
} else {
|
| 151 |
-
$espec = $spec['elem'];
|
| 152 |
-
switch ($etype) {
|
| 153 |
-
case TType::STRUCT:
|
| 154 |
-
$class = $espec['class'];
|
| 155 |
-
$elem = new $class();
|
| 156 |
-
$xfer += $elem->read($input);
|
| 157 |
-
break;
|
| 158 |
-
case TType::MAP:
|
| 159 |
-
$xfer += $this->_readMap($elem, $espec, $input);
|
| 160 |
-
break;
|
| 161 |
-
case TType::LST:
|
| 162 |
-
$xfer += $this->_readList($elem, $espec, $input, false);
|
| 163 |
-
break;
|
| 164 |
-
case TType::SET:
|
| 165 |
-
$xfer += $this->_readList($elem, $espec, $input, true);
|
| 166 |
-
break;
|
| 167 |
-
}
|
| 168 |
-
}
|
| 169 |
-
if ($set) {
|
| 170 |
-
$var[$elem] = true;
|
| 171 |
-
} else {
|
| 172 |
-
$var []= $elem;
|
| 173 |
-
}
|
| 174 |
-
}
|
| 175 |
-
if ($set) {
|
| 176 |
-
$xfer += $input->readSetEnd();
|
| 177 |
-
} else {
|
| 178 |
-
$xfer += $input->readListEnd();
|
| 179 |
-
}
|
| 180 |
-
return $xfer;
|
| 181 |
-
}
|
| 182 |
-
|
| 183 |
-
protected function _read($class, $spec, $input) {
|
| 184 |
-
$xfer = 0;
|
| 185 |
-
$fname = null;
|
| 186 |
-
$ftype = 0;
|
| 187 |
-
$fid = 0;
|
| 188 |
-
$xfer += $input->readStructBegin($fname);
|
| 189 |
-
while (true) {
|
| 190 |
-
$xfer += $input->readFieldBegin($fname, $ftype, $fid);
|
| 191 |
-
if ($ftype == TType::STOP) {
|
| 192 |
-
break;
|
| 193 |
-
}
|
| 194 |
-
if (isset($spec[$fid])) {
|
| 195 |
-
$fspec = $spec[$fid];
|
| 196 |
-
$var = $fspec['var'];
|
| 197 |
-
if ($ftype == $fspec['type']) {
|
| 198 |
-
$xfer = 0;
|
| 199 |
-
if (isset(TBase::$tmethod[$ftype])) {
|
| 200 |
-
$func = 'read'.TBase::$tmethod[$ftype];
|
| 201 |
-
$xfer += $input->$func($this->$var);
|
| 202 |
-
} else {
|
| 203 |
-
switch ($ftype) {
|
| 204 |
-
case TType::STRUCT:
|
| 205 |
-
$class = $fspec['class'];
|
| 206 |
-
$this->$var = new $class();
|
| 207 |
-
$xfer += $this->$var->read($input);
|
| 208 |
-
break;
|
| 209 |
-
case TType::MAP:
|
| 210 |
-
$xfer += $this->_readMap($this->$var, $fspec, $input);
|
| 211 |
-
break;
|
| 212 |
-
case TType::LST:
|
| 213 |
-
$xfer += $this->_readList($this->$var, $fspec, $input, false);
|
| 214 |
-
break;
|
| 215 |
-
case TType::SET:
|
| 216 |
-
$xfer += $this->_readList($this->$var, $fspec, $input, true);
|
| 217 |
-
break;
|
| 218 |
-
}
|
| 219 |
-
}
|
| 220 |
-
} else {
|
| 221 |
-
$xfer += $input->skip($ftype);
|
| 222 |
-
}
|
| 223 |
-
} else {
|
| 224 |
-
$xfer += $input->skip($ftype);
|
| 225 |
-
}
|
| 226 |
-
$xfer += $input->readFieldEnd();
|
| 227 |
-
}
|
| 228 |
-
$xfer += $input->readStructEnd();
|
| 229 |
-
return $xfer;
|
| 230 |
-
}
|
| 231 |
-
|
| 232 |
-
private function _writeMap($var, $spec, $output) {
|
| 233 |
-
$xfer = 0;
|
| 234 |
-
$ktype = $spec['ktype'];
|
| 235 |
-
$vtype = $spec['vtype'];
|
| 236 |
-
$kwrite = $vwrite = null;
|
| 237 |
-
if (isset(TBase::$tmethod[$ktype])) {
|
| 238 |
-
$kwrite = 'write'.TBase::$tmethod[$ktype];
|
| 239 |
-
} else {
|
| 240 |
-
$kspec = $spec['key'];
|
| 241 |
-
}
|
| 242 |
-
if (isset(TBase::$tmethod[$vtype])) {
|
| 243 |
-
$vwrite = 'write'.TBase::$tmethod[$vtype];
|
| 244 |
-
} else {
|
| 245 |
-
$vspec = $spec['val'];
|
| 246 |
-
}
|
| 247 |
-
$xfer += $output->writeMapBegin($ktype, $vtype, count($var));
|
| 248 |
-
foreach ($var as $key => $val) {
|
| 249 |
-
if (isset($kwrite)) {
|
| 250 |
-
$xfer += $output->$kwrite($key);
|
| 251 |
-
} else {
|
| 252 |
-
switch ($ktype) {
|
| 253 |
-
case TType::STRUCT:
|
| 254 |
-
$xfer += $key->write($output);
|
| 255 |
-
break;
|
| 256 |
-
case TType::MAP:
|
| 257 |
-
$xfer += $this->_writeMap($key, $kspec, $output);
|
| 258 |
-
break;
|
| 259 |
-
case TType::LST:
|
| 260 |
-
$xfer += $this->_writeList($key, $kspec, $output, false);
|
| 261 |
-
break;
|
| 262 |
-
case TType::SET:
|
| 263 |
-
$xfer += $this->_writeList($key, $kspec, $output, true);
|
| 264 |
-
break;
|
| 265 |
-
}
|
| 266 |
-
}
|
| 267 |
-
if (isset($vwrite)) {
|
| 268 |
-
$xfer += $output->$vwrite($val);
|
| 269 |
-
} else {
|
| 270 |
-
switch ($vtype) {
|
| 271 |
-
case TType::STRUCT:
|
| 272 |
-
$xfer += $val->write($output);
|
| 273 |
-
break;
|
| 274 |
-
case TType::MAP:
|
| 275 |
-
$xfer += $this->_writeMap($val, $vspec, $output);
|
| 276 |
-
break;
|
| 277 |
-
case TType::LST:
|
| 278 |
-
$xfer += $this->_writeList($val, $vspec, $output, false);
|
| 279 |
-
break;
|
| 280 |
-
case TType::SET:
|
| 281 |
-
$xfer += $this->_writeList($val, $vspec, $output, true);
|
| 282 |
-
break;
|
| 283 |
-
}
|
| 284 |
-
}
|
| 285 |
-
}
|
| 286 |
-
$xfer += $output->writeMapEnd();
|
| 287 |
-
return $xfer;
|
| 288 |
-
}
|
| 289 |
-
|
| 290 |
-
private function _writeList($var, $spec, $output, $set=false) {
|
| 291 |
-
$xfer = 0;
|
| 292 |
-
$etype = $spec['etype'];
|
| 293 |
-
$ewrite = null;
|
| 294 |
-
if (isset(TBase::$tmethod[$etype])) {
|
| 295 |
-
$ewrite = 'write'.TBase::$tmethod[$etype];
|
| 296 |
-
} else {
|
| 297 |
-
$espec = $spec['elem'];
|
| 298 |
-
}
|
| 299 |
-
if ($set) {
|
| 300 |
-
$xfer += $output->writeSetBegin($etype, count($var));
|
| 301 |
-
} else {
|
| 302 |
-
$xfer += $output->writeListBegin($etype, count($var));
|
| 303 |
-
}
|
| 304 |
-
foreach ($var as $key => $val) {
|
| 305 |
-
$elem = $set ? $key : $val;
|
| 306 |
-
if (isset($ewrite)) {
|
| 307 |
-
$xfer += $output->$ewrite($elem);
|
| 308 |
-
} else {
|
| 309 |
-
switch ($etype) {
|
| 310 |
-
case TType::STRUCT:
|
| 311 |
-
$xfer += $elem->write($output);
|
| 312 |
-
break;
|
| 313 |
-
case TType::MAP:
|
| 314 |
-
$xfer += $this->_writeMap($elem, $espec, $output);
|
| 315 |
-
break;
|
| 316 |
-
case TType::LST:
|
| 317 |
-
$xfer += $this->_writeList($elem, $espec, $output, false);
|
| 318 |
-
break;
|
| 319 |
-
case TType::SET:
|
| 320 |
-
$xfer += $this->_writeList($elem, $espec, $output, true);
|
| 321 |
-
break;
|
| 322 |
-
}
|
| 323 |
-
}
|
| 324 |
-
}
|
| 325 |
-
if ($set) {
|
| 326 |
-
$xfer += $output->writeSetEnd();
|
| 327 |
-
} else {
|
| 328 |
-
$xfer += $output->writeListEnd();
|
| 329 |
-
}
|
| 330 |
-
return $xfer;
|
| 331 |
-
}
|
| 332 |
-
|
| 333 |
-
protected function _write($class, $spec, $output) {
|
| 334 |
-
$xfer = 0;
|
| 335 |
-
$xfer += $output->writeStructBegin($class);
|
| 336 |
-
foreach ($spec as $fid => $fspec) {
|
| 337 |
-
$var = $fspec['var'];
|
| 338 |
-
if ($this->$var !== null) {
|
| 339 |
-
$ftype = $fspec['type'];
|
| 340 |
-
$xfer += $output->writeFieldBegin($var, $ftype, $fid);
|
| 341 |
-
if (isset(TBase::$tmethod[$ftype])) {
|
| 342 |
-
$func = 'write'.TBase::$tmethod[$ftype];
|
| 343 |
-
$xfer += $output->$func($this->$var);
|
| 344 |
-
} else {
|
| 345 |
-
switch ($ftype) {
|
| 346 |
-
case TType::STRUCT:
|
| 347 |
-
$xfer += $this->$var->write($output);
|
| 348 |
-
break;
|
| 349 |
-
case TType::MAP:
|
| 350 |
-
$xfer += $this->_writeMap($this->$var, $fspec, $output);
|
| 351 |
-
break;
|
| 352 |
-
case TType::LST:
|
| 353 |
-
$xfer += $this->_writeList($this->$var, $fspec, $output, false);
|
| 354 |
-
break;
|
| 355 |
-
case TType::SET:
|
| 356 |
-
$xfer += $this->_writeList($this->$var, $fspec, $output, true);
|
| 357 |
-
break;
|
| 358 |
-
}
|
| 359 |
-
}
|
| 360 |
-
$xfer += $output->writeFieldEnd();
|
| 361 |
-
}
|
| 362 |
-
}
|
| 363 |
-
$xfer += $output->writeFieldStop();
|
| 364 |
-
$xfer += $output->writeStructEnd();
|
| 365 |
-
return $xfer;
|
| 366 |
-
}
|
| 367 |
-
}
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Licensed to the Apache Software Foundation (ASF) under one
|
| 4 |
+
* or more contributor license agreements. See the NOTICE file
|
| 5 |
+
* distributed with this work for additional information
|
| 6 |
+
* regarding copyright ownership. The ASF licenses this file
|
| 7 |
+
* to you under the Apache License, Version 2.0 (the
|
| 8 |
+
* "License"); you may not use this file except in compliance
|
| 9 |
+
* with the License. You may obtain a copy of the License at
|
| 10 |
+
*
|
| 11 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
+
*
|
| 13 |
+
* Unless required by applicable law or agreed to in writing,
|
| 14 |
+
* software distributed under the License is distributed on an
|
| 15 |
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 16 |
+
* KIND, either express or implied. See the License for the
|
| 17 |
+
* specific language governing permissions and limitations
|
| 18 |
+
* under the License.
|
| 19 |
+
*
|
| 20 |
+
* @package thrift
|
| 21 |
+
*/
|
| 22 |
+
|
| 23 |
+
namespace Thrift\Base;
|
| 24 |
+
|
| 25 |
+
use Thrift\Type\TType;
|
| 26 |
+
|
| 27 |
+
/**
|
| 28 |
+
* Base class from which other Thrift structs extend. This is so that we can
|
| 29 |
+
* cut back on the size of the generated code which is turning out to have a
|
| 30 |
+
* nontrivial cost just to load thanks to the wondrously abysmal implementation
|
| 31 |
+
* of PHP. Note that code is intentionally duplicated in here to avoid making
|
| 32 |
+
* function calls for every field or member of a container..
|
| 33 |
+
*/
|
| 34 |
+
abstract class TBase {
|
| 35 |
+
|
| 36 |
+
static $tmethod = array(TType::BOOL => 'Bool',
|
| 37 |
+
TType::BYTE => 'Byte',
|
| 38 |
+
TType::I16 => 'I16',
|
| 39 |
+
TType::I32 => 'I32',
|
| 40 |
+
TType::I64 => 'I64',
|
| 41 |
+
TType::DOUBLE => 'Double',
|
| 42 |
+
TType::STRING => 'String');
|
| 43 |
+
|
| 44 |
+
abstract function read($input);
|
| 45 |
+
|
| 46 |
+
abstract function write($output);
|
| 47 |
+
|
| 48 |
+
public function __construct($spec=null, $vals=null) {
|
| 49 |
+
if (is_array($spec) && is_array($vals)) {
|
| 50 |
+
foreach ($spec as $fid => $fspec) {
|
| 51 |
+
$var = $fspec['var'];
|
| 52 |
+
if (isset($vals[$var])) {
|
| 53 |
+
$this->$var = $vals[$var];
|
| 54 |
+
}
|
| 55 |
+
}
|
| 56 |
+
}
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
public function __wakeup()
|
| 60 |
+
{
|
| 61 |
+
$this->__construct(get_object_vars($this));
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
private function _readMap(&$var, $spec, $input) {
|
| 65 |
+
$xfer = 0;
|
| 66 |
+
$ktype = $spec['ktype'];
|
| 67 |
+
$vtype = $spec['vtype'];
|
| 68 |
+
$kread = $vread = null;
|
| 69 |
+
if (isset(TBase::$tmethod[$ktype])) {
|
| 70 |
+
$kread = 'read'.TBase::$tmethod[$ktype];
|
| 71 |
+
} else {
|
| 72 |
+
$kspec = $spec['key'];
|
| 73 |
+
}
|
| 74 |
+
if (isset(TBase::$tmethod[$vtype])) {
|
| 75 |
+
$vread = 'read'.TBase::$tmethod[$vtype];
|
| 76 |
+
} else {
|
| 77 |
+
$vspec = $spec['val'];
|
| 78 |
+
}
|
| 79 |
+
$var = array();
|
| 80 |
+
$_ktype = $_vtype = $size = 0;
|
| 81 |
+
$xfer += $input->readMapBegin($_ktype, $_vtype, $size);
|
| 82 |
+
for ($i = 0; $i < $size; ++$i) {
|
| 83 |
+
$key = $val = null;
|
| 84 |
+
if ($kread !== null) {
|
| 85 |
+
$xfer += $input->$kread($key);
|
| 86 |
+
} else {
|
| 87 |
+
switch ($ktype) {
|
| 88 |
+
case TType::STRUCT:
|
| 89 |
+
$class = $kspec['class'];
|
| 90 |
+
$key = new $class();
|
| 91 |
+
$xfer += $key->read($input);
|
| 92 |
+
break;
|
| 93 |
+
case TType::MAP:
|
| 94 |
+
$xfer += $this->_readMap($key, $kspec, $input);
|
| 95 |
+
break;
|
| 96 |
+
case TType::LST:
|
| 97 |
+
$xfer += $this->_readList($key, $kspec, $input, false);
|
| 98 |
+
break;
|
| 99 |
+
case TType::SET:
|
| 100 |
+
$xfer += $this->_readList($key, $kspec, $input, true);
|
| 101 |
+
break;
|
| 102 |
+
}
|
| 103 |
+
}
|
| 104 |
+
if ($vread !== null) {
|
| 105 |
+
$xfer += $input->$vread($val);
|
| 106 |
+
} else {
|
| 107 |
+
switch ($vtype) {
|
| 108 |
+
case TType::STRUCT:
|
| 109 |
+
$class = $vspec['class'];
|
| 110 |
+
$val = new $class();
|
| 111 |
+
$xfer += $val->read($input);
|
| 112 |
+
break;
|
| 113 |
+
case TType::MAP:
|
| 114 |
+
$xfer += $this->_readMap($val, $vspec, $input);
|
| 115 |
+
break;
|
| 116 |
+
case TType::LST:
|
| 117 |
+
$xfer += $this->_readList($val, $vspec, $input, false);
|
| 118 |
+
break;
|
| 119 |
+
case TType::SET:
|
| 120 |
+
$xfer += $this->_readList($val, $vspec, $input, true);
|
| 121 |
+
break;
|
| 122 |
+
}
|
| 123 |
+
}
|
| 124 |
+
$var[$key] = $val;
|
| 125 |
+
}
|
| 126 |
+
$xfer += $input->readMapEnd();
|
| 127 |
+
return $xfer;
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
private function _readList(&$var, $spec, $input, $set=false) {
|
| 131 |
+
$xfer = 0;
|
| 132 |
+
$etype = $spec['etype'];
|
| 133 |
+
$eread = $vread = null;
|
| 134 |
+
if (isset(TBase::$tmethod[$etype])) {
|
| 135 |
+
$eread = 'read'.TBase::$tmethod[$etype];
|
| 136 |
+
} else {
|
| 137 |
+
$espec = $spec['elem'];
|
| 138 |
+
}
|
| 139 |
+
$var = array();
|
| 140 |
+
$_etype = $size = 0;
|
| 141 |
+
if ($set) {
|
| 142 |
+
$xfer += $input->readSetBegin($_etype, $size);
|
| 143 |
+
} else {
|
| 144 |
+
$xfer += $input->readListBegin($_etype, $size);
|
| 145 |
+
}
|
| 146 |
+
for ($i = 0; $i < $size; ++$i) {
|
| 147 |
+
$elem = null;
|
| 148 |
+
if ($eread !== null) {
|
| 149 |
+
$xfer += $input->$eread($elem);
|
| 150 |
+
} else {
|
| 151 |
+
$espec = $spec['elem'];
|
| 152 |
+
switch ($etype) {
|
| 153 |
+
case TType::STRUCT:
|
| 154 |
+
$class = $espec['class'];
|
| 155 |
+
$elem = new $class();
|
| 156 |
+
$xfer += $elem->read($input);
|
| 157 |
+
break;
|
| 158 |
+
case TType::MAP:
|
| 159 |
+
$xfer += $this->_readMap($elem, $espec, $input);
|
| 160 |
+
break;
|
| 161 |
+
case TType::LST:
|
| 162 |
+
$xfer += $this->_readList($elem, $espec, $input, false);
|
| 163 |
+
break;
|
| 164 |
+
case TType::SET:
|
| 165 |
+
$xfer += $this->_readList($elem, $espec, $input, true);
|
| 166 |
+
break;
|
| 167 |
+
}
|
| 168 |
+
}
|
| 169 |
+
if ($set) {
|
| 170 |
+
$var[$elem] = true;
|
| 171 |
+
} else {
|
| 172 |
+
$var []= $elem;
|
| 173 |
+
}
|
| 174 |
+
}
|
| 175 |
+
if ($set) {
|
| 176 |
+
$xfer += $input->readSetEnd();
|
| 177 |
+
} else {
|
| 178 |
+
$xfer += $input->readListEnd();
|
| 179 |
+
}
|
| 180 |
+
return $xfer;
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
protected function _read($class, $spec, $input) {
|
| 184 |
+
$xfer = 0;
|
| 185 |
+
$fname = null;
|
| 186 |
+
$ftype = 0;
|
| 187 |
+
$fid = 0;
|
| 188 |
+
$xfer += $input->readStructBegin($fname);
|
| 189 |
+
while (true) {
|
| 190 |
+
$xfer += $input->readFieldBegin($fname, $ftype, $fid);
|
| 191 |
+
if ($ftype == TType::STOP) {
|
| 192 |
+
break;
|
| 193 |
+
}
|
| 194 |
+
if (isset($spec[$fid])) {
|
| 195 |
+
$fspec = $spec[$fid];
|
| 196 |
+
$var = $fspec['var'];
|
| 197 |
+
if ($ftype == $fspec['type']) {
|
| 198 |
+
$xfer = 0;
|
| 199 |
+
if (isset(TBase::$tmethod[$ftype])) {
|
| 200 |
+
$func = 'read'.TBase::$tmethod[$ftype];
|
| 201 |
+
$xfer += $input->$func($this->$var);
|
| 202 |
+
} else {
|
| 203 |
+
switch ($ftype) {
|
| 204 |
+
case TType::STRUCT:
|
| 205 |
+
$class = $fspec['class'];
|
| 206 |
+
$this->$var = new $class();
|
| 207 |
+
$xfer += $this->$var->read($input);
|
| 208 |
+
break;
|
| 209 |
+
case TType::MAP:
|
| 210 |
+
$xfer += $this->_readMap($this->$var, $fspec, $input);
|
| 211 |
+
break;
|
| 212 |
+
case TType::LST:
|
| 213 |
+
$xfer += $this->_readList($this->$var, $fspec, $input, false);
|
| 214 |
+
break;
|
| 215 |
+
case TType::SET:
|
| 216 |
+
$xfer += $this->_readList($this->$var, $fspec, $input, true);
|
| 217 |
+
break;
|
| 218 |
+
}
|
| 219 |
+
}
|
| 220 |
+
} else {
|
| 221 |
+
$xfer += $input->skip($ftype);
|
| 222 |
+
}
|
| 223 |
+
} else {
|
| 224 |
+
$xfer += $input->skip($ftype);
|
| 225 |
+
}
|
| 226 |
+
$xfer += $input->readFieldEnd();
|
| 227 |
+
}
|
| 228 |
+
$xfer += $input->readStructEnd();
|
| 229 |
+
return $xfer;
|
| 230 |
+
}
|
| 231 |
+
|
| 232 |
+
private function _writeMap($var, $spec, $output) {
|
| 233 |
+
$xfer = 0;
|
| 234 |
+
$ktype = $spec['ktype'];
|
| 235 |
+
$vtype = $spec['vtype'];
|
| 236 |
+
$kwrite = $vwrite = null;
|
| 237 |
+
if (isset(TBase::$tmethod[$ktype])) {
|
| 238 |
+
$kwrite = 'write'.TBase::$tmethod[$ktype];
|
| 239 |
+
} else {
|
| 240 |
+
$kspec = $spec['key'];
|
| 241 |
+
}
|
| 242 |
+
if (isset(TBase::$tmethod[$vtype])) {
|
| 243 |
+
$vwrite = 'write'.TBase::$tmethod[$vtype];
|
| 244 |
+
} else {
|
| 245 |
+
$vspec = $spec['val'];
|
| 246 |
+
}
|
| 247 |
+
$xfer += $output->writeMapBegin($ktype, $vtype, count($var));
|
| 248 |
+
foreach ($var as $key => $val) {
|
| 249 |
+
if (isset($kwrite)) {
|
| 250 |
+
$xfer += $output->$kwrite($key);
|
| 251 |
+
} else {
|
| 252 |
+
switch ($ktype) {
|
| 253 |
+
case TType::STRUCT:
|
| 254 |
+
$xfer += $key->write($output);
|
| 255 |
+
break;
|
| 256 |
+
case TType::MAP:
|
| 257 |
+
$xfer += $this->_writeMap($key, $kspec, $output);
|
| 258 |
+
break;
|
| 259 |
+
case TType::LST:
|
| 260 |
+
$xfer += $this->_writeList($key, $kspec, $output, false);
|
| 261 |
+
break;
|
| 262 |
+
case TType::SET:
|
| 263 |
+
$xfer += $this->_writeList($key, $kspec, $output, true);
|
| 264 |
+
break;
|
| 265 |
+
}
|
| 266 |
+
}
|
| 267 |
+
if (isset($vwrite)) {
|
| 268 |
+
$xfer += $output->$vwrite($val);
|
| 269 |
+
} else {
|
| 270 |
+
switch ($vtype) {
|
| 271 |
+
case TType::STRUCT:
|
| 272 |
+
$xfer += $val->write($output);
|
| 273 |
+
break;
|
| 274 |
+
case TType::MAP:
|
| 275 |
+
$xfer += $this->_writeMap($val, $vspec, $output);
|
| 276 |
+
break;
|
| 277 |
+
case TType::LST:
|
| 278 |
+
$xfer += $this->_writeList($val, $vspec, $output, false);
|
| 279 |
+
break;
|
| 280 |
+
case TType::SET:
|
| 281 |
+
$xfer += $this->_writeList($val, $vspec, $output, true);
|
| 282 |
+
break;
|
| 283 |
+
}
|
| 284 |
+
}
|
| 285 |
+
}
|
| 286 |
+
$xfer += $output->writeMapEnd();
|
| 287 |
+
return $xfer;
|
| 288 |
+
}
|
| 289 |
+
|
| 290 |
+
private function _writeList($var, $spec, $output, $set=false) {
|
| 291 |
+
$xfer = 0;
|
| 292 |
+
$etype = $spec['etype'];
|
| 293 |
+
$ewrite = null;
|
| 294 |
+
if (isset(TBase::$tmethod[$etype])) {
|
| 295 |
+
$ewrite = 'write'.TBase::$tmethod[$etype];
|
| 296 |
+
} else {
|
| 297 |
+
$espec = $spec['elem'];
|
| 298 |
+
}
|
| 299 |
+
if ($set) {
|
| 300 |
+
$xfer += $output->writeSetBegin($etype, count($var));
|
| 301 |
+
} else {
|
| 302 |
+
$xfer += $output->writeListBegin($etype, count($var));
|
| 303 |
+
}
|
| 304 |
+
foreach ($var as $key => $val) {
|
| 305 |
+
$elem = $set ? $key : $val;
|
| 306 |
+
if (isset($ewrite)) {
|
| 307 |
+
$xfer += $output->$ewrite($elem);
|
| 308 |
+
} else {
|
| 309 |
+
switch ($etype) {
|
| 310 |
+
case TType::STRUCT:
|
| 311 |
+
$xfer += $elem->write($output);
|
| 312 |
+
break;
|
| 313 |
+
case TType::MAP:
|
| 314 |
+
$xfer += $this->_writeMap($elem, $espec, $output);
|
| 315 |
+
break;
|
| 316 |
+
case TType::LST:
|
| 317 |
+
$xfer += $this->_writeList($elem, $espec, $output, false);
|
| 318 |
+
break;
|
| 319 |
+
case TType::SET:
|
| 320 |
+
$xfer += $this->_writeList($elem, $espec, $output, true);
|
| 321 |
+
break;
|
| 322 |
+
}
|
| 323 |
+
}
|
| 324 |
+
}
|
| 325 |
+
if ($set) {
|
| 326 |
+
$xfer += $output->writeSetEnd();
|
| 327 |
+
} else {
|
| 328 |
+
$xfer += $output->writeListEnd();
|
| 329 |
+
}
|
| 330 |
+
return $xfer;
|
| 331 |
+
}
|
| 332 |
+
|
| 333 |
+
protected function _write($class, $spec, $output) {
|
| 334 |
+
$xfer = 0;
|
| 335 |
+
$xfer += $output->writeStructBegin($class);
|
| 336 |
+
foreach ($spec as $fid => $fspec) {
|
| 337 |
+
$var = $fspec['var'];
|
| 338 |
+
if ($this->$var !== null) {
|
| 339 |
+
$ftype = $fspec['type'];
|
| 340 |
+
$xfer += $output->writeFieldBegin($var, $ftype, $fid);
|
| 341 |
+
if (isset(TBase::$tmethod[$ftype])) {
|
| 342 |
+
$func = 'write'.TBase::$tmethod[$ftype];
|
| 343 |
+
$xfer += $output->$func($this->$var);
|
| 344 |
+
} else {
|
| 345 |
+
switch ($ftype) {
|
| 346 |
+
case TType::STRUCT:
|
| 347 |
+
$xfer += $this->$var->write($output);
|
| 348 |
+
break;
|
| 349 |
+
case TType::MAP:
|
| 350 |
+
$xfer += $this->_writeMap($this->$var, $fspec, $output);
|
| 351 |
+
break;
|
| 352 |
+
case TType::LST:
|
| 353 |
+
$xfer += $this->_writeList($this->$var, $fspec, $output, false);
|
| 354 |
+
break;
|
| 355 |
+
case TType::SET:
|
| 356 |
+
$xfer += $this->_writeList($this->$var, $fspec, $output, true);
|
| 357 |
+
break;
|
| 358 |
+
}
|
| 359 |
+
}
|
| 360 |
+
$xfer += $output->writeFieldEnd();
|
| 361 |
+
}
|
| 362 |
+
}
|
| 363 |
+
$xfer += $output->writeFieldStop();
|
| 364 |
+
$xfer += $output->writeStructEnd();
|
| 365 |
+
return $xfer;
|
| 366 |
+
}
|
| 367 |
+
}
|
app/code/community/Boxalino/{CemSearch/Lib/vendor → Intelligence/lib}/Thrift/ClassLoader/ThriftClassLoader.php
RENAMED
|
@@ -1,223 +1,223 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
/*
|
| 3 |
-
* Licensed to the Apache Software Foundation (ASF) under one
|
| 4 |
-
* or more contributor license agreements. See the NOTICE file
|
| 5 |
-
* distributed with this work for additional information
|
| 6 |
-
* regarding copyright ownership. The ASF licenses this file
|
| 7 |
-
* to you under the Apache License, Version 2.0 (the
|
| 8 |
-
* "License"); you may not use this file except in compliance
|
| 9 |
-
* with the License. You may obtain a copy of the License at
|
| 10 |
-
*
|
| 11 |
-
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
-
*
|
| 13 |
-
* Unless required by applicable law or agreed to in writing,
|
| 14 |
-
* software distributed under the License is distributed on an
|
| 15 |
-
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 16 |
-
* KIND, either express or implied. See the License for the
|
| 17 |
-
* specific language governing permissions and limitations
|
| 18 |
-
* under the License.
|
| 19 |
-
*
|
| 20 |
-
* ClassLoader to load Thrift library and definitions
|
| 21 |
-
* Inspired from UniversalClassLoader from Symfony 2
|
| 22 |
-
*
|
| 23 |
-
* @package thrift.classloader
|
| 24 |
-
*/
|
| 25 |
-
|
| 26 |
-
namespace Thrift\ClassLoader;
|
| 27 |
-
|
| 28 |
-
class ThriftClassLoader
|
| 29 |
-
{
|
| 30 |
-
/**
|
| 31 |
-
* Namespaces path
|
| 32 |
-
* @var array
|
| 33 |
-
*/
|
| 34 |
-
protected $namespaces = array();
|
| 35 |
-
|
| 36 |
-
/**
|
| 37 |
-
* Thrift definition paths
|
| 38 |
-
* @var type
|
| 39 |
-
*/
|
| 40 |
-
protected $definitions = array();
|
| 41 |
-
|
| 42 |
-
/**
|
| 43 |
-
* Do we use APC cache ?
|
| 44 |
-
* @var boolean
|
| 45 |
-
*/
|
| 46 |
-
protected $apc = false;
|
| 47 |
-
|
| 48 |
-
/**
|
| 49 |
-
* APC Cache prefix
|
| 50 |
-
* @var string
|
| 51 |
-
*/
|
| 52 |
-
protected $apc_prefix;
|
| 53 |
-
|
| 54 |
-
/**
|
| 55 |
-
* Set autoloader to use APC cache
|
| 56 |
-
* @param boolean $apc
|
| 57 |
-
* @param string $apc_prefix
|
| 58 |
-
*/
|
| 59 |
-
public function __construct($apc = false, $apc_prefix = null)
|
| 60 |
-
{
|
| 61 |
-
$this->apc = $apc;
|
| 62 |
-
$this->apc_prefix = $apc_prefix;
|
| 63 |
-
}
|
| 64 |
-
|
| 65 |
-
/**
|
| 66 |
-
* Registers a namespace.
|
| 67 |
-
*
|
| 68 |
-
* @param string $namespace The namespace
|
| 69 |
-
* @param array|string $paths The location(s) of the namespace
|
| 70 |
-
*/
|
| 71 |
-
public function registerNamespace($namespace, $paths)
|
| 72 |
-
{
|
| 73 |
-
$this->namespaces[$namespace] = (array) $paths;
|
| 74 |
-
}
|
| 75 |
-
|
| 76 |
-
/**
|
| 77 |
-
* Registers a Thrift definition namespace.
|
| 78 |
-
*
|
| 79 |
-
* @param string $namespace The definition namespace
|
| 80 |
-
* @param array|string $paths The location(s) of the definition namespace
|
| 81 |
-
*/
|
| 82 |
-
public function registerDefinition($namespace, $paths)
|
| 83 |
-
{
|
| 84 |
-
$this->definitions[$namespace] = (array) $paths;
|
| 85 |
-
}
|
| 86 |
-
|
| 87 |
-
/**
|
| 88 |
-
* Registers this instance as an autoloader.
|
| 89 |
-
*
|
| 90 |
-
* @param Boolean $prepend Whether to prepend the autoloader or not
|
| 91 |
-
*/
|
| 92 |
-
public function register($prepend = false)
|
| 93 |
-
{
|
| 94 |
-
spl_autoload_register(array($this, 'loadClass'), true, $prepend);
|
| 95 |
-
}
|
| 96 |
-
|
| 97 |
-
/**
|
| 98 |
-
* Loads the given class, definition or interface.
|
| 99 |
-
*
|
| 100 |
-
* @param string $class The name of the class
|
| 101 |
-
*/
|
| 102 |
-
public function loadClass($class)
|
| 103 |
-
{
|
| 104 |
-
if (
|
| 105 |
-
(true === $this->apc && ($file = $this->findFileInApc($class))) or
|
| 106 |
-
($file = $this->findFile($class))
|
| 107 |
-
)
|
| 108 |
-
{
|
| 109 |
-
require_once $file;
|
| 110 |
-
}
|
| 111 |
-
}
|
| 112 |
-
|
| 113 |
-
/**
|
| 114 |
-
* Loads the given class or interface in APC.
|
| 115 |
-
* @param string $class The name of the class
|
| 116 |
-
* @return string
|
| 117 |
-
*/
|
| 118 |
-
protected function findFileInApc($class)
|
| 119 |
-
{
|
| 120 |
-
if (false === $file = apc_fetch($this->apc_prefix.$class)) {
|
| 121 |
-
apc_store($this->apc_prefix.$class, $file = $this->findFile($class));
|
| 122 |
-
}
|
| 123 |
-
|
| 124 |
-
return $file;
|
| 125 |
-
}
|
| 126 |
-
|
| 127 |
-
/**
|
| 128 |
-
* Find class in namespaces or definitions directories
|
| 129 |
-
* @param string $class
|
| 130 |
-
* @return string
|
| 131 |
-
*/
|
| 132 |
-
public function findFile($class)
|
| 133 |
-
{
|
| 134 |
-
// Remove first backslash
|
| 135 |
-
if ('\\' == $class[0])
|
| 136 |
-
{
|
| 137 |
-
$class = substr($class, 1);
|
| 138 |
-
}
|
| 139 |
-
|
| 140 |
-
if (false !== $pos = strrpos($class, '\\'))
|
| 141 |
-
{
|
| 142 |
-
// Namespaced class name
|
| 143 |
-
$namespace = substr($class, 0, $pos);
|
| 144 |
-
|
| 145 |
-
// Iterate in normal namespaces
|
| 146 |
-
foreach ($this->namespaces as $ns => $dirs)
|
| 147 |
-
{
|
| 148 |
-
//Don't interfere with other autoloaders
|
| 149 |
-
if (0 !== strpos($namespace, $ns))
|
| 150 |
-
{
|
| 151 |
-
continue;
|
| 152 |
-
}
|
| 153 |
-
|
| 154 |
-
foreach ($dirs as $dir)
|
| 155 |
-
{
|
| 156 |
-
$className = substr($class, $pos + 1);
|
| 157 |
-
|
| 158 |
-
$file = $dir.DIRECTORY_SEPARATOR.
|
| 159 |
-
str_replace('\\', DIRECTORY_SEPARATOR, $namespace).
|
| 160 |
-
DIRECTORY_SEPARATOR.
|
| 161 |
-
$className.'.php';
|
| 162 |
-
|
| 163 |
-
if (file_exists($file))
|
| 164 |
-
{
|
| 165 |
-
return $file;
|
| 166 |
-
}
|
| 167 |
-
}
|
| 168 |
-
}
|
| 169 |
-
|
| 170 |
-
// Iterate in Thrift namespaces
|
| 171 |
-
|
| 172 |
-
// Remove first part of namespace
|
| 173 |
-
$m = explode('\\', $class);
|
| 174 |
-
|
| 175 |
-
// Ignore wrong call
|
| 176 |
-
if(count($m) <= 1)
|
| 177 |
-
{
|
| 178 |
-
return;
|
| 179 |
-
}
|
| 180 |
-
|
| 181 |
-
$class = array_pop($m);
|
| 182 |
-
$namespace = implode('\\', $m);
|
| 183 |
-
|
| 184 |
-
foreach ($this->definitions as $ns => $dirs)
|
| 185 |
-
{
|
| 186 |
-
//Don't interfere with other autoloaders
|
| 187 |
-
if (0 !== strpos($namespace, $ns))
|
| 188 |
-
{
|
| 189 |
-
continue;
|
| 190 |
-
}
|
| 191 |
-
|
| 192 |
-
foreach ($dirs as $dir)
|
| 193 |
-
{
|
| 194 |
-
/**
|
| 195 |
-
* Available in service: Interface, Client, Processor, Rest
|
| 196 |
-
* And every service methods (_.+)
|
| 197 |
-
*/
|
| 198 |
-
if(
|
| 199 |
-
0 === preg_match('#(.+)(if|client|processor|rest)$#i', $class, $n) and
|
| 200 |
-
0 === preg_match('#(.+)_[a-z0-9]+_(args|result)$#i', $class, $n)
|
| 201 |
-
)
|
| 202 |
-
{
|
| 203 |
-
$className = 'Types';
|
| 204 |
-
}
|
| 205 |
-
else
|
| 206 |
-
{
|
| 207 |
-
$className = $n[1];
|
| 208 |
-
}
|
| 209 |
-
|
| 210 |
-
$file = $dir.DIRECTORY_SEPARATOR .
|
| 211 |
-
str_replace('\\', DIRECTORY_SEPARATOR, $namespace) .
|
| 212 |
-
DIRECTORY_SEPARATOR .
|
| 213 |
-
$className . '.php';
|
| 214 |
-
|
| 215 |
-
if (file_exists($file))
|
| 216 |
-
{
|
| 217 |
-
return $file;
|
| 218 |
-
}
|
| 219 |
-
}
|
| 220 |
-
}
|
| 221 |
-
}
|
| 222 |
-
}
|
| 223 |
-
}
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Licensed to the Apache Software Foundation (ASF) under one
|
| 4 |
+
* or more contributor license agreements. See the NOTICE file
|
| 5 |
+
* distributed with this work for additional information
|
| 6 |
+
* regarding copyright ownership. The ASF licenses this file
|
| 7 |
+
* to you under the Apache License, Version 2.0 (the
|
| 8 |
+
* "License"); you may not use this file except in compliance
|
| 9 |
+
* with the License. You may obtain a copy of the License at
|
| 10 |
+
*
|
| 11 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
+
*
|
| 13 |
+
* Unless required by applicable law or agreed to in writing,
|
| 14 |
+
* software distributed under the License is distributed on an
|
| 15 |
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 16 |
+
* KIND, either express or implied. See the License for the
|
| 17 |
+
* specific language governing permissions and limitations
|
| 18 |
+
* under the License.
|
| 19 |
+
*
|
| 20 |
+
* ClassLoader to load Thrift library and definitions
|
| 21 |
+
* Inspired from UniversalClassLoader from Symfony 2
|
| 22 |
+
*
|
| 23 |
+
* @package thrift.classloader
|
| 24 |
+
*/
|
| 25 |
+
|
| 26 |
+
namespace Thrift\ClassLoader;
|
| 27 |
+
|
| 28 |
+
class ThriftClassLoader
|
| 29 |
+
{
|
| 30 |
+
/**
|
| 31 |
+
* Namespaces path
|
| 32 |
+
* @var array
|
| 33 |
+
*/
|
| 34 |
+
protected $namespaces = array();
|
| 35 |
+
|
| 36 |
+
/**
|
| 37 |
+
* Thrift definition paths
|
| 38 |
+
* @var type
|
| 39 |
+
*/
|
| 40 |
+
protected $definitions = array();
|
| 41 |
+
|
| 42 |
+
/**
|
| 43 |
+
* Do we use APC cache ?
|
| 44 |
+
* @var boolean
|
| 45 |
+
*/
|
| 46 |
+
protected $apc = false;
|
| 47 |
+
|
| 48 |
+
/**
|
| 49 |
+
* APC Cache prefix
|
| 50 |
+
* @var string
|
| 51 |
+
*/
|
| 52 |
+
protected $apc_prefix;
|
| 53 |
+
|
| 54 |
+
/**
|
| 55 |
+
* Set autoloader to use APC cache
|
| 56 |
+
* @param boolean $apc
|
| 57 |
+
* @param string $apc_prefix
|
| 58 |
+
*/
|
| 59 |
+
public function __construct($apc = false, $apc_prefix = null)
|
| 60 |
+
{
|
| 61 |
+
$this->apc = $apc;
|
| 62 |
+
$this->apc_prefix = $apc_prefix;
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
/**
|
| 66 |
+
* Registers a namespace.
|
| 67 |
+
*
|
| 68 |
+
* @param string $namespace The namespace
|
| 69 |
+
* @param array|string $paths The location(s) of the namespace
|
| 70 |
+
*/
|
| 71 |
+
public function registerNamespace($namespace, $paths)
|
| 72 |
+
{
|
| 73 |
+
$this->namespaces[$namespace] = (array) $paths;
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
/**
|
| 77 |
+
* Registers a Thrift definition namespace.
|
| 78 |
+
*
|
| 79 |
+
* @param string $namespace The definition namespace
|
| 80 |
+
* @param array|string $paths The location(s) of the definition namespace
|
| 81 |
+
*/
|
| 82 |
+
public function registerDefinition($namespace, $paths)
|
| 83 |
+
{
|
| 84 |
+
$this->definitions[$namespace] = (array) $paths;
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
/**
|
| 88 |
+
* Registers this instance as an autoloader.
|
| 89 |
+
*
|
| 90 |
+
* @param Boolean $prepend Whether to prepend the autoloader or not
|
| 91 |
+
*/
|
| 92 |
+
public function register($prepend = false)
|
| 93 |
+
{
|
| 94 |
+
spl_autoload_register(array($this, 'loadClass'), true, $prepend);
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
/**
|
| 98 |
+
* Loads the given class, definition or interface.
|
| 99 |
+
*
|
| 100 |
+
* @param string $class The name of the class
|
| 101 |
+
*/
|
| 102 |
+
public function loadClass($class)
|
| 103 |
+
{
|
| 104 |
+
if (
|
| 105 |
+
(true === $this->apc && ($file = $this->findFileInApc($class))) or
|
| 106 |
+
($file = $this->findFile($class))
|
| 107 |
+
)
|
| 108 |
+
{
|
| 109 |
+
require_once $file;
|
| 110 |
+
}
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
/**
|
| 114 |
+
* Loads the given class or interface in APC.
|
| 115 |
+
* @param string $class The name of the class
|
| 116 |
+
* @return string
|
| 117 |
+
*/
|
| 118 |
+
protected function findFileInApc($class)
|
| 119 |
+
{
|
| 120 |
+
if (false === $file = apc_fetch($this->apc_prefix.$class)) {
|
| 121 |
+
apc_store($this->apc_prefix.$class, $file = $this->findFile($class));
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
return $file;
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
/**
|
| 128 |
+
* Find class in namespaces or definitions directories
|
| 129 |
+
* @param string $class
|
| 130 |
+
* @return string
|
| 131 |
+
*/
|
| 132 |
+
public function findFile($class)
|
| 133 |
+
{
|
| 134 |
+
// Remove first backslash
|
| 135 |
+
if ('\\' == $class[0])
|
| 136 |
+
{
|
| 137 |
+
$class = substr($class, 1);
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
if (false !== $pos = strrpos($class, '\\'))
|
| 141 |
+
{
|
| 142 |
+
// Namespaced class name
|
| 143 |
+
$namespace = substr($class, 0, $pos);
|
| 144 |
+
|
| 145 |
+
// Iterate in normal namespaces
|
| 146 |
+
foreach ($this->namespaces as $ns => $dirs)
|
| 147 |
+
{
|
| 148 |
+
//Don't interfere with other autoloaders
|
| 149 |
+
if (0 !== strpos($namespace, $ns))
|
| 150 |
+
{
|
| 151 |
+
continue;
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
foreach ($dirs as $dir)
|
| 155 |
+
{
|
| 156 |
+
$className = substr($class, $pos + 1);
|
| 157 |
+
|
| 158 |
+
$file = $dir.DIRECTORY_SEPARATOR.
|
| 159 |
+
str_replace('\\', DIRECTORY_SEPARATOR, $namespace).
|
| 160 |
+
DIRECTORY_SEPARATOR.
|
| 161 |
+
$className.'.php';
|
| 162 |
+
|
| 163 |
+
if (file_exists($file))
|
| 164 |
+
{
|
| 165 |
+
return $file;
|
| 166 |
+
}
|
| 167 |
+
}
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
// Iterate in Thrift namespaces
|
| 171 |
+
|
| 172 |
+
// Remove first part of namespace
|
| 173 |
+
$m = explode('\\', $class);
|
| 174 |
+
|
| 175 |
+
// Ignore wrong call
|
| 176 |
+
if(count($m) <= 1)
|
| 177 |
+
{
|
| 178 |
+
return;
|
| 179 |
+
}
|
| 180 |
+
|
| 181 |
+
$class = array_pop($m);
|
| 182 |
+
$namespace = implode('\\', $m);
|
| 183 |
+
|
| 184 |
+
foreach ($this->definitions as $ns => $dirs)
|
| 185 |
+
{
|
| 186 |
+
//Don't interfere with other autoloaders
|
| 187 |
+
if (0 !== strpos($namespace, $ns))
|
| 188 |
+
{
|
| 189 |
+
continue;
|
| 190 |
+
}
|
| 191 |
+
|
| 192 |
+
foreach ($dirs as $dir)
|
| 193 |
+
{
|
| 194 |
+
/**
|
| 195 |
+
* Available in service: Interface, Client, Processor, Rest
|
| 196 |
+
* And every service methods (_.+)
|
| 197 |
+
*/
|
| 198 |
+
if(
|
| 199 |
+
0 === preg_match('#(.+)(if|client|processor|rest)$#i', $class, $n) and
|
| 200 |
+
0 === preg_match('#(.+)_[a-z0-9]+_(args|result)$#i', $class, $n)
|
| 201 |
+
)
|
| 202 |
+
{
|
| 203 |
+
$className = 'Types';
|
| 204 |
+
}
|
| 205 |
+
else
|
| 206 |
+
{
|
| 207 |
+
$className = $n[1];
|
| 208 |
+
}
|
| 209 |
+
|
| 210 |
+
$file = $dir.DIRECTORY_SEPARATOR .
|
| 211 |
+
str_replace('\\', DIRECTORY_SEPARATOR, $namespace) .
|
| 212 |
+
DIRECTORY_SEPARATOR .
|
| 213 |
+
$className . '.php';
|
| 214 |
+
|
| 215 |
+
if (file_exists($file))
|
| 216 |
+
{
|
| 217 |
+
return $file;
|
| 218 |
+
}
|
| 219 |
+
}
|
| 220 |
+
}
|
| 221 |
+
}
|
| 222 |
+
}
|
| 223 |
+
}
|
app/code/community/Boxalino/{CemSearch/Lib/vendor → Intelligence/lib}/Thrift/Exception/TApplicationException.php
RENAMED
|
@@ -1,72 +1,72 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
/*
|
| 3 |
-
* Licensed to the Apache Software Foundation (ASF) under one
|
| 4 |
-
* or more contributor license agreements. See the NOTICE file
|
| 5 |
-
* distributed with this work for additional information
|
| 6 |
-
* regarding copyright ownership. The ASF licenses this file
|
| 7 |
-
* to you under the Apache License, Version 2.0 (the
|
| 8 |
-
* "License"); you may not use this file except in compliance
|
| 9 |
-
* with the License. You may obtain a copy of the License at
|
| 10 |
-
*
|
| 11 |
-
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
-
*
|
| 13 |
-
* Unless required by applicable law or agreed to in writing,
|
| 14 |
-
* software distributed under the License is distributed on an
|
| 15 |
-
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 16 |
-
* KIND, either express or implied. See the License for the
|
| 17 |
-
* specific language governing permissions and limitations
|
| 18 |
-
* under the License.
|
| 19 |
-
*
|
| 20 |
-
* @package thrift
|
| 21 |
-
*/
|
| 22 |
-
|
| 23 |
-
namespace Thrift\Exception;
|
| 24 |
-
|
| 25 |
-
use Thrift\Exception\TException;
|
| 26 |
-
use Thrift\Type\TType;
|
| 27 |
-
|
| 28 |
-
class TApplicationException extends TException {
|
| 29 |
-
static $_TSPEC =
|
| 30 |
-
array(1 => array('var' => 'message',
|
| 31 |
-
'type' => TType::STRING),
|
| 32 |
-
2 => array('var' => 'code',
|
| 33 |
-
'type' => TType::I32));
|
| 34 |
-
|
| 35 |
-
const UNKNOWN = 0;
|
| 36 |
-
const UNKNOWN_METHOD = 1;
|
| 37 |
-
const INVALID_MESSAGE_TYPE = 2;
|
| 38 |
-
const WRONG_METHOD_NAME = 3;
|
| 39 |
-
const BAD_SEQUENCE_ID = 4;
|
| 40 |
-
const MISSING_RESULT = 5;
|
| 41 |
-
const INTERNAL_ERROR = 6;
|
| 42 |
-
const PROTOCOL_ERROR = 7;
|
| 43 |
-
const INVALID_TRANSFORM = 8;
|
| 44 |
-
const INVALID_PROTOCOL = 9;
|
| 45 |
-
const UNSUPPORTED_CLIENT_TYPE = 10;
|
| 46 |
-
|
| 47 |
-
function __construct($message=null, $code=0) {
|
| 48 |
-
parent::__construct($message, $code);
|
| 49 |
-
}
|
| 50 |
-
|
| 51 |
-
public function read($output) {
|
| 52 |
-
return $this->_read('TApplicationException', self::$_TSPEC, $output);
|
| 53 |
-
}
|
| 54 |
-
|
| 55 |
-
public function write($output) {
|
| 56 |
-
$xfer = 0;
|
| 57 |
-
$xfer += $output->writeStructBegin('TApplicationException');
|
| 58 |
-
if ($message = $this->getMessage()) {
|
| 59 |
-
$xfer += $output->writeFieldBegin('message', TType::STRING, 1);
|
| 60 |
-
$xfer += $output->writeString($message);
|
| 61 |
-
$xfer += $output->writeFieldEnd();
|
| 62 |
-
}
|
| 63 |
-
if ($code = $this->getCode()) {
|
| 64 |
-
$xfer += $output->writeFieldBegin('type', TType::I32, 2);
|
| 65 |
-
$xfer += $output->writeI32($code);
|
| 66 |
-
$xfer += $output->writeFieldEnd();
|
| 67 |
-
}
|
| 68 |
-
$xfer += $output->writeFieldStop();
|
| 69 |
-
$xfer += $output->writeStructEnd();
|
| 70 |
-
return $xfer;
|
| 71 |
-
}
|
| 72 |
-
}
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Licensed to the Apache Software Foundation (ASF) under one
|
| 4 |
+
* or more contributor license agreements. See the NOTICE file
|
| 5 |
+
* distributed with this work for additional information
|
| 6 |
+
* regarding copyright ownership. The ASF licenses this file
|
| 7 |
+
* to you under the Apache License, Version 2.0 (the
|
| 8 |
+
* "License"); you may not use this file except in compliance
|
| 9 |
+
* with the License. You may obtain a copy of the License at
|
| 10 |
+
*
|
| 11 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
+
*
|
| 13 |
+
* Unless required by applicable law or agreed to in writing,
|
| 14 |
+
* software distributed under the License is distributed on an
|
| 15 |
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 16 |
+
* KIND, either express or implied. See the License for the
|
| 17 |
+
* specific language governing permissions and limitations
|
| 18 |
+
* under the License.
|
| 19 |
+
*
|
| 20 |
+
* @package thrift
|
| 21 |
+
*/
|
| 22 |
+
|
| 23 |
+
namespace Thrift\Exception;
|
| 24 |
+
|
| 25 |
+
use Thrift\Exception\TException;
|
| 26 |
+
use Thrift\Type\TType;
|
| 27 |
+
|
| 28 |
+
class TApplicationException extends TException {
|
| 29 |
+
static $_TSPEC =
|
| 30 |
+
array(1 => array('var' => 'message',
|
| 31 |
+
'type' => TType::STRING),
|
| 32 |
+
2 => array('var' => 'code',
|
| 33 |
+
'type' => TType::I32));
|
| 34 |
+
|
| 35 |
+
const UNKNOWN = 0;
|
| 36 |
+
const UNKNOWN_METHOD = 1;
|
| 37 |
+
const INVALID_MESSAGE_TYPE = 2;
|
| 38 |
+
const WRONG_METHOD_NAME = 3;
|
| 39 |
+
const BAD_SEQUENCE_ID = 4;
|
| 40 |
+
const MISSING_RESULT = 5;
|
| 41 |
+
const INTERNAL_ERROR = 6;
|
| 42 |
+
const PROTOCOL_ERROR = 7;
|
| 43 |
+
const INVALID_TRANSFORM = 8;
|
| 44 |
+
const INVALID_PROTOCOL = 9;
|
| 45 |
+
const UNSUPPORTED_CLIENT_TYPE = 10;
|
| 46 |
+
|
| 47 |
+
function __construct($message=null, $code=0) {
|
| 48 |
+
parent::__construct($message, $code);
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
public function read($output) {
|
| 52 |
+
return $this->_read('TApplicationException', self::$_TSPEC, $output);
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
public function write($output) {
|
| 56 |
+
$xfer = 0;
|
| 57 |
+
$xfer += $output->writeStructBegin('TApplicationException');
|
| 58 |
+
if ($message = $this->getMessage()) {
|
| 59 |
+
$xfer += $output->writeFieldBegin('message', TType::STRING, 1);
|
| 60 |
+
$xfer += $output->writeString($message);
|
| 61 |
+
$xfer += $output->writeFieldEnd();
|
| 62 |
+
}
|
| 63 |
+
if ($code = $this->getCode()) {
|
| 64 |
+
$xfer += $output->writeFieldBegin('type', TType::I32, 2);
|
| 65 |
+
$xfer += $output->writeI32($code);
|
| 66 |
+
$xfer += $output->writeFieldEnd();
|
| 67 |
+
}
|
| 68 |
+
$xfer += $output->writeFieldStop();
|
| 69 |
+
$xfer += $output->writeStructEnd();
|
| 70 |
+
return $xfer;
|
| 71 |
+
}
|
| 72 |
+
}
|
app/code/community/Boxalino/{CemSearch/Lib/vendor → Intelligence/lib}/Thrift/Exception/TException.php
RENAMED
|
@@ -1,369 +1,369 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
/*
|
| 3 |
-
* Licensed to the Apache Software Foundation (ASF) under one
|
| 4 |
-
* or more contributor license agreements. See the NOTICE file
|
| 5 |
-
* distributed with this work for additional information
|
| 6 |
-
* regarding copyright ownership. The ASF licenses this file
|
| 7 |
-
* to you under the Apache License, Version 2.0 (the
|
| 8 |
-
* "License"); you may not use this file except in compliance
|
| 9 |
-
* with the License. You may obtain a copy of the License at
|
| 10 |
-
*
|
| 11 |
-
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
-
*
|
| 13 |
-
* Unless required by applicable law or agreed to in writing,
|
| 14 |
-
* software distributed under the License is distributed on an
|
| 15 |
-
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 16 |
-
* KIND, either express or implied. See the License for the
|
| 17 |
-
* specific language governing permissions and limitations
|
| 18 |
-
* under the License.
|
| 19 |
-
*
|
| 20 |
-
* @package thrift
|
| 21 |
-
*/
|
| 22 |
-
|
| 23 |
-
namespace Thrift\Exception;
|
| 24 |
-
|
| 25 |
-
use Thrift\Type\TType;
|
| 26 |
-
use Thrift\Base\TBase;
|
| 27 |
-
|
| 28 |
-
/**
|
| 29 |
-
* NOTE(mcslee): This currently contains a ton of duplicated code from TBase
|
| 30 |
-
* because we need to save CPU cycles and this is not yet in an extension.
|
| 31 |
-
* Ideally we'd multiply-inherit TException from both Exception and Base, but
|
| 32 |
-
* that's not possible in PHP and there are no modules either, so for now we
|
| 33 |
-
* apologetically take a trip to HackTown.
|
| 34 |
-
*
|
| 35 |
-
* Can be called with standard Exception constructor (message, code) or with
|
| 36 |
-
* Thrift Base object constructor (spec, vals).
|
| 37 |
-
*
|
| 38 |
-
* @param mixed $p1 Message (string) or type-spec (array)
|
| 39 |
-
* @param mixed $p2 Code (integer) or values (array)
|
| 40 |
-
*/
|
| 41 |
-
class TException extends \Exception {
|
| 42 |
-
function __construct($p1=null, $p2=0) {
|
| 43 |
-
if (is_array($p1) && is_array($p2)) {
|
| 44 |
-
$spec = $p1;
|
| 45 |
-
$vals = $p2;
|
| 46 |
-
foreach ($spec as $fid => $fspec) {
|
| 47 |
-
$var = $fspec['var'];
|
| 48 |
-
if (isset($vals[$var])) {
|
| 49 |
-
$this->$var = $vals[$var];
|
| 50 |
-
}
|
| 51 |
-
}
|
| 52 |
-
} else {
|
| 53 |
-
parent::__construct($p1, $p2);
|
| 54 |
-
}
|
| 55 |
-
}
|
| 56 |
-
|
| 57 |
-
static $tmethod = array(TType::BOOL => 'Bool',
|
| 58 |
-
TType::BYTE => 'Byte',
|
| 59 |
-
TType::I16 => 'I16',
|
| 60 |
-
TType::I32 => 'I32',
|
| 61 |
-
TType::I64 => 'I64',
|
| 62 |
-
TType::DOUBLE => 'Double',
|
| 63 |
-
TType::STRING => 'String');
|
| 64 |
-
|
| 65 |
-
private function _readMap(&$var, $spec, $input) {
|
| 66 |
-
$xfer = 0;
|
| 67 |
-
$ktype = $spec['ktype'];
|
| 68 |
-
$vtype = $spec['vtype'];
|
| 69 |
-
$kread = $vread = null;
|
| 70 |
-
if (isset(TBase::$tmethod[$ktype])) {
|
| 71 |
-
$kread = 'read'.TBase::$tmethod[$ktype];
|
| 72 |
-
} else {
|
| 73 |
-
$kspec = $spec['key'];
|
| 74 |
-
}
|
| 75 |
-
if (isset(TBase::$tmethod[$vtype])) {
|
| 76 |
-
$vread = 'read'.TBase::$tmethod[$vtype];
|
| 77 |
-
} else {
|
| 78 |
-
$vspec = $spec['val'];
|
| 79 |
-
}
|
| 80 |
-
$var = array();
|
| 81 |
-
$_ktype = $_vtype = $size = 0;
|
| 82 |
-
$xfer += $input->readMapBegin($_ktype, $_vtype, $size);
|
| 83 |
-
for ($i = 0; $i < $size; ++$i) {
|
| 84 |
-
$key = $val = null;
|
| 85 |
-
if ($kread !== null) {
|
| 86 |
-
$xfer += $input->$kread($key);
|
| 87 |
-
} else {
|
| 88 |
-
switch ($ktype) {
|
| 89 |
-
case TType::STRUCT:
|
| 90 |
-
$class = $kspec['class'];
|
| 91 |
-
$key = new $class();
|
| 92 |
-
$xfer += $key->read($input);
|
| 93 |
-
break;
|
| 94 |
-
case TType::MAP:
|
| 95 |
-
$xfer += $this->_readMap($key, $kspec, $input);
|
| 96 |
-
break;
|
| 97 |
-
case TType::LST:
|
| 98 |
-
$xfer += $this->_readList($key, $kspec, $input, false);
|
| 99 |
-
break;
|
| 100 |
-
case TType::SET:
|
| 101 |
-
$xfer += $this->_readList($key, $kspec, $input, true);
|
| 102 |
-
break;
|
| 103 |
-
}
|
| 104 |
-
}
|
| 105 |
-
if ($vread !== null) {
|
| 106 |
-
$xfer += $input->$vread($val);
|
| 107 |
-
} else {
|
| 108 |
-
switch ($vtype) {
|
| 109 |
-
case TType::STRUCT:
|
| 110 |
-
$class = $vspec['class'];
|
| 111 |
-
$val = new $class();
|
| 112 |
-
$xfer += $val->read($input);
|
| 113 |
-
break;
|
| 114 |
-
case TType::MAP:
|
| 115 |
-
$xfer += $this->_readMap($val, $vspec, $input);
|
| 116 |
-
break;
|
| 117 |
-
case TType::LST:
|
| 118 |
-
$xfer += $this->_readList($val, $vspec, $input, false);
|
| 119 |
-
break;
|
| 120 |
-
case TType::SET:
|
| 121 |
-
$xfer += $this->_readList($val, $vspec, $input, true);
|
| 122 |
-
break;
|
| 123 |
-
}
|
| 124 |
-
}
|
| 125 |
-
$var[$key] = $val;
|
| 126 |
-
}
|
| 127 |
-
$xfer += $input->readMapEnd();
|
| 128 |
-
return $xfer;
|
| 129 |
-
}
|
| 130 |
-
|
| 131 |
-
private function _readList(&$var, $spec, $input, $set=false) {
|
| 132 |
-
$xfer = 0;
|
| 133 |
-
$etype = $spec['etype'];
|
| 134 |
-
$eread = $vread = null;
|
| 135 |
-
if (isset(TBase::$tmethod[$etype])) {
|
| 136 |
-
$eread = 'read'.TBase::$tmethod[$etype];
|
| 137 |
-
} else {
|
| 138 |
-
$espec = $spec['elem'];
|
| 139 |
-
}
|
| 140 |
-
$var = array();
|
| 141 |
-
$_etype = $size = 0;
|
| 142 |
-
if ($set) {
|
| 143 |
-
$xfer += $input->readSetBegin($_etype, $size);
|
| 144 |
-
} else {
|
| 145 |
-
$xfer += $input->readListBegin($_etype, $size);
|
| 146 |
-
}
|
| 147 |
-
for ($i = 0; $i < $size; ++$i) {
|
| 148 |
-
$elem = null;
|
| 149 |
-
if ($eread !== null) {
|
| 150 |
-
$xfer += $input->$eread($elem);
|
| 151 |
-
} else {
|
| 152 |
-
$espec = $spec['elem'];
|
| 153 |
-
switch ($etype) {
|
| 154 |
-
case TType::STRUCT:
|
| 155 |
-
$class = $espec['class'];
|
| 156 |
-
$elem = new $class();
|
| 157 |
-
$xfer += $elem->read($input);
|
| 158 |
-
break;
|
| 159 |
-
case TType::MAP:
|
| 160 |
-
$xfer += $this->_readMap($elem, $espec, $input);
|
| 161 |
-
break;
|
| 162 |
-
case TType::LST:
|
| 163 |
-
$xfer += $this->_readList($elem, $espec, $input, false);
|
| 164 |
-
break;
|
| 165 |
-
case TType::SET:
|
| 166 |
-
$xfer += $this->_readList($elem, $espec, $input, true);
|
| 167 |
-
break;
|
| 168 |
-
}
|
| 169 |
-
}
|
| 170 |
-
if ($set) {
|
| 171 |
-
$var[$elem] = true;
|
| 172 |
-
} else {
|
| 173 |
-
$var []= $elem;
|
| 174 |
-
}
|
| 175 |
-
}
|
| 176 |
-
if ($set) {
|
| 177 |
-
$xfer += $input->readSetEnd();
|
| 178 |
-
} else {
|
| 179 |
-
$xfer += $input->readListEnd();
|
| 180 |
-
}
|
| 181 |
-
return $xfer;
|
| 182 |
-
}
|
| 183 |
-
|
| 184 |
-
protected function _read($class, $spec, $input) {
|
| 185 |
-
$xfer = 0;
|
| 186 |
-
$fname = null;
|
| 187 |
-
$ftype = 0;
|
| 188 |
-
$fid = 0;
|
| 189 |
-
$xfer += $input->readStructBegin($fname);
|
| 190 |
-
while (true) {
|
| 191 |
-
$xfer += $input->readFieldBegin($fname, $ftype, $fid);
|
| 192 |
-
if ($ftype == TType::STOP) {
|
| 193 |
-
break;
|
| 194 |
-
}
|
| 195 |
-
if (isset($spec[$fid])) {
|
| 196 |
-
$fspec = $spec[$fid];
|
| 197 |
-
$var = $fspec['var'];
|
| 198 |
-
if ($ftype == $fspec['type']) {
|
| 199 |
-
$xfer = 0;
|
| 200 |
-
if (isset(TBase::$tmethod[$ftype])) {
|
| 201 |
-
$func = 'read'.TBase::$tmethod[$ftype];
|
| 202 |
-
$xfer += $input->$func($this->$var);
|
| 203 |
-
} else {
|
| 204 |
-
switch ($ftype) {
|
| 205 |
-
case TType::STRUCT:
|
| 206 |
-
$class = $fspec['class'];
|
| 207 |
-
$this->$var = new $class();
|
| 208 |
-
$xfer += $this->$var->read($input);
|
| 209 |
-
break;
|
| 210 |
-
case TType::MAP:
|
| 211 |
-
$xfer += $this->_readMap($this->$var, $fspec, $input);
|
| 212 |
-
break;
|
| 213 |
-
case TType::LST:
|
| 214 |
-
$xfer += $this->_readList($this->$var, $fspec, $input, false);
|
| 215 |
-
break;
|
| 216 |
-
case TType::SET:
|
| 217 |
-
$xfer += $this->_readList($this->$var, $fspec, $input, true);
|
| 218 |
-
break;
|
| 219 |
-
}
|
| 220 |
-
}
|
| 221 |
-
} else {
|
| 222 |
-
$xfer += $input->skip($ftype);
|
| 223 |
-
}
|
| 224 |
-
} else {
|
| 225 |
-
$xfer += $input->skip($ftype);
|
| 226 |
-
}
|
| 227 |
-
$xfer += $input->readFieldEnd();
|
| 228 |
-
}
|
| 229 |
-
$xfer += $input->readStructEnd();
|
| 230 |
-
return $xfer;
|
| 231 |
-
}
|
| 232 |
-
|
| 233 |
-
private function _writeMap($var, $spec, $output) {
|
| 234 |
-
$xfer = 0;
|
| 235 |
-
$ktype = $spec['ktype'];
|
| 236 |
-
$vtype = $spec['vtype'];
|
| 237 |
-
$kwrite = $vwrite = null;
|
| 238 |
-
if (isset(TBase::$tmethod[$ktype])) {
|
| 239 |
-
$kwrite = 'write'.TBase::$tmethod[$ktype];
|
| 240 |
-
} else {
|
| 241 |
-
$kspec = $spec['key'];
|
| 242 |
-
}
|
| 243 |
-
if (isset(TBase::$tmethod[$vtype])) {
|
| 244 |
-
$vwrite = 'write'.TBase::$tmethod[$vtype];
|
| 245 |
-
} else {
|
| 246 |
-
$vspec = $spec['val'];
|
| 247 |
-
}
|
| 248 |
-
$xfer += $output->writeMapBegin($ktype, $vtype, count($var));
|
| 249 |
-
foreach ($var as $key => $val) {
|
| 250 |
-
if (isset($kwrite)) {
|
| 251 |
-
$xfer += $output->$kwrite($key);
|
| 252 |
-
} else {
|
| 253 |
-
switch ($ktype) {
|
| 254 |
-
case TType::STRUCT:
|
| 255 |
-
$xfer += $key->write($output);
|
| 256 |
-
break;
|
| 257 |
-
case TType::MAP:
|
| 258 |
-
$xfer += $this->_writeMap($key, $kspec, $output);
|
| 259 |
-
break;
|
| 260 |
-
case TType::LST:
|
| 261 |
-
$xfer += $this->_writeList($key, $kspec, $output, false);
|
| 262 |
-
break;
|
| 263 |
-
case TType::SET:
|
| 264 |
-
$xfer += $this->_writeList($key, $kspec, $output, true);
|
| 265 |
-
break;
|
| 266 |
-
}
|
| 267 |
-
}
|
| 268 |
-
if (isset($vwrite)) {
|
| 269 |
-
$xfer += $output->$vwrite($val);
|
| 270 |
-
} else {
|
| 271 |
-
switch ($vtype) {
|
| 272 |
-
case TType::STRUCT:
|
| 273 |
-
$xfer += $val->write($output);
|
| 274 |
-
break;
|
| 275 |
-
case TType::MAP:
|
| 276 |
-
$xfer += $this->_writeMap($val, $vspec, $output);
|
| 277 |
-
break;
|
| 278 |
-
case TType::LST:
|
| 279 |
-
$xfer += $this->_writeList($val, $vspec, $output, false);
|
| 280 |
-
break;
|
| 281 |
-
case TType::SET:
|
| 282 |
-
$xfer += $this->_writeList($val, $vspec, $output, true);
|
| 283 |
-
break;
|
| 284 |
-
}
|
| 285 |
-
}
|
| 286 |
-
}
|
| 287 |
-
$xfer += $output->writeMapEnd();
|
| 288 |
-
return $xfer;
|
| 289 |
-
}
|
| 290 |
-
|
| 291 |
-
private function _writeList($var, $spec, $output, $set=false) {
|
| 292 |
-
$xfer = 0;
|
| 293 |
-
$etype = $spec['etype'];
|
| 294 |
-
$ewrite = null;
|
| 295 |
-
if (isset(TBase::$tmethod[$etype])) {
|
| 296 |
-
$ewrite = 'write'.TBase::$tmethod[$etype];
|
| 297 |
-
} else {
|
| 298 |
-
$espec = $spec['elem'];
|
| 299 |
-
}
|
| 300 |
-
if ($set) {
|
| 301 |
-
$xfer += $output->writeSetBegin($etype, count($var));
|
| 302 |
-
} else {
|
| 303 |
-
$xfer += $output->writeListBegin($etype, count($var));
|
| 304 |
-
}
|
| 305 |
-
foreach ($var as $key => $val) {
|
| 306 |
-
$elem = $set ? $key : $val;
|
| 307 |
-
if (isset($ewrite)) {
|
| 308 |
-
$xfer += $output->$ewrite($elem);
|
| 309 |
-
} else {
|
| 310 |
-
switch ($etype) {
|
| 311 |
-
case TType::STRUCT:
|
| 312 |
-
$xfer += $elem->write($output);
|
| 313 |
-
break;
|
| 314 |
-
case TType::MAP:
|
| 315 |
-
$xfer += $this->_writeMap($elem, $espec, $output);
|
| 316 |
-
break;
|
| 317 |
-
case TType::LST:
|
| 318 |
-
$xfer += $this->_writeList($elem, $espec, $output, false);
|
| 319 |
-
break;
|
| 320 |
-
case TType::SET:
|
| 321 |
-
$xfer += $this->_writeList($elem, $espec, $output, true);
|
| 322 |
-
break;
|
| 323 |
-
}
|
| 324 |
-
}
|
| 325 |
-
}
|
| 326 |
-
if ($set) {
|
| 327 |
-
$xfer += $output->writeSetEnd();
|
| 328 |
-
} else {
|
| 329 |
-
$xfer += $output->writeListEnd();
|
| 330 |
-
}
|
| 331 |
-
return $xfer;
|
| 332 |
-
}
|
| 333 |
-
|
| 334 |
-
protected function _write($class, $spec, $output) {
|
| 335 |
-
$xfer = 0;
|
| 336 |
-
$xfer += $output->writeStructBegin($class);
|
| 337 |
-
foreach ($spec as $fid => $fspec) {
|
| 338 |
-
$var = $fspec['var'];
|
| 339 |
-
if ($this->$var !== null) {
|
| 340 |
-
$ftype = $fspec['type'];
|
| 341 |
-
$xfer += $output->writeFieldBegin($var, $ftype, $fid);
|
| 342 |
-
if (isset(TBase::$tmethod[$ftype])) {
|
| 343 |
-
$func = 'write'.TBase::$tmethod[$ftype];
|
| 344 |
-
$xfer += $output->$func($this->$var);
|
| 345 |
-
} else {
|
| 346 |
-
switch ($ftype) {
|
| 347 |
-
case TType::STRUCT:
|
| 348 |
-
$xfer += $this->$var->write($output);
|
| 349 |
-
break;
|
| 350 |
-
case TType::MAP:
|
| 351 |
-
$xfer += $this->_writeMap($this->$var, $fspec, $output);
|
| 352 |
-
break;
|
| 353 |
-
case TType::LST:
|
| 354 |
-
$xfer += $this->_writeList($this->$var, $fspec, $output, false);
|
| 355 |
-
break;
|
| 356 |
-
case TType::SET:
|
| 357 |
-
$xfer += $this->_writeList($this->$var, $fspec, $output, true);
|
| 358 |
-
break;
|
| 359 |
-
}
|
| 360 |
-
}
|
| 361 |
-
$xfer += $output->writeFieldEnd();
|
| 362 |
-
}
|
| 363 |
-
}
|
| 364 |
-
$xfer += $output->writeFieldStop();
|
| 365 |
-
$xfer += $output->writeStructEnd();
|
| 366 |
-
return $xfer;
|
| 367 |
-
}
|
| 368 |
-
|
| 369 |
-
}
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Licensed to the Apache Software Foundation (ASF) under one
|
| 4 |
+
* or more contributor license agreements. See the NOTICE file
|
| 5 |
+
* distributed with this work for additional information
|
| 6 |
+
* regarding copyright ownership. The ASF licenses this file
|
| 7 |
+
* to you under the Apache License, Version 2.0 (the
|
| 8 |
+
* "License"); you may not use this file except in compliance
|
| 9 |
+
* with the License. You may obtain a copy of the License at
|
| 10 |
+
*
|
| 11 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
+
*
|
| 13 |
+
* Unless required by applicable law or agreed to in writing,
|
| 14 |
+
* software distributed under the License is distributed on an
|
| 15 |
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 16 |
+
* KIND, either express or implied. See the License for the
|
| 17 |
+
* specific language governing permissions and limitations
|
| 18 |
+
* under the License.
|
| 19 |
+
*
|
| 20 |
+
* @package thrift
|
| 21 |
+
*/
|
| 22 |
+
|
| 23 |
+
namespace Thrift\Exception;
|
| 24 |
+
|
| 25 |
+
use Thrift\Type\TType;
|
| 26 |
+
use Thrift\Base\TBase;
|
| 27 |
+
|
| 28 |
+
/**
|
| 29 |
+
* NOTE(mcslee): This currently contains a ton of duplicated code from TBase
|
| 30 |
+
* because we need to save CPU cycles and this is not yet in an extension.
|
| 31 |
+
* Ideally we'd multiply-inherit TException from both Exception and Base, but
|
| 32 |
+
* that's not possible in PHP and there are no modules either, so for now we
|
| 33 |
+
* apologetically take a trip to HackTown.
|
| 34 |
+
*
|
| 35 |
+
* Can be called with standard Exception constructor (message, code) or with
|
| 36 |
+
* Thrift Base object constructor (spec, vals).
|
| 37 |
+
*
|
| 38 |
+
* @param mixed $p1 Message (string) or type-spec (array)
|
| 39 |
+
* @param mixed $p2 Code (integer) or values (array)
|
| 40 |
+
*/
|
| 41 |
+
class TException extends \Exception {
|
| 42 |
+
function __construct($p1=null, $p2=0) {
|
| 43 |
+
if (is_array($p1) && is_array($p2)) {
|
| 44 |
+
$spec = $p1;
|
| 45 |
+
$vals = $p2;
|
| 46 |
+
foreach ($spec as $fid => $fspec) {
|
| 47 |
+
$var = $fspec['var'];
|
| 48 |
+
if (isset($vals[$var])) {
|
| 49 |
+
$this->$var = $vals[$var];
|
| 50 |
+
}
|
| 51 |
+
}
|
| 52 |
+
} else {
|
| 53 |
+
parent::__construct($p1, $p2);
|
| 54 |
+
}
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
static $tmethod = array(TType::BOOL => 'Bool',
|
| 58 |
+
TType::BYTE => 'Byte',
|
| 59 |
+
TType::I16 => 'I16',
|
| 60 |
+
TType::I32 => 'I32',
|
| 61 |
+
TType::I64 => 'I64',
|
| 62 |
+
TType::DOUBLE => 'Double',
|
| 63 |
+
TType::STRING => 'String');
|
| 64 |
+
|
| 65 |
+
private function _readMap(&$var, $spec, $input) {
|
| 66 |
+
$xfer = 0;
|
| 67 |
+
$ktype = $spec['ktype'];
|
| 68 |
+
$vtype = $spec['vtype'];
|
| 69 |
+
$kread = $vread = null;
|
| 70 |
+
if (isset(TBase::$tmethod[$ktype])) {
|
| 71 |
+
$kread = 'read'.TBase::$tmethod[$ktype];
|
| 72 |
+
} else {
|
| 73 |
+
$kspec = $spec['key'];
|
| 74 |
+
}
|
| 75 |
+
if (isset(TBase::$tmethod[$vtype])) {
|
| 76 |
+
$vread = 'read'.TBase::$tmethod[$vtype];
|
| 77 |
+
} else {
|
| 78 |
+
$vspec = $spec['val'];
|
| 79 |
+
}
|
| 80 |
+
$var = array();
|
| 81 |
+
$_ktype = $_vtype = $size = 0;
|
| 82 |
+
$xfer += $input->readMapBegin($_ktype, $_vtype, $size);
|
| 83 |
+
for ($i = 0; $i < $size; ++$i) {
|
| 84 |
+
$key = $val = null;
|
| 85 |
+
if ($kread !== null) {
|
| 86 |
+
$xfer += $input->$kread($key);
|
| 87 |
+
} else {
|
| 88 |
+
switch ($ktype) {
|
| 89 |
+
case TType::STRUCT:
|
| 90 |
+
$class = $kspec['class'];
|
| 91 |
+
$key = new $class();
|
| 92 |
+
$xfer += $key->read($input);
|
| 93 |
+
break;
|
| 94 |
+
case TType::MAP:
|
| 95 |
+
$xfer += $this->_readMap($key, $kspec, $input);
|
| 96 |
+
break;
|
| 97 |
+
case TType::LST:
|
| 98 |
+
$xfer += $this->_readList($key, $kspec, $input, false);
|
| 99 |
+
break;
|
| 100 |
+
case TType::SET:
|
| 101 |
+
$xfer += $this->_readList($key, $kspec, $input, true);
|
| 102 |
+
break;
|
| 103 |
+
}
|
| 104 |
+
}
|
| 105 |
+
if ($vread !== null) {
|
| 106 |
+
$xfer += $input->$vread($val);
|
| 107 |
+
} else {
|
| 108 |
+
switch ($vtype) {
|
| 109 |
+
case TType::STRUCT:
|
| 110 |
+
$class = $vspec['class'];
|
| 111 |
+
$val = new $class();
|
| 112 |
+
$xfer += $val->read($input);
|
| 113 |
+
break;
|
| 114 |
+
case TType::MAP:
|
| 115 |
+
$xfer += $this->_readMap($val, $vspec, $input);
|
| 116 |
+
break;
|
| 117 |
+
case TType::LST:
|
| 118 |
+
$xfer += $this->_readList($val, $vspec, $input, false);
|
| 119 |
+
break;
|
| 120 |
+
case TType::SET:
|
| 121 |
+
$xfer += $this->_readList($val, $vspec, $input, true);
|
| 122 |
+
break;
|
| 123 |
+
}
|
| 124 |
+
}
|
| 125 |
+
$var[$key] = $val;
|
| 126 |
+
}
|
| 127 |
+
$xfer += $input->readMapEnd();
|
| 128 |
+
return $xfer;
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
private function _readList(&$var, $spec, $input, $set=false) {
|
| 132 |
+
$xfer = 0;
|
| 133 |
+
$etype = $spec['etype'];
|
| 134 |
+
$eread = $vread = null;
|
| 135 |
+
if (isset(TBase::$tmethod[$etype])) {
|
| 136 |
+
$eread = 'read'.TBase::$tmethod[$etype];
|
| 137 |
+
} else {
|
| 138 |
+
$espec = $spec['elem'];
|
| 139 |
+
}
|
| 140 |
+
$var = array();
|
| 141 |
+
$_etype = $size = 0;
|
| 142 |
+
if ($set) {
|
| 143 |
+
$xfer += $input->readSetBegin($_etype, $size);
|
| 144 |
+
} else {
|
| 145 |
+
$xfer += $input->readListBegin($_etype, $size);
|
| 146 |
+
}
|
| 147 |
+
for ($i = 0; $i < $size; ++$i) {
|
| 148 |
+
$elem = null;
|
| 149 |
+
if ($eread !== null) {
|
| 150 |
+
$xfer += $input->$eread($elem);
|
| 151 |
+
} else {
|
| 152 |
+
$espec = $spec['elem'];
|
| 153 |
+
switch ($etype) {
|
| 154 |
+
case TType::STRUCT:
|
| 155 |
+
$class = $espec['class'];
|
| 156 |
+
$elem = new $class();
|
| 157 |
+
$xfer += $elem->read($input);
|
| 158 |
+
break;
|
| 159 |
+
case TType::MAP:
|
| 160 |
+
$xfer += $this->_readMap($elem, $espec, $input);
|
| 161 |
+
break;
|
| 162 |
+
case TType::LST:
|
| 163 |
+
$xfer += $this->_readList($elem, $espec, $input, false);
|
| 164 |
+
break;
|
| 165 |
+
case TType::SET:
|
| 166 |
+
$xfer += $this->_readList($elem, $espec, $input, true);
|
| 167 |
+
break;
|
| 168 |
+
}
|
| 169 |
+
}
|
| 170 |
+
if ($set) {
|
| 171 |
+
$var[$elem] = true;
|
| 172 |
+
} else {
|
| 173 |
+
$var []= $elem;
|
| 174 |
+
}
|
| 175 |
+
}
|
| 176 |
+
if ($set) {
|
| 177 |
+
$xfer += $input->readSetEnd();
|
| 178 |
+
} else {
|
| 179 |
+
$xfer += $input->readListEnd();
|
| 180 |
+
}
|
| 181 |
+
return $xfer;
|
| 182 |
+
}
|
| 183 |
+
|
| 184 |
+
protected function _read($class, $spec, $input) {
|
| 185 |
+
$xfer = 0;
|
| 186 |
+
$fname = null;
|
| 187 |
+
$ftype = 0;
|
| 188 |
+
$fid = 0;
|
| 189 |
+
$xfer += $input->readStructBegin($fname);
|
| 190 |
+
while (true) {
|
| 191 |
+
$xfer += $input->readFieldBegin($fname, $ftype, $fid);
|
| 192 |
+
if ($ftype == TType::STOP) {
|
| 193 |
+
break;
|
| 194 |
+
}
|
| 195 |
+
if (isset($spec[$fid])) {
|
| 196 |
+
$fspec = $spec[$fid];
|
| 197 |
+
$var = $fspec['var'];
|
| 198 |
+
if ($ftype == $fspec['type']) {
|
| 199 |
+
$xfer = 0;
|
| 200 |
+
if (isset(TBase::$tmethod[$ftype])) {
|
| 201 |
+
$func = 'read'.TBase::$tmethod[$ftype];
|
| 202 |
+
$xfer += $input->$func($this->$var);
|
| 203 |
+
} else {
|
| 204 |
+
switch ($ftype) {
|
| 205 |
+
case TType::STRUCT:
|
| 206 |
+
$class = $fspec['class'];
|
| 207 |
+
$this->$var = new $class();
|
| 208 |
+
$xfer += $this->$var->read($input);
|
| 209 |
+
break;
|
| 210 |
+
case TType::MAP:
|
| 211 |
+
$xfer += $this->_readMap($this->$var, $fspec, $input);
|
| 212 |
+
break;
|
| 213 |
+
case TType::LST:
|
| 214 |
+
$xfer += $this->_readList($this->$var, $fspec, $input, false);
|
| 215 |
+
break;
|
| 216 |
+
case TType::SET:
|
| 217 |
+
$xfer += $this->_readList($this->$var, $fspec, $input, true);
|
| 218 |
+
break;
|
| 219 |
+
}
|
| 220 |
+
}
|
| 221 |
+
} else {
|
| 222 |
+
$xfer += $input->skip($ftype);
|
| 223 |
+
}
|
| 224 |
+
} else {
|
| 225 |
+
$xfer += $input->skip($ftype);
|
| 226 |
+
}
|
| 227 |
+
$xfer += $input->readFieldEnd();
|
| 228 |
+
}
|
| 229 |
+
$xfer += $input->readStructEnd();
|
| 230 |
+
return $xfer;
|
| 231 |
+
}
|
| 232 |
+
|
| 233 |
+
private function _writeMap($var, $spec, $output) {
|
| 234 |
+
$xfer = 0;
|
| 235 |
+
$ktype = $spec['ktype'];
|
| 236 |
+
$vtype = $spec['vtype'];
|
| 237 |
+
$kwrite = $vwrite = null;
|
| 238 |
+
if (isset(TBase::$tmethod[$ktype])) {
|
| 239 |
+
$kwrite = 'write'.TBase::$tmethod[$ktype];
|
| 240 |
+
} else {
|
| 241 |
+
$kspec = $spec['key'];
|
| 242 |
+
}
|
| 243 |
+
if (isset(TBase::$tmethod[$vtype])) {
|
| 244 |
+
$vwrite = 'write'.TBase::$tmethod[$vtype];
|
| 245 |
+
} else {
|
| 246 |
+
$vspec = $spec['val'];
|
| 247 |
+
}
|
| 248 |
+
$xfer += $output->writeMapBegin($ktype, $vtype, count($var));
|
| 249 |
+
foreach ($var as $key => $val) {
|
| 250 |
+
if (isset($kwrite)) {
|
| 251 |
+
$xfer += $output->$kwrite($key);
|
| 252 |
+
} else {
|
| 253 |
+
switch ($ktype) {
|
| 254 |
+
case TType::STRUCT:
|
| 255 |
+
$xfer += $key->write($output);
|
| 256 |
+
break;
|
| 257 |
+
case TType::MAP:
|
| 258 |
+
$xfer += $this->_writeMap($key, $kspec, $output);
|
| 259 |
+
break;
|
| 260 |
+
case TType::LST:
|
| 261 |
+
$xfer += $this->_writeList($key, $kspec, $output, false);
|
| 262 |
+
break;
|
| 263 |
+
case TType::SET:
|
| 264 |
+
$xfer += $this->_writeList($key, $kspec, $output, true);
|
| 265 |
+
break;
|
| 266 |
+
}
|
| 267 |
+
}
|
| 268 |
+
if (isset($vwrite)) {
|
| 269 |
+
$xfer += $output->$vwrite($val);
|
| 270 |
+
} else {
|
| 271 |
+
switch ($vtype) {
|
| 272 |
+
case TType::STRUCT:
|
| 273 |
+
$xfer += $val->write($output);
|
| 274 |
+
break;
|
| 275 |
+
case TType::MAP:
|
| 276 |
+
$xfer += $this->_writeMap($val, $vspec, $output);
|
| 277 |
+
break;
|
| 278 |
+
case TType::LST:
|
| 279 |
+
$xfer += $this->_writeList($val, $vspec, $output, false);
|
| 280 |
+
break;
|
| 281 |
+
case TType::SET:
|
| 282 |
+
$xfer += $this->_writeList($val, $vspec, $output, true);
|
| 283 |
+
break;
|
| 284 |
+
}
|
| 285 |
+
}
|
| 286 |
+
}
|
| 287 |
+
$xfer += $output->writeMapEnd();
|
| 288 |
+
return $xfer;
|
| 289 |
+
}
|
| 290 |
+
|
| 291 |
+
private function _writeList($var, $spec, $output, $set=false) {
|
| 292 |
+
$xfer = 0;
|
| 293 |
+
$etype = $spec['etype'];
|
| 294 |
+
$ewrite = null;
|
| 295 |
+
if (isset(TBase::$tmethod[$etype])) {
|
| 296 |
+
$ewrite = 'write'.TBase::$tmethod[$etype];
|
| 297 |
+
} else {
|
| 298 |
+
$espec = $spec['elem'];
|
| 299 |
+
}
|
| 300 |
+
if ($set) {
|
| 301 |
+
$xfer += $output->writeSetBegin($etype, count($var));
|
| 302 |
+
} else {
|
| 303 |
+
$xfer += $output->writeListBegin($etype, count($var));
|
| 304 |
+
}
|
| 305 |
+
foreach ($var as $key => $val) {
|
| 306 |
+
$elem = $set ? $key : $val;
|
| 307 |
+
if (isset($ewrite)) {
|
| 308 |
+
$xfer += $output->$ewrite($elem);
|
| 309 |
+
} else {
|
| 310 |
+
switch ($etype) {
|
| 311 |
+
case TType::STRUCT:
|
| 312 |
+
$xfer += $elem->write($output);
|
| 313 |
+
break;
|
| 314 |
+
case TType::MAP:
|
| 315 |
+
$xfer += $this->_writeMap($elem, $espec, $output);
|
| 316 |
+
break;
|
| 317 |
+
case TType::LST:
|
| 318 |
+
$xfer += $this->_writeList($elem, $espec, $output, false);
|
| 319 |
+
break;
|
| 320 |
+
case TType::SET:
|
| 321 |
+
$xfer += $this->_writeList($elem, $espec, $output, true);
|
| 322 |
+
break;
|
| 323 |
+
}
|
| 324 |
+
}
|
| 325 |
+
}
|
| 326 |
+
if ($set) {
|
| 327 |
+
$xfer += $output->writeSetEnd();
|
| 328 |
+
} else {
|
| 329 |
+
$xfer += $output->writeListEnd();
|
| 330 |
+
}
|
| 331 |
+
return $xfer;
|
| 332 |
+
}
|
| 333 |
+
|
| 334 |
+
protected function _write($class, $spec, $output) {
|
| 335 |
+
$xfer = 0;
|
| 336 |
+
$xfer += $output->writeStructBegin($class);
|
| 337 |
+
foreach ($spec as $fid => $fspec) {
|
| 338 |
+
$var = $fspec['var'];
|
| 339 |
+
if ($this->$var !== null) {
|
| 340 |
+
$ftype = $fspec['type'];
|
| 341 |
+
$xfer += $output->writeFieldBegin($var, $ftype, $fid);
|
| 342 |
+
if (isset(TBase::$tmethod[$ftype])) {
|
| 343 |
+
$func = 'write'.TBase::$tmethod[$ftype];
|
| 344 |
+
$xfer += $output->$func($this->$var);
|
| 345 |
+
} else {
|
| 346 |
+
switch ($ftype) {
|
| 347 |
+
case TType::STRUCT:
|
| 348 |
+
$xfer += $this->$var->write($output);
|
| 349 |
+
break;
|
| 350 |
+
case TType::MAP:
|
| 351 |
+
$xfer += $this->_writeMap($this->$var, $fspec, $output);
|
| 352 |
+
break;
|
| 353 |
+
case TType::LST:
|
| 354 |
+
$xfer += $this->_writeList($this->$var, $fspec, $output, false);
|
| 355 |
+
break;
|
| 356 |
+
case TType::SET:
|
| 357 |
+
$xfer += $this->_writeList($this->$var, $fspec, $output, true);
|
| 358 |
+
break;
|
| 359 |
+
}
|
| 360 |
+
}
|
| 361 |
+
$xfer += $output->writeFieldEnd();
|
| 362 |
+
}
|
| 363 |
+
}
|
| 364 |
+
$xfer += $output->writeFieldStop();
|
| 365 |
+
$xfer += $output->writeStructEnd();
|
| 366 |
+
return $xfer;
|
| 367 |
+
}
|
| 368 |
+
|
| 369 |
+
}
|
app/code/community/Boxalino/{CemSearch/Lib/vendor → Intelligence/lib}/Thrift/Exception/TProtocolException.php
RENAMED
|
@@ -1,48 +1,48 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
/*
|
| 3 |
-
* Licensed to the Apache Software Foundation (ASF) under one
|
| 4 |
-
* or more contributor license agreements. See the NOTICE file
|
| 5 |
-
* distributed with this work for additional information
|
| 6 |
-
* regarding copyright ownership. The ASF licenses this file
|
| 7 |
-
* to you under the Apache License, Version 2.0 (the
|
| 8 |
-
* "License"); you may not use this file except in compliance
|
| 9 |
-
* with the License. You may obtain a copy of the License at
|
| 10 |
-
*
|
| 11 |
-
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
-
*
|
| 13 |
-
* Unless required by applicable law or agreed to in writing,
|
| 14 |
-
* software distributed under the License is distributed on an
|
| 15 |
-
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 16 |
-
* KIND, either express or implied. See the License for the
|
| 17 |
-
* specific language governing permissions and limitations
|
| 18 |
-
* under the License.
|
| 19 |
-
*
|
| 20 |
-
* @package thrift.protocol
|
| 21 |
-
* @author: rmarin (marin.radu@facebook.com)
|
| 22 |
-
*/
|
| 23 |
-
|
| 24 |
-
namespace Thrift\Exception;
|
| 25 |
-
|
| 26 |
-
use Thrift\Exception\TException;
|
| 27 |
-
|
| 28 |
-
/**
|
| 29 |
-
* Protocol module. Contains all the types and definitions needed to implement
|
| 30 |
-
* a protocol encoder/decoder.
|
| 31 |
-
*
|
| 32 |
-
* @package thrift.protocol
|
| 33 |
-
*/
|
| 34 |
-
|
| 35 |
-
/**
|
| 36 |
-
* Protocol exceptions
|
| 37 |
-
*/
|
| 38 |
-
class TProtocolException extends TException {
|
| 39 |
-
const UNKNOWN = 0;
|
| 40 |
-
const INVALID_DATA = 1;
|
| 41 |
-
const NEGATIVE_SIZE = 2;
|
| 42 |
-
const SIZE_LIMIT = 3;
|
| 43 |
-
const BAD_VERSION = 4;
|
| 44 |
-
|
| 45 |
-
function __construct($message=null, $code=0) {
|
| 46 |
-
parent::__construct($message, $code);
|
| 47 |
-
}
|
| 48 |
-
}
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Licensed to the Apache Software Foundation (ASF) under one
|
| 4 |
+
* or more contributor license agreements. See the NOTICE file
|
| 5 |
+
* distributed with this work for additional information
|
| 6 |
+
* regarding copyright ownership. The ASF licenses this file
|
| 7 |
+
* to you under the Apache License, Version 2.0 (the
|
| 8 |
+
* "License"); you may not use this file except in compliance
|
| 9 |
+
* with the License. You may obtain a copy of the License at
|
| 10 |
+
*
|
| 11 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
+
*
|
| 13 |
+
* Unless required by applicable law or agreed to in writing,
|
| 14 |
+
* software distributed under the License is distributed on an
|
| 15 |
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 16 |
+
* KIND, either express or implied. See the License for the
|
| 17 |
+
* specific language governing permissions and limitations
|
| 18 |
+
* under the License.
|
| 19 |
+
*
|
| 20 |
+
* @package thrift.protocol
|
| 21 |
+
* @author: rmarin (marin.radu@facebook.com)
|
| 22 |
+
*/
|
| 23 |
+
|
| 24 |
+
namespace Thrift\Exception;
|
| 25 |
+
|
| 26 |
+
use Thrift\Exception\TException;
|
| 27 |
+
|
| 28 |
+
/**
|
| 29 |
+
* Protocol module. Contains all the types and definitions needed to implement
|
| 30 |
+
* a protocol encoder/decoder.
|
| 31 |
+
*
|
| 32 |
+
* @package thrift.protocol
|
| 33 |
+
*/
|
| 34 |
+
|
| 35 |
+
/**
|
| 36 |
+
* Protocol exceptions
|
| 37 |
+
*/
|
| 38 |
+
class TProtocolException extends TException {
|
| 39 |
+
const UNKNOWN = 0;
|
| 40 |
+
const INVALID_DATA = 1;
|
| 41 |
+
const NEGATIVE_SIZE = 2;
|
| 42 |
+
const SIZE_LIMIT = 3;
|
| 43 |
+
const BAD_VERSION = 4;
|
| 44 |
+
|
| 45 |
+
function __construct($message=null, $code=0) {
|
| 46 |
+
parent::__construct($message, $code);
|
| 47 |
+
}
|
| 48 |
+
}
|
app/code/community/Boxalino/{CemSearch/Lib/vendor → Intelligence/lib}/Thrift/Exception/TTransportException.php
RENAMED
|
@@ -1,41 +1,41 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
/*
|
| 3 |
-
* Licensed to the Apache Software Foundation (ASF) under one
|
| 4 |
-
* or more contributor license agreements. See the NOTICE file
|
| 5 |
-
* distributed with this work for additional information
|
| 6 |
-
* regarding copyright ownership. The ASF licenses this file
|
| 7 |
-
* to you under the Apache License, Version 2.0 (the
|
| 8 |
-
* "License"); you may not use this file except in compliance
|
| 9 |
-
* with the License. You may obtain a copy of the License at
|
| 10 |
-
*
|
| 11 |
-
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
-
*
|
| 13 |
-
* Unless required by applicable law or agreed to in writing,
|
| 14 |
-
* software distributed under the License is distributed on an
|
| 15 |
-
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 16 |
-
* KIND, either express or implied. See the License for the
|
| 17 |
-
* specific language governing permissions and limitations
|
| 18 |
-
* under the License.
|
| 19 |
-
*
|
| 20 |
-
* @package thrift.transport
|
| 21 |
-
*/
|
| 22 |
-
|
| 23 |
-
namespace Thrift\Exception;
|
| 24 |
-
|
| 25 |
-
use Thrift\Exception\TException;
|
| 26 |
-
|
| 27 |
-
/**
|
| 28 |
-
* Transport exceptions
|
| 29 |
-
*/
|
| 30 |
-
class TTransportException extends TException {
|
| 31 |
-
|
| 32 |
-
const UNKNOWN = 0;
|
| 33 |
-
const NOT_OPEN = 1;
|
| 34 |
-
const ALREADY_OPEN = 2;
|
| 35 |
-
const TIMED_OUT = 3;
|
| 36 |
-
const END_OF_FILE = 4;
|
| 37 |
-
|
| 38 |
-
function __construct($message=null, $code=0) {
|
| 39 |
-
parent::__construct($message, $code);
|
| 40 |
-
}
|
| 41 |
}
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Licensed to the Apache Software Foundation (ASF) under one
|
| 4 |
+
* or more contributor license agreements. See the NOTICE file
|
| 5 |
+
* distributed with this work for additional information
|
| 6 |
+
* regarding copyright ownership. The ASF licenses this file
|
| 7 |
+
* to you under the Apache License, Version 2.0 (the
|
| 8 |
+
* "License"); you may not use this file except in compliance
|
| 9 |
+
* with the License. You may obtain a copy of the License at
|
| 10 |
+
*
|
| 11 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
+
*
|
| 13 |
+
* Unless required by applicable law or agreed to in writing,
|
| 14 |
+
* software distributed under the License is distributed on an
|
| 15 |
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 16 |
+
* KIND, either express or implied. See the License for the
|
| 17 |
+
* specific language governing permissions and limitations
|
| 18 |
+
* under the License.
|
| 19 |
+
*
|
| 20 |
+
* @package thrift.transport
|
| 21 |
+
*/
|
| 22 |
+
|
| 23 |
+
namespace Thrift\Exception;
|
| 24 |
+
|
| 25 |
+
use Thrift\Exception\TException;
|
| 26 |
+
|
| 27 |
+
/**
|
| 28 |
+
* Transport exceptions
|
| 29 |
+
*/
|
| 30 |
+
class TTransportException extends TException {
|
| 31 |
+
|
| 32 |
+
const UNKNOWN = 0;
|
| 33 |
+
const NOT_OPEN = 1;
|
| 34 |
+
const ALREADY_OPEN = 2;
|
| 35 |
+
const TIMED_OUT = 3;
|
| 36 |
+
const END_OF_FILE = 4;
|
| 37 |
+
|
| 38 |
+
function __construct($message=null, $code=0) {
|
| 39 |
+
parent::__construct($message, $code);
|
| 40 |
+
}
|
| 41 |
}
|
app/code/community/Boxalino/{CemSearch/Lib/vendor → Intelligence/lib}/Thrift/Factory/TBinaryProtocolFactory.php
RENAMED
|
@@ -1,43 +1,43 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
/*
|
| 3 |
-
* Licensed to the Apache Software Foundation (ASF) under one
|
| 4 |
-
* or more contributor license agreements. See the NOTICE file
|
| 5 |
-
* distributed with this work for additional information
|
| 6 |
-
* regarding copyright ownership. The ASF licenses this file
|
| 7 |
-
* to you under the Apache License, Version 2.0 (the
|
| 8 |
-
* "License"); you may not use this file except in compliance
|
| 9 |
-
* with the License. You may obtain a copy of the License at
|
| 10 |
-
*
|
| 11 |
-
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
-
*
|
| 13 |
-
* Unless required by applicable law or agreed to in writing,
|
| 14 |
-
* software distributed under the License is distributed on an
|
| 15 |
-
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 16 |
-
* KIND, either express or implied. See the License for the
|
| 17 |
-
* specific language governing permissions and limitations
|
| 18 |
-
* under the License.
|
| 19 |
-
*
|
| 20 |
-
* @package thrift.protocol
|
| 21 |
-
*/
|
| 22 |
-
|
| 23 |
-
namespace Thrift\Factory;
|
| 24 |
-
|
| 25 |
-
use Thrift\Factory\TProtocolFactory;
|
| 26 |
-
use Thrift\Protocol\TBinaryProtocol;
|
| 27 |
-
|
| 28 |
-
/**
|
| 29 |
-
* Binary Protocol Factory
|
| 30 |
-
*/
|
| 31 |
-
class TBinaryProtocolFactory implements TProtocolFactory {
|
| 32 |
-
private $strictRead_ = false;
|
| 33 |
-
private $strictWrite_ = false;
|
| 34 |
-
|
| 35 |
-
public function __construct($strictRead=false, $strictWrite=false) {
|
| 36 |
-
$this->strictRead_ = $strictRead;
|
| 37 |
-
$this->strictWrite_ = $strictWrite;
|
| 38 |
-
}
|
| 39 |
-
|
| 40 |
-
public function getProtocol($trans) {
|
| 41 |
-
return new TBinaryProtocol($trans, $this->strictRead_, $this->strictWrite_);
|
| 42 |
-
}
|
| 43 |
}
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Licensed to the Apache Software Foundation (ASF) under one
|
| 4 |
+
* or more contributor license agreements. See the NOTICE file
|
| 5 |
+
* distributed with this work for additional information
|
| 6 |
+
* regarding copyright ownership. The ASF licenses this file
|
| 7 |
+
* to you under the Apache License, Version 2.0 (the
|
| 8 |
+
* "License"); you may not use this file except in compliance
|
| 9 |
+
* with the License. You may obtain a copy of the License at
|
| 10 |
+
*
|
| 11 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
+
*
|
| 13 |
+
* Unless required by applicable law or agreed to in writing,
|
| 14 |
+
* software distributed under the License is distributed on an
|
| 15 |
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 16 |
+
* KIND, either express or implied. See the License for the
|
| 17 |
+
* specific language governing permissions and limitations
|
| 18 |
+
* under the License.
|
| 19 |
+
*
|
| 20 |
+
* @package thrift.protocol
|
| 21 |
+
*/
|
| 22 |
+
|
| 23 |
+
namespace Thrift\Factory;
|
| 24 |
+
|
| 25 |
+
use Thrift\Factory\TProtocolFactory;
|
| 26 |
+
use Thrift\Protocol\TBinaryProtocol;
|
| 27 |
+
|
| 28 |
+
/**
|
| 29 |
+
* Binary Protocol Factory
|
| 30 |
+
*/
|
| 31 |
+
class TBinaryProtocolFactory implements TProtocolFactory {
|
| 32 |
+
private $strictRead_ = false;
|
| 33 |
+
private $strictWrite_ = false;
|
| 34 |
+
|
| 35 |
+
public function __construct($strictRead=false, $strictWrite=false) {
|
| 36 |
+
$this->strictRead_ = $strictRead;
|
| 37 |
+
$this->strictWrite_ = $strictWrite;
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
public function getProtocol($trans) {
|
| 41 |
+
return new TBinaryProtocol($trans, $this->strictRead_, $this->strictWrite_);
|
| 42 |
+
}
|
| 43 |
}
|
app/code/community/Boxalino/{CemSearch/Lib/vendor → Intelligence/lib}/Thrift/Factory/TCompactProtocolFactory.php
RENAMED
|
@@ -1,39 +1,39 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
/*
|
| 3 |
-
* Licensed to the Apache Software Foundation (ASF) under one
|
| 4 |
-
* or more contributor license agreements. See the NOTICE file
|
| 5 |
-
* distributed with this work for additional information
|
| 6 |
-
* regarding copyright ownership. The ASF licenses this file
|
| 7 |
-
* to you under the Apache License, Version 2.0 (the
|
| 8 |
-
* "License"); you may not use this file except in compliance
|
| 9 |
-
* with the License. You may obtain a copy of the License at
|
| 10 |
-
*
|
| 11 |
-
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
-
*
|
| 13 |
-
* Unless required by applicable law or agreed to in writing,
|
| 14 |
-
* software distributed under the License is distributed on an
|
| 15 |
-
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 16 |
-
* KIND, either express or implied. See the License for the
|
| 17 |
-
* specific language governing permissions and limitations
|
| 18 |
-
* under the License.
|
| 19 |
-
*
|
| 20 |
-
* @package thrift.protocol
|
| 21 |
-
*/
|
| 22 |
-
|
| 23 |
-
namespace Thrift\Factory;
|
| 24 |
-
|
| 25 |
-
use Thrift\Factory\TProtocolFactory;
|
| 26 |
-
use Thrift\Protocol\TCompactProtocol;
|
| 27 |
-
|
| 28 |
-
/**
|
| 29 |
-
* Compact Protocol Factory
|
| 30 |
-
*/
|
| 31 |
-
class TCompactProtocolFactory implements TProtocolFactory {
|
| 32 |
-
|
| 33 |
-
public function __construct() {
|
| 34 |
-
}
|
| 35 |
-
|
| 36 |
-
public function getProtocol($trans) {
|
| 37 |
-
return new TCompactProtocol($trans);
|
| 38 |
-
}
|
| 39 |
}
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Licensed to the Apache Software Foundation (ASF) under one
|
| 4 |
+
* or more contributor license agreements. See the NOTICE file
|
| 5 |
+
* distributed with this work for additional information
|
| 6 |
+
* regarding copyright ownership. The ASF licenses this file
|
| 7 |
+
* to you under the Apache License, Version 2.0 (the
|
| 8 |
+
* "License"); you may not use this file except in compliance
|
| 9 |
+
* with the License. You may obtain a copy of the License at
|
| 10 |
+
*
|
| 11 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
+
*
|
| 13 |
+
* Unless required by applicable law or agreed to in writing,
|
| 14 |
+
* software distributed under the License is distributed on an
|
| 15 |
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 16 |
+
* KIND, either express or implied. See the License for the
|
| 17 |
+
* specific language governing permissions and limitations
|
| 18 |
+
* under the License.
|
| 19 |
+
*
|
| 20 |
+
* @package thrift.protocol
|
| 21 |
+
*/
|
| 22 |
+
|
| 23 |
+
namespace Thrift\Factory;
|
| 24 |
+
|
| 25 |
+
use Thrift\Factory\TProtocolFactory;
|
| 26 |
+
use Thrift\Protocol\TCompactProtocol;
|
| 27 |
+
|
| 28 |
+
/**
|
| 29 |
+
* Compact Protocol Factory
|
| 30 |
+
*/
|
| 31 |
+
class TCompactProtocolFactory implements TProtocolFactory {
|
| 32 |
+
|
| 33 |
+
public function __construct() {
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
public function getProtocol($trans) {
|
| 37 |
+
return new TCompactProtocol($trans);
|
| 38 |
+
}
|
| 39 |
}
|
app/code/community/Boxalino/{CemSearch/Lib/vendor → Intelligence/lib}/Thrift/Factory/TJSONProtocolFactory.php
RENAMED
|
@@ -1,41 +1,41 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
/*
|
| 3 |
-
* Licensed to the Apache Software Foundation (ASF) under one
|
| 4 |
-
* or more contributor license agreements. See the NOTICE file
|
| 5 |
-
* distributed with this work for additional information
|
| 6 |
-
* regarding copyright ownership. The ASF licenses this file
|
| 7 |
-
* to you under the Apache License, Version 2.0 (the
|
| 8 |
-
* "License"); you may not use this file except in compliance
|
| 9 |
-
* with the License. You may obtain a copy of the License at
|
| 10 |
-
*
|
| 11 |
-
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
-
*
|
| 13 |
-
* Unless required by applicable law or agreed to in writing,
|
| 14 |
-
* software distributed under the License is distributed on an
|
| 15 |
-
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 16 |
-
* KIND, either express or implied. See the License for the
|
| 17 |
-
* specific language governing permissions and limitations
|
| 18 |
-
* under the License.
|
| 19 |
-
*
|
| 20 |
-
* @package thrift.protocol
|
| 21 |
-
*/
|
| 22 |
-
|
| 23 |
-
namespace Thrift\Factory;
|
| 24 |
-
|
| 25 |
-
use Thrift\Factory\TProtocolFactory;
|
| 26 |
-
use Thrift\Protocol\TJSONProtocol;
|
| 27 |
-
|
| 28 |
-
/**
|
| 29 |
-
* JSON Protocol Factory
|
| 30 |
-
*/
|
| 31 |
-
class TJSONProtocolFactory implements TProtocolFactory
|
| 32 |
-
{
|
| 33 |
-
public function __construct()
|
| 34 |
-
{
|
| 35 |
-
}
|
| 36 |
-
|
| 37 |
-
public function getProtocol($trans)
|
| 38 |
-
{
|
| 39 |
-
return new TJSONProtocol($trans);
|
| 40 |
-
}
|
| 41 |
-
}
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Licensed to the Apache Software Foundation (ASF) under one
|
| 4 |
+
* or more contributor license agreements. See the NOTICE file
|
| 5 |
+
* distributed with this work for additional information
|
| 6 |
+
* regarding copyright ownership. The ASF licenses this file
|
| 7 |
+
* to you under the Apache License, Version 2.0 (the
|
| 8 |
+
* "License"); you may not use this file except in compliance
|
| 9 |
+
* with the License. You may obtain a copy of the License at
|
| 10 |
+
*
|
| 11 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
+
*
|
| 13 |
+
* Unless required by applicable law or agreed to in writing,
|
| 14 |
+
* software distributed under the License is distributed on an
|
| 15 |
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 16 |
+
* KIND, either express or implied. See the License for the
|
| 17 |
+
* specific language governing permissions and limitations
|
| 18 |
+
* under the License.
|
| 19 |
+
*
|
| 20 |
+
* @package thrift.protocol
|
| 21 |
+
*/
|
| 22 |
+
|
| 23 |
+
namespace Thrift\Factory;
|
| 24 |
+
|
| 25 |
+
use Thrift\Factory\TProtocolFactory;
|
| 26 |
+
use Thrift\Protocol\TJSONProtocol;
|
| 27 |
+
|
| 28 |
+
/**
|
| 29 |
+
* JSON Protocol Factory
|
| 30 |
+
*/
|
| 31 |
+
class TJSONProtocolFactory implements TProtocolFactory
|
| 32 |
+
{
|
| 33 |
+
public function __construct()
|
| 34 |
+
{
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
public function getProtocol($trans)
|
| 38 |
+
{
|
| 39 |
+
return new TJSONProtocol($trans);
|
| 40 |
+
}
|
| 41 |
+
}
|
app/code/community/Boxalino/Intelligence/lib/Thrift/Factory/TProtocol.php
ADDED
|
@@ -0,0 +1,346 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Licensed to the Apache Software Foundation (ASF) under one
|
| 4 |
+
* or more contributor license agreements. See the NOTICE file
|
| 5 |
+
* distributed with this work for additional information
|
| 6 |
+
* regarding copyright ownership. The ASF licenses this file
|
| 7 |
+
* to you under the Apache License, Version 2.0 (the
|
| 8 |
+
* "License"); you may not use this file except in compliance
|
| 9 |
+
* with the License. You may obtain a copy of the License at
|
| 10 |
+
*
|
| 11 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
+
*
|
| 13 |
+
* Unless required by applicable law or agreed to in writing,
|
| 14 |
+
* software distributed under the License is distributed on an
|
| 15 |
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 16 |
+
* KIND, either express or implied. See the License for the
|
| 17 |
+
* specific language governing permissions and limitations
|
| 18 |
+
* under the License.
|
| 19 |
+
*
|
| 20 |
+
* @package thrift.protocol
|
| 21 |
+
*/
|
| 22 |
+
|
| 23 |
+
namespace Thrift\Factory;
|
| 24 |
+
|
| 25 |
+
use Thrift\Type\TType;
|
| 26 |
+
use Thrift\Exception\TProtocolException;
|
| 27 |
+
|
| 28 |
+
/**
|
| 29 |
+
* Protocol base class module.
|
| 30 |
+
*/
|
| 31 |
+
abstract class TProtocol {
|
| 32 |
+
// The below may seem silly, but it is to get around the problem that the
|
| 33 |
+
// "instanceof" operator can only take in a T_VARIABLE and not a T_STRING
|
| 34 |
+
// or T_CONSTANT_ENCAPSED_STRING. Using "is_a()" instead of "instanceof" is
|
| 35 |
+
// a workaround but is deprecated in PHP5. This is used in the generated
|
| 36 |
+
// deserialization code.
|
| 37 |
+
static $TBINARYPROTOCOLACCELERATED = 'TBinaryProtocolAccelerated';
|
| 38 |
+
|
| 39 |
+
/**
|
| 40 |
+
* Underlying transport
|
| 41 |
+
*
|
| 42 |
+
* @var TTransport
|
| 43 |
+
*/
|
| 44 |
+
protected $trans_;
|
| 45 |
+
|
| 46 |
+
/**
|
| 47 |
+
* Constructor
|
| 48 |
+
*/
|
| 49 |
+
protected function __construct($trans) {
|
| 50 |
+
$this->trans_ = $trans;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
/**
|
| 54 |
+
* Accessor for transport
|
| 55 |
+
*
|
| 56 |
+
* @return TTransport
|
| 57 |
+
*/
|
| 58 |
+
public function getTransport() {
|
| 59 |
+
return $this->trans_;
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
/**
|
| 63 |
+
* Writes the message header
|
| 64 |
+
*
|
| 65 |
+
* @param string $name Function name
|
| 66 |
+
* @param int $type message type TMessageType::CALL or TMessageType::REPLY
|
| 67 |
+
* @param int $seqid The sequence id of this message
|
| 68 |
+
*/
|
| 69 |
+
public abstract function writeMessageBegin($name, $type, $seqid);
|
| 70 |
+
|
| 71 |
+
/**
|
| 72 |
+
* Close the message
|
| 73 |
+
*/
|
| 74 |
+
public abstract function writeMessageEnd();
|
| 75 |
+
|
| 76 |
+
/**
|
| 77 |
+
* Writes a struct header.
|
| 78 |
+
*
|
| 79 |
+
* @param string $name Struct name
|
| 80 |
+
* @throws TException on write error
|
| 81 |
+
* @return int How many bytes written
|
| 82 |
+
*/
|
| 83 |
+
public abstract function writeStructBegin($name);
|
| 84 |
+
|
| 85 |
+
/**
|
| 86 |
+
* Close a struct.
|
| 87 |
+
*
|
| 88 |
+
* @throws TException on write error
|
| 89 |
+
* @return int How many bytes written
|
| 90 |
+
*/
|
| 91 |
+
public abstract function writeStructEnd();
|
| 92 |
+
|
| 93 |
+
/*
|
| 94 |
+
* Starts a field.
|
| 95 |
+
*
|
| 96 |
+
* @param string $name Field name
|
| 97 |
+
* @param int $type Field type
|
| 98 |
+
* @param int $fid Field id
|
| 99 |
+
* @throws TException on write error
|
| 100 |
+
* @return int How many bytes written
|
| 101 |
+
*/
|
| 102 |
+
public abstract function writeFieldBegin($fieldName, $fieldType, $fieldId);
|
| 103 |
+
|
| 104 |
+
public abstract function writeFieldEnd();
|
| 105 |
+
|
| 106 |
+
public abstract function writeFieldStop();
|
| 107 |
+
|
| 108 |
+
public abstract function writeMapBegin($keyType, $valType, $size);
|
| 109 |
+
|
| 110 |
+
public abstract function writeMapEnd();
|
| 111 |
+
|
| 112 |
+
public abstract function writeListBegin($elemType, $size);
|
| 113 |
+
|
| 114 |
+
public abstract function writeListEnd();
|
| 115 |
+
|
| 116 |
+
public abstract function writeSetBegin($elemType, $size);
|
| 117 |
+
|
| 118 |
+
public abstract function writeSetEnd();
|
| 119 |
+
|
| 120 |
+
public abstract function writeBool($bool);
|
| 121 |
+
|
| 122 |
+
public abstract function writeByte($byte);
|
| 123 |
+
|
| 124 |
+
public abstract function writeI16($i16);
|
| 125 |
+
|
| 126 |
+
public abstract function writeI32($i32);
|
| 127 |
+
|
| 128 |
+
public abstract function writeI64($i64);
|
| 129 |
+
|
| 130 |
+
public abstract function writeDouble($dub);
|
| 131 |
+
|
| 132 |
+
public abstract function writeString($str);
|
| 133 |
+
|
| 134 |
+
/**
|
| 135 |
+
* Reads the message header
|
| 136 |
+
*
|
| 137 |
+
* @param string $name Function name
|
| 138 |
+
* @param int $type message type TMessageType::CALL or TMessageType::REPLY
|
| 139 |
+
* @parem int $seqid The sequence id of this message
|
| 140 |
+
*/
|
| 141 |
+
public abstract function readMessageBegin(&$name, &$type, &$seqid);
|
| 142 |
+
|
| 143 |
+
/**
|
| 144 |
+
* Read the close of message
|
| 145 |
+
*/
|
| 146 |
+
public abstract function readMessageEnd();
|
| 147 |
+
|
| 148 |
+
public abstract function readStructBegin(&$name);
|
| 149 |
+
|
| 150 |
+
public abstract function readStructEnd();
|
| 151 |
+
|
| 152 |
+
public abstract function readFieldBegin(&$name, &$fieldType, &$fieldId);
|
| 153 |
+
|
| 154 |
+
public abstract function readFieldEnd();
|
| 155 |
+
|
| 156 |
+
public abstract function readMapBegin(&$keyType, &$valType, &$size);
|
| 157 |
+
|
| 158 |
+
public abstract function readMapEnd();
|
| 159 |
+
|
| 160 |
+
public abstract function readListBegin(&$elemType, &$size);
|
| 161 |
+
|
| 162 |
+
public abstract function readListEnd();
|
| 163 |
+
|
| 164 |
+
public abstract function readSetBegin(&$elemType, &$size);
|
| 165 |
+
|
| 166 |
+
public abstract function readSetEnd();
|
| 167 |
+
|
| 168 |
+
public abstract function readBool(&$bool);
|
| 169 |
+
|
| 170 |
+
public abstract function readByte(&$byte);
|
| 171 |
+
|
| 172 |
+
public abstract function readI16(&$i16);
|
| 173 |
+
|
| 174 |
+
public abstract function readI32(&$i32);
|
| 175 |
+
|
| 176 |
+
public abstract function readI64(&$i64);
|
| 177 |
+
|
| 178 |
+
public abstract function readDouble(&$dub);
|
| 179 |
+
|
| 180 |
+
public abstract function readString(&$str);
|
| 181 |
+
|
| 182 |
+
/**
|
| 183 |
+
* The skip function is a utility to parse over unrecognized date without
|
| 184 |
+
* causing corruption.
|
| 185 |
+
*
|
| 186 |
+
* @param TType $type What type is it
|
| 187 |
+
*/
|
| 188 |
+
public function skip($type) {
|
| 189 |
+
switch ($type) {
|
| 190 |
+
case TType::BOOL:
|
| 191 |
+
return $this->readBool($bool);
|
| 192 |
+
case TType::BYTE:
|
| 193 |
+
return $this->readByte($byte);
|
| 194 |
+
case TType::I16:
|
| 195 |
+
return $this->readI16($i16);
|
| 196 |
+
case TType::I32:
|
| 197 |
+
return $this->readI32($i32);
|
| 198 |
+
case TType::I64:
|
| 199 |
+
return $this->readI64($i64);
|
| 200 |
+
case TType::DOUBLE:
|
| 201 |
+
return $this->readDouble($dub);
|
| 202 |
+
case TType::STRING:
|
| 203 |
+
return $this->readString($str);
|
| 204 |
+
case TType::STRUCT:
|
| 205 |
+
{
|
| 206 |
+
$result = $this->readStructBegin($name);
|
| 207 |
+
while (true) {
|
| 208 |
+
$result += $this->readFieldBegin($name, $ftype, $fid);
|
| 209 |
+
if ($ftype == TType::STOP) {
|
| 210 |
+
break;
|
| 211 |
+
}
|
| 212 |
+
$result += $this->skip($ftype);
|
| 213 |
+
$result += $this->readFieldEnd();
|
| 214 |
+
}
|
| 215 |
+
$result += $this->readStructEnd();
|
| 216 |
+
return $result;
|
| 217 |
+
}
|
| 218 |
+
case TType::MAP:
|
| 219 |
+
{
|
| 220 |
+
$result = $this->readMapBegin($keyType, $valType, $size);
|
| 221 |
+
for ($i = 0; $i < $size; $i++) {
|
| 222 |
+
$result += $this->skip($keyType);
|
| 223 |
+
$result += $this->skip($valType);
|
| 224 |
+
}
|
| 225 |
+
$result += $this->readMapEnd();
|
| 226 |
+
return $result;
|
| 227 |
+
}
|
| 228 |
+
case TType::SET:
|
| 229 |
+
{
|
| 230 |
+
$result = $this->readSetBegin($elemType, $size);
|
| 231 |
+
for ($i = 0; $i < $size; $i++) {
|
| 232 |
+
$result += $this->skip($elemType);
|
| 233 |
+
}
|
| 234 |
+
$result += $this->readSetEnd();
|
| 235 |
+
return $result;
|
| 236 |
+
}
|
| 237 |
+
case TType::LST:
|
| 238 |
+
{
|
| 239 |
+
$result = $this->readListBegin($elemType, $size);
|
| 240 |
+
for ($i = 0; $i < $size; $i++) {
|
| 241 |
+
$result += $this->skip($elemType);
|
| 242 |
+
}
|
| 243 |
+
$result += $this->readListEnd();
|
| 244 |
+
return $result;
|
| 245 |
+
}
|
| 246 |
+
default:
|
| 247 |
+
throw new TProtocolException('Unknown field type: '.$type,
|
| 248 |
+
TProtocolException::INVALID_DATA);
|
| 249 |
+
}
|
| 250 |
+
}
|
| 251 |
+
|
| 252 |
+
/**
|
| 253 |
+
* Utility for skipping binary data
|
| 254 |
+
*
|
| 255 |
+
* @param TTransport $itrans TTransport object
|
| 256 |
+
* @param int $type Field type
|
| 257 |
+
*/
|
| 258 |
+
public static function skipBinary($itrans, $type) {
|
| 259 |
+
switch ($type) {
|
| 260 |
+
case TType::BOOL:
|
| 261 |
+
return $itrans->readAll(1);
|
| 262 |
+
case TType::BYTE:
|
| 263 |
+
return $itrans->readAll(1);
|
| 264 |
+
case TType::I16:
|
| 265 |
+
return $itrans->readAll(2);
|
| 266 |
+
case TType::I32:
|
| 267 |
+
return $itrans->readAll(4);
|
| 268 |
+
case TType::I64:
|
| 269 |
+
return $itrans->readAll(8);
|
| 270 |
+
case TType::DOUBLE:
|
| 271 |
+
return $itrans->readAll(8);
|
| 272 |
+
case TType::STRING:
|
| 273 |
+
$len = unpack('N', $itrans->readAll(4));
|
| 274 |
+
$len = $len[1];
|
| 275 |
+
if ($len > 0x7fffffff) {
|
| 276 |
+
$len = 0 - (($len - 1) ^ 0xffffffff);
|
| 277 |
+
}
|
| 278 |
+
return 4 + $itrans->readAll($len);
|
| 279 |
+
case TType::STRUCT:
|
| 280 |
+
{
|
| 281 |
+
$result = 0;
|
| 282 |
+
while (true) {
|
| 283 |
+
$ftype = 0;
|
| 284 |
+
$fid = 0;
|
| 285 |
+
$data = $itrans->readAll(1);
|
| 286 |
+
$arr = unpack('c', $data);
|
| 287 |
+
$ftype = $arr[1];
|
| 288 |
+
if ($ftype == TType::STOP) {
|
| 289 |
+
break;
|
| 290 |
+
}
|
| 291 |
+
// I16 field id
|
| 292 |
+
$result += $itrans->readAll(2);
|
| 293 |
+
$result += self::skipBinary($itrans, $ftype);
|
| 294 |
+
}
|
| 295 |
+
return $result;
|
| 296 |
+
}
|
| 297 |
+
case TType::MAP:
|
| 298 |
+
{
|
| 299 |
+
// Ktype
|
| 300 |
+
$data = $itrans->readAll(1);
|
| 301 |
+
$arr = unpack('c', $data);
|
| 302 |
+
$ktype = $arr[1];
|
| 303 |
+
// Vtype
|
| 304 |
+
$data = $itrans->readAll(1);
|
| 305 |
+
$arr = unpack('c', $data);
|
| 306 |
+
$vtype = $arr[1];
|
| 307 |
+
// Size
|
| 308 |
+
$data = $itrans->readAll(4);
|
| 309 |
+
$arr = unpack('N', $data);
|
| 310 |
+
$size = $arr[1];
|
| 311 |
+
if ($size > 0x7fffffff) {
|
| 312 |
+
$size = 0 - (($size - 1) ^ 0xffffffff);
|
| 313 |
+
}
|
| 314 |
+
$result = 6;
|
| 315 |
+
for ($i = 0; $i < $size; $i++) {
|
| 316 |
+
$result += self::skipBinary($itrans, $ktype);
|
| 317 |
+
$result += self::skipBinary($itrans, $vtype);
|
| 318 |
+
}
|
| 319 |
+
return $result;
|
| 320 |
+
}
|
| 321 |
+
case TType::SET:
|
| 322 |
+
case TType::LST:
|
| 323 |
+
{
|
| 324 |
+
// Vtype
|
| 325 |
+
$data = $itrans->readAll(1);
|
| 326 |
+
$arr = unpack('c', $data);
|
| 327 |
+
$vtype = $arr[1];
|
| 328 |
+
// Size
|
| 329 |
+
$data = $itrans->readAll(4);
|
| 330 |
+
$arr = unpack('N', $data);
|
| 331 |
+
$size = $arr[1];
|
| 332 |
+
if ($size > 0x7fffffff) {
|
| 333 |
+
$size = 0 - (($size - 1) ^ 0xffffffff);
|
| 334 |
+
}
|
| 335 |
+
$result = 5;
|
| 336 |
+
for ($i = 0; $i < $size; $i++) {
|
| 337 |
+
$result += self::skipBinary($itrans, $vtype);
|
| 338 |
+
}
|
| 339 |
+
return $result;
|
| 340 |
+
}
|
| 341 |
+
default:
|
| 342 |
+
throw new TProtocolException('Unknown field type: '.$type,
|
| 343 |
+
TProtocolException::INVALID_DATA);
|
| 344 |
+
}
|
| 345 |
+
}
|
| 346 |
+
}
|
app/code/community/Boxalino/{CemSearch/Lib/vendor → Intelligence/lib}/Thrift/Factory/TProtocolFactory.php
RENAMED
|
@@ -1,35 +1,35 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
/*
|
| 3 |
-
* Licensed to the Apache Software Foundation (ASF) under one
|
| 4 |
-
* or more contributor license agreements. See the NOTICE file
|
| 5 |
-
* distributed with this work for additional information
|
| 6 |
-
* regarding copyright ownership. The ASF licenses this file
|
| 7 |
-
* to you under the Apache License, Version 2.0 (the
|
| 8 |
-
* "License"); you may not use this file except in compliance
|
| 9 |
-
* with the License. You may obtain a copy of the License at
|
| 10 |
-
*
|
| 11 |
-
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
-
*
|
| 13 |
-
* Unless required by applicable law or agreed to in writing,
|
| 14 |
-
* software distributed under the License is distributed on an
|
| 15 |
-
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 16 |
-
* KIND, either express or implied. See the License for the
|
| 17 |
-
* specific language governing permissions and limitations
|
| 18 |
-
* under the License.
|
| 19 |
-
*
|
| 20 |
-
* @package thrift.protocol
|
| 21 |
-
*/
|
| 22 |
-
|
| 23 |
-
namespace Thrift\Factory;
|
| 24 |
-
|
| 25 |
-
/**
|
| 26 |
-
* Protocol factory creates protocol objects from transports
|
| 27 |
-
*/
|
| 28 |
-
interface TProtocolFactory {
|
| 29 |
-
/**
|
| 30 |
-
* Build a protocol from the base transport
|
| 31 |
-
*
|
| 32 |
-
* @return Thrift\Protocol\TProtocol protocol
|
| 33 |
-
*/
|
| 34 |
-
public function getProtocol($trans);
|
| 35 |
-
}
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Licensed to the Apache Software Foundation (ASF) under one
|
| 4 |
+
* or more contributor license agreements. See the NOTICE file
|
| 5 |
+
* distributed with this work for additional information
|
| 6 |
+
* regarding copyright ownership. The ASF licenses this file
|
| 7 |
+
* to you under the Apache License, Version 2.0 (the
|
| 8 |
+
* "License"); you may not use this file except in compliance
|
| 9 |
+
* with the License. You may obtain a copy of the License at
|
| 10 |
+
*
|
| 11 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
+
*
|
| 13 |
+
* Unless required by applicable law or agreed to in writing,
|
| 14 |
+
* software distributed under the License is distributed on an
|
| 15 |
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 16 |
+
* KIND, either express or implied. See the License for the
|
| 17 |
+
* specific language governing permissions and limitations
|
| 18 |
+
* under the License.
|
| 19 |
+
*
|
| 20 |
+
* @package thrift.protocol
|
| 21 |
+
*/
|
| 22 |
+
|
| 23 |
+
namespace Thrift\Factory;
|
| 24 |
+
|
| 25 |
+
/**
|
| 26 |
+
* Protocol factory creates protocol objects from transports
|
| 27 |
+
*/
|
| 28 |
+
interface TProtocolFactory {
|
| 29 |
+
/**
|
| 30 |
+
* Build a protocol from the base transport
|
| 31 |
+
*
|
| 32 |
+
* @return \Thrift\Protocol\TProtocol protocol
|
| 33 |
+
*/
|
| 34 |
+
public function getProtocol($trans);
|
| 35 |
+
}
|
app/code/community/Boxalino/{CemSearch/Lib/vendor → Intelligence/lib}/Thrift/Factory/TStringFuncFactory.php
RENAMED
|
@@ -1,63 +1,63 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
/*
|
| 3 |
-
* Licensed to the Apache Software Foundation (ASF) under one
|
| 4 |
-
* or more contributor license agreements. See the NOTICE file
|
| 5 |
-
* distributed with this work for additional information
|
| 6 |
-
* regarding copyright ownership. The ASF licenses this file
|
| 7 |
-
* to you under the Apache License, Version 2.0 (the
|
| 8 |
-
* "License"); you may not use this file except in compliance
|
| 9 |
-
* with the License. You may obtain a copy of the License at
|
| 10 |
-
*
|
| 11 |
-
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
-
*
|
| 13 |
-
* Unless required by applicable law or agreed to in writing,
|
| 14 |
-
* software distributed under the License is distributed on an
|
| 15 |
-
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 16 |
-
* KIND, either express or implied. See the License for the
|
| 17 |
-
* specific language governing permissions and limitations
|
| 18 |
-
* under the License.
|
| 19 |
-
*
|
| 20 |
-
*/
|
| 21 |
-
|
| 22 |
-
namespace Thrift\Factory;
|
| 23 |
-
|
| 24 |
-
use Thrift\StringFunc\Mbstring;
|
| 25 |
-
use Thrift\StringFunc\Core;
|
| 26 |
-
|
| 27 |
-
class TStringFuncFactory {
|
| 28 |
-
private static $_instance;
|
| 29 |
-
|
| 30 |
-
/**
|
| 31 |
-
* Get the Singleton instance of TStringFunc implementation that is
|
| 32 |
-
* compatible with the current system's mbstring.func_overload settings.
|
| 33 |
-
*
|
| 34 |
-
* @return TStringFunc
|
| 35 |
-
*/
|
| 36 |
-
public static function create() {
|
| 37 |
-
if(!self::$_instance) {
|
| 38 |
-
self::_setInstance();
|
| 39 |
-
}
|
| 40 |
-
|
| 41 |
-
return self::$_instance;
|
| 42 |
-
}
|
| 43 |
-
|
| 44 |
-
private static function _setInstance() {
|
| 45 |
-
/**
|
| 46 |
-
* Cannot use str* functions for byte counting because multibyte
|
| 47 |
-
* characters will be read a single bytes.
|
| 48 |
-
*
|
| 49 |
-
* See: http://us.php.net/manual/en/mbstring.overload.php
|
| 50 |
-
*/
|
| 51 |
-
if(ini_get('mbstring.func_overload') & 2) {
|
| 52 |
-
self::$_instance = new Mbstring();
|
| 53 |
-
}
|
| 54 |
-
/**
|
| 55 |
-
* mbstring is not installed or does not have function overloading
|
| 56 |
-
* of the str* functions enabled so use PHP core str* functions for
|
| 57 |
-
* byte counting.
|
| 58 |
-
*/
|
| 59 |
-
else {
|
| 60 |
-
self::$_instance = new Core();
|
| 61 |
-
}
|
| 62 |
-
}
|
| 63 |
}
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Licensed to the Apache Software Foundation (ASF) under one
|
| 4 |
+
* or more contributor license agreements. See the NOTICE file
|
| 5 |
+
* distributed with this work for additional information
|
| 6 |
+
* regarding copyright ownership. The ASF licenses this file
|
| 7 |
+
* to you under the Apache License, Version 2.0 (the
|
| 8 |
+
* "License"); you may not use this file except in compliance
|
| 9 |
+
* with the License. You may obtain a copy of the License at
|
| 10 |
+
*
|
| 11 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
+
*
|
| 13 |
+
* Unless required by applicable law or agreed to in writing,
|
| 14 |
+
* software distributed under the License is distributed on an
|
| 15 |
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 16 |
+
* KIND, either express or implied. See the License for the
|
| 17 |
+
* specific language governing permissions and limitations
|
| 18 |
+
* under the License.
|
| 19 |
+
*
|
| 20 |
+
*/
|
| 21 |
+
|
| 22 |
+
namespace Thrift\Factory;
|
| 23 |
+
|
| 24 |
+
use Thrift\StringFunc\Mbstring;
|
| 25 |
+
use Thrift\StringFunc\Core;
|
| 26 |
+
|
| 27 |
+
class TStringFuncFactory {
|
| 28 |
+
private static $_instance;
|
| 29 |
+
|
| 30 |
+
/**
|
| 31 |
+
* Get the Singleton instance of TStringFunc implementation that is
|
| 32 |
+
* compatible with the current system's mbstring.func_overload settings.
|
| 33 |
+
*
|
| 34 |
+
* @return TStringFunc
|
| 35 |
+
*/
|
| 36 |
+
public static function create() {
|
| 37 |
+
if(!self::$_instance) {
|
| 38 |
+
self::_setInstance();
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
return self::$_instance;
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
private static function _setInstance() {
|
| 45 |
+
/**
|
| 46 |
+
* Cannot use str* functions for byte counting because multibyte
|
| 47 |
+
* characters will be read a single bytes.
|
| 48 |
+
*
|
| 49 |
+
* See: http://us.php.net/manual/en/mbstring.overload.php
|
| 50 |
+
*/
|
| 51 |
+
if(ini_get('mbstring.func_overload') & 2) {
|
| 52 |
+
self::$_instance = new Mbstring();
|
| 53 |
+
}
|
| 54 |
+
/**
|
| 55 |
+
* mbstring is not installed or does not have function overloading
|
| 56 |
+
* of the str* functions enabled so use PHP core str* functions for
|
| 57 |
+
* byte counting.
|
| 58 |
+
*/
|
| 59 |
+
else {
|
| 60 |
+
self::$_instance = new Core();
|
| 61 |
+
}
|
| 62 |
+
}
|
| 63 |
}
|
app/code/community/Boxalino/{CemSearch/Lib/vendor → Intelligence/lib}/Thrift/Factory/TTransportFactory.php
RENAMED
|
@@ -1,16 +1,16 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
|
| 3 |
-
namespace Thrift\Factory;
|
| 4 |
-
|
| 5 |
-
use Thrift\Transport\TTransport;
|
| 6 |
-
|
| 7 |
-
class TTransportFactory {
|
| 8 |
-
/**
|
| 9 |
-
* @static
|
| 10 |
-
* @param TTransport $transport
|
| 11 |
-
* @return TTransport
|
| 12 |
-
*/
|
| 13 |
-
public static function getTransport(TTransport $transport) {
|
| 14 |
-
return $transport;
|
| 15 |
-
}
|
| 16 |
-
}
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
namespace Thrift\Factory;
|
| 4 |
+
|
| 5 |
+
use Thrift\Transport\TTransport;
|
| 6 |
+
|
| 7 |
+
class TTransportFactory {
|
| 8 |
+
/**
|
| 9 |
+
* @static
|
| 10 |
+
* @param TTransport $transport
|
| 11 |
+
* @return TTransport
|
| 12 |
+
*/
|
| 13 |
+
public static function getTransport(TTransport $transport) {
|
| 14 |
+
return $transport;
|
| 15 |
+
}
|
| 16 |
+
}
|
app/code/community/Boxalino/{CemSearch/Lib/vendor → Intelligence/lib}/Thrift/Protocol/JSON/BaseContext.php
RENAMED
|
@@ -1,39 +1,39 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
/*
|
| 3 |
-
* Licensed to the Apache Software Foundation (ASF) under one
|
| 4 |
-
* or more contributor license agreements. See the NOTICE file
|
| 5 |
-
* distributed with this work for additional information
|
| 6 |
-
* regarding copyright ownership. The ASF licenses this file
|
| 7 |
-
* to you under the Apache License, Version 2.0 (the
|
| 8 |
-
* "License"); you may not use this file except in compliance
|
| 9 |
-
* with the License. You may obtain a copy of the License at
|
| 10 |
-
*
|
| 11 |
-
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
-
*
|
| 13 |
-
* Unless required by applicable law or agreed to in writing,
|
| 14 |
-
* software distributed under the License is distributed on an
|
| 15 |
-
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 16 |
-
* KIND, either express or implied. See the License for the
|
| 17 |
-
* specific language governing permissions and limitations
|
| 18 |
-
* under the License.
|
| 19 |
-
*
|
| 20 |
-
* @package thrift.protocol
|
| 21 |
-
*/
|
| 22 |
-
|
| 23 |
-
namespace Thrift\Protocol\JSON;
|
| 24 |
-
|
| 25 |
-
class BaseContext
|
| 26 |
-
{
|
| 27 |
-
function escapeNum()
|
| 28 |
-
{
|
| 29 |
-
return false;
|
| 30 |
-
}
|
| 31 |
-
|
| 32 |
-
function write()
|
| 33 |
-
{
|
| 34 |
-
}
|
| 35 |
-
|
| 36 |
-
function read()
|
| 37 |
-
{
|
| 38 |
-
}
|
| 39 |
}
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Licensed to the Apache Software Foundation (ASF) under one
|
| 4 |
+
* or more contributor license agreements. See the NOTICE file
|
| 5 |
+
* distributed with this work for additional information
|
| 6 |
+
* regarding copyright ownership. The ASF licenses this file
|
| 7 |
+
* to you under the Apache License, Version 2.0 (the
|
| 8 |
+
* "License"); you may not use this file except in compliance
|
| 9 |
+
* with the License. You may obtain a copy of the License at
|
| 10 |
+
*
|
| 11 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
+
*
|
| 13 |
+
* Unless required by applicable law or agreed to in writing,
|
| 14 |
+
* software distributed under the License is distributed on an
|
| 15 |
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 16 |
+
* KIND, either express or implied. See the License for the
|
| 17 |
+
* specific language governing permissions and limitations
|
| 18 |
+
* under the License.
|
| 19 |
+
*
|
| 20 |
+
* @package thrift.protocol
|
| 21 |
+
*/
|
| 22 |
+
|
| 23 |
+
namespace Thrift\Protocol\JSON;
|
| 24 |
+
|
| 25 |
+
class BaseContext
|
| 26 |
+
{
|
| 27 |
+
function escapeNum()
|
| 28 |
+
{
|
| 29 |
+
return false;
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
function write()
|
| 33 |
+
{
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
function read()
|
| 37 |
+
{
|
| 38 |
+
}
|
| 39 |
}
|
app/code/community/Boxalino/{CemSearch/Lib/vendor → Intelligence/lib}/Thrift/Protocol/JSON/ListContext.php
RENAMED
|
@@ -1,52 +1,52 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
/*
|
| 3 |
-
* Licensed to the Apache Software Foundation (ASF) under one
|
| 4 |
-
* or more contributor license agreements. See the NOTICE file
|
| 5 |
-
* distributed with this work for additional information
|
| 6 |
-
* regarding copyright ownership. The ASF licenses this file
|
| 7 |
-
* to you under the Apache License, Version 2.0 (the
|
| 8 |
-
* "License"); you may not use this file except in compliance
|
| 9 |
-
* with the License. You may obtain a copy of the License at
|
| 10 |
-
*
|
| 11 |
-
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
-
*
|
| 13 |
-
* Unless required by applicable law or agreed to in writing,
|
| 14 |
-
* software distributed under the License is distributed on an
|
| 15 |
-
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 16 |
-
* KIND, either express or implied. See the License for the
|
| 17 |
-
* specific language governing permissions and limitations
|
| 18 |
-
* under the License.
|
| 19 |
-
*
|
| 20 |
-
* @package thrift.protocol
|
| 21 |
-
*/
|
| 22 |
-
|
| 23 |
-
namespace Thrift\Protocol\JSON;
|
| 24 |
-
|
| 25 |
-
use Thrift\Protocol\JSON\BaseContext;
|
| 26 |
-
use Thrift\Protocol\TJSONProtocol;
|
| 27 |
-
|
| 28 |
-
class ListContext extends BaseContext
|
| 29 |
-
{
|
| 30 |
-
private $first_ = true;
|
| 31 |
-
private $p_;
|
| 32 |
-
|
| 33 |
-
public function __construct($p) {
|
| 34 |
-
$this->p_ = $p;
|
| 35 |
-
}
|
| 36 |
-
|
| 37 |
-
public function write() {
|
| 38 |
-
if ($this->first_) {
|
| 39 |
-
$this->first_ = false;
|
| 40 |
-
} else {
|
| 41 |
-
$this->p_->getTransport()->write(TJSONProtocol::COMMA);
|
| 42 |
-
}
|
| 43 |
-
}
|
| 44 |
-
|
| 45 |
-
public function read() {
|
| 46 |
-
if ($this->first_) {
|
| 47 |
-
$this->first_ = false;
|
| 48 |
-
} else {
|
| 49 |
-
$this->p_->readJSONSyntaxChar(TJSONProtocol::COMMA);
|
| 50 |
-
}
|
| 51 |
-
}
|
| 52 |
}
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Licensed to the Apache Software Foundation (ASF) under one
|
| 4 |
+
* or more contributor license agreements. See the NOTICE file
|
| 5 |
+
* distributed with this work for additional information
|
| 6 |
+
* regarding copyright ownership. The ASF licenses this file
|
| 7 |
+
* to you under the Apache License, Version 2.0 (the
|
| 8 |
+
* "License"); you may not use this file except in compliance
|
| 9 |
+
* with the License. You may obtain a copy of the License at
|
| 10 |
+
*
|
| 11 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
+
*
|
| 13 |
+
* Unless required by applicable law or agreed to in writing,
|
| 14 |
+
* software distributed under the License is distributed on an
|
| 15 |
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 16 |
+
* KIND, either express or implied. See the License for the
|
| 17 |
+
* specific language governing permissions and limitations
|
| 18 |
+
* under the License.
|
| 19 |
+
*
|
| 20 |
+
* @package thrift.protocol
|
| 21 |
+
*/
|
| 22 |
+
|
| 23 |
+
namespace Thrift\Protocol\JSON;
|
| 24 |
+
|
| 25 |
+
use Thrift\Protocol\JSON\BaseContext;
|
| 26 |
+
use Thrift\Protocol\TJSONProtocol;
|
| 27 |
+
|
| 28 |
+
class ListContext extends BaseContext
|
| 29 |
+
{
|
| 30 |
+
private $first_ = true;
|
| 31 |
+
private $p_;
|
| 32 |
+
|
| 33 |
+
public function __construct($p) {
|
| 34 |
+
$this->p_ = $p;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
public function write() {
|
| 38 |
+
if ($this->first_) {
|
| 39 |
+
$this->first_ = false;
|
| 40 |
+
} else {
|
| 41 |
+
$this->p_->getTransport()->write(TJSONProtocol::COMMA);
|
| 42 |
+
}
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
public function read() {
|
| 46 |
+
if ($this->first_) {
|
| 47 |
+
$this->first_ = false;
|
| 48 |
+
} else {
|
| 49 |
+
$this->p_->readJSONSyntaxChar(TJSONProtocol::COMMA);
|
| 50 |
+
}
|
| 51 |
+
}
|
| 52 |
}
|
app/code/community/Boxalino/{CemSearch/Lib/vendor → Intelligence/lib}/Thrift/Protocol/JSON/LookaheadReader.php
RENAMED
|
@@ -1,54 +1,54 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
/*
|
| 3 |
-
* Licensed to the Apache Software Foundation (ASF) under one
|
| 4 |
-
* or more contributor license agreements. See the NOTICE file
|
| 5 |
-
* distributed with this work for additional information
|
| 6 |
-
* regarding copyright ownership. The ASF licenses this file
|
| 7 |
-
* to you under the Apache License, Version 2.0 (the
|
| 8 |
-
* "License"); you may not use this file except in compliance
|
| 9 |
-
* with the License. You may obtain a copy of the License at
|
| 10 |
-
*
|
| 11 |
-
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
-
*
|
| 13 |
-
* Unless required by applicable law or agreed to in writing,
|
| 14 |
-
* software distributed under the License is distributed on an
|
| 15 |
-
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 16 |
-
* KIND, either express or implied. See the License for the
|
| 17 |
-
* specific language governing permissions and limitations
|
| 18 |
-
* under the License.
|
| 19 |
-
*
|
| 20 |
-
* @package thrift.protocol
|
| 21 |
-
*/
|
| 22 |
-
|
| 23 |
-
namespace Thrift\Protocol\JSON;
|
| 24 |
-
|
| 25 |
-
class LookaheadReader
|
| 26 |
-
{
|
| 27 |
-
private $hasData_ = false;
|
| 28 |
-
private $data_ = array();
|
| 29 |
-
private $p_;
|
| 30 |
-
|
| 31 |
-
public function __construct($p)
|
| 32 |
-
{
|
| 33 |
-
$this->p_ = $p;
|
| 34 |
-
}
|
| 35 |
-
|
| 36 |
-
public function read() {
|
| 37 |
-
if ($this->hasData_) {
|
| 38 |
-
$this->hasData_ = false;
|
| 39 |
-
} else {
|
| 40 |
-
$this->data_ = $this->p_->getTransport()->readAll(1);
|
| 41 |
-
}
|
| 42 |
-
|
| 43 |
-
return substr($this->data_, 0, 1);
|
| 44 |
-
}
|
| 45 |
-
|
| 46 |
-
public function peek() {
|
| 47 |
-
if (!$this->hasData_) {
|
| 48 |
-
$this->data_ = $this->p_->getTransport()->readAll(1);
|
| 49 |
-
}
|
| 50 |
-
|
| 51 |
-
$this->hasData_ = true;
|
| 52 |
-
return substr($this->data_, 0, 1);
|
| 53 |
-
}
|
| 54 |
}
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Licensed to the Apache Software Foundation (ASF) under one
|
| 4 |
+
* or more contributor license agreements. See the NOTICE file
|
| 5 |
+
* distributed with this work for additional information
|
| 6 |
+
* regarding copyright ownership. The ASF licenses this file
|
| 7 |
+
* to you under the Apache License, Version 2.0 (the
|
| 8 |
+
* "License"); you may not use this file except in compliance
|
| 9 |
+
* with the License. You may obtain a copy of the License at
|
| 10 |
+
*
|
| 11 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
+
*
|
| 13 |
+
* Unless required by applicable law or agreed to in writing,
|
| 14 |
+
* software distributed under the License is distributed on an
|
| 15 |
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 16 |
+
* KIND, either express or implied. See the License for the
|
| 17 |
+
* specific language governing permissions and limitations
|
| 18 |
+
* under the License.
|
| 19 |
+
*
|
| 20 |
+
* @package thrift.protocol
|
| 21 |
+
*/
|
| 22 |
+
|
| 23 |
+
namespace Thrift\Protocol\JSON;
|
| 24 |
+
|
| 25 |
+
class LookaheadReader
|
| 26 |
+
{
|
| 27 |
+
private $hasData_ = false;
|
| 28 |
+
private $data_ = array();
|
| 29 |
+
private $p_;
|
| 30 |
+
|
| 31 |
+
public function __construct($p)
|
| 32 |
+
{
|
| 33 |
+
$this->p_ = $p;
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
public function read() {
|
| 37 |
+
if ($this->hasData_) {
|
| 38 |
+
$this->hasData_ = false;
|
| 39 |
+
} else {
|
| 40 |
+
$this->data_ = $this->p_->getTransport()->readAll(1);
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
return substr($this->data_, 0, 1);
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
public function peek() {
|
| 47 |
+
if (!$this->hasData_) {
|
| 48 |
+
$this->data_ = $this->p_->getTransport()->readAll(1);
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
$this->hasData_ = true;
|
| 52 |
+
return substr($this->data_, 0, 1);
|
| 53 |
+
}
|
| 54 |
}
|
app/code/community/Boxalino/{CemSearch/Lib/vendor → Intelligence/lib}/Thrift/Protocol/JSON/PairContext.php
RENAMED
|
@@ -1,60 +1,60 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
/*
|
| 3 |
-
* Licensed to the Apache Software Foundation (ASF) under one
|
| 4 |
-
* or more contributor license agreements. See the NOTICE file
|
| 5 |
-
* distributed with this work for additional information
|
| 6 |
-
* regarding copyright ownership. The ASF licenses this file
|
| 7 |
-
* to you under the Apache License, Version 2.0 (the
|
| 8 |
-
* "License"); you may not use this file except in compliance
|
| 9 |
-
* with the License. You may obtain a copy of the License at
|
| 10 |
-
*
|
| 11 |
-
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
-
*
|
| 13 |
-
* Unless required by applicable law or agreed to in writing,
|
| 14 |
-
* software distributed under the License is distributed on an
|
| 15 |
-
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 16 |
-
* KIND, either express or implied. See the License for the
|
| 17 |
-
* specific language governing permissions and limitations
|
| 18 |
-
* under the License.
|
| 19 |
-
*
|
| 20 |
-
* @package thrift.protocol
|
| 21 |
-
*/
|
| 22 |
-
|
| 23 |
-
namespace Thrift\Protocol\JSON;
|
| 24 |
-
|
| 25 |
-
use Thrift\Protocol\JSON\BaseContext;
|
| 26 |
-
use Thrift\Protocol\TJSONProtocol;
|
| 27 |
-
|
| 28 |
-
class PairContext extends BaseContext {
|
| 29 |
-
private $first_ = true;
|
| 30 |
-
private $colon_ = true;
|
| 31 |
-
private $p_ = null;
|
| 32 |
-
|
| 33 |
-
public function __construct($p) {
|
| 34 |
-
$this->p_ = $p;
|
| 35 |
-
}
|
| 36 |
-
|
| 37 |
-
public function write() {
|
| 38 |
-
if ($this->first_) {
|
| 39 |
-
$this->first_ = false;
|
| 40 |
-
$this->colon_ = true;
|
| 41 |
-
} else {
|
| 42 |
-
$this->p_->getTransport()->write($this->colon_ ? TJSONProtocol::COLON : TJSONProtocol::COMMA);
|
| 43 |
-
$this->colon_ = !$this->colon_;
|
| 44 |
-
}
|
| 45 |
-
}
|
| 46 |
-
|
| 47 |
-
public function read() {
|
| 48 |
-
if ($this->first_) {
|
| 49 |
-
$this->first_ = false;
|
| 50 |
-
$this->colon_ = true;
|
| 51 |
-
} else {
|
| 52 |
-
$this->p_->readJSONSyntaxChar($this->colon_ ? TJSONProtocol::COLON : TJSONProtocol::COMMA);
|
| 53 |
-
$this->colon_ = !$this->colon_;
|
| 54 |
-
}
|
| 55 |
-
}
|
| 56 |
-
|
| 57 |
-
public function escapeNum() {
|
| 58 |
-
return $this->colon_;
|
| 59 |
-
}
|
| 60 |
}
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Licensed to the Apache Software Foundation (ASF) under one
|
| 4 |
+
* or more contributor license agreements. See the NOTICE file
|
| 5 |
+
* distributed with this work for additional information
|
| 6 |
+
* regarding copyright ownership. The ASF licenses this file
|
| 7 |
+
* to you under the Apache License, Version 2.0 (the
|
| 8 |
+
* "License"); you may not use this file except in compliance
|
| 9 |
+
* with the License. You may obtain a copy of the License at
|
| 10 |
+
*
|
| 11 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
+
*
|
| 13 |
+
* Unless required by applicable law or agreed to in writing,
|
| 14 |
+
* software distributed under the License is distributed on an
|
| 15 |
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 16 |
+
* KIND, either express or implied. See the License for the
|
| 17 |
+
* specific language governing permissions and limitations
|
| 18 |
+
* under the License.
|
| 19 |
+
*
|
| 20 |
+
* @package thrift.protocol
|
| 21 |
+
*/
|
| 22 |
+
|
| 23 |
+
namespace Thrift\Protocol\JSON;
|
| 24 |
+
|
| 25 |
+
use Thrift\Protocol\JSON\BaseContext;
|
| 26 |
+
use Thrift\Protocol\TJSONProtocol;
|
| 27 |
+
|
| 28 |
+
class PairContext extends BaseContext {
|
| 29 |
+
private $first_ = true;
|
| 30 |
+
private $colon_ = true;
|
| 31 |
+
private $p_ = null;
|
| 32 |
+
|
| 33 |
+
public function __construct($p) {
|
| 34 |
+
$this->p_ = $p;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
public function write() {
|
| 38 |
+
if ($this->first_) {
|
| 39 |
+
$this->first_ = false;
|
| 40 |
+
$this->colon_ = true;
|
| 41 |
+
} else {
|
| 42 |
+
$this->p_->getTransport()->write($this->colon_ ? TJSONProtocol::COLON : TJSONProtocol::COMMA);
|
| 43 |
+
$this->colon_ = !$this->colon_;
|
| 44 |
+
}
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
public function read() {
|
| 48 |
+
if ($this->first_) {
|
| 49 |
+
$this->first_ = false;
|
| 50 |
+
$this->colon_ = true;
|
| 51 |
+
} else {
|
| 52 |
+
$this->p_->readJSONSyntaxChar($this->colon_ ? TJSONProtocol::COLON : TJSONProtocol::COMMA);
|
| 53 |
+
$this->colon_ = !$this->colon_;
|
| 54 |
+
}
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
public function escapeNum() {
|
| 58 |
+
return $this->colon_;
|
| 59 |
+
}
|
| 60 |
}
|
app/code/community/Boxalino/{CemSearch/Lib/vendor → Intelligence/lib}/Thrift/Protocol/TBinaryProtocol.php
RENAMED
|
@@ -1,396 +1,396 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
/*
|
| 3 |
-
* Licensed to the Apache Software Foundation (ASF) under one
|
| 4 |
-
* or more contributor license agreements. See the NOTICE file
|
| 5 |
-
* distributed with this work for additional information
|
| 6 |
-
* regarding copyright ownership. The ASF licenses this file
|
| 7 |
-
* to you under the Apache License, Version 2.0 (the
|
| 8 |
-
* "License"); you may not use this file except in compliance
|
| 9 |
-
* with the License. You may obtain a copy of the License at
|
| 10 |
-
*
|
| 11 |
-
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
-
*
|
| 13 |
-
* Unless required by applicable law or agreed to in writing,
|
| 14 |
-
* software distributed under the License is distributed on an
|
| 15 |
-
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 16 |
-
* KIND, either express or implied. See the License for the
|
| 17 |
-
* specific language governing permissions and limitations
|
| 18 |
-
* under the License.
|
| 19 |
-
*
|
| 20 |
-
* @package thrift.protocol
|
| 21 |
-
*/
|
| 22 |
-
|
| 23 |
-
namespace Thrift\Protocol;
|
| 24 |
-
|
| 25 |
-
use Thrift\Protocol\TProtocol;
|
| 26 |
-
use Thrift\Type\TType;
|
| 27 |
-
use Thrift\Exception\TProtocolException;
|
| 28 |
-
use Thrift\Factory\TStringFuncFactory;
|
| 29 |
-
|
| 30 |
-
/**
|
| 31 |
-
* Binary implementation of the Thrift protocol.
|
| 32 |
-
*
|
| 33 |
-
*/
|
| 34 |
-
class TBinaryProtocol extends TProtocol {
|
| 35 |
-
|
| 36 |
-
const VERSION_MASK = 0xffff0000;
|
| 37 |
-
const VERSION_1 = 0x80010000;
|
| 38 |
-
|
| 39 |
-
protected $strictRead_ = false;
|
| 40 |
-
protected $strictWrite_ = true;
|
| 41 |
-
|
| 42 |
-
public function __construct($trans, $strictRead=false, $strictWrite=true) {
|
| 43 |
-
parent::__construct($trans);
|
| 44 |
-
$this->strictRead_ = $strictRead;
|
| 45 |
-
$this->strictWrite_ = $strictWrite;
|
| 46 |
-
}
|
| 47 |
-
|
| 48 |
-
public function writeMessageBegin($name, $type, $seqid) {
|
| 49 |
-
if ($this->strictWrite_) {
|
| 50 |
-
$version = self::VERSION_1 | $type;
|
| 51 |
-
return
|
| 52 |
-
$this->writeI32($version) +
|
| 53 |
-
$this->writeString($name) +
|
| 54 |
-
$this->writeI32($seqid);
|
| 55 |
-
} else {
|
| 56 |
-
return
|
| 57 |
-
$this->writeString($name) +
|
| 58 |
-
$this->writeByte($type) +
|
| 59 |
-
$this->writeI32($seqid);
|
| 60 |
-
}
|
| 61 |
-
}
|
| 62 |
-
|
| 63 |
-
public function writeMessageEnd() {
|
| 64 |
-
return 0;
|
| 65 |
-
}
|
| 66 |
-
|
| 67 |
-
public function writeStructBegin($name) {
|
| 68 |
-
return 0;
|
| 69 |
-
}
|
| 70 |
-
|
| 71 |
-
public function writeStructEnd() {
|
| 72 |
-
return 0;
|
| 73 |
-
}
|
| 74 |
-
|
| 75 |
-
public function writeFieldBegin($fieldName, $fieldType, $fieldId) {
|
| 76 |
-
return
|
| 77 |
-
$this->writeByte($fieldType) +
|
| 78 |
-
$this->writeI16($fieldId);
|
| 79 |
-
}
|
| 80 |
-
|
| 81 |
-
public function writeFieldEnd() {
|
| 82 |
-
return 0;
|
| 83 |
-
}
|
| 84 |
-
|
| 85 |
-
public function writeFieldStop() {
|
| 86 |
-
return
|
| 87 |
-
$this->writeByte(TType::STOP);
|
| 88 |
-
}
|
| 89 |
-
|
| 90 |
-
public function writeMapBegin($keyType, $valType, $size) {
|
| 91 |
-
return
|
| 92 |
-
$this->writeByte($keyType) +
|
| 93 |
-
$this->writeByte($valType) +
|
| 94 |
-
$this->writeI32($size);
|
| 95 |
-
}
|
| 96 |
-
|
| 97 |
-
public function writeMapEnd() {
|
| 98 |
-
return 0;
|
| 99 |
-
}
|
| 100 |
-
|
| 101 |
-
public function writeListBegin($elemType, $size) {
|
| 102 |
-
return
|
| 103 |
-
$this->writeByte($elemType) +
|
| 104 |
-
$this->writeI32($size);
|
| 105 |
-
}
|
| 106 |
-
|
| 107 |
-
public function writeListEnd() {
|
| 108 |
-
return 0;
|
| 109 |
-
}
|
| 110 |
-
|
| 111 |
-
public function writeSetBegin($elemType, $size) {
|
| 112 |
-
return
|
| 113 |
-
$this->writeByte($elemType) +
|
| 114 |
-
$this->writeI32($size);
|
| 115 |
-
}
|
| 116 |
-
|
| 117 |
-
public function writeSetEnd() {
|
| 118 |
-
return 0;
|
| 119 |
-
}
|
| 120 |
-
|
| 121 |
-
public function writeBool($value) {
|
| 122 |
-
$data = pack('c', $value ? 1 : 0);
|
| 123 |
-
$this->trans_->write($data, 1);
|
| 124 |
-
return 1;
|
| 125 |
-
}
|
| 126 |
-
|
| 127 |
-
public function writeByte($value) {
|
| 128 |
-
$data = pack('c', $value);
|
| 129 |
-
$this->trans_->write($data, 1);
|
| 130 |
-
return 1;
|
| 131 |
-
}
|
| 132 |
-
|
| 133 |
-
public function writeI16($value) {
|
| 134 |
-
$data = pack('n', $value);
|
| 135 |
-
$this->trans_->write($data, 2);
|
| 136 |
-
return 2;
|
| 137 |
-
}
|
| 138 |
-
|
| 139 |
-
public function writeI32($value) {
|
| 140 |
-
$data = pack('N', $value);
|
| 141 |
-
$this->trans_->write($data, 4);
|
| 142 |
-
return 4;
|
| 143 |
-
}
|
| 144 |
-
|
| 145 |
-
public function writeI64($value) {
|
| 146 |
-
// If we are on a 32bit architecture we have to explicitly deal with
|
| 147 |
-
// 64-bit twos-complement arithmetic since PHP wants to treat all ints
|
| 148 |
-
// as signed and any int over 2^31 - 1 as a float
|
| 149 |
-
if (PHP_INT_SIZE == 4) {
|
| 150 |
-
$neg = $value < 0;
|
| 151 |
-
|
| 152 |
-
if ($neg) {
|
| 153 |
-
$value *= -1;
|
| 154 |
-
}
|
| 155 |
-
|
| 156 |
-
$hi = (int)($value / 4294967296);
|
| 157 |
-
$lo = (int)$value;
|
| 158 |
-
|
| 159 |
-
if ($neg) {
|
| 160 |
-
$hi = ~$hi;
|
| 161 |
-
$lo = ~$lo;
|
| 162 |
-
if (($lo & (int)0xffffffff) == (int)0xffffffff) {
|
| 163 |
-
$lo = 0;
|
| 164 |
-
$hi++;
|
| 165 |
-
} else {
|
| 166 |
-
$lo++;
|
| 167 |
-
}
|
| 168 |
-
}
|
| 169 |
-
$data = pack('N2', $hi, $lo);
|
| 170 |
-
|
| 171 |
-
} else {
|
| 172 |
-
$hi = $value >> 32;
|
| 173 |
-
$lo = $value & 0xFFFFFFFF;
|
| 174 |
-
$data = pack('N2', $hi, $lo);
|
| 175 |
-
}
|
| 176 |
-
|
| 177 |
-
$this->trans_->write($data, 8);
|
| 178 |
-
return 8;
|
| 179 |
-
}
|
| 180 |
-
|
| 181 |
-
public function writeDouble($value) {
|
| 182 |
-
$data = pack('d', $value);
|
| 183 |
-
$this->trans_->write(strrev($data), 8);
|
| 184 |
-
return 8;
|
| 185 |
-
}
|
| 186 |
-
|
| 187 |
-
public function writeString($value) {
|
| 188 |
-
$len = TStringFuncFactory::create()->strlen($value);
|
| 189 |
-
$result = $this->writeI32($len);
|
| 190 |
-
if ($len) {
|
| 191 |
-
$this->trans_->write($value, $len);
|
| 192 |
-
}
|
| 193 |
-
return $result + $len;
|
| 194 |
-
}
|
| 195 |
-
|
| 196 |
-
public function readMessageBegin(&$name, &$type, &$seqid) {
|
| 197 |
-
$result = $this->readI32($sz);
|
| 198 |
-
if ($sz < 0) {
|
| 199 |
-
$version = (int) ($sz & self::VERSION_MASK);
|
| 200 |
-
if ($version != (int) self::VERSION_1) {
|
| 201 |
-
throw new TProtocolException('Bad version identifier: '.$sz, TProtocolException::BAD_VERSION);
|
| 202 |
-
}
|
| 203 |
-
$type = $sz & 0x000000ff;
|
| 204 |
-
$result +=
|
| 205 |
-
$this->readString($name) +
|
| 206 |
-
$this->readI32($seqid);
|
| 207 |
-
} else {
|
| 208 |
-
if ($this->strictRead_) {
|
| 209 |
-
throw new TProtocolException('No version identifier, old protocol client?', TProtocolException::BAD_VERSION);
|
| 210 |
-
} else {
|
| 211 |
-
// Handle pre-versioned input
|
| 212 |
-
$name = $this->trans_->readAll($sz);
|
| 213 |
-
$result +=
|
| 214 |
-
$sz +
|
| 215 |
-
$this->readByte($type) +
|
| 216 |
-
$this->readI32($seqid);
|
| 217 |
-
}
|
| 218 |
-
}
|
| 219 |
-
return $result;
|
| 220 |
-
}
|
| 221 |
-
|
| 222 |
-
public function readMessageEnd() {
|
| 223 |
-
return 0;
|
| 224 |
-
}
|
| 225 |
-
|
| 226 |
-
public function readStructBegin(&$name) {
|
| 227 |
-
$name = '';
|
| 228 |
-
return 0;
|
| 229 |
-
}
|
| 230 |
-
|
| 231 |
-
public function readStructEnd() {
|
| 232 |
-
return 0;
|
| 233 |
-
}
|
| 234 |
-
|
| 235 |
-
public function readFieldBegin(&$name, &$fieldType, &$fieldId) {
|
| 236 |
-
$result = $this->readByte($fieldType);
|
| 237 |
-
if ($fieldType == TType::STOP) {
|
| 238 |
-
$fieldId = 0;
|
| 239 |
-
return $result;
|
| 240 |
-
}
|
| 241 |
-
$result += $this->readI16($fieldId);
|
| 242 |
-
return $result;
|
| 243 |
-
}
|
| 244 |
-
|
| 245 |
-
public function readFieldEnd() {
|
| 246 |
-
return 0;
|
| 247 |
-
}
|
| 248 |
-
|
| 249 |
-
public function readMapBegin(&$keyType, &$valType, &$size) {
|
| 250 |
-
return
|
| 251 |
-
$this->readByte($keyType) +
|
| 252 |
-
$this->readByte($valType) +
|
| 253 |
-
$this->readI32($size);
|
| 254 |
-
}
|
| 255 |
-
|
| 256 |
-
public function readMapEnd() {
|
| 257 |
-
return 0;
|
| 258 |
-
}
|
| 259 |
-
|
| 260 |
-
public function readListBegin(&$elemType, &$size) {
|
| 261 |
-
return
|
| 262 |
-
$this->readByte($elemType) +
|
| 263 |
-
$this->readI32($size);
|
| 264 |
-
}
|
| 265 |
-
|
| 266 |
-
public function readListEnd() {
|
| 267 |
-
return 0;
|
| 268 |
-
}
|
| 269 |
-
|
| 270 |
-
public function readSetBegin(&$elemType, &$size) {
|
| 271 |
-
return
|
| 272 |
-
$this->readByte($elemType) +
|
| 273 |
-
$this->readI32($size);
|
| 274 |
-
}
|
| 275 |
-
|
| 276 |
-
public function readSetEnd() {
|
| 277 |
-
return 0;
|
| 278 |
-
}
|
| 279 |
-
|
| 280 |
-
public function readBool(&$value) {
|
| 281 |
-
$data = $this->trans_->readAll(1);
|
| 282 |
-
$arr = unpack('c', $data);
|
| 283 |
-
$value = $arr[1] == 1;
|
| 284 |
-
return 1;
|
| 285 |
-
}
|
| 286 |
-
|
| 287 |
-
public function readByte(&$value) {
|
| 288 |
-
$data = $this->trans_->readAll(1);
|
| 289 |
-
$arr = unpack('c', $data);
|
| 290 |
-
$value = $arr[1];
|
| 291 |
-
return 1;
|
| 292 |
-
}
|
| 293 |
-
|
| 294 |
-
public function readI16(&$value) {
|
| 295 |
-
$data = $this->trans_->readAll(2);
|
| 296 |
-
$arr = unpack('n', $data);
|
| 297 |
-
$value = $arr[1];
|
| 298 |
-
if ($value > 0x7fff) {
|
| 299 |
-
$value = 0 - (($value - 1) ^ 0xffff);
|
| 300 |
-
}
|
| 301 |
-
return 2;
|
| 302 |
-
}
|
| 303 |
-
|
| 304 |
-
public function readI32(&$value) {
|
| 305 |
-
$data = $this->trans_->readAll(4);
|
| 306 |
-
$arr = unpack('N', $data);
|
| 307 |
-
$value = $arr[1];
|
| 308 |
-
if ($value > 0x7fffffff) {
|
| 309 |
-
$value = 0 - (($value - 1) ^ 0xffffffff);
|
| 310 |
-
}
|
| 311 |
-
return 4;
|
| 312 |
-
}
|
| 313 |
-
|
| 314 |
-
public function readI64(&$value) {
|
| 315 |
-
$data = $this->trans_->readAll(8);
|
| 316 |
-
|
| 317 |
-
$arr = unpack('N2', $data);
|
| 318 |
-
|
| 319 |
-
// If we are on a 32bit architecture we have to explicitly deal with
|
| 320 |
-
// 64-bit twos-complement arithmetic since PHP wants to treat all ints
|
| 321 |
-
// as signed and any int over 2^31 - 1 as a float
|
| 322 |
-
if (PHP_INT_SIZE == 4) {
|
| 323 |
-
|
| 324 |
-
$hi = $arr[1];
|
| 325 |
-
$lo = $arr[2];
|
| 326 |
-
$isNeg = $hi < 0;
|
| 327 |
-
|
| 328 |
-
// Check for a negative
|
| 329 |
-
if ($isNeg) {
|
| 330 |
-
$hi = ~$hi & (int)0xffffffff;
|
| 331 |
-
$lo = ~$lo & (int)0xffffffff;
|
| 332 |
-
|
| 333 |
-
if ($lo == (int)0xffffffff) {
|
| 334 |
-
$hi++;
|
| 335 |
-
$lo = 0;
|
| 336 |
-
} else {
|
| 337 |
-
$lo++;
|
| 338 |
-
}
|
| 339 |
-
}
|
| 340 |
-
|
| 341 |
-
// Force 32bit words in excess of 2G to pe positive - we deal wigh sign
|
| 342 |
-
// explicitly below
|
| 343 |
-
|
| 344 |
-
if ($hi & (int)0x80000000) {
|
| 345 |
-
$hi &= (int)0x7fffffff;
|
| 346 |
-
$hi += 0x80000000;
|
| 347 |
-
}
|
| 348 |
-
|
| 349 |
-
if ($lo & (int)0x80000000) {
|
| 350 |
-
$lo &= (int)0x7fffffff;
|
| 351 |
-
$lo += 0x80000000;
|
| 352 |
-
}
|
| 353 |
-
|
| 354 |
-
$value = $hi * 4294967296 + $lo;
|
| 355 |
-
|
| 356 |
-
if ($isNeg) {
|
| 357 |
-
$value = 0 - $value;
|
| 358 |
-
}
|
| 359 |
-
} else {
|
| 360 |
-
|
| 361 |
-
// Upcast negatives in LSB bit
|
| 362 |
-
if ($arr[2] & 0x80000000) {
|
| 363 |
-
$arr[2] = $arr[2] & 0xffffffff;
|
| 364 |
-
}
|
| 365 |
-
|
| 366 |
-
// Check for a negative
|
| 367 |
-
if ($arr[1] & 0x80000000) {
|
| 368 |
-
$arr[1] = $arr[1] & 0xffffffff;
|
| 369 |
-
$arr[1] = $arr[1] ^ 0xffffffff;
|
| 370 |
-
$arr[2] = $arr[2] ^ 0xffffffff;
|
| 371 |
-
$value = 0 - $arr[1]*4294967296 - $arr[2] - 1;
|
| 372 |
-
} else {
|
| 373 |
-
$value = $arr[1]*4294967296 + $arr[2];
|
| 374 |
-
}
|
| 375 |
-
}
|
| 376 |
-
|
| 377 |
-
return 8;
|
| 378 |
-
}
|
| 379 |
-
|
| 380 |
-
public function readDouble(&$value) {
|
| 381 |
-
$data = strrev($this->trans_->readAll(8));
|
| 382 |
-
$arr = unpack('d', $data);
|
| 383 |
-
$value = $arr[1];
|
| 384 |
-
return 8;
|
| 385 |
-
}
|
| 386 |
-
|
| 387 |
-
public function readString(&$value) {
|
| 388 |
-
$result = $this->readI32($len);
|
| 389 |
-
if ($len) {
|
| 390 |
-
$value = $this->trans_->readAll($len);
|
| 391 |
-
} else {
|
| 392 |
-
$value = '';
|
| 393 |
-
}
|
| 394 |
-
return $result + $len;
|
| 395 |
-
}
|
| 396 |
-
}
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Licensed to the Apache Software Foundation (ASF) under one
|
| 4 |
+
* or more contributor license agreements. See the NOTICE file
|
| 5 |
+
* distributed with this work for additional information
|
| 6 |
+
* regarding copyright ownership. The ASF licenses this file
|
| 7 |
+
* to you under the Apache License, Version 2.0 (the
|
| 8 |
+
* "License"); you may not use this file except in compliance
|
| 9 |
+
* with the License. You may obtain a copy of the License at
|
| 10 |
+
*
|
| 11 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
+
*
|
| 13 |
+
* Unless required by applicable law or agreed to in writing,
|
| 14 |
+
* software distributed under the License is distributed on an
|
| 15 |
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 16 |
+
* KIND, either express or implied. See the License for the
|
| 17 |
+
* specific language governing permissions and limitations
|
| 18 |
+
* under the License.
|
| 19 |
+
*
|
| 20 |
+
* @package thrift.protocol
|
| 21 |
+
*/
|
| 22 |
+
|
| 23 |
+
namespace Thrift\Protocol;
|
| 24 |
+
|
| 25 |
+
use Thrift\Protocol\TProtocol;
|
| 26 |
+
use Thrift\Type\TType;
|
| 27 |
+
use Thrift\Exception\TProtocolException;
|
| 28 |
+
use Thrift\Factory\TStringFuncFactory;
|
| 29 |
+
|
| 30 |
+
/**
|
| 31 |
+
* Binary implementation of the Thrift protocol.
|
| 32 |
+
*
|
| 33 |
+
*/
|
| 34 |
+
class TBinaryProtocol extends TProtocol {
|
| 35 |
+
|
| 36 |
+
const VERSION_MASK = 0xffff0000;
|
| 37 |
+
const VERSION_1 = 0x80010000;
|
| 38 |
+
|
| 39 |
+
protected $strictRead_ = false;
|
| 40 |
+
protected $strictWrite_ = true;
|
| 41 |
+
|
| 42 |
+
public function __construct($trans, $strictRead=false, $strictWrite=true) {
|
| 43 |
+
parent::__construct($trans);
|
| 44 |
+
$this->strictRead_ = $strictRead;
|
| 45 |
+
$this->strictWrite_ = $strictWrite;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
public function writeMessageBegin($name, $type, $seqid) {
|
| 49 |
+
if ($this->strictWrite_) {
|
| 50 |
+
$version = self::VERSION_1 | $type;
|
| 51 |
+
return
|
| 52 |
+
$this->writeI32($version) +
|
| 53 |
+
$this->writeString($name) +
|
| 54 |
+
$this->writeI32($seqid);
|
| 55 |
+
} else {
|
| 56 |
+
return
|
| 57 |
+
$this->writeString($name) +
|
| 58 |
+
$this->writeByte($type) +
|
| 59 |
+
$this->writeI32($seqid);
|
| 60 |
+
}
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
public function writeMessageEnd() {
|
| 64 |
+
return 0;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
public function writeStructBegin($name) {
|
| 68 |
+
return 0;
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
public function writeStructEnd() {
|
| 72 |
+
return 0;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
public function writeFieldBegin($fieldName, $fieldType, $fieldId) {
|
| 76 |
+
return
|
| 77 |
+
$this->writeByte($fieldType) +
|
| 78 |
+
$this->writeI16($fieldId);
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
public function writeFieldEnd() {
|
| 82 |
+
return 0;
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
public function writeFieldStop() {
|
| 86 |
+
return
|
| 87 |
+
$this->writeByte(TType::STOP);
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
public function writeMapBegin($keyType, $valType, $size) {
|
| 91 |
+
return
|
| 92 |
+
$this->writeByte($keyType) +
|
| 93 |
+
$this->writeByte($valType) +
|
| 94 |
+
$this->writeI32($size);
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
public function writeMapEnd() {
|
| 98 |
+
return 0;
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
public function writeListBegin($elemType, $size) {
|
| 102 |
+
return
|
| 103 |
+
$this->writeByte($elemType) +
|
| 104 |
+
$this->writeI32($size);
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
public function writeListEnd() {
|
| 108 |
+
return 0;
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
public function writeSetBegin($elemType, $size) {
|
| 112 |
+
return
|
| 113 |
+
$this->writeByte($elemType) +
|
| 114 |
+
$this->writeI32($size);
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
public function writeSetEnd() {
|
| 118 |
+
return 0;
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
public function writeBool($value) {
|
| 122 |
+
$data = pack('c', $value ? 1 : 0);
|
| 123 |
+
$this->trans_->write($data, 1);
|
| 124 |
+
return 1;
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
public function writeByte($value) {
|
| 128 |
+
$data = pack('c', $value);
|
| 129 |
+
$this->trans_->write($data, 1);
|
| 130 |
+
return 1;
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
public function writeI16($value) {
|
| 134 |
+
$data = pack('n', $value);
|
| 135 |
+
$this->trans_->write($data, 2);
|
| 136 |
+
return 2;
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
public function writeI32($value) {
|
| 140 |
+
$data = pack('N', $value);
|
| 141 |
+
$this->trans_->write($data, 4);
|
| 142 |
+
return 4;
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
public function writeI64($value) {
|
| 146 |
+
// If we are on a 32bit architecture we have to explicitly deal with
|
| 147 |
+
// 64-bit twos-complement arithmetic since PHP wants to treat all ints
|
| 148 |
+
// as signed and any int over 2^31 - 1 as a float
|
| 149 |
+
if (PHP_INT_SIZE == 4) {
|
| 150 |
+
$neg = $value < 0;
|
| 151 |
+
|
| 152 |
+
if ($neg) {
|
| 153 |
+
$value *= -1;
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
$hi = (int)($value / 4294967296);
|
| 157 |
+
$lo = (int)$value;
|
| 158 |
+
|
| 159 |
+
if ($neg) {
|
| 160 |
+
$hi = ~$hi;
|
| 161 |
+
$lo = ~$lo;
|
| 162 |
+
if (($lo & (int)0xffffffff) == (int)0xffffffff) {
|
| 163 |
+
$lo = 0;
|
| 164 |
+
$hi++;
|
| 165 |
+
} else {
|
| 166 |
+
$lo++;
|
| 167 |
+
}
|
| 168 |
+
}
|
| 169 |
+
$data = pack('N2', $hi, $lo);
|
| 170 |
+
|
| 171 |
+
} else {
|
| 172 |
+
$hi = $value >> 32;
|
| 173 |
+
$lo = $value & 0xFFFFFFFF;
|
| 174 |
+
$data = pack('N2', $hi, $lo);
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
$this->trans_->write($data, 8);
|
| 178 |
+
return 8;
|
| 179 |
+
}
|
| 180 |
+
|
| 181 |
+
public function writeDouble($value) {
|
| 182 |
+
$data = pack('d', $value);
|
| 183 |
+
$this->trans_->write(strrev($data), 8);
|
| 184 |
+
return 8;
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
public function writeString($value) {
|
| 188 |
+
$len = TStringFuncFactory::create()->strlen($value);
|
| 189 |
+
$result = $this->writeI32($len);
|
| 190 |
+
if ($len) {
|
| 191 |
+
$this->trans_->write($value, $len);
|
| 192 |
+
}
|
| 193 |
+
return $result + $len;
|
| 194 |
+
}
|
| 195 |
+
|
| 196 |
+
public function readMessageBegin(&$name, &$type, &$seqid) {
|
| 197 |
+
$result = $this->readI32($sz);
|
| 198 |
+
if ($sz < 0) {
|
| 199 |
+
$version = (int) ($sz & self::VERSION_MASK);
|
| 200 |
+
if ($version != (int) self::VERSION_1) {
|
| 201 |
+
throw new TProtocolException('Bad version identifier: '.$sz, TProtocolException::BAD_VERSION);
|
| 202 |
+
}
|
| 203 |
+
$type = $sz & 0x000000ff;
|
| 204 |
+
$result +=
|
| 205 |
+
$this->readString($name) +
|
| 206 |
+
$this->readI32($seqid);
|
| 207 |
+
} else {
|
| 208 |
+
if ($this->strictRead_) {
|
| 209 |
+
throw new TProtocolException('No version identifier, old protocol client?', TProtocolException::BAD_VERSION);
|
| 210 |
+
} else {
|
| 211 |
+
// Handle pre-versioned input
|
| 212 |
+
$name = $this->trans_->readAll($sz);
|
| 213 |
+
$result +=
|
| 214 |
+
$sz +
|
| 215 |
+
$this->readByte($type) +
|
| 216 |
+
$this->readI32($seqid);
|
| 217 |
+
}
|
| 218 |
+
}
|
| 219 |
+
return $result;
|
| 220 |
+
}
|
| 221 |
+
|
| 222 |
+
public function readMessageEnd() {
|
| 223 |
+
return 0;
|
| 224 |
+
}
|
| 225 |
+
|
| 226 |
+
public function readStructBegin(&$name) {
|
| 227 |
+
$name = '';
|
| 228 |
+
return 0;
|
| 229 |
+
}
|
| 230 |
+
|
| 231 |
+
public function readStructEnd() {
|
| 232 |
+
return 0;
|
| 233 |
+
}
|
| 234 |
+
|
| 235 |
+
public function readFieldBegin(&$name, &$fieldType, &$fieldId) {
|
| 236 |
+
$result = $this->readByte($fieldType);
|
| 237 |
+
if ($fieldType == TType::STOP) {
|
| 238 |
+
$fieldId = 0;
|
| 239 |
+
return $result;
|
| 240 |
+
}
|
| 241 |
+
$result += $this->readI16($fieldId);
|
| 242 |
+
return $result;
|
| 243 |
+
}
|
| 244 |
+
|
| 245 |
+
public function readFieldEnd() {
|
| 246 |
+
return 0;
|
| 247 |
+
}
|
| 248 |
+
|
| 249 |
+
public function readMapBegin(&$keyType, &$valType, &$size) {
|
| 250 |
+
return
|
| 251 |
+
$this->readByte($keyType) +
|
| 252 |
+
$this->readByte($valType) +
|
| 253 |
+
$this->readI32($size);
|
| 254 |
+
}
|
| 255 |
+
|
| 256 |
+
public function readMapEnd() {
|
| 257 |
+
return 0;
|
| 258 |
+
}
|
| 259 |
+
|
| 260 |
+
public function readListBegin(&$elemType, &$size) {
|
| 261 |
+
return
|
| 262 |
+
$this->readByte($elemType) +
|
| 263 |
+
$this->readI32($size);
|
| 264 |
+
}
|
| 265 |
+
|
| 266 |
+
public function readListEnd() {
|
| 267 |
+
return 0;
|
| 268 |
+
}
|
| 269 |
+
|
| 270 |
+
public function readSetBegin(&$elemType, &$size) {
|
| 271 |
+
return
|
| 272 |
+
$this->readByte($elemType) +
|
| 273 |
+
$this->readI32($size);
|
| 274 |
+
}
|
| 275 |
+
|
| 276 |
+
public function readSetEnd() {
|
| 277 |
+
return 0;
|
| 278 |
+
}
|
| 279 |
+
|
| 280 |
+
public function readBool(&$value) {
|
| 281 |
+
$data = $this->trans_->readAll(1);
|
| 282 |
+
$arr = unpack('c', $data);
|
| 283 |
+
$value = $arr[1] == 1;
|
| 284 |
+
return 1;
|
| 285 |
+
}
|
| 286 |
+
|
| 287 |
+
public function readByte(&$value) {
|
| 288 |
+
$data = $this->trans_->readAll(1);
|
| 289 |
+
$arr = unpack('c', $data);
|
| 290 |
+
$value = $arr[1];
|
| 291 |
+
return 1;
|
| 292 |
+
}
|
| 293 |
+
|
| 294 |
+
public function readI16(&$value) {
|
| 295 |
+
$data = $this->trans_->readAll(2);
|
| 296 |
+
$arr = unpack('n', $data);
|
| 297 |
+
$value = $arr[1];
|
| 298 |
+
if ($value > 0x7fff) {
|
| 299 |
+
$value = 0 - (($value - 1) ^ 0xffff);
|
| 300 |
+
}
|
| 301 |
+
return 2;
|
| 302 |
+
}
|
| 303 |
+
|
| 304 |
+
public function readI32(&$value) {
|
| 305 |
+
$data = $this->trans_->readAll(4);
|
| 306 |
+
$arr = unpack('N', $data);
|
| 307 |
+
$value = $arr[1];
|
| 308 |
+
if ($value > 0x7fffffff) {
|
| 309 |
+
$value = 0 - (($value - 1) ^ 0xffffffff);
|
| 310 |
+
}
|
| 311 |
+
return 4;
|
| 312 |
+
}
|
| 313 |
+
|
| 314 |
+
public function readI64(&$value) {
|
| 315 |
+
$data = $this->trans_->readAll(8);
|
| 316 |
+
|
| 317 |
+
$arr = unpack('N2', $data);
|
| 318 |
+
|
| 319 |
+
// If we are on a 32bit architecture we have to explicitly deal with
|
| 320 |
+
// 64-bit twos-complement arithmetic since PHP wants to treat all ints
|
| 321 |
+
// as signed and any int over 2^31 - 1 as a float
|
| 322 |
+
if (PHP_INT_SIZE == 4) {
|
| 323 |
+
|
| 324 |
+
$hi = $arr[1];
|
| 325 |
+
$lo = $arr[2];
|
| 326 |
+
$isNeg = $hi < 0;
|
| 327 |
+
|
| 328 |
+
// Check for a negative
|
| 329 |
+
if ($isNeg) {
|
| 330 |
+
$hi = ~$hi & (int)0xffffffff;
|
| 331 |
+
$lo = ~$lo & (int)0xffffffff;
|
| 332 |
+
|
| 333 |
+
if ($lo == (int)0xffffffff) {
|
| 334 |
+
$hi++;
|
| 335 |
+
$lo = 0;
|
| 336 |
+
} else {
|
| 337 |
+
$lo++;
|
| 338 |
+
}
|
| 339 |
+
}
|
| 340 |
+
|
| 341 |
+
// Force 32bit words in excess of 2G to pe positive - we deal wigh sign
|
| 342 |
+
// explicitly below
|
| 343 |
+
|
| 344 |
+
if ($hi & (int)0x80000000) {
|
| 345 |
+
$hi &= (int)0x7fffffff;
|
| 346 |
+
$hi += 0x80000000;
|
| 347 |
+
}
|
| 348 |
+
|
| 349 |
+
if ($lo & (int)0x80000000) {
|
| 350 |
+
$lo &= (int)0x7fffffff;
|
| 351 |
+
$lo += 0x80000000;
|
| 352 |
+
}
|
| 353 |
+
|
| 354 |
+
$value = $hi * 4294967296 + $lo;
|
| 355 |
+
|
| 356 |
+
if ($isNeg) {
|
| 357 |
+
$value = 0 - $value;
|
| 358 |
+
}
|
| 359 |
+
} else {
|
| 360 |
+
|
| 361 |
+
// Upcast negatives in LSB bit
|
| 362 |
+
if ($arr[2] & 0x80000000) {
|
| 363 |
+
$arr[2] = $arr[2] & 0xffffffff;
|
| 364 |
+
}
|
| 365 |
+
|
| 366 |
+
// Check for a negative
|
| 367 |
+
if ($arr[1] & 0x80000000) {
|
| 368 |
+
$arr[1] = $arr[1] & 0xffffffff;
|
| 369 |
+
$arr[1] = $arr[1] ^ 0xffffffff;
|
| 370 |
+
$arr[2] = $arr[2] ^ 0xffffffff;
|
| 371 |
+
$value = 0 - $arr[1]*4294967296 - $arr[2] - 1;
|
| 372 |
+
} else {
|
| 373 |
+
$value = $arr[1]*4294967296 + $arr[2];
|
| 374 |
+
}
|
| 375 |
+
}
|
| 376 |
+
|
| 377 |
+
return 8;
|
| 378 |
+
}
|
| 379 |
+
|
| 380 |
+
public function readDouble(&$value) {
|
| 381 |
+
$data = strrev($this->trans_->readAll(8));
|
| 382 |
+
$arr = unpack('d', $data);
|
| 383 |
+
$value = $arr[1];
|
| 384 |
+
return 8;
|
| 385 |
+
}
|
| 386 |
+
|
| 387 |
+
public function readString(&$value) {
|
| 388 |
+
$result = $this->readI32($len);
|
| 389 |
+
if ($len) {
|
| 390 |
+
$value = $this->trans_->readAll($len);
|
| 391 |
+
} else {
|
| 392 |
+
$value = '';
|
| 393 |
+
}
|
| 394 |
+
return $result + $len;
|
| 395 |
+
}
|
| 396 |
+
}
|
app/code/community/Boxalino/{CemSearch/Lib/vendor → Intelligence/lib}/Thrift/Protocol/TBinaryProtocolAccelerated.php
RENAMED
|
@@ -1,47 +1,47 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
/*
|
| 3 |
-
* Licensed to the Apache Software Foundation (ASF) under one
|
| 4 |
-
* or more contributor license agreements. See the NOTICE file
|
| 5 |
-
* distributed with this work for additional information
|
| 6 |
-
* regarding copyright ownership. The ASF licenses this file
|
| 7 |
-
* to you under the Apache License, Version 2.0 (the
|
| 8 |
-
* "License"); you may not use this file except in compliance
|
| 9 |
-
* with the License. You may obtain a copy of the License at
|
| 10 |
-
*
|
| 11 |
-
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
-
*
|
| 13 |
-
* Unless required by applicable law or agreed to in writing,
|
| 14 |
-
* software distributed under the License is distributed on an
|
| 15 |
-
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 16 |
-
* KIND, either express or implied. See the License for the
|
| 17 |
-
* specific language governing permissions and limitations
|
| 18 |
-
* under the License.
|
| 19 |
-
*
|
| 20 |
-
* @package thrift.protocol
|
| 21 |
-
*/
|
| 22 |
-
|
| 23 |
-
namespace Thrift\Protocol;
|
| 24 |
-
|
| 25 |
-
use Thrift\Protocol\TBinaryProtocol;
|
| 26 |
-
use Thrift\Transport\TBufferedTransport;
|
| 27 |
-
|
| 28 |
-
/**
|
| 29 |
-
* Accelerated binary protocol: used in conjunction with the thrift_protocol
|
| 30 |
-
* extension for faster deserialization
|
| 31 |
-
*/
|
| 32 |
-
class TBinaryProtocolAccelerated extends TBinaryProtocol {
|
| 33 |
-
public function __construct($trans, $strictRead=false, $strictWrite=true) {
|
| 34 |
-
// If the transport doesn't implement putBack, wrap it in a
|
| 35 |
-
// TBufferedTransport (which does)
|
| 36 |
-
if (!method_exists($trans, 'putBack')) {
|
| 37 |
-
$trans = new TBufferedTransport($trans);
|
| 38 |
-
}
|
| 39 |
-
parent::__construct($trans, $strictRead, $strictWrite);
|
| 40 |
-
}
|
| 41 |
-
public function isStrictRead() {
|
| 42 |
-
return $this->strictRead_;
|
| 43 |
-
}
|
| 44 |
-
public function isStrictWrite() {
|
| 45 |
-
return $this->strictWrite_;
|
| 46 |
-
}
|
| 47 |
}
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Licensed to the Apache Software Foundation (ASF) under one
|
| 4 |
+
* or more contributor license agreements. See the NOTICE file
|
| 5 |
+
* distributed with this work for additional information
|
| 6 |
+
* regarding copyright ownership. The ASF licenses this file
|
| 7 |
+
* to you under the Apache License, Version 2.0 (the
|
| 8 |
+
* "License"); you may not use this file except in compliance
|
| 9 |
+
* with the License. You may obtain a copy of the License at
|
| 10 |
+
*
|
| 11 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
+
*
|
| 13 |
+
* Unless required by applicable law or agreed to in writing,
|
| 14 |
+
* software distributed under the License is distributed on an
|
| 15 |
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 16 |
+
* KIND, either express or implied. See the License for the
|
| 17 |
+
* specific language governing permissions and limitations
|
| 18 |
+
* under the License.
|
| 19 |
+
*
|
| 20 |
+
* @package thrift.protocol
|
| 21 |
+
*/
|
| 22 |
+
|
| 23 |
+
namespace Thrift\Protocol;
|
| 24 |
+
|
| 25 |
+
use Thrift\Protocol\TBinaryProtocol;
|
| 26 |
+
use Thrift\Transport\TBufferedTransport;
|
| 27 |
+
|
| 28 |
+
/**
|
| 29 |
+
* Accelerated binary protocol: used in conjunction with the thrift_protocol
|
| 30 |
+
* extension for faster deserialization
|
| 31 |
+
*/
|
| 32 |
+
class TBinaryProtocolAccelerated extends TBinaryProtocol {
|
| 33 |
+
public function __construct($trans, $strictRead=false, $strictWrite=true) {
|
| 34 |
+
// If the transport doesn't implement putBack, wrap it in a
|
| 35 |
+
// TBufferedTransport (which does)
|
| 36 |
+
if (!method_exists($trans, 'putBack')) {
|
| 37 |
+
$trans = new TBufferedTransport($trans);
|
| 38 |
+
}
|
| 39 |
+
parent::__construct($trans, $strictRead, $strictWrite);
|
| 40 |
+
}
|
| 41 |
+
public function isStrictRead() {
|
| 42 |
+
return $this->strictRead_;
|
| 43 |
+
}
|
| 44 |
+
public function isStrictWrite() {
|
| 45 |
+
return $this->strictWrite_;
|
| 46 |
+
}
|
| 47 |
}
|
app/code/community/Boxalino/{CemSearch/Lib/vendor → Intelligence/lib}/Thrift/Protocol/TCompactProtocol.php
RENAMED
|
@@ -1,670 +1,670 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
/*
|
| 3 |
-
* Licensed to the Apache Software Foundation (ASF) under one
|
| 4 |
-
* or more contributor license agreements. See the NOTICE file
|
| 5 |
-
* distributed with this work for additional information
|
| 6 |
-
* regarding copyright ownership. The ASF licenses this file
|
| 7 |
-
* to you under the Apache License, Version 2.0 (the
|
| 8 |
-
* "License"); you may not use this file except in compliance
|
| 9 |
-
* with the License. You may obtain a copy of the License at
|
| 10 |
-
*
|
| 11 |
-
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
-
*
|
| 13 |
-
* Unless required by applicable law or agreed to in writing,
|
| 14 |
-
* software distributed under the License is distributed on an
|
| 15 |
-
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 16 |
-
* KIND, either express or implied. See the License for the
|
| 17 |
-
* specific language governing permissions and limitations
|
| 18 |
-
* under the License.
|
| 19 |
-
*
|
| 20 |
-
* @package thrift.protocol
|
| 21 |
-
*/
|
| 22 |
-
|
| 23 |
-
namespace Thrift\Protocol;
|
| 24 |
-
|
| 25 |
-
use Thrift\Protocol\TProtocol;
|
| 26 |
-
use Thrift\Type\TType;
|
| 27 |
-
use Thrift\Exception\TProtocolException;
|
| 28 |
-
use Thrift\Factory\TStringFuncFactory;
|
| 29 |
-
|
| 30 |
-
/**
|
| 31 |
-
* Compact implementation of the Thrift protocol.
|
| 32 |
-
*
|
| 33 |
-
*/
|
| 34 |
-
class TCompactProtocol extends TProtocol {
|
| 35 |
-
|
| 36 |
-
const COMPACT_STOP = 0x00;
|
| 37 |
-
const COMPACT_TRUE = 0x01;
|
| 38 |
-
const COMPACT_FALSE = 0x02;
|
| 39 |
-
const COMPACT_BYTE = 0x03;
|
| 40 |
-
const COMPACT_I16 = 0x04;
|
| 41 |
-
const COMPACT_I32 = 0x05;
|
| 42 |
-
const COMPACT_I64 = 0x06;
|
| 43 |
-
const COMPACT_DOUBLE = 0x07;
|
| 44 |
-
const COMPACT_BINARY = 0x08;
|
| 45 |
-
const COMPACT_LIST = 0x09;
|
| 46 |
-
const COMPACT_SET = 0x0A;
|
| 47 |
-
const COMPACT_MAP = 0x0B;
|
| 48 |
-
const COMPACT_STRUCT = 0x0C;
|
| 49 |
-
|
| 50 |
-
const STATE_CLEAR = 0;
|
| 51 |
-
const STATE_FIELD_WRITE = 1;
|
| 52 |
-
const STATE_VALUE_WRITE = 2;
|
| 53 |
-
const STATE_CONTAINER_WRITE = 3;
|
| 54 |
-
const STATE_BOOL_WRITE = 4;
|
| 55 |
-
const STATE_FIELD_READ = 5;
|
| 56 |
-
const STATE_CONTAINER_READ = 6;
|
| 57 |
-
const STATE_VALUE_READ = 7;
|
| 58 |
-
const STATE_BOOL_READ = 8;
|
| 59 |
-
|
| 60 |
-
const VERSION_MASK = 0x1f;
|
| 61 |
-
const VERSION = 1;
|
| 62 |
-
const PROTOCOL_ID = 0x82;
|
| 63 |
-
const TYPE_MASK = 0xe0;
|
| 64 |
-
const TYPE_SHIFT_AMOUNT = 5;
|
| 65 |
-
|
| 66 |
-
protected static $ctypes = array(
|
| 67 |
-
TType::STOP => TCompactProtocol::COMPACT_STOP,
|
| 68 |
-
TType::BOOL => TCompactProtocol::COMPACT_TRUE, // used for collection
|
| 69 |
-
TType::BYTE => TCompactProtocol::COMPACT_BYTE,
|
| 70 |
-
TType::I16 => TCompactProtocol::COMPACT_I16,
|
| 71 |
-
TType::I32 => TCompactProtocol::COMPACT_I32,
|
| 72 |
-
TType::I64 => TCompactProtocol::COMPACT_I64,
|
| 73 |
-
TType::DOUBLE => TCompactProtocol::COMPACT_DOUBLE,
|
| 74 |
-
TType::STRING => TCompactProtocol::COMPACT_BINARY,
|
| 75 |
-
TType::STRUCT => TCompactProtocol::COMPACT_STRUCT,
|
| 76 |
-
TType::LST => TCompactProtocol::COMPACT_LIST,
|
| 77 |
-
TType::SET => TCompactProtocol::COMPACT_SET,
|
| 78 |
-
TType::MAP => TCompactProtocol::COMPACT_MAP,
|
| 79 |
-
);
|
| 80 |
-
|
| 81 |
-
protected static $ttypes = array(
|
| 82 |
-
TCompactProtocol::COMPACT_STOP => TType::STOP ,
|
| 83 |
-
TCompactProtocol::COMPACT_TRUE => TType::BOOL, // used for collection
|
| 84 |
-
TCompactProtocol::COMPACT_FALSE => TType::BOOL,
|
| 85 |
-
TCompactProtocol::COMPACT_BYTE => TType::BYTE,
|
| 86 |
-
TCompactProtocol::COMPACT_I16 => TType::I16,
|
| 87 |
-
TCompactProtocol::COMPACT_I32 => TType::I32,
|
| 88 |
-
TCompactProtocol::COMPACT_I64 => TType::I64,
|
| 89 |
-
TCompactProtocol::COMPACT_DOUBLE => TType::DOUBLE,
|
| 90 |
-
TCompactProtocol::COMPACT_BINARY => TType::STRING,
|
| 91 |
-
TCompactProtocol::COMPACT_STRUCT => TType::STRUCT,
|
| 92 |
-
TCompactProtocol::COMPACT_LIST => TType::LST,
|
| 93 |
-
TCompactProtocol::COMPACT_SET => TType::SET,
|
| 94 |
-
TCompactProtocol::COMPACT_MAP => TType::MAP,
|
| 95 |
-
);
|
| 96 |
-
|
| 97 |
-
protected $state = TCompactProtocol::STATE_CLEAR;
|
| 98 |
-
protected $lastFid = 0;
|
| 99 |
-
protected $boolFid = null;
|
| 100 |
-
protected $boolValue = null;
|
| 101 |
-
protected $structs = array();
|
| 102 |
-
protected $containers = array();
|
| 103 |
-
|
| 104 |
-
// Some varint / zigzag helper methods
|
| 105 |
-
public function toZigZag($n, $bits) {
|
| 106 |
-
return ($n << 1) ^ ($n >> ($bits - 1));
|
| 107 |
-
}
|
| 108 |
-
|
| 109 |
-
public function fromZigZag($n) {
|
| 110 |
-
return ($n >> 1) ^ -($n & 1);
|
| 111 |
-
}
|
| 112 |
-
|
| 113 |
-
public function getVarint($data) {
|
| 114 |
-
$out = "";
|
| 115 |
-
while (true) {
|
| 116 |
-
if (($data & ~0x7f) === 0) {
|
| 117 |
-
$out .= chr($data);
|
| 118 |
-
break;
|
| 119 |
-
} else {
|
| 120 |
-
$out .= chr(($data & 0xff) | 0x80);
|
| 121 |
-
$data = $data >> 7;
|
| 122 |
-
}
|
| 123 |
-
}
|
| 124 |
-
return $out;
|
| 125 |
-
}
|
| 126 |
-
|
| 127 |
-
public function writeVarint($data) {
|
| 128 |
-
$out = $this->getVarint($data);
|
| 129 |
-
$result = TStringFuncFactory::create()->strlen($out);
|
| 130 |
-
$this->trans_->write($out, $result);
|
| 131 |
-
return $result;
|
| 132 |
-
}
|
| 133 |
-
|
| 134 |
-
public function readVarint(&$result) {
|
| 135 |
-
$idx = 0;
|
| 136 |
-
$shift = 0;
|
| 137 |
-
$result = 0;
|
| 138 |
-
while (true) {
|
| 139 |
-
$x = $this->trans_->readAll(1);
|
| 140 |
-
$arr = unpack('C', $x);
|
| 141 |
-
$byte = $arr[1];
|
| 142 |
-
$idx += 1;
|
| 143 |
-
$result |= ($byte & 0x7f) << $shift;
|
| 144 |
-
if (($byte >> 7) === 0) {
|
| 145 |
-
return $idx;
|
| 146 |
-
}
|
| 147 |
-
$shift += 7;
|
| 148 |
-
}
|
| 149 |
-
|
| 150 |
-
return $idx;
|
| 151 |
-
}
|
| 152 |
-
|
| 153 |
-
public function __construct($trans) {
|
| 154 |
-
parent::__construct($trans);
|
| 155 |
-
}
|
| 156 |
-
|
| 157 |
-
public function writeMessageBegin($name, $type, $seqid) {
|
| 158 |
-
$written =
|
| 159 |
-
$this->writeUByte(TCompactProtocol::PROTOCOL_ID) +
|
| 160 |
-
$this->writeUByte(TCompactProtocol::VERSION |
|
| 161 |
-
($type << TCompactProtocol::TYPE_SHIFT_AMOUNT)) +
|
| 162 |
-
$this->writeVarint($seqid) +
|
| 163 |
-
$this->writeString($name);
|
| 164 |
-
$this->state = TCompactProtocol::STATE_VALUE_WRITE;
|
| 165 |
-
return $written;
|
| 166 |
-
}
|
| 167 |
-
|
| 168 |
-
public function writeMessageEnd() {
|
| 169 |
-
$this->state = TCompactProtocol::STATE_CLEAR;
|
| 170 |
-
return 0;
|
| 171 |
-
}
|
| 172 |
-
|
| 173 |
-
public function writeStructBegin($name) {
|
| 174 |
-
$this->structs[] = array($this->state, $this->lastFid);
|
| 175 |
-
$this->state = TCompactProtocol::STATE_FIELD_WRITE;
|
| 176 |
-
$this->lastFid = 0;
|
| 177 |
-
return 0;
|
| 178 |
-
}
|
| 179 |
-
|
| 180 |
-
public function writeStructEnd() {
|
| 181 |
-
$old_values = array_pop($this->structs);
|
| 182 |
-
$this->state = $old_values[0];
|
| 183 |
-
$this->lastFid = $old_values[1];
|
| 184 |
-
return 0;
|
| 185 |
-
}
|
| 186 |
-
|
| 187 |
-
public function writeFieldStop() {
|
| 188 |
-
return $this->writeByte(0);
|
| 189 |
-
}
|
| 190 |
-
|
| 191 |
-
public function writeFieldHeader($type, $fid) {
|
| 192 |
-
$written = 0;
|
| 193 |
-
$delta = $fid - $this->lastFid;
|
| 194 |
-
if (0 < $delta && $delta <= 15) {
|
| 195 |
-
$written = $this->writeUByte(($delta << 4) | $type);
|
| 196 |
-
} else {
|
| 197 |
-
$written = $this->writeByte($type) +
|
| 198 |
-
$this->writeI16($fid);
|
| 199 |
-
}
|
| 200 |
-
$this->lastFid = $fid;
|
| 201 |
-
return $written;
|
| 202 |
-
}
|
| 203 |
-
|
| 204 |
-
public function writeFieldBegin($field_name, $field_type, $field_id) {
|
| 205 |
-
if ($field_type == TTYPE::BOOL) {
|
| 206 |
-
$this->state = TCompactProtocol::STATE_BOOL_WRITE;
|
| 207 |
-
$this->boolFid = $field_id;
|
| 208 |
-
return 0;
|
| 209 |
-
} else {
|
| 210 |
-
$this->state = TCompactProtocol::STATE_VALUE_WRITE;
|
| 211 |
-
return $this->writeFieldHeader(self::$ctypes[$field_type], $field_id);
|
| 212 |
-
}
|
| 213 |
-
}
|
| 214 |
-
|
| 215 |
-
public function writeFieldEnd() {
|
| 216 |
-
$this->state = TCompactProtocol::STATE_FIELD_WRITE;
|
| 217 |
-
return 0;
|
| 218 |
-
}
|
| 219 |
-
|
| 220 |
-
public function writeCollectionBegin($etype, $size) {
|
| 221 |
-
$written = 0;
|
| 222 |
-
if ($size <= 14) {
|
| 223 |
-
$written = $this->writeUByte($size << 4 |
|
| 224 |
-
self::$ctypes[$etype]);
|
| 225 |
-
} else {
|
| 226 |
-
$written = $this->writeUByte(0xf0 |
|
| 227 |
-
self::$ctypes[$etype]) +
|
| 228 |
-
$this->writeVarint($size);
|
| 229 |
-
}
|
| 230 |
-
$this->containers[] = $this->state;
|
| 231 |
-
$this->state = TCompactProtocol::STATE_CONTAINER_WRITE;
|
| 232 |
-
|
| 233 |
-
return $written;
|
| 234 |
-
}
|
| 235 |
-
|
| 236 |
-
public function writeMapBegin($key_type, $val_type, $size) {
|
| 237 |
-
$written = 0;
|
| 238 |
-
if ($size == 0) {
|
| 239 |
-
$written = $this->writeByte(0);
|
| 240 |
-
} else {
|
| 241 |
-
$written = $this->writeVarint($size) +
|
| 242 |
-
$this->writeUByte(self::$ctypes[$key_type] << 4 |
|
| 243 |
-
self::$ctypes[$val_type]);
|
| 244 |
-
}
|
| 245 |
-
$this->containers[] = $this->state;
|
| 246 |
-
return $written;
|
| 247 |
-
}
|
| 248 |
-
|
| 249 |
-
public function writeCollectionEnd() {
|
| 250 |
-
$this->state = array_pop($this->containers);
|
| 251 |
-
return 0;
|
| 252 |
-
}
|
| 253 |
-
|
| 254 |
-
public function writeMapEnd() {
|
| 255 |
-
return $this->writeCollectionEnd();
|
| 256 |
-
}
|
| 257 |
-
|
| 258 |
-
public function writeListBegin($elem_type, $size) {
|
| 259 |
-
return $this->writeCollectionBegin($elem_type, $size);
|
| 260 |
-
}
|
| 261 |
-
|
| 262 |
-
public function writeListEnd() {
|
| 263 |
-
return $this->writeCollectionEnd();
|
| 264 |
-
}
|
| 265 |
-
|
| 266 |
-
public function writeSetBegin($elem_type, $size) {
|
| 267 |
-
return $this->writeCollectionBegin($elem_type, $size);
|
| 268 |
-
}
|
| 269 |
-
|
| 270 |
-
public function writeSetEnd() {
|
| 271 |
-
return $this->writeCollectionEnd();
|
| 272 |
-
}
|
| 273 |
-
|
| 274 |
-
public function writeBool($value) {
|
| 275 |
-
if ($this->state == TCompactProtocol::STATE_BOOL_WRITE) {
|
| 276 |
-
$ctype = TCompactProtocol::COMPACT_FALSE;
|
| 277 |
-
if ($value) {
|
| 278 |
-
$ctype = TCompactProtocol::COMPACT_TRUE;
|
| 279 |
-
}
|
| 280 |
-
return $this->writeFieldHeader($ctype, $this->boolFid);
|
| 281 |
-
} else if ($this->state == TCompactProtocol::STATE_CONTAINER_WRITE) {
|
| 282 |
-
return $this->writeByte($value ? 1 : 0);
|
| 283 |
-
} else {
|
| 284 |
-
throw new TProtocolException('Invalid state in compact protocol');
|
| 285 |
-
}
|
| 286 |
-
}
|
| 287 |
-
|
| 288 |
-
public function writeByte($value) {
|
| 289 |
-
$data = pack('c', $value);
|
| 290 |
-
$this->trans_->write($data, 1);
|
| 291 |
-
return 1;
|
| 292 |
-
}
|
| 293 |
-
|
| 294 |
-
public function writeUByte($byte) {
|
| 295 |
-
$this->trans_->write(pack('C', $byte), 1);
|
| 296 |
-
return 1;
|
| 297 |
-
}
|
| 298 |
-
|
| 299 |
-
public function writeI16($value) {
|
| 300 |
-
$thing = $this->toZigZag($value, 16);
|
| 301 |
-
return $this->writeVarint($thing);
|
| 302 |
-
}
|
| 303 |
-
|
| 304 |
-
public function writeI32($value) {
|
| 305 |
-
$thing = $this->toZigZag($value, 32);
|
| 306 |
-
return $this->writeVarint($thing);
|
| 307 |
-
}
|
| 308 |
-
|
| 309 |
-
public function writeDouble($value) {
|
| 310 |
-
$data = pack('d', $value);
|
| 311 |
-
$this->trans_->write(strrev($data), 8);
|
| 312 |
-
return 8;
|
| 313 |
-
}
|
| 314 |
-
|
| 315 |
-
public function writeString($value) {
|
| 316 |
-
$len = TStringFuncFactory::create()->strlen($value);
|
| 317 |
-
$result = $this->writeVarint($len);
|
| 318 |
-
if ($len) {
|
| 319 |
-
$this->trans_->write($value, $len);
|
| 320 |
-
}
|
| 321 |
-
return $result + $len;
|
| 322 |
-
}
|
| 323 |
-
|
| 324 |
-
public function readFieldBegin(&$name, &$field_type, &$field_id) {
|
| 325 |
-
$result = $this->readUByte($field_type);
|
| 326 |
-
|
| 327 |
-
if (($field_type & 0x0f) == TType::STOP) {
|
| 328 |
-
$field_id = 0;
|
| 329 |
-
return $result;
|
| 330 |
-
}
|
| 331 |
-
$delta = $field_type >> 4;
|
| 332 |
-
if ($delta == 0) {
|
| 333 |
-
$result += $this->readI16($field_id);
|
| 334 |
-
} else {
|
| 335 |
-
$field_id = $this->lastFid + $delta;
|
| 336 |
-
}
|
| 337 |
-
$this->lastFid = $field_id;
|
| 338 |
-
$field_type &= 0x0f;
|
| 339 |
-
if ($field_type == TCompactProtocol::COMPACT_TRUE) {
|
| 340 |
-
$this->state = TCompactProtocol::STATE_BOOL_READ;
|
| 341 |
-
$this->boolValue = true;
|
| 342 |
-
} else if ($field_type == TCompactProtocol::COMPACT_FALSE) {
|
| 343 |
-
$this->state = TCompactProtocol::STATE_BOOL_READ;
|
| 344 |
-
$this->boolValue = false;
|
| 345 |
-
} else {
|
| 346 |
-
$this->state = TCompactProtocol::STATE_VALUE_READ;
|
| 347 |
-
}
|
| 348 |
-
$field_type = $this->getTType($field_type);
|
| 349 |
-
return $result;
|
| 350 |
-
}
|
| 351 |
-
|
| 352 |
-
public function readFieldEnd() {
|
| 353 |
-
$this->state = TCompactProtocol::STATE_FIELD_READ;
|
| 354 |
-
return 0;
|
| 355 |
-
}
|
| 356 |
-
|
| 357 |
-
public function readUByte(&$value) {
|
| 358 |
-
$data = $this->trans_->readAll(1);
|
| 359 |
-
$arr = unpack('C', $data);
|
| 360 |
-
$value = $arr[1];
|
| 361 |
-
return 1;
|
| 362 |
-
}
|
| 363 |
-
|
| 364 |
-
public function readByte(&$value) {
|
| 365 |
-
$data = $this->trans_->readAll(1);
|
| 366 |
-
$arr = unpack('c', $data);
|
| 367 |
-
$value = $arr[1];
|
| 368 |
-
return 1;
|
| 369 |
-
}
|
| 370 |
-
|
| 371 |
-
public function readZigZag(&$value) {
|
| 372 |
-
$result = $this->readVarint($value);
|
| 373 |
-
$value = $this->fromZigZag($value);
|
| 374 |
-
return $result;
|
| 375 |
-
}
|
| 376 |
-
|
| 377 |
-
public function readMessageBegin(&$name, &$type, &$seqid) {
|
| 378 |
-
$protoId = 0;
|
| 379 |
-
$result = $this->readUByte($protoId);
|
| 380 |
-
if ($protoId != TCompactProtocol::PROTOCOL_ID) {
|
| 381 |
-
throw new TProtocolException('Bad protocol id in TCompact message');
|
| 382 |
-
}
|
| 383 |
-
$verType = 0;
|
| 384 |
-
$result += $this->readUByte($verType);
|
| 385 |
-
$type = ($verType & TCompactProtocol::TYPE_MASK) >>
|
| 386 |
-
TCompactProtocol::TYPE_SHIFT_AMOUNT;
|
| 387 |
-
$version = $verType & TCompactProtocol::VERSION_MASK;
|
| 388 |
-
if ($version != TCompactProtocol::VERSION) {
|
| 389 |
-
throw new TProtocolException('Bad version in TCompact message');
|
| 390 |
-
}
|
| 391 |
-
$result += $this->readVarint($seqId);
|
| 392 |
-
$name += $this->readString($name);
|
| 393 |
-
|
| 394 |
-
return $result;
|
| 395 |
-
}
|
| 396 |
-
|
| 397 |
-
public function readMessageEnd() {
|
| 398 |
-
return 0;
|
| 399 |
-
}
|
| 400 |
-
|
| 401 |
-
public function readStructBegin(&$name) {
|
| 402 |
-
$name = ''; // unused
|
| 403 |
-
$this->structs[] = array($this->state, $this->lastFid);
|
| 404 |
-
$this->state = TCompactProtocol::STATE_FIELD_READ;
|
| 405 |
-
$this->lastFid = 0;
|
| 406 |
-
return 0;
|
| 407 |
-
}
|
| 408 |
-
|
| 409 |
-
public function readStructEnd() {
|
| 410 |
-
$last = array_pop($this->structs);
|
| 411 |
-
$this->state = $last[0];
|
| 412 |
-
$this->lastFid = $last[1];
|
| 413 |
-
return 0;
|
| 414 |
-
}
|
| 415 |
-
|
| 416 |
-
public function readCollectionBegin(&$type, &$size) {
|
| 417 |
-
$sizeType = 0;
|
| 418 |
-
$result = $this->readUByte($sizeType);
|
| 419 |
-
$size = $sizeType >> 4;
|
| 420 |
-
$type = $this->getTType($sizeType);
|
| 421 |
-
if ($size == 15) {
|
| 422 |
-
$result += $this->readVarint($size);
|
| 423 |
-
}
|
| 424 |
-
$this->containers[] = $this->state;
|
| 425 |
-
$this->state = TCompactProtocol::STATE_CONTAINER_READ;
|
| 426 |
-
|
| 427 |
-
return $result;
|
| 428 |
-
}
|
| 429 |
-
|
| 430 |
-
public function readMapBegin(&$key_type, &$val_type, &$size) {
|
| 431 |
-
$result = $this->readVarint($size);
|
| 432 |
-
$types = 0;
|
| 433 |
-
if ($size > 0) {
|
| 434 |
-
$result += $this->readUByte($types);
|
| 435 |
-
}
|
| 436 |
-
$val_type = $this->getTType($types);
|
| 437 |
-
$key_type = $this->getTType($types >> 4);
|
| 438 |
-
$this->containers[] = $this->state;
|
| 439 |
-
$this->state = TCompactProtocol::STATE_CONTAINER_READ;
|
| 440 |
-
|
| 441 |
-
return $result;
|
| 442 |
-
}
|
| 443 |
-
|
| 444 |
-
public function readCollectionEnd() {
|
| 445 |
-
$this->state = array_pop($this->containers);
|
| 446 |
-
return 0;
|
| 447 |
-
}
|
| 448 |
-
|
| 449 |
-
public function readMapEnd() {
|
| 450 |
-
return $this->readCollectionEnd();
|
| 451 |
-
}
|
| 452 |
-
|
| 453 |
-
public function readListBegin(&$elem_type, &$size) {
|
| 454 |
-
return $this->readCollectionBegin($elem_type, $size);
|
| 455 |
-
}
|
| 456 |
-
|
| 457 |
-
public function readListEnd() {
|
| 458 |
-
return $this->readCollectionEnd();
|
| 459 |
-
}
|
| 460 |
-
|
| 461 |
-
public function readSetBegin(&$elem_type, &$size) {
|
| 462 |
-
return $this->readCollectionBegin($elem_type, $size);
|
| 463 |
-
}
|
| 464 |
-
|
| 465 |
-
public function readSetEnd() {
|
| 466 |
-
return $this->readCollectionEnd();
|
| 467 |
-
}
|
| 468 |
-
|
| 469 |
-
public function readBool(&$value) {
|
| 470 |
-
if ($this->state == TCompactProtocol::STATE_BOOL_READ) {
|
| 471 |
-
$value = $this->boolValue;
|
| 472 |
-
return 0;
|
| 473 |
-
} else if ($this->state == TCompactProtocol::STATE_CONTAINER_READ) {
|
| 474 |
-
return $this->readByte($value);
|
| 475 |
-
} else {
|
| 476 |
-
throw new TProtocolException('Invalid state in compact protocol');
|
| 477 |
-
}
|
| 478 |
-
}
|
| 479 |
-
|
| 480 |
-
public function readI16(&$value) {
|
| 481 |
-
return $this->readZigZag($value);
|
| 482 |
-
}
|
| 483 |
-
|
| 484 |
-
public function readI32(&$value) {
|
| 485 |
-
return $this->readZigZag($value);
|
| 486 |
-
}
|
| 487 |
-
|
| 488 |
-
public function readDouble(&$value) {
|
| 489 |
-
$data = strrev($this->trans_->readAll(8));
|
| 490 |
-
$arr = unpack('d', $data);
|
| 491 |
-
$value = $arr[1];
|
| 492 |
-
return 8;
|
| 493 |
-
}
|
| 494 |
-
|
| 495 |
-
public function readString(&$value) {
|
| 496 |
-
$result = $this->readVarint($len);
|
| 497 |
-
if ($len) {
|
| 498 |
-
$value = $this->trans_->readAll($len);
|
| 499 |
-
} else {
|
| 500 |
-
$value = '';
|
| 501 |
-
}
|
| 502 |
-
return $result + $len;
|
| 503 |
-
}
|
| 504 |
-
|
| 505 |
-
public function getTType($byte) {
|
| 506 |
-
return self::$ttypes[$byte & 0x0f];
|
| 507 |
-
}
|
| 508 |
-
|
| 509 |
-
// If we are on a 32bit architecture we have to explicitly deal with
|
| 510 |
-
// 64-bit twos-complement arithmetic since PHP wants to treat all ints
|
| 511 |
-
// as signed and any int over 2^31 - 1 as a float
|
| 512 |
-
|
| 513 |
-
// Read and write I64 as two 32 bit numbers $hi and $lo
|
| 514 |
-
|
| 515 |
-
public function readI64(&$value) {
|
| 516 |
-
// Read varint from wire
|
| 517 |
-
$hi = 0;
|
| 518 |
-
$lo = 0;
|
| 519 |
-
|
| 520 |
-
$idx = 0;
|
| 521 |
-
$shift = 0;
|
| 522 |
-
|
| 523 |
-
while (true) {
|
| 524 |
-
$x = $this->trans_->readAll(1);
|
| 525 |
-
$arr = unpack('C', $x);
|
| 526 |
-
$byte = $arr[1];
|
| 527 |
-
$idx += 1;
|
| 528 |
-
if ($shift < 32) {
|
| 529 |
-
$lo |= (($byte & 0x7f) << $shift) &
|
| 530 |
-
0x00000000ffffffff;
|
| 531 |
-
}
|
| 532 |
-
// Shift hi and lo together.
|
| 533 |
-
if ($shift >= 32) {
|
| 534 |
-
$hi |= (($byte & 0x7f) << ($shift - 32));
|
| 535 |
-
} else if ($shift > 25) {
|
| 536 |
-
$hi |= (($byte & 0x7f) >> ($shift - 25));
|
| 537 |
-
}
|
| 538 |
-
if (($byte >> 7) === 0) {
|
| 539 |
-
break;
|
| 540 |
-
}
|
| 541 |
-
$shift += 7;
|
| 542 |
-
}
|
| 543 |
-
|
| 544 |
-
// Now, unzig it.
|
| 545 |
-
$xorer = 0;
|
| 546 |
-
if ($lo & 1) {
|
| 547 |
-
$xorer = 0xffffffff;
|
| 548 |
-
}
|
| 549 |
-
$lo = ($lo >> 1) & 0x7fffffff;
|
| 550 |
-
$lo = $lo | (($hi & 1) << 31);
|
| 551 |
-
$hi = ($hi >> 1) ^ $xorer;
|
| 552 |
-
$lo = $lo ^ $xorer;
|
| 553 |
-
|
| 554 |
-
// Now put $hi and $lo back together
|
| 555 |
-
if (true) {
|
| 556 |
-
$isNeg = $hi < 0;
|
| 557 |
-
|
| 558 |
-
// Check for a negative
|
| 559 |
-
if ($isNeg) {
|
| 560 |
-
$hi = ~$hi & (int)0xffffffff;
|
| 561 |
-
$lo = ~$lo & (int)0xffffffff;
|
| 562 |
-
|
| 563 |
-
if ($lo == (int)0xffffffff) {
|
| 564 |
-
$hi++;
|
| 565 |
-
$lo = 0;
|
| 566 |
-
} else {
|
| 567 |
-
$lo++;
|
| 568 |
-
}
|
| 569 |
-
}
|
| 570 |
-
|
| 571 |
-
// Force 32bit words in excess of 2G to be positive - we deal with sign
|
| 572 |
-
// explicitly below
|
| 573 |
-
|
| 574 |
-
if ($hi & (int)0x80000000) {
|
| 575 |
-
$hi &= (int)0x7fffffff;
|
| 576 |
-
$hi += 0x80000000;
|
| 577 |
-
}
|
| 578 |
-
|
| 579 |
-
if ($lo & (int)0x80000000) {
|
| 580 |
-
$lo &= (int)0x7fffffff;
|
| 581 |
-
$lo += 0x80000000;
|
| 582 |
-
}
|
| 583 |
-
|
| 584 |
-
$value = $hi * 4294967296 + $lo;
|
| 585 |
-
|
| 586 |
-
if ($isNeg) {
|
| 587 |
-
$value = 0 - $value;
|
| 588 |
-
}
|
| 589 |
-
} else {
|
| 590 |
-
|
| 591 |
-
// Upcast negatives in LSB bit
|
| 592 |
-
if ($arr[2] & 0x80000000) {
|
| 593 |
-
$arr[2] = $arr[2] & 0xffffffff;
|
| 594 |
-
}
|
| 595 |
-
|
| 596 |
-
// Check for a negative
|
| 597 |
-
if ($arr[1] & 0x80000000) {
|
| 598 |
-
$arr[1] = $arr[1] & 0xffffffff;
|
| 599 |
-
$arr[1] = $arr[1] ^ 0xffffffff;
|
| 600 |
-
$arr[2] = $arr[2] ^ 0xffffffff;
|
| 601 |
-
$value = 0 - $arr[1] * 4294967296 - $arr[2] - 1;
|
| 602 |
-
} else {
|
| 603 |
-
$value = $arr[1] * 4294967296 + $arr[2];
|
| 604 |
-
}
|
| 605 |
-
}
|
| 606 |
-
|
| 607 |
-
return $idx;
|
| 608 |
-
}
|
| 609 |
-
|
| 610 |
-
public function writeI64($value) {
|
| 611 |
-
// If we are in an I32 range, use the easy method below.
|
| 612 |
-
if (($value > 4294967296) || ($value < -4294967296)) {
|
| 613 |
-
// Convert $value to $hi and $lo
|
| 614 |
-
$neg = $value < 0;
|
| 615 |
-
|
| 616 |
-
if ($neg) {
|
| 617 |
-
$value *= -1;
|
| 618 |
-
}
|
| 619 |
-
|
| 620 |
-
$hi = (int)$value >> 32;
|
| 621 |
-
$lo = (int)$value & 0xffffffff;
|
| 622 |
-
|
| 623 |
-
if ($neg) {
|
| 624 |
-
$hi = ~$hi;
|
| 625 |
-
$lo = ~$lo;
|
| 626 |
-
if (($lo & (int)0xffffffff) == (int)0xffffffff) {
|
| 627 |
-
$lo = 0;
|
| 628 |
-
$hi++;
|
| 629 |
-
} else {
|
| 630 |
-
$lo++;
|
| 631 |
-
}
|
| 632 |
-
}
|
| 633 |
-
|
| 634 |
-
// Now do the zigging and zagging.
|
| 635 |
-
$xorer = 0;
|
| 636 |
-
if ($neg) {
|
| 637 |
-
$xorer = 0xffffffff;
|
| 638 |
-
}
|
| 639 |
-
$lowbit = ($lo >> 31) & 1;
|
| 640 |
-
$hi = ($hi << 1) | $lowbit;
|
| 641 |
-
$lo = ($lo << 1);
|
| 642 |
-
$lo = ($lo ^ $xorer) & 0xffffffff;
|
| 643 |
-
$hi = ($hi ^ $xorer) & 0xffffffff;
|
| 644 |
-
|
| 645 |
-
// now write out the varint, ensuring we shift both hi and lo
|
| 646 |
-
$out = "";
|
| 647 |
-
while (true) {
|
| 648 |
-
if (($lo & ~0x7f) === 0 &&
|
| 649 |
-
$hi === 0) {
|
| 650 |
-
$out .= chr($lo);
|
| 651 |
-
break;
|
| 652 |
-
} else {
|
| 653 |
-
$out .= chr(($lo & 0xff) | 0x80);
|
| 654 |
-
$lo = $lo >> 7;
|
| 655 |
-
$lo = $lo | ($hi << 25);
|
| 656 |
-
$hi = $hi >> 7;
|
| 657 |
-
// Right shift carries sign, but we don't want it to.
|
| 658 |
-
$hi = $hi & (127 << 25);
|
| 659 |
-
}
|
| 660 |
-
}
|
| 661 |
-
|
| 662 |
-
$ret = TStringFuncFactory::create()->strlen($out);
|
| 663 |
-
$this->trans_->write($out, $ret);
|
| 664 |
-
|
| 665 |
-
return $ret;
|
| 666 |
-
} else {
|
| 667 |
-
return $this->writeVarint($this->toZigZag($value, 64));
|
| 668 |
-
}
|
| 669 |
-
}
|
| 670 |
-
}
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Licensed to the Apache Software Foundation (ASF) under one
|
| 4 |
+
* or more contributor license agreements. See the NOTICE file
|
| 5 |
+
* distributed with this work for additional information
|
| 6 |
+
* regarding copyright ownership. The ASF licenses this file
|
| 7 |
+
* to you under the Apache License, Version 2.0 (the
|
| 8 |
+
* "License"); you may not use this file except in compliance
|
| 9 |
+
* with the License. You may obtain a copy of the License at
|
| 10 |
+
*
|
| 11 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
+
*
|
| 13 |
+
* Unless required by applicable law or agreed to in writing,
|
| 14 |
+
* software distributed under the License is distributed on an
|
| 15 |
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 16 |
+
* KIND, either express or implied. See the License for the
|
| 17 |
+
* specific language governing permissions and limitations
|
| 18 |
+
* under the License.
|
| 19 |
+
*
|
| 20 |
+
* @package thrift.protocol
|
| 21 |
+
*/
|
| 22 |
+
|
| 23 |
+
namespace Thrift\Protocol;
|
| 24 |
+
|
| 25 |
+
use Thrift\Protocol\TProtocol;
|
| 26 |
+
use Thrift\Type\TType;
|
| 27 |
+
use Thrift\Exception\TProtocolException;
|
| 28 |
+
use Thrift\Factory\TStringFuncFactory;
|
| 29 |
+
|
| 30 |
+
/**
|
| 31 |
+
* Compact implementation of the Thrift protocol.
|
| 32 |
+
*
|
| 33 |
+
*/
|
| 34 |
+
class TCompactProtocol extends TProtocol {
|
| 35 |
+
|
| 36 |
+
const COMPACT_STOP = 0x00;
|
| 37 |
+
const COMPACT_TRUE = 0x01;
|
| 38 |
+
const COMPACT_FALSE = 0x02;
|
| 39 |
+
const COMPACT_BYTE = 0x03;
|
| 40 |
+
const COMPACT_I16 = 0x04;
|
| 41 |
+
const COMPACT_I32 = 0x05;
|
| 42 |
+
const COMPACT_I64 = 0x06;
|
| 43 |
+
const COMPACT_DOUBLE = 0x07;
|
| 44 |
+
const COMPACT_BINARY = 0x08;
|
| 45 |
+
const COMPACT_LIST = 0x09;
|
| 46 |
+
const COMPACT_SET = 0x0A;
|
| 47 |
+
const COMPACT_MAP = 0x0B;
|
| 48 |
+
const COMPACT_STRUCT = 0x0C;
|
| 49 |
+
|
| 50 |
+
const STATE_CLEAR = 0;
|
| 51 |
+
const STATE_FIELD_WRITE = 1;
|
| 52 |
+
const STATE_VALUE_WRITE = 2;
|
| 53 |
+
const STATE_CONTAINER_WRITE = 3;
|
| 54 |
+
const STATE_BOOL_WRITE = 4;
|
| 55 |
+
const STATE_FIELD_READ = 5;
|
| 56 |
+
const STATE_CONTAINER_READ = 6;
|
| 57 |
+
const STATE_VALUE_READ = 7;
|
| 58 |
+
const STATE_BOOL_READ = 8;
|
| 59 |
+
|
| 60 |
+
const VERSION_MASK = 0x1f;
|
| 61 |
+
const VERSION = 1;
|
| 62 |
+
const PROTOCOL_ID = 0x82;
|
| 63 |
+
const TYPE_MASK = 0xe0;
|
| 64 |
+
const TYPE_SHIFT_AMOUNT = 5;
|
| 65 |
+
|
| 66 |
+
protected static $ctypes = array(
|
| 67 |
+
TType::STOP => TCompactProtocol::COMPACT_STOP,
|
| 68 |
+
TType::BOOL => TCompactProtocol::COMPACT_TRUE, // used for collection
|
| 69 |
+
TType::BYTE => TCompactProtocol::COMPACT_BYTE,
|
| 70 |
+
TType::I16 => TCompactProtocol::COMPACT_I16,
|
| 71 |
+
TType::I32 => TCompactProtocol::COMPACT_I32,
|
| 72 |
+
TType::I64 => TCompactProtocol::COMPACT_I64,
|
| 73 |
+
TType::DOUBLE => TCompactProtocol::COMPACT_DOUBLE,
|
| 74 |
+
TType::STRING => TCompactProtocol::COMPACT_BINARY,
|
| 75 |
+
TType::STRUCT => TCompactProtocol::COMPACT_STRUCT,
|
| 76 |
+
TType::LST => TCompactProtocol::COMPACT_LIST,
|
| 77 |
+
TType::SET => TCompactProtocol::COMPACT_SET,
|
| 78 |
+
TType::MAP => TCompactProtocol::COMPACT_MAP,
|
| 79 |
+
);
|
| 80 |
+
|
| 81 |
+
protected static $ttypes = array(
|
| 82 |
+
TCompactProtocol::COMPACT_STOP => TType::STOP ,
|
| 83 |
+
TCompactProtocol::COMPACT_TRUE => TType::BOOL, // used for collection
|
| 84 |
+
TCompactProtocol::COMPACT_FALSE => TType::BOOL,
|
| 85 |
+
TCompactProtocol::COMPACT_BYTE => TType::BYTE,
|
| 86 |
+
TCompactProtocol::COMPACT_I16 => TType::I16,
|
| 87 |
+
TCompactProtocol::COMPACT_I32 => TType::I32,
|
| 88 |
+
TCompactProtocol::COMPACT_I64 => TType::I64,
|
| 89 |
+
TCompactProtocol::COMPACT_DOUBLE => TType::DOUBLE,
|
| 90 |
+
TCompactProtocol::COMPACT_BINARY => TType::STRING,
|
| 91 |
+
TCompactProtocol::COMPACT_STRUCT => TType::STRUCT,
|
| 92 |
+
TCompactProtocol::COMPACT_LIST => TType::LST,
|
| 93 |
+
TCompactProtocol::COMPACT_SET => TType::SET,
|
| 94 |
+
TCompactProtocol::COMPACT_MAP => TType::MAP,
|
| 95 |
+
);
|
| 96 |
+
|
| 97 |
+
protected $state = TCompactProtocol::STATE_CLEAR;
|
| 98 |
+
protected $lastFid = 0;
|
| 99 |
+
protected $boolFid = null;
|
| 100 |
+
protected $boolValue = null;
|
| 101 |
+
protected $structs = array();
|
| 102 |
+
protected $containers = array();
|
| 103 |
+
|
| 104 |
+
// Some varint / zigzag helper methods
|
| 105 |
+
public function toZigZag($n, $bits) {
|
| 106 |
+
return ($n << 1) ^ ($n >> ($bits - 1));
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
public function fromZigZag($n) {
|
| 110 |
+
return ($n >> 1) ^ -($n & 1);
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
public function getVarint($data) {
|
| 114 |
+
$out = "";
|
| 115 |
+
while (true) {
|
| 116 |
+
if (($data & ~0x7f) === 0) {
|
| 117 |
+
$out .= chr($data);
|
| 118 |
+
break;
|
| 119 |
+
} else {
|
| 120 |
+
$out .= chr(($data & 0xff) | 0x80);
|
| 121 |
+
$data = $data >> 7;
|
| 122 |
+
}
|
| 123 |
+
}
|
| 124 |
+
return $out;
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
public function writeVarint($data) {
|
| 128 |
+
$out = $this->getVarint($data);
|
| 129 |
+
$result = TStringFuncFactory::create()->strlen($out);
|
| 130 |
+
$this->trans_->write($out, $result);
|
| 131 |
+
return $result;
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
public function readVarint(&$result) {
|
| 135 |
+
$idx = 0;
|
| 136 |
+
$shift = 0;
|
| 137 |
+
$result = 0;
|
| 138 |
+
while (true) {
|
| 139 |
+
$x = $this->trans_->readAll(1);
|
| 140 |
+
$arr = unpack('C', $x);
|
| 141 |
+
$byte = $arr[1];
|
| 142 |
+
$idx += 1;
|
| 143 |
+
$result |= ($byte & 0x7f) << $shift;
|
| 144 |
+
if (($byte >> 7) === 0) {
|
| 145 |
+
return $idx;
|
| 146 |
+
}
|
| 147 |
+
$shift += 7;
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
return $idx;
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
+
public function __construct($trans) {
|
| 154 |
+
parent::__construct($trans);
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
public function writeMessageBegin($name, $type, $seqid) {
|
| 158 |
+
$written =
|
| 159 |
+
$this->writeUByte(TCompactProtocol::PROTOCOL_ID) +
|
| 160 |
+
$this->writeUByte(TCompactProtocol::VERSION |
|
| 161 |
+
($type << TCompactProtocol::TYPE_SHIFT_AMOUNT)) +
|
| 162 |
+
$this->writeVarint($seqid) +
|
| 163 |
+
$this->writeString($name);
|
| 164 |
+
$this->state = TCompactProtocol::STATE_VALUE_WRITE;
|
| 165 |
+
return $written;
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
public function writeMessageEnd() {
|
| 169 |
+
$this->state = TCompactProtocol::STATE_CLEAR;
|
| 170 |
+
return 0;
|
| 171 |
+
}
|
| 172 |
+
|
| 173 |
+
public function writeStructBegin($name) {
|
| 174 |
+
$this->structs[] = array($this->state, $this->lastFid);
|
| 175 |
+
$this->state = TCompactProtocol::STATE_FIELD_WRITE;
|
| 176 |
+
$this->lastFid = 0;
|
| 177 |
+
return 0;
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
public function writeStructEnd() {
|
| 181 |
+
$old_values = array_pop($this->structs);
|
| 182 |
+
$this->state = $old_values[0];
|
| 183 |
+
$this->lastFid = $old_values[1];
|
| 184 |
+
return 0;
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
public function writeFieldStop() {
|
| 188 |
+
return $this->writeByte(0);
|
| 189 |
+
}
|
| 190 |
+
|
| 191 |
+
public function writeFieldHeader($type, $fid) {
|
| 192 |
+
$written = 0;
|
| 193 |
+
$delta = $fid - $this->lastFid;
|
| 194 |
+
if (0 < $delta && $delta <= 15) {
|
| 195 |
+
$written = $this->writeUByte(($delta << 4) | $type);
|
| 196 |
+
} else {
|
| 197 |
+
$written = $this->writeByte($type) +
|
| 198 |
+
$this->writeI16($fid);
|
| 199 |
+
}
|
| 200 |
+
$this->lastFid = $fid;
|
| 201 |
+
return $written;
|
| 202 |
+
}
|
| 203 |
+
|
| 204 |
+
public function writeFieldBegin($field_name, $field_type, $field_id) {
|
| 205 |
+
if ($field_type == TTYPE::BOOL) {
|
| 206 |
+
$this->state = TCompactProtocol::STATE_BOOL_WRITE;
|
| 207 |
+
$this->boolFid = $field_id;
|
| 208 |
+
return 0;
|
| 209 |
+
} else {
|
| 210 |
+
$this->state = TCompactProtocol::STATE_VALUE_WRITE;
|
| 211 |
+
return $this->writeFieldHeader(self::$ctypes[$field_type], $field_id);
|
| 212 |
+
}
|
| 213 |
+
}
|
| 214 |
+
|
| 215 |
+
public function writeFieldEnd() {
|
| 216 |
+
$this->state = TCompactProtocol::STATE_FIELD_WRITE;
|
| 217 |
+
return 0;
|
| 218 |
+
}
|
| 219 |
+
|
| 220 |
+
public function writeCollectionBegin($etype, $size) {
|
| 221 |
+
$written = 0;
|
| 222 |
+
if ($size <= 14) {
|
| 223 |
+
$written = $this->writeUByte($size << 4 |
|
| 224 |
+
self::$ctypes[$etype]);
|
| 225 |
+
} else {
|
| 226 |
+
$written = $this->writeUByte(0xf0 |
|
| 227 |
+
self::$ctypes[$etype]) +
|
| 228 |
+
$this->writeVarint($size);
|
| 229 |
+
}
|
| 230 |
+
$this->containers[] = $this->state;
|
| 231 |
+
$this->state = TCompactProtocol::STATE_CONTAINER_WRITE;
|
| 232 |
+
|
| 233 |
+
return $written;
|
| 234 |
+
}
|
| 235 |
+
|
| 236 |
+
public function writeMapBegin($key_type, $val_type, $size) {
|
| 237 |
+
$written = 0;
|
| 238 |
+
if ($size == 0) {
|
| 239 |
+
$written = $this->writeByte(0);
|
| 240 |
+
} else {
|
| 241 |
+
$written = $this->writeVarint($size) +
|
| 242 |
+
$this->writeUByte(self::$ctypes[$key_type] << 4 |
|
| 243 |
+
self::$ctypes[$val_type]);
|
| 244 |
+
}
|
| 245 |
+
$this->containers[] = $this->state;
|
| 246 |
+
return $written;
|
| 247 |
+
}
|
| 248 |
+
|
| 249 |
+
public function writeCollectionEnd() {
|
| 250 |
+
$this->state = array_pop($this->containers);
|
| 251 |
+
return 0;
|
| 252 |
+
}
|
| 253 |
+
|
| 254 |
+
public function writeMapEnd() {
|
| 255 |
+
return $this->writeCollectionEnd();
|
| 256 |
+
}
|
| 257 |
+
|
| 258 |
+
public function writeListBegin($elem_type, $size) {
|
| 259 |
+
return $this->writeCollectionBegin($elem_type, $size);
|
| 260 |
+
}
|
| 261 |
+
|
| 262 |
+
public function writeListEnd() {
|
| 263 |
+
return $this->writeCollectionEnd();
|
| 264 |
+
}
|
| 265 |
+
|
| 266 |
+
public function writeSetBegin($elem_type, $size) {
|
| 267 |
+
return $this->writeCollectionBegin($elem_type, $size);
|
| 268 |
+
}
|
| 269 |
+
|
| 270 |
+
public function writeSetEnd() {
|
| 271 |
+
return $this->writeCollectionEnd();
|
| 272 |
+
}
|
| 273 |
+
|
| 274 |
+
public function writeBool($value) {
|
| 275 |
+
if ($this->state == TCompactProtocol::STATE_BOOL_WRITE) {
|
| 276 |
+
$ctype = TCompactProtocol::COMPACT_FALSE;
|
| 277 |
+
if ($value) {
|
| 278 |
+
$ctype = TCompactProtocol::COMPACT_TRUE;
|
| 279 |
+
}
|
| 280 |
+
return $this->writeFieldHeader($ctype, $this->boolFid);
|
| 281 |
+
} else if ($this->state == TCompactProtocol::STATE_CONTAINER_WRITE) {
|
| 282 |
+
return $this->writeByte($value ? 1 : 0);
|
| 283 |
+
} else {
|
| 284 |
+
throw new TProtocolException('Invalid state in compact protocol');
|
| 285 |
+
}
|
| 286 |
+
}
|
| 287 |
+
|
| 288 |
+
public function writeByte($value) {
|
| 289 |
+
$data = pack('c', $value);
|
| 290 |
+
$this->trans_->write($data, 1);
|
| 291 |
+
return 1;
|
| 292 |
+
}
|
| 293 |
+
|
| 294 |
+
public function writeUByte($byte) {
|
| 295 |
+
$this->trans_->write(pack('C', $byte), 1);
|
| 296 |
+
return 1;
|
| 297 |
+
}
|
| 298 |
+
|
| 299 |
+
public function writeI16($value) {
|
| 300 |
+
$thing = $this->toZigZag($value, 16);
|
| 301 |
+
return $this->writeVarint($thing);
|
| 302 |
+
}
|
| 303 |
+
|
| 304 |
+
public function writeI32($value) {
|
| 305 |
+
$thing = $this->toZigZag($value, 32);
|
| 306 |
+
return $this->writeVarint($thing);
|
| 307 |
+
}
|
| 308 |
+
|
| 309 |
+
public function writeDouble($value) {
|
| 310 |
+
$data = pack('d', $value);
|
| 311 |
+
$this->trans_->write(strrev($data), 8);
|
| 312 |
+
return 8;
|
| 313 |
+
}
|
| 314 |
+
|
| 315 |
+
public function writeString($value) {
|
| 316 |
+
$len = TStringFuncFactory::create()->strlen($value);
|
| 317 |
+
$result = $this->writeVarint($len);
|
| 318 |
+
if ($len) {
|
| 319 |
+
$this->trans_->write($value, $len);
|
| 320 |
+
}
|
| 321 |
+
return $result + $len;
|
| 322 |
+
}
|
| 323 |
+
|
| 324 |
+
public function readFieldBegin(&$name, &$field_type, &$field_id) {
|
| 325 |
+
$result = $this->readUByte($field_type);
|
| 326 |
+
|
| 327 |
+
if (($field_type & 0x0f) == TType::STOP) {
|
| 328 |
+
$field_id = 0;
|
| 329 |
+
return $result;
|
| 330 |
+
}
|
| 331 |
+
$delta = $field_type >> 4;
|
| 332 |
+
if ($delta == 0) {
|
| 333 |
+
$result += $this->readI16($field_id);
|
| 334 |
+
} else {
|
| 335 |
+
$field_id = $this->lastFid + $delta;
|
| 336 |
+
}
|
| 337 |
+
$this->lastFid = $field_id;
|
| 338 |
+
$field_type &= 0x0f;
|
| 339 |
+
if ($field_type == TCompactProtocol::COMPACT_TRUE) {
|
| 340 |
+
$this->state = TCompactProtocol::STATE_BOOL_READ;
|
| 341 |
+
$this->boolValue = true;
|
| 342 |
+
} else if ($field_type == TCompactProtocol::COMPACT_FALSE) {
|
| 343 |
+
$this->state = TCompactProtocol::STATE_BOOL_READ;
|
| 344 |
+
$this->boolValue = false;
|
| 345 |
+
} else {
|
| 346 |
+
$this->state = TCompactProtocol::STATE_VALUE_READ;
|
| 347 |
+
}
|
| 348 |
+
$field_type = $this->getTType($field_type);
|
| 349 |
+
return $result;
|
| 350 |
+
}
|
| 351 |
+
|
| 352 |
+
public function readFieldEnd() {
|
| 353 |
+
$this->state = TCompactProtocol::STATE_FIELD_READ;
|
| 354 |
+
return 0;
|
| 355 |
+
}
|
| 356 |
+
|
| 357 |
+
public function readUByte(&$value) {
|
| 358 |
+
$data = $this->trans_->readAll(1);
|
| 359 |
+
$arr = unpack('C', $data);
|
| 360 |
+
$value = $arr[1];
|
| 361 |
+
return 1;
|
| 362 |
+
}
|
| 363 |
+
|
| 364 |
+
public function readByte(&$value) {
|
| 365 |
+
$data = $this->trans_->readAll(1);
|
| 366 |
+
$arr = unpack('c', $data);
|
| 367 |
+
$value = $arr[1];
|
| 368 |
+
return 1;
|
| 369 |
+
}
|
| 370 |
+
|
| 371 |
+
public function readZigZag(&$value) {
|
| 372 |
+
$result = $this->readVarint($value);
|
| 373 |
+
$value = $this->fromZigZag($value);
|
| 374 |
+
return $result;
|
| 375 |
+
}
|
| 376 |
+
|
| 377 |
+
public function readMessageBegin(&$name, &$type, &$seqid) {
|
| 378 |
+
$protoId = 0;
|
| 379 |
+
$result = $this->readUByte($protoId);
|
| 380 |
+
if ($protoId != TCompactProtocol::PROTOCOL_ID) {
|
| 381 |
+
throw new TProtocolException('Bad protocol id in TCompact message');
|
| 382 |
+
}
|
| 383 |
+
$verType = 0;
|
| 384 |
+
$result += $this->readUByte($verType);
|
| 385 |
+
$type = ($verType & TCompactProtocol::TYPE_MASK) >>
|
| 386 |
+
TCompactProtocol::TYPE_SHIFT_AMOUNT;
|
| 387 |
+
$version = $verType & TCompactProtocol::VERSION_MASK;
|
| 388 |
+
if ($version != TCompactProtocol::VERSION) {
|
| 389 |
+
throw new TProtocolException('Bad version in TCompact message');
|
| 390 |
+
}
|
| 391 |
+
$result += $this->readVarint($seqId);
|
| 392 |
+
$name += $this->readString($name);
|
| 393 |
+
|
| 394 |
+
return $result;
|
| 395 |
+
}
|
| 396 |
+
|
| 397 |
+
public function readMessageEnd() {
|
| 398 |
+
return 0;
|
| 399 |
+
}
|
| 400 |
+
|
| 401 |
+
public function readStructBegin(&$name) {
|
| 402 |
+
$name = ''; // unused
|
| 403 |
+
$this->structs[] = array($this->state, $this->lastFid);
|
| 404 |
+
$this->state = TCompactProtocol::STATE_FIELD_READ;
|
| 405 |
+
$this->lastFid = 0;
|
| 406 |
+
return 0;
|
| 407 |
+
}
|
| 408 |
+
|
| 409 |
+
public function readStructEnd() {
|
| 410 |
+
$last = array_pop($this->structs);
|
| 411 |
+
$this->state = $last[0];
|
| 412 |
+
$this->lastFid = $last[1];
|
| 413 |
+
return 0;
|
| 414 |
+
}
|
| 415 |
+
|
| 416 |
+
public function readCollectionBegin(&$type, &$size) {
|
| 417 |
+
$sizeType = 0;
|
| 418 |
+
$result = $this->readUByte($sizeType);
|
| 419 |
+
$size = $sizeType >> 4;
|
| 420 |
+
$type = $this->getTType($sizeType);
|
| 421 |
+
if ($size == 15) {
|
| 422 |
+
$result += $this->readVarint($size);
|
| 423 |
+
}
|
| 424 |
+
$this->containers[] = $this->state;
|
| 425 |
+
$this->state = TCompactProtocol::STATE_CONTAINER_READ;
|
| 426 |
+
|
| 427 |
+
return $result;
|
| 428 |
+
}
|
| 429 |
+
|
| 430 |
+
public function readMapBegin(&$key_type, &$val_type, &$size) {
|
| 431 |
+
$result = $this->readVarint($size);
|
| 432 |
+
$types = 0;
|
| 433 |
+
if ($size > 0) {
|
| 434 |
+
$result += $this->readUByte($types);
|
| 435 |
+
}
|
| 436 |
+
$val_type = $this->getTType($types);
|
| 437 |
+
$key_type = $this->getTType($types >> 4);
|
| 438 |
+
$this->containers[] = $this->state;
|
| 439 |
+
$this->state = TCompactProtocol::STATE_CONTAINER_READ;
|
| 440 |
+
|
| 441 |
+
return $result;
|
| 442 |
+
}
|
| 443 |
+
|
| 444 |
+
public function readCollectionEnd() {
|
| 445 |
+
$this->state = array_pop($this->containers);
|
| 446 |
+
return 0;
|
| 447 |
+
}
|
| 448 |
+
|
| 449 |
+
public function readMapEnd() {
|
| 450 |
+
return $this->readCollectionEnd();
|
| 451 |
+
}
|
| 452 |
+
|
| 453 |
+
public function readListBegin(&$elem_type, &$size) {
|
| 454 |
+
return $this->readCollectionBegin($elem_type, $size);
|
| 455 |
+
}
|
| 456 |
+
|
| 457 |
+
public function readListEnd() {
|
| 458 |
+
return $this->readCollectionEnd();
|
| 459 |
+
}
|
| 460 |
+
|
| 461 |
+
public function readSetBegin(&$elem_type, &$size) {
|
| 462 |
+
return $this->readCollectionBegin($elem_type, $size);
|
| 463 |
+
}
|
| 464 |
+
|
| 465 |
+
public function readSetEnd() {
|
| 466 |
+
return $this->readCollectionEnd();
|
| 467 |
+
}
|
| 468 |
+
|
| 469 |
+
public function readBool(&$value) {
|
| 470 |
+
if ($this->state == TCompactProtocol::STATE_BOOL_READ) {
|
| 471 |
+
$value = $this->boolValue;
|
| 472 |
+
return 0;
|
| 473 |
+
} else if ($this->state == TCompactProtocol::STATE_CONTAINER_READ) {
|
| 474 |
+
return $this->readByte($value);
|
| 475 |
+
} else {
|
| 476 |
+
throw new TProtocolException('Invalid state in compact protocol');
|
| 477 |
+
}
|
| 478 |
+
}
|
| 479 |
+
|
| 480 |
+
public function readI16(&$value) {
|
| 481 |
+
return $this->readZigZag($value);
|
| 482 |
+
}
|
| 483 |
+
|
| 484 |
+
public function readI32(&$value) {
|
| 485 |
+
return $this->readZigZag($value);
|
| 486 |
+
}
|
| 487 |
+
|
| 488 |
+
public function readDouble(&$value) {
|
| 489 |
+
$data = strrev($this->trans_->readAll(8));
|
| 490 |
+
$arr = unpack('d', $data);
|
| 491 |
+
$value = $arr[1];
|
| 492 |
+
return 8;
|
| 493 |
+
}
|
| 494 |
+
|
| 495 |
+
public function readString(&$value) {
|
| 496 |
+
$result = $this->readVarint($len);
|
| 497 |
+
if ($len) {
|
| 498 |
+
$value = $this->trans_->readAll($len);
|
| 499 |
+
} else {
|
| 500 |
+
$value = '';
|
| 501 |
+
}
|
| 502 |
+
return $result + $len;
|
| 503 |
+
}
|
| 504 |
+
|
| 505 |
+
public function getTType($byte) {
|
| 506 |
+
return self::$ttypes[$byte & 0x0f];
|
| 507 |
+
}
|
| 508 |
+
|
| 509 |
+
// If we are on a 32bit architecture we have to explicitly deal with
|
| 510 |
+
// 64-bit twos-complement arithmetic since PHP wants to treat all ints
|
| 511 |
+
// as signed and any int over 2^31 - 1 as a float
|
| 512 |
+
|
| 513 |
+
// Read and write I64 as two 32 bit numbers $hi and $lo
|
| 514 |
+
|
| 515 |
+
public function readI64(&$value) {
|
| 516 |
+
// Read varint from wire
|
| 517 |
+
$hi = 0;
|
| 518 |
+
$lo = 0;
|
| 519 |
+
|
| 520 |
+
$idx = 0;
|
| 521 |
+
$shift = 0;
|
| 522 |
+
|
| 523 |
+
while (true) {
|
| 524 |
+
$x = $this->trans_->readAll(1);
|
| 525 |
+
$arr = unpack('C', $x);
|
| 526 |
+
$byte = $arr[1];
|
| 527 |
+
$idx += 1;
|
| 528 |
+
if ($shift < 32) {
|
| 529 |
+
$lo |= (($byte & 0x7f) << $shift) &
|
| 530 |
+
0x00000000ffffffff;
|
| 531 |
+
}
|
| 532 |
+
// Shift hi and lo together.
|
| 533 |
+
if ($shift >= 32) {
|
| 534 |
+
$hi |= (($byte & 0x7f) << ($shift - 32));
|
| 535 |
+
} else if ($shift > 25) {
|
| 536 |
+
$hi |= (($byte & 0x7f) >> ($shift - 25));
|
| 537 |
+
}
|
| 538 |
+
if (($byte >> 7) === 0) {
|
| 539 |
+
break;
|
| 540 |
+
}
|
| 541 |
+
$shift += 7;
|
| 542 |
+
}
|
| 543 |
+
|
| 544 |
+
// Now, unzig it.
|
| 545 |
+
$xorer = 0;
|
| 546 |
+
if ($lo & 1) {
|
| 547 |
+
$xorer = 0xffffffff;
|
| 548 |
+
}
|
| 549 |
+
$lo = ($lo >> 1) & 0x7fffffff;
|
| 550 |
+
$lo = $lo | (($hi & 1) << 31);
|
| 551 |
+
$hi = ($hi >> 1) ^ $xorer;
|
| 552 |
+
$lo = $lo ^ $xorer;
|
| 553 |
+
|
| 554 |
+
// Now put $hi and $lo back together
|
| 555 |
+
if (true) {
|
| 556 |
+
$isNeg = $hi < 0;
|
| 557 |
+
|
| 558 |
+
// Check for a negative
|
| 559 |
+
if ($isNeg) {
|
| 560 |
+
$hi = ~$hi & (int)0xffffffff;
|
| 561 |
+
$lo = ~$lo & (int)0xffffffff;
|
| 562 |
+
|
| 563 |
+
if ($lo == (int)0xffffffff) {
|
| 564 |
+
$hi++;
|
| 565 |
+
$lo = 0;
|
| 566 |
+
} else {
|
| 567 |
+
$lo++;
|
| 568 |
+
}
|
| 569 |
+
}
|
| 570 |
+
|
| 571 |
+
// Force 32bit words in excess of 2G to be positive - we deal with sign
|
| 572 |
+
// explicitly below
|
| 573 |
+
|
| 574 |
+
if ($hi & (int)0x80000000) {
|
| 575 |
+
$hi &= (int)0x7fffffff;
|
| 576 |
+
$hi += 0x80000000;
|
| 577 |
+
}
|
| 578 |
+
|
| 579 |
+
if ($lo & (int)0x80000000) {
|
| 580 |
+
$lo &= (int)0x7fffffff;
|
| 581 |
+
$lo += 0x80000000;
|
| 582 |
+
}
|
| 583 |
+
|
| 584 |
+
$value = $hi * 4294967296 + $lo;
|
| 585 |
+
|
| 586 |
+
if ($isNeg) {
|
| 587 |
+
$value = 0 - $value;
|
| 588 |
+
}
|
| 589 |
+
} else {
|
| 590 |
+
|
| 591 |
+
// Upcast negatives in LSB bit
|
| 592 |
+
if ($arr[2] & 0x80000000) {
|
| 593 |
+
$arr[2] = $arr[2] & 0xffffffff;
|
| 594 |
+
}
|
| 595 |
+
|
| 596 |
+
// Check for a negative
|
| 597 |
+
if ($arr[1] & 0x80000000) {
|
| 598 |
+
$arr[1] = $arr[1] & 0xffffffff;
|
| 599 |
+
$arr[1] = $arr[1] ^ 0xffffffff;
|
| 600 |
+
$arr[2] = $arr[2] ^ 0xffffffff;
|
| 601 |
+
$value = 0 - $arr[1] * 4294967296 - $arr[2] - 1;
|
| 602 |
+
} else {
|
| 603 |
+
$value = $arr[1] * 4294967296 + $arr[2];
|
| 604 |
+
}
|
| 605 |
+
}
|
| 606 |
+
|
| 607 |
+
return $idx;
|
| 608 |
+
}
|
| 609 |
+
|
| 610 |
+
public function writeI64($value) {
|
| 611 |
+
// If we are in an I32 range, use the easy method below.
|
| 612 |
+
if (($value > 4294967296) || ($value < -4294967296)) {
|
| 613 |
+
// Convert $value to $hi and $lo
|
| 614 |
+
$neg = $value < 0;
|
| 615 |
+
|
| 616 |
+
if ($neg) {
|
| 617 |
+
$value *= -1;
|
| 618 |
+
}
|
| 619 |
+
|
| 620 |
+
$hi = (int)$value >> 32;
|
| 621 |
+
$lo = (int)$value & 0xffffffff;
|
| 622 |
+
|
| 623 |
+
if ($neg) {
|
| 624 |
+
$hi = ~$hi;
|
| 625 |
+
$lo = ~$lo;
|
| 626 |
+
if (($lo & (int)0xffffffff) == (int)0xffffffff) {
|
| 627 |
+
$lo = 0;
|
| 628 |
+
$hi++;
|
| 629 |
+
} else {
|
| 630 |
+
$lo++;
|
| 631 |
+
}
|
| 632 |
+
}
|
| 633 |
+
|
| 634 |
+
// Now do the zigging and zagging.
|
| 635 |
+
$xorer = 0;
|
| 636 |
+
if ($neg) {
|
| 637 |
+
$xorer = 0xffffffff;
|
| 638 |
+
}
|
| 639 |
+
$lowbit = ($lo >> 31) & 1;
|
| 640 |
+
$hi = ($hi << 1) | $lowbit;
|
| 641 |
+
$lo = ($lo << 1);
|
| 642 |
+
$lo = ($lo ^ $xorer) & 0xffffffff;
|
| 643 |
+
$hi = ($hi ^ $xorer) & 0xffffffff;
|
| 644 |
+
|
| 645 |
+
// now write out the varint, ensuring we shift both hi and lo
|
| 646 |
+
$out = "";
|
| 647 |
+
while (true) {
|
| 648 |
+
if (($lo & ~0x7f) === 0 &&
|
| 649 |
+
$hi === 0) {
|
| 650 |
+
$out .= chr($lo);
|
| 651 |
+
break;
|
| 652 |
+
} else {
|
| 653 |
+
$out .= chr(($lo & 0xff) | 0x80);
|
| 654 |
+
$lo = $lo >> 7;
|
| 655 |
+
$lo = $lo | ($hi << 25);
|
| 656 |
+
$hi = $hi >> 7;
|
| 657 |
+
// Right shift carries sign, but we don't want it to.
|
| 658 |
+
$hi = $hi & (127 << 25);
|
| 659 |
+
}
|
| 660 |
+
}
|
| 661 |
+
|
| 662 |
+
$ret = TStringFuncFactory::create()->strlen($out);
|
| 663 |
+
$this->trans_->write($out, $ret);
|
| 664 |
+
|
| 665 |
+
return $ret;
|
| 666 |
+
} else {
|
| 667 |
+
return $this->writeVarint($this->toZigZag($value, 64));
|
| 668 |
+
}
|
| 669 |
+
}
|
| 670 |
+
}
|
app/code/community/Boxalino/{CemSearch/Lib/vendor → Intelligence/lib}/Thrift/Protocol/TJSONProtocol.php
RENAMED
|
@@ -1,694 +1,694 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
|
| 3 |
-
/*
|
| 4 |
-
* Licensed to the Apache Software Foundation (ASF) under one
|
| 5 |
-
* or more contributor license agreements. See the NOTICE file
|
| 6 |
-
* distributed with this work for additional information
|
| 7 |
-
* regarding copyright ownership. The ASF licenses this file
|
| 8 |
-
* to you under the Apache License, Version 2.0 (the
|
| 9 |
-
* "License"); you may not use this file except in compliance
|
| 10 |
-
* with the License. You may obtain a copy of the License at
|
| 11 |
-
*
|
| 12 |
-
* http://www.apache.org/licenses/LICENSE-2.0
|
| 13 |
-
*
|
| 14 |
-
* Unless required by applicable law or agreed to in writing,
|
| 15 |
-
* software distributed under the License is distributed on an
|
| 16 |
-
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 17 |
-
* KIND, either express or implied. See the License for the
|
| 18 |
-
* specific language governing permissions and limitations
|
| 19 |
-
* under the License.
|
| 20 |
-
*
|
| 21 |
-
* @package thrift.protocol
|
| 22 |
-
*/
|
| 23 |
-
|
| 24 |
-
namespace Thrift\Protocol;
|
| 25 |
-
|
| 26 |
-
use Thrift\Protocol\TProtocol;
|
| 27 |
-
use Thrift\Type\TType;
|
| 28 |
-
use Thrift\Exception\TProtocolException;
|
| 29 |
-
use Thrift\Protocol\JSON\BaseContext;
|
| 30 |
-
use Thrift\Protocol\JSON\LookaheadReader;
|
| 31 |
-
use Thrift\Protocol\JSON\PairContext;
|
| 32 |
-
use Thrift\Protocol\JSON\ListContext;
|
| 33 |
-
|
| 34 |
-
/**
|
| 35 |
-
* JSON implementation of thrift protocol, ported from Java.
|
| 36 |
-
*/
|
| 37 |
-
class TJSONProtocol extends TProtocol
|
| 38 |
-
{
|
| 39 |
-
const COMMA = ',';
|
| 40 |
-
const COLON = ':';
|
| 41 |
-
const LBRACE = '{';
|
| 42 |
-
const RBRACE = '}';
|
| 43 |
-
const LBRACKET = '[';
|
| 44 |
-
const RBRACKET = ']';
|
| 45 |
-
const QUOTE = '"';
|
| 46 |
-
const BACKSLASH = '\\';
|
| 47 |
-
const ZERO = '0';
|
| 48 |
-
const ESCSEQ = '\\';
|
| 49 |
-
const DOUBLEESC = '__DOUBLE_ESCAPE_SEQUENCE__';
|
| 50 |
-
|
| 51 |
-
const VERSION = 1;
|
| 52 |
-
|
| 53 |
-
public static $JSON_CHAR_TABLE = array(
|
| 54 |
-
/* 0 1 2 3 4 5 6 7 8 9 A B C D E F */
|
| 55 |
-
0, 0, 0, 0, 0, 0, 0, 0, 'b', 't', 'n', 0, 'f', 'r', 0, 0, // 0
|
| 56 |
-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1
|
| 57 |
-
1, 1, '"', 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 2
|
| 58 |
-
);
|
| 59 |
-
|
| 60 |
-
public static $ESCAPE_CHARS = array('"', '\\', "b", "f", "n", "r", "t");
|
| 61 |
-
|
| 62 |
-
public static $ESCAPE_CHAR_VALS = array(
|
| 63 |
-
'"', '\\', "\x08", "\f", "\n", "\r", "\t",
|
| 64 |
-
);
|
| 65 |
-
|
| 66 |
-
const NAME_BOOL = "tf";
|
| 67 |
-
const NAME_BYTE = "i8";
|
| 68 |
-
const NAME_I16 = "i16";
|
| 69 |
-
const NAME_I32 = "i32";
|
| 70 |
-
const NAME_I64 = "i64";
|
| 71 |
-
const NAME_DOUBLE = "dbl";
|
| 72 |
-
const NAME_STRUCT = "rec";
|
| 73 |
-
const NAME_STRING = "str";
|
| 74 |
-
const NAME_MAP = "map";
|
| 75 |
-
const NAME_LIST = "lst";
|
| 76 |
-
const NAME_SET = "set";
|
| 77 |
-
|
| 78 |
-
private function getTypeNameForTypeID($typeID)
|
| 79 |
-
{
|
| 80 |
-
switch ($typeID) {
|
| 81 |
-
case TType::BOOL:
|
| 82 |
-
return self::NAME_BOOL;
|
| 83 |
-
case TType::BYTE:
|
| 84 |
-
return self::NAME_BYTE;
|
| 85 |
-
case TType::I16:
|
| 86 |
-
return self::NAME_I16;
|
| 87 |
-
case TType::I32:
|
| 88 |
-
return self::NAME_I32;
|
| 89 |
-
case TType::I64:
|
| 90 |
-
return self::NAME_I64;
|
| 91 |
-
case TType::DOUBLE:
|
| 92 |
-
return self::NAME_DOUBLE;
|
| 93 |
-
case TType::STRING:
|
| 94 |
-
return self::NAME_STRING;
|
| 95 |
-
case TType::STRUCT:
|
| 96 |
-
return self::NAME_STRUCT;
|
| 97 |
-
case TType::MAP:
|
| 98 |
-
return self::NAME_MAP;
|
| 99 |
-
case TType::SET:
|
| 100 |
-
return self::NAME_SET;
|
| 101 |
-
case TType::LST:
|
| 102 |
-
return self::NAME_LIST;
|
| 103 |
-
default:
|
| 104 |
-
throw new TProtocolException("Unrecognized type", TProtocolException::UNKNOWN);
|
| 105 |
-
}
|
| 106 |
-
}
|
| 107 |
-
|
| 108 |
-
private function getTypeIDForTypeName($name)
|
| 109 |
-
{
|
| 110 |
-
$result = TType::STOP;
|
| 111 |
-
|
| 112 |
-
if (strlen($name) > 1) {
|
| 113 |
-
switch (substr($name, 0, 1)) {
|
| 114 |
-
case 'd':
|
| 115 |
-
$result = TType::DOUBLE;
|
| 116 |
-
break;
|
| 117 |
-
case 'i':
|
| 118 |
-
switch (substr($name, 1, 1)) {
|
| 119 |
-
case '8':
|
| 120 |
-
$result = TType::BYTE;
|
| 121 |
-
break;
|
| 122 |
-
case '1':
|
| 123 |
-
$result = TType::I16;
|
| 124 |
-
break;
|
| 125 |
-
case '3':
|
| 126 |
-
$result = TType::I32;
|
| 127 |
-
break;
|
| 128 |
-
case '6':
|
| 129 |
-
$result = TType::I64;
|
| 130 |
-
break;
|
| 131 |
-
}
|
| 132 |
-
break;
|
| 133 |
-
case 'l':
|
| 134 |
-
$result = TType::LST;
|
| 135 |
-
break;
|
| 136 |
-
case 'm':
|
| 137 |
-
$result = TType::MAP;
|
| 138 |
-
break;
|
| 139 |
-
case 'r':
|
| 140 |
-
$result = TType::STRUCT;
|
| 141 |
-
break;
|
| 142 |
-
case 's':
|
| 143 |
-
if (substr($name, 1, 1) == 't') {
|
| 144 |
-
$result = TType::STRING;
|
| 145 |
-
}
|
| 146 |
-
else if (substr($name, 1, 1) == 'e') {
|
| 147 |
-
$result = TType::SET;
|
| 148 |
-
}
|
| 149 |
-
break;
|
| 150 |
-
case 't':
|
| 151 |
-
$result = TType::BOOL;
|
| 152 |
-
break;
|
| 153 |
-
}
|
| 154 |
-
}
|
| 155 |
-
if ($result == TType::STOP) {
|
| 156 |
-
throw new TProtocolException("Unrecognized type", TProtocolException::INVALID_DATA);
|
| 157 |
-
}
|
| 158 |
-
return $result;
|
| 159 |
-
}
|
| 160 |
-
|
| 161 |
-
public $contextStack_ = array();
|
| 162 |
-
public $context_;
|
| 163 |
-
public $reader_;
|
| 164 |
-
|
| 165 |
-
private function pushContext($c) {
|
| 166 |
-
array_push($this->contextStack_, $this->context_);
|
| 167 |
-
$this->context_ = $c;
|
| 168 |
-
}
|
| 169 |
-
|
| 170 |
-
private function popContext() {
|
| 171 |
-
$this->context_ = array_pop($this->contextStack_);
|
| 172 |
-
}
|
| 173 |
-
|
| 174 |
-
public function __construct($trans) {
|
| 175 |
-
parent::__construct($trans);
|
| 176 |
-
$this->context_ = new BaseContext();
|
| 177 |
-
$this->reader_ = new LookaheadReader($this);
|
| 178 |
-
}
|
| 179 |
-
|
| 180 |
-
public function reset() {
|
| 181 |
-
$this->contextStack_ = array();
|
| 182 |
-
$this->context_ = new BaseContext();
|
| 183 |
-
$this->reader_ = new LookaheadReader($this);
|
| 184 |
-
}
|
| 185 |
-
|
| 186 |
-
private $tmpbuf_ = array(4);
|
| 187 |
-
|
| 188 |
-
public function readJSONSyntaxChar($b) {
|
| 189 |
-
$ch = $this->reader_->read();
|
| 190 |
-
|
| 191 |
-
if (substr($ch, 0, 1) != $b) {
|
| 192 |
-
throw new TProtocolException("Unexpected character: " . $ch, TProtocolException::INVALID_DATA);
|
| 193 |
-
}
|
| 194 |
-
}
|
| 195 |
-
|
| 196 |
-
private function hexVal($s) {
|
| 197 |
-
for ($i = 0; $i < strlen($s); $i++) {
|
| 198 |
-
$ch = substr($s, $i, 1);
|
| 199 |
-
|
| 200 |
-
if (!($ch >= "a" && $ch <= "f") && !($ch >= "0" && $ch <= "9")) {
|
| 201 |
-
throw new TProtocolException("Expected hex character " . $ch, TProtocolException::INVALID_DATA);
|
| 202 |
-
}
|
| 203 |
-
}
|
| 204 |
-
|
| 205 |
-
return hexdec($s);
|
| 206 |
-
}
|
| 207 |
-
|
| 208 |
-
private function hexChar($val) {
|
| 209 |
-
return dechex($val);
|
| 210 |
-
}
|
| 211 |
-
|
| 212 |
-
private function writeJSONString($b) {
|
| 213 |
-
$this->context_->write();
|
| 214 |
-
|
| 215 |
-
if (is_numeric($b) && $this->context_->escapeNum()) {
|
| 216 |
-
$this->trans_->write(self::QUOTE);
|
| 217 |
-
}
|
| 218 |
-
|
| 219 |
-
$this->trans_->write(json_encode($b));
|
| 220 |
-
|
| 221 |
-
if (is_numeric($b) && $this->context_->escapeNum()) {
|
| 222 |
-
$this->trans_->write(self::QUOTE);
|
| 223 |
-
}
|
| 224 |
-
}
|
| 225 |
-
|
| 226 |
-
private function writeJSONInteger($num) {
|
| 227 |
-
$this->context_->write();
|
| 228 |
-
|
| 229 |
-
if ($this->context_->escapeNum()) {
|
| 230 |
-
$this->trans_->write(self::QUOTE);
|
| 231 |
-
}
|
| 232 |
-
|
| 233 |
-
$this->trans_->write($num);
|
| 234 |
-
|
| 235 |
-
if ($this->context_->escapeNum()) {
|
| 236 |
-
$this->trans_->write(self::QUOTE);
|
| 237 |
-
}
|
| 238 |
-
}
|
| 239 |
-
|
| 240 |
-
private function writeJSONDouble($num) {
|
| 241 |
-
$this->context_->write();
|
| 242 |
-
|
| 243 |
-
if ($this->context_->escapeNum()) {
|
| 244 |
-
$this->trans_->write(self::QUOTE);
|
| 245 |
-
}
|
| 246 |
-
|
| 247 |
-
$this->trans_->write(json_encode($num));
|
| 248 |
-
|
| 249 |
-
if ($this->context_->escapeNum()) {
|
| 250 |
-
$this->trans_->write(self::QUOTE);
|
| 251 |
-
}
|
| 252 |
-
}
|
| 253 |
-
|
| 254 |
-
private function writeJSONBase64($data) {
|
| 255 |
-
$this->context_->write();
|
| 256 |
-
$this->trans_->write(self::QUOTE);
|
| 257 |
-
$this->trans_->write(json_encode(base64_encode($data)));
|
| 258 |
-
$this->trans_->write(self::QUOTE);
|
| 259 |
-
}
|
| 260 |
-
|
| 261 |
-
private function writeJSONObjectStart() {
|
| 262 |
-
$this->context_->write();
|
| 263 |
-
$this->trans_->write(self::LBRACE);
|
| 264 |
-
$this->pushContext(new PairContext($this));
|
| 265 |
-
}
|
| 266 |
-
|
| 267 |
-
private function writeJSONObjectEnd() {
|
| 268 |
-
$this->popContext();
|
| 269 |
-
$this->trans_->write(self::RBRACE);
|
| 270 |
-
}
|
| 271 |
-
|
| 272 |
-
private function writeJSONArrayStart() {
|
| 273 |
-
$this->context_->write();
|
| 274 |
-
$this->trans_->write(self::LBRACKET);
|
| 275 |
-
$this->pushContext(new ListContext($this));
|
| 276 |
-
}
|
| 277 |
-
|
| 278 |
-
private function writeJSONArrayEnd() {
|
| 279 |
-
$this->popContext();
|
| 280 |
-
$this->trans_->write(self::RBRACKET);
|
| 281 |
-
}
|
| 282 |
-
|
| 283 |
-
private function readJSONString($skipContext) {
|
| 284 |
-
if (!$skipContext) {
|
| 285 |
-
$this->context_->read();
|
| 286 |
-
}
|
| 287 |
-
|
| 288 |
-
$jsonString = '';
|
| 289 |
-
$lastChar = NULL;
|
| 290 |
-
while (true) {
|
| 291 |
-
$ch = $this->reader_->read();
|
| 292 |
-
$jsonString .= $ch;
|
| 293 |
-
if ($ch == self::QUOTE &&
|
| 294 |
-
$lastChar !== NULL &&
|
| 295 |
-
$lastChar !== self::ESCSEQ) {
|
| 296 |
-
break;
|
| 297 |
-
}
|
| 298 |
-
if ($ch == self::ESCSEQ && $lastChar == self::ESCSEQ) {
|
| 299 |
-
$lastChar = self::DOUBLEESC;
|
| 300 |
-
} else {
|
| 301 |
-
$lastChar = $ch;
|
| 302 |
-
}
|
| 303 |
-
}
|
| 304 |
-
return json_decode($jsonString);
|
| 305 |
-
}
|
| 306 |
-
|
| 307 |
-
private function isJSONNumeric($b) {
|
| 308 |
-
switch ($b) {
|
| 309 |
-
case '+':
|
| 310 |
-
case '-':
|
| 311 |
-
case '.':
|
| 312 |
-
case '0':
|
| 313 |
-
case '1':
|
| 314 |
-
case '2':
|
| 315 |
-
case '3':
|
| 316 |
-
case '4':
|
| 317 |
-
case '5':
|
| 318 |
-
case '6':
|
| 319 |
-
case '7':
|
| 320 |
-
case '8':
|
| 321 |
-
case '9':
|
| 322 |
-
case 'E':
|
| 323 |
-
case 'e':
|
| 324 |
-
return true;
|
| 325 |
-
}
|
| 326 |
-
return false;
|
| 327 |
-
}
|
| 328 |
-
|
| 329 |
-
private function readJSONNumericChars() {
|
| 330 |
-
$strbld = array();
|
| 331 |
-
|
| 332 |
-
while (true) {
|
| 333 |
-
$ch = $this->reader_->peek();
|
| 334 |
-
|
| 335 |
-
if (!$this->isJSONNumeric($ch)) {
|
| 336 |
-
break;
|
| 337 |
-
}
|
| 338 |
-
|
| 339 |
-
$strbld[] = $this->reader_->read();
|
| 340 |
-
}
|
| 341 |
-
|
| 342 |
-
return implode("", $strbld);
|
| 343 |
-
}
|
| 344 |
-
|
| 345 |
-
private function readJSONInteger() {
|
| 346 |
-
$this->context_->read();
|
| 347 |
-
|
| 348 |
-
if ($this->context_->escapeNum()) {
|
| 349 |
-
$this->readJSONSyntaxChar(self::QUOTE);
|
| 350 |
-
}
|
| 351 |
-
|
| 352 |
-
$str = $this->readJSONNumericChars();
|
| 353 |
-
|
| 354 |
-
if ($this->context_->escapeNum()) {
|
| 355 |
-
$this->readJSONSyntaxChar(self::QUOTE);
|
| 356 |
-
}
|
| 357 |
-
|
| 358 |
-
if (!is_numeric($str)) {
|
| 359 |
-
throw new TProtocolException("Invalid data in numeric: " . $str, TProtocolException::INVALID_DATA);
|
| 360 |
-
}
|
| 361 |
-
|
| 362 |
-
return intval($str);
|
| 363 |
-
}
|
| 364 |
-
|
| 365 |
-
/**
|
| 366 |
-
* Identical to readJSONInteger but without the final cast.
|
| 367 |
-
* Needed for proper handling of i64 on 32 bit machines. Why a
|
| 368 |
-
* separate function? So we don't have to force the rest of the
|
| 369 |
-
* use cases through the extra conditional.
|
| 370 |
-
*/
|
| 371 |
-
private function readJSONIntegerAsString() {
|
| 372 |
-
$this->context_->read();
|
| 373 |
-
|
| 374 |
-
if ($this->context_->escapeNum()) {
|
| 375 |
-
$this->readJSONSyntaxChar(self::QUOTE);
|
| 376 |
-
}
|
| 377 |
-
|
| 378 |
-
$str = $this->readJSONNumericChars();
|
| 379 |
-
|
| 380 |
-
if ($this->context_->escapeNum()) {
|
| 381 |
-
$this->readJSONSyntaxChar(self::QUOTE);
|
| 382 |
-
}
|
| 383 |
-
|
| 384 |
-
if (!is_numeric($str)) {
|
| 385 |
-
throw new TProtocolException("Invalid data in numeric: " . $str, TProtocolException::INVALID_DATA);
|
| 386 |
-
}
|
| 387 |
-
|
| 388 |
-
return $str;
|
| 389 |
-
}
|
| 390 |
-
|
| 391 |
-
private function readJSONDouble() {
|
| 392 |
-
$this->context_->read();
|
| 393 |
-
|
| 394 |
-
if (substr($this->reader_->peek(), 0, 1) == self::QUOTE) {
|
| 395 |
-
$arr = $this->readJSONString(true);
|
| 396 |
-
|
| 397 |
-
if ($arr == "NaN") {
|
| 398 |
-
return NAN;
|
| 399 |
-
} else if ($arr == "Infinity") {
|
| 400 |
-
return INF;
|
| 401 |
-
} else if (!$this->context_->escapeNum()) {
|
| 402 |
-
throw new TProtocolException("Numeric data unexpectedly quoted " . $arr,
|
| 403 |
-
TProtocolException::INVALID_DATA);
|
| 404 |
-
}
|
| 405 |
-
|
| 406 |
-
return floatval($arr);
|
| 407 |
-
} else {
|
| 408 |
-
if ($this->context_->escapeNum()) {
|
| 409 |
-
$this->readJSONSyntaxChar(self::QUOTE);
|
| 410 |
-
}
|
| 411 |
-
|
| 412 |
-
return floatval($this->readJSONNumericChars());
|
| 413 |
-
}
|
| 414 |
-
}
|
| 415 |
-
|
| 416 |
-
private function readJSONBase64() {
|
| 417 |
-
$arr = $this->readJSONString(false);
|
| 418 |
-
$data = base64_decode($arr, true);
|
| 419 |
-
|
| 420 |
-
if ($data === false) {
|
| 421 |
-
throw new TProtocolException("Invalid base64 data " . $arr, TProtocolException::INVALID_DATA);
|
| 422 |
-
}
|
| 423 |
-
|
| 424 |
-
return $data;
|
| 425 |
-
}
|
| 426 |
-
|
| 427 |
-
private function readJSONObjectStart() {
|
| 428 |
-
$this->context_->read();
|
| 429 |
-
$this->readJSONSyntaxChar(self::LBRACE);
|
| 430 |
-
$this->pushContext(new PairContext($this));
|
| 431 |
-
}
|
| 432 |
-
|
| 433 |
-
private function readJSONObjectEnd() {
|
| 434 |
-
$this->readJSONSyntaxChar(self::RBRACE);
|
| 435 |
-
$this->popContext();
|
| 436 |
-
}
|
| 437 |
-
|
| 438 |
-
private function readJSONArrayStart()
|
| 439 |
-
{
|
| 440 |
-
$this->context_->read();
|
| 441 |
-
$this->readJSONSyntaxChar(self::LBRACKET);
|
| 442 |
-
$this->pushContext(new ListContext($this));
|
| 443 |
-
}
|
| 444 |
-
|
| 445 |
-
private function readJSONArrayEnd() {
|
| 446 |
-
$this->readJSONSyntaxChar(self::RBRACKET);
|
| 447 |
-
$this->popContext();
|
| 448 |
-
}
|
| 449 |
-
|
| 450 |
-
/**
|
| 451 |
-
* Writes the message header
|
| 452 |
-
*
|
| 453 |
-
* @param string $name Function name
|
| 454 |
-
* @param int $type message type TMessageType::CALL or TMessageType::REPLY
|
| 455 |
-
* @param int $seqid The sequence id of this message
|
| 456 |
-
*/
|
| 457 |
-
public function writeMessageBegin($name, $type, $seqid) {
|
| 458 |
-
$this->writeJSONArrayStart();
|
| 459 |
-
$this->writeJSONInteger(self::VERSION);
|
| 460 |
-
$this->writeJSONString($name);
|
| 461 |
-
$this->writeJSONInteger($type);
|
| 462 |
-
$this->writeJSONInteger($seqid);
|
| 463 |
-
}
|
| 464 |
-
|
| 465 |
-
/**
|
| 466 |
-
* Close the message
|
| 467 |
-
*/
|
| 468 |
-
public function writeMessageEnd() {
|
| 469 |
-
$this->writeJSONArrayEnd();
|
| 470 |
-
}
|
| 471 |
-
|
| 472 |
-
/**
|
| 473 |
-
* Writes a struct header.
|
| 474 |
-
*
|
| 475 |
-
* @param string $name Struct name
|
| 476 |
-
* @throws TException on write error
|
| 477 |
-
* @return int How many bytes written
|
| 478 |
-
*/
|
| 479 |
-
public function writeStructBegin($name) {
|
| 480 |
-
$this->writeJSONObjectStart();
|
| 481 |
-
}
|
| 482 |
-
|
| 483 |
-
/**
|
| 484 |
-
* Close a struct.
|
| 485 |
-
*
|
| 486 |
-
* @throws TException on write error
|
| 487 |
-
* @return int How many bytes written
|
| 488 |
-
*/
|
| 489 |
-
public function writeStructEnd() {
|
| 490 |
-
$this->writeJSONObjectEnd();
|
| 491 |
-
}
|
| 492 |
-
|
| 493 |
-
public function writeFieldBegin($fieldName, $fieldType, $fieldId) {
|
| 494 |
-
$this->writeJSONInteger($fieldId);
|
| 495 |
-
$this->writeJSONObjectStart();
|
| 496 |
-
$this->writeJSONString($this->getTypeNameForTypeID($fieldType));
|
| 497 |
-
}
|
| 498 |
-
|
| 499 |
-
public function writeFieldEnd() {
|
| 500 |
-
$this->writeJsonObjectEnd();
|
| 501 |
-
}
|
| 502 |
-
|
| 503 |
-
public function writeFieldStop() {
|
| 504 |
-
}
|
| 505 |
-
|
| 506 |
-
public function writeMapBegin($keyType, $valType, $size) {
|
| 507 |
-
$this->writeJSONArrayStart();
|
| 508 |
-
$this->writeJSONString($this->getTypeNameForTypeID($keyType));
|
| 509 |
-
$this->writeJSONString($this->getTypeNameForTypeID($valType));
|
| 510 |
-
$this->writeJSONInteger($size);
|
| 511 |
-
$this->writeJSONObjectStart();
|
| 512 |
-
}
|
| 513 |
-
|
| 514 |
-
public function writeMapEnd() {
|
| 515 |
-
$this->writeJSONObjectEnd();
|
| 516 |
-
$this->writeJSONArrayEnd();
|
| 517 |
-
}
|
| 518 |
-
|
| 519 |
-
public function writeListBegin($elemType, $size) {
|
| 520 |
-
$this->writeJSONArrayStart();
|
| 521 |
-
$this->writeJSONString($this->getTypeNameForTypeID($elemType));
|
| 522 |
-
$this->writeJSONInteger($size);
|
| 523 |
-
}
|
| 524 |
-
|
| 525 |
-
public function writeListEnd() {
|
| 526 |
-
$this->writeJSONArrayEnd();
|
| 527 |
-
}
|
| 528 |
-
|
| 529 |
-
public function writeSetBegin($elemType, $size) {
|
| 530 |
-
$this->writeJSONArrayStart();
|
| 531 |
-
$this->writeJSONString($this->getTypeNameForTypeID($elemType));
|
| 532 |
-
$this->writeJSONInteger($size);
|
| 533 |
-
}
|
| 534 |
-
|
| 535 |
-
public function writeSetEnd() {
|
| 536 |
-
$this->writeJSONArrayEnd();
|
| 537 |
-
}
|
| 538 |
-
|
| 539 |
-
public function writeBool($bool) {
|
| 540 |
-
$this->writeJSONInteger($bool ? 1 : 0);
|
| 541 |
-
}
|
| 542 |
-
|
| 543 |
-
public function writeByte($byte) {
|
| 544 |
-
$this->writeJSONInteger($byte);
|
| 545 |
-
}
|
| 546 |
-
|
| 547 |
-
public function writeI16($i16) {
|
| 548 |
-
$this->writeJSONInteger($i16);
|
| 549 |
-
}
|
| 550 |
-
|
| 551 |
-
public function writeI32($i32) {
|
| 552 |
-
$this->writeJSONInteger($i32);
|
| 553 |
-
}
|
| 554 |
-
|
| 555 |
-
public function writeI64($i64) {
|
| 556 |
-
$this->writeJSONInteger($i64);
|
| 557 |
-
}
|
| 558 |
-
|
| 559 |
-
public function writeDouble($dub) {
|
| 560 |
-
$this->writeJSONDouble($dub);
|
| 561 |
-
}
|
| 562 |
-
|
| 563 |
-
public function writeString($str) {
|
| 564 |
-
$this->writeJSONString($str);
|
| 565 |
-
}
|
| 566 |
-
|
| 567 |
-
/**
|
| 568 |
-
* Reads the message header
|
| 569 |
-
*
|
| 570 |
-
* @param string $name Function name
|
| 571 |
-
* @param int $type message type TMessageType::CALL or TMessageType::REPLY
|
| 572 |
-
* @parem int $seqid The sequence id of this message
|
| 573 |
-
*/
|
| 574 |
-
public function readMessageBegin(&$name, &$type, &$seqid) {
|
| 575 |
-
$this->readJSONArrayStart();
|
| 576 |
-
|
| 577 |
-
if ($this->readJSONInteger() != self::VERSION) {
|
| 578 |
-
throw new TProtocolException("Message contained bad version", TProtocolException::BAD_VERSION);
|
| 579 |
-
}
|
| 580 |
-
|
| 581 |
-
$name = $this->readJSONString(false);
|
| 582 |
-
$type = $this->readJSONInteger();
|
| 583 |
-
$seqid = $this->readJSONInteger();
|
| 584 |
-
|
| 585 |
-
return true;
|
| 586 |
-
}
|
| 587 |
-
|
| 588 |
-
/**
|
| 589 |
-
* Read the close of message
|
| 590 |
-
*/
|
| 591 |
-
public function readMessageEnd() {
|
| 592 |
-
$this->readJSONArrayEnd();
|
| 593 |
-
}
|
| 594 |
-
|
| 595 |
-
public function readStructBegin(&$name) {
|
| 596 |
-
$this->readJSONObjectStart();
|
| 597 |
-
return 0;
|
| 598 |
-
}
|
| 599 |
-
|
| 600 |
-
public function readStructEnd() {
|
| 601 |
-
$this->readJSONObjectEnd();
|
| 602 |
-
}
|
| 603 |
-
|
| 604 |
-
public function readFieldBegin(&$name, &$fieldType, &$fieldId) {
|
| 605 |
-
$ch = $this->reader_->peek();
|
| 606 |
-
$name = "";
|
| 607 |
-
|
| 608 |
-
if (substr($ch, 0, 1) == self::RBRACE) {
|
| 609 |
-
$fieldType = TType::STOP;
|
| 610 |
-
} else {
|
| 611 |
-
$fieldId = $this->readJSONInteger();
|
| 612 |
-
$this->readJSONObjectStart();
|
| 613 |
-
$fieldType = $this->getTypeIDForTypeName($this->readJSONString(false));
|
| 614 |
-
}
|
| 615 |
-
}
|
| 616 |
-
|
| 617 |
-
public function readFieldEnd() {
|
| 618 |
-
$this->readJSONObjectEnd();
|
| 619 |
-
}
|
| 620 |
-
|
| 621 |
-
public function readMapBegin(&$keyType, &$valType, &$size) {
|
| 622 |
-
$this->readJSONArrayStart();
|
| 623 |
-
$keyType = $this->getTypeIDForTypeName($this->readJSONString(false));
|
| 624 |
-
$valType = $this->getTypeIDForTypeName($this->readJSONString(false));
|
| 625 |
-
$size = $this->readJSONInteger();
|
| 626 |
-
$this->readJSONObjectStart();
|
| 627 |
-
}
|
| 628 |
-
|
| 629 |
-
public function readMapEnd() {
|
| 630 |
-
$this->readJSONObjectEnd();
|
| 631 |
-
$this->readJSONArrayEnd();
|
| 632 |
-
}
|
| 633 |
-
|
| 634 |
-
public function readListBegin(&$elemType, &$size) {
|
| 635 |
-
$this->readJSONArrayStart();
|
| 636 |
-
$elemType = $this->getTypeIDForTypeName($this->readJSONString(false));
|
| 637 |
-
$size = $this->readJSONInteger();
|
| 638 |
-
return true;
|
| 639 |
-
}
|
| 640 |
-
|
| 641 |
-
public function readListEnd() {
|
| 642 |
-
$this->readJSONArrayEnd();
|
| 643 |
-
}
|
| 644 |
-
|
| 645 |
-
public function readSetBegin(&$elemType, &$size) {
|
| 646 |
-
$this->readJSONArrayStart();
|
| 647 |
-
$elemType = $this->getTypeIDForTypeName($this->readJSONString(false));
|
| 648 |
-
$size = $this->readJSONInteger();
|
| 649 |
-
return true;
|
| 650 |
-
}
|
| 651 |
-
|
| 652 |
-
public function readSetEnd() {
|
| 653 |
-
$this->readJSONArrayEnd();
|
| 654 |
-
}
|
| 655 |
-
|
| 656 |
-
public function readBool(&$bool) {
|
| 657 |
-
$bool = $this->readJSONInteger() == 0 ? false : true;
|
| 658 |
-
return true;
|
| 659 |
-
}
|
| 660 |
-
|
| 661 |
-
public function readByte(&$byte) {
|
| 662 |
-
$byte = $this->readJSONInteger();
|
| 663 |
-
return true;
|
| 664 |
-
}
|
| 665 |
-
|
| 666 |
-
public function readI16(&$i16) {
|
| 667 |
-
$i16 = $this->readJSONInteger();
|
| 668 |
-
return true;
|
| 669 |
-
}
|
| 670 |
-
|
| 671 |
-
public function readI32(&$i32) {
|
| 672 |
-
$i32 = $this->readJSONInteger();
|
| 673 |
-
return true;
|
| 674 |
-
}
|
| 675 |
-
|
| 676 |
-
public function readI64(&$i64) {
|
| 677 |
-
if ( PHP_INT_SIZE === 4 ) {
|
| 678 |
-
$i64 = $this->readJSONIntegerAsString();
|
| 679 |
-
} else {
|
| 680 |
-
$i64 = $this->readJSONInteger();
|
| 681 |
-
}
|
| 682 |
-
return true;
|
| 683 |
-
}
|
| 684 |
-
|
| 685 |
-
public function readDouble(&$dub) {
|
| 686 |
-
$dub = $this->readJSONDouble();
|
| 687 |
-
return true;
|
| 688 |
-
}
|
| 689 |
-
|
| 690 |
-
public function readString(&$str) {
|
| 691 |
-
$str = $this->readJSONString(false);
|
| 692 |
-
return true;
|
| 693 |
-
}
|
| 694 |
-
}
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
/*
|
| 4 |
+
* Licensed to the Apache Software Foundation (ASF) under one
|
| 5 |
+
* or more contributor license agreements. See the NOTICE file
|
| 6 |
+
* distributed with this work for additional information
|
| 7 |
+
* regarding copyright ownership. The ASF licenses this file
|
| 8 |
+
* to you under the Apache License, Version 2.0 (the
|
| 9 |
+
* "License"); you may not use this file except in compliance
|
| 10 |
+
* with the License. You may obtain a copy of the License at
|
| 11 |
+
*
|
| 12 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 13 |
+
*
|
| 14 |
+
* Unless required by applicable law or agreed to in writing,
|
| 15 |
+
* software distributed under the License is distributed on an
|
| 16 |
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 17 |
+
* KIND, either express or implied. See the License for the
|
| 18 |
+
* specific language governing permissions and limitations
|
| 19 |
+
* under the License.
|
| 20 |
+
*
|
| 21 |
+
* @package thrift.protocol
|
| 22 |
+
*/
|
| 23 |
+
|
| 24 |
+
namespace Thrift\Protocol;
|
| 25 |
+
|
| 26 |
+
use Thrift\Protocol\TProtocol;
|
| 27 |
+
use Thrift\Type\TType;
|
| 28 |
+
use Thrift\Exception\TProtocolException;
|
| 29 |
+
use Thrift\Protocol\JSON\BaseContext;
|
| 30 |
+
use Thrift\Protocol\JSON\LookaheadReader;
|
| 31 |
+
use Thrift\Protocol\JSON\PairContext;
|
| 32 |
+
use Thrift\Protocol\JSON\ListContext;
|
| 33 |
+
|
| 34 |
+
/**
|
| 35 |
+
* JSON implementation of thrift protocol, ported from Java.
|
| 36 |
+
*/
|
| 37 |
+
class TJSONProtocol extends TProtocol
|
| 38 |
+
{
|
| 39 |
+
const COMMA = ',';
|
| 40 |
+
const COLON = ':';
|
| 41 |
+
const LBRACE = '{';
|
| 42 |
+
const RBRACE = '}';
|
| 43 |
+
const LBRACKET = '[';
|
| 44 |
+
const RBRACKET = ']';
|
| 45 |
+
const QUOTE = '"';
|
| 46 |
+
const BACKSLASH = '\\';
|
| 47 |
+
const ZERO = '0';
|
| 48 |
+
const ESCSEQ = '\\';
|
| 49 |
+
const DOUBLEESC = '__DOUBLE_ESCAPE_SEQUENCE__';
|
| 50 |
+
|
| 51 |
+
const VERSION = 1;
|
| 52 |
+
|
| 53 |
+
public static $JSON_CHAR_TABLE = array(
|
| 54 |
+
/* 0 1 2 3 4 5 6 7 8 9 A B C D E F */
|
| 55 |
+
0, 0, 0, 0, 0, 0, 0, 0, 'b', 't', 'n', 0, 'f', 'r', 0, 0, // 0
|
| 56 |
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1
|
| 57 |
+
1, 1, '"', 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 2
|
| 58 |
+
);
|
| 59 |
+
|
| 60 |
+
public static $ESCAPE_CHARS = array('"', '\\', "b", "f", "n", "r", "t");
|
| 61 |
+
|
| 62 |
+
public static $ESCAPE_CHAR_VALS = array(
|
| 63 |
+
'"', '\\', "\x08", "\f", "\n", "\r", "\t",
|
| 64 |
+
);
|
| 65 |
+
|
| 66 |
+
const NAME_BOOL = "tf";
|
| 67 |
+
const NAME_BYTE = "i8";
|
| 68 |
+
const NAME_I16 = "i16";
|
| 69 |
+
const NAME_I32 = "i32";
|
| 70 |
+
const NAME_I64 = "i64";
|
| 71 |
+
const NAME_DOUBLE = "dbl";
|
| 72 |
+
const NAME_STRUCT = "rec";
|
| 73 |
+
const NAME_STRING = "str";
|
| 74 |
+
const NAME_MAP = "map";
|
| 75 |
+
const NAME_LIST = "lst";
|
| 76 |
+
const NAME_SET = "set";
|
| 77 |
+
|
| 78 |
+
private function getTypeNameForTypeID($typeID)
|
| 79 |
+
{
|
| 80 |
+
switch ($typeID) {
|
| 81 |
+
case TType::BOOL:
|
| 82 |
+
return self::NAME_BOOL;
|
| 83 |
+
case TType::BYTE:
|
| 84 |
+
return self::NAME_BYTE;
|
| 85 |
+
case TType::I16:
|
| 86 |
+
return self::NAME_I16;
|
| 87 |
+
case TType::I32:
|
| 88 |
+
return self::NAME_I32;
|
| 89 |
+
case TType::I64:
|
| 90 |
+
return self::NAME_I64;
|
| 91 |
+
case TType::DOUBLE:
|
| 92 |
+
return self::NAME_DOUBLE;
|
| 93 |
+
case TType::STRING:
|
| 94 |
+
return self::NAME_STRING;
|
| 95 |
+
case TType::STRUCT:
|
| 96 |
+
return self::NAME_STRUCT;
|
| 97 |
+
case TType::MAP:
|
| 98 |
+
return self::NAME_MAP;
|
| 99 |
+
case TType::SET:
|
| 100 |
+
return self::NAME_SET;
|
| 101 |
+
case TType::LST:
|
| 102 |
+
return self::NAME_LIST;
|
| 103 |
+
default:
|
| 104 |
+
throw new TProtocolException("Unrecognized type", TProtocolException::UNKNOWN);
|
| 105 |
+
}
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
private function getTypeIDForTypeName($name)
|
| 109 |
+
{
|
| 110 |
+
$result = TType::STOP;
|
| 111 |
+
|
| 112 |
+
if (strlen($name) > 1) {
|
| 113 |
+
switch (substr($name, 0, 1)) {
|
| 114 |
+
case 'd':
|
| 115 |
+
$result = TType::DOUBLE;
|
| 116 |
+
break;
|
| 117 |
+
case 'i':
|
| 118 |
+
switch (substr($name, 1, 1)) {
|
| 119 |
+
case '8':
|
| 120 |
+
$result = TType::BYTE;
|
| 121 |
+
break;
|
| 122 |
+
case '1':
|
| 123 |
+
$result = TType::I16;
|
| 124 |
+
break;
|
| 125 |
+
case '3':
|
| 126 |
+
$result = TType::I32;
|
| 127 |
+
break;
|
| 128 |
+
case '6':
|
| 129 |
+
$result = TType::I64;
|
| 130 |
+
break;
|
| 131 |
+
}
|
| 132 |
+
break;
|
| 133 |
+
case 'l':
|
| 134 |
+
$result = TType::LST;
|
| 135 |
+
break;
|
| 136 |
+
case 'm':
|
| 137 |
+
$result = TType::MAP;
|
| 138 |
+
break;
|
| 139 |
+
case 'r':
|
| 140 |
+
$result = TType::STRUCT;
|
| 141 |
+
break;
|
| 142 |
+
case 's':
|
| 143 |
+
if (substr($name, 1, 1) == 't') {
|
| 144 |
+
$result = TType::STRING;
|
| 145 |
+
}
|
| 146 |
+
else if (substr($name, 1, 1) == 'e') {
|
| 147 |
+
$result = TType::SET;
|
| 148 |
+
}
|
| 149 |
+
break;
|
| 150 |
+
case 't':
|
| 151 |
+
$result = TType::BOOL;
|
| 152 |
+
break;
|
| 153 |
+
}
|
| 154 |
+
}
|
| 155 |
+
if ($result == TType::STOP) {
|
| 156 |
+
throw new TProtocolException("Unrecognized type", TProtocolException::INVALID_DATA);
|
| 157 |
+
}
|
| 158 |
+
return $result;
|
| 159 |
+
}
|
| 160 |
+
|
| 161 |
+
public $contextStack_ = array();
|
| 162 |
+
public $context_;
|
| 163 |
+
public $reader_;
|
| 164 |
+
|
| 165 |
+
private function pushContext($c) {
|
| 166 |
+
array_push($this->contextStack_, $this->context_);
|
| 167 |
+
$this->context_ = $c;
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
private function popContext() {
|
| 171 |
+
$this->context_ = array_pop($this->contextStack_);
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
public function __construct($trans) {
|
| 175 |
+
parent::__construct($trans);
|
| 176 |
+
$this->context_ = new BaseContext();
|
| 177 |
+
$this->reader_ = new LookaheadReader($this);
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
public function reset() {
|
| 181 |
+
$this->contextStack_ = array();
|
| 182 |
+
$this->context_ = new BaseContext();
|
| 183 |
+
$this->reader_ = new LookaheadReader($this);
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
+
private $tmpbuf_ = array(4);
|
| 187 |
+
|
| 188 |
+
public function readJSONSyntaxChar($b) {
|
| 189 |
+
$ch = $this->reader_->read();
|
| 190 |
+
|
| 191 |
+
if (substr($ch, 0, 1) != $b) {
|
| 192 |
+
throw new TProtocolException("Unexpected character: " . $ch, TProtocolException::INVALID_DATA);
|
| 193 |
+
}
|
| 194 |
+
}
|
| 195 |
+
|
| 196 |
+
private function hexVal($s) {
|
| 197 |
+
for ($i = 0; $i < strlen($s); $i++) {
|
| 198 |
+
$ch = substr($s, $i, 1);
|
| 199 |
+
|
| 200 |
+
if (!($ch >= "a" && $ch <= "f") && !($ch >= "0" && $ch <= "9")) {
|
| 201 |
+
throw new TProtocolException("Expected hex character " . $ch, TProtocolException::INVALID_DATA);
|
| 202 |
+
}
|
| 203 |
+
}
|
| 204 |
+
|
| 205 |
+
return hexdec($s);
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
private function hexChar($val) {
|
| 209 |
+
return dechex($val);
|
| 210 |
+
}
|
| 211 |
+
|
| 212 |
+
private function writeJSONString($b) {
|
| 213 |
+
$this->context_->write();
|
| 214 |
+
|
| 215 |
+
if (is_numeric($b) && $this->context_->escapeNum()) {
|
| 216 |
+
$this->trans_->write(self::QUOTE);
|
| 217 |
+
}
|
| 218 |
+
|
| 219 |
+
$this->trans_->write(json_encode($b));
|
| 220 |
+
|
| 221 |
+
if (is_numeric($b) && $this->context_->escapeNum()) {
|
| 222 |
+
$this->trans_->write(self::QUOTE);
|
| 223 |
+
}
|
| 224 |
+
}
|
| 225 |
+
|
| 226 |
+
private function writeJSONInteger($num) {
|
| 227 |
+
$this->context_->write();
|
| 228 |
+
|
| 229 |
+
if ($this->context_->escapeNum()) {
|
| 230 |
+
$this->trans_->write(self::QUOTE);
|
| 231 |
+
}
|
| 232 |
+
|
| 233 |
+
$this->trans_->write($num);
|
| 234 |
+
|
| 235 |
+
if ($this->context_->escapeNum()) {
|
| 236 |
+
$this->trans_->write(self::QUOTE);
|
| 237 |
+
}
|
| 238 |
+
}
|
| 239 |
+
|
| 240 |
+
private function writeJSONDouble($num) {
|
| 241 |
+
$this->context_->write();
|
| 242 |
+
|
| 243 |
+
if ($this->context_->escapeNum()) {
|
| 244 |
+
$this->trans_->write(self::QUOTE);
|
| 245 |
+
}
|
| 246 |
+
|
| 247 |
+
$this->trans_->write(json_encode($num));
|
| 248 |
+
|
| 249 |
+
if ($this->context_->escapeNum()) {
|
| 250 |
+
$this->trans_->write(self::QUOTE);
|
| 251 |
+
}
|
| 252 |
+
}
|
| 253 |
+
|
| 254 |
+
private function writeJSONBase64($data) {
|
| 255 |
+
$this->context_->write();
|
| 256 |
+
$this->trans_->write(self::QUOTE);
|
| 257 |
+
$this->trans_->write(json_encode(base64_encode($data)));
|
| 258 |
+
$this->trans_->write(self::QUOTE);
|
| 259 |
+
}
|
| 260 |
+
|
| 261 |
+
private function writeJSONObjectStart() {
|
| 262 |
+
$this->context_->write();
|
| 263 |
+
$this->trans_->write(self::LBRACE);
|
| 264 |
+
$this->pushContext(new PairContext($this));
|
| 265 |
+
}
|
| 266 |
+
|
| 267 |
+
private function writeJSONObjectEnd() {
|
| 268 |
+
$this->popContext();
|
| 269 |
+
$this->trans_->write(self::RBRACE);
|
| 270 |
+
}
|
| 271 |
+
|
| 272 |
+
private function writeJSONArrayStart() {
|
| 273 |
+
$this->context_->write();
|
| 274 |
+
$this->trans_->write(self::LBRACKET);
|
| 275 |
+
$this->pushContext(new ListContext($this));
|
| 276 |
+
}
|
| 277 |
+
|
| 278 |
+
private function writeJSONArrayEnd() {
|
| 279 |
+
$this->popContext();
|
| 280 |
+
$this->trans_->write(self::RBRACKET);
|
| 281 |
+
}
|
| 282 |
+
|
| 283 |
+
private function readJSONString($skipContext) {
|
| 284 |
+
if (!$skipContext) {
|
| 285 |
+
$this->context_->read();
|
| 286 |
+
}
|
| 287 |
+
|
| 288 |
+
$jsonString = '';
|
| 289 |
+
$lastChar = NULL;
|
| 290 |
+
while (true) {
|
| 291 |
+
$ch = $this->reader_->read();
|
| 292 |
+
$jsonString .= $ch;
|
| 293 |
+
if ($ch == self::QUOTE &&
|
| 294 |
+
$lastChar !== NULL &&
|
| 295 |
+
$lastChar !== self::ESCSEQ) {
|
| 296 |
+
break;
|
| 297 |
+
}
|
| 298 |
+
if ($ch == self::ESCSEQ && $lastChar == self::ESCSEQ) {
|
| 299 |
+
$lastChar = self::DOUBLEESC;
|
| 300 |
+
} else {
|
| 301 |
+
$lastChar = $ch;
|
| 302 |
+
}
|
| 303 |
+
}
|
| 304 |
+
return json_decode($jsonString);
|
| 305 |
+
}
|
| 306 |
+
|
| 307 |
+
private function isJSONNumeric($b) {
|
| 308 |
+
switch ($b) {
|
| 309 |
+
case '+':
|
| 310 |
+
case '-':
|
| 311 |
+
case '.':
|
| 312 |
+
case '0':
|
| 313 |
+
case '1':
|
| 314 |
+
case '2':
|
| 315 |
+
case '3':
|
| 316 |
+
case '4':
|
| 317 |
+
case '5':
|
| 318 |
+
case '6':
|
| 319 |
+
case '7':
|
| 320 |
+
case '8':
|
| 321 |
+
case '9':
|
| 322 |
+
case 'E':
|
| 323 |
+
case 'e':
|
| 324 |
+
return true;
|
| 325 |
+
}
|
| 326 |
+
return false;
|
| 327 |
+
}
|
| 328 |
+
|
| 329 |
+
private function readJSONNumericChars() {
|
| 330 |
+
$strbld = array();
|
| 331 |
+
|
| 332 |
+
while (true) {
|
| 333 |
+
$ch = $this->reader_->peek();
|
| 334 |
+
|
| 335 |
+
if (!$this->isJSONNumeric($ch)) {
|
| 336 |
+
break;
|
| 337 |
+
}
|
| 338 |
+
|
| 339 |
+
$strbld[] = $this->reader_->read();
|
| 340 |
+
}
|
| 341 |
+
|
| 342 |
+
return implode("", $strbld);
|
| 343 |
+
}
|
| 344 |
+
|
| 345 |
+
private function readJSONInteger() {
|
| 346 |
+
$this->context_->read();
|
| 347 |
+
|
| 348 |
+
if ($this->context_->escapeNum()) {
|
| 349 |
+
$this->readJSONSyntaxChar(self::QUOTE);
|
| 350 |
+
}
|
| 351 |
+
|
| 352 |
+
$str = $this->readJSONNumericChars();
|
| 353 |
+
|
| 354 |
+
if ($this->context_->escapeNum()) {
|
| 355 |
+
$this->readJSONSyntaxChar(self::QUOTE);
|
| 356 |
+
}
|
| 357 |
+
|
| 358 |
+
if (!is_numeric($str)) {
|
| 359 |
+
throw new TProtocolException("Invalid data in numeric: " . $str, TProtocolException::INVALID_DATA);
|
| 360 |
+
}
|
| 361 |
+
|
| 362 |
+
return intval($str);
|
| 363 |
+
}
|
| 364 |
+
|
| 365 |
+
/**
|
| 366 |
+
* Identical to readJSONInteger but without the final cast.
|
| 367 |
+
* Needed for proper handling of i64 on 32 bit machines. Why a
|
| 368 |
+
* separate function? So we don't have to force the rest of the
|
| 369 |
+
* use cases through the extra conditional.
|
| 370 |
+
*/
|
| 371 |
+
private function readJSONIntegerAsString() {
|
| 372 |
+
$this->context_->read();
|
| 373 |
+
|
| 374 |
+
if ($this->context_->escapeNum()) {
|
| 375 |
+
$this->readJSONSyntaxChar(self::QUOTE);
|
| 376 |
+
}
|
| 377 |
+
|
| 378 |
+
$str = $this->readJSONNumericChars();
|
| 379 |
+
|
| 380 |
+
if ($this->context_->escapeNum()) {
|
| 381 |
+
$this->readJSONSyntaxChar(self::QUOTE);
|
| 382 |
+
}
|
| 383 |
+
|
| 384 |
+
if (!is_numeric($str)) {
|
| 385 |
+
throw new TProtocolException("Invalid data in numeric: " . $str, TProtocolException::INVALID_DATA);
|
| 386 |
+
}
|
| 387 |
+
|
| 388 |
+
return $str;
|
| 389 |
+
}
|
| 390 |
+
|
| 391 |
+
private function readJSONDouble() {
|
| 392 |
+
$this->context_->read();
|
| 393 |
+
|
| 394 |
+
if (substr($this->reader_->peek(), 0, 1) == self::QUOTE) {
|
| 395 |
+
$arr = $this->readJSONString(true);
|
| 396 |
+
|
| 397 |
+
if ($arr == "NaN") {
|
| 398 |
+
return NAN;
|
| 399 |
+
} else if ($arr == "Infinity") {
|
| 400 |
+
return INF;
|
| 401 |
+
} else if (!$this->context_->escapeNum()) {
|
| 402 |
+
throw new TProtocolException("Numeric data unexpectedly quoted " . $arr,
|
| 403 |
+
TProtocolException::INVALID_DATA);
|
| 404 |
+
}
|
| 405 |
+
|
| 406 |
+
return floatval($arr);
|
| 407 |
+
} else {
|
| 408 |
+
if ($this->context_->escapeNum()) {
|
| 409 |
+
$this->readJSONSyntaxChar(self::QUOTE);
|
| 410 |
+
}
|
| 411 |
+
|
| 412 |
+
return floatval($this->readJSONNumericChars());
|
| 413 |
+
}
|
| 414 |
+
}
|
| 415 |
+
|
| 416 |
+
private function readJSONBase64() {
|
| 417 |
+
$arr = $this->readJSONString(false);
|
| 418 |
+
$data = base64_decode($arr, true);
|
| 419 |
+
|
| 420 |
+
if ($data === false) {
|
| 421 |
+
throw new TProtocolException("Invalid base64 data " . $arr, TProtocolException::INVALID_DATA);
|
| 422 |
+
}
|
| 423 |
+
|
| 424 |
+
return $data;
|
| 425 |
+
}
|
| 426 |
+
|
| 427 |
+
private function readJSONObjectStart() {
|
| 428 |
+
$this->context_->read();
|
| 429 |
+
$this->readJSONSyntaxChar(self::LBRACE);
|
| 430 |
+
$this->pushContext(new PairContext($this));
|
| 431 |
+
}
|
| 432 |
+
|
| 433 |
+
private function readJSONObjectEnd() {
|
| 434 |
+
$this->readJSONSyntaxChar(self::RBRACE);
|
| 435 |
+
$this->popContext();
|
| 436 |
+
}
|
| 437 |
+
|
| 438 |
+
private function readJSONArrayStart()
|
| 439 |
+
{
|
| 440 |
+
$this->context_->read();
|
| 441 |
+
$this->readJSONSyntaxChar(self::LBRACKET);
|
| 442 |
+
$this->pushContext(new ListContext($this));
|
| 443 |
+
}
|
| 444 |
+
|
| 445 |
+
private function readJSONArrayEnd() {
|
| 446 |
+
$this->readJSONSyntaxChar(self::RBRACKET);
|
| 447 |
+
$this->popContext();
|
| 448 |
+
}
|
| 449 |
+
|
| 450 |
+
/**
|
| 451 |
+
* Writes the message header
|
| 452 |
+
*
|
| 453 |
+
* @param string $name Function name
|
| 454 |
+
* @param int $type message type TMessageType::CALL or TMessageType::REPLY
|
| 455 |
+
* @param int $seqid The sequence id of this message
|
| 456 |
+
*/
|
| 457 |
+
public function writeMessageBegin($name, $type, $seqid) {
|
| 458 |
+
$this->writeJSONArrayStart();
|
| 459 |
+
$this->writeJSONInteger(self::VERSION);
|
| 460 |
+
$this->writeJSONString($name);
|
| 461 |
+
$this->writeJSONInteger($type);
|
| 462 |
+
$this->writeJSONInteger($seqid);
|
| 463 |
+
}
|
| 464 |
+
|
| 465 |
+
/**
|
| 466 |
+
* Close the message
|
| 467 |
+
*/
|
| 468 |
+
public function writeMessageEnd() {
|
| 469 |
+
$this->writeJSONArrayEnd();
|
| 470 |
+
}
|
| 471 |
+
|
| 472 |
+
/**
|
| 473 |
+
* Writes a struct header.
|
| 474 |
+
*
|
| 475 |
+
* @param string $name Struct name
|
| 476 |
+
* @throws TException on write error
|
| 477 |
+
* @return int How many bytes written
|
| 478 |
+
*/
|
| 479 |
+
public function writeStructBegin($name) {
|
| 480 |
+
$this->writeJSONObjectStart();
|
| 481 |
+
}
|
| 482 |
+
|
| 483 |
+
/**
|
| 484 |
+
* Close a struct.
|
| 485 |
+
*
|
| 486 |
+
* @throws TException on write error
|
| 487 |
+
* @return int How many bytes written
|
| 488 |
+
*/
|
| 489 |
+
public function writeStructEnd() {
|
| 490 |
+
$this->writeJSONObjectEnd();
|
| 491 |
+
}
|
| 492 |
+
|
| 493 |
+
public function writeFieldBegin($fieldName, $fieldType, $fieldId) {
|
| 494 |
+
$this->writeJSONInteger($fieldId);
|
| 495 |
+
$this->writeJSONObjectStart();
|
| 496 |
+
$this->writeJSONString($this->getTypeNameForTypeID($fieldType));
|
| 497 |
+
}
|
| 498 |
+
|
| 499 |
+
public function writeFieldEnd() {
|
| 500 |
+
$this->writeJsonObjectEnd();
|
| 501 |
+
}
|
| 502 |
+
|
| 503 |
+
public function writeFieldStop() {
|
| 504 |
+
}
|
| 505 |
+
|
| 506 |
+
public function writeMapBegin($keyType, $valType, $size) {
|
| 507 |
+
$this->writeJSONArrayStart();
|
| 508 |
+
$this->writeJSONString($this->getTypeNameForTypeID($keyType));
|
| 509 |
+
$this->writeJSONString($this->getTypeNameForTypeID($valType));
|
| 510 |
+
$this->writeJSONInteger($size);
|
| 511 |
+
$this->writeJSONObjectStart();
|
| 512 |
+
}
|
| 513 |
+
|
| 514 |
+
public function writeMapEnd() {
|
| 515 |
+
$this->writeJSONObjectEnd();
|
| 516 |
+
$this->writeJSONArrayEnd();
|
| 517 |
+
}
|
| 518 |
+
|
| 519 |
+
public function writeListBegin($elemType, $size) {
|
| 520 |
+
$this->writeJSONArrayStart();
|
| 521 |
+
$this->writeJSONString($this->getTypeNameForTypeID($elemType));
|
| 522 |
+
$this->writeJSONInteger($size);
|
| 523 |
+
}
|
| 524 |
+
|
| 525 |
+
public function writeListEnd() {
|
| 526 |
+
$this->writeJSONArrayEnd();
|
| 527 |
+
}
|
| 528 |
+
|
| 529 |
+
public function writeSetBegin($elemType, $size) {
|
| 530 |
+
$this->writeJSONArrayStart();
|
| 531 |
+
$this->writeJSONString($this->getTypeNameForTypeID($elemType));
|
| 532 |
+
$this->writeJSONInteger($size);
|
| 533 |
+
}
|
| 534 |
+
|
| 535 |
+
public function writeSetEnd() {
|
| 536 |
+
$this->writeJSONArrayEnd();
|
| 537 |
+
}
|
| 538 |
+
|
| 539 |
+
public function writeBool($bool) {
|
| 540 |
+
$this->writeJSONInteger($bool ? 1 : 0);
|
| 541 |
+
}
|
| 542 |
+
|
| 543 |
+
public function writeByte($byte) {
|
| 544 |
+
$this->writeJSONInteger($byte);
|
| 545 |
+
}
|
| 546 |
+
|
| 547 |
+
public function writeI16($i16) {
|
| 548 |
+
$this->writeJSONInteger($i16);
|
| 549 |
+
}
|
| 550 |
+
|
| 551 |
+
public function writeI32($i32) {
|
| 552 |
+
$this->writeJSONInteger($i32);
|
| 553 |
+
}
|
| 554 |
+
|
| 555 |
+
public function writeI64($i64) {
|
| 556 |
+
$this->writeJSONInteger($i64);
|
| 557 |
+
}
|
| 558 |
+
|
| 559 |
+
public function writeDouble($dub) {
|
| 560 |
+
$this->writeJSONDouble($dub);
|
| 561 |
+
}
|
| 562 |
+
|
| 563 |
+
public function writeString($str) {
|
| 564 |
+
$this->writeJSONString($str);
|
| 565 |
+
}
|
| 566 |
+
|
| 567 |
+
/**
|
| 568 |
+
* Reads the message header
|
| 569 |
+
*
|
| 570 |
+
* @param string $name Function name
|
| 571 |
+
* @param int $type message type TMessageType::CALL or TMessageType::REPLY
|
| 572 |
+
* @parem int $seqid The sequence id of this message
|
| 573 |
+
*/
|
| 574 |
+
public function readMessageBegin(&$name, &$type, &$seqid) {
|
| 575 |
+
$this->readJSONArrayStart();
|
| 576 |
+
|
| 577 |
+
if ($this->readJSONInteger() != self::VERSION) {
|
| 578 |
+
throw new TProtocolException("Message contained bad version", TProtocolException::BAD_VERSION);
|
| 579 |
+
}
|
| 580 |
+
|
| 581 |
+
$name = $this->readJSONString(false);
|
| 582 |
+
$type = $this->readJSONInteger();
|
| 583 |
+
$seqid = $this->readJSONInteger();
|
| 584 |
+
|
| 585 |
+
return true;
|
| 586 |
+
}
|
| 587 |
+
|
| 588 |
+
/**
|
| 589 |
+
* Read the close of message
|
| 590 |
+
*/
|
| 591 |
+
public function readMessageEnd() {
|
| 592 |
+
$this->readJSONArrayEnd();
|
| 593 |
+
}
|
| 594 |
+
|
| 595 |
+
public function readStructBegin(&$name) {
|
| 596 |
+
$this->readJSONObjectStart();
|
| 597 |
+
return 0;
|
| 598 |
+
}
|
| 599 |
+
|
| 600 |
+
public function readStructEnd() {
|
| 601 |
+
$this->readJSONObjectEnd();
|
| 602 |
+
}
|
| 603 |
+
|
| 604 |
+
public function readFieldBegin(&$name, &$fieldType, &$fieldId) {
|
| 605 |
+
$ch = $this->reader_->peek();
|
| 606 |
+
$name = "";
|
| 607 |
+
|
| 608 |
+
if (substr($ch, 0, 1) == self::RBRACE) {
|
| 609 |
+
$fieldType = TType::STOP;
|
| 610 |
+
} else {
|
| 611 |
+
$fieldId = $this->readJSONInteger();
|
| 612 |
+
$this->readJSONObjectStart();
|
| 613 |
+
$fieldType = $this->getTypeIDForTypeName($this->readJSONString(false));
|
| 614 |
+
}
|
| 615 |
+
}
|
| 616 |
+
|
| 617 |
+
public function readFieldEnd() {
|
| 618 |
+
$this->readJSONObjectEnd();
|
| 619 |
+
}
|
| 620 |
+
|
| 621 |
+
public function readMapBegin(&$keyType, &$valType, &$size) {
|
| 622 |
+
$this->readJSONArrayStart();
|
| 623 |
+
$keyType = $this->getTypeIDForTypeName($this->readJSONString(false));
|
| 624 |
+
$valType = $this->getTypeIDForTypeName($this->readJSONString(false));
|
| 625 |
+
$size = $this->readJSONInteger();
|
| 626 |
+
$this->readJSONObjectStart();
|
| 627 |
+
}
|
| 628 |
+
|
| 629 |
+
public function readMapEnd() {
|
| 630 |
+
$this->readJSONObjectEnd();
|
| 631 |
+
$this->readJSONArrayEnd();
|
| 632 |
+
}
|
| 633 |
+
|
| 634 |
+
public function readListBegin(&$elemType, &$size) {
|
| 635 |
+
$this->readJSONArrayStart();
|
| 636 |
+
$elemType = $this->getTypeIDForTypeName($this->readJSONString(false));
|
| 637 |
+
$size = $this->readJSONInteger();
|
| 638 |
+
return true;
|
| 639 |
+
}
|
| 640 |
+
|
| 641 |
+
public function readListEnd() {
|
| 642 |
+
$this->readJSONArrayEnd();
|
| 643 |
+
}
|
| 644 |
+
|
| 645 |
+
public function readSetBegin(&$elemType, &$size) {
|
| 646 |
+
$this->readJSONArrayStart();
|
| 647 |
+
$elemType = $this->getTypeIDForTypeName($this->readJSONString(false));
|
| 648 |
+
$size = $this->readJSONInteger();
|
| 649 |
+
return true;
|
| 650 |
+
}
|
| 651 |
+
|
| 652 |
+
public function readSetEnd() {
|
| 653 |
+
$this->readJSONArrayEnd();
|
| 654 |
+
}
|
| 655 |
+
|
| 656 |
+
public function readBool(&$bool) {
|
| 657 |
+
$bool = $this->readJSONInteger() == 0 ? false : true;
|
| 658 |
+
return true;
|
| 659 |
+
}
|
| 660 |
+
|
| 661 |
+
public function readByte(&$byte) {
|
| 662 |
+
$byte = $this->readJSONInteger();
|
| 663 |
+
return true;
|
| 664 |
+
}
|
| 665 |
+
|
| 666 |
+
public function readI16(&$i16) {
|
| 667 |
+
$i16 = $this->readJSONInteger();
|
| 668 |
+
return true;
|
| 669 |
+
}
|
| 670 |
+
|
| 671 |
+
public function readI32(&$i32) {
|
| 672 |
+
$i32 = $this->readJSONInteger();
|
| 673 |
+
return true;
|
| 674 |
+
}
|
| 675 |
+
|
| 676 |
+
public function readI64(&$i64) {
|
| 677 |
+
if ( PHP_INT_SIZE === 4 ) {
|
| 678 |
+
$i64 = $this->readJSONIntegerAsString();
|
| 679 |
+
} else {
|
| 680 |
+
$i64 = $this->readJSONInteger();
|
| 681 |
+
}
|
| 682 |
+
return true;
|
| 683 |
+
}
|
| 684 |
+
|
| 685 |
+
public function readDouble(&$dub) {
|
| 686 |
+
$dub = $this->readJSONDouble();
|
| 687 |
+
return true;
|
| 688 |
+
}
|
| 689 |
+
|
| 690 |
+
public function readString(&$str) {
|
| 691 |
+
$str = $this->readJSONString(false);
|
| 692 |
+
return true;
|
| 693 |
+
}
|
| 694 |
+
}
|
app/code/community/Boxalino/{CemSearch/Lib/vendor → Intelligence/lib}/Thrift/Protocol/TProtocol.php
RENAMED
|
@@ -1,346 +1,346 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
/*
|
| 3 |
-
* Licensed to the Apache Software Foundation (ASF) under one
|
| 4 |
-
* or more contributor license agreements. See the NOTICE file
|
| 5 |
-
* distributed with this work for additional information
|
| 6 |
-
* regarding copyright ownership. The ASF licenses this file
|
| 7 |
-
* to you under the Apache License, Version 2.0 (the
|
| 8 |
-
* "License"); you may not use this file except in compliance
|
| 9 |
-
* with the License. You may obtain a copy of the License at
|
| 10 |
-
*
|
| 11 |
-
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
-
*
|
| 13 |
-
* Unless required by applicable law or agreed to in writing,
|
| 14 |
-
* software distributed under the License is distributed on an
|
| 15 |
-
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 16 |
-
* KIND, either express or implied. See the License for the
|
| 17 |
-
* specific language governing permissions and limitations
|
| 18 |
-
* under the License.
|
| 19 |
-
*
|
| 20 |
-
* @package thrift.protocol
|
| 21 |
-
*/
|
| 22 |
-
|
| 23 |
-
namespace Thrift\Protocol;
|
| 24 |
-
|
| 25 |
-
use Thrift\Type\TType;
|
| 26 |
-
use Thrift\Exception\TProtocolException;
|
| 27 |
-
|
| 28 |
-
/**
|
| 29 |
-
* Protocol base class module.
|
| 30 |
-
*/
|
| 31 |
-
abstract class TProtocol {
|
| 32 |
-
// The below may seem silly, but it is to get around the problem that the
|
| 33 |
-
// "instanceof" operator can only take in a T_VARIABLE and not a T_STRING
|
| 34 |
-
// or T_CONSTANT_ENCAPSED_STRING. Using "is_a()" instead of "instanceof" is
|
| 35 |
-
// a workaround but is deprecated in PHP5. This is used in the generated
|
| 36 |
-
// deserialization code.
|
| 37 |
-
static $TBINARYPROTOCOLACCELERATED = 'TBinaryProtocolAccelerated';
|
| 38 |
-
|
| 39 |
-
/**
|
| 40 |
-
* Underlying transport
|
| 41 |
-
*
|
| 42 |
-
* @var TTransport
|
| 43 |
-
*/
|
| 44 |
-
protected $trans_;
|
| 45 |
-
|
| 46 |
-
/**
|
| 47 |
-
* Constructor
|
| 48 |
-
*/
|
| 49 |
-
protected function __construct($trans) {
|
| 50 |
-
$this->trans_ = $trans;
|
| 51 |
-
}
|
| 52 |
-
|
| 53 |
-
/**
|
| 54 |
-
* Accessor for transport
|
| 55 |
-
*
|
| 56 |
-
* @return TTransport
|
| 57 |
-
*/
|
| 58 |
-
public function getTransport() {
|
| 59 |
-
return $this->trans_;
|
| 60 |
-
}
|
| 61 |
-
|
| 62 |
-
/**
|
| 63 |
-
* Writes the message header
|
| 64 |
-
*
|
| 65 |
-
* @param string $name Function name
|
| 66 |
-
* @param int $type message type TMessageType::CALL or TMessageType::REPLY
|
| 67 |
-
* @param int $seqid The sequence id of this message
|
| 68 |
-
*/
|
| 69 |
-
public abstract function writeMessageBegin($name, $type, $seqid);
|
| 70 |
-
|
| 71 |
-
/**
|
| 72 |
-
* Close the message
|
| 73 |
-
*/
|
| 74 |
-
public abstract function writeMessageEnd();
|
| 75 |
-
|
| 76 |
-
/**
|
| 77 |
-
* Writes a struct header.
|
| 78 |
-
*
|
| 79 |
-
* @param string $name Struct name
|
| 80 |
-
* @throws TException on write error
|
| 81 |
-
* @return int How many bytes written
|
| 82 |
-
*/
|
| 83 |
-
public abstract function writeStructBegin($name);
|
| 84 |
-
|
| 85 |
-
/**
|
| 86 |
-
* Close a struct.
|
| 87 |
-
*
|
| 88 |
-
* @throws TException on write error
|
| 89 |
-
* @return int How many bytes written
|
| 90 |
-
*/
|
| 91 |
-
public abstract function writeStructEnd();
|
| 92 |
-
|
| 93 |
-
/*
|
| 94 |
-
* Starts a field.
|
| 95 |
-
*
|
| 96 |
-
* @param string $name Field name
|
| 97 |
-
* @param int $type Field type
|
| 98 |
-
* @param int $fid Field id
|
| 99 |
-
* @throws TException on write error
|
| 100 |
-
* @return int How many bytes written
|
| 101 |
-
*/
|
| 102 |
-
public abstract function writeFieldBegin($fieldName, $fieldType, $fieldId);
|
| 103 |
-
|
| 104 |
-
public abstract function writeFieldEnd();
|
| 105 |
-
|
| 106 |
-
public abstract function writeFieldStop();
|
| 107 |
-
|
| 108 |
-
public abstract function writeMapBegin($keyType, $valType, $size);
|
| 109 |
-
|
| 110 |
-
public abstract function writeMapEnd();
|
| 111 |
-
|
| 112 |
-
public abstract function writeListBegin($elemType, $size);
|
| 113 |
-
|
| 114 |
-
public abstract function writeListEnd();
|
| 115 |
-
|
| 116 |
-
public abstract function writeSetBegin($elemType, $size);
|
| 117 |
-
|
| 118 |
-
public abstract function writeSetEnd();
|
| 119 |
-
|
| 120 |
-
public abstract function writeBool($bool);
|
| 121 |
-
|
| 122 |
-
public abstract function writeByte($byte);
|
| 123 |
-
|
| 124 |
-
public abstract function writeI16($i16);
|
| 125 |
-
|
| 126 |
-
public abstract function writeI32($i32);
|
| 127 |
-
|
| 128 |
-
public abstract function writeI64($i64);
|
| 129 |
-
|
| 130 |
-
public abstract function writeDouble($dub);
|
| 131 |
-
|
| 132 |
-
public abstract function writeString($str);
|
| 133 |
-
|
| 134 |
-
/**
|
| 135 |
-
* Reads the message header
|
| 136 |
-
*
|
| 137 |
-
* @param string $name Function name
|
| 138 |
-
* @param int $type message type TMessageType::CALL or TMessageType::REPLY
|
| 139 |
-
* @parem int $seqid The sequence id of this message
|
| 140 |
-
*/
|
| 141 |
-
public abstract function readMessageBegin(&$name, &$type, &$seqid);
|
| 142 |
-
|
| 143 |
-
/**
|
| 144 |
-
* Read the close of message
|
| 145 |
-
*/
|
| 146 |
-
public abstract function readMessageEnd();
|
| 147 |
-
|
| 148 |
-
public abstract function readStructBegin(&$name);
|
| 149 |
-
|
| 150 |
-
public abstract function readStructEnd();
|
| 151 |
-
|
| 152 |
-
public abstract function readFieldBegin(&$name, &$fieldType, &$fieldId);
|
| 153 |
-
|
| 154 |
-
public abstract function readFieldEnd();
|
| 155 |
-
|
| 156 |
-
public abstract function readMapBegin(&$keyType, &$valType, &$size);
|
| 157 |
-
|
| 158 |
-
public abstract function readMapEnd();
|
| 159 |
-
|
| 160 |
-
public abstract function readListBegin(&$elemType, &$size);
|
| 161 |
-
|
| 162 |
-
public abstract function readListEnd();
|
| 163 |
-
|
| 164 |
-
public abstract function readSetBegin(&$elemType, &$size);
|
| 165 |
-
|
| 166 |
-
public abstract function readSetEnd();
|
| 167 |
-
|
| 168 |
-
public abstract function readBool(&$bool);
|
| 169 |
-
|
| 170 |
-
public abstract function readByte(&$byte);
|
| 171 |
-
|
| 172 |
-
public abstract function readI16(&$i16);
|
| 173 |
-
|
| 174 |
-
public abstract function readI32(&$i32);
|
| 175 |
-
|
| 176 |
-
public abstract function readI64(&$i64);
|
| 177 |
-
|
| 178 |
-
public abstract function readDouble(&$dub);
|
| 179 |
-
|
| 180 |
-
public abstract function readString(&$str);
|
| 181 |
-
|
| 182 |
-
/**
|
| 183 |
-
* The skip function is a utility to parse over unrecognized date without
|
| 184 |
-
* causing corruption.
|
| 185 |
-
*
|
| 186 |
-
* @param TType $type What type is it
|
| 187 |
-
*/
|
| 188 |
-
public function skip($type) {
|
| 189 |
-
switch ($type) {
|
| 190 |
-
case TType::BOOL:
|
| 191 |
-
return $this->readBool($bool);
|
| 192 |
-
case TType::BYTE:
|
| 193 |
-
return $this->readByte($byte);
|
| 194 |
-
case TType::I16:
|
| 195 |
-
return $this->readI16($i16);
|
| 196 |
-
case TType::I32:
|
| 197 |
-
return $this->readI32($i32);
|
| 198 |
-
case TType::I64:
|
| 199 |
-
return $this->readI64($i64);
|
| 200 |
-
case TType::DOUBLE:
|
| 201 |
-
return $this->readDouble($dub);
|
| 202 |
-
case TType::STRING:
|
| 203 |
-
return $this->readString($str);
|
| 204 |
-
case TType::STRUCT:
|
| 205 |
-
{
|
| 206 |
-
$result = $this->readStructBegin($name);
|
| 207 |
-
while (true) {
|
| 208 |
-
$result += $this->readFieldBegin($name, $ftype, $fid);
|
| 209 |
-
if ($ftype == TType::STOP) {
|
| 210 |
-
break;
|
| 211 |
-
}
|
| 212 |
-
$result += $this->skip($ftype);
|
| 213 |
-
$result += $this->readFieldEnd();
|
| 214 |
-
}
|
| 215 |
-
$result += $this->readStructEnd();
|
| 216 |
-
return $result;
|
| 217 |
-
}
|
| 218 |
-
case TType::MAP:
|
| 219 |
-
{
|
| 220 |
-
$result = $this->readMapBegin($keyType, $valType, $size);
|
| 221 |
-
for ($i = 0; $i < $size; $i++) {
|
| 222 |
-
$result += $this->skip($keyType);
|
| 223 |
-
$result += $this->skip($valType);
|
| 224 |
-
}
|
| 225 |
-
$result += $this->readMapEnd();
|
| 226 |
-
return $result;
|
| 227 |
-
}
|
| 228 |
-
case TType::SET:
|
| 229 |
-
{
|
| 230 |
-
$result = $this->readSetBegin($elemType, $size);
|
| 231 |
-
for ($i = 0; $i < $size; $i++) {
|
| 232 |
-
$result += $this->skip($elemType);
|
| 233 |
-
}
|
| 234 |
-
$result += $this->readSetEnd();
|
| 235 |
-
return $result;
|
| 236 |
-
}
|
| 237 |
-
case TType::LST:
|
| 238 |
-
{
|
| 239 |
-
$result = $this->readListBegin($elemType, $size);
|
| 240 |
-
for ($i = 0; $i < $size; $i++) {
|
| 241 |
-
$result += $this->skip($elemType);
|
| 242 |
-
}
|
| 243 |
-
$result += $this->readListEnd();
|
| 244 |
-
return $result;
|
| 245 |
-
}
|
| 246 |
-
default:
|
| 247 |
-
throw new TProtocolException('Unknown field type: '.$type,
|
| 248 |
-
TProtocolException::INVALID_DATA);
|
| 249 |
-
}
|
| 250 |
-
}
|
| 251 |
-
|
| 252 |
-
/**
|
| 253 |
-
* Utility for skipping binary data
|
| 254 |
-
*
|
| 255 |
-
* @param TTransport $itrans TTransport object
|
| 256 |
-
* @param int $type Field type
|
| 257 |
-
*/
|
| 258 |
-
public static function skipBinary($itrans, $type) {
|
| 259 |
-
switch ($type) {
|
| 260 |
-
case TType::BOOL:
|
| 261 |
-
return $itrans->readAll(1);
|
| 262 |
-
case TType::BYTE:
|
| 263 |
-
return $itrans->readAll(1);
|
| 264 |
-
case TType::I16:
|
| 265 |
-
return $itrans->readAll(2);
|
| 266 |
-
case TType::I32:
|
| 267 |
-
return $itrans->readAll(4);
|
| 268 |
-
case TType::I64:
|
| 269 |
-
return $itrans->readAll(8);
|
| 270 |
-
case TType::DOUBLE:
|
| 271 |
-
return $itrans->readAll(8);
|
| 272 |
-
case TType::STRING:
|
| 273 |
-
$len = unpack('N', $itrans->readAll(4));
|
| 274 |
-
$len = $len[1];
|
| 275 |
-
if ($len > 0x7fffffff) {
|
| 276 |
-
$len = 0 - (($len - 1) ^ 0xffffffff);
|
| 277 |
-
}
|
| 278 |
-
return 4 + $itrans->readAll($len);
|
| 279 |
-
case TType::STRUCT:
|
| 280 |
-
{
|
| 281 |
-
$result = 0;
|
| 282 |
-
while (true) {
|
| 283 |
-
$ftype = 0;
|
| 284 |
-
$fid = 0;
|
| 285 |
-
$data = $itrans->readAll(1);
|
| 286 |
-
$arr = unpack('c', $data);
|
| 287 |
-
$ftype = $arr[1];
|
| 288 |
-
if ($ftype == TType::STOP) {
|
| 289 |
-
break;
|
| 290 |
-
}
|
| 291 |
-
// I16 field id
|
| 292 |
-
$result += $itrans->readAll(2);
|
| 293 |
-
$result += self::skipBinary($itrans, $ftype);
|
| 294 |
-
}
|
| 295 |
-
return $result;
|
| 296 |
-
}
|
| 297 |
-
case TType::MAP:
|
| 298 |
-
{
|
| 299 |
-
// Ktype
|
| 300 |
-
$data = $itrans->readAll(1);
|
| 301 |
-
$arr = unpack('c', $data);
|
| 302 |
-
$ktype = $arr[1];
|
| 303 |
-
// Vtype
|
| 304 |
-
$data = $itrans->readAll(1);
|
| 305 |
-
$arr = unpack('c', $data);
|
| 306 |
-
$vtype = $arr[1];
|
| 307 |
-
// Size
|
| 308 |
-
$data = $itrans->readAll(4);
|
| 309 |
-
$arr = unpack('N', $data);
|
| 310 |
-
$size = $arr[1];
|
| 311 |
-
if ($size > 0x7fffffff) {
|
| 312 |
-
$size = 0 - (($size - 1) ^ 0xffffffff);
|
| 313 |
-
}
|
| 314 |
-
$result = 6;
|
| 315 |
-
for ($i = 0; $i < $size; $i++) {
|
| 316 |
-
$result += self::skipBinary($itrans, $ktype);
|
| 317 |
-
$result += self::skipBinary($itrans, $vtype);
|
| 318 |
-
}
|
| 319 |
-
return $result;
|
| 320 |
-
}
|
| 321 |
-
case TType::SET:
|
| 322 |
-
case TType::LST:
|
| 323 |
-
{
|
| 324 |
-
// Vtype
|
| 325 |
-
$data = $itrans->readAll(1);
|
| 326 |
-
$arr = unpack('c', $data);
|
| 327 |
-
$vtype = $arr[1];
|
| 328 |
-
// Size
|
| 329 |
-
$data = $itrans->readAll(4);
|
| 330 |
-
$arr = unpack('N', $data);
|
| 331 |
-
$size = $arr[1];
|
| 332 |
-
if ($size > 0x7fffffff) {
|
| 333 |
-
$size = 0 - (($size - 1) ^ 0xffffffff);
|
| 334 |
-
}
|
| 335 |
-
$result = 5;
|
| 336 |
-
for ($i = 0; $i < $size; $i++) {
|
| 337 |
-
$result += self::skipBinary($itrans, $vtype);
|
| 338 |
-
}
|
| 339 |
-
return $result;
|
| 340 |
-
}
|
| 341 |
-
default:
|
| 342 |
-
throw new TProtocolException('Unknown field type: '.$type,
|
| 343 |
-
TProtocolException::INVALID_DATA);
|
| 344 |
-
}
|
| 345 |
-
}
|
| 346 |
-
}
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Licensed to the Apache Software Foundation (ASF) under one
|
| 4 |
+
* or more contributor license agreements. See the NOTICE file
|
| 5 |
+
* distributed with this work for additional information
|
| 6 |
+
* regarding copyright ownership. The ASF licenses this file
|
| 7 |
+
* to you under the Apache License, Version 2.0 (the
|
| 8 |
+
* "License"); you may not use this file except in compliance
|
| 9 |
+
* with the License. You may obtain a copy of the License at
|
| 10 |
+
*
|
| 11 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
+
*
|
| 13 |
+
* Unless required by applicable law or agreed to in writing,
|
| 14 |
+
* software distributed under the License is distributed on an
|
| 15 |
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 16 |
+
* KIND, either express or implied. See the License for the
|
| 17 |
+
* specific language governing permissions and limitations
|
| 18 |
+
* under the License.
|
| 19 |
+
*
|
| 20 |
+
* @package thrift.protocol
|
| 21 |
+
*/
|
| 22 |
+
|
| 23 |
+
namespace Thrift\Protocol;
|
| 24 |
+
|
| 25 |
+
use Thrift\Type\TType;
|
| 26 |
+
use Thrift\Exception\TProtocolException;
|
| 27 |
+
|
| 28 |
+
/**
|
| 29 |
+
* Protocol base class module.
|
| 30 |
+
*/
|
| 31 |
+
abstract class TProtocol {
|
| 32 |
+
// The below may seem silly, but it is to get around the problem that the
|
| 33 |
+
// "instanceof" operator can only take in a T_VARIABLE and not a T_STRING
|
| 34 |
+
// or T_CONSTANT_ENCAPSED_STRING. Using "is_a()" instead of "instanceof" is
|
| 35 |
+
// a workaround but is deprecated in PHP5. This is used in the generated
|
| 36 |
+
// deserialization code.
|
| 37 |
+
static $TBINARYPROTOCOLACCELERATED = 'TBinaryProtocolAccelerated';
|
| 38 |
+
|
| 39 |
+
/**
|
| 40 |
+
* Underlying transport
|
| 41 |
+
*
|
| 42 |
+
* @var TTransport
|
| 43 |
+
*/
|
| 44 |
+
protected $trans_;
|
| 45 |
+
|
| 46 |
+
/**
|
| 47 |
+
* Constructor
|
| 48 |
+
*/
|
| 49 |
+
protected function __construct($trans) {
|
| 50 |
+
$this->trans_ = $trans;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
/**
|
| 54 |
+
* Accessor for transport
|
| 55 |
+
*
|
| 56 |
+
* @return TTransport
|
| 57 |
+
*/
|
| 58 |
+
public function getTransport() {
|
| 59 |
+
return $this->trans_;
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
/**
|
| 63 |
+
* Writes the message header
|
| 64 |
+
*
|
| 65 |
+
* @param string $name Function name
|
| 66 |
+
* @param int $type message type TMessageType::CALL or TMessageType::REPLY
|
| 67 |
+
* @param int $seqid The sequence id of this message
|
| 68 |
+
*/
|
| 69 |
+
public abstract function writeMessageBegin($name, $type, $seqid);
|
| 70 |
+
|
| 71 |
+
/**
|
| 72 |
+
* Close the message
|
| 73 |
+
*/
|
| 74 |
+
public abstract function writeMessageEnd();
|
| 75 |
+
|
| 76 |
+
/**
|
| 77 |
+
* Writes a struct header.
|
| 78 |
+
*
|
| 79 |
+
* @param string $name Struct name
|
| 80 |
+
* @throws TException on write error
|
| 81 |
+
* @return int How many bytes written
|
| 82 |
+
*/
|
| 83 |
+
public abstract function writeStructBegin($name);
|
| 84 |
+
|
| 85 |
+
/**
|
| 86 |
+
* Close a struct.
|
| 87 |
+
*
|
| 88 |
+
* @throws TException on write error
|
| 89 |
+
* @return int How many bytes written
|
| 90 |
+
*/
|
| 91 |
+
public abstract function writeStructEnd();
|
| 92 |
+
|
| 93 |
+
/*
|
| 94 |
+
* Starts a field.
|
| 95 |
+
*
|
| 96 |
+
* @param string $name Field name
|
| 97 |
+
* @param int $type Field type
|
| 98 |
+
* @param int $fid Field id
|
| 99 |
+
* @throws TException on write error
|
| 100 |
+
* @return int How many bytes written
|
| 101 |
+
*/
|
| 102 |
+
public abstract function writeFieldBegin($fieldName, $fieldType, $fieldId);
|
| 103 |
+
|
| 104 |
+
public abstract function writeFieldEnd();
|
| 105 |
+
|
| 106 |
+
public abstract function writeFieldStop();
|
| 107 |
+
|
| 108 |
+
public abstract function writeMapBegin($keyType, $valType, $size);
|
| 109 |
+
|
| 110 |
+
public abstract function writeMapEnd();
|
| 111 |
+
|
| 112 |
+
public abstract function writeListBegin($elemType, $size);
|
| 113 |
+
|
| 114 |
+
public abstract function writeListEnd();
|
| 115 |
+
|
| 116 |
+
public abstract function writeSetBegin($elemType, $size);
|
| 117 |
+
|
| 118 |
+
public abstract function writeSetEnd();
|
| 119 |
+
|
| 120 |
+
public abstract function writeBool($bool);
|
| 121 |
+
|
| 122 |
+
public abstract function writeByte($byte);
|
| 123 |
+
|
| 124 |
+
public abstract function writeI16($i16);
|
| 125 |
+
|
| 126 |
+
public abstract function writeI32($i32);
|
| 127 |
+
|
| 128 |
+
public abstract function writeI64($i64);
|
| 129 |
+
|
| 130 |
+
public abstract function writeDouble($dub);
|
| 131 |
+
|
| 132 |
+
public abstract function writeString($str);
|
| 133 |
+
|
| 134 |
+
/**
|
| 135 |
+
* Reads the message header
|
| 136 |
+
*
|
| 137 |
+
* @param string $name Function name
|
| 138 |
+
* @param int $type message type TMessageType::CALL or TMessageType::REPLY
|
| 139 |
+
* @parem int $seqid The sequence id of this message
|
| 140 |
+
*/
|
| 141 |
+
public abstract function readMessageBegin(&$name, &$type, &$seqid);
|
| 142 |
+
|
| 143 |
+
/**
|
| 144 |
+
* Read the close of message
|
| 145 |
+
*/
|
| 146 |
+
public abstract function readMessageEnd();
|
| 147 |
+
|
| 148 |
+
public abstract function readStructBegin(&$name);
|
| 149 |
+
|
| 150 |
+
public abstract function readStructEnd();
|
| 151 |
+
|
| 152 |
+
public abstract function readFieldBegin(&$name, &$fieldType, &$fieldId);
|
| 153 |
+
|
| 154 |
+
public abstract function readFieldEnd();
|
| 155 |
+
|
| 156 |
+
public abstract function readMapBegin(&$keyType, &$valType, &$size);
|
| 157 |
+
|
| 158 |
+
public abstract function readMapEnd();
|
| 159 |
+
|
| 160 |
+
public abstract function readListBegin(&$elemType, &$size);
|
| 161 |
+
|
| 162 |
+
public abstract function readListEnd();
|
| 163 |
+
|
| 164 |
+
public abstract function readSetBegin(&$elemType, &$size);
|
| 165 |
+
|
| 166 |
+
public abstract function readSetEnd();
|
| 167 |
+
|
| 168 |
+
public abstract function readBool(&$bool);
|
| 169 |
+
|
| 170 |
+
public abstract function readByte(&$byte);
|
| 171 |
+
|
| 172 |
+
public abstract function readI16(&$i16);
|
| 173 |
+
|
| 174 |
+
public abstract function readI32(&$i32);
|
| 175 |
+
|
| 176 |
+
public abstract function readI64(&$i64);
|
| 177 |
+
|
| 178 |
+
public abstract function readDouble(&$dub);
|
| 179 |
+
|
| 180 |
+
public abstract function readString(&$str);
|
| 181 |
+
|
| 182 |
+
/**
|
| 183 |
+
* The skip function is a utility to parse over unrecognized date without
|
| 184 |
+
* causing corruption.
|
| 185 |
+
*
|
| 186 |
+
* @param TType $type What type is it
|
| 187 |
+
*/
|
| 188 |
+
public function skip($type) {
|
| 189 |
+
switch ($type) {
|
| 190 |
+
case TType::BOOL:
|
| 191 |
+
return $this->readBool($bool);
|
| 192 |
+
case TType::BYTE:
|
| 193 |
+
return $this->readByte($byte);
|
| 194 |
+
case TType::I16:
|
| 195 |
+
return $this->readI16($i16);
|
| 196 |
+
case TType::I32:
|
| 197 |
+
return $this->readI32($i32);
|
| 198 |
+
case TType::I64:
|
| 199 |
+
return $this->readI64($i64);
|
| 200 |
+
case TType::DOUBLE:
|
| 201 |
+
return $this->readDouble($dub);
|
| 202 |
+
case TType::STRING:
|
| 203 |
+
return $this->readString($str);
|
| 204 |
+
case TType::STRUCT:
|
| 205 |
+
{
|
| 206 |
+
$result = $this->readStructBegin($name);
|
| 207 |
+
while (true) {
|
| 208 |
+
$result += $this->readFieldBegin($name, $ftype, $fid);
|
| 209 |
+
if ($ftype == TType::STOP) {
|
| 210 |
+
break;
|
| 211 |
+
}
|
| 212 |
+
$result += $this->skip($ftype);
|
| 213 |
+
$result += $this->readFieldEnd();
|
| 214 |
+
}
|
| 215 |
+
$result += $this->readStructEnd();
|
| 216 |
+
return $result;
|
| 217 |
+
}
|
| 218 |
+
case TType::MAP:
|
| 219 |
+
{
|
| 220 |
+
$result = $this->readMapBegin($keyType, $valType, $size);
|
| 221 |
+
for ($i = 0; $i < $size; $i++) {
|
| 222 |
+
$result += $this->skip($keyType);
|
| 223 |
+
$result += $this->skip($valType);
|
| 224 |
+
}
|
| 225 |
+
$result += $this->readMapEnd();
|
| 226 |
+
return $result;
|
| 227 |
+
}
|
| 228 |
+
case TType::SET:
|
| 229 |
+
{
|
| 230 |
+
$result = $this->readSetBegin($elemType, $size);
|
| 231 |
+
for ($i = 0; $i < $size; $i++) {
|
| 232 |
+
$result += $this->skip($elemType);
|
| 233 |
+
}
|
| 234 |
+
$result += $this->readSetEnd();
|
| 235 |
+
return $result;
|
| 236 |
+
}
|
| 237 |
+
case TType::LST:
|
| 238 |
+
{
|
| 239 |
+
$result = $this->readListBegin($elemType, $size);
|
| 240 |
+
for ($i = 0; $i < $size; $i++) {
|
| 241 |
+
$result += $this->skip($elemType);
|
| 242 |
+
}
|
| 243 |
+
$result += $this->readListEnd();
|
| 244 |
+
return $result;
|
| 245 |
+
}
|
| 246 |
+
default:
|
| 247 |
+
throw new TProtocolException('Unknown field type: '.$type,
|
| 248 |
+
TProtocolException::INVALID_DATA);
|
| 249 |
+
}
|
| 250 |
+
}
|
| 251 |
+
|
| 252 |
+
/**
|
| 253 |
+
* Utility for skipping binary data
|
| 254 |
+
*
|
| 255 |
+
* @param TTransport $itrans TTransport object
|
| 256 |
+
* @param int $type Field type
|
| 257 |
+
*/
|
| 258 |
+
public static function skipBinary($itrans, $type) {
|
| 259 |
+
switch ($type) {
|
| 260 |
+
case TType::BOOL:
|
| 261 |
+
return $itrans->readAll(1);
|
| 262 |
+
case TType::BYTE:
|
| 263 |
+
return $itrans->readAll(1);
|
| 264 |
+
case TType::I16:
|
| 265 |
+
return $itrans->readAll(2);
|
| 266 |
+
case TType::I32:
|
| 267 |
+
return $itrans->readAll(4);
|
| 268 |
+
case TType::I64:
|
| 269 |
+
return $itrans->readAll(8);
|
| 270 |
+
case TType::DOUBLE:
|
| 271 |
+
return $itrans->readAll(8);
|
| 272 |
+
case TType::STRING:
|
| 273 |
+
$len = unpack('N', $itrans->readAll(4));
|
| 274 |
+
$len = $len[1];
|
| 275 |
+
if ($len > 0x7fffffff) {
|
| 276 |
+
$len = 0 - (($len - 1) ^ 0xffffffff);
|
| 277 |
+
}
|
| 278 |
+
return 4 + $itrans->readAll($len);
|
| 279 |
+
case TType::STRUCT:
|
| 280 |
+
{
|
| 281 |
+
$result = 0;
|
| 282 |
+
while (true) {
|
| 283 |
+
$ftype = 0;
|
| 284 |
+
$fid = 0;
|
| 285 |
+
$data = $itrans->readAll(1);
|
| 286 |
+
$arr = unpack('c', $data);
|
| 287 |
+
$ftype = $arr[1];
|
| 288 |
+
if ($ftype == TType::STOP) {
|
| 289 |
+
break;
|
| 290 |
+
}
|
| 291 |
+
// I16 field id
|
| 292 |
+
$result += $itrans->readAll(2);
|
| 293 |
+
$result += self::skipBinary($itrans, $ftype);
|
| 294 |
+
}
|
| 295 |
+
return $result;
|
| 296 |
+
}
|
| 297 |
+
case TType::MAP:
|
| 298 |
+
{
|
| 299 |
+
// Ktype
|
| 300 |
+
$data = $itrans->readAll(1);
|
| 301 |
+
$arr = unpack('c', $data);
|
| 302 |
+
$ktype = $arr[1];
|
| 303 |
+
// Vtype
|
| 304 |
+
$data = $itrans->readAll(1);
|
| 305 |
+
$arr = unpack('c', $data);
|
| 306 |
+
$vtype = $arr[1];
|
| 307 |
+
// Size
|
| 308 |
+
$data = $itrans->readAll(4);
|
| 309 |
+
$arr = unpack('N', $data);
|
| 310 |
+
$size = $arr[1];
|
| 311 |
+
if ($size > 0x7fffffff) {
|
| 312 |
+
$size = 0 - (($size - 1) ^ 0xffffffff);
|
| 313 |
+
}
|
| 314 |
+
$result = 6;
|
| 315 |
+
for ($i = 0; $i < $size; $i++) {
|
| 316 |
+
$result += self::skipBinary($itrans, $ktype);
|
| 317 |
+
$result += self::skipBinary($itrans, $vtype);
|
| 318 |
+
}
|
| 319 |
+
return $result;
|
| 320 |
+
}
|
| 321 |
+
case TType::SET:
|
| 322 |
+
case TType::LST:
|
| 323 |
+
{
|
| 324 |
+
// Vtype
|
| 325 |
+
$data = $itrans->readAll(1);
|
| 326 |
+
$arr = unpack('c', $data);
|
| 327 |
+
$vtype = $arr[1];
|
| 328 |
+
// Size
|
| 329 |
+
$data = $itrans->readAll(4);
|
| 330 |
+
$arr = unpack('N', $data);
|
| 331 |
+
$size = $arr[1];
|
| 332 |
+
if ($size > 0x7fffffff) {
|
| 333 |
+
$size = 0 - (($size - 1) ^ 0xffffffff);
|
| 334 |
+
}
|
| 335 |
+
$result = 5;
|
| 336 |
+
for ($i = 0; $i < $size; $i++) {
|
| 337 |
+
$result += self::skipBinary($itrans, $vtype);
|
| 338 |
+
}
|
| 339 |
+
return $result;
|
| 340 |
+
}
|
| 341 |
+
default:
|
| 342 |
+
throw new TProtocolException('Unknown field type: '.$type,
|
| 343 |
+
TProtocolException::INVALID_DATA);
|
| 344 |
+
}
|
| 345 |
+
}
|
| 346 |
+
}
|
app/code/community/Boxalino/{CemSearch/Lib/vendor → Intelligence/lib}/Thrift/Serializer/TBinarySerializer.php
RENAMED
|
@@ -1,73 +1,73 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
/*
|
| 3 |
-
* Licensed to the Apache Software Foundation (ASF) under one
|
| 4 |
-
* or more contributor license agreements. See the NOTICE file
|
| 5 |
-
* distributed with this work for additional information
|
| 6 |
-
* regarding copyright ownership. The ASF licenses this file
|
| 7 |
-
* to you under the Apache License, Version 2.0 (the
|
| 8 |
-
* "License"); you may not use this file except in compliance
|
| 9 |
-
* with the License. You may obtain a copy of the License at
|
| 10 |
-
*
|
| 11 |
-
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
-
*
|
| 13 |
-
* Unless required by applicable law or agreed to in writing,
|
| 14 |
-
* software distributed under the License is distributed on an
|
| 15 |
-
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 16 |
-
* KIND, either express or implied. See the License for the
|
| 17 |
-
* specific language governing permissions and limitations
|
| 18 |
-
* under the License.
|
| 19 |
-
*
|
| 20 |
-
* @package thrift.protocol
|
| 21 |
-
* @author: rmarin (marin.radu@facebook.com)
|
| 22 |
-
*/
|
| 23 |
-
|
| 24 |
-
namespace Thrift\Serializer;
|
| 25 |
-
|
| 26 |
-
use Thrift\Transport\TMemoryBuffer;
|
| 27 |
-
use Thrift\Protocol\TBinaryProtocolAccelerated;
|
| 28 |
-
use Thrift\Type\TMessageType;
|
| 29 |
-
|
| 30 |
-
/**
|
| 31 |
-
* Utility class for serializing and deserializing
|
| 32 |
-
* a thrift object using TBinaryProtocolAccelerated.
|
| 33 |
-
*/
|
| 34 |
-
class TBinarySerializer {
|
| 35 |
-
|
| 36 |
-
// NOTE(rmarin): Because thrift_protocol_write_binary
|
| 37 |
-
// adds a begin message prefix, you cannot specify
|
| 38 |
-
// a transport in which to serialize an object. It has to
|
| 39 |
-
// be a string. Otherwise we will break the compatibility with
|
| 40 |
-
// normal deserialization.
|
| 41 |
-
public static function serialize($object) {
|
| 42 |
-
$transport = new TMemoryBuffer();
|
| 43 |
-
$protocol = new TBinaryProtocolAccelerated($transport);
|
| 44 |
-
if (function_exists('thrift_protocol_write_binary')) {
|
| 45 |
-
thrift_protocol_write_binary($protocol, $object->getName(),
|
| 46 |
-
TMessageType::REPLY, $object,
|
| 47 |
-
0, $protocol->isStrictWrite());
|
| 48 |
-
|
| 49 |
-
$protocol->readMessageBegin($unused_name, $unused_type,
|
| 50 |
-
$unused_seqid);
|
| 51 |
-
} else {
|
| 52 |
-
$object->write($protocol);
|
| 53 |
-
}
|
| 54 |
-
$protocol->getTransport()->flush();
|
| 55 |
-
return $transport->getBuffer();
|
| 56 |
-
}
|
| 57 |
-
|
| 58 |
-
public static function deserialize($string_object, $class_name) {
|
| 59 |
-
$transport = new TMemoryBuffer();
|
| 60 |
-
$protocol = new TBinaryProtocolAccelerated($transport);
|
| 61 |
-
if (function_exists('thrift_protocol_read_binary')) {
|
| 62 |
-
$protocol->writeMessageBegin('', TMessageType::REPLY, 0);
|
| 63 |
-
$transport->write($string_object);
|
| 64 |
-
return thrift_protocol_read_binary($protocol, $class_name,
|
| 65 |
-
$protocol->isStrictRead());
|
| 66 |
-
} else {
|
| 67 |
-
$transport->write($string_object);
|
| 68 |
-
$object = new $class_name();
|
| 69 |
-
$object->read($protocol);
|
| 70 |
-
return $object;
|
| 71 |
-
}
|
| 72 |
-
}
|
| 73 |
-
}
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Licensed to the Apache Software Foundation (ASF) under one
|
| 4 |
+
* or more contributor license agreements. See the NOTICE file
|
| 5 |
+
* distributed with this work for additional information
|
| 6 |
+
* regarding copyright ownership. The ASF licenses this file
|
| 7 |
+
* to you under the Apache License, Version 2.0 (the
|
| 8 |
+
* "License"); you may not use this file except in compliance
|
| 9 |
+
* with the License. You may obtain a copy of the License at
|
| 10 |
+
*
|
| 11 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
+
*
|
| 13 |
+
* Unless required by applicable law or agreed to in writing,
|
| 14 |
+
* software distributed under the License is distributed on an
|
| 15 |
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 16 |
+
* KIND, either express or implied. See the License for the
|
| 17 |
+
* specific language governing permissions and limitations
|
| 18 |
+
* under the License.
|
| 19 |
+
*
|
| 20 |
+
* @package thrift.protocol
|
| 21 |
+
* @author: rmarin (marin.radu@facebook.com)
|
| 22 |
+
*/
|
| 23 |
+
|
| 24 |
+
namespace Thrift\Serializer;
|
| 25 |
+
|
| 26 |
+
use Thrift\Transport\TMemoryBuffer;
|
| 27 |
+
use Thrift\Protocol\TBinaryProtocolAccelerated;
|
| 28 |
+
use Thrift\Type\TMessageType;
|
| 29 |
+
|
| 30 |
+
/**
|
| 31 |
+
* Utility class for serializing and deserializing
|
| 32 |
+
* a thrift object using TBinaryProtocolAccelerated.
|
| 33 |
+
*/
|
| 34 |
+
class TBinarySerializer {
|
| 35 |
+
|
| 36 |
+
// NOTE(rmarin): Because thrift_protocol_write_binary
|
| 37 |
+
// adds a begin message prefix, you cannot specify
|
| 38 |
+
// a transport in which to serialize an object. It has to
|
| 39 |
+
// be a string. Otherwise we will break the compatibility with
|
| 40 |
+
// normal deserialization.
|
| 41 |
+
public static function serialize($object) {
|
| 42 |
+
$transport = new TMemoryBuffer();
|
| 43 |
+
$protocol = new TBinaryProtocolAccelerated($transport);
|
| 44 |
+
if (function_exists('thrift_protocol_write_binary')) {
|
| 45 |
+
thrift_protocol_write_binary($protocol, $object->getName(),
|
| 46 |
+
TMessageType::REPLY, $object,
|
| 47 |
+
0, $protocol->isStrictWrite());
|
| 48 |
+
|
| 49 |
+
$protocol->readMessageBegin($unused_name, $unused_type,
|
| 50 |
+
$unused_seqid);
|
| 51 |
+
} else {
|
| 52 |
+
$object->write($protocol);
|
| 53 |
+
}
|
| 54 |
+
$protocol->getTransport()->flush();
|
| 55 |
+
return $transport->getBuffer();
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
public static function deserialize($string_object, $class_name) {
|
| 59 |
+
$transport = new TMemoryBuffer();
|
| 60 |
+
$protocol = new TBinaryProtocolAccelerated($transport);
|
| 61 |
+
if (function_exists('thrift_protocol_read_binary')) {
|
| 62 |
+
$protocol->writeMessageBegin('', TMessageType::REPLY, 0);
|
| 63 |
+
$transport->write($string_object);
|
| 64 |
+
return thrift_protocol_read_binary($protocol, $class_name,
|
| 65 |
+
$protocol->isStrictRead());
|
| 66 |
+
} else {
|
| 67 |
+
$transport->write($string_object);
|
| 68 |
+
$object = new $class_name();
|
| 69 |
+
$object->read($protocol);
|
| 70 |
+
return $object;
|
| 71 |
+
}
|
| 72 |
+
}
|
| 73 |
+
}
|
app/code/community/Boxalino/{CemSearch/Lib/vendor → Intelligence/lib}/Thrift/Server/TForkingServer.php
RENAMED
|
@@ -1,119 +1,119 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
|
| 3 |
-
namespace Thrift\Server;
|
| 4 |
-
|
| 5 |
-
use Thrift\Server\TServer;
|
| 6 |
-
use Thrift\Transport\TTransport;
|
| 7 |
-
use Thrift\Exception\TException;
|
| 8 |
-
use Thrift\Exception\TTransportException;
|
| 9 |
-
|
| 10 |
-
/**
|
| 11 |
-
* A forking implementation of a Thrift server.
|
| 12 |
-
*
|
| 13 |
-
* @package thrift.server
|
| 14 |
-
*/
|
| 15 |
-
class TForkingServer extends TServer {
|
| 16 |
-
/**
|
| 17 |
-
* Flag for the main serving loop
|
| 18 |
-
*
|
| 19 |
-
* @var bool
|
| 20 |
-
*/
|
| 21 |
-
private $stop_ = false;
|
| 22 |
-
|
| 23 |
-
/**
|
| 24 |
-
* List of children.
|
| 25 |
-
*
|
| 26 |
-
* @var array
|
| 27 |
-
*/
|
| 28 |
-
protected $children_ = array();
|
| 29 |
-
|
| 30 |
-
/**
|
| 31 |
-
* Listens for new client using the supplied
|
| 32 |
-
* transport. We fork when a new connection
|
| 33 |
-
* arrives.
|
| 34 |
-
*
|
| 35 |
-
* @return void
|
| 36 |
-
*/
|
| 37 |
-
public function serve() {
|
| 38 |
-
$this->transport_->listen();
|
| 39 |
-
|
| 40 |
-
while (!$this->stop_) {
|
| 41 |
-
try {
|
| 42 |
-
$transport = $this->transport_->accept();
|
| 43 |
-
|
| 44 |
-
if ($transport != null) {
|
| 45 |
-
$pid = pcntl_fork();
|
| 46 |
-
|
| 47 |
-
if ($pid > 0) {
|
| 48 |
-
$this->handleParent($transport, $pid);
|
| 49 |
-
}
|
| 50 |
-
else if ($pid === 0) {
|
| 51 |
-
$this->handleChild($transport);
|
| 52 |
-
}
|
| 53 |
-
else {
|
| 54 |
-
throw new TException('Failed to fork');
|
| 55 |
-
}
|
| 56 |
-
}
|
| 57 |
-
}
|
| 58 |
-
catch (TTransportException $e) { }
|
| 59 |
-
|
| 60 |
-
$this->collectChildren();
|
| 61 |
-
}
|
| 62 |
-
}
|
| 63 |
-
|
| 64 |
-
/**
|
| 65 |
-
* Code run by the parent
|
| 66 |
-
*
|
| 67 |
-
* @param TTransport $transport
|
| 68 |
-
* @param int $pid
|
| 69 |
-
* @return void
|
| 70 |
-
*/
|
| 71 |
-
private function handleParent(TTransport $transport, $pid) {
|
| 72 |
-
$this->children_[$pid] = $transport;
|
| 73 |
-
}
|
| 74 |
-
|
| 75 |
-
/**
|
| 76 |
-
* Code run by the child.
|
| 77 |
-
*
|
| 78 |
-
* @param TTransport $transport
|
| 79 |
-
* @return void
|
| 80 |
-
*/
|
| 81 |
-
private function handleChild(TTransport $transport) {
|
| 82 |
-
try {
|
| 83 |
-
$inputTransport = $this->inputTransportFactory_->getTransport($transport);
|
| 84 |
-
$outputTransport = $this->outputTransportFactory_->getTransport($transport);
|
| 85 |
-
$inputProtocol = $this->inputProtocolFactory_->getProtocol($inputTransport);
|
| 86 |
-
$outputProtocol = $this->outputProtocolFactory_->getProtocol($outputTransport);
|
| 87 |
-
while ($this->processor_->process($inputProtocol, $outputProtocol)) { }
|
| 88 |
-
@$transport->close();
|
| 89 |
-
}
|
| 90 |
-
catch (TTransportException $e) { }
|
| 91 |
-
|
| 92 |
-
exit(0);
|
| 93 |
-
}
|
| 94 |
-
|
| 95 |
-
/**
|
| 96 |
-
* Collects any children we may have
|
| 97 |
-
*
|
| 98 |
-
* @return void
|
| 99 |
-
*/
|
| 100 |
-
private function collectChildren() {
|
| 101 |
-
foreach ($this->children_ as $pid => $transport) {
|
| 102 |
-
if (pcntl_waitpid($pid, $status, WNOHANG) > 0) {
|
| 103 |
-
unset($this->children_[$pid]);
|
| 104 |
-
if ($transport) @$transport->close();
|
| 105 |
-
}
|
| 106 |
-
}
|
| 107 |
-
}
|
| 108 |
-
|
| 109 |
-
/**
|
| 110 |
-
* Stops the server running. Kills the transport
|
| 111 |
-
* and then stops the main serving loop
|
| 112 |
-
*
|
| 113 |
-
* @return void
|
| 114 |
-
*/
|
| 115 |
-
public function stop() {
|
| 116 |
-
$this->transport_->close();
|
| 117 |
-
$this->stop_ = true;
|
| 118 |
-
}
|
| 119 |
-
}
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
namespace Thrift\Server;
|
| 4 |
+
|
| 5 |
+
use Thrift\Server\TServer;
|
| 6 |
+
use Thrift\Transport\TTransport;
|
| 7 |
+
use Thrift\Exception\TException;
|
| 8 |
+
use Thrift\Exception\TTransportException;
|
| 9 |
+
|
| 10 |
+
/**
|
| 11 |
+
* A forking implementation of a Thrift server.
|
| 12 |
+
*
|
| 13 |
+
* @package thrift.server
|
| 14 |
+
*/
|
| 15 |
+
class TForkingServer extends TServer {
|
| 16 |
+
/**
|
| 17 |
+
* Flag for the main serving loop
|
| 18 |
+
*
|
| 19 |
+
* @var bool
|
| 20 |
+
*/
|
| 21 |
+
private $stop_ = false;
|
| 22 |
+
|
| 23 |
+
/**
|
| 24 |
+
* List of children.
|
| 25 |
+
*
|
| 26 |
+
* @var array
|
| 27 |
+
*/
|
| 28 |
+
protected $children_ = array();
|
| 29 |
+
|
| 30 |
+
/**
|
| 31 |
+
* Listens for new client using the supplied
|
| 32 |
+
* transport. We fork when a new connection
|
| 33 |
+
* arrives.
|
| 34 |
+
*
|
| 35 |
+
* @return void
|
| 36 |
+
*/
|
| 37 |
+
public function serve() {
|
| 38 |
+
$this->transport_->listen();
|
| 39 |
+
|
| 40 |
+
while (!$this->stop_) {
|
| 41 |
+
try {
|
| 42 |
+
$transport = $this->transport_->accept();
|
| 43 |
+
|
| 44 |
+
if ($transport != null) {
|
| 45 |
+
$pid = pcntl_fork();
|
| 46 |
+
|
| 47 |
+
if ($pid > 0) {
|
| 48 |
+
$this->handleParent($transport, $pid);
|
| 49 |
+
}
|
| 50 |
+
else if ($pid === 0) {
|
| 51 |
+
$this->handleChild($transport);
|
| 52 |
+
}
|
| 53 |
+
else {
|
| 54 |
+
throw new TException('Failed to fork');
|
| 55 |
+
}
|
| 56 |
+
}
|
| 57 |
+
}
|
| 58 |
+
catch (TTransportException $e) { }
|
| 59 |
+
|
| 60 |
+
$this->collectChildren();
|
| 61 |
+
}
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
/**
|
| 65 |
+
* Code run by the parent
|
| 66 |
+
*
|
| 67 |
+
* @param TTransport $transport
|
| 68 |
+
* @param int $pid
|
| 69 |
+
* @return void
|
| 70 |
+
*/
|
| 71 |
+
private function handleParent(TTransport $transport, $pid) {
|
| 72 |
+
$this->children_[$pid] = $transport;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
/**
|
| 76 |
+
* Code run by the child.
|
| 77 |
+
*
|
| 78 |
+
* @param TTransport $transport
|
| 79 |
+
* @return void
|
| 80 |
+
*/
|
| 81 |
+
private function handleChild(TTransport $transport) {
|
| 82 |
+
try {
|
| 83 |
+
$inputTransport = $this->inputTransportFactory_->getTransport($transport);
|
| 84 |
+
$outputTransport = $this->outputTransportFactory_->getTransport($transport);
|
| 85 |
+
$inputProtocol = $this->inputProtocolFactory_->getProtocol($inputTransport);
|
| 86 |
+
$outputProtocol = $this->outputProtocolFactory_->getProtocol($outputTransport);
|
| 87 |
+
while ($this->processor_->process($inputProtocol, $outputProtocol)) { }
|
| 88 |
+
@$transport->close();
|
| 89 |
+
}
|
| 90 |
+
catch (TTransportException $e) { }
|
| 91 |
+
|
| 92 |
+
exit(0);
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
/**
|
| 96 |
+
* Collects any children we may have
|
| 97 |
+
*
|
| 98 |
+
* @return void
|
| 99 |
+
*/
|
| 100 |
+
private function collectChildren() {
|
| 101 |
+
foreach ($this->children_ as $pid => $transport) {
|
| 102 |
+
if (pcntl_waitpid($pid, $status, WNOHANG) > 0) {
|
| 103 |
+
unset($this->children_[$pid]);
|
| 104 |
+
if ($transport) @$transport->close();
|
| 105 |
+
}
|
| 106 |
+
}
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
/**
|
| 110 |
+
* Stops the server running. Kills the transport
|
| 111 |
+
* and then stops the main serving loop
|
| 112 |
+
*
|
| 113 |
+
* @return void
|
| 114 |
+
*/
|
| 115 |
+
public function stop() {
|
| 116 |
+
$this->transport_->close();
|
| 117 |
+
$this->stop_ = true;
|
| 118 |
+
}
|
| 119 |
+
}
|
app/code/community/Boxalino/{CemSearch/Lib/vendor → Intelligence/lib}/Thrift/Server/TServer.php
RENAMED
|
@@ -1,101 +1,101 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
|
| 3 |
-
namespace Thrift\Server;
|
| 4 |
-
|
| 5 |
-
use Thrift\Server\TServerTransport;
|
| 6 |
-
use Thrift\Factory\TTransportFactory;
|
| 7 |
-
use Thrift\Factory\TProtocolFactory;
|
| 8 |
-
|
| 9 |
-
/**
|
| 10 |
-
* Generic class for a Thrift server.
|
| 11 |
-
*
|
| 12 |
-
* @package thrift.server
|
| 13 |
-
*/
|
| 14 |
-
abstract class TServer {
|
| 15 |
-
|
| 16 |
-
/**
|
| 17 |
-
* Processor to handle new clients
|
| 18 |
-
*
|
| 19 |
-
* @var TProcessor
|
| 20 |
-
*/
|
| 21 |
-
protected $processor_;
|
| 22 |
-
|
| 23 |
-
/**
|
| 24 |
-
* Server transport to be used for listening
|
| 25 |
-
* and accepting new clients
|
| 26 |
-
*
|
| 27 |
-
* @var TServerTransport
|
| 28 |
-
*/
|
| 29 |
-
protected $transport_;
|
| 30 |
-
|
| 31 |
-
/**
|
| 32 |
-
* Input transport factory
|
| 33 |
-
*
|
| 34 |
-
* @var TTransportFactory
|
| 35 |
-
*/
|
| 36 |
-
protected $inputTransportFactory_;
|
| 37 |
-
|
| 38 |
-
/**
|
| 39 |
-
* Output transport factory
|
| 40 |
-
*
|
| 41 |
-
* @var TTransportFactory
|
| 42 |
-
*/
|
| 43 |
-
protected $outputTransportFactory_;
|
| 44 |
-
|
| 45 |
-
/**
|
| 46 |
-
* Input protocol factory
|
| 47 |
-
*
|
| 48 |
-
* @var TProtocolFactory
|
| 49 |
-
*/
|
| 50 |
-
protected $inputProtocolFactory_;
|
| 51 |
-
|
| 52 |
-
/**
|
| 53 |
-
* Output protocol factory
|
| 54 |
-
*
|
| 55 |
-
* @var TProtocolFactory
|
| 56 |
-
*/
|
| 57 |
-
protected $outputProtocolFactory_;
|
| 58 |
-
|
| 59 |
-
/**
|
| 60 |
-
* Sets up all the factories, etc
|
| 61 |
-
*
|
| 62 |
-
* @param object $processor
|
| 63 |
-
* @param TServerTransport $transport
|
| 64 |
-
* @param TTransportFactory $inputTransportFactory
|
| 65 |
-
* @param TTransportFactory $outputTransportFactory
|
| 66 |
-
* @param TProtocolFactory $inputProtocolFactory
|
| 67 |
-
* @param TProtocolFactory $outputProtocolFactory
|
| 68 |
-
* @return void
|
| 69 |
-
*/
|
| 70 |
-
public function __construct($processor,
|
| 71 |
-
TServerTransport $transport,
|
| 72 |
-
TTransportFactory $inputTransportFactory,
|
| 73 |
-
TTransportFactory $outputTransportFactory,
|
| 74 |
-
TProtocolFactory $inputProtocolFactory,
|
| 75 |
-
TProtocolFactory $outputProtocolFactory) {
|
| 76 |
-
$this->processor_ = $processor;
|
| 77 |
-
$this->transport_ = $transport;
|
| 78 |
-
$this->inputTransportFactory_ = $inputTransportFactory;
|
| 79 |
-
$this->outputTransportFactory_ = $outputTransportFactory;
|
| 80 |
-
$this->inputProtocolFactory_ = $inputProtocolFactory;
|
| 81 |
-
$this->outputProtocolFactory_ = $outputProtocolFactory;
|
| 82 |
-
}
|
| 83 |
-
|
| 84 |
-
/**
|
| 85 |
-
* Serves the server. This should never return
|
| 86 |
-
* unless a problem permits it to do so or it
|
| 87 |
-
* is interrupted intentionally
|
| 88 |
-
*
|
| 89 |
-
* @abstract
|
| 90 |
-
* @return void
|
| 91 |
-
*/
|
| 92 |
-
abstract public function serve();
|
| 93 |
-
|
| 94 |
-
/**
|
| 95 |
-
* Stops the server serving
|
| 96 |
-
*
|
| 97 |
-
* @abstract
|
| 98 |
-
* @return void
|
| 99 |
-
*/
|
| 100 |
-
abstract public function stop();
|
| 101 |
-
}
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
namespace Thrift\Server;
|
| 4 |
+
|
| 5 |
+
use Thrift\Server\TServerTransport;
|
| 6 |
+
use Thrift\Factory\TTransportFactory;
|
| 7 |
+
use Thrift\Factory\TProtocolFactory;
|
| 8 |
+
|
| 9 |
+
/**
|
| 10 |
+
* Generic class for a Thrift server.
|
| 11 |
+
*
|
| 12 |
+
* @package thrift.server
|
| 13 |
+
*/
|
| 14 |
+
abstract class TServer {
|
| 15 |
+
|
| 16 |
+
/**
|
| 17 |
+
* Processor to handle new clients
|
| 18 |
+
*
|
| 19 |
+
* @var TProcessor
|
| 20 |
+
*/
|
| 21 |
+
protected $processor_;
|
| 22 |
+
|
| 23 |
+
/**
|
| 24 |
+
* Server transport to be used for listening
|
| 25 |
+
* and accepting new clients
|
| 26 |
+
*
|
| 27 |
+
* @var TServerTransport
|
| 28 |
+
*/
|
| 29 |
+
protected $transport_;
|
| 30 |
+
|
| 31 |
+
/**
|
| 32 |
+
* Input transport factory
|
| 33 |
+
*
|
| 34 |
+
* @var TTransportFactory
|
| 35 |
+
*/
|
| 36 |
+
protected $inputTransportFactory_;
|
| 37 |
+
|
| 38 |
+
/**
|
| 39 |
+
* Output transport factory
|
| 40 |
+
*
|
| 41 |
+
* @var TTransportFactory
|
| 42 |
+
*/
|
| 43 |
+
protected $outputTransportFactory_;
|
| 44 |
+
|
| 45 |
+
/**
|
| 46 |
+
* Input protocol factory
|
| 47 |
+
*
|
| 48 |
+
* @var TProtocolFactory
|
| 49 |
+
*/
|
| 50 |
+
protected $inputProtocolFactory_;
|
| 51 |
+
|
| 52 |
+
/**
|
| 53 |
+
* Output protocol factory
|
| 54 |
+
*
|
| 55 |
+
* @var TProtocolFactory
|
| 56 |
+
*/
|
| 57 |
+
protected $outputProtocolFactory_;
|
| 58 |
+
|
| 59 |
+
/**
|
| 60 |
+
* Sets up all the factories, etc
|
| 61 |
+
*
|
| 62 |
+
* @param object $processor
|
| 63 |
+
* @param TServerTransport $transport
|
| 64 |
+
* @param TTransportFactory $inputTransportFactory
|
| 65 |
+
* @param TTransportFactory $outputTransportFactory
|
| 66 |
+
* @param TProtocolFactory $inputProtocolFactory
|
| 67 |
+
* @param TProtocolFactory $outputProtocolFactory
|
| 68 |
+
* @return void
|
| 69 |
+
*/
|
| 70 |
+
public function __construct($processor,
|
| 71 |
+
TServerTransport $transport,
|
| 72 |
+
TTransportFactory $inputTransportFactory,
|
| 73 |
+
TTransportFactory $outputTransportFactory,
|
| 74 |
+
TProtocolFactory $inputProtocolFactory,
|
| 75 |
+
TProtocolFactory $outputProtocolFactory) {
|
| 76 |
+
$this->processor_ = $processor;
|
| 77 |
+
$this->transport_ = $transport;
|
| 78 |
+
$this->inputTransportFactory_ = $inputTransportFactory;
|
| 79 |
+
$this->outputTransportFactory_ = $outputTransportFactory;
|
| 80 |
+
$this->inputProtocolFactory_ = $inputProtocolFactory;
|
| 81 |
+
$this->outputProtocolFactory_ = $outputProtocolFactory;
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
/**
|
| 85 |
+
* Serves the server. This should never return
|
| 86 |
+
* unless a problem permits it to do so or it
|
| 87 |
+
* is interrupted intentionally
|
| 88 |
+
*
|
| 89 |
+
* @abstract
|
| 90 |
+
* @return void
|
| 91 |
+
*/
|
| 92 |
+
abstract public function serve();
|
| 93 |
+
|
| 94 |
+
/**
|
| 95 |
+
* Stops the server serving
|
| 96 |
+
*
|
| 97 |
+
* @abstract
|
| 98 |
+
* @return void
|
| 99 |
+
*/
|
| 100 |
+
abstract public function stop();
|
| 101 |
+
}
|
app/code/community/Boxalino/{CemSearch/Lib/vendor → Intelligence/lib}/Thrift/Server/TServerSocket.php
RENAMED
|
@@ -1,98 +1,98 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
|
| 3 |
-
namespace Thrift\Server;
|
| 4 |
-
|
| 5 |
-
use Thrift\Server\TServerTransport;
|
| 6 |
-
use Thrift\Transport\TSocket;
|
| 7 |
-
|
| 8 |
-
/**
|
| 9 |
-
* Socket implementation of a server agent.
|
| 10 |
-
*
|
| 11 |
-
* @package thrift.transport
|
| 12 |
-
*/
|
| 13 |
-
class TServerSocket extends TServerTransport {
|
| 14 |
-
|
| 15 |
-
/**
|
| 16 |
-
* Handle for the listener socket
|
| 17 |
-
*
|
| 18 |
-
* @var resource
|
| 19 |
-
*/
|
| 20 |
-
private $listener_;
|
| 21 |
-
|
| 22 |
-
/**
|
| 23 |
-
* Port for the listener to listen on
|
| 24 |
-
*
|
| 25 |
-
* @var int
|
| 26 |
-
*/
|
| 27 |
-
private $port_;
|
| 28 |
-
|
| 29 |
-
/**
|
| 30 |
-
* Timeout when listening for a new client
|
| 31 |
-
*
|
| 32 |
-
* @var int
|
| 33 |
-
*/
|
| 34 |
-
private $acceptTimeout_ = 30000;
|
| 35 |
-
|
| 36 |
-
/**
|
| 37 |
-
* Host to listen on
|
| 38 |
-
*
|
| 39 |
-
* @var string
|
| 40 |
-
*/
|
| 41 |
-
private $host_;
|
| 42 |
-
|
| 43 |
-
/**
|
| 44 |
-
* ServerSocket constructor
|
| 45 |
-
*
|
| 46 |
-
* @param string $host Host to listen on
|
| 47 |
-
* @param int $port Port to listen on
|
| 48 |
-
* @return void
|
| 49 |
-
*/
|
| 50 |
-
public function __construct($host = 'localhost', $port = 9090) {
|
| 51 |
-
$this->host_ = $host;
|
| 52 |
-
$this->port_ = $port;
|
| 53 |
-
}
|
| 54 |
-
|
| 55 |
-
/**
|
| 56 |
-
* Sets the accept timeout
|
| 57 |
-
*
|
| 58 |
-
* @param int $acceptTimeout
|
| 59 |
-
* @return void
|
| 60 |
-
*/
|
| 61 |
-
public function setAcceptTimeout($acceptTimeout) {
|
| 62 |
-
$this->acceptTimeout_ = $acceptTimeout;
|
| 63 |
-
}
|
| 64 |
-
|
| 65 |
-
/**
|
| 66 |
-
* Opens a new socket server handle
|
| 67 |
-
*
|
| 68 |
-
* @return void
|
| 69 |
-
*/
|
| 70 |
-
public function listen() {
|
| 71 |
-
$this->listener_ = stream_socket_server('tcp://' . $this->host_ . ':' . $this->port_);
|
| 72 |
-
}
|
| 73 |
-
|
| 74 |
-
/**
|
| 75 |
-
* Closes the socket server handle
|
| 76 |
-
*
|
| 77 |
-
* @return void
|
| 78 |
-
*/
|
| 79 |
-
public function close() {
|
| 80 |
-
@fclose($this->listener_);
|
| 81 |
-
$this->listener_ = null;
|
| 82 |
-
}
|
| 83 |
-
|
| 84 |
-
/**
|
| 85 |
-
* Implementation of accept. If not client is accepted in the given time
|
| 86 |
-
*
|
| 87 |
-
* @return TSocket
|
| 88 |
-
*/
|
| 89 |
-
protected function acceptImpl() {
|
| 90 |
-
$handle = @stream_socket_accept($this->listener_, $this->acceptTimeout_ / 1000.0);
|
| 91 |
-
if(!$handle) return null;
|
| 92 |
-
|
| 93 |
-
$socket = new TSocket();
|
| 94 |
-
$socket->setHandle($handle);
|
| 95 |
-
|
| 96 |
-
return $socket;
|
| 97 |
-
}
|
| 98 |
-
}
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
namespace Thrift\Server;
|
| 4 |
+
|
| 5 |
+
use Thrift\Server\TServerTransport;
|
| 6 |
+
use Thrift\Transport\TSocket;
|
| 7 |
+
|
| 8 |
+
/**
|
| 9 |
+
* Socket implementation of a server agent.
|
| 10 |
+
*
|
| 11 |
+
* @package thrift.transport
|
| 12 |
+
*/
|
| 13 |
+
class TServerSocket extends TServerTransport {
|
| 14 |
+
|
| 15 |
+
/**
|
| 16 |
+
* Handle for the listener socket
|
| 17 |
+
*
|
| 18 |
+
* @var resource
|
| 19 |
+
*/
|
| 20 |
+
private $listener_;
|
| 21 |
+
|
| 22 |
+
/**
|
| 23 |
+
* Port for the listener to listen on
|
| 24 |
+
*
|
| 25 |
+
* @var int
|
| 26 |
+
*/
|
| 27 |
+
private $port_;
|
| 28 |
+
|
| 29 |
+
/**
|
| 30 |
+
* Timeout when listening for a new client
|
| 31 |
+
*
|
| 32 |
+
* @var int
|
| 33 |
+
*/
|
| 34 |
+
private $acceptTimeout_ = 30000;
|
| 35 |
+
|
| 36 |
+
/**
|
| 37 |
+
* Host to listen on
|
| 38 |
+
*
|
| 39 |
+
* @var string
|
| 40 |
+
*/
|
| 41 |
+
private $host_;
|
| 42 |
+
|
| 43 |
+
/**
|
| 44 |
+
* ServerSocket constructor
|
| 45 |
+
*
|
| 46 |
+
* @param string $host Host to listen on
|
| 47 |
+
* @param int $port Port to listen on
|
| 48 |
+
* @return void
|
| 49 |
+
*/
|
| 50 |
+
public function __construct($host = 'localhost', $port = 9090) {
|
| 51 |
+
$this->host_ = $host;
|
| 52 |
+
$this->port_ = $port;
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
/**
|
| 56 |
+
* Sets the accept timeout
|
| 57 |
+
*
|
| 58 |
+
* @param int $acceptTimeout
|
| 59 |
+
* @return void
|
| 60 |
+
*/
|
| 61 |
+
public function setAcceptTimeout($acceptTimeout) {
|
| 62 |
+
$this->acceptTimeout_ = $acceptTimeout;
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
/**
|
| 66 |
+
* Opens a new socket server handle
|
| 67 |
+
*
|
| 68 |
+
* @return void
|
| 69 |
+
*/
|
| 70 |
+
public function listen() {
|
| 71 |
+
$this->listener_ = stream_socket_server('tcp://' . $this->host_ . ':' . $this->port_);
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
/**
|
| 75 |
+
* Closes the socket server handle
|
| 76 |
+
*
|
| 77 |
+
* @return void
|
| 78 |
+
*/
|
| 79 |
+
public function close() {
|
| 80 |
+
@fclose($this->listener_);
|
| 81 |
+
$this->listener_ = null;
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
/**
|
| 85 |
+
* Implementation of accept. If not client is accepted in the given time
|
| 86 |
+
*
|
| 87 |
+
* @return TSocket
|
| 88 |
+
*/
|
| 89 |
+
protected function acceptImpl() {
|
| 90 |
+
$handle = @stream_socket_accept($this->listener_, $this->acceptTimeout_ / 1000.0);
|
| 91 |
+
if(!$handle) return null;
|
| 92 |
+
|
| 93 |
+
$socket = new TSocket();
|
| 94 |
+
$socket->setHandle($handle);
|
| 95 |
+
|
| 96 |
+
return $socket;
|
| 97 |
+
}
|
| 98 |
+
}
|
app/code/community/Boxalino/{CemSearch/Lib/vendor → Intelligence/lib}/Thrift/Server/TServerTransport.php
RENAMED
|
@@ -1,54 +1,54 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
|
| 3 |
-
namespace Thrift\Server;
|
| 4 |
-
|
| 5 |
-
use Thrift\Exception\TTransportException;
|
| 6 |
-
|
| 7 |
-
/**
|
| 8 |
-
* Generic class for Server agent.
|
| 9 |
-
*
|
| 10 |
-
* @package thrift.transport
|
| 11 |
-
*/
|
| 12 |
-
abstract class TServerTransport {
|
| 13 |
-
/**
|
| 14 |
-
* List for new clients
|
| 15 |
-
*
|
| 16 |
-
* @abstract
|
| 17 |
-
* @return void
|
| 18 |
-
*/
|
| 19 |
-
abstract public function listen();
|
| 20 |
-
|
| 21 |
-
/**
|
| 22 |
-
* Close the server
|
| 23 |
-
*
|
| 24 |
-
* @abstract
|
| 25 |
-
* @return void
|
| 26 |
-
*/
|
| 27 |
-
abstract public function close();
|
| 28 |
-
|
| 29 |
-
/**
|
| 30 |
-
* Subclasses should use this to implement
|
| 31 |
-
* accept.
|
| 32 |
-
*
|
| 33 |
-
* @abstract
|
| 34 |
-
* @return TTransport
|
| 35 |
-
*/
|
| 36 |
-
protected abstract function acceptImpl();
|
| 37 |
-
|
| 38 |
-
/**
|
| 39 |
-
* Uses the accept implemtation. If null is returned, an
|
| 40 |
-
* exception is thrown.
|
| 41 |
-
*
|
| 42 |
-
* @throws TTransportException
|
| 43 |
-
* @return TTransport
|
| 44 |
-
*/
|
| 45 |
-
public function accept() {
|
| 46 |
-
$transport = $this->acceptImpl();
|
| 47 |
-
|
| 48 |
-
if ($transport == null) {
|
| 49 |
-
throw new TTransportException("accept() may not return NULL");
|
| 50 |
-
}
|
| 51 |
-
|
| 52 |
-
return $transport;
|
| 53 |
-
}
|
| 54 |
-
}
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
namespace Thrift\Server;
|
| 4 |
+
|
| 5 |
+
use Thrift\Exception\TTransportException;
|
| 6 |
+
|
| 7 |
+
/**
|
| 8 |
+
* Generic class for Server agent.
|
| 9 |
+
*
|
| 10 |
+
* @package thrift.transport
|
| 11 |
+
*/
|
| 12 |
+
abstract class TServerTransport {
|
| 13 |
+
/**
|
| 14 |
+
* List for new clients
|
| 15 |
+
*
|
| 16 |
+
* @abstract
|
| 17 |
+
* @return void
|
| 18 |
+
*/
|
| 19 |
+
abstract public function listen();
|
| 20 |
+
|
| 21 |
+
/**
|
| 22 |
+
* Close the server
|
| 23 |
+
*
|
| 24 |
+
* @abstract
|
| 25 |
+
* @return void
|
| 26 |
+
*/
|
| 27 |
+
abstract public function close();
|
| 28 |
+
|
| 29 |
+
/**
|
| 30 |
+
* Subclasses should use this to implement
|
| 31 |
+
* accept.
|
| 32 |
+
*
|
| 33 |
+
* @abstract
|
| 34 |
+
* @return TTransport
|
| 35 |
+
*/
|
| 36 |
+
protected abstract function acceptImpl();
|
| 37 |
+
|
| 38 |
+
/**
|
| 39 |
+
* Uses the accept implemtation. If null is returned, an
|
| 40 |
+
* exception is thrown.
|
| 41 |
+
*
|
| 42 |
+
* @throws TTransportException
|
| 43 |
+
* @return TTransport
|
| 44 |
+
*/
|
| 45 |
+
public function accept() {
|
| 46 |
+
$transport = $this->acceptImpl();
|
| 47 |
+
|
| 48 |
+
if ($transport == null) {
|
| 49 |
+
throw new TTransportException("accept() may not return NULL");
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
return $transport;
|
| 53 |
+
}
|
| 54 |
+
}
|
app/code/community/Boxalino/{CemSearch/Lib/vendor → Intelligence/lib}/Thrift/Server/TSimpleServer.php
RENAMED
|
@@ -1,57 +1,57 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
|
| 3 |
-
namespace Thrift\Server;
|
| 4 |
-
|
| 5 |
-
use Thrift\Server\TServer;
|
| 6 |
-
use Thrift\Exception\TTransportException;
|
| 7 |
-
|
| 8 |
-
/**
|
| 9 |
-
* Simple implemtation of a Thrift server.
|
| 10 |
-
*
|
| 11 |
-
* @package thrift.server
|
| 12 |
-
*/
|
| 13 |
-
class TSimpleServer extends TServer {
|
| 14 |
-
/**
|
| 15 |
-
* Flag for the main serving loop
|
| 16 |
-
*
|
| 17 |
-
* @var bool
|
| 18 |
-
*/
|
| 19 |
-
private $stop_ = false;
|
| 20 |
-
|
| 21 |
-
/**
|
| 22 |
-
* Listens for new client using the supplied
|
| 23 |
-
* transport. It handles TTransportExceptions
|
| 24 |
-
* to avoid timeouts etc killing it
|
| 25 |
-
*
|
| 26 |
-
* @return void
|
| 27 |
-
*/
|
| 28 |
-
public function serve() {
|
| 29 |
-
$this->transport_->listen();
|
| 30 |
-
|
| 31 |
-
while (!$this->stop_) {
|
| 32 |
-
try {
|
| 33 |
-
$transport = $this->transport_->accept();
|
| 34 |
-
|
| 35 |
-
if ($transport != null) {
|
| 36 |
-
$inputTransport = $this->inputTransportFactory_->getTransport($transport);
|
| 37 |
-
$outputTransport = $this->outputTransportFactory_->getTransport($transport);
|
| 38 |
-
$inputProtocol = $this->inputProtocolFactory_->getProtocol($inputTransport);
|
| 39 |
-
$outputProtocol = $this->outputProtocolFactory_->getProtocol($outputTransport);
|
| 40 |
-
while ($this->processor_->process($inputProtocol, $outputProtocol)) { }
|
| 41 |
-
}
|
| 42 |
-
}
|
| 43 |
-
catch (TTransportException $e) { }
|
| 44 |
-
}
|
| 45 |
-
}
|
| 46 |
-
|
| 47 |
-
/**
|
| 48 |
-
* Stops the server running. Kills the transport
|
| 49 |
-
* and then stops the main serving loop
|
| 50 |
-
*
|
| 51 |
-
* @return void
|
| 52 |
-
*/
|
| 53 |
-
public function stop() {
|
| 54 |
-
$this->transport_->close();
|
| 55 |
-
$this->stop_ = true;
|
| 56 |
-
}
|
| 57 |
-
}
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
namespace Thrift\Server;
|
| 4 |
+
|
| 5 |
+
use Thrift\Server\TServer;
|
| 6 |
+
use Thrift\Exception\TTransportException;
|
| 7 |
+
|
| 8 |
+
/**
|
| 9 |
+
* Simple implemtation of a Thrift server.
|
| 10 |
+
*
|
| 11 |
+
* @package thrift.server
|
| 12 |
+
*/
|
| 13 |
+
class TSimpleServer extends TServer {
|
| 14 |
+
/**
|
| 15 |
+
* Flag for the main serving loop
|
| 16 |
+
*
|
| 17 |
+
* @var bool
|
| 18 |
+
*/
|
| 19 |
+
private $stop_ = false;
|
| 20 |
+
|
| 21 |
+
/**
|
| 22 |
+
* Listens for new client using the supplied
|
| 23 |
+
* transport. It handles TTransportExceptions
|
| 24 |
+
* to avoid timeouts etc killing it
|
| 25 |
+
*
|
| 26 |
+
* @return void
|
| 27 |
+
*/
|
| 28 |
+
public function serve() {
|
| 29 |
+
$this->transport_->listen();
|
| 30 |
+
|
| 31 |
+
while (!$this->stop_) {
|
| 32 |
+
try {
|
| 33 |
+
$transport = $this->transport_->accept();
|
| 34 |
+
|
| 35 |
+
if ($transport != null) {
|
| 36 |
+
$inputTransport = $this->inputTransportFactory_->getTransport($transport);
|
| 37 |
+
$outputTransport = $this->outputTransportFactory_->getTransport($transport);
|
| 38 |
+
$inputProtocol = $this->inputProtocolFactory_->getProtocol($inputTransport);
|
| 39 |
+
$outputProtocol = $this->outputProtocolFactory_->getProtocol($outputTransport);
|
| 40 |
+
while ($this->processor_->process($inputProtocol, $outputProtocol)) { }
|
| 41 |
+
}
|
| 42 |
+
}
|
| 43 |
+
catch (TTransportException $e) { }
|
| 44 |
+
}
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
/**
|
| 48 |
+
* Stops the server running. Kills the transport
|
| 49 |
+
* and then stops the main serving loop
|
| 50 |
+
*
|
| 51 |
+
* @return void
|
| 52 |
+
*/
|
| 53 |
+
public function stop() {
|
| 54 |
+
$this->transport_->close();
|
| 55 |
+
$this->stop_ = true;
|
| 56 |
+
}
|
| 57 |
+
}
|
app/code/community/Boxalino/{CemSearch/Lib/vendor → Intelligence/lib}/Thrift/StringFunc/Core.php
RENAMED
|
@@ -1,38 +1,38 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
/*
|
| 3 |
-
* Licensed to the Apache Software Foundation (ASF) under one
|
| 4 |
-
* or more contributor license agreements. See the NOTICE file
|
| 5 |
-
* distributed with this work for additional information
|
| 6 |
-
* regarding copyright ownership. The ASF licenses this file
|
| 7 |
-
* to you under the Apache License, Version 2.0 (the
|
| 8 |
-
* "License"); you may not use this file except in compliance
|
| 9 |
-
* with the License. You may obtain a copy of the License at
|
| 10 |
-
*
|
| 11 |
-
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
-
*
|
| 13 |
-
* Unless required by applicable law or agreed to in writing,
|
| 14 |
-
* software distributed under the License is distributed on an
|
| 15 |
-
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 16 |
-
* KIND, either express or implied. See the License for the
|
| 17 |
-
* specific language governing permissions and limitations
|
| 18 |
-
* under the License.
|
| 19 |
-
*
|
| 20 |
-
*/
|
| 21 |
-
|
| 22 |
-
namespace Thrift\StringFunc;
|
| 23 |
-
|
| 24 |
-
use Thrift\StringFunc\TStringFunc;
|
| 25 |
-
|
| 26 |
-
class Core implements TStringFunc {
|
| 27 |
-
public function substr($str, $start, $length = null) {
|
| 28 |
-
// specifying a null $length would return an empty string
|
| 29 |
-
if($length === null) {
|
| 30 |
-
return substr($str, $start);
|
| 31 |
-
}
|
| 32 |
-
return substr($str, $start, $length);
|
| 33 |
-
}
|
| 34 |
-
|
| 35 |
-
public function strlen($str) {
|
| 36 |
-
return strlen($str);
|
| 37 |
-
}
|
| 38 |
}
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Licensed to the Apache Software Foundation (ASF) under one
|
| 4 |
+
* or more contributor license agreements. See the NOTICE file
|
| 5 |
+
* distributed with this work for additional information
|
| 6 |
+
* regarding copyright ownership. The ASF licenses this file
|
| 7 |
+
* to you under the Apache License, Version 2.0 (the
|
| 8 |
+
* "License"); you may not use this file except in compliance
|
| 9 |
+
* with the License. You may obtain a copy of the License at
|
| 10 |
+
*
|
| 11 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
+
*
|
| 13 |
+
* Unless required by applicable law or agreed to in writing,
|
| 14 |
+
* software distributed under the License is distributed on an
|
| 15 |
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 16 |
+
* KIND, either express or implied. See the License for the
|
| 17 |
+
* specific language governing permissions and limitations
|
| 18 |
+
* under the License.
|
| 19 |
+
*
|
| 20 |
+
*/
|
| 21 |
+
|
| 22 |
+
namespace Thrift\StringFunc;
|
| 23 |
+
|
| 24 |
+
use Thrift\StringFunc\TStringFunc;
|
| 25 |
+
|
| 26 |
+
class Core implements TStringFunc {
|
| 27 |
+
public function substr($str, $start, $length = null) {
|
| 28 |
+
// specifying a null $length would return an empty string
|
| 29 |
+
if($length === null) {
|
| 30 |
+
return substr($str, $start);
|
| 31 |
+
}
|
| 32 |
+
return substr($str, $start, $length);
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
public function strlen($str) {
|
| 36 |
+
return strlen($str);
|
| 37 |
+
}
|
| 38 |
}
|
app/code/community/Boxalino/{CemSearch/Lib/vendor → Intelligence/lib}/Thrift/StringFunc/Mbstring.php
RENAMED
|
@@ -1,45 +1,45 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
/*
|
| 3 |
-
* Licensed to the Apache Software Foundation (ASF) under one
|
| 4 |
-
* or more contributor license agreements. See the NOTICE file
|
| 5 |
-
* distributed with this work for additional information
|
| 6 |
-
* regarding copyright ownership. The ASF licenses this file
|
| 7 |
-
* to you under the Apache License, Version 2.0 (the
|
| 8 |
-
* "License"); you may not use this file except in compliance
|
| 9 |
-
* with the License. You may obtain a copy of the License at
|
| 10 |
-
*
|
| 11 |
-
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
-
*
|
| 13 |
-
* Unless required by applicable law or agreed to in writing,
|
| 14 |
-
* software distributed under the License is distributed on an
|
| 15 |
-
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 16 |
-
* KIND, either express or implied. See the License for the
|
| 17 |
-
* specific language governing permissions and limitations
|
| 18 |
-
* under the License.
|
| 19 |
-
*
|
| 20 |
-
*/
|
| 21 |
-
|
| 22 |
-
namespace Thrift\StringFunc;
|
| 23 |
-
|
| 24 |
-
use Thrift\StringFunc\TStringFunc;
|
| 25 |
-
|
| 26 |
-
class Mbstring implements TStringFunc {
|
| 27 |
-
public function substr($str, $start, $length = null) {
|
| 28 |
-
/**
|
| 29 |
-
* We need to set the charset parameter, which is the second
|
| 30 |
-
* optional parameter and the first optional parameter can't
|
| 31 |
-
* be null or false as a "magic" value because that would
|
| 32 |
-
* cause an empty string to be returned, so we need to
|
| 33 |
-
* actually calculate the proper length value.
|
| 34 |
-
*/
|
| 35 |
-
if($length === null) {
|
| 36 |
-
$length = $this->strlen($str) - $start;
|
| 37 |
-
}
|
| 38 |
-
|
| 39 |
-
return mb_substr($str, $start, $length, '8bit');
|
| 40 |
-
}
|
| 41 |
-
|
| 42 |
-
public function strlen($str) {
|
| 43 |
-
return mb_strlen($str, '8bit');
|
| 44 |
-
}
|
| 45 |
}
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Licensed to the Apache Software Foundation (ASF) under one
|
| 4 |
+
* or more contributor license agreements. See the NOTICE file
|
| 5 |
+
* distributed with this work for additional information
|
| 6 |
+
* regarding copyright ownership. The ASF licenses this file
|
| 7 |
+
* to you under the Apache License, Version 2.0 (the
|
| 8 |
+
* "License"); you may not use this file except in compliance
|
| 9 |
+
* with the License. You may obtain a copy of the License at
|
| 10 |
+
*
|
| 11 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
+
*
|
| 13 |
+
* Unless required by applicable law or agreed to in writing,
|
| 14 |
+
* software distributed under the License is distributed on an
|
| 15 |
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 16 |
+
* KIND, either express or implied. See the License for the
|
| 17 |
+
* specific language governing permissions and limitations
|
| 18 |
+
* under the License.
|
| 19 |
+
*
|
| 20 |
+
*/
|
| 21 |
+
|
| 22 |
+
namespace Thrift\StringFunc;
|
| 23 |
+
|
| 24 |
+
use Thrift\StringFunc\TStringFunc;
|
| 25 |
+
|
| 26 |
+
class Mbstring implements TStringFunc {
|
| 27 |
+
public function substr($str, $start, $length = null) {
|
| 28 |
+
/**
|
| 29 |
+
* We need to set the charset parameter, which is the second
|
| 30 |
+
* optional parameter and the first optional parameter can't
|
| 31 |
+
* be null or false as a "magic" value because that would
|
| 32 |
+
* cause an empty string to be returned, so we need to
|
| 33 |
+
* actually calculate the proper length value.
|
| 34 |
+
*/
|
| 35 |
+
if($length === null) {
|
| 36 |
+
$length = $this->strlen($str) - $start;
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
return mb_substr($str, $start, $length, '8bit');
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
public function strlen($str) {
|
| 43 |
+
return mb_strlen($str, '8bit');
|
| 44 |
+
}
|
| 45 |
}
|
app/code/community/Boxalino/{CemSearch/Lib/vendor → Intelligence/lib}/Thrift/StringFunc/TStringFunc.php
RENAMED
|
@@ -1,27 +1,27 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
/*
|
| 3 |
-
* Licensed to the Apache Software Foundation (ASF) under one
|
| 4 |
-
* or more contributor license agreements. See the NOTICE file
|
| 5 |
-
* distributed with this work for additional information
|
| 6 |
-
* regarding copyright ownership. The ASF licenses this file
|
| 7 |
-
* to you under the Apache License, Version 2.0 (the
|
| 8 |
-
* "License"); you may not use this file except in compliance
|
| 9 |
-
* with the License. You may obtain a copy of the License at
|
| 10 |
-
*
|
| 11 |
-
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
-
*
|
| 13 |
-
* Unless required by applicable law or agreed to in writing,
|
| 14 |
-
* software distributed under the License is distributed on an
|
| 15 |
-
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 16 |
-
* KIND, either express or implied. See the License for the
|
| 17 |
-
* specific language governing permissions and limitations
|
| 18 |
-
* under the License.
|
| 19 |
-
*
|
| 20 |
-
*/
|
| 21 |
-
|
| 22 |
-
namespace Thrift\StringFunc;
|
| 23 |
-
|
| 24 |
-
interface TStringFunc {
|
| 25 |
-
public function substr($str, $start, $length = null);
|
| 26 |
-
public function strlen($str);
|
| 27 |
}
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Licensed to the Apache Software Foundation (ASF) under one
|
| 4 |
+
* or more contributor license agreements. See the NOTICE file
|
| 5 |
+
* distributed with this work for additional information
|
| 6 |
+
* regarding copyright ownership. The ASF licenses this file
|
| 7 |
+
* to you under the Apache License, Version 2.0 (the
|
| 8 |
+
* "License"); you may not use this file except in compliance
|
| 9 |
+
* with the License. You may obtain a copy of the License at
|
| 10 |
+
*
|
| 11 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
+
*
|
| 13 |
+
* Unless required by applicable law or agreed to in writing,
|
| 14 |
+
* software distributed under the License is distributed on an
|
| 15 |
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 16 |
+
* KIND, either express or implied. See the License for the
|
| 17 |
+
* specific language governing permissions and limitations
|
| 18 |
+
* under the License.
|
| 19 |
+
*
|
| 20 |
+
*/
|
| 21 |
+
|
| 22 |
+
namespace Thrift\StringFunc;
|
| 23 |
+
|
| 24 |
+
interface TStringFunc {
|
| 25 |
+
public function substr($str, $start, $length = null);
|
| 26 |
+
public function strlen($str);
|
| 27 |
}
|
app/code/community/Boxalino/{CemSearch/Lib/vendor → Intelligence/lib}/Thrift/Transport/P13nTCurlClient.php
RENAMED
|
@@ -1,76 +1,77 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
namespace Thrift\Transport;
|
| 3 |
-
|
| 4 |
-
use Thrift\Transport\TTransport;
|
| 5 |
-
use Thrift\Exception\TTransportException;
|
| 6 |
-
use Thrift\Factory\TStringFuncFactory;
|
| 7 |
-
|
| 8 |
-
class P13nTCurlClient extends TCurlClient {
|
| 9 |
-
|
| 10 |
-
private static $curlHandle;
|
| 11 |
-
|
| 12 |
-
protected $authorizationString;
|
| 13 |
-
|
| 14 |
-
/**
|
| 15 |
-
* Opens and sends the actual request over the HTTP connection
|
| 16 |
-
*
|
| 17 |
-
* @throws TTransportException if a writing error occurs
|
| 18 |
-
*/
|
| 19 |
-
public function flush() {
|
| 20 |
-
// God, PHP really has some esoteric ways of doing simple things.
|
| 21 |
-
if (!self::$curlHandle) {
|
| 22 |
-
register_shutdown_function(array('Thrift\\Transport\\TCurlClient', 'closeCurlHandle'));
|
| 23 |
-
self::$curlHandle = curl_init();
|
| 24 |
-
curl_setopt(self::$curlHandle, CURLOPT_RETURNTRANSFER, true);
|
| 25 |
-
curl_setopt(self::$curlHandle, CURLOPT_BINARYTRANSFER, true);
|
| 26 |
-
curl_setopt(self::$curlHandle, CURLOPT_USERAGENT, 'PHP/TCurlClient');
|
| 27 |
-
curl_setopt(self::$curlHandle, CURLOPT_CUSTOMREQUEST, 'POST');
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
curl_setopt(self::$curlHandle,
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
$
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
'
|
| 38 |
-
'
|
| 39 |
-
'Content-
|
| 40 |
-
'
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
$this->request_
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
self::$curlHandle
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
self::$curlHandle
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
}
|
|
|
| 1 |
+
<?php
|
| 2 |
+
namespace Thrift\Transport;
|
| 3 |
+
|
| 4 |
+
use Thrift\Transport\TTransport;
|
| 5 |
+
use Thrift\Exception\TTransportException;
|
| 6 |
+
use Thrift\Factory\TStringFuncFactory;
|
| 7 |
+
|
| 8 |
+
class P13nTCurlClient extends TCurlClient {
|
| 9 |
+
|
| 10 |
+
private static $curlHandle;
|
| 11 |
+
|
| 12 |
+
protected $authorizationString;
|
| 13 |
+
|
| 14 |
+
/**
|
| 15 |
+
* Opens and sends the actual request over the HTTP connection
|
| 16 |
+
*
|
| 17 |
+
* @throws TTransportException if a writing error occurs
|
| 18 |
+
*/
|
| 19 |
+
public function flush() {
|
| 20 |
+
// God, PHP really has some esoteric ways of doing simple things.
|
| 21 |
+
if (!self::$curlHandle) {
|
| 22 |
+
register_shutdown_function(array('Thrift\\Transport\\TCurlClient', 'closeCurlHandle'));
|
| 23 |
+
self::$curlHandle = curl_init();
|
| 24 |
+
curl_setopt(self::$curlHandle, CURLOPT_RETURNTRANSFER, true);
|
| 25 |
+
curl_setopt(self::$curlHandle, CURLOPT_BINARYTRANSFER, true);
|
| 26 |
+
curl_setopt(self::$curlHandle, CURLOPT_USERAGENT, 'PHP/TCurlClient');
|
| 27 |
+
curl_setopt(self::$curlHandle, CURLOPT_CUSTOMREQUEST, 'POST');
|
| 28 |
+
curl_setopt(self::$curlHandle, CURLOPT_SSL_VERIFYPEER, false);
|
| 29 |
+
// FOLLOWLOCATION cannot be activated when safe_mode is enabled or an open_basedir is set
|
| 30 |
+
@curl_setopt(self::$curlHandle, CURLOPT_FOLLOWLOCATION, true);
|
| 31 |
+
curl_setopt(self::$curlHandle, CURLOPT_MAXREDIRS, 1);
|
| 32 |
+
}
|
| 33 |
+
$host = $this->host_.($this->port_ != 80 ? ':'.$this->port_ : '');
|
| 34 |
+
$fullUrl = $this->scheme_."://".$host.$this->uri_;
|
| 35 |
+
|
| 36 |
+
$headers = array('Host: '.$host,
|
| 37 |
+
'Accept: application/x-thrift',
|
| 38 |
+
'User-Agent: PHP/THttpClient',
|
| 39 |
+
'Content-Type: application/x-thrift',
|
| 40 |
+
'Content-Length: '.TStringFuncFactory::create()->strlen($this->request_),
|
| 41 |
+
'Authorization: Basic '.$this->authorizationString);
|
| 42 |
+
|
| 43 |
+
curl_setopt(self::$curlHandle, CURLOPT_HTTPHEADER, $headers);
|
| 44 |
+
|
| 45 |
+
if ($this->timeout_ > 0) {
|
| 46 |
+
curl_setopt(self::$curlHandle, CURLOPT_TIMEOUT, $this->timeout_);
|
| 47 |
+
}
|
| 48 |
+
curl_setopt(self::$curlHandle, CURLOPT_POSTFIELDS, $this->request_);
|
| 49 |
+
$this->request_ = '';
|
| 50 |
+
|
| 51 |
+
curl_setopt(self::$curlHandle, CURLOPT_URL, $fullUrl);
|
| 52 |
+
$this->response_ = curl_exec(self::$curlHandle);
|
| 53 |
+
|
| 54 |
+
// Connect failed?
|
| 55 |
+
if (!$this->response_) {
|
| 56 |
+
curl_close(self::$curlHandle);
|
| 57 |
+
self::$curlHandle = null;
|
| 58 |
+
$error = 'TCurlClient: Could not connect to '.$fullUrl;
|
| 59 |
+
throw new TTransportException($error, TTransportException::NOT_OPEN);
|
| 60 |
+
}
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
static function closeCurlHandle() {
|
| 64 |
+
try {
|
| 65 |
+
if (self::$curlHandle) {
|
| 66 |
+
curl_close(self::$curlHandle);
|
| 67 |
+
self::$curlHandle = null;
|
| 68 |
+
}
|
| 69 |
+
} catch (\Exception $x) {
|
| 70 |
+
error_log('There was an error closing the curl handle: ' . $x->getMessage());
|
| 71 |
+
}
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
public function setAuthorization($username, $password) {
|
| 75 |
+
$this->authorizationString = base64_encode($username.':'.$password);
|
| 76 |
+
}
|
| 77 |
+
}
|
app/code/community/Boxalino/{CemSearch/Lib/vendor → Intelligence/lib}/Thrift/Transport/P13nTHttpClient.php
RENAMED
|
@@ -1,51 +1,51 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
namespace Thrift\Transport;
|
| 3 |
-
|
| 4 |
-
use Thrift\Transport\TTransport;
|
| 5 |
-
use Thrift\Exception\TTransportException;
|
| 6 |
-
use Thrift\Factory\TStringFuncFactory;
|
| 7 |
-
|
| 8 |
-
class P13nTHttpClient extends THttpClient {
|
| 9 |
-
|
| 10 |
-
protected $authorizationString;
|
| 11 |
-
|
| 12 |
-
/**
|
| 13 |
-
* Opens and sends the actual request over the HTTP connection
|
| 14 |
-
*
|
| 15 |
-
* @throws TTransportException if a writing error occurs
|
| 16 |
-
*/
|
| 17 |
-
public function flush() {
|
| 18 |
-
// God, PHP really has some esoteric ways of doing simple things.
|
| 19 |
-
$host = $this->host_.($this->port_ != 80 ? ':'.$this->port_ : '');
|
| 20 |
-
|
| 21 |
-
$headers = array('Host: '.$host,
|
| 22 |
-
'Accept: application/x-thrift',
|
| 23 |
-
'User-Agent: PHP/THttpClient',
|
| 24 |
-
'Content-Type: application/x-thrift',
|
| 25 |
-
'Content-Length: '.TStringFuncFactory::create()->strlen($this->buf_),
|
| 26 |
-
'Authorization: Basic '.$this->authorizationString);
|
| 27 |
-
|
| 28 |
-
$options = array('method' => 'POST',
|
| 29 |
-
'header' => implode("\r\n", $headers),
|
| 30 |
-
'max_redirects' => 1,
|
| 31 |
-
'content' => $this->buf_);
|
| 32 |
-
if ($this->timeout_ > 0) {
|
| 33 |
-
$options['timeout'] = $this->timeout_;
|
| 34 |
-
}
|
| 35 |
-
$this->buf_ = '';
|
| 36 |
-
|
| 37 |
-
$contextid = stream_context_create(array('http' => $options));
|
| 38 |
-
$this->handle_ = @fopen($this->scheme_.'://'.$host.$this->uri_, 'r', false, $contextid);
|
| 39 |
-
|
| 40 |
-
// Connect failed?
|
| 41 |
-
if ($this->handle_ === FALSE) {
|
| 42 |
-
$this->handle_ = null;
|
| 43 |
-
$error = 'P13nTHttpClient: Could not connect to '.$host.$this->uri_;
|
| 44 |
-
throw new TTransportException($error, TTransportException::NOT_OPEN);
|
| 45 |
-
}
|
| 46 |
-
}
|
| 47 |
-
|
| 48 |
-
public function setAuthorization($username, $password) {
|
| 49 |
-
$this->authorizationString = base64_encode($username.':'.$password);
|
| 50 |
-
}
|
| 51 |
-
}
|
| 1 |
+
<?php
|
| 2 |
+
namespace Thrift\Transport;
|
| 3 |
+
|
| 4 |
+
use Thrift\Transport\TTransport;
|
| 5 |
+
use Thrift\Exception\TTransportException;
|
| 6 |
+
use Thrift\Factory\TStringFuncFactory;
|
| 7 |
+
|
| 8 |
+
class P13nTHttpClient extends THttpClient {
|
| 9 |
+
|
| 10 |
+
protected $authorizationString;
|
| 11 |
+
|
| 12 |
+
/**
|
| 13 |
+
* Opens and sends the actual request over the HTTP connection
|
| 14 |
+
*
|
| 15 |
+
* @throws TTransportException if a writing error occurs
|
| 16 |
+
*/
|
| 17 |
+
public function flush() {
|
| 18 |
+
// God, PHP really has some esoteric ways of doing simple things.
|
| 19 |
+
$host = $this->host_.($this->port_ != 80 ? ':'.$this->port_ : '');
|
| 20 |
+
|
| 21 |
+
$headers = array('Host: '.$host,
|
| 22 |
+
'Accept: application/x-thrift',
|
| 23 |
+
'User-Agent: PHP/THttpClient',
|
| 24 |
+
'Content-Type: application/x-thrift',
|
| 25 |
+
'Content-Length: '.TStringFuncFactory::create()->strlen($this->buf_),
|
| 26 |
+
'Authorization: Basic '.$this->authorizationString);
|
| 27 |
+
|
| 28 |
+
$options = array('method' => 'POST',
|
| 29 |
+
'header' => implode("\r\n", $headers),
|
| 30 |
+
'max_redirects' => 1,
|
| 31 |
+
'content' => $this->buf_);
|
| 32 |
+
if ($this->timeout_ > 0) {
|
| 33 |
+
$options['timeout'] = $this->timeout_;
|
| 34 |
+
}
|
| 35 |
+
$this->buf_ = '';
|
| 36 |
+
|
| 37 |
+
$contextid = stream_context_create(array('http' => $options));
|
| 38 |
+
$this->handle_ = @fopen($this->scheme_.'://'.$host.$this->uri_, 'r', false, $contextid);
|
| 39 |
+
|
| 40 |
+
// Connect failed?
|
| 41 |
+
if ($this->handle_ === FALSE) {
|
| 42 |
+
$this->handle_ = null;
|
| 43 |
+
$error = 'P13nTHttpClient: Could not connect to '.$host.$this->uri_;
|
| 44 |
+
throw new TTransportException($error, TTransportException::NOT_OPEN);
|
| 45 |
+
}
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
public function setAuthorization($username, $password) {
|
| 49 |
+
$this->authorizationString = base64_encode($username.':'.$password);
|
| 50 |
+
}
|
| 51 |
+
}
|
app/code/community/Boxalino/{CemSearch/Lib/vendor → Intelligence/lib}/Thrift/Transport/TBufferedTransport.php
RENAMED
|
@@ -1,165 +1,165 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
/*
|
| 3 |
-
* Licensed to the Apache Software Foundation (ASF) under one
|
| 4 |
-
* or more contributor license agreements. See the NOTICE file
|
| 5 |
-
* distributed with this work for additional information
|
| 6 |
-
* regarding copyright ownership. The ASF licenses this file
|
| 7 |
-
* to you under the Apache License, Version 2.0 (the
|
| 8 |
-
* "License"); you may not use this file except in compliance
|
| 9 |
-
* with the License. You may obtain a copy of the License at
|
| 10 |
-
*
|
| 11 |
-
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
-
*
|
| 13 |
-
* Unless required by applicable law or agreed to in writing,
|
| 14 |
-
* software distributed under the License is distributed on an
|
| 15 |
-
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 16 |
-
* KIND, either express or implied. See the License for the
|
| 17 |
-
* specific language governing permissions and limitations
|
| 18 |
-
* under the License.
|
| 19 |
-
*
|
| 20 |
-
* @package thrift.transport
|
| 21 |
-
*/
|
| 22 |
-
|
| 23 |
-
namespace Thrift\Transport;
|
| 24 |
-
|
| 25 |
-
use Thrift\Transport\TTransport;
|
| 26 |
-
use Thrift\Factory\TStringFuncFactory;
|
| 27 |
-
|
| 28 |
-
/**
|
| 29 |
-
* Buffered transport. Stores data to an internal buffer that it doesn't
|
| 30 |
-
* actually write out until flush is called. For reading, we do a greedy
|
| 31 |
-
* read and then serve data out of the internal buffer.
|
| 32 |
-
*
|
| 33 |
-
* @package thrift.transport
|
| 34 |
-
*/
|
| 35 |
-
class TBufferedTransport extends TTransport {
|
| 36 |
-
|
| 37 |
-
/**
|
| 38 |
-
* Constructor. Creates a buffered transport around an underlying transport
|
| 39 |
-
*/
|
| 40 |
-
public function __construct($transport=null, $rBufSize=512, $wBufSize=512) {
|
| 41 |
-
$this->transport_ = $transport;
|
| 42 |
-
$this->rBufSize_ = $rBufSize;
|
| 43 |
-
$this->wBufSize_ = $wBufSize;
|
| 44 |
-
}
|
| 45 |
-
|
| 46 |
-
/**
|
| 47 |
-
* The underlying transport
|
| 48 |
-
*
|
| 49 |
-
* @var TTransport
|
| 50 |
-
*/
|
| 51 |
-
protected $transport_ = null;
|
| 52 |
-
|
| 53 |
-
/**
|
| 54 |
-
* The receive buffer size
|
| 55 |
-
*
|
| 56 |
-
* @var int
|
| 57 |
-
*/
|
| 58 |
-
protected $rBufSize_ = 512;
|
| 59 |
-
|
| 60 |
-
/**
|
| 61 |
-
* The write buffer size
|
| 62 |
-
*
|
| 63 |
-
* @var int
|
| 64 |
-
*/
|
| 65 |
-
protected $wBufSize_ = 512;
|
| 66 |
-
|
| 67 |
-
/**
|
| 68 |
-
* The write buffer.
|
| 69 |
-
*
|
| 70 |
-
* @var string
|
| 71 |
-
*/
|
| 72 |
-
protected $wBuf_ = '';
|
| 73 |
-
|
| 74 |
-
/**
|
| 75 |
-
* The read buffer.
|
| 76 |
-
*
|
| 77 |
-
* @var string
|
| 78 |
-
*/
|
| 79 |
-
protected $rBuf_ = '';
|
| 80 |
-
|
| 81 |
-
public function isOpen() {
|
| 82 |
-
return $this->transport_->isOpen();
|
| 83 |
-
}
|
| 84 |
-
|
| 85 |
-
public function open() {
|
| 86 |
-
$this->transport_->open();
|
| 87 |
-
}
|
| 88 |
-
|
| 89 |
-
public function close() {
|
| 90 |
-
$this->transport_->close();
|
| 91 |
-
}
|
| 92 |
-
|
| 93 |
-
public function putBack($data) {
|
| 94 |
-
if (TStringFuncFactory::create()->strlen($this->rBuf_) === 0) {
|
| 95 |
-
$this->rBuf_ = $data;
|
| 96 |
-
} else {
|
| 97 |
-
$this->rBuf_ = ($data . $this->rBuf_);
|
| 98 |
-
}
|
| 99 |
-
}
|
| 100 |
-
|
| 101 |
-
/**
|
| 102 |
-
* The reason that we customize readAll here is that the majority of PHP
|
| 103 |
-
* streams are already internally buffered by PHP. The socket stream, for
|
| 104 |
-
* example, buffers internally and blocks if you call read with $len greater
|
| 105 |
-
* than the amount of data available, unlike recv() in C.
|
| 106 |
-
*
|
| 107 |
-
* Therefore, use the readAll method of the wrapped transport inside
|
| 108 |
-
* the buffered readAll.
|
| 109 |
-
*/
|
| 110 |
-
public function readAll($len) {
|
| 111 |
-
$have = TStringFuncFactory::create()->strlen($this->rBuf_);
|
| 112 |
-
if ($have == 0) {
|
| 113 |
-
$data = $this->transport_->readAll($len);
|
| 114 |
-
} else if ($have < $len) {
|
| 115 |
-
$data = $this->rBuf_;
|
| 116 |
-
$this->rBuf_ = '';
|
| 117 |
-
$data .= $this->transport_->readAll($len - $have);
|
| 118 |
-
} else if ($have == $len) {
|
| 119 |
-
$data = $this->rBuf_;
|
| 120 |
-
$this->rBuf_ = '';
|
| 121 |
-
} else if ($have > $len) {
|
| 122 |
-
$data = TStringFuncFactory::create()->substr($this->rBuf_, 0, $len);
|
| 123 |
-
$this->rBuf_ = TStringFuncFactory::create()->substr($this->rBuf_, $len);
|
| 124 |
-
}
|
| 125 |
-
return $data;
|
| 126 |
-
}
|
| 127 |
-
|
| 128 |
-
public function read($len) {
|
| 129 |
-
if (TStringFuncFactory::create()->strlen($this->rBuf_) === 0) {
|
| 130 |
-
$this->rBuf_ = $this->transport_->read($this->rBufSize_);
|
| 131 |
-
}
|
| 132 |
-
|
| 133 |
-
if (TStringFuncFactory::create()->strlen($this->rBuf_) <= $len) {
|
| 134 |
-
$ret = $this->rBuf_;
|
| 135 |
-
$this->rBuf_ = '';
|
| 136 |
-
return $ret;
|
| 137 |
-
}
|
| 138 |
-
|
| 139 |
-
$ret = TStringFuncFactory::create()->substr($this->rBuf_, 0, $len);
|
| 140 |
-
$this->rBuf_ = TStringFuncFactory::create()->substr($this->rBuf_, $len);
|
| 141 |
-
return $ret;
|
| 142 |
-
}
|
| 143 |
-
|
| 144 |
-
public function write($buf) {
|
| 145 |
-
$this->wBuf_ .= $buf;
|
| 146 |
-
if (TStringFuncFactory::create()->strlen($this->wBuf_) >= $this->wBufSize_) {
|
| 147 |
-
$out = $this->wBuf_;
|
| 148 |
-
|
| 149 |
-
// Note that we clear the internal wBuf_ prior to the underlying write
|
| 150 |
-
// to ensure we're in a sane state (i.e. internal buffer cleaned)
|
| 151 |
-
// if the underlying write throws up an exception
|
| 152 |
-
$this->wBuf_ = '';
|
| 153 |
-
$this->transport_->write($out);
|
| 154 |
-
}
|
| 155 |
-
}
|
| 156 |
-
|
| 157 |
-
public function flush() {
|
| 158 |
-
if (TStringFuncFactory::create()->strlen($this->wBuf_) > 0) {
|
| 159 |
-
$this->transport_->write($this->wBuf_);
|
| 160 |
-
$this->wBuf_ = '';
|
| 161 |
-
}
|
| 162 |
-
$this->transport_->flush();
|
| 163 |
-
}
|
| 164 |
-
|
| 165 |
-
}
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Licensed to the Apache Software Foundation (ASF) under one
|
| 4 |
+
* or more contributor license agreements. See the NOTICE file
|
| 5 |
+
* distributed with this work for additional information
|
| 6 |
+
* regarding copyright ownership. The ASF licenses this file
|
| 7 |
+
* to you under the Apache License, Version 2.0 (the
|
| 8 |
+
* "License"); you may not use this file except in compliance
|
| 9 |
+
* with the License. You may obtain a copy of the License at
|
| 10 |
+
*
|
| 11 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
+
*
|
| 13 |
+
* Unless required by applicable law or agreed to in writing,
|
| 14 |
+
* software distributed under the License is distributed on an
|
| 15 |
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 16 |
+
* KIND, either express or implied. See the License for the
|
| 17 |
+
* specific language governing permissions and limitations
|
| 18 |
+
* under the License.
|
| 19 |
+
*
|
| 20 |
+
* @package thrift.transport
|
| 21 |
+
*/
|
| 22 |
+
|
| 23 |
+
namespace Thrift\Transport;
|
| 24 |
+
|
| 25 |
+
use Thrift\Transport\TTransport;
|
| 26 |
+
use Thrift\Factory\TStringFuncFactory;
|
| 27 |
+
|
| 28 |
+
/**
|
| 29 |
+
* Buffered transport. Stores data to an internal buffer that it doesn't
|
| 30 |
+
* actually write out until flush is called. For reading, we do a greedy
|
| 31 |
+
* read and then serve data out of the internal buffer.
|
| 32 |
+
*
|
| 33 |
+
* @package thrift.transport
|
| 34 |
+
*/
|
| 35 |
+
class TBufferedTransport extends TTransport {
|
| 36 |
+
|
| 37 |
+
/**
|
| 38 |
+
* Constructor. Creates a buffered transport around an underlying transport
|
| 39 |
+
*/
|
| 40 |
+
public function __construct($transport=null, $rBufSize=512, $wBufSize=512) {
|
| 41 |
+
$this->transport_ = $transport;
|
| 42 |
+
$this->rBufSize_ = $rBufSize;
|
| 43 |
+
$this->wBufSize_ = $wBufSize;
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
/**
|
| 47 |
+
* The underlying transport
|
| 48 |
+
*
|
| 49 |
+
* @var TTransport
|
| 50 |
+
*/
|
| 51 |
+
protected $transport_ = null;
|
| 52 |
+
|
| 53 |
+
/**
|
| 54 |
+
* The receive buffer size
|
| 55 |
+
*
|
| 56 |
+
* @var int
|
| 57 |
+
*/
|
| 58 |
+
protected $rBufSize_ = 512;
|
| 59 |
+
|
| 60 |
+
/**
|
| 61 |
+
* The write buffer size
|
| 62 |
+
*
|
| 63 |
+
* @var int
|
| 64 |
+
*/
|
| 65 |
+
protected $wBufSize_ = 512;
|
| 66 |
+
|
| 67 |
+
/**
|
| 68 |
+
* The write buffer.
|
| 69 |
+
*
|
| 70 |
+
* @var string
|
| 71 |
+
*/
|
| 72 |
+
protected $wBuf_ = '';
|
| 73 |
+
|
| 74 |
+
/**
|
| 75 |
+
* The read buffer.
|
| 76 |
+
*
|
| 77 |
+
* @var string
|
| 78 |
+
*/
|
| 79 |
+
protected $rBuf_ = '';
|
| 80 |
+
|
| 81 |
+
public function isOpen() {
|
| 82 |
+
return $this->transport_->isOpen();
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
public function open() {
|
| 86 |
+
$this->transport_->open();
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
public function close() {
|
| 90 |
+
$this->transport_->close();
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
public function putBack($data) {
|
| 94 |
+
if (TStringFuncFactory::create()->strlen($this->rBuf_) === 0) {
|
| 95 |
+
$this->rBuf_ = $data;
|
| 96 |
+
} else {
|
| 97 |
+
$this->rBuf_ = ($data . $this->rBuf_);
|
| 98 |
+
}
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
/**
|
| 102 |
+
* The reason that we customize readAll here is that the majority of PHP
|
| 103 |
+
* streams are already internally buffered by PHP. The socket stream, for
|
| 104 |
+
* example, buffers internally and blocks if you call read with $len greater
|
| 105 |
+
* than the amount of data available, unlike recv() in C.
|
| 106 |
+
*
|
| 107 |
+
* Therefore, use the readAll method of the wrapped transport inside
|
| 108 |
+
* the buffered readAll.
|
| 109 |
+
*/
|
| 110 |
+
public function readAll($len) {
|
| 111 |
+
$have = TStringFuncFactory::create()->strlen($this->rBuf_);
|
| 112 |
+
if ($have == 0) {
|
| 113 |
+
$data = $this->transport_->readAll($len);
|
| 114 |
+
} else if ($have < $len) {
|
| 115 |
+
$data = $this->rBuf_;
|
| 116 |
+
$this->rBuf_ = '';
|
| 117 |
+
$data .= $this->transport_->readAll($len - $have);
|
| 118 |
+
} else if ($have == $len) {
|
| 119 |
+
$data = $this->rBuf_;
|
| 120 |
+
$this->rBuf_ = '';
|
| 121 |
+
} else if ($have > $len) {
|
| 122 |
+
$data = TStringFuncFactory::create()->substr($this->rBuf_, 0, $len);
|
| 123 |
+
$this->rBuf_ = TStringFuncFactory::create()->substr($this->rBuf_, $len);
|
| 124 |
+
}
|
| 125 |
+
return $data;
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
public function read($len) {
|
| 129 |
+
if (TStringFuncFactory::create()->strlen($this->rBuf_) === 0) {
|
| 130 |
+
$this->rBuf_ = $this->transport_->read($this->rBufSize_);
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
if (TStringFuncFactory::create()->strlen($this->rBuf_) <= $len) {
|
| 134 |
+
$ret = $this->rBuf_;
|
| 135 |
+
$this->rBuf_ = '';
|
| 136 |
+
return $ret;
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
$ret = TStringFuncFactory::create()->substr($this->rBuf_, 0, $len);
|
| 140 |
+
$this->rBuf_ = TStringFuncFactory::create()->substr($this->rBuf_, $len);
|
| 141 |
+
return $ret;
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
public function write($buf) {
|
| 145 |
+
$this->wBuf_ .= $buf;
|
| 146 |
+
if (TStringFuncFactory::create()->strlen($this->wBuf_) >= $this->wBufSize_) {
|
| 147 |
+
$out = $this->wBuf_;
|
| 148 |
+
|
| 149 |
+
// Note that we clear the internal wBuf_ prior to the underlying write
|
| 150 |
+
// to ensure we're in a sane state (i.e. internal buffer cleaned)
|
| 151 |
+
// if the underlying write throws up an exception
|
| 152 |
+
$this->wBuf_ = '';
|
| 153 |
+
$this->transport_->write($out);
|
| 154 |
+
}
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
public function flush() {
|
| 158 |
+
if (TStringFuncFactory::create()->strlen($this->wBuf_) > 0) {
|
| 159 |
+
$this->transport_->write($this->wBuf_);
|
| 160 |
+
$this->wBuf_ = '';
|
| 161 |
+
}
|
| 162 |
+
$this->transport_->flush();
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
}
|
app/code/community/Boxalino/{CemSearch/Lib/vendor → Intelligence/lib}/Thrift/Transport/TCurlClient.php
RENAMED
|
@@ -1,222 +1,222 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
/*
|
| 3 |
-
* Licensed to the Apache Software Foundation (ASF) under one
|
| 4 |
-
* or more contributor license agreements. See the NOTICE file
|
| 5 |
-
* distributed with this work for additional information
|
| 6 |
-
* regarding copyright ownership. The ASF licenses this file
|
| 7 |
-
* to you under the Apache License, Version 2.0 (the
|
| 8 |
-
* "License"); you may not use this file except in compliance
|
| 9 |
-
* with the License. You may obtain a copy of the License at
|
| 10 |
-
*
|
| 11 |
-
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
-
*
|
| 13 |
-
* Unless required by applicable law or agreed to in writing,
|
| 14 |
-
* software distributed under the License is distributed on an
|
| 15 |
-
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 16 |
-
* KIND, either express or implied. See the License for the
|
| 17 |
-
* specific language governing permissions and limitations
|
| 18 |
-
* under the License.
|
| 19 |
-
*
|
| 20 |
-
* @package thrift.transport
|
| 21 |
-
*/
|
| 22 |
-
|
| 23 |
-
namespace Thrift\Transport;
|
| 24 |
-
|
| 25 |
-
use Thrift\Transport\TTransport;
|
| 26 |
-
use Thrift\Exception\TTransportException;
|
| 27 |
-
use Thrift\Factory\TStringFuncFactory;
|
| 28 |
-
|
| 29 |
-
/**
|
| 30 |
-
* HTTP client for Thrift
|
| 31 |
-
*
|
| 32 |
-
* @package thrift.transport
|
| 33 |
-
*/
|
| 34 |
-
class TCurlClient extends TTransport {
|
| 35 |
-
|
| 36 |
-
private static $curlHandle;
|
| 37 |
-
|
| 38 |
-
/**
|
| 39 |
-
* The host to connect to
|
| 40 |
-
*
|
| 41 |
-
* @var string
|
| 42 |
-
*/
|
| 43 |
-
protected $host_;
|
| 44 |
-
|
| 45 |
-
/**
|
| 46 |
-
* The port to connect on
|
| 47 |
-
*
|
| 48 |
-
* @var int
|
| 49 |
-
*/
|
| 50 |
-
protected $port_;
|
| 51 |
-
|
| 52 |
-
/**
|
| 53 |
-
* The URI to request
|
| 54 |
-
*
|
| 55 |
-
* @var string
|
| 56 |
-
*/
|
| 57 |
-
protected $uri_;
|
| 58 |
-
|
| 59 |
-
/**
|
| 60 |
-
* The scheme to use for the request, i.e. http, https
|
| 61 |
-
*
|
| 62 |
-
* @var string
|
| 63 |
-
*/
|
| 64 |
-
protected $scheme_;
|
| 65 |
-
|
| 66 |
-
/**
|
| 67 |
-
* Buffer for the HTTP request data
|
| 68 |
-
*
|
| 69 |
-
* @var string
|
| 70 |
-
*/
|
| 71 |
-
protected $request_;
|
| 72 |
-
|
| 73 |
-
/**
|
| 74 |
-
* Buffer for the HTTP response data.
|
| 75 |
-
*
|
| 76 |
-
* @var binary string
|
| 77 |
-
*/
|
| 78 |
-
protected $response_;
|
| 79 |
-
|
| 80 |
-
/**
|
| 81 |
-
* Read timeout
|
| 82 |
-
*
|
| 83 |
-
* @var float
|
| 84 |
-
*/
|
| 85 |
-
protected $timeout_;
|
| 86 |
-
|
| 87 |
-
/**
|
| 88 |
-
* Make a new HTTP client.
|
| 89 |
-
*
|
| 90 |
-
* @param string $host
|
| 91 |
-
* @param int $port
|
| 92 |
-
* @param string $uri
|
| 93 |
-
*/
|
| 94 |
-
public function __construct($host, $port=80, $uri='', $scheme = 'http') {
|
| 95 |
-
if ((TStringFuncFactory::create()->strlen($uri) > 0) && ($uri{0} != '/')) {
|
| 96 |
-
$uri = '/'.$uri;
|
| 97 |
-
}
|
| 98 |
-
$this->scheme_ = $scheme;
|
| 99 |
-
$this->host_ = $host;
|
| 100 |
-
$this->port_ = $port;
|
| 101 |
-
$this->uri_ = $uri;
|
| 102 |
-
$this->request_ = '';
|
| 103 |
-
$this->response_ = null;
|
| 104 |
-
$this->timeout_ = null;
|
| 105 |
-
}
|
| 106 |
-
|
| 107 |
-
/**
|
| 108 |
-
* Set read timeout
|
| 109 |
-
*
|
| 110 |
-
* @param float $timeout
|
| 111 |
-
*/
|
| 112 |
-
public function setTimeoutSecs($timeout) {
|
| 113 |
-
$this->timeout_ = $timeout;
|
| 114 |
-
}
|
| 115 |
-
|
| 116 |
-
/**
|
| 117 |
-
* Whether this transport is open.
|
| 118 |
-
*
|
| 119 |
-
* @return boolean true if open
|
| 120 |
-
*/
|
| 121 |
-
public function isOpen() {
|
| 122 |
-
return true;
|
| 123 |
-
}
|
| 124 |
-
|
| 125 |
-
/**
|
| 126 |
-
* Open the transport for reading/writing
|
| 127 |
-
*
|
| 128 |
-
* @throws TTransportException if cannot open
|
| 129 |
-
*/
|
| 130 |
-
public function open() {
|
| 131 |
-
}
|
| 132 |
-
|
| 133 |
-
/**
|
| 134 |
-
* Close the transport.
|
| 135 |
-
*/
|
| 136 |
-
public function close() {
|
| 137 |
-
$this->request_ = '';
|
| 138 |
-
$this->response_ = null;
|
| 139 |
-
}
|
| 140 |
-
|
| 141 |
-
/**
|
| 142 |
-
* Read some data into the array.
|
| 143 |
-
*
|
| 144 |
-
* @param int $len How much to read
|
| 145 |
-
* @return string The data that has been read
|
| 146 |
-
* @throws TTransportException if cannot read any more data
|
| 147 |
-
*/
|
| 148 |
-
public function read($len) {
|
| 149 |
-
if ($len >= strlen($this->response_)) {
|
| 150 |
-
return $this->response_;
|
| 151 |
-
} else {
|
| 152 |
-
$ret = substr($this->response_, 0, $len);
|
| 153 |
-
$this->response_ = substr($this->response_, $len);
|
| 154 |
-
return $ret;
|
| 155 |
-
}
|
| 156 |
-
}
|
| 157 |
-
|
| 158 |
-
/**
|
| 159 |
-
* Writes some data into the pending buffer
|
| 160 |
-
*
|
| 161 |
-
* @param string $buf The data to write
|
| 162 |
-
* @throws TTransportException if writing fails
|
| 163 |
-
*/
|
| 164 |
-
public function write($buf) {
|
| 165 |
-
$this->request_ .= $buf;
|
| 166 |
-
}
|
| 167 |
-
|
| 168 |
-
/**
|
| 169 |
-
* Opens and sends the actual request over the HTTP connection
|
| 170 |
-
*
|
| 171 |
-
* @throws TTransportException if a writing error occurs
|
| 172 |
-
*/
|
| 173 |
-
public function flush() {
|
| 174 |
-
if (!self::$curlHandle) {
|
| 175 |
-
register_shutdown_function(array('Thrift\\Transport\\TCurlClient', 'closeCurlHandle'));
|
| 176 |
-
self::$curlHandle = curl_init();
|
| 177 |
-
curl_setopt(self::$curlHandle, CURLOPT_RETURNTRANSFER, true);
|
| 178 |
-
curl_setopt(self::$curlHandle, CURLOPT_BINARYTRANSFER, true);
|
| 179 |
-
curl_setopt(self::$curlHandle, CURLOPT_USERAGENT, 'PHP/TCurlClient');
|
| 180 |
-
curl_setopt(self::$curlHandle, CURLOPT_CUSTOMREQUEST, 'POST');
|
| 181 |
-
curl_setopt(self::$curlHandle, CURLOPT_FOLLOWLOCATION, true);
|
| 182 |
-
curl_setopt(self::$curlHandle, CURLOPT_MAXREDIRS, 1);
|
| 183 |
-
}
|
| 184 |
-
// God, PHP really has some esoteric ways of doing simple things.
|
| 185 |
-
$host = $this->host_.($this->port_ != 80 ? ':'.$this->port_ : '');
|
| 186 |
-
$fullUrl = $this->scheme_."://".$host.$this->uri_;
|
| 187 |
-
|
| 188 |
-
$headers = array('Accept: application/x-thrift',
|
| 189 |
-
'Content-Type: application/x-thrift',
|
| 190 |
-
'Content-Length: '.TStringFuncFactory::create()->strlen($this->request_));
|
| 191 |
-
curl_setopt(self::$curlHandle, CURLOPT_HTTPHEADER, $headers);
|
| 192 |
-
|
| 193 |
-
if ($this->timeout_ > 0) {
|
| 194 |
-
curl_setopt(self::$curlHandle, CURLOPT_TIMEOUT, $this->timeout_);
|
| 195 |
-
}
|
| 196 |
-
curl_setopt(self::$curlHandle, CURLOPT_POSTFIELDS, $this->request_);
|
| 197 |
-
$this->request_ = '';
|
| 198 |
-
|
| 199 |
-
curl_setopt(self::$curlHandle, CURLOPT_URL, $fullUrl);
|
| 200 |
-
$this->response_ = curl_exec(self::$curlHandle);
|
| 201 |
-
|
| 202 |
-
// Connect failed?
|
| 203 |
-
if (!$this->response_) {
|
| 204 |
-
curl_close(self::$curlHandle);
|
| 205 |
-
self::$curlHandle = null;
|
| 206 |
-
$error = 'TCurlClient: Could not connect to '.$fullUrl;
|
| 207 |
-
throw new TTransportException($error, TTransportException::NOT_OPEN);
|
| 208 |
-
}
|
| 209 |
-
}
|
| 210 |
-
|
| 211 |
-
static function closeCurlHandle() {
|
| 212 |
-
try {
|
| 213 |
-
if (self::$curlHandle) {
|
| 214 |
-
curl_close(self::$curlHandle);
|
| 215 |
-
self::$curlHandle = null;
|
| 216 |
-
}
|
| 217 |
-
} catch (\Exception $x) {
|
| 218 |
-
error_log('There was an error closing the curl handle: ' . $x->getMessage());
|
| 219 |
-
}
|
| 220 |
-
}
|
| 221 |
-
|
| 222 |
}
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Licensed to the Apache Software Foundation (ASF) under one
|
| 4 |
+
* or more contributor license agreements. See the NOTICE file
|
| 5 |
+
* distributed with this work for additional information
|
| 6 |
+
* regarding copyright ownership. The ASF licenses this file
|
| 7 |
+
* to you under the Apache License, Version 2.0 (the
|
| 8 |
+
* "License"); you may not use this file except in compliance
|
| 9 |
+
* with the License. You may obtain a copy of the License at
|
| 10 |
+
*
|
| 11 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
+
*
|
| 13 |
+
* Unless required by applicable law or agreed to in writing,
|
| 14 |
+
* software distributed under the License is distributed on an
|
| 15 |
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 16 |
+
* KIND, either express or implied. See the License for the
|
| 17 |
+
* specific language governing permissions and limitations
|
| 18 |
+
* under the License.
|
| 19 |
+
*
|
| 20 |
+
* @package thrift.transport
|
| 21 |
+
*/
|
| 22 |
+
|
| 23 |
+
namespace Thrift\Transport;
|
| 24 |
+
|
| 25 |
+
use Thrift\Transport\TTransport;
|
| 26 |
+
use Thrift\Exception\TTransportException;
|
| 27 |
+
use Thrift\Factory\TStringFuncFactory;
|
| 28 |
+
|
| 29 |
+
/**
|
| 30 |
+
* HTTP client for Thrift
|
| 31 |
+
*
|
| 32 |
+
* @package thrift.transport
|
| 33 |
+
*/
|
| 34 |
+
class TCurlClient extends TTransport {
|
| 35 |
+
|
| 36 |
+
private static $curlHandle;
|
| 37 |
+
|
| 38 |
+
/**
|
| 39 |
+
* The host to connect to
|
| 40 |
+
*
|
| 41 |
+
* @var string
|
| 42 |
+
*/
|
| 43 |
+
protected $host_;
|
| 44 |
+
|
| 45 |
+
/**
|
| 46 |
+
* The port to connect on
|
| 47 |
+
*
|
| 48 |
+
* @var int
|
| 49 |
+
*/
|
| 50 |
+
protected $port_;
|
| 51 |
+
|
| 52 |
+
/**
|
| 53 |
+
* The URI to request
|
| 54 |
+
*
|
| 55 |
+
* @var string
|
| 56 |
+
*/
|
| 57 |
+
protected $uri_;
|
| 58 |
+
|
| 59 |
+
/**
|
| 60 |
+
* The scheme to use for the request, i.e. http, https
|
| 61 |
+
*
|
| 62 |
+
* @var string
|
| 63 |
+
*/
|
| 64 |
+
protected $scheme_;
|
| 65 |
+
|
| 66 |
+
/**
|
| 67 |
+
* Buffer for the HTTP request data
|
| 68 |
+
*
|
| 69 |
+
* @var string
|
| 70 |
+
*/
|
| 71 |
+
protected $request_;
|
| 72 |
+
|
| 73 |
+
/**
|
| 74 |
+
* Buffer for the HTTP response data.
|
| 75 |
+
*
|
| 76 |
+
* @var binary string
|
| 77 |
+
*/
|
| 78 |
+
protected $response_;
|
| 79 |
+
|
| 80 |
+
/**
|
| 81 |
+
* Read timeout
|
| 82 |
+
*
|
| 83 |
+
* @var float
|
| 84 |
+
*/
|
| 85 |
+
protected $timeout_;
|
| 86 |
+
|
| 87 |
+
/**
|
| 88 |
+
* Make a new HTTP client.
|
| 89 |
+
*
|
| 90 |
+
* @param string $host
|
| 91 |
+
* @param int $port
|
| 92 |
+
* @param string $uri
|
| 93 |
+
*/
|
| 94 |
+
public function __construct($host, $port=80, $uri='', $scheme = 'http') {
|
| 95 |
+
if ((TStringFuncFactory::create()->strlen($uri) > 0) && ($uri{0} != '/')) {
|
| 96 |
+
$uri = '/'.$uri;
|
| 97 |
+
}
|
| 98 |
+
$this->scheme_ = $scheme;
|
| 99 |
+
$this->host_ = $host;
|
| 100 |
+
$this->port_ = $port;
|
| 101 |
+
$this->uri_ = $uri;
|
| 102 |
+
$this->request_ = '';
|
| 103 |
+
$this->response_ = null;
|
| 104 |
+
$this->timeout_ = null;
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
/**
|
| 108 |
+
* Set read timeout
|
| 109 |
+
*
|
| 110 |
+
* @param float $timeout
|
| 111 |
+
*/
|
| 112 |
+
public function setTimeoutSecs($timeout) {
|
| 113 |
+
$this->timeout_ = $timeout;
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
/**
|
| 117 |
+
* Whether this transport is open.
|
| 118 |
+
*
|
| 119 |
+
* @return boolean true if open
|
| 120 |
+
*/
|
| 121 |
+
public function isOpen() {
|
| 122 |
+
return true;
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
/**
|
| 126 |
+
* Open the transport for reading/writing
|
| 127 |
+
*
|
| 128 |
+
* @throws TTransportException if cannot open
|
| 129 |
+
*/
|
| 130 |
+
public function open() {
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
/**
|
| 134 |
+
* Close the transport.
|
| 135 |
+
*/
|
| 136 |
+
public function close() {
|
| 137 |
+
$this->request_ = '';
|
| 138 |
+
$this->response_ = null;
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
/**
|
| 142 |
+
* Read some data into the array.
|
| 143 |
+
*
|
| 144 |
+
* @param int $len How much to read
|
| 145 |
+
* @return string The data that has been read
|
| 146 |
+
* @throws TTransportException if cannot read any more data
|
| 147 |
+
*/
|
| 148 |
+
public function read($len) {
|
| 149 |
+
if ($len >= strlen($this->response_)) {
|
| 150 |
+
return $this->response_;
|
| 151 |
+
} else {
|
| 152 |
+
$ret = substr($this->response_, 0, $len);
|
| 153 |
+
$this->response_ = substr($this->response_, $len);
|
| 154 |
+
return $ret;
|
| 155 |
+
}
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
/**
|
| 159 |
+
* Writes some data into the pending buffer
|
| 160 |
+
*
|
| 161 |
+
* @param string $buf The data to write
|
| 162 |
+
* @throws TTransportException if writing fails
|
| 163 |
+
*/
|
| 164 |
+
public function write($buf) {
|
| 165 |
+
$this->request_ .= $buf;
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
/**
|
| 169 |
+
* Opens and sends the actual request over the HTTP connection
|
| 170 |
+
*
|
| 171 |
+
* @throws TTransportException if a writing error occurs
|
| 172 |
+
*/
|
| 173 |
+
public function flush() {
|
| 174 |
+
if (!self::$curlHandle) {
|
| 175 |
+
register_shutdown_function(array('Thrift\\Transport\\TCurlClient', 'closeCurlHandle'));
|
| 176 |
+
self::$curlHandle = curl_init();
|
| 177 |
+
curl_setopt(self::$curlHandle, CURLOPT_RETURNTRANSFER, true);
|
| 178 |
+
curl_setopt(self::$curlHandle, CURLOPT_BINARYTRANSFER, true);
|
| 179 |
+
curl_setopt(self::$curlHandle, CURLOPT_USERAGENT, 'PHP/TCurlClient');
|
| 180 |
+
curl_setopt(self::$curlHandle, CURLOPT_CUSTOMREQUEST, 'POST');
|
| 181 |
+
curl_setopt(self::$curlHandle, CURLOPT_FOLLOWLOCATION, true);
|
| 182 |
+
curl_setopt(self::$curlHandle, CURLOPT_MAXREDIRS, 1);
|
| 183 |
+
}
|
| 184 |
+
// God, PHP really has some esoteric ways of doing simple things.
|
| 185 |
+
$host = $this->host_.($this->port_ != 80 ? ':'.$this->port_ : '');
|
| 186 |
+
$fullUrl = $this->scheme_."://".$host.$this->uri_;
|
| 187 |
+
|
| 188 |
+
$headers = array('Accept: application/x-thrift',
|
| 189 |
+
'Content-Type: application/x-thrift',
|
| 190 |
+
'Content-Length: '.TStringFuncFactory::create()->strlen($this->request_));
|
| 191 |
+
curl_setopt(self::$curlHandle, CURLOPT_HTTPHEADER, $headers);
|
| 192 |
+
|
| 193 |
+
if ($this->timeout_ > 0) {
|
| 194 |
+
curl_setopt(self::$curlHandle, CURLOPT_TIMEOUT, $this->timeout_);
|
| 195 |
+
}
|
| 196 |
+
curl_setopt(self::$curlHandle, CURLOPT_POSTFIELDS, $this->request_);
|
| 197 |
+
$this->request_ = '';
|
| 198 |
+
|
| 199 |
+
curl_setopt(self::$curlHandle, CURLOPT_URL, $fullUrl);
|
| 200 |
+
$this->response_ = curl_exec(self::$curlHandle);
|
| 201 |
+
|
| 202 |
+
// Connect failed?
|
| 203 |
+
if (!$this->response_) {
|
| 204 |
+
curl_close(self::$curlHandle);
|
| 205 |
+
self::$curlHandle = null;
|
| 206 |
+
$error = 'TCurlClient: Could not connect to '.$fullUrl;
|
| 207 |
+
throw new TTransportException($error, TTransportException::NOT_OPEN);
|
| 208 |
+
}
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
static function closeCurlHandle() {
|
| 212 |
+
try {
|
| 213 |
+
if (self::$curlHandle) {
|
| 214 |
+
curl_close(self::$curlHandle);
|
| 215 |
+
self::$curlHandle = null;
|
| 216 |
+
}
|
| 217 |
+
} catch (\Exception $x) {
|
| 218 |
+
error_log('There was an error closing the curl handle: ' . $x->getMessage());
|
| 219 |
+
}
|
| 220 |
+
}
|
| 221 |
+
|
| 222 |
}
|
app/code/community/Boxalino/{CemSearch/Lib/vendor → Intelligence/lib}/Thrift/Transport/TFramedTransport.php
RENAMED
|
@@ -1,183 +1,183 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
/*
|
| 3 |
-
* Licensed to the Apache Software Foundation (ASF) under one
|
| 4 |
-
* or more contributor license agreements. See the NOTICE file
|
| 5 |
-
* distributed with this work for additional information
|
| 6 |
-
* regarding copyright ownership. The ASF licenses this file
|
| 7 |
-
* to you under the Apache License, Version 2.0 (the
|
| 8 |
-
* "License"); you may not use this file except in compliance
|
| 9 |
-
* with the License. You may obtain a copy of the License at
|
| 10 |
-
*
|
| 11 |
-
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
-
*
|
| 13 |
-
* Unless required by applicable law or agreed to in writing,
|
| 14 |
-
* software distributed under the License is distributed on an
|
| 15 |
-
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 16 |
-
* KIND, either express or implied. See the License for the
|
| 17 |
-
* specific language governing permissions and limitations
|
| 18 |
-
* under the License.
|
| 19 |
-
*
|
| 20 |
-
* @package thrift.transport
|
| 21 |
-
*/
|
| 22 |
-
|
| 23 |
-
namespace Thrift\Transport;
|
| 24 |
-
|
| 25 |
-
use Thrift\Transport\TTransport;
|
| 26 |
-
use Thrift\Factory\TStringFuncFactory;
|
| 27 |
-
|
| 28 |
-
/**
|
| 29 |
-
* Framed transport. Writes and reads data in chunks that are stamped with
|
| 30 |
-
* their length.
|
| 31 |
-
*
|
| 32 |
-
* @package thrift.transport
|
| 33 |
-
*/
|
| 34 |
-
class TFramedTransport extends TTransport {
|
| 35 |
-
|
| 36 |
-
/**
|
| 37 |
-
* Underlying transport object.
|
| 38 |
-
*
|
| 39 |
-
* @var TTransport
|
| 40 |
-
*/
|
| 41 |
-
private $transport_;
|
| 42 |
-
|
| 43 |
-
/**
|
| 44 |
-
* Buffer for read data.
|
| 45 |
-
*
|
| 46 |
-
* @var string
|
| 47 |
-
*/
|
| 48 |
-
private $rBuf_;
|
| 49 |
-
|
| 50 |
-
/**
|
| 51 |
-
* Buffer for queued output data
|
| 52 |
-
*
|
| 53 |
-
* @var string
|
| 54 |
-
*/
|
| 55 |
-
private $wBuf_;
|
| 56 |
-
|
| 57 |
-
/**
|
| 58 |
-
* Whether to frame reads
|
| 59 |
-
*
|
| 60 |
-
* @var bool
|
| 61 |
-
*/
|
| 62 |
-
private $read_;
|
| 63 |
-
|
| 64 |
-
/**
|
| 65 |
-
* Whether to frame writes
|
| 66 |
-
*
|
| 67 |
-
* @var bool
|
| 68 |
-
*/
|
| 69 |
-
private $write_;
|
| 70 |
-
|
| 71 |
-
/**
|
| 72 |
-
* Constructor.
|
| 73 |
-
*
|
| 74 |
-
* @param TTransport $transport Underlying transport
|
| 75 |
-
*/
|
| 76 |
-
public function __construct($transport=null, $read=true, $write=true) {
|
| 77 |
-
$this->transport_ = $transport;
|
| 78 |
-
$this->read_ = $read;
|
| 79 |
-
$this->write_ = $write;
|
| 80 |
-
}
|
| 81 |
-
|
| 82 |
-
public function isOpen() {
|
| 83 |
-
return $this->transport_->isOpen();
|
| 84 |
-
}
|
| 85 |
-
|
| 86 |
-
public function open() {
|
| 87 |
-
$this->transport_->open();
|
| 88 |
-
}
|
| 89 |
-
|
| 90 |
-
public function close() {
|
| 91 |
-
$this->transport_->close();
|
| 92 |
-
}
|
| 93 |
-
|
| 94 |
-
/**
|
| 95 |
-
* Reads from the buffer. When more data is required reads another entire
|
| 96 |
-
* chunk and serves future reads out of that.
|
| 97 |
-
*
|
| 98 |
-
* @param int $len How much data
|
| 99 |
-
*/
|
| 100 |
-
public function read($len) {
|
| 101 |
-
if (!$this->read_) {
|
| 102 |
-
return $this->transport_->read($len);
|
| 103 |
-
}
|
| 104 |
-
|
| 105 |
-
if (TStringFuncFactory::create()->strlen($this->rBuf_) === 0) {
|
| 106 |
-
$this->readFrame();
|
| 107 |
-
}
|
| 108 |
-
|
| 109 |
-
// Just return full buff
|
| 110 |
-
if ($len >= TStringFuncFactory::create()->strlen($this->rBuf_)) {
|
| 111 |
-
$out = $this->rBuf_;
|
| 112 |
-
$this->rBuf_ = null;
|
| 113 |
-
return $out;
|
| 114 |
-
}
|
| 115 |
-
|
| 116 |
-
// Return TStringFuncFactory::create()->substr
|
| 117 |
-
$out = TStringFuncFactory::create()->substr($this->rBuf_, 0, $len);
|
| 118 |
-
$this->rBuf_ = TStringFuncFactory::create()->substr($this->rBuf_, $len);
|
| 119 |
-
return $out;
|
| 120 |
-
}
|
| 121 |
-
|
| 122 |
-
/**
|
| 123 |
-
* Put previously read data back into the buffer
|
| 124 |
-
*
|
| 125 |
-
* @param string $data data to return
|
| 126 |
-
*/
|
| 127 |
-
public function putBack($data) {
|
| 128 |
-
if (TStringFuncFactory::create()->strlen($this->rBuf_) === 0) {
|
| 129 |
-
$this->rBuf_ = $data;
|
| 130 |
-
} else {
|
| 131 |
-
$this->rBuf_ = ($data . $this->rBuf_);
|
| 132 |
-
}
|
| 133 |
-
}
|
| 134 |
-
|
| 135 |
-
/**
|
| 136 |
-
* Reads a chunk of data into the internal read buffer.
|
| 137 |
-
*/
|
| 138 |
-
private function readFrame() {
|
| 139 |
-
$buf = $this->transport_->readAll(4);
|
| 140 |
-
$val = unpack('N', $buf);
|
| 141 |
-
$sz = $val[1];
|
| 142 |
-
|
| 143 |
-
$this->rBuf_ = $this->transport_->readAll($sz);
|
| 144 |
-
}
|
| 145 |
-
|
| 146 |
-
/**
|
| 147 |
-
* Writes some data to the pending output buffer.
|
| 148 |
-
*
|
| 149 |
-
* @param string $buf The data
|
| 150 |
-
* @param int $len Limit of bytes to write
|
| 151 |
-
*/
|
| 152 |
-
public function write($buf, $len=null) {
|
| 153 |
-
if (!$this->write_) {
|
| 154 |
-
return $this->transport_->write($buf, $len);
|
| 155 |
-
}
|
| 156 |
-
|
| 157 |
-
if ($len !== null && $len < TStringFuncFactory::create()->strlen($buf)) {
|
| 158 |
-
$buf = TStringFuncFactory::create()->substr($buf, 0, $len);
|
| 159 |
-
}
|
| 160 |
-
$this->wBuf_ .= $buf;
|
| 161 |
-
}
|
| 162 |
-
|
| 163 |
-
/**
|
| 164 |
-
* Writes the output buffer to the stream in the format of a 4-byte length
|
| 165 |
-
* followed by the actual data.
|
| 166 |
-
*/
|
| 167 |
-
public function flush() {
|
| 168 |
-
if (!$this->write_ || TStringFuncFactory::create()->strlen($this->wBuf_) == 0) {
|
| 169 |
-
return $this->transport_->flush();
|
| 170 |
-
}
|
| 171 |
-
|
| 172 |
-
$out = pack('N', TStringFuncFactory::create()->strlen($this->wBuf_));
|
| 173 |
-
$out .= $this->wBuf_;
|
| 174 |
-
|
| 175 |
-
// Note that we clear the internal wBuf_ prior to the underlying write
|
| 176 |
-
// to ensure we're in a sane state (i.e. internal buffer cleaned)
|
| 177 |
-
// if the underlying write throws up an exception
|
| 178 |
-
$this->wBuf_ = '';
|
| 179 |
-
$this->transport_->write($out);
|
| 180 |
-
$this->transport_->flush();
|
| 181 |
-
}
|
| 182 |
-
|
| 183 |
-
}
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Licensed to the Apache Software Foundation (ASF) under one
|
| 4 |
+
* or more contributor license agreements. See the NOTICE file
|
| 5 |
+
* distributed with this work for additional information
|
| 6 |
+
* regarding copyright ownership. The ASF licenses this file
|
| 7 |
+
* to you under the Apache License, Version 2.0 (the
|
| 8 |
+
* "License"); you may not use this file except in compliance
|
| 9 |
+
* with the License. You may obtain a copy of the License at
|
| 10 |
+
*
|
| 11 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
+
*
|
| 13 |
+
* Unless required by applicable law or agreed to in writing,
|
| 14 |
+
* software distributed under the License is distributed on an
|
| 15 |
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 16 |
+
* KIND, either express or implied. See the License for the
|
| 17 |
+
* specific language governing permissions and limitations
|
| 18 |
+
* under the License.
|
| 19 |
+
*
|
| 20 |
+
* @package thrift.transport
|
| 21 |
+
*/
|
| 22 |
+
|
| 23 |
+
namespace Thrift\Transport;
|
| 24 |
+
|
| 25 |
+
use Thrift\Transport\TTransport;
|
| 26 |
+
use Thrift\Factory\TStringFuncFactory;
|
| 27 |
+
|
| 28 |
+
/**
|
| 29 |
+
* Framed transport. Writes and reads data in chunks that are stamped with
|
| 30 |
+
* their length.
|
| 31 |
+
*
|
| 32 |
+
* @package thrift.transport
|
| 33 |
+
*/
|
| 34 |
+
class TFramedTransport extends TTransport {
|
| 35 |
+
|
| 36 |
+
/**
|
| 37 |
+
* Underlying transport object.
|
| 38 |
+
*
|
| 39 |
+
* @var TTransport
|
| 40 |
+
*/
|
| 41 |
+
private $transport_;
|
| 42 |
+
|
| 43 |
+
/**
|
| 44 |
+
* Buffer for read data.
|
| 45 |
+
*
|
| 46 |
+
* @var string
|
| 47 |
+
*/
|
| 48 |
+
private $rBuf_;
|
| 49 |
+
|
| 50 |
+
/**
|
| 51 |
+
* Buffer for queued output data
|
| 52 |
+
*
|
| 53 |
+
* @var string
|
| 54 |
+
*/
|
| 55 |
+
private $wBuf_;
|
| 56 |
+
|
| 57 |
+
/**
|
| 58 |
+
* Whether to frame reads
|
| 59 |
+
*
|
| 60 |
+
* @var bool
|
| 61 |
+
*/
|
| 62 |
+
private $read_;
|
| 63 |
+
|
| 64 |
+
/**
|
| 65 |
+
* Whether to frame writes
|
| 66 |
+
*
|
| 67 |
+
* @var bool
|
| 68 |
+
*/
|
| 69 |
+
private $write_;
|
| 70 |
+
|
| 71 |
+
/**
|
| 72 |
+
* Constructor.
|
| 73 |
+
*
|
| 74 |
+
* @param TTransport $transport Underlying transport
|
| 75 |
+
*/
|
| 76 |
+
public function __construct($transport=null, $read=true, $write=true) {
|
| 77 |
+
$this->transport_ = $transport;
|
| 78 |
+
$this->read_ = $read;
|
| 79 |
+
$this->write_ = $write;
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
public function isOpen() {
|
| 83 |
+
return $this->transport_->isOpen();
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
public function open() {
|
| 87 |
+
$this->transport_->open();
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
public function close() {
|
| 91 |
+
$this->transport_->close();
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
/**
|
| 95 |
+
* Reads from the buffer. When more data is required reads another entire
|
| 96 |
+
* chunk and serves future reads out of that.
|
| 97 |
+
*
|
| 98 |
+
* @param int $len How much data
|
| 99 |
+
*/
|
| 100 |
+
public function read($len) {
|
| 101 |
+
if (!$this->read_) {
|
| 102 |
+
return $this->transport_->read($len);
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
if (TStringFuncFactory::create()->strlen($this->rBuf_) === 0) {
|
| 106 |
+
$this->readFrame();
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
// Just return full buff
|
| 110 |
+
if ($len >= TStringFuncFactory::create()->strlen($this->rBuf_)) {
|
| 111 |
+
$out = $this->rBuf_;
|
| 112 |
+
$this->rBuf_ = null;
|
| 113 |
+
return $out;
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
// Return TStringFuncFactory::create()->substr
|
| 117 |
+
$out = TStringFuncFactory::create()->substr($this->rBuf_, 0, $len);
|
| 118 |
+
$this->rBuf_ = TStringFuncFactory::create()->substr($this->rBuf_, $len);
|
| 119 |
+
return $out;
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
/**
|
| 123 |
+
* Put previously read data back into the buffer
|
| 124 |
+
*
|
| 125 |
+
* @param string $data data to return
|
| 126 |
+
*/
|
| 127 |
+
public function putBack($data) {
|
| 128 |
+
if (TStringFuncFactory::create()->strlen($this->rBuf_) === 0) {
|
| 129 |
+
$this->rBuf_ = $data;
|
| 130 |
+
} else {
|
| 131 |
+
$this->rBuf_ = ($data . $this->rBuf_);
|
| 132 |
+
}
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
/**
|
| 136 |
+
* Reads a chunk of data into the internal read buffer.
|
| 137 |
+
*/
|
| 138 |
+
private function readFrame() {
|
| 139 |
+
$buf = $this->transport_->readAll(4);
|
| 140 |
+
$val = unpack('N', $buf);
|
| 141 |
+
$sz = $val[1];
|
| 142 |
+
|
| 143 |
+
$this->rBuf_ = $this->transport_->readAll($sz);
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
/**
|
| 147 |
+
* Writes some data to the pending output buffer.
|
| 148 |
+
*
|
| 149 |
+
* @param string $buf The data
|
| 150 |
+
* @param int $len Limit of bytes to write
|
| 151 |
+
*/
|
| 152 |
+
public function write($buf, $len=null) {
|
| 153 |
+
if (!$this->write_) {
|
| 154 |
+
return $this->transport_->write($buf, $len);
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
if ($len !== null && $len < TStringFuncFactory::create()->strlen($buf)) {
|
| 158 |
+
$buf = TStringFuncFactory::create()->substr($buf, 0, $len);
|
| 159 |
+
}
|
| 160 |
+
$this->wBuf_ .= $buf;
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
/**
|
| 164 |
+
* Writes the output buffer to the stream in the format of a 4-byte length
|
| 165 |
+
* followed by the actual data.
|
| 166 |
+
*/
|
| 167 |
+
public function flush() {
|
| 168 |
+
if (!$this->write_ || TStringFuncFactory::create()->strlen($this->wBuf_) == 0) {
|
| 169 |
+
return $this->transport_->flush();
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
$out = pack('N', TStringFuncFactory::create()->strlen($this->wBuf_));
|
| 173 |
+
$out .= $this->wBuf_;
|
| 174 |
+
|
| 175 |
+
// Note that we clear the internal wBuf_ prior to the underlying write
|
| 176 |
+
// to ensure we're in a sane state (i.e. internal buffer cleaned)
|
| 177 |
+
// if the underlying write throws up an exception
|
| 178 |
+
$this->wBuf_ = '';
|
| 179 |
+
$this->transport_->write($out);
|
| 180 |
+
$this->transport_->flush();
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
}
|
app/code/community/Boxalino/{CemSearch/Lib/vendor → Intelligence/lib}/Thrift/Transport/THttpClient.php
RENAMED
|
@@ -1,206 +1,206 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
/*
|
| 3 |
-
* Licensed to the Apache Software Foundation (ASF) under one
|
| 4 |
-
* or more contributor license agreements. See the NOTICE file
|
| 5 |
-
* distributed with this work for additional information
|
| 6 |
-
* regarding copyright ownership. The ASF licenses this file
|
| 7 |
-
* to you under the Apache License, Version 2.0 (the
|
| 8 |
-
* "License"); you may not use this file except in compliance
|
| 9 |
-
* with the License. You may obtain a copy of the License at
|
| 10 |
-
*
|
| 11 |
-
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
-
*
|
| 13 |
-
* Unless required by applicable law or agreed to in writing,
|
| 14 |
-
* software distributed under the License is distributed on an
|
| 15 |
-
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 16 |
-
* KIND, either express or implied. See the License for the
|
| 17 |
-
* specific language governing permissions and limitations
|
| 18 |
-
* under the License.
|
| 19 |
-
*
|
| 20 |
-
* @package thrift.transport
|
| 21 |
-
*/
|
| 22 |
-
|
| 23 |
-
namespace Thrift\Transport;
|
| 24 |
-
|
| 25 |
-
use Thrift\Transport\TTransport;
|
| 26 |
-
use Thrift\Exception\TTransportException;
|
| 27 |
-
use Thrift\Factory\TStringFuncFactory;
|
| 28 |
-
|
| 29 |
-
/**
|
| 30 |
-
* HTTP client for Thrift
|
| 31 |
-
*
|
| 32 |
-
* @package thrift.transport
|
| 33 |
-
*/
|
| 34 |
-
class THttpClient extends TTransport {
|
| 35 |
-
|
| 36 |
-
/**
|
| 37 |
-
* The host to connect to
|
| 38 |
-
*
|
| 39 |
-
* @var string
|
| 40 |
-
*/
|
| 41 |
-
protected $host_;
|
| 42 |
-
|
| 43 |
-
/**
|
| 44 |
-
* The port to connect on
|
| 45 |
-
*
|
| 46 |
-
* @var int
|
| 47 |
-
*/
|
| 48 |
-
protected $port_;
|
| 49 |
-
|
| 50 |
-
/**
|
| 51 |
-
* The URI to request
|
| 52 |
-
*
|
| 53 |
-
* @var string
|
| 54 |
-
*/
|
| 55 |
-
protected $uri_;
|
| 56 |
-
|
| 57 |
-
/**
|
| 58 |
-
* The scheme to use for the request, i.e. http, https
|
| 59 |
-
*
|
| 60 |
-
* @var string
|
| 61 |
-
*/
|
| 62 |
-
protected $scheme_;
|
| 63 |
-
|
| 64 |
-
/**
|
| 65 |
-
* Buffer for the HTTP request data
|
| 66 |
-
*
|
| 67 |
-
* @var string
|
| 68 |
-
*/
|
| 69 |
-
protected $buf_;
|
| 70 |
-
|
| 71 |
-
/**
|
| 72 |
-
* Input socket stream.
|
| 73 |
-
*
|
| 74 |
-
* @var resource
|
| 75 |
-
*/
|
| 76 |
-
protected $handle_;
|
| 77 |
-
|
| 78 |
-
/**
|
| 79 |
-
* Read timeout
|
| 80 |
-
*
|
| 81 |
-
* @var float
|
| 82 |
-
*/
|
| 83 |
-
protected $timeout_;
|
| 84 |
-
|
| 85 |
-
/**
|
| 86 |
-
* Make a new HTTP client.
|
| 87 |
-
*
|
| 88 |
-
* @param string $host
|
| 89 |
-
* @param int $port
|
| 90 |
-
* @param string $uri
|
| 91 |
-
*/
|
| 92 |
-
public function __construct($host, $port=80, $uri='', $scheme = 'http') {
|
| 93 |
-
if ((TStringFuncFactory::create()->strlen($uri) > 0) && ($uri{0} != '/')) {
|
| 94 |
-
$uri = '/'.$uri;
|
| 95 |
-
}
|
| 96 |
-
$this->scheme_ = $scheme;
|
| 97 |
-
$this->host_ = $host;
|
| 98 |
-
$this->port_ = $port;
|
| 99 |
-
$this->uri_ = $uri;
|
| 100 |
-
$this->buf_ = '';
|
| 101 |
-
$this->handle_ = null;
|
| 102 |
-
$this->timeout_ = null;
|
| 103 |
-
}
|
| 104 |
-
|
| 105 |
-
/**
|
| 106 |
-
* Set read timeout
|
| 107 |
-
*
|
| 108 |
-
* @param float $timeout
|
| 109 |
-
*/
|
| 110 |
-
public function setTimeoutSecs($timeout) {
|
| 111 |
-
$this->timeout_ = $timeout;
|
| 112 |
-
}
|
| 113 |
-
|
| 114 |
-
/**
|
| 115 |
-
* Whether this transport is open.
|
| 116 |
-
*
|
| 117 |
-
* @return boolean true if open
|
| 118 |
-
*/
|
| 119 |
-
public function isOpen() {
|
| 120 |
-
return true;
|
| 121 |
-
}
|
| 122 |
-
|
| 123 |
-
/**
|
| 124 |
-
* Open the transport for reading/writing
|
| 125 |
-
*
|
| 126 |
-
* @throws TTransportException if cannot open
|
| 127 |
-
*/
|
| 128 |
-
public function open() {}
|
| 129 |
-
|
| 130 |
-
/**
|
| 131 |
-
* Close the transport.
|
| 132 |
-
*/
|
| 133 |
-
public function close() {
|
| 134 |
-
if ($this->handle_) {
|
| 135 |
-
@fclose($this->handle_);
|
| 136 |
-
$this->handle_ = null;
|
| 137 |
-
}
|
| 138 |
-
}
|
| 139 |
-
|
| 140 |
-
/**
|
| 141 |
-
* Read some data into the array.
|
| 142 |
-
*
|
| 143 |
-
* @param int $len How much to read
|
| 144 |
-
* @return string The data that has been read
|
| 145 |
-
* @throws TTransportException if cannot read any more data
|
| 146 |
-
*/
|
| 147 |
-
public function read($len) {
|
| 148 |
-
$data = @fread($this->handle_, $len);
|
| 149 |
-
if ($data === FALSE || $data === '') {
|
| 150 |
-
$md = stream_get_meta_data($this->handle_);
|
| 151 |
-
if ($md['timed_out']) {
|
| 152 |
-
throw new TTransportException('THttpClient: timed out reading '.$len.' bytes from '.$this->host_.':'.$this->port_.$this->uri_, TTransportException::TIMED_OUT);
|
| 153 |
-
} else {
|
| 154 |
-
throw new TTransportException('THttpClient: Could not read '.$len.' bytes from '.$this->host_.':'.$this->port_.$this->uri_, TTransportException::UNKNOWN);
|
| 155 |
-
}
|
| 156 |
-
}
|
| 157 |
-
return $data;
|
| 158 |
-
}
|
| 159 |
-
|
| 160 |
-
/**
|
| 161 |
-
* Writes some data into the pending buffer
|
| 162 |
-
*
|
| 163 |
-
* @param string $buf The data to write
|
| 164 |
-
* @throws TTransportException if writing fails
|
| 165 |
-
*/
|
| 166 |
-
public function write($buf) {
|
| 167 |
-
$this->buf_ .= $buf;
|
| 168 |
-
}
|
| 169 |
-
|
| 170 |
-
/**
|
| 171 |
-
* Opens and sends the actual request over the HTTP connection
|
| 172 |
-
*
|
| 173 |
-
* @throws TTransportException if a writing error occurs
|
| 174 |
-
*/
|
| 175 |
-
public function flush() {
|
| 176 |
-
// God, PHP really has some esoteric ways of doing simple things.
|
| 177 |
-
$host = $this->host_.($this->port_ != 80 ? ':'.$this->port_ : '');
|
| 178 |
-
|
| 179 |
-
$headers = array('Host: '.$host,
|
| 180 |
-
'Accept: application/x-thrift',
|
| 181 |
-
'User-Agent: PHP/THttpClient',
|
| 182 |
-
'Content-Type: application/x-thrift',
|
| 183 |
-
'Content-Length: '.TStringFuncFactory::create()->strlen($this->buf_),
|
| 184 |
-
'Authorization: Basic Z2VzY2hlbmtpZGVlOlRoYWViOG9vdG9vWA==');
|
| 185 |
-
|
| 186 |
-
$options = array('method' => 'POST',
|
| 187 |
-
'header' => implode("\r\n", $headers),
|
| 188 |
-
'max_redirects' => 1,
|
| 189 |
-
'content' => $this->buf_);
|
| 190 |
-
if ($this->timeout_ > 0) {
|
| 191 |
-
$options['timeout'] = $this->timeout_;
|
| 192 |
-
}
|
| 193 |
-
$this->buf_ = '';
|
| 194 |
-
|
| 195 |
-
$contextid = stream_context_create(array('http' => $options));
|
| 196 |
-
$this->handle_ = @fopen($this->scheme_.'://'.$host.$this->uri_, 'r', false, $contextid);
|
| 197 |
-
|
| 198 |
-
// Connect failed?
|
| 199 |
-
if ($this->handle_ === FALSE) {
|
| 200 |
-
$this->handle_ = null;
|
| 201 |
-
$error = 'THttpClient: Could not connect to '.$host.$this->uri_;
|
| 202 |
-
throw new TTransportException($error, TTransportException::NOT_OPEN);
|
| 203 |
-
}
|
| 204 |
-
}
|
| 205 |
-
|
| 206 |
-
}
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Licensed to the Apache Software Foundation (ASF) under one
|
| 4 |
+
* or more contributor license agreements. See the NOTICE file
|
| 5 |
+
* distributed with this work for additional information
|
| 6 |
+
* regarding copyright ownership. The ASF licenses this file
|
| 7 |
+
* to you under the Apache License, Version 2.0 (the
|
| 8 |
+
* "License"); you may not use this file except in compliance
|
| 9 |
+
* with the License. You may obtain a copy of the License at
|
| 10 |
+
*
|
| 11 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
+
*
|
| 13 |
+
* Unless required by applicable law or agreed to in writing,
|
| 14 |
+
* software distributed under the License is distributed on an
|
| 15 |
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 16 |
+
* KIND, either express or implied. See the License for the
|
| 17 |
+
* specific language governing permissions and limitations
|
| 18 |
+
* under the License.
|
| 19 |
+
*
|
| 20 |
+
* @package thrift.transport
|
| 21 |
+
*/
|
| 22 |
+
|
| 23 |
+
namespace Thrift\Transport;
|
| 24 |
+
|
| 25 |
+
use Thrift\Transport\TTransport;
|
| 26 |
+
use Thrift\Exception\TTransportException;
|
| 27 |
+
use Thrift\Factory\TStringFuncFactory;
|
| 28 |
+
|
| 29 |
+
/**
|
| 30 |
+
* HTTP client for Thrift
|
| 31 |
+
*
|
| 32 |
+
* @package thrift.transport
|
| 33 |
+
*/
|
| 34 |
+
class THttpClient extends TTransport {
|
| 35 |
+
|
| 36 |
+
/**
|
| 37 |
+
* The host to connect to
|
| 38 |
+
*
|
| 39 |
+
* @var string
|
| 40 |
+
*/
|
| 41 |
+
protected $host_;
|
| 42 |
+
|
| 43 |
+
/**
|
| 44 |
+
* The port to connect on
|
| 45 |
+
*
|
| 46 |
+
* @var int
|
| 47 |
+
*/
|
| 48 |
+
protected $port_;
|
| 49 |
+
|
| 50 |
+
/**
|
| 51 |
+
* The URI to request
|
| 52 |
+
*
|
| 53 |
+
* @var string
|
| 54 |
+
*/
|
| 55 |
+
protected $uri_;
|
| 56 |
+
|
| 57 |
+
/**
|
| 58 |
+
* The scheme to use for the request, i.e. http, https
|
| 59 |
+
*
|
| 60 |
+
* @var string
|
| 61 |
+
*/
|
| 62 |
+
protected $scheme_;
|
| 63 |
+
|
| 64 |
+
/**
|
| 65 |
+
* Buffer for the HTTP request data
|
| 66 |
+
*
|
| 67 |
+
* @var string
|
| 68 |
+
*/
|
| 69 |
+
protected $buf_;
|
| 70 |
+
|
| 71 |
+
/**
|
| 72 |
+
* Input socket stream.
|
| 73 |
+
*
|
| 74 |
+
* @var resource
|
| 75 |
+
*/
|
| 76 |
+
protected $handle_;
|
| 77 |
+
|
| 78 |
+
/**
|
| 79 |
+
* Read timeout
|
| 80 |
+
*
|
| 81 |
+
* @var float
|
| 82 |
+
*/
|
| 83 |
+
protected $timeout_;
|
| 84 |
+
|
| 85 |
+
/**
|
| 86 |
+
* Make a new HTTP client.
|
| 87 |
+
*
|
| 88 |
+
* @param string $host
|
| 89 |
+
* @param int $port
|
| 90 |
+
* @param string $uri
|
| 91 |
+
*/
|
| 92 |
+
public function __construct($host, $port=80, $uri='', $scheme = 'http') {
|
| 93 |
+
if ((TStringFuncFactory::create()->strlen($uri) > 0) && ($uri{0} != '/')) {
|
| 94 |
+
$uri = '/'.$uri;
|
| 95 |
+
}
|
| 96 |
+
$this->scheme_ = $scheme;
|
| 97 |
+
$this->host_ = $host;
|
| 98 |
+
$this->port_ = $port;
|
| 99 |
+
$this->uri_ = $uri;
|
| 100 |
+
$this->buf_ = '';
|
| 101 |
+
$this->handle_ = null;
|
| 102 |
+
$this->timeout_ = null;
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
/**
|
| 106 |
+
* Set read timeout
|
| 107 |
+
*
|
| 108 |
+
* @param float $timeout
|
| 109 |
+
*/
|
| 110 |
+
public function setTimeoutSecs($timeout) {
|
| 111 |
+
$this->timeout_ = $timeout;
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
/**
|
| 115 |
+
* Whether this transport is open.
|
| 116 |
+
*
|
| 117 |
+
* @return boolean true if open
|
| 118 |
+
*/
|
| 119 |
+
public function isOpen() {
|
| 120 |
+
return true;
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
/**
|
| 124 |
+
* Open the transport for reading/writing
|
| 125 |
+
*
|
| 126 |
+
* @throws TTransportException if cannot open
|
| 127 |
+
*/
|
| 128 |
+
public function open() {}
|
| 129 |
+
|
| 130 |
+
/**
|
| 131 |
+
* Close the transport.
|
| 132 |
+
*/
|
| 133 |
+
public function close() {
|
| 134 |
+
if ($this->handle_) {
|
| 135 |
+
@fclose($this->handle_);
|
| 136 |
+
$this->handle_ = null;
|
| 137 |
+
}
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
/**
|
| 141 |
+
* Read some data into the array.
|
| 142 |
+
*
|
| 143 |
+
* @param int $len How much to read
|
| 144 |
+
* @return string The data that has been read
|
| 145 |
+
* @throws TTransportException if cannot read any more data
|
| 146 |
+
*/
|
| 147 |
+
public function read($len) {
|
| 148 |
+
$data = @fread($this->handle_, $len);
|
| 149 |
+
if ($data === FALSE || $data === '') {
|
| 150 |
+
$md = stream_get_meta_data($this->handle_);
|
| 151 |
+
if ($md['timed_out']) {
|
| 152 |
+
throw new TTransportException('THttpClient: timed out reading '.$len.' bytes from '.$this->host_.':'.$this->port_.$this->uri_, TTransportException::TIMED_OUT);
|
| 153 |
+
} else {
|
| 154 |
+
throw new TTransportException('THttpClient: Could not read '.$len.' bytes from '.$this->host_.':'.$this->port_.$this->uri_, TTransportException::UNKNOWN);
|
| 155 |
+
}
|
| 156 |
+
}
|
| 157 |
+
return $data;
|
| 158 |
+
}
|
| 159 |
+
|
| 160 |
+
/**
|
| 161 |
+
* Writes some data into the pending buffer
|
| 162 |
+
*
|
| 163 |
+
* @param string $buf The data to write
|
| 164 |
+
* @throws TTransportException if writing fails
|
| 165 |
+
*/
|
| 166 |
+
public function write($buf) {
|
| 167 |
+
$this->buf_ .= $buf;
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
/**
|
| 171 |
+
* Opens and sends the actual request over the HTTP connection
|
| 172 |
+
*
|
| 173 |
+
* @throws TTransportException if a writing error occurs
|
| 174 |
+
*/
|
| 175 |
+
public function flush() {
|
| 176 |
+
// God, PHP really has some esoteric ways of doing simple things.
|
| 177 |
+
$host = $this->host_.($this->port_ != 80 ? ':'.$this->port_ : '');
|
| 178 |
+
|
| 179 |
+
$headers = array('Host: '.$host,
|
| 180 |
+
'Accept: application/x-thrift',
|
| 181 |
+
'User-Agent: PHP/THttpClient',
|
| 182 |
+
'Content-Type: application/x-thrift',
|
| 183 |
+
'Content-Length: '.TStringFuncFactory::create()->strlen($this->buf_),
|
| 184 |
+
'Authorization: Basic Z2VzY2hlbmtpZGVlOlRoYWViOG9vdG9vWA==');
|
| 185 |
+
|
| 186 |
+
$options = array('method' => 'POST',
|
| 187 |
+
'header' => implode("\r\n", $headers),
|
| 188 |
+
'max_redirects' => 1,
|
| 189 |
+
'content' => $this->buf_);
|
| 190 |
+
if ($this->timeout_ > 0) {
|
| 191 |
+
$options['timeout'] = $this->timeout_;
|
| 192 |
+
}
|
| 193 |
+
$this->buf_ = '';
|
| 194 |
+
|
| 195 |
+
$contextid = stream_context_create(array('http' => $options));
|
| 196 |
+
$this->handle_ = @fopen($this->scheme_.'://'.$host.$this->uri_, 'r', false, $contextid);
|
| 197 |
+
|
| 198 |
+
// Connect failed?
|
| 199 |
+
if ($this->handle_ === FALSE) {
|
| 200 |
+
$this->handle_ = null;
|
| 201 |
+
$error = 'THttpClient: Could not connect to '.$host.$this->uri_;
|
| 202 |
+
throw new TTransportException($error, TTransportException::NOT_OPEN);
|
| 203 |
+
}
|
| 204 |
+
}
|
| 205 |
+
|
| 206 |
+
}
|
app/code/community/Boxalino/{CemSearch/Lib/vendor → Intelligence/lib}/Thrift/Transport/TMemoryBuffer.php
RENAMED
|
@@ -1,89 +1,89 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
/*
|
| 3 |
-
* Licensed to the Apache Software Foundation (ASF) under one
|
| 4 |
-
* or more contributor license agreements. See the NOTICE file
|
| 5 |
-
* distributed with this wo
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
