ORView.php
1 <?php 2 3 namespace App\Http\Livewire\Jsons; 4 5 use App\Models\JsonDraft; 6 use Illuminate\Support\Collection; 7 use Livewire\Component; 8 use Livewire\WithPagination; 9 10 class ORView extends BaseJsonView 11 { 12 public function getEvidencesListProperty() 13 { 14 return collect($this->json->json['evidencelist']); 15 } 16 17 public function diffedEvidenceList() 18 { 19 $olds = $this->oldJson->json['evidencelist']; 20 $news = collect($this->json->json['evidencelist']); 21 $result = []; 22 $used = []; 23 24 foreach ($news as $new) { 25 $used[] = $new; 26 $position = array_search($new,$olds); 27 28 if ($position === false) { 29 $aux = ''; 30 } else { 31 $aux = $olds[$position]; 32 } 33 34 $result[] = $this->applyDiff($new ?? '', $aux ?? ''); 35 } 36 37 $used = collect($used); 38 foreach ($olds as $old) { 39 if (!$used->contains($old)) { 40 $result[] = $this->applyDiff('', $old ?? ''); 41 } 42 } 43 44 return collect(implode(', ',$result)); 45 } 46 47 public function render() 48 { 49 return view('livewire.jsons.or-view') 50 ->layoutData([ 51 'title' => $this->json->schema_name, 52 'entity' => $this->json, 53 'breadcrumb' => 'jsons.view', 54 ]); 55 } 56 }