Advertisement
Guest User

Untitled

a guest
Dec 13th, 2015
556
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. /**
  4. * Aquatuning Software Development - Warehouse - Subscriber
  5. *
  6. * @category Aquatuning
  7. * @package Shopware\Plugins\AtsdWarehouse
  8. * @copyright Copyright (c) 2013, Aquatuning GmbH
  9. */
  10.  
  11. namespace Shopware\AtsdWarehouse\Subscriber\Components;
  12.  
  13.  
  14.  
  15. /**
  16. * Aquatuning Software Development - Warehouse - Subscriber
  17. */
  18.  
  19. class Document implements \Enlight\Event\SubscriberInterface
  20. {
  21.  
  22. /**
  23. * Main bootstrap object.
  24. *
  25. * @var \Shopware_Components_Plugin_Bootstrap
  26. */
  27.  
  28. protected $bootstrap;
  29.  
  30. /**
  31. * ...
  32. *
  33. * @var integer
  34. */
  35.  
  36. static public $documentId = null;
  37.  
  38.  
  39.  
  40.  
  41.  
  42. /**
  43. * ...
  44. *
  45. * @param \Shopware_Components_Plugin_Bootstrap $bootstrap
  46. *
  47. * @return \Shopware\AtsdWarehouse\Subscriber\Components\Document
  48. */
  49.  
  50. public function __construct( \Shopware_Components_Plugin_Bootstrap $bootstrap )
  51. {
  52. // set params
  53. $this->bootstrap = $bootstrap;
  54. }
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63. /**
  64. * Return the subscribed controller events.
  65. *
  66. * @return array
  67. */
  68.  
  69. public static function getSubscribedEvents()
  70. {
  71. // return the events
  72. return array(
  73. 'Shopware_Components_Document::setDocumentId::before' => "beforeDocumentSetDocumentIdHook",
  74. 'Shopware_Components_Document::assignValues::after' => "afterDocumentAssignValuesHook",
  75. 'Theme_Inheritance_Template_Directories_Collected' => "onCollectDirectoriesEvent"
  76. );
  77. }
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87. /**
  88. * Add our document path.
  89. *
  90. * @param \Enlight_Event_EventArgs $args
  91. *
  92. * @return array
  93. */
  94.  
  95. public function onCollectDirectoriesEvent( \Enlight_Event_EventArgs $args )
  96. {
  97. // get the current directories
  98. $directories = $args->getReturn();
  99.  
  100. // add our own
  101. array_push(
  102. $directories,
  103. $this->bootstrap->Path() . "Views/"
  104. );
  105.  
  106. // and we re done
  107. return $directories;
  108. }
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116. /**
  117. * ...
  118. *
  119. * @param \Enlight_Hook_HookArgs $args
  120. *
  121. * @return void
  122. */
  123.  
  124. public function beforeDocumentSetDocumentIdHook( \Enlight_Hook_HookArgs $args )
  125. {
  126. // just save the document id
  127. self :: $documentId = $args->get( "id" );
  128.  
  129. // and we re done
  130. return;
  131. }
  132.  
  133.  
  134.  
  135.  
  136.  
  137. /**
  138. * ...
  139. *
  140. * @param \Enlight_Hook_HookArgs $args
  141. *
  142. * @return void
  143. */
  144.  
  145. public function afterDocumentAssignValuesHook( \Enlight_Hook_HookArgs $args )
  146. {
  147. // is this our document?!
  148. if ( self :: $documentId != 5 )
  149. // nothing to do here
  150. return;
  151.  
  152. // get the controller
  153. $document = $args->getSubject();
  154.  
  155. // get the view
  156. $view = $document->_view;
  157.  
  158. // get the pages
  159. $pages = $view->getTemplateVars( "Pages" );
  160.  
  161. // loop all articles within the first page (for now)
  162. foreach ( $pages[0] as &$article )
  163. {
  164. // set a default value
  165. $article['atsdLocation'] = "";
  166.  
  167. // get the article model
  168. $model = Shopware()->Models()->find( '\Shopware\Models\Article\Article', (integer) $article['articleID'] );
  169.  
  170. // not found?!
  171. if ( !$model instanceof \Shopware\Models\Article\Article )
  172. // weird
  173. continue;
  174.  
  175. // find the location for it
  176. $location = Shopware()->Models()
  177. ->getRepository( '\Shopware\CustomModels\AtsdWarehouse\Warehouse\Location\Location' )
  178. ->findOneLocationByArticle( $model );
  179.  
  180. // we found no location
  181. if ( !is_array( $location ) )
  182. // next one
  183. continue;
  184.  
  185. // set it
  186. $article['atsdLocation'] = $location['shelf']['store']['identifier'] . " " .$location['shelf']['identifier'] . " " . $location['positionY'] . "-" . $location['positionX'];
  187. }
  188.  
  189. // now sort it
  190. $this->array_sort_by_column( $pages[0], "atsdLocation" );
  191.  
  192. // assign it again
  193. $view->assign( "Pages", $pages );
  194.  
  195. // and we re done
  196. return;
  197. }
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.  
  207.  
  208.  
  209.  
  210. /**
  211. * Sort an array by its column.
  212. *
  213. * @param array $arr
  214. * @param string $col
  215. * @param int|string $dir
  216. *
  217. * @return void
  218. */
  219.  
  220. public function array_sort_by_column( &$arr, $col, $dir = SORT_ASC )
  221. {
  222. $sort_col = array();
  223. foreach ($arr as $key=> $row)
  224. $sort_col[$key] = $row[$col];
  225. array_multisort($sort_col, $dir, $arr);
  226. }
  227.  
  228.  
  229.  
  230.  
  231.  
  232. }
Advertisement
RAW Paste Data Copied
Advertisement