PageRenderTime 298ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/magmi/plugins/base/itemprocessors/defaultvalues/00_default_values.php

https://bitbucket.org/jit_bec/shopifine
PHP | 100 lines | 67 code | 13 blank | 20 comment | 4 complexity | 7acc08093925d578c78e46e8f28d27c1 MD5 | raw file
Possible License(s): LGPL-3.0
  1. <?php
  2. /**
  3. * Class SampleItemProcessor
  4. * @author dweeves
  5. *
  6. * This class is a sample for item processing
  7. */
  8. class DefaultValuesItemProcessor extends Magmi_ItemProcessor
  9. {
  10. protected $_dset=array();
  11. protected $_dcols=array();
  12. public function getPluginInfo()
  13. {
  14. return array(
  15. "name" => "Default Values setter",
  16. "author" => "Dweeves",
  17. "version" => "0.0.5",
  18. "url" => "http://sourceforge.net/apps/mediawiki/magmi/index.php?title=Default_Values_setter"
  19. );
  20. }
  21. /**
  22. * you can add/remove columns for the item passed since it is passed by reference
  23. * @param Magmi_Engine $mmi : reference to magmi engine instance (convenient to perform database operations)
  24. * @param unknown_type $item : modifiable reference to item before import
  25. * the $item is a key/value array with column names as keys and values as read from csv file.
  26. * @return bool :
  27. * true if you want the item to be imported after your custom processing
  28. * false if you want to skip item import after your processing
  29. */
  30. public function processItemBeforeId(&$item,$params=null)
  31. {
  32. foreach($this->_dcols as $col)
  33. {
  34. $item[$col]=$this->_dset[$col];
  35. }
  36. return true;
  37. }
  38. public function processItemAfterId(&$item,$params=null)
  39. {
  40. return true;
  41. }
  42. /*
  43. public function processItemException(&$item,$params=null)
  44. {
  45. }*/
  46. public function initialize($params)
  47. {
  48. foreach($params as $k=>$v)
  49. {
  50. if(preg_match_all("/^DEFAULT:(.*)$/",$k,$m) && $k!="DEFAULT:columnlist")
  51. {
  52. $this->_dset[$m[1][0]]=$params[$k];
  53. }
  54. }
  55. }
  56. public function getPluginParams($params)
  57. {
  58. $pp=array();
  59. foreach($params as $k=>$v)
  60. {
  61. if(preg_match("/^DEFAULT:.*$/",$k))
  62. {
  63. $pp[$k]=$v;
  64. }
  65. }
  66. return $pp;
  67. }
  68. public function processColumnList(&$cols,$params=null)
  69. {
  70. $dcols=array_diff(array_keys($this->_dset),array_intersect($cols,array_keys($this->_dset)));
  71. foreach($dcols as $col)
  72. {
  73. if(!empty($this->_dset[$col]))
  74. {
  75. $cols[]=$col;
  76. $this->_dcols[]=$col;
  77. }
  78. }
  79. $this->log("Adding Columns ".implode(",",$dcols),"startup");
  80. return true;
  81. }
  82. static public function getCategory()
  83. {
  84. return "Input Data Preprocessing";
  85. }
  86. }