Doofinder_Feed - Version 1.7.0

Version Notes

WARNING: Updated Doofinder PHP Library. This is a big update. Remember to clear Magento Cache!!!

Download this release

Release Info

Developer Carlos Escribano Rey
Extension Doofinder_Feed
Version 1.7.0
Comparing to
See all releases


Code changes from version 1.6.13 to 1.7.0

Files changed (50) hide show
  1. app/code/community/Doofinder/Feed/Block/Adminhtml/Log/View.php +1 -1
  2. app/code/community/Doofinder/Feed/Block/Adminhtml/Map/Additional.php +1 -1
  3. app/code/community/Doofinder/Feed/Block/Integration.php +1 -1
  4. app/code/community/Doofinder/Feed/Block/Settings/Buttons/Generate.php +1 -1
  5. app/code/community/Doofinder/Feed/Block/Settings/Buttons/ViewLog.php +1 -1
  6. app/code/community/Doofinder/Feed/Block/Settings/Panel/Crondescription.php +1 -1
  7. app/code/community/Doofinder/Feed/Block/Settings/Panel/Datetime.php +1 -1
  8. app/code/community/Doofinder/Feed/Block/Settings/Panel/Description.php +1 -1
  9. app/code/community/Doofinder/Feed/Block/Settings/Panel/File.php +1 -1
  10. app/code/community/Doofinder/Feed/Block/Settings/Panel/Layerdescription.php +1 -1
  11. app/code/community/Doofinder/Feed/Block/Settings/Panel/Message.php +1 -1
  12. app/code/community/Doofinder/Feed/Helper/Data.php +2 -2
  13. app/code/community/Doofinder/Feed/Helper/Log.php +2 -2
  14. app/code/community/Doofinder/Feed/Helper/Search.php +11 -13
  15. app/code/community/Doofinder/Feed/Helper/Tax.php +2 -2
  16. app/code/community/Doofinder/Feed/Model/Adminhtml/System/Config/Backend/Cron.php +1 -1
  17. app/code/community/Doofinder/Feed/Model/Config.php +2 -2
  18. app/code/community/Doofinder/Feed/Model/Cron.php +1 -1
  19. app/code/community/Doofinder/Feed/Model/Generator.php +2 -2
  20. app/code/community/Doofinder/Feed/Model/Log.php +1 -1
  21. app/code/community/Doofinder/Feed/Model/Map/Product/Abstract.php +2 -2
  22. app/code/community/Doofinder/Feed/Model/Map/Product/Associated.php +2 -2
  23. app/code/community/Doofinder/Feed/Model/Map/Product/Bundle.php +2 -2
  24. app/code/community/Doofinder/Feed/Model/Map/Product/Configurable.php +2 -2
  25. app/code/community/Doofinder/Feed/Model/Map/Product/Downloadable.php +2 -2
  26. app/code/community/Doofinder/Feed/Model/Map/Product/Grouped.php +2 -2
  27. app/code/community/Doofinder/Feed/Model/Map/Product/Simple.php +2 -2
  28. app/code/community/Doofinder/Feed/Model/Map/Product/Virtual.php +2 -2
  29. app/code/community/Doofinder/Feed/Model/Mysql4/Cron.php +1 -1
  30. app/code/community/Doofinder/Feed/Model/Mysql4/Cron/Collection.php +1 -1
  31. app/code/community/Doofinder/Feed/Model/Mysql4/Log.php +1 -1
  32. app/code/community/Doofinder/Feed/Model/Mysql4/Log/Collection.php +1 -1
  33. app/code/community/Doofinder/Feed/Model/Observers/Autoloader.php +10 -0
  34. app/code/community/Doofinder/Feed/Model/Observers/Feed.php +1 -1
  35. app/code/community/Doofinder/Feed/Model/Observers/Logs.php +1 -1
  36. app/code/community/Doofinder/Feed/Model/Observers/Schedule.php +1 -1
  37. app/code/community/Doofinder/Feed/Model/Resource/Mysql4/Setup.php +1 -1
  38. app/code/community/Doofinder/Feed/Model/System/Config/Backend/Map/Additional.php +1 -1
  39. app/code/community/Doofinder/Feed/Model/System/Config/Reset.php +1 -1
  40. app/code/community/Doofinder/Feed/Model/System/Config/Source/Product/Attributes.php +1 -1
  41. app/code/community/Doofinder/Feed/Model/Tools.php +2 -2
  42. app/code/community/Doofinder/Feed/controllers/DoofinderFeedFeedController.php +1 -1
  43. app/code/community/Doofinder/Feed/controllers/DoofinderFeedLogController.php +1 -1
  44. app/code/community/Doofinder/Feed/controllers/FeedController.php +2 -2
  45. app/code/community/Doofinder/Feed/controllers/IndexController.php +2 -2
  46. app/code/community/Doofinder/Feed/etc/config.xml +9 -1
  47. lib/Doofinder/doofinder_api.php +0 -804
  48. lib/Doofinder/doofinder_management_api.php +0 -408
  49. lib/Doofinder/errors.php +0 -48
  50. package.xml +5 -5
app/code/community/Doofinder/Feed/Block/Adminhtml/Log/View.php CHANGED
@@ -6,7 +6,7 @@
6
  /**
7
  * @category blocks
8
  * @package Doofinder_Feed
9
- * @version 1.6.13
10
  */
11
 
12
  class Doofinder_Feed_Block_Adminhtml_Log_View extends Mage_Adminhtml_Block_Widget_Grid
6
  /**
7
  * @category blocks
8
  * @package Doofinder_Feed
9
+ * @version 1.7.0
10
  */
11
 
12
  class Doofinder_Feed_Block_Adminhtml_Log_View extends Mage_Adminhtml_Block_Widget_Grid
app/code/community/Doofinder/Feed/Block/Adminhtml/Map/Additional.php CHANGED
@@ -6,7 +6,7 @@
6
  /**
7
  * @category blocks
8
  * @package Doofinder_Feed
9
- * @version 1.6.13
10
  */
11
 
12
  class Doofinder_Feed_Block_Adminhtml_Map_Additional extends Mage_Adminhtml_Block_System_Config_Form_Field
6
  /**
7
  * @category blocks
8
  * @package Doofinder_Feed
9
+ * @version 1.7.0
10
  */
11
 
12
  class Doofinder_Feed_Block_Adminhtml_Map_Additional extends Mage_Adminhtml_Block_System_Config_Form_Field
app/code/community/Doofinder/Feed/Block/Integration.php CHANGED
@@ -6,7 +6,7 @@
6
  /**
7
  * @category blocks
8
  * @package Doofinder_Feed
9
- * @version 1.6.13
10
  */
11
 
12
  class Doofinder_Feed_Block_Integration extends Mage_Core_Block_Abstract
6
  /**
7
  * @category blocks
8
  * @package Doofinder_Feed
9
+ * @version 1.7.0
10
  */
11
 
12
  class Doofinder_Feed_Block_Integration extends Mage_Core_Block_Abstract
app/code/community/Doofinder/Feed/Block/Settings/Buttons/Generate.php CHANGED
@@ -6,7 +6,7 @@
6
  /**
7
  * @category blocks
8
  * @package Doofinder_Feed
9
- * @version 1.6.13
10
  */
11
 
12
  class Doofinder_Feed_Block_Settings_Buttons_Generate extends Mage_Adminhtml_Block_System_Config_Form_Field
6
  /**
7
  * @category blocks
8
  * @package Doofinder_Feed
9
+ * @version 1.7.0
10
  */
11
 
12
  class Doofinder_Feed_Block_Settings_Buttons_Generate extends Mage_Adminhtml_Block_System_Config_Form_Field
app/code/community/Doofinder/Feed/Block/Settings/Buttons/ViewLog.php CHANGED
@@ -6,7 +6,7 @@
6
  /**
7
  * @category blocks
8
  * @package Doofinder_Feed
9
- * @version 1.6.13
10
  */
11
 
12
  class Doofinder_Feed_Block_Settings_Buttons_ViewLog extends Mage_Adminhtml_Block_System_Config_Form_Field
6
  /**
7
  * @category blocks
8
  * @package Doofinder_Feed
9
+ * @version 1.7.0
10
  */
11
 
12
  class Doofinder_Feed_Block_Settings_Buttons_ViewLog extends Mage_Adminhtml_Block_System_Config_Form_Field
app/code/community/Doofinder/Feed/Block/Settings/Panel/Crondescription.php CHANGED
@@ -6,7 +6,7 @@
6
  /**
7
  * @category blocks
8
  * @package Doofinder_Feed
9
- * @version 1.6.13
10
  */
11
 
12
  class Doofinder_Feed_Block_Settings_Panel_CronDescription extends Doofinder_Feed_Block_Settings_Panel_Description
6
  /**
7
  * @category blocks
8
  * @package Doofinder_Feed
9
+ * @version 1.7.0
10
  */
11
 
12
  class Doofinder_Feed_Block_Settings_Panel_CronDescription extends Doofinder_Feed_Block_Settings_Panel_Description
app/code/community/Doofinder/Feed/Block/Settings/Panel/Datetime.php CHANGED
@@ -6,7 +6,7 @@
6
  /**
7
  * @category blocks
8
  * @package Doofinder_Feed
9
- * @version 1.6.13
10
  */
11
 
12
  class Doofinder_Feed_Block_Settings_Panel_Datetime extends Mage_Adminhtml_Block_System_Config_Form_Field
6
  /**
7
  * @category blocks
8
  * @package Doofinder_Feed
9
+ * @version 1.7.0
10
  */
11
 
12
  class Doofinder_Feed_Block_Settings_Panel_Datetime extends Mage_Adminhtml_Block_System_Config_Form_Field
app/code/community/Doofinder/Feed/Block/Settings/Panel/Description.php CHANGED
@@ -6,7 +6,7 @@
6
  /**
7
  * @category blocks
8
  * @package Doofinder_Feed
9
- * @version 1.6.13
10
  */
11
 
12
  class Doofinder_Feed_Block_Settings_Panel_Description extends Mage_Adminhtml_Block_System_Config_Form_Field
6
  /**
7
  * @category blocks
8
  * @package Doofinder_Feed
9
+ * @version 1.7.0
10
  */
11
 
12
  class Doofinder_Feed_Block_Settings_Panel_Description extends Mage_Adminhtml_Block_System_Config_Form_Field
app/code/community/Doofinder/Feed/Block/Settings/Panel/File.php CHANGED
@@ -6,7 +6,7 @@
6
  /**
7
  * @category blocks
8
  * @package Doofinder_Feed
9
- * @version 1.6.13
10
  */
11
 
12
  class Doofinder_Feed_Block_Settings_Panel_File extends Mage_Adminhtml_Block_System_Config_Form_Field
6
  /**
7
  * @category blocks
8
  * @package Doofinder_Feed
9
+ * @version 1.7.0
10
  */
11
 
12
  class Doofinder_Feed_Block_Settings_Panel_File extends Mage_Adminhtml_Block_System_Config_Form_Field
app/code/community/Doofinder/Feed/Block/Settings/Panel/Layerdescription.php CHANGED
@@ -6,7 +6,7 @@
6
  /**
7
  * @category blocks
8
  * @package Doofinder_Feed
9
- * @version 1.6.13
10
  */
11
 
12
  class Doofinder_Feed_Block_Settings_Panel_LayerDescription extends Doofinder_Feed_Block_Settings_Panel_Description
6
  /**
7
  * @category blocks
8
  * @package Doofinder_Feed
9
+ * @version 1.7.0
10
  */
11
 
12
  class Doofinder_Feed_Block_Settings_Panel_LayerDescription extends Doofinder_Feed_Block_Settings_Panel_Description
app/code/community/Doofinder/Feed/Block/Settings/Panel/Message.php CHANGED
@@ -6,7 +6,7 @@
6
  /**
7
  * @category blocks
8
  * @package Doofinder_Feed
9
- * @version 1.6.13
10
  */
11
 
12
  class Doofinder_Feed_Block_Settings_Panel_Message extends Mage_Adminhtml_Block_System_Config_Form_Field
6
  /**
7
  * @category blocks
8
  * @package Doofinder_Feed
9
+ * @version 1.7.0
10
  */
11
 
12
  class Doofinder_Feed_Block_Settings_Panel_Message extends Mage_Adminhtml_Block_System_Config_Form_Field
app/code/community/Doofinder/Feed/Helper/Data.php CHANGED
@@ -6,13 +6,13 @@
6
  /**
7
  * @category Helpers
8
  * @package Doofinder_Feed
9
- * @version 1.6.13
10
  */
11
 
12
  /**
13
  * Data helper for Doofinder Feed
14
  *
15
- * @version 1.6.13
16
  * @package Doofinder_Feed
17
  */
18
  class Doofinder_Feed_Helper_Data extends Mage_Core_Helper_Abstract
6
  /**
7
  * @category Helpers
8
  * @package Doofinder_Feed
9
+ * @version 1.7.0
10
  */
11
 
12
  /**
13
  * Data helper for Doofinder Feed
14
  *
15
+ * @version 1.7.0
16
  * @package Doofinder_Feed
17
  */
18
  class Doofinder_Feed_Helper_Data extends Mage_Core_Helper_Abstract
app/code/community/Doofinder/Feed/Helper/Log.php CHANGED
@@ -6,13 +6,13 @@
6
  /**
7
  * @category Helpers
8
  * @package Doofinder_Feed
9
- * @version 1.6.13
10
  */
11
 
12
  /**
13
  * Log helper for Doofinder Feed
14
  *
15
- * @version 1.6.13
16
  * @package Doofinder_Feed
17
  */
18
  class Doofinder_Feed_Helper_Log extends Mage_Core_Helper_Abstract
6
  /**
7
  * @category Helpers
8
  * @package Doofinder_Feed
9
+ * @version 1.7.0
10
  */
11
 
12
  /**
13
  * Log helper for Doofinder Feed
14
  *
15
+ * @version 1.7.0
16
  * @package Doofinder_Feed
17
  */
18
  class Doofinder_Feed_Helper_Log extends Mage_Core_Helper_Abstract
app/code/community/Doofinder/Feed/Helper/Search.php CHANGED
@@ -1,5 +1,4 @@
1
  <?php
2
- require_once(Mage::getBaseDir('lib') . DS. 'Doofinder' . DS .'doofinder_api.php');
3
 
4
  class Doofinder_Feed_Helper_Search extends Mage_Core_Helper_Abstract
5
  {
@@ -23,28 +22,27 @@ class Doofinder_Feed_Helper_Search extends Mage_Core_Helper_Abstract
23
  $hashId = Mage::getStoreConfig('doofinder_search/internal_settings/hash_id', Mage::app()->getStore());
24
  $apiKey = Mage::getStoreConfig('doofinder_search/internal_settings/api_key', Mage::app()->getStore());
25
  $limit = Mage::getStoreConfig('doofinder_search/internal_settings/request_limit', Mage::app()->getStore());
26
- $ids = false;
27
 
28
- $df = new DoofinderApi($hashId, $apiKey);
29
- $dfResults = $df->query($queryText, null, array('rpp' => $limit, 'transformer' => 'onlyid', 'filter' => array()));
30
 
31
  // Store objects
32
- $this->_lastSearch = $df;
33
- $this->_lastResults = $dfResults;
34
 
35
- return $this->retrieveIds($dfResults);
36
  }
37
 
38
  /**
39
  * Retrieve ids from Doofinder Results
40
  *
41
- * @param DoofinderResults $dfResults
42
  * @return array
43
  */
44
- protected function retrieveIds(DoofinderResults $dfResults)
45
  {
46
- $ids = array();
47
- foreach($dfResults->getResults() as $result) {
48
  $ids[] = $result['id'];
49
  }
50
 
@@ -61,8 +59,8 @@ class Doofinder_Feed_Helper_Search extends Mage_Core_Helper_Abstract
61
  $limit = Mage::getStoreConfig('doofinder_search/internal_settings/total_limit', Mage::app()->getStore());
62
  $ids = $this->retrieveIds($this->_lastResults);
63
 
64
- while (count($ids) < $limit && ($dfResults = $this->_lastSearch->nextPage())) {
65
- $ids = array_merge($ids, $this->retrieveIds($dfResults));
66
  }
67
 
68
  return $ids;
1
  <?php
 
2
 
3
  class Doofinder_Feed_Helper_Search extends Mage_Core_Helper_Abstract
4
  {
22
  $hashId = Mage::getStoreConfig('doofinder_search/internal_settings/hash_id', Mage::app()->getStore());
23
  $apiKey = Mage::getStoreConfig('doofinder_search/internal_settings/api_key', Mage::app()->getStore());
24
  $limit = Mage::getStoreConfig('doofinder_search/internal_settings/request_limit', Mage::app()->getStore());
 
25
 
26
+ $client = new \Doofinder\Api\Search\Client($hashId, $apiKey);
27
+ $results = $client->query($queryText, null, ['rpp' => $limit, 'transformer' => 'onlyid', 'filter' => []]);
28
 
29
  // Store objects
30
+ $this->_lastSearch = $client;
31
+ $this->_lastResults = $results;
32
 
33
+ return $this->retrieveIds($results);
34
  }
35
 
36
  /**
37
  * Retrieve ids from Doofinder Results
38
  *
39
+ * @param \Doofinder\Api\Search\Results $results
40
  * @return array
41
  */
42
+ protected function retrieveIds(DoofinderResults $results)
43
  {
44
+ $ids = [];
45
+ foreach ($results->getResults() as $result) {
46
  $ids[] = $result['id'];
47
  }
48
 
59
  $limit = Mage::getStoreConfig('doofinder_search/internal_settings/total_limit', Mage::app()->getStore());
60
  $ids = $this->retrieveIds($this->_lastResults);
61
 
62
+ while (count($ids) < $limit && ($results = $this->_lastSearch->nextPage())) {
63
+ $ids = array_merge($ids, $this->retrieveIds($results));
64
  }
65
 
66
  return $ids;
app/code/community/Doofinder/Feed/Helper/Tax.php CHANGED
@@ -6,13 +6,13 @@
6
  /**
7
  * @category Helpers
8
  * @package Doofinder_Feed
9
- * @version 1.6.13
10
  */
11
 
12
  /**
13
  * Tax helper for Doofinder Feed
14
  *
15
- * @version 1.6.13
16
  * @package Doofinder_Feed
17
  */
18
  class Doofinder_Feed_Helper_Tax extends Mage_Tax_Helper_Data
6
  /**
7
  * @category Helpers
8
  * @package Doofinder_Feed
9
+ * @version 1.7.0
10
  */
11
 
12
  /**
13
  * Tax helper for Doofinder Feed
14
  *
15
+ * @version 1.7.0
16
  * @package Doofinder_Feed
17
  */
18
  class Doofinder_Feed_Helper_Tax extends Mage_Tax_Helper_Data
app/code/community/Doofinder/Feed/Model/Adminhtml/System/Config/Backend/Cron.php CHANGED
@@ -6,7 +6,7 @@
6
  /**
7
  * @category Models
8
  * @package Doofinder_Feed
9
- * @version 1.6.13
10
  */
11
 
12
  class Doofinder_Feed_Model_Adminhtml_System_Config_Backend_Cron extends Mage_Core_Model_Config_Data {
6
  /**
7
  * @category Models
8
  * @package Doofinder_Feed
9
+ * @version 1.7.0
10
  */
11
 
12
  class Doofinder_Feed_Model_Adminhtml_System_Config_Backend_Cron extends Mage_Core_Model_Config_Data {
app/code/community/Doofinder/Feed/Model/Config.php CHANGED
@@ -6,13 +6,13 @@
6
  /**
7
  * @category Models
8
  * @package Doofinder_Feed
9
- * @version 1.6.13
10
  */
11
 
12
  /**
13
  * Config model for Doofinder Feed
14
  *
15
- * @version 1.6.13
16
  * @package Doofinder_Feed
17
  */
18
  class Doofinder_Feed_Model_Config extends Mage_Core_Model_Config_Data
6
  /**
7
  * @category Models
8
  * @package Doofinder_Feed
9
+ * @version 1.7.0
10
  */
11
 
12
  /**
13
  * Config model for Doofinder Feed
14
  *
15
+ * @version 1.7.0
16
  * @package Doofinder_Feed
17
  */
18
  class Doofinder_Feed_Model_Config extends Mage_Core_Model_Config_Data
app/code/community/Doofinder/Feed/Model/Cron.php CHANGED
@@ -6,7 +6,7 @@
6
  /**
7
  * @category Models
8
  * @package Doofinder_Feed
9
- * @version 1.6.13
10
  */
11
 
12
  class Doofinder_Feed_Model_Cron extends Mage_Core_Model_Abstract {
6
  /**
7
  * @category Models
8
  * @package Doofinder_Feed
9
+ * @version 1.7.0
10
  */
11
 
12
  class Doofinder_Feed_Model_Cron extends Mage_Core_Model_Abstract {
app/code/community/Doofinder/Feed/Model/Generator.php CHANGED
@@ -6,13 +6,13 @@
6
  /**
7
  * @category Models
8
  * @package Doofinder_Feed
9
- * @version 1.6.13
10
  */
11
 
12
  /**
13
  * Generator model for Doofinder Feed
14
  *
15
- * @version 1.6.13
16
  * @package Doofinder_Feed
17
  */
18
  if (!defined('DS'))
6
  /**
7
  * @category Models
8
  * @package Doofinder_Feed
9
+ * @version 1.7.0
10
  */
11
 
12
  /**
13
  * Generator model for Doofinder Feed
14
  *
15
+ * @version 1.7.0
16
  * @package Doofinder_Feed
17
  */
18
  if (!defined('DS'))
app/code/community/Doofinder/Feed/Model/Log.php CHANGED
@@ -6,7 +6,7 @@
6
  /**
7
  * @category Models
8
  * @package Doofinder_Feed
9
- * @version 1.6.13
10
  */
11
 
12
  class Doofinder_Feed_Model_Log extends Mage_Core_Model_Abstract {
6
  /**
7
  * @category Models
8
  * @package Doofinder_Feed
9
+ * @version 1.7.0
10
  */
11
 
12
  class Doofinder_Feed_Model_Log extends Mage_Core_Model_Abstract {
app/code/community/Doofinder/Feed/Model/Map/Product/Abstract.php CHANGED
@@ -6,13 +6,13 @@
6
  /**
7
  * @category Models
8
  * @package Doofinder_Feed
9
- * @version 1.6.13
10
  */
11
 
12
  /**
13
  * Abstract Product Map Model for Doofinder Feed
14
  *
15
- * @version 1.6.13
16
  * @package Doofinder_Feed
17
  */
18
  class Doofinder_Feed_Model_Map_Product_Abstract extends Varien_Object
6
  /**
7
  * @category Models
8
  * @package Doofinder_Feed
9
+ * @version 1.7.0
10
  */
11
 
12
  /**
13
  * Abstract Product Map Model for Doofinder Feed
14
  *
15
+ * @version 1.7.0
16
  * @package Doofinder_Feed
17
  */
18
  class Doofinder_Feed_Model_Map_Product_Abstract extends Varien_Object
app/code/community/Doofinder/Feed/Model/Map/Product/Associated.php CHANGED
@@ -6,13 +6,13 @@
6
  /**
7
  * @category Models
8
  * @package Doofinder_Feed
9
- * @version 1.6.13
10
  */
11
 
12
  /**
13
  * Associated Product Map Model for Doofinder Feed
14
  *
15
- * @version 1.6.13
16
  * @package Doofinder_Feed
17
  */
18
  class Doofinder_Feed_Model_Map_Product_Associated
6
  /**
7
  * @category Models
8
  * @package Doofinder_Feed
9
+ * @version 1.7.0
10
  */
11
 
12
  /**
13
  * Associated Product Map Model for Doofinder Feed
14
  *
15
+ * @version 1.7.0
16
  * @package Doofinder_Feed
17
  */
18
  class Doofinder_Feed_Model_Map_Product_Associated
app/code/community/Doofinder/Feed/Model/Map/Product/Bundle.php CHANGED
@@ -6,13 +6,13 @@
6
  /**
7
  * @category Models
8
  * @package Doofinder_Feed
9
- * @version 1.6.13
10
  */
11
 
12
  /**
13
  * Bundle Product Map Model for Doofinder Feed
14
  *
15
- * @version 1.6.13
16
  * @package Doofinder_Feed
17
  */
18
  class Doofinder_Feed_Model_Map_Product_Bundle
6
  /**
7
  * @category Models
8
  * @package Doofinder_Feed
9
+ * @version 1.7.0
10
  */
11
 
12
  /**
13
  * Bundle Product Map Model for Doofinder Feed
14
  *
15
+ * @version 1.7.0
16
  * @package Doofinder_Feed
17
  */
18
  class Doofinder_Feed_Model_Map_Product_Bundle
app/code/community/Doofinder/Feed/Model/Map/Product/Configurable.php CHANGED
@@ -6,13 +6,13 @@
6
  /**
7
  * @category Models
8
  * @package Doofinder_Feed
9
- * @version 1.6.13
10
  */
11
 
12
  /**
13
  * Configurable Product Map Model for Doofinder Feed
14
  *
15
- * @version 1.6.13
16
  * @package Doofinder_Feed
17
  */
18
  class Doofinder_Feed_Model_Map_Product_Configurable
6
  /**
7
  * @category Models
8
  * @package Doofinder_Feed
9
+ * @version 1.7.0
10
  */
11
 
12
  /**
13
  * Configurable Product Map Model for Doofinder Feed
14
  *
15
+ * @version 1.7.0
16
  * @package Doofinder_Feed
17
  */
18
  class Doofinder_Feed_Model_Map_Product_Configurable
app/code/community/Doofinder/Feed/Model/Map/Product/Downloadable.php CHANGED
@@ -6,13 +6,13 @@
6
  /**
7
  * @category Models
8
  * @package Doofinder_Feed
9
- * @version 1.6.13
10
  */
11
 
12
  /**
13
  * Downloadable Product Map Model for Doofinder Feed
14
  *
15
- * @version 1.6.13
16
  * @package Doofinder_Feed
17
  */
18
  class Doofinder_Feed_Model_Map_Product_Downloadable
6
  /**
7
  * @category Models
8
  * @package Doofinder_Feed
9
+ * @version 1.7.0
10
  */
11
 
12
  /**
13
  * Downloadable Product Map Model for Doofinder Feed
14
  *
15
+ * @version 1.7.0
16
  * @package Doofinder_Feed
17
  */
18
  class Doofinder_Feed_Model_Map_Product_Downloadable
app/code/community/Doofinder/Feed/Model/Map/Product/Grouped.php CHANGED
@@ -6,13 +6,13 @@
6
  /**
7
  * @category Models
8
  * @package Doofinder_Feed
9
- * @version 1.6.13
10
  */
11
 
12
  /**
13
  * Grouped Product Map Model for Doofinder Feed
14
  *
15
- * @version 1.6.13
16
  * @package Doofinder_Feed
17
  */
18
  class Doofinder_Feed_Model_Map_Product_Grouped
6
  /**
7
  * @category Models
8
  * @package Doofinder_Feed
9
+ * @version 1.7.0
10
  */
11
 
12
  /**
13
  * Grouped Product Map Model for Doofinder Feed
14
  *
15
+ * @version 1.7.0
16
  * @package Doofinder_Feed
17
  */
18
  class Doofinder_Feed_Model_Map_Product_Grouped
app/code/community/Doofinder/Feed/Model/Map/Product/Simple.php CHANGED
@@ -6,13 +6,13 @@
6
  /**
7
  * @category Models
8
  * @package Doofinder_Feed
9
- * @version 1.6.13
10
  */
11
 
12
  /**
13
  * Simple Product Map Model for Doofinder Feed
14
  *
15
- * @version 1.6.13
16
  * @package Doofinder_Feed
17
  */
18
  class Doofinder_Feed_Model_Map_Product_Simple
6
  /**
7
  * @category Models
8
  * @package Doofinder_Feed
9
+ * @version 1.7.0
10
  */
11
 
12
  /**
13
  * Simple Product Map Model for Doofinder Feed
14
  *
15
+ * @version 1.7.0
16
  * @package Doofinder_Feed
17
  */
18
  class Doofinder_Feed_Model_Map_Product_Simple
app/code/community/Doofinder/Feed/Model/Map/Product/Virtual.php CHANGED
@@ -6,13 +6,13 @@
6
  /**
7
  * @category Models
8
  * @package Doofinder_Feed
9
- * @version 1.6.13
10
  */
11
 
12
  /**
13
  * Virtual Product Map Model for Doofinder Feed
14
  *
15
- * @version 1.6.13
16
  * @package Doofinder_Feed
17
  */
18
  class Doofinder_Feed_Model_Map_Product_Virtual
6
  /**
7
  * @category Models
8
  * @package Doofinder_Feed
9
+ * @version 1.7.0
10
  */
11
 
12
  /**
13
  * Virtual Product Map Model for Doofinder Feed
14
  *
15
+ * @version 1.7.0
16
  * @package Doofinder_Feed
17
  */
18
  class Doofinder_Feed_Model_Map_Product_Virtual
app/code/community/Doofinder/Feed/Model/Mysql4/Cron.php CHANGED
@@ -6,7 +6,7 @@
6
  /**
7
  * @category Models
8
  * @package Doofinder_Feed
9
- * @version 1.6.13
10
  */
11
 
12
  class Doofinder_Feed_Model_Mysql4_Cron extends Mage_Core_Model_Mysql4_Abstract {
6
  /**
7
  * @category Models
8
  * @package Doofinder_Feed
9
+ * @version 1.7.0
10
  */
11
 
12
  class Doofinder_Feed_Model_Mysql4_Cron extends Mage_Core_Model_Mysql4_Abstract {
app/code/community/Doofinder/Feed/Model/Mysql4/Cron/Collection.php CHANGED
@@ -6,7 +6,7 @@
6
  /**
7
  * @category Models
8
  * @package Doofinder_Feed
9
- * @version 1.6.13
10
  */
11
 
12
  class Doofinder_Feed_Model_Mysql4_Cron_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract {
6
  /**
7
  * @category Models
8
  * @package Doofinder_Feed
9
+ * @version 1.7.0
10
  */
11
 
12
  class Doofinder_Feed_Model_Mysql4_Cron_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract {
app/code/community/Doofinder/Feed/Model/Mysql4/Log.php CHANGED
@@ -6,7 +6,7 @@
6
  /**
7
  * @category Models
8
  * @package Doofinder_Feed
9
- * @version 1.6.13
10
  */
11
 
12
  class Doofinder_Feed_Model_Mysql4_Log extends Mage_Core_Model_Mysql4_Abstract {
6
  /**
7
  * @category Models
8
  * @package Doofinder_Feed
9
+ * @version 1.7.0
10
  */
11
 
12
  class Doofinder_Feed_Model_Mysql4_Log extends Mage_Core_Model_Mysql4_Abstract {
app/code/community/Doofinder/Feed/Model/Mysql4/Log/Collection.php CHANGED
@@ -6,7 +6,7 @@
6
  /**
7
  * @category Models
8
  * @package Doofinder_Feed
9
- * @version 1.6.13
10
  */
11
 
12
  class Doofinder_Feed_Model_Mysql4_Log_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
6
  /**
7
  * @category Models
8
  * @package Doofinder_Feed
9
+ * @version 1.7.0
10
  */
11
 
12
  class Doofinder_Feed_Model_Mysql4_Log_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
app/code/community/Doofinder/Feed/Model/Observers/Autoloader.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Doofinder_Feed_Model_Observers_Autoloader
4
+ {
5
+ public function addAutoloader()
6
+ {
7
+ require_once(Mage::getBaseDir('lib') . DS. 'php-doofinder' . DS .'autoload.php');
8
+ return $this;
9
+ }
10
+ }
app/code/community/Doofinder/Feed/Model/Observers/Feed.php CHANGED
@@ -6,7 +6,7 @@
6
  /**
7
  * @category Models
8
  * @package Doofinder_Feed
9
- * @version 1.6.13
10
  */
11
 
12
  require_once(Mage::getBaseDir('lib') . DS. 'Doofinder' . DS .'doofinder_management_api.php');
6
  /**
7
  * @category Models
8
  * @package Doofinder_Feed
9
+ * @version 1.7.0
10
  */
11
 
12
  require_once(Mage::getBaseDir('lib') . DS. 'Doofinder' . DS .'doofinder_management_api.php');
app/code/community/Doofinder/Feed/Model/Observers/Logs.php CHANGED
@@ -6,7 +6,7 @@
6
  /**
7
  * @category Models
8
  * @package Doofinder_Feed
9
- * @version 1.6.13
10
  */
11
 
12
  class Doofinder_Feed_Model_Observers_Logs
6
  /**
7
  * @category Models
8
  * @package Doofinder_Feed
9
+ * @version 1.7.0
10
  */
11
 
12
  class Doofinder_Feed_Model_Observers_Logs
app/code/community/Doofinder/Feed/Model/Observers/Schedule.php CHANGED
@@ -6,7 +6,7 @@
6
  /**
7
  * @category Models
8
  * @package Doofinder_Feed
9
- * @version 1.6.13
10
  */
11
 
12
  class Doofinder_Feed_Model_Observers_Schedule
6
  /**
7
  * @category Models
8
  * @package Doofinder_Feed
9
+ * @version 1.7.0
10
  */
11
 
12
  class Doofinder_Feed_Model_Observers_Schedule
app/code/community/Doofinder/Feed/Model/Resource/Mysql4/Setup.php CHANGED
@@ -6,7 +6,7 @@
6
  /**
7
  * @category Models
8
  * @package Doofinder_Feed
9
- * @version 1.6.13
10
  */
11
 
12
  class Doofinder_Feed_Model_Resource_Mysql4_Setup extends Mage_Core_Model_Resource_Setup {
6
  /**
7
  * @category Models
8
  * @package Doofinder_Feed
9
+ * @version 1.7.0
10
  */
11
 
12
  class Doofinder_Feed_Model_Resource_Mysql4_Setup extends Mage_Core_Model_Resource_Setup {
app/code/community/Doofinder/Feed/Model/System/Config/Backend/Map/Additional.php CHANGED
@@ -6,7 +6,7 @@
6
  /**
7
  * @category Models
8
  * @package Doofinder_Feed
9
- * @version 1.6.13
10
  */
11
 
12
  class Doofinder_Feed_Model_System_Config_Backend_Map_Additional extends Mage_Adminhtml_Model_System_Config_Backend_Serialized
6
  /**
7
  * @category Models
8
  * @package Doofinder_Feed
9
+ * @version 1.7.0
10
  */
11
 
12
  class Doofinder_Feed_Model_System_Config_Backend_Map_Additional extends Mage_Adminhtml_Model_System_Config_Backend_Serialized
app/code/community/Doofinder/Feed/Model/System/Config/Reset.php CHANGED
@@ -6,7 +6,7 @@
6
  /**
7
  * @category Models
8
  * @package Doofinder_Feed
9
- * @version 1.6.13
10
  */
11
 
12
  class Doofinder_Feed_Model_System_Config_Reset extends Mage_Core_Model_Config_Data
6
  /**
7
  * @category Models
8
  * @package Doofinder_Feed
9
+ * @version 1.7.0
10
  */
11
 
12
  class Doofinder_Feed_Model_System_Config_Reset extends Mage_Core_Model_Config_Data
app/code/community/Doofinder/Feed/Model/System/Config/Source/Product/Attributes.php CHANGED
@@ -6,7 +6,7 @@
6
  /**
7
  * @category Models
8
  * @package Doofinder_Feed
9
- * @version 1.6.13
10
  */
11
 
12
  class Doofinder_Feed_Model_System_Config_Source_Product_Attributes
6
  /**
7
  * @category Models
8
  * @package Doofinder_Feed
9
+ * @version 1.7.0
10
  */
11
 
12
  class Doofinder_Feed_Model_System_Config_Source_Product_Attributes
app/code/community/Doofinder/Feed/Model/Tools.php CHANGED
@@ -6,13 +6,13 @@
6
  /**
7
  * @category Models
8
  * @package Doofinder_Feed
9
- * @version 1.6.13
10
  */
11
 
12
  /**
13
  * Tools model for Doofinder Feed
14
  *
15
- * @version 1.6.13
16
  * @package Doofinder_Feed
17
  */
18
  class Doofinder_Feed_Model_Tools extends Varien_Object
6
  /**
7
  * @category Models
8
  * @package Doofinder_Feed
9
+ * @version 1.7.0
10
  */
11
 
12
  /**
13
  * Tools model for Doofinder Feed
14
  *
15
+ * @version 1.7.0
16
  * @package Doofinder_Feed
17
  */
18
  class Doofinder_Feed_Model_Tools extends Varien_Object
app/code/community/Doofinder/Feed/controllers/DoofinderFeedFeedController.php CHANGED
@@ -6,7 +6,7 @@
6
  /**
7
  * @category controllers
8
  * @package Doofinder_Feed
9
- * @version 1.6.13
10
  */
11
 
12
  class Doofinder_Feed_DoofinderFeedFeedController extends Mage_Adminhtml_Controller_Action
6
  /**
7
  * @category controllers
8
  * @package Doofinder_Feed
9
+ * @version 1.7.0
10
  */
11
 
12
  class Doofinder_Feed_DoofinderFeedFeedController extends Mage_Adminhtml_Controller_Action
app/code/community/Doofinder/Feed/controllers/DoofinderFeedLogController.php CHANGED
@@ -6,7 +6,7 @@
6
  /**
7
  * @category controllers
8
  * @package Doofinder_Feed
9
- * @version 1.6.13
10
  */
11
 
12
  class Doofinder_Feed_DoofinderFeedLogController extends Mage_Adminhtml_Controller_Action
6
  /**
7
  * @category controllers
8
  * @package Doofinder_Feed
9
+ * @version 1.7.0
10
  */
11
 
12
  class Doofinder_Feed_DoofinderFeedLogController extends Mage_Adminhtml_Controller_Action
app/code/community/Doofinder/Feed/controllers/FeedController.php CHANGED
@@ -6,13 +6,13 @@
6
  /**
7
  * @category controllers
8
  * @package Doofinder_Feed
9
- * @version 1.6.13
10
  */
11
 
12
  /**
13
  * Feed controller for Doofinder Feed
14
  *
15
- * @version 1.6.13
16
  * @package Doofinder_Feed
17
  */
18
  class Doofinder_Feed_FeedController extends Mage_Core_Controller_Front_Action
6
  /**
7
  * @category controllers
8
  * @package Doofinder_Feed
9
+ * @version 1.7.0
10
  */
11
 
12
  /**
13
  * Feed controller for Doofinder Feed
14
  *
15
+ * @version 1.7.0
16
  * @package Doofinder_Feed
17
  */
18
  class Doofinder_Feed_FeedController extends Mage_Core_Controller_Front_Action
app/code/community/Doofinder/Feed/controllers/IndexController.php CHANGED
@@ -6,13 +6,13 @@
6
  /**
7
  * @category controllers
8
  * @package Doofinder_Feed
9
- * @version 1.6.13
10
  */
11
 
12
  /**
13
  * Index controller for Doofinder Feed
14
  *
15
- * @version 1.6.13
16
  * @package Doofinder_Feed
17
  */
18
  class Doofinder_Feed_IndexController extends Mage_Core_Controller_Front_Action
6
  /**
7
  * @category controllers
8
  * @package Doofinder_Feed
9
+ * @version 1.7.0
10
  */
11
 
12
  /**
13
  * Index controller for Doofinder Feed
14
  *
15
+ * @version 1.7.0
16
  * @package Doofinder_Feed
17
  */
18
  class Doofinder_Feed_IndexController extends Mage_Core_Controller_Front_Action
app/code/community/Doofinder/Feed/etc/config.xml CHANGED
@@ -3,7 +3,7 @@
3
 
4
  <modules>
5
  <Doofinder_Feed>
6
- <version>1.6.13</version>
7
  </Doofinder_Feed>
8
  </modules>
9
  <global>
@@ -78,6 +78,14 @@
78
  </doofinder_feed>
79
  </observers>
80
  </catalog_product_save_after>
 
 
 
 
 
 
 
 
81
  </events>
82
  </global>
83
 
3
 
4
  <modules>
5
  <Doofinder_Feed>
6
+ <version>1.7.0</version>
7
  </Doofinder_Feed>
8
  </modules>
9
  <global>
78
  </doofinder_feed>
79
  </observers>
80
  </catalog_product_save_after>
81
+ <resource_get_tablename>
82
+ <observers>
83
+ <doofinder_feed>
84
+ <class>doofinder_feed/observers_autoloader</class>
85
+ <method>addAutoloader</method>
86
+ </doofinder_feed>
87
+ </observers>
88
+ </resource_get_tablename>
89
  </events>
90
  </global>
91
 
lib/Doofinder/doofinder_api.php DELETED
@@ -1,804 +0,0 @@
1
- <?php
2
- /**
3
- * Author:: JoeZ99 (<jzarate@gmail.com>). all credit to Gilles Devaux (<gilles.devaux@gmail.com>) (https://github.com/flaptor/indextank-php)
4
- *
5
- * License:: Apache License, Version 2.0
6
- *
7
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
8
- * not use this file except in compliance with the License. You may obtain
9
- * 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, software
14
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16
- * License for the specific language governing permissions and limitations
17
- * under the License.
18
- */
19
-
20
-
21
- class DoofinderApi{
22
- /*
23
- * Basic client for an account.
24
- * It needs an API url to be constructed.
25
- * Its only method is to query the doofinder search server
26
- * Returns a DoofinderResults object
27
- */
28
-
29
- const URL_SUFFIX = '-search.doofinder.com';
30
- const DEFAULT_TIMEOUT = 10000;
31
- const DEFAULT_RPP = 10;
32
- const DEFAULT_PARAMS_PREFIX = 'dfParam_';
33
- const DEFAULT_API_VERSION = '4';
34
- const VERSION = '5.2.5';
35
-
36
- private $api_key = null; // user API_KEY
37
- private $hashid = null; // hashid of the doofinder account
38
-
39
- private $apiVersion = null;
40
- private $url = null;
41
- private $results = null;
42
- private $query = null;
43
- private $search_options = array(); // assoc. array with doofinder options to be sent as request parameters
44
-
45
- private $page = 1; // the page of the search results we're at
46
- private $queryName = null; // the name of the last successfull query made
47
- private $lastQuery = null; // the last successfull query made
48
- private $total = null; // total number of results obtained
49
- private $maxScore = null;
50
- private $paramsPrefix = self::DEFAULT_PARAMS_PREFIX;
51
- private $serializationArray = null;
52
- private $queryParameter = 'query'; // the parameter used for querying
53
- private $allowedParameters = array('page', 'rpp', 'timeout', 'types', 'filter', 'query_name', 'transformer'); // request parameters that doofinder handle
54
-
55
- /**
56
- * Constructor. account's hashid and api version set here
57
- *
58
- * @param string $hashid the account's hashid
59
- * @param boolean $fromParams if set, the object is unserialized from GET or POST params
60
- * @param array $init_options. associative array with some options:
61
- * -'prefix' (default: 'dfParam_')=> the prefix to use when serializing.
62
- * -'queryParameter' (default: 'query') => the parameter used for querying
63
- * -'apiVersion' (default: '4')=> the api of the search server to query
64
- * -'restrictedRequest'(default: $_REQUEST): =>restrict request object
65
- * to look for params when unserializing. either 'get' or 'post'
66
- * @throws DoofinderException if $hashid is not a md5 hash or api is no 4, 3.0 or 1.0
67
- */
68
- function __construct($hashid, $api_key, $fromParams=false, $init_options = array()){
69
- $zone_key_array = explode('-', $api_key);
70
-
71
- if(2 === count($zone_key_array)){
72
- $this->api_key = $zone_key_array[1];
73
- $this->zone = $zone_key_array[0];
74
- $this->url = "https://" . $this->zone . self::URL_SUFFIX;
75
- } else {
76
- throw new DoofinderException("API Key is no properly set.");
77
- }
78
-
79
- if(array_key_exists('prefix', $init_options)){
80
- $this->paramsPrefix = $init_options['prefix'];
81
- }
82
-
83
-
84
- $this->allowedParameters = array_map(array($this, 'addprefix'), $this->allowedParameters);
85
-
86
-
87
- if(array_key_exists('queryParameter', $init_options)){
88
- $this->queryParameter = $init_options['queryParameter'];
89
- } else {
90
- $this->queryParameter = $this->paramsPrefix.$this->queryParameter;
91
- }
92
-
93
-
94
- $this->apiVersion = array_key_exists('apiVersion', $init_options) ?
95
- $init_options['apiVersion'] : self::DEFAULT_API_VERSION;
96
- $this->serializationArray = $_REQUEST;
97
- if(array_key_exists('restrictedRequest', $init_options))
98
- {
99
- switch(strtolower($init_options['restrictedRequest'])){
100
- case 'get':
101
- $this->serializationArray = $_GET;
102
- break;
103
- case 'post':
104
- $this->serializationArray = $_POST;
105
- break;
106
- }
107
- }
108
- $patt = '/^[0-9a-f]{32}$/i';
109
- if(!preg_match($patt, $hashid))
110
- {
111
- throw new DoofinderException("Wrong hashid");
112
- }
113
- if(!in_array($this->apiVersion, array('5', '4', '3.0','1.0')))
114
- {
115
- throw new DoofinderException('Wrong API');
116
- }
117
- $this->hashid = $hashid;
118
- if($fromParams)
119
- {
120
- $this->fromQuerystring();
121
- }
122
-
123
- }
124
-
125
- private function addprefix($value){
126
- return $this->paramsPrefix.$value;
127
- }
128
-
129
- /*
130
- * translateFilter
131
- *
132
- * translates a range filter to the new ES format
133
- * 'from'=>9, 'to'=>20 to 'gte'=>9, 'lte'=>20
134
- *
135
- * @param array $filter
136
- * @return array the translated filter
137
- */
138
- private function translateFilter($filter){
139
- $new_filter = array();
140
- foreach($filter as $key => $value){
141
- if ($key === 'from') {
142
- $new_filter['gte'] = $value;
143
- } else if ($key === 'to') {
144
- $new_filter['lte'] = $value;
145
- } else {
146
- $new_filter[$key] = $value;
147
- }
148
- }
149
- return $new_filter;
150
- }
151
-
152
- private function reqHeaders(){
153
- $headers = array();
154
- $headers[] = 'Expect:'; //Fixes the HTTP/1.1 417 Expectation Failed
155
- $authHeaderName = $this->apiVersion == '4' ? 'API Token: ' : 'authorization: ';
156
- $headers[] = $authHeaderName . $this->api_key; //API Authorization
157
- return $headers;
158
- }
159
-
160
- private function apiCall($entry_point='search', $params=array()){
161
- $params['hashid'] = $this->hashid;
162
- $args = http_build_query($this->sanitize($params)); // remove any null value from the array
163
-
164
- $url = $this->url.'/'.$this->apiVersion.'/'.$entry_point.'?'.$args;
165
-
166
- $session = curl_init($url);
167
- curl_setopt($session, CURLOPT_CUSTOMREQUEST, 'GET');
168
- curl_setopt($session, CURLOPT_HEADER, false); // Tell curl not to return headers
169
- curl_setopt($session, CURLOPT_RETURNTRANSFER, true); // Tell curl to return the response
170
- curl_setopt($session, CURLOPT_HTTPHEADER, $this->reqHeaders()); // Adding request headers
171
- $response = curl_exec($session);
172
- $httpCode = curl_getinfo($session, CURLINFO_HTTP_CODE);
173
- curl_close($session);
174
-
175
- if (floor($httpCode / 100) == 2) {
176
- return $response;
177
- }
178
- throw new DoofinderException($httpCode.' - '.$response, $httpCode);
179
- }
180
-
181
- public function getOptions(){
182
- return $this->apiCall('options/'.$this->hashid);
183
- }
184
-
185
- /**
186
- * query. makes the query to the doofinder search server.
187
- * also set several search parameters through it's $options argument
188
- *
189
- * @param string $query the search query
190
- * @param int $page the page number or the results to show
191
- * @param array $options query options:
192
- * - 'rpp'=> number of results per page. default 10
193
- * - 'timeout' => timeout after which the search server drops the conn.
194
- * defaults to 10 seconds
195
- * - 'types' => types of index to search at. default: all.
196
- * - 'filter' => filter to apply. ['color'=>['red','blue'], 'price'=>['from'=>33]]
197
- * - any other param will be sent as a request parameter
198
- * @return DoofinderResults results
199
- */
200
- public function query($query=null, $page=null, $options = array()){
201
- if($query){
202
- $this->search_options['query'] = $query;
203
- }
204
- if($page){
205
- $this->search_options['page'] = (int)$page;
206
- }
207
- foreach($options as $optionName => $optionValue){
208
- $this->search_options[$optionName] = $options[$optionName];
209
- }
210
-
211
- $params = $this->search_options;
212
-
213
- // translate filters
214
- if(!empty($params['filter']))
215
- {
216
- foreach($params['filter'] as $filterName => $filterValue){
217
- $params['filter'][$filterName] = $this->translateFilter($filterValue);
218
- }
219
- }
220
-
221
- // no query? then match all documents
222
- if(!$this->optionExists('query') || !trim($this->search_options['query'])){
223
- $params['query_name'] = 'match_all';
224
- }
225
-
226
- // if filters without query_name, pre-query first to obtain it.
227
- if (empty($params['query_name']) && !empty($params['filter']))
228
- {
229
- $filter = $params['filter'];
230
- unset($params['filter']);
231
- $dfResults = new DoofinderResults($this->apiCall('search', $params));
232
- $params['query_name'] = $dfResults->getProperty('query_name');
233
- $params['filter'] = $filter;
234
- }
235
- $dfResults = new DoofinderResults($this->apiCall('search', $params));
236
- $this->page = $dfResults->getProperty('page');
237
- $this->total = $dfResults->getProperty('total');
238
- $this->search_options['query'] = $dfResults->getProperty('query');
239
- $this->maxScore = $dfResults->getProperty('max_score');
240
- $this->queryName = $dfResults->getProperty('query_name');
241
- $this->lastQuery = $dfResults->getProperty('query');
242
-
243
- return $dfResults;
244
- }
245
-
246
- /**
247
- * hasNext
248
- *
249
- * @return boolean true if there is another page of results
250
- */
251
- public function hasNext(){
252
- return $this->page*$this->getRpp() < $this->total;
253
- }
254
-
255
- /**
256
- * hasPrev
257
- *
258
- * @return true if there is a previous page of results
259
- */
260
- public function hasPrev(){
261
- return ($this->page-1)*$this->getRpp() > 0;
262
- }
263
-
264
-
265
- /**
266
- * getPage
267
- *
268
- * obtain the current page number
269
- * @return int the page number
270
- */
271
- public function getPage(){
272
- return $this->page;
273
- }
274
-
275
- /**
276
- * setFilter
277
- *
278
- * set a filter for the query
279
- * @param string filterName the name of the filter to set
280
- * @param array filter if simple array, terms filter assumed
281
- * if 'from', 'to' in keys, range filter assumed
282
- */
283
- public function setFilter($filterName, $filter){
284
- if(!$this->optionExists('filter')){
285
- $this->search_options['filter'] = array();
286
- }
287
- $this->search_options['filter'][$filterName] = $filter;
288
- }
289
-
290
- /**
291
- * getFilter
292
- *
293
- * get conditions for certain filter
294
- * @param string filterName
295
- * @return array filter conditions: - simple array if terms filter
296
- * - 'from', 'to' assoc array if range f.
297
- * @return false if no filter definition found
298
- */
299
- public function getFilter($filterName){
300
- if($this->optionExists('filter') && isset($this->search_options['filter'][$filterName])){
301
- return $this->filter[$filterName];
302
- }
303
- return false;
304
- }
305
-
306
- /**
307
- * getFilters
308
- *
309
- * get all filters and their configs
310
- * @return array assoc array filterName => filterConditions
311
- */
312
- public function getFilters(){
313
- return $this->search_options['filter'];
314
- }
315
-
316
-
317
- /**
318
- * addTerm
319
- *
320
- * add a term to a terms filter
321
- * @param string filterName the filter to add the term to
322
- * @param string term the term to add
323
- */
324
- public function addTerm($filterName, $term){
325
- if(!$this->optionExists('filter')){
326
- $this->search_options['filter'] = array($filterName => array());
327
- }
328
- if(!isset($this->search_options['filter'][$filterName]))
329
- {
330
- $this->filter[$filterName] = array();
331
- $this->search_options['filter'][$filterName] = array();
332
- }
333
- $this->filter[$filterName][] = $term;
334
- $this->search_options['filter'][$filterName][] = $term;
335
- }
336
-
337
- /**
338
- * removeTerm
339
- *
340
- * remove a term from a terms filter
341
- * @param string filterName the filter to remove the term from
342
- * @param string term the term to be removed
343
- */
344
- public function removeTerm($filterName, $term){
345
- if($this->optionExists('filter') && isset($this->search_options['filter'][$filterName]) &&
346
- in_array($term, $this->search_options['filter'][$filterName]))
347
- {
348
- function filter_me($value){
349
- global $term;
350
- return $value != $term;
351
- }
352
- $this->search_options['filter'][$filterName] =
353
- array_filter($this->search_options['filter'][$filterName], 'filter_me');
354
- }
355
- }
356
-
357
- /**
358
- * setRange
359
- *
360
- * set a range filter
361
- * @param string filterName the filter to set
362
- * @param int from the lower bound value. included
363
- * @param int to the upper bound value. included
364
- */
365
- public function setRange($filterName, $from=null, $to=null){
366
- if(!$this->optionExists('filter')){
367
- $this->search_options['filter'] = array($filterName=>array());
368
- }
369
- if(!isset($this->search_options['filter'][$filterName]))
370
- {
371
- $this->search_options['filter'][$filterName] = array();
372
- }
373
- if($from)
374
- {
375
- $this->search_options['filter'][$filterName]['from'] = $from;
376
- }
377
- if($to)
378
- {
379
- $this->search_options['filter'][$filterName]['to'] = $from;
380
- }
381
- }
382
-
383
- /**
384
- * toQuerystring
385
- *
386
- * 'serialize' the object's state to querystring params
387
- * @param int $page the pagenumber. defaults to the current page
388
- */
389
- public function toQuerystring($page=null){
390
-
391
- foreach($this->search_options as $paramName => $paramValue){
392
- if($paramName == 'query'){
393
- $toParams[$this->queryParameter] = $paramValue;
394
- } else {
395
- $toParams[$this->paramsPrefix.$paramName] = $paramValue;
396
- }
397
- }
398
- if($page){
399
- $toParams[$this->paramsPrefix.'page'] = $page;
400
- }
401
- return http_build_query($toParams);
402
- }
403
-
404
- /**
405
- * fromQuerystring
406
- *
407
- * obtain object's state from querystring params
408
- * @param string $params where to obtain params from:
409
- * - 'GET' $_GET params (default)
410
- * - 'POST' $_POST params
411
- */
412
- public function fromQuerystring(){
413
- $doofinderReqParams = array_filter(array_keys($this->serializationArray),
414
- array($this, 'belongsToDoofinder'));
415
-
416
- foreach($doofinderReqParams as $dfReqParam){
417
- if($dfReqParam == $this->queryParameter){
418
- $keey = 'query';
419
- } else {
420
- $keey = substr($dfReqParam, strlen($this->paramsPrefix));
421
- }
422
- $this->search_options[$keey] = $this->serializationArray[$dfReqParam];
423
- }
424
- }
425
-
426
- /**
427
- * sanitize
428
- *
429
- * Clean array of keys with empty values
430
- *
431
- * @param array $params array to be cleaned
432
- * @return array array with no empty keys
433
- */
434
- private function sanitize($params){
435
- $result = array();
436
- foreach($params as $name => $value){
437
- if (is_array($value)){
438
- $result[$name] = $this->sanitize($value);
439
- } else if (trim($value)){
440
- $result[$name] = $value;
441
- }
442
- }
443
- return $result;
444
- }
445
-
446
- /**
447
- * belongsToDoofinder
448
- *
449
- * to know if certain parameter name belongs to doofinder serialization parameters
450
- *
451
- * @param string $paramName name of the param
452
- * @return boolean true or false.
453
- */
454
- private function belongsToDoofinder($paramName){
455
- if($pos = strpos($paramName, '[')){
456
- $paramName = substr($paramName, 0, $pos);
457
- }
458
- return in_array($paramName, $this->allowedParameters) || $paramName == $this->queryParameter;
459
- }
460
-
461
- /**
462
- * optionExists
463
- *
464
- * checks whether a search option is defined in $this->search_options
465
- *
466
- * @param string $optionName
467
- * @return boolean
468
- */
469
- private function optionExists($optionName){
470
- return array_key_exists($optionName, $this->search_options);
471
- }
472
-
473
- /**
474
- * nextPage
475
- *
476
- * obtain the results for the next page
477
- * @return DoofinderResults if there are results.
478
- * @return null otherwise
479
- */
480
- public function nextPage(){
481
- if($this->hasNext())
482
- {
483
- return $this->query($this->lastQuery, $this->page+1 );
484
- }
485
- return null;
486
- }
487
-
488
-
489
- /**
490
- * prevPage
491
- *
492
- * obtain results for the previous page
493
- * @return DoofinderResults
494
- * @return null otherwise
495
- */
496
- public function prevPage(){
497
- if($this->hasPrev())
498
- {
499
- return $this->query($this->lastQuery, $this->page-1 );
500
- }
501
- return null;
502
- }
503
-
504
- /**
505
- * numPages
506
- *
507
- * @return integer the number of pages
508
- */
509
- public function numPages(){
510
- return ceil($this->total / $this->getRpp());
511
- }
512
-
513
- public function getRpp(){
514
- $rpp = $this->optionExists('rpp') ? $this->search_options['rpp'] : null;
515
- $rpp = $rpp ? $rpp: self::DEFAULT_RPP;
516
- return $rpp;
517
- }
518
- /**
519
- * setApiVersion
520
- *
521
- * sets the api version to use.
522
- * @param string $apiVersion the api version , '1.0' or '3.0' or '4'
523
- */
524
- public function setApiVersion($apiVersion){
525
- $this->apiVersion = $apiVersion;
526
- }
527
-
528
- /**
529
- * setPrefix
530
- *
531
- * sets the prefix that will be used for serialization to querystring params
532
- * @param string $prefix the prefix
533
- */
534
- public function setPrefix($prefix){
535
- $this->paramsPrefix = $prefix;
536
- }
537
-
538
- /**
539
- * setQueryName
540
- *
541
- * sets query_name
542
- * CAUTION: node will complain if this is wrong
543
- */
544
- public function setQueryName($queryName){
545
- $this->queryName = $queryName;
546
- }
547
-
548
- /**
549
- * getFilterType
550
- * obtain the filter type (i.e. 'terms' or 'numeric range' from its conditions)
551
- * @param array filter conditions
552
- * @return string 'terms' or 'numericrange' false otherwise
553
- */
554
- private function getFilterType($filter){
555
- if(!is_array($filter))
556
- {
557
- return false;
558
- }
559
- if(count(array_intersect(array('from', 'to'), array_keys($filter)))>0)
560
- {
561
- return 'numericrange';
562
- }
563
- return 'terms';
564
- }
565
-
566
-
567
- }
568
-
569
- /**
570
- * @author JoeZ99 <jzarate@gmail.com>
571
- *
572
- * DoofinderResults
573
- *
574
- * Very thin wrapper of the results obtained from the doofinder server
575
- * it holds to accessor:
576
- * - getProperty : get single property of the search results (rpp, page, etc....)
577
- * - getResults: get an array with the results
578
- */
579
- class DoofinderResults{
580
-
581
- // doofinder status
582
- const SUCCESS = 'success'; // everything ok
583
- const NOTFOUND = 'notfound'; // no account with the provided hashid found
584
- const EXHAUSTED = 'exhausted'; // the account has reached its query limit
585
-
586
- private $properties = null;
587
- private $results = null;
588
- private $facets = null;
589
- private $filter = null;
590
- public $status = null;
591
-
592
- /**
593
- * Constructor
594
- *
595
- * @param string $jsonString stringified json returned by doofinder search server
596
- */
597
- function __construct($jsonString){
598
- $rawResults = json_decode($jsonString, true);
599
- foreach($rawResults as $kkey => $vall){
600
- if(!is_array($vall)){
601
- $this->properties[$kkey] = $vall;
602
- }
603
- }
604
- // doofinder status
605
- $this->status = isset($this->properties['doofinder_status'])?
606
- $this->properties['doofinder_status'] : self::SUCCESS;
607
-
608
- // results
609
- $this->results = array();
610
-
611
- if(isset($rawResults['results']) && is_array($rawResults['results']))
612
- {
613
- $this->results = $rawResults['results'];
614
- }
615
-
616
- // build a friendly filter array
617
- $this->filter = array();
618
- // reorder filter, before assigning it to $this
619
- if(isset($rawResults['filter']))
620
- {
621
- foreach($rawResults['filter'] as $filterType => $filters)
622
- {
623
- foreach($filters as $filterName => $filterProperties)
624
- {
625
- $this->filter[$filterName] = $filterProperties;
626
- }
627
- }
628
- }
629
-
630
- // facets
631
- $this->facets = array();
632
- if(isset($rawResults['facets']))
633
- {
634
- $this->facets = $rawResults['facets'];
635
-
636
- // mark "selected" true or false according to filters presence
637
- foreach($this->facets as $facetName => $facetProperties){
638
- switch($facetProperties['_type']){
639
- case 'terms':
640
- foreach($facetProperties['terms'] as $pos => $term){
641
- if(isset($this->filter[$facetName]) && in_array($term['term'], $this->filter[$facetName])){
642
- $this->facets[$facetName]['terms'][$pos]['selected'] = true;
643
- } else {
644
- $this->facets[$facetName]['terms'][$pos]['selected'] = false;
645
- }
646
- }
647
- break;
648
- case 'range':
649
- foreach($facetProperties['ranges'] as $pos => $range){
650
- $this->facets[$facetName]['ranges'][$pos]['selected_from'] = false;
651
- $this->facets[$facetName]['ranges'][$pos]['selected_to'] = false;
652
- if(isset($this->filter[$facetName]) && isset($this->filter[$facetName]['gte'])){
653
- $this->facets[$facetName]['ranges'][$pos]['selected_from'] = $this->filter[$facetName]['gte'];
654
- }
655
- if(isset($this->filter[$facetName]) && isset($this->filter[$facetName]['lte'])){
656
- $this->facets[$facetName]['ranges'][$pos]['selected_to'] = $this->filter[$facetName]['lte'];
657
- }
658
-
659
- }
660
- break;
661
- }
662
- }
663
- }
664
- }
665
-
666
- /**
667
- * getProperty
668
- *
669
- * get single property from the results
670
- * @param string @propertyName: 'results_per_page', 'query', 'max_score', 'page', 'total', 'hashid'
671
- * @return mixed the value of the property
672
- */
673
- public function getProperty($propertyName){
674
- return array_key_exists($propertyName, $this->properties) ?
675
- $this->properties[$propertyName]: null;
676
- }
677
-
678
- /**
679
- * getResults
680
- *
681
- * @return array search results. at the moment, only the 'cooked' version.
682
- * Each result is of the form:
683
- * array('header'=>...,
684
- * 'body' => ..,
685
- * 'price' => ..,
686
- * 'href' => ...,
687
- * 'image' => ...,
688
- * 'type' => ...,
689
- * 'id' => ..)
690
- */
691
- public function getResults(){
692
- return $this->results;
693
- }
694
-
695
- /**
696
- *
697
- * getFacetsNames
698
- *
699
- * @return array facets names.
700
- */
701
- public function getFacetsNames(){
702
- return array_keys($this->facets);
703
- }
704
-
705
- /**
706
- * getFacet
707
- *
708
- * @param string name the facet name whose results are wanted
709
- *
710
- * @return array facet search data
711
- * - for terms facets
712
- * array(
713
- * '_type'=> 'terms', // type of facet 'terms' or 'range'
714
- * 'missing'=> 3, // # of elements with no value for this facet
715
- * 'others'=> 2, // # of terms not present in the search response
716
- * 'total'=> 6, // # number of possible terms for this facet
717
- * 'terms'=> array(
718
- * array('count'=>6, 'term'=>'Blue', 'selected'=>false), // in the response, there are 6 'blue' terms
719
- * array('count'=>3, 'term': 'Red', 'selected'=>true), // if 'selected'=>true, that term has been selected as filter
720
- * ...
721
- * )
722
- * )
723
- * - for range facets
724
- * array(
725
- * '_type'=> 'range',
726
- * 'ranges'=> array(
727
- * array(
728
- * 'count'=>6, // in the response, 6 elements within that range.
729
- * 'from':0,
730
- * 'min': 30
731
- * 'max': 90,
732
- * 'mean'=>33.2,
733
- * 'total'=>432,
734
- * 'total_count'=>6,
735
- * 'selected_from'=> 34.3 // if present. this value has been used as filter. false otherwise
736
- * 'selected_to'=> 99.3 // if present. this value has been used as filter. false otherwise
737
- * ),
738
- * ...
739
- * )
740
- * )
741
- *
742
- *
743
- */
744
- public function getFacet($facetName){
745
- return $this->facets[$facetName];
746
- }
747
-
748
- /**
749
- * getFacets
750
- *
751
- * get the whole facets associative array:
752
- * array('color'=>array(...), 'brand'=>array(...))
753
- * each array is defined as in getFacet() docstring
754
- *
755
- * @return array facets assoc. array
756
- */
757
- public function getFacets(){
758
- return $this->facets;
759
- }
760
-
761
- /**
762
- * getAppliedFilters
763
- *
764
- * get the filters the query has defined
765
- * array('categories' => array( // filter name . same as facet name
766
- * 'Sillas de paseo', // if simple array, it's a terms facet
767
- * 'Sacos sillas de paseo'
768
- * ),
769
- * 'color' => array(
770
- * 'red',
771
- * 'blue'
772
- * ),
773
- * 'price' => array(
774
- * 'include_upper'=>true, // if 'from' , 'to' keys, it's a range facet
775
- * 'from'=>35.19,
776
- * 'to'=>9999
777
- * )
778
- * )
779
- * MEANING OF THE EXAMPLE FILTER:
780
- * "FROM the query results, filter only results that have ('Sillas de paseo' OR 'Sacos sillas de paseo') categories
781
- * AND ('red' OR 'blue') color AND price is BETWEEN 34.3 and 99.3"
782
-
783
- */
784
- public function getAppliedFilters(){
785
- return $this->filter;
786
- }
787
-
788
- /**
789
- * isOk
790
- *
791
- * checks if all went well
792
- * @return boolean true if the status is 'success'.
793
- * false if the status is not.
794
- */
795
- public function isOk(){
796
- return $this->status == self::SUCCESS;
797
- }
798
- }
799
-
800
-
801
- class DoofinderException extends Exception{
802
-
803
- }
804
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
lib/Doofinder/doofinder_management_api.php DELETED
@@ -1,408 +0,0 @@
1
- <?php
2
- /**
3
- * Author:: JoeZ99 (<jzarate@gmail.com>).
4
- *
5
- * License:: Apache License, Version 2.0
6
- *
7
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
8
- * not use this file except in compliance with the License. You may obtain
9
- * 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, software
14
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16
- * License for the specific language governing permissions and limitations
17
- * under the License.
18
- */
19
- require_once dirname(__FILE__).'/errors.php';
20
-
21
-
22
- /**
23
- * Class to manage the connection with the API servers.
24
- *
25
- * Needs APIKEY in initialization.
26
- * Example: $dma = new DoofinderManagementApi('eu1-d531af87f10969f90792a4296e2784b089b8a875')
27
- */
28
- class DoofinderManagementApi
29
- {
30
- const REMOTE_API_ENDPOINT = "https://%s-api.doofinder.com/v1";
31
- const LOCAL_API_ENDPOINT = "http://localhost:8000/api/v1";
32
-
33
- private $apiKey = null;
34
- private $clusterRegion = 'eu1';
35
- private $token = null;
36
- private $baseManagementUrl = null;
37
-
38
- function __construct($apiKey, $local = false){
39
- $this->apiKey = $apiKey;
40
- $clusterToken = explode('-', $apiKey);
41
- $this->clusterRegion = $clusterToken[0];
42
- $this->token = $clusterToken[1];
43
- if ($local === true){
44
- $this->baseManagementUrl = self::LOCAL_API_ENDPOINT;
45
- } else {
46
- $this->baseManagementUrl = sprintf(self::REMOTE_API_ENDPOINT, $this->clusterRegion);
47
- }
48
- }
49
-
50
- /**
51
- * Makes the actual request to the API server and normalize response
52
- *
53
- * @param string $method The HTTP method to use. 'GET|PUT|POST|DELETE'
54
- * @param string $entryPoint The path to use. '/<hashid>/items/product'
55
- * @param array $params If any, url request parameters
56
- * @param array $data If any, body request parameters
57
- * @return array Array with both status code and response .
58
- */
59
- function managementApiCall($method='GET', $entryPoint='', $params=null, $data=null){
60
- $headers = array('Authorization: Token '.$this->token, // for Auth
61
- 'Content-Type: application/json',
62
- 'Expect:'); // Fixes the HTTP/1.1 417 Expectation Failed
63
-
64
- $url = $this->baseManagementUrl.'/'.$entryPoint;
65
- if (is_array($params) && sizeof($params) > 0){
66
- $url .= '?'.http_build_query($params);
67
- }
68
-
69
- $session = curl_init($url);
70
- curl_setopt($session, CURLOPT_CUSTOMREQUEST, $method);
71
- curl_setopt($session, CURLOPT_HEADER, false);
72
- curl_setopt($session, CURLOPT_RETURNTRANSFER, true); // Tell curl to return the response
73
- curl_setopt($session, CURLOPT_HTTPHEADER, $headers); // Adding request headers
74
-
75
- if (in_array($method, array('POST', 'PUT'))){
76
- curl_setopt($session, CURLOPT_POSTFIELDS, $data);
77
- }
78
-
79
- $response = curl_exec($session);
80
- $httpCode = curl_getinfo($session, CURLINFO_HTTP_CODE);
81
- curl_close($session);
82
-
83
- handleErrors($httpCode, $response);
84
-
85
- $return = array('statusCode' => $httpCode);
86
- $return['response'] = ($decoded = json_decode($response, true)) ? $decoded : $response;
87
-
88
- return $return;
89
- }
90
-
91
- /**
92
- * To get info on all possible api entry points
93
- * @return array An assoc. array with the different entry points
94
- */
95
- function getApiRoot(){
96
- $response = $this->managementApiCall();
97
- return $response['response'];
98
- }
99
-
100
- /**
101
- * Obtain a list of SearchEngines objects, ready to interact with the API
102
- * @return array list of searchEngines objects
103
- */
104
- function getSearchEngines(){
105
- $searchEngines = array();
106
- $apiRoot = $this->getApiRoot();
107
- unset($apiRoot['searchengines']);
108
-
109
- foreach($apiRoot as $hashid => $props){
110
- $searchEngines[] = new SearchEngine($this, $hashid, $props['name']);
111
- }
112
-
113
- return $searchEngines;
114
- }
115
-
116
- }
117
-
118
- /**
119
- * Class with all the capabilities described in the API
120
- *
121
- * see http://www.doofinder.com/developer/topics/api/management-api
122
- */
123
- class SearchEngine {
124
- public $name = null;
125
- public $hashid = null;
126
-
127
- private $dma = null; // DoofinderManagementApi instance
128
-
129
- function __construct($dma, $hashid, $name){
130
- $this->name = $name;
131
- $this->hashid = $hashid;
132
- $this->dma = $dma;
133
- }
134