| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- <?php
- namespace App\Console\Commands;
- use Illuminate\Console\Command;
- use App\Models\WbwTemplate;
- class UpgradeWbwWeight extends Command
- {
- /**
- * The name and signature of the console command.
- * php artisan upgrade:wbw.weight 66
- * @var string
- */
- protected $signature = 'upgrade:wbw.weight {book?} {para?}';
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = 'upgrade wbw template weight by word bold ';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
- /**
- * Execute the console command.
- *
- * @return int
- */
- public function handle()
- {
- $book = $this->argument('book');
- $para = $this->argument('para');
- for ($iBook=1; $iBook <= 217 ; $iBook++) {
- if($book && $book != $iBook ){
- continue;
- }
- $this->info('running book='.$iBook);
- $maxPara = WbwTemplate::where("book",$iBook)->max('paragraph');
- $bar = $this->output->createProgressBar($maxPara);
- for ($iPara=1; $iPara <= $maxPara ; $iPara++) {
- if($para && $para != $iPara ){
- continue;
- }
- $bar->advance();
- $words = WbwTemplate::where("book",$iBook)
- ->where("paragraph",$iPara)
- ->orderBy('wid','asc')
- ->get();
- $start = -1;
- $bold = 0;
- for ($iWord=0; $iWord < count($words); $iWord++) {
- WbwTemplate::where('id',$words[$iWord]->id)->update(['weight'=>1]);
- if($words[$iWord]->style === 'bld'){
- if($start === -1){
- $start = $iWord;
- $bold = 1;
- }else{
- $bold++;
- }
- }else{
- if($start>=0){
- $weight = 10 / pow($bold,2);
- for ($i=$start; $i < $iWord ; $i++) {
- $wordWeight = 1 + $weight;
- $result = WbwTemplate::where('id',$words[$i]->id)
- ->update(['weight'=>(int)$wordWeight]);
- }
- $start = -1;
- $bold = 0;
- }
- }
- }
- }
- $bar->finish();
- }
- return 0;
- }
- }
|