UpgradeWbwWeight.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use App\Models\WbwTemplate;
  5. class UpgradeWbwWeight extends Command
  6. {
  7. /**
  8. * The name and signature of the console command.
  9. * php artisan upgrade:wbw.weight 66
  10. * @var string
  11. */
  12. protected $signature = 'upgrade:wbw.weight {book?} {para?}';
  13. /**
  14. * The console command description.
  15. *
  16. * @var string
  17. */
  18. protected $description = 'upgrade wbw template weight by word bold ';
  19. /**
  20. * Create a new command instance.
  21. *
  22. * @return void
  23. */
  24. public function __construct()
  25. {
  26. parent::__construct();
  27. }
  28. /**
  29. * Execute the console command.
  30. *
  31. * @return int
  32. */
  33. public function handle()
  34. {
  35. $book = $this->argument('book');
  36. $para = $this->argument('para');
  37. for ($iBook=1; $iBook <= 217 ; $iBook++) {
  38. if($book && $book != $iBook ){
  39. continue;
  40. }
  41. $this->info('running book='.$iBook);
  42. $maxPara = WbwTemplate::where("book",$iBook)->max('paragraph');
  43. $bar = $this->output->createProgressBar($maxPara);
  44. for ($iPara=1; $iPara <= $maxPara ; $iPara++) {
  45. if($para && $para != $iPara ){
  46. continue;
  47. }
  48. $bar->advance();
  49. $words = WbwTemplate::where("book",$iBook)
  50. ->where("paragraph",$iPara)
  51. ->orderBy('wid','asc')
  52. ->get();
  53. $start = -1;
  54. $bold = 0;
  55. for ($iWord=0; $iWord < count($words); $iWord++) {
  56. WbwTemplate::where('id',$words[$iWord]->id)->update(['weight'=>1]);
  57. if($words[$iWord]->style === 'bld'){
  58. if($start === -1){
  59. $start = $iWord;
  60. $bold = 1;
  61. }else{
  62. $bold++;
  63. }
  64. }else{
  65. if($start>=0){
  66. $weight = 10 / pow($bold,2);
  67. for ($i=$start; $i < $iWord ; $i++) {
  68. $wordWeight = 1 + $weight;
  69. $result = WbwTemplate::where('id',$words[$i]->id)
  70. ->update(['weight'=>(int)$wordWeight]);
  71. }
  72. $start = -1;
  73. $bold = 0;
  74. }
  75. }
  76. }
  77. }
  78. $bar->finish();
  79. }
  80. return 0;
  81. }
  82. }