Guest User

Untitled

a guest
Jan 22nd, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.79 KB | None | 0 0
  1. <?php
  2. //App::import('Router');
  3. class FillTwitterQueueShell extends Shell {
  4.  
  5. var $uses = array ( 'City', 'Departement', 'Region', 'TwitterQueue' ) ;
  6.  
  7.  
  8. function main ( ) {
  9.  
  10. $regionList = $this->Region->find('all', array( 'contain' => false,
  11. 'conditions' => array(
  12. 'Region.is_available' => 1 ),
  13. 'fields' => array(
  14. 'Region.id',
  15. 'Region.slug',
  16. 'Region.name')
  17. )
  18. );
  19. foreach ( $regionList as $region ) {
  20. $regionUrl = Router::url ( array (
  21. 'controller' => 'departements',
  22. 'action' => 'index',
  23. 'ext' => 'html',
  24. 'RegionSlug' => $region['Region']['slug']),
  25. true
  26. );
  27.  
  28.  
  29. $regionData = array ( 'model' => 'region',
  30. 'model_id' => $region['Region']['id'],
  31. 'title' => 'Go-menage : ' . $region['Region']['name'],
  32. 'url' => $regionUrl ) ;
  33.  
  34. $this->TwitterQueue->create ( ) ;
  35. $this->TwitterQueue->save ( $regionData ) ;
  36.  
  37.  
  38. $departementList = $this->Departement->find('all',array(
  39. 'contain' => false,
  40. 'conditions' => array (
  41. Departement.region_id' => $region['Region']['id'],
  42. Departement.is_available' => 1
  43. ),
  44. 'fields' => array (
  45. 'Departement.slug' ,
  46. 'Departement.id',
  47. 'Departement.name' )
  48. )
  49. );
  50.  
  51. foreach ( $departementList as $departement ) {
  52.  
  53. $departementUrl = Router::url ( array (
  54. 'controller' => 'cities',
  55. 'action' => 'index',
  56. 'ext' => 'html',
  57. 'RegionSlug' => $region['Region']['slug'],
  58. 'DepartementSlug' => $departement['Departement']['slug']
  59. ),
  60. true
  61. );
  62.  
  63. $departementFullUrl = Router::url ( array (
  64. 'controller' => 'cities',
  65. 'action' => 'index',
  66. 'ext' => 'html',
  67. 'RegionSlug' => $region['Region']['slug'],
  68. 'DepartementSlug' => $departement['Departement']['slug'],
  69. true
  70. ),
  71. true
  72. );
  73.  
  74. $departementData = array ( 'model' => 'departement',
  75. 'model_id' => $departement['Departement']['id'],
  76. 'title' => 'Go-menage : ' . $departement['Departement']['name'],
  77. 'url' => $departementUrl
  78. );
  79. $this->TwitterQueue->create ( ) ;
  80. $this->TwitterQueue->save ( $departementData ) ;
  81.  
  82. // ON construit l'url de toutes les villes du département
  83.  
  84.  
  85.  
  86. $departementFullData = array ( 'model' => 'departement',
  87. 'model_id' => $departement['Departement']['id'],
  88. 'title' => 'Go-menage : toutes les villes de ' . $departement['Departement']['name'],
  89. 'url' => $departementFullUrl
  90. );
  91.  
  92. $this->TwitterQueue->create ( ) ;
  93. $this->TwitterQueue->save ( $departementFullData ) ;
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100. $cityList = $this->City->find (
  101. 'all',
  102. array (
  103. 'contain' => array ( ) ,
  104. 'conditions' => array (
  105. 'City.is_available' => 1,
  106. 'City.departement_id' => $departement['Departement']['id']
  107. ),
  108. 'fields' => array ( 'City.slug', 'City.id', 'City.name' )
  109. ));
  110.  
  111. foreach ( $cityList as $city ) {
  112.  
  113. $cityUrl = Router::url (
  114. array (
  115. 'controller' => 'cities',
  116. 'action' => 'view',
  117. 'ext' => 'html',
  118. 'RegionSlug' => $region['Region']['slug'],
  119. 'DepartementSlug' => $departement['Departement']['slug'],
  120. 'CitySlug' => $city['City']['slug'] )
  121. , true
  122. ) ;
  123.  
  124.  
  125. $cityData = array ( 'model' => 'city',
  126. 'model_id' => $city['City']['id'],
  127. 'title' => 'Go-menage : ' . $city['City']['name'],
  128. 'url' => $cityUrl
  129. );
  130.  
  131. $this->TwitterQueue->create ( ) ;
  132.  
  133. $this->TwitterQueue->save ( $cityData ) ;
  134.  
  135.  
  136. }
  137. }
  138. }
  139. }
  140. }
Add Comment
Please, Sign In to add comment